Your Name 478562c312
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
feat: migrate product planning workspace
2026-03-26 16:38:48 +08:00

60 lines
2.1 KiB
TypeScript

export const PRODUCT_PLANNING_API_CONFIG_KEY = "product_planning_api_config";
export type ProductPlanningApiConfig = {
oneboundBaseUrl: string;
taobaoApiKey: string;
taobaoApiSecret: string;
qaApiUrl: string;
qaToken: string;
saleApiUrl: string;
saleToken: string;
};
const DEFAULT_ONEBOUND_BASE_URL = "https://api-gw.onebound.cn";
const DEFAULT_QA_API_URL = "http://119.91.237.2:5432/taobao_social_feed_aggregate";
const DEFAULT_SALE_API_URL = "http://119.91.237.2:5432/taobao_item_month_sale";
function normalizeUrl(value: unknown, fallback: string) {
const normalized = String(value || "").trim().replace(/\/+$/, "");
const normalizedFallback = String(fallback || "").trim().replace(/\/+$/, "");
return normalized || normalizedFallback;
}
function normalizeSecret(value: unknown, fallback = "") {
const normalized = String(value || "").trim();
const normalizedFallback = String(fallback || "").trim();
return normalized || normalizedFallback;
}
export function defaultProductPlanningApiConfig(): ProductPlanningApiConfig {
return {
oneboundBaseUrl: DEFAULT_ONEBOUND_BASE_URL,
taobaoApiKey: "",
taobaoApiSecret: "",
qaApiUrl: DEFAULT_QA_API_URL,
qaToken: "",
saleApiUrl: DEFAULT_SALE_API_URL,
saleToken: "",
};
}
export function normalizeProductPlanningApiConfig(
value: unknown,
fallback?: Partial<ProductPlanningApiConfig>
): ProductPlanningApiConfig {
const raw =
value && typeof value === "object" && !Array.isArray(value)
? (value as Record<string, unknown>)
: {};
return {
oneboundBaseUrl: normalizeUrl(raw.oneboundBaseUrl, fallback?.oneboundBaseUrl || DEFAULT_ONEBOUND_BASE_URL),
taobaoApiKey: normalizeSecret(raw.taobaoApiKey, fallback?.taobaoApiKey || ""),
taobaoApiSecret: normalizeSecret(raw.taobaoApiSecret, fallback?.taobaoApiSecret || ""),
qaApiUrl: normalizeUrl(raw.qaApiUrl, fallback?.qaApiUrl || DEFAULT_QA_API_URL),
qaToken: normalizeSecret(raw.qaToken, fallback?.qaToken || ""),
saleApiUrl: normalizeUrl(raw.saleApiUrl, fallback?.saleApiUrl || DEFAULT_SALE_API_URL),
saleToken: normalizeSecret(raw.saleToken, fallback?.saleToken || ""),
};
}