feat(api): 开发平台、门店相关代码
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const uuidSchema = z.uuid();
|
||||
const currencyCodeSchema = z
|
||||
.string()
|
||||
.regex(/^[A-Z]{3}$/, '必须是 ISO 4217 大写币种代码');
|
||||
|
||||
/** 创建门店时唯一允许提交明文 API Key 的请求契约。 */
|
||||
export const createStoreRequestSchema = z
|
||||
.object({
|
||||
platform_id: uuidSchema,
|
||||
name: z.string().trim().min(1).max(120),
|
||||
client_id: z.string().trim().min(1).max(120),
|
||||
api_key: z.string().min(1).max(8_192),
|
||||
currency_code: currencyCodeSchema,
|
||||
is_default: z.boolean().default(false),
|
||||
note: z.string().trim().max(2_000).nullable().optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
/** 修改门店不允许变更平台或平台账户,避免授权连接身份被悄然替换。 */
|
||||
export const updateStoreRequestSchema = z
|
||||
.object({
|
||||
name: z.string().trim().min(1).max(120).optional(),
|
||||
currency_code: currencyCodeSchema.optional(),
|
||||
note: z.string().trim().max(2_000).nullable().optional(),
|
||||
api_key: z.string().min(1).max(8_192).optional(),
|
||||
})
|
||||
.strict()
|
||||
.refine((value) => Object.keys(value).length > 0, {
|
||||
message: '至少需要提交一个可修改字段',
|
||||
});
|
||||
|
||||
export const listStoresQuerySchema = z
|
||||
.object({
|
||||
platform_id: uuidSchema,
|
||||
cursor: z.string().min(1).optional(),
|
||||
limit: z.coerce.number().int().min(1).max(100).default(20),
|
||||
})
|
||||
.strict();
|
||||
|
||||
export type CreateStoreRequest = z.infer<typeof createStoreRequestSchema>;
|
||||
export type UpdateStoreRequest = z.infer<typeof updateStoreRequestSchema>;
|
||||
export type ListStoresQuery = z.infer<typeof listStoresQuerySchema>;
|
||||
|
||||
export type Store = {
|
||||
id: string;
|
||||
platform_id: string;
|
||||
name: string;
|
||||
platform_client_id: string;
|
||||
currency_code: string;
|
||||
is_default: boolean;
|
||||
note: string | null;
|
||||
status: string;
|
||||
credential_status: string;
|
||||
credential_checked_at: string | null;
|
||||
last_error: { code: string; message: string; at: string } | null;
|
||||
api_key_expires_at: string | null;
|
||||
product_limit: number | null;
|
||||
product_limit_checked_at: string | null;
|
||||
warehouse_count: number;
|
||||
warehouses_synced_at: string | null;
|
||||
cookie_status: null;
|
||||
watermark_template: { id: string; name: string } | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
revision: number;
|
||||
};
|
||||
|
||||
export type Operation = {
|
||||
id: string;
|
||||
kind: string;
|
||||
status: string;
|
||||
created_at: string;
|
||||
completed_at: string | null;
|
||||
error: { code: string; message: string } | null;
|
||||
};
|
||||
Reference in New Issue
Block a user