fix(POSTV1-01): 允许非关键外部服务降级启动

This commit is contained in:
suyx
2026-08-05 11:22:42 +08:00
parent 443e8b94f0
commit 99fe07a761
4 changed files with 21 additions and 16 deletions
+7 -7
View File
@@ -1,6 +1,6 @@
import { createConnection } from "node:net";
import { RealAmapAdapter } from "./amap-adapter.js";
import { MockAmapAdapter, RealAmapAdapter } from "./amap-adapter.js";
const API_CREDENTIALS = ["Dada/P0A/api/resend", "Dada/P0A/api/amap", "Dada/P0A/admin/pepper"] as const;
@@ -15,7 +15,7 @@ export async function receiveApiCredentials(input: NodeJS.ReadableStream = proce
if (names.length !== expected.length || names.some((name, index) => name !== expected[index])) {
throw new Error("API credential channel contains an unexpected credential scope.");
}
if (expected.some((name) => typeof parsed[name] !== "string" || parsed[name] === "")) {
if (expected.some((name) => typeof parsed[name] !== "string")) {
throw new Error("API credential channel contains an invalid credential value.");
}
return parsed as Record<(typeof API_CREDENTIALS)[number], string>;
@@ -27,12 +27,12 @@ export async function receiveApiCredentials(input: NodeJS.ReadableStream = proce
}
export function initializeApiCredentialClients(credentials: Record<(typeof API_CREDENTIALS)[number], string>) {
const configured = API_CREDENTIALS.every((name) => credentials[name].length > 0);
try {
if (!configured) throw new Error("API credential client initialization failed.");
try {
const adminPepper = credentials["Dada/P0A/admin/pepper"];
if (!adminPepper) throw new Error("admin_pepper_not_configured");
return {
adminAllowlistPepper: Buffer.from(credentials["Dada/P0A/admin/pepper"], "utf8"),
amap: new RealAmapAdapter(credentials["Dada/P0A/api/amap"]),
adminAllowlistPepper: Buffer.from(adminPepper, "utf8"),
amap: credentials["Dada/P0A/api/amap"] ? new RealAmapAdapter(credentials["Dada/P0A/api/amap"]) : new MockAmapAdapter(),
};
} finally {
for (const name of API_CREDENTIALS) credentials[name] = "";