125 lines
3.7 KiB
JavaScript
125 lines
3.7 KiB
JavaScript
const parseBoolean = (value, fallback = false) => {
|
|
if (typeof value === "boolean") {
|
|
return value;
|
|
}
|
|
if (typeof value === "string") {
|
|
const normalized = value.trim().toLowerCase();
|
|
if (["1", "true", "yes", "on"].includes(normalized)) {
|
|
return true;
|
|
}
|
|
if (["0", "false", "no", "off"].includes(normalized)) {
|
|
return false;
|
|
}
|
|
}
|
|
return fallback;
|
|
};
|
|
|
|
const normalizeApiUrl = (value) => String(value || "").replace(/\/+$/, "");
|
|
|
|
export const IS_DEV = parseBoolean(
|
|
import.meta.env.VITE_IS_DEV,
|
|
import.meta.env.DEV ?? import.meta.env.MODE !== "production"
|
|
);
|
|
const normalizeReleaseSource = (value) => {
|
|
const normalized = String(value || "").trim().toLowerCase();
|
|
if (["local", "deployment", "auto"].includes(normalized)) {
|
|
return normalized;
|
|
}
|
|
return IS_DEV ? "local" : "deployment";
|
|
};
|
|
export const RELEASE_SOURCE_ENV = String(import.meta.env.VITE_RELEASE_SOURCE || "").trim().toLowerCase();
|
|
export const RELEASE_SOURCE = normalizeReleaseSource(RELEASE_SOURCE_ENV);
|
|
export const DEFAULT_LEGACY_API_URL = "https://api.truckwash.io";
|
|
export const DEFAULT_PUBLIC_GATEWAY_API_URL = "https://api-v2.truckwash.io";
|
|
export const DEFAULT_STABLE_API_URL = `${DEFAULT_PUBLIC_GATEWAY_API_URL}/master/api`;
|
|
|
|
// Development mode
|
|
export const POS_STEP_1_VERSION = 2; //(IS_DEV ? 2 : 1);
|
|
export const API_URL = normalizeApiUrl(
|
|
import.meta.env.VITE_API_URL || (IS_DEV ? "/api" : DEFAULT_STABLE_API_URL)
|
|
);
|
|
export const RELEASE_MANAGER_CONTROL_API_URL = normalizeApiUrl(
|
|
import.meta.env.VITE_RELEASE_MANAGER_CONTROL_API_URL || API_URL
|
|
);
|
|
export const RELEASE_PUBLIC_GATEWAY_API_URL = normalizeApiUrl(
|
|
import.meta.env.VITE_RELEASE_PUBLIC_GATEWAY_API_URL || DEFAULT_PUBLIC_GATEWAY_API_URL
|
|
);
|
|
export const RELEASE_MANAGER_CONTROL_API_FALLBACK_URLS = String(
|
|
import.meta.env.VITE_RELEASE_MANAGER_CONTROL_API_FALLBACK_URLS ||
|
|
(IS_DEV ? `${DEFAULT_STABLE_API_URL},${DEFAULT_PUBLIC_GATEWAY_API_URL}` : "")
|
|
)
|
|
.split(",")
|
|
.map((url) => normalizeApiUrl(url.trim()))
|
|
.filter(Boolean);
|
|
export const RELEASE_TRUSTED_ORIGINS = String(import.meta.env.VITE_RELEASE_TRUSTED_ORIGINS || "")
|
|
.split(",")
|
|
.map((origin) => origin.trim().replace(/\/+$/, ""))
|
|
.filter(Boolean);
|
|
export const SELF_SERVE_ATTACHMENT_TRUSTED_ORIGINS = String(
|
|
import.meta.env.VITE_SELF_SERVE_ATTACHMENT_TRUSTED_ORIGINS || ""
|
|
)
|
|
.split(",")
|
|
.map((origin) => origin.trim().replace(/\/+$/, ""))
|
|
.filter(Boolean);
|
|
|
|
// Allowed origins
|
|
export const ALLOWED_ORIGINS = [
|
|
"https://truckwash.io",
|
|
"https://www.truckwash.io",
|
|
"http://localhost:5173",
|
|
"http://localhost:4173",
|
|
"http://localhost:4174",
|
|
"http://127.0.0.1:5173",
|
|
"http://127.0.0.1:4173",
|
|
"http://127.0.0.1:4174",
|
|
"https://dev.truckwash.io",
|
|
];
|
|
export const MIGRATION_ORIGIN = "https://truckwash.io";
|
|
|
|
// Global request queue / retry / progress configuration
|
|
export const REQUEST_QUEUE_CONFIG = Object.freeze({
|
|
// Per-method concurrency limits
|
|
concurrency: Object.freeze({
|
|
GET: 10,
|
|
POST: 1,
|
|
PATCH: 1,
|
|
PUT: 1,
|
|
DELETE: 1,
|
|
DEFAULT: 1,
|
|
}),
|
|
// Delay between queue starts (0 = no pacing delay)
|
|
spacingMs: 0,
|
|
// Retries by HTTP status code
|
|
retryByStatusCode: Object.freeze({
|
|
429: 4,
|
|
500: 1,
|
|
502: 2,
|
|
503: 2,
|
|
504: 2,
|
|
}),
|
|
retryDelay: Object.freeze({
|
|
baseMs: 300,
|
|
maxMs: 3000,
|
|
jitterMs: 50,
|
|
}),
|
|
ping: Object.freeze({
|
|
endpoint: "/ping",
|
|
intervalMs: 30000,
|
|
timeoutMs: 5000,
|
|
}),
|
|
inspector: Object.freeze({
|
|
expandedByDefault: false,
|
|
timerRefreshMs: 250,
|
|
recentRequestsLimit: 8,
|
|
errorHistoryLimit: 10,
|
|
missingPermissionsLimit: 20,
|
|
componentPermissionReportWindowMs: 2000,
|
|
payloadMaxChars: 4000,
|
|
}),
|
|
// Queue progress widget behavior
|
|
progress: Object.freeze({
|
|
minBatchSizeToShow: 2,
|
|
completedVisibleMs: 2500,
|
|
}),
|
|
});
|