82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
/** Platzhalter bis ZKA-Produktregistrierung vorliegt – Bank kann ablehnen, Config-Check bricht nicht ab. */
|
||
export const FINTS_PRODUCT_ID_PLACEHOLDER = "XXXXX";
|
||
|
||
export type FintsConfigStatus = {
|
||
ready: boolean;
|
||
missing: string[];
|
||
warnings: string[];
|
||
usesProductIdPlaceholder: boolean;
|
||
};
|
||
|
||
export function getFintsConfigStatus(overrides?: {
|
||
blz?: string;
|
||
url?: string;
|
||
login?: string;
|
||
productId?: string;
|
||
pin?: string;
|
||
}): FintsConfigStatus {
|
||
const url = overrides?.url || process.env.FINTS_BANK_URL || "";
|
||
const blz = overrides?.blz || process.env.FINTS_BANK_BLZ || "";
|
||
const login = overrides?.login || process.env.FINTS_USER_ID || "";
|
||
const pin = overrides?.pin || process.env.FINTS_PIN || "";
|
||
const productId = overrides?.productId || process.env.FINTS_PRODUCT_ID || "";
|
||
|
||
const missing: string[] = [];
|
||
if (!url) missing.push("FinTS-URL");
|
||
if (!blz) missing.push("BLZ");
|
||
if (!login) missing.push("Zugangsnummer");
|
||
if (!pin) missing.push("PIN");
|
||
|
||
const warnings: string[] = [];
|
||
const usesProductIdPlaceholder = !productId;
|
||
if (usesProductIdPlaceholder) {
|
||
warnings.push(
|
||
"Produkt-ID (ZKA) noch nicht gesetzt – Sync wird versucht, die Bank kann die Anfrage ablehnen.",
|
||
);
|
||
}
|
||
|
||
return {
|
||
ready: missing.length === 0,
|
||
missing,
|
||
warnings,
|
||
usesProductIdPlaceholder,
|
||
};
|
||
}
|
||
|
||
export function resolveFintsEnvFields(overrides?: {
|
||
blz?: string;
|
||
url?: string;
|
||
login?: string;
|
||
productId?: string;
|
||
productVersion?: string;
|
||
pin?: string;
|
||
}): {
|
||
productId: string;
|
||
productVersion: string;
|
||
url: string;
|
||
blz: string;
|
||
login: string;
|
||
pin: string;
|
||
usesProductIdPlaceholder: boolean;
|
||
} {
|
||
const status = getFintsConfigStatus(overrides);
|
||
if (!status.ready) {
|
||
throw new Error(
|
||
`FinTS-Zugang unvollständig: ${status.missing.join(", ")} fehlt. Bitte in Convex-Env oder Einstellungen ergänzen.`,
|
||
);
|
||
}
|
||
|
||
const productId =
|
||
overrides?.productId || process.env.FINTS_PRODUCT_ID || FINTS_PRODUCT_ID_PLACEHOLDER;
|
||
|
||
return {
|
||
productId,
|
||
productVersion: overrides?.productVersion || process.env.FINTS_PRODUCT_VERSION || "1.0.0",
|
||
url: overrides?.url || process.env.FINTS_BANK_URL || "",
|
||
blz: overrides?.blz || process.env.FINTS_BANK_BLZ || "",
|
||
login: overrides?.login || process.env.FINTS_USER_ID || "",
|
||
pin: overrides?.pin || process.env.FINTS_PIN || "",
|
||
usesProductIdPlaceholder: status.usesProductIdPlaceholder,
|
||
};
|
||
}
|