feat(pricing): 开发定价方案
This commit is contained in:
@@ -24,6 +24,7 @@ const environmentSchema = z.object({
|
||||
NODE_ENV: z
|
||||
.enum(['development', 'test', 'production'])
|
||||
.default('development'),
|
||||
PRICING_ALLOW_DRAFT_RATES: z.enum(['true', 'false', 'auto']).default('auto'),
|
||||
API_PORT: z.coerce.number().int().min(1).max(65_535).default(8200),
|
||||
API_PUBLIC_ORIGIN: z.url().default('http://localhost:8200'),
|
||||
WEB_ORIGIN: z.url().default('http://localhost:8100'),
|
||||
@@ -96,15 +97,26 @@ const environmentSchema = z.object({
|
||||
});
|
||||
|
||||
type Environment = z.infer<typeof environmentSchema>;
|
||||
export function draftPricingEnabled(
|
||||
nodeEnvironment: Environment['NODE_ENV'],
|
||||
setting: Environment['PRICING_ALLOW_DRAFT_RATES'],
|
||||
): boolean {
|
||||
return (
|
||||
nodeEnvironment !== 'production' &&
|
||||
(setting === 'true' ||
|
||||
(nodeEnvironment === 'development' && setting === 'auto'))
|
||||
);
|
||||
}
|
||||
export type AppConfig = Omit<
|
||||
Environment,
|
||||
'TRUSTED_PROXY_CIDRS' | 'SWAGGER_ENABLED'
|
||||
'TRUSTED_PROXY_CIDRS' | 'SWAGGER_ENABLED' | 'PRICING_ALLOW_DRAFT_RATES'
|
||||
> & {
|
||||
trustedProxyCidrs: string[];
|
||||
swaggerEnabled: boolean;
|
||||
objectStorageAccessKey: string;
|
||||
objectStorageSecretKey: string;
|
||||
objectStorageForcePathStyle: boolean;
|
||||
pricingAllowDraftRates: boolean;
|
||||
};
|
||||
|
||||
function validateEnvironment(
|
||||
@@ -140,6 +152,11 @@ function createAppConfig(environment: Environment): AppConfig {
|
||||
objectStorageSecretKey,
|
||||
objectStorageForcePathStyle:
|
||||
environment.OBJECT_STORAGE_FORCE_PATH_STYLE === 'true',
|
||||
// 草稿费率仅用于本地商品编辑联调,生产配置无法开启。
|
||||
pricingAllowDraftRates: draftPricingEnabled(
|
||||
environment.NODE_ENV,
|
||||
environment.PRICING_ALLOW_DRAFT_RATES,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user