Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -1,3 +1,4 @@
import { EnabledLocalesConfigError, parseEnabledLocales } from "@hivegrid/i18n";
import { getEnvVariableDefinition, validateEnv } from "./index.js";
import { getDomainRoutingConfig } from "./routing.js";
import type { ApiConfig, ApiConfigDiagnostic, ApiConfigErrorDetails, ApiConfigOptions, ApiConfigResult, EnvRecord, RequiredApiConfigOptions } from "./types.js";
@@ -9,6 +10,22 @@ const DEFAULT_LAGO_TIMEOUT_MS = 10_000;
const DEFAULT_MOLLIE_TIMEOUT_MS = 10_000;
const MIN_PORT = 1;
const MAX_PORT = 65535;
const MIN_SECRET_LENGTH = 32;
const MAX_METRICS_TOKEN_BYTES = 512;
const STRENGTH_CHECKED_SECRETS = [
"SESSION_SECRET",
"CRYPTO_SECRET",
"ADMIN_CONNECTION_MASTER_KEY",
"JWT_SECRET",
"API_ACCESS_TOKEN",
"ANALYTICS_TOKEN",
"AUDIT_CHAIN_SECRET",
"METRICS_TOKEN",
"MAILJET_WEBHOOK_SECRET",
"ADMIN_EMAIL_EVENT_WEBHOOK_SECRET",
"ADMIN_EMAIL_BCC_CAPABILITY_SECRET",
"API_KEY_HASH_SECRET",
] as const;
export class ApiConfigError extends Error {
readonly diagnostics: ApiConfigDiagnostic[];
@@ -53,6 +70,20 @@ export function loadApiConfig(env: EnvRecord = process.env, options: ApiConfigOp
if (portResult.diagnostic) {
diagnostics.push(portResult.diagnostic);
}
diagnostics.push(...validateApiSecretStrength(env, nodeEnv));
try {
parseEnabledLocales(env.I18N_ENABLED_LOCALES, {
allowReviewLocales: nodeEnv !== "production" || env.SENTRY_ENVIRONMENT?.trim().toLowerCase() === "staging",
});
} catch (error) {
if (!(error instanceof EnabledLocalesConfigError)) throw error;
diagnostics.push({
code: "invalid-enum",
name: "I18N_ENABLED_LOCALES",
classification: getEnvVariableDefinition("I18N_ENABLED_LOCALES")?.classification,
message: error.message,
});
}
const config: ApiConfig = {
appName: present(env.APP_NAME) ?? DEFAULT_APP_NAME,
@@ -74,6 +105,13 @@ export function loadApiConfig(env: EnvRecord = process.env, options: ApiConfigOp
mailjet: {
webhookSecret: present(env.MAILJET_WEBHOOK_SECRET),
},
adminEmail: {
eventWebhookSecret: present(env.ADMIN_EMAIL_EVENT_WEBHOOK_SECRET),
bccCapabilitySecret: present(env.ADMIN_EMAIL_BCC_CAPABILITY_SECRET),
bccInboundDomain:
present(env.ADMIN_EMAIL_BCC_INBOUND_DOMAIN) ??
`bcc.${routing.appBaseDomain.split(":")[0]}`,
},
lago: {
apiUrl: present(env.LAGO_API_URL),
apiKey: present(env.LAGO_API_KEY),
@@ -156,6 +194,45 @@ function normalizeListenPort(apiPort: string | undefined, port: string | undefin
return { port: parsed };
}
function validateApiSecretStrength(env: EnvRecord, nodeEnv: string): ApiConfigDiagnostic[] {
if (nodeEnv !== "production") {
return [];
}
const diagnostics: ApiConfigDiagnostic[] = [];
const firstPurposeByValue = new Map<string, (typeof STRENGTH_CHECKED_SECRETS)[number]>();
for (const name of STRENGTH_CHECKED_SECRETS) {
const value = present(env[name]);
if (!value) {
continue;
}
const byteLength = Buffer.byteLength(value, "utf8");
if (byteLength < MIN_SECRET_LENGTH || (name === "METRICS_TOKEN" && byteLength > MAX_METRICS_TOKEN_BYTES)) {
diagnostics.push({
code: "weak-secret",
name,
classification: getEnvVariableDefinition(name)?.classification,
message: name === "METRICS_TOKEN"
? `METRICS_TOKEN must contain ${MIN_SECRET_LENGTH}..${MAX_METRICS_TOKEN_BYTES} bytes in production.`
: `${name} must be at least ${MIN_SECRET_LENGTH} bytes in production.`,
});
}
const existingPurpose = firstPurposeByValue.get(value);
if (existingPurpose) {
diagnostics.push({
code: "weak-secret",
name,
classification: getEnvVariableDefinition(name)?.classification,
message: `${name} must use an independent value and must not be identical to ${existingPurpose}.`,
});
} else {
firstPurposeByValue.set(value, name);
}
}
return diagnostics;
}
function toDiagnostics(issues: ReturnType<typeof validateEnv>["missing"]): ApiConfigDiagnostic[] {
return issues.map((issue) => ({
code: "missing-required",