You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.6 KiB
74 lines
2.6 KiB
import { z } from "zod";
|
|
|
|
/** 地点二级字段(对象本身必填时可为空对象) */
|
|
const msLocationDetailsSchema = z
|
|
.object({
|
|
company_name: z.string().max(128).optional(),
|
|
suite: z.string().max(64).optional(),
|
|
contact_first: z.string().max(64).optional(),
|
|
contact_last: z.string().max(64).optional(),
|
|
contact_email: z.string().max(128).optional(),
|
|
contact_phone: z.string().max(64).optional(),
|
|
reference: z.string().max(128).optional(),
|
|
notes: z.string().max(1000).optional(),
|
|
opens_at: z.string().max(32).optional(),
|
|
closes_at: z.string().max(32).optional(),
|
|
})
|
|
.strict();
|
|
|
|
/** 与 QuoteRequestBody.mothership_details 同构(禁止任意键) */
|
|
const msCheckoutMothershipDetailsSchema = z
|
|
.object({
|
|
pickup: msLocationDetailsSchema.default({}),
|
|
delivery: msLocationDetailsSchema.default({}),
|
|
request_delivery_appointment: z.boolean().optional(),
|
|
fba_number: z.string().max(128).optional(),
|
|
fba_po_number: z.string().max(128).optional(),
|
|
cargo: z
|
|
.array(
|
|
z
|
|
.object({
|
|
piece_count_type: z.string().max(32).optional(),
|
|
piece_count_qty: z.number().min(0).max(999999).optional(),
|
|
description: z.string().max(500).optional(),
|
|
nmfc: z.string().max(64).optional(),
|
|
hazmat: z.boolean().optional(),
|
|
alcohol: z.boolean().optional(),
|
|
tobacco: z.boolean().optional(),
|
|
})
|
|
.strict(),
|
|
)
|
|
.max(20)
|
|
.optional(),
|
|
})
|
|
.strict()
|
|
.optional();
|
|
|
|
export const msCheckoutSchema = z
|
|
.object({
|
|
customer_id: z.string().min(1, "请填写客户标识"),
|
|
quote_id: z.string().min(1, "请填写报价单号").max(64),
|
|
preferred_carrier: z
|
|
.string()
|
|
.min(1, "请选择承运商")
|
|
.max(128, "承运商名称过长"),
|
|
coverage: z.enum(["basic", "freight_protect"], {
|
|
errorMap: () => ({ message: "保障方案无效" }),
|
|
}),
|
|
cargo_value_usd: z.number().finite().positive().max(1_000_000).optional(),
|
|
mothership_details: msCheckoutMothershipDetailsSchema,
|
|
pickup_accessorials: z.array(z.string().min(1).max(64)).max(20).optional(),
|
|
delivery_accessorials: z.array(z.string().min(1).max(64)).max(20).optional(),
|
|
})
|
|
.superRefine((val, ctx) => {
|
|
if (val.coverage === "freight_protect") {
|
|
if (val.cargo_value_usd == null || val.cargo_value_usd <= 0) {
|
|
ctx.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
message: "选择 FreightProtect 时请填写大于 0 的货物价值(美元)",
|
|
path: ["cargo_value_usd"],
|
|
});
|
|
}
|
|
}
|
|
});
|