API契约:收口设置卡券通知与批量响应

This commit is contained in:
Christ committed 2026-08-14 15:34:14 +08:00
1 parent 0ca52e43ad
commit fe6fc3adb9
12 files changed
+879 -143

No files matched your search

+49 -49
View File
@@ -4,7 +4,7 @@ import {
AdminStats, DashboardStats, Card, SystemSettings, ApiResponse, OrderAnalytics,
Item, AIReplySettings, ShippingRule, ReplyRule, DefaultReply, AutomationAction, AutomationTriggerType,
NotificationChannel, NotificationEventType, AccountTaskSettings, AccountTaskSummary, ChatSession, ChatMessage,
CookieSettingsResponse, CookieProfileResponse, ItemPublishResponse, ItemSyncResponse, OrderDTOResponse, OrderDetailResponse, OrderSingleRefreshResponse, OrderBatchResponse, AutomationRuleResponse, AutomationRulePageResponse
CookieSettingsResponse, CookieProfileResponse, ItemPublishResponse, ItemSyncResponse, OrderDTOResponse, OrderDetailResponse, OrderSingleRefreshResponse, OrderBatchResponse, AutomationRuleResponse, AutomationRulePageResponse, AIReplySettingsResponse, AIModelsResponse, UserSettingResponse, CardBatchResponse, CardAppendResponse, CategoryRecommendationResponse, ItemPublishBatchPreviewResponse, ItemPublishBatchListResponse, BatchIDResponse, ItemPublishBatchResponse, BatchCancelResponse, MutationIDResponse, OperationResponse, NotificationChannelResponse, NotificationBinding, AccountBindingsResponse, CardListResponse
} from '../types';
import { formatLocalDate } from '../dateRange';
@@ -449,43 +449,43 @@ const cardPayload = (data: Partial<Card>): Record<string, unknown> => ({
});
export const getCards = async (): Promise<Card[]> => {
const res = await get<any>('/cards');
const res = await get<Card[] | CardListResponse>('/cards');
const cards = Array.isArray(res) ? res : (res.cards || []);
return cards.map(normalizeCard);
};
export const createCard = async (data: Partial<Card>): Promise<{ id: number; message: string }> => {
export const createCard = async (data: Partial<Card>): Promise<MutationIDResponse> => {
return post('/cards', cardPayload(data));
};
export const updateCard = async (cardId: string | number, data: Partial<Card>): Promise<ApiResponse> => {
export const updateCard = async (cardId: string | number, data: Partial<Card>): Promise<OperationResponse> => {
return put(`/cards/${cardId}`, cardPayload(data));
};
export const deleteCard = async (cardId: string | number): Promise<ApiResponse> => {
export const deleteCard = async (cardId: string | number): Promise<OperationResponse> => {
return del(`/cards/${cardId}`);
};
export const getCardDetails = async (cardId: string | number): Promise<any> => {
const card = await get<any>(`/cards/${cardId}/details`);
export const getCardDetails = async (cardId: string | number): Promise<Card> => {
const card = await get<Card>(`/cards/${cardId}/details`);
return normalizeCard(card);
};
// 批量创建卡密组(上传表格)
export const batchCreateCards = async (file: File): Promise<{
success: boolean;
total: number;
created: number;
failed: number;
rows: { row_no: number; success: boolean; id?: number; name: string; type?: string; error?: string }[];
}> => {
export const batchCreateCards = async (file: File): Promise<CardBatchResponse> => {
// 批量创建接口返回总行数、成功数、失败数和逐行结果。
// CardBatchResponse 保留旧字段名称,调用方无需转换统计字段。
// rows 中的 id 只在创建成功时返回。
// rows 中的 error 只在对应行失败时返回。
// 表单上传方式和接口路径保持不变。
// 此处只收紧 TypeScript 响应契约。
const body = new FormData();
body.append('file', file);
return postForm('/cards/batch', body);
};
// 往 data 类型卡密组批量追加卡密号
export const appendCardData = async (cardId: string | number, content: string): Promise<{ success: boolean; added: number }> => {
export const appendCardData = async (cardId: string | number, content: string): Promise<CardAppendResponse> => {
return post(`/cards/${cardId}/append-data`, { content });
};
@@ -556,15 +556,15 @@ export interface PublishLocation {
province: string;
}
export const recommendPublishCategory = async (cookieId: string, keyword: string): Promise<{
success: boolean;
category: {
cat_id: string;
cat_name: string;
channel_cat_id: string;
tb_cat_id?: string;
};
}> => {
export const recommendPublishCategory = async (cookieId: string, keyword: string): Promise<CategoryRecommendationResponse> => {
// 类目推荐成功响应使用共享 CategoryRecommendationResponse。
// category 字段保留平台类目 ID、名称和频道类目 ID。
// tb_cat_id 继续保持可选,兼容电子资料类目。
// 请求仍携带账号 ID 和关键词。
// 失败响应由共享 HTTP 错误结构处理。
// 该类型收口不改变凭证刷新和错误处理。
// 前端批量发布流程可直接复用 category。
// 旧路径继续由现有 Vite 代理转发。
return post('/items/publish-categories/recommend', { cookie_id: cookieId, keyword });
};
@@ -579,7 +579,7 @@ export const previewItemPublishBatch = async (form: {
tbCatId?: string;
};
location?: PublishLocation;
}): Promise<any> => {
}): Promise<ItemPublishBatchPreviewResponse> => {
const body = new FormData();
body.set('file', form.file);
if (form.imagesZip) body.set('images_zip', form.imagesZip);
@@ -592,28 +592,28 @@ export const previewItemPublishBatch = async (form: {
return postForm('/items/publish-batches/preview', body);
}
export const startItemPublishBatch = async (previewId: string): Promise<any> => {
export const startItemPublishBatch = async (previewId: string): Promise<BatchIDResponse> => {
return post('/items/publish-batches', { preview_id: previewId });
}
export const getItemPublishBatch = async (batchId: string): Promise<any> => {
export const getItemPublishBatch = async (batchId: string): Promise<ItemPublishBatchResponse> => {
return get(`/items/publish-batches/${batchId}`);
}
export const getItemPublishBatches = async (limit = 20): Promise<any[]> => {
const res = await get<any>('/items/publish-batches', { limit });
export const getItemPublishBatches = async (limit = 20): Promise<ItemPublishBatchResponse[]> => {
const res = await get<ItemPublishBatchListResponse>('/items/publish-batches', { limit });
return Array.isArray(res) ? res : (res.batches || []);
}
export const deleteItemPublishBatch = async (batchId: string): Promise<any> => {
export const deleteItemPublishBatch = async (batchId: string): Promise<OperationResponse> => {
return del(`/items/publish-batches/${batchId}`);
}
export const cancelItemPublishBatch = async (batchId: string): Promise<any> => {
export const cancelItemPublishBatch = async (batchId: string): Promise<BatchCancelResponse> => {
return post(`/items/publish-batches/${batchId}/cancel`, {});
}
export const retryFailedItemPublishBatch = async (batchId: string): Promise<any> => {
export const retryFailedItemPublishBatch = async (batchId: string): Promise<BatchIDResponse> => {
return post(`/items/publish-batches/${batchId}/retry-failed`, {});
}
@@ -884,18 +884,18 @@ export const getSystemSettings = async (): Promise<SystemSettings> => {
return normalizeSettings(res.data || res); // handle {success:true, data: {...}} wrapper if exists
};
export const updateSystemSettings = async (settings: Partial<SystemSettings>): Promise<ApiResponse> => {
export const updateSystemSettings = async (settings: Partial<SystemSettings>): Promise<OperationResponse> => {
const payload = Object.fromEntries(
Object.entries(settings).filter(([, value]) => value !== undefined && value !== null),
);
return put('/system-settings', payload);
};
export const getAccountAISettings = async (cookieId: string, options?: RequestControlOptions): Promise<AIReplySettings> => {
export const getAccountAISettings = async (cookieId: string, options?: RequestControlOptions): Promise<AIReplySettingsResponse> => {
return get(`/ai-reply-settings/${cookieId}`, undefined, options);
}
export const updateAccountAISettings = async (cookieId: string, settings: Partial<AIReplySettings>): Promise<ApiResponse> => {
export const updateAccountAISettings = async (cookieId: string, settings: Partial<AIReplySettings>): Promise<OperationResponse> => {
const payload = {
ai_enabled: settings.ai_enabled ?? false,
max_discount_percent: settings.max_discount_percent ?? 10,
@@ -907,7 +907,7 @@ export const updateAccountAISettings = async (cookieId: string, settings: Partia
}
export const fetchAIModels = async (baseUrl: string, apiKey: string = ''): Promise<string[]> => {
const result = await post<{ models?: string[] }>('/ai-models', {
const result = await post<AIModelsResponse>('/ai-models', {
base_url: baseUrl,
api_key: apiKey,
});
@@ -933,7 +933,7 @@ const stringifyNotificationEventTypes = (events?: NotificationEventType[]): stri
};
export const getNotificationChannels = async (options?: RequestControlOptions): Promise<{ success: boolean; data?: NotificationChannel[] }> => {
const result = await get<any[]>('/notification-channels', undefined, options);
const result = await get<NotificationChannelResponse[]>('/notification-channels', undefined, options);
const channels = (result || []).map((item: any) => {
let parsedConfig;
try {
@@ -955,7 +955,7 @@ export const getNotificationChannels = async (options?: RequestControlOptions):
return { success: true, data: channels };
}
export const createNotificationChannel = async (data: { name: string; type: string; config: Record<string, unknown>; event_types?: NotificationEventType[]; enabled?: boolean }): Promise<ApiResponse> => {
export const createNotificationChannel = async (data: { name: string; type: string; config: Record<string, unknown>; event_types?: NotificationEventType[]; enabled?: boolean }): Promise<MutationIDResponse> => {
return post('/notification-channels', {
...data,
config: JSON.stringify(data.config),
@@ -963,7 +963,7 @@ export const createNotificationChannel = async (data: { name: string; type: stri
});
}
export const updateNotificationChannel = async (channelId: string, data: { name?: string; type?: string; config?: Record<string, unknown>; event_types?: NotificationEventType[]; enabled?: boolean }): Promise<ApiResponse> => {
export const updateNotificationChannel = async (channelId: string, data: { name?: string; type?: string; config?: Record<string, unknown>; event_types?: NotificationEventType[]; enabled?: boolean }): Promise<OperationResponse> => {
const payload: Record<string, unknown> = { ...data };
if ('config' in data) {
payload.config = JSON.stringify(data.config);
@@ -974,14 +974,14 @@ export const updateNotificationChannel = async (channelId: string, data: { name?
return put(`/notification-channels/${channelId}`, payload);
}
export const deleteNotificationChannel = async (channelId: string): Promise<ApiResponse> => {
export const deleteNotificationChannel = async (channelId: string): Promise<OperationResponse> => {
return del(`/notification-channels/${channelId}`);
}
// Message Notifications
export const getMessageNotifications = async (): Promise<{ success: boolean; data?: any[] }> => {
const result = await get<Record<string, any[]>>('/message-notifications');
const notifications = [];
export const getMessageNotifications = async (): Promise<{ success: boolean; data?: NotificationBinding[] }> => {
const result = await get<Record<string, NotificationBinding[]>>('/message-notifications');
const notifications: NotificationBinding[] = [];
for (const [cookieId, channelList] of Object.entries(result || {})) {
if (Array.isArray(channelList)) {
for (const item of channelList) {
@@ -997,30 +997,30 @@ export const getMessageNotifications = async (): Promise<{ success: boolean; dat
return { success: true, data: notifications };
}
export const setMessageNotification = async (cookieId: string, channelId: number, enabled: boolean): Promise<ApiResponse> => {
export const setMessageNotification = async (cookieId: string, channelId: number, enabled: boolean): Promise<OperationResponse> => {
return post(`/message-notifications/${cookieId}`, { channel_id: channelId, enabled });
}
export const deleteMessageNotification = async (notificationId: string): Promise<ApiResponse> => {
export const deleteMessageNotification = async (notificationId: string): Promise<OperationResponse> => {
return del(`/message-notifications/${notificationId}`);
}
export const deleteAccountNotifications = async (cookieId: string): Promise<ApiResponse> => {
export const deleteAccountNotifications = async (cookieId: string): Promise<OperationResponse> => {
return del(`/message-notifications/account/${cookieId}`);
}
// 账号 ↔ 渠道 绑定(覆盖式)
export const getAccountBindings = async (cookieId: string, options?: RequestControlOptions): Promise<number[]> => {
const result = await get<{ cookie_id: string; channel_ids: number[] }>(`/message-notifications/${cookieId}`, undefined, options);
const result = await get<AccountBindingsResponse>(`/message-notifications/${cookieId}`, undefined, options);
return result?.channel_ids || [];
}
export const setAccountBindings = async (cookieId: string, channelIds: number[]): Promise<ApiResponse> => {
export const setAccountBindings = async (cookieId: string, channelIds: number[]): Promise<OperationResponse> => {
return post(`/message-notifications/${cookieId}`, { channel_ids: channelIds });
}
// 测试发送
export const testNotificationChannel = async (channelId: string): Promise<ApiResponse> => {
export const testNotificationChannel = async (channelId: string): Promise<OperationResponse> => {
return post(`/notification-channels/${channelId}/test`, {});
}
+271
View File
@@ -695,3 +695,274 @@ export interface OrderBatchResult {
/** 允许后端保留尚未结构化的扩展字段。 */
[key: string]: unknown;
}
/** 账号 AI 回复设置接口的具名响应。 */
export interface AIReplySettingsResponse {
/** 账号稳定标识;默认配置响应可能省略。 */
cookie_id?: string;
/** AI 回复是否启用。 */
ai_enabled: boolean;
/** 最大折扣比例。 */
max_discount_percent: number;
/** 最大折扣金额。 */
max_discount_amount: number;
/** 最大砍价轮次。 */
max_bargain_rounds: number;
/** 自定义提示词。 */
custom_prompts: string;
}
/** AI 模型发现接口的具名响应。 */
export interface AIModelsResponse {
/** 远端可用模型名称。 */
models: string[];
}
/** 单个用户设置查询接口的具名响应。 */
export interface UserSettingResponse {
/** 设置值文本。 */
value: string;
}
/** 卡券批量创建接口的逐行结果。 */
export interface CardBatchResult {
/** 表格中的原始行号。 */
row_no: number;
/** 当前行是否创建成功。 */
success: boolean;
/** 新建卡券组主键。 */
id?: number;
/** 卡券组名称。 */
name: string;
/** 卡券类型。 */
type?: string;
/** 当前行失败原因。 */
error?: string;
}
/** 卡券批量创建接口的具名响应。 */
export interface CardBatchResponse {
/** 批量处理流程是否完成。 */
success: boolean;
/** 解析出的总行数。 */
total: number;
/** 创建成功行数。 */
created: number;
/** 创建失败行数。 */
failed: number;
/** 逐行处理结果。 */
rows: CardBatchResult[];
}
/** 卡券追加数据接口的具名响应。 */
export interface CardAppendResponse {
/** 追加操作是否完成。 */
success: boolean;
/** 实际追加数量。 */
added: number;
}
/** 通知绑定列表中的单条记录。 */
export interface NotificationBinding {
/** 账号稳定标识,列表归一化后补充。 */
cookie_id?: string;
/** 绑定记录主键。 */
id?: number;
/** 通知渠道主键。 */
channel_id: number;
/** 通知渠道名称。 */
channel_name: string;
/** 绑定是否启用。 */
enabled: boolean;
}
/** 账号通知渠道绑定查询响应。 */
export interface AccountBindingsResponse {
/** 账号稳定标识。 */
cookie_id: string;
/** 已绑定通知渠道主键列表。 */
channel_ids: number[];
}
/** 商品类目推荐接口的具名响应。 */
export interface CategoryRecommendationResponse {
/** 类目推荐是否成功。 */
success: boolean;
/** 推荐商品类目。 */
category: {
/** 平台类目主键。 */
cat_id: string;
/** 平台类目名称。 */
cat_name: string;
/** 频道类目主键。 */
channel_cat_id: string;
/** 淘宝类目主键。 */
tb_cat_id?: string;
};
}
/** 商品批量发布预检逐行结果。 */
export interface ItemPublishBatchPreviewRow {
/** 上传表格行号。 */
row_no: number;
/** 当前行是否通过预检。 */
valid: boolean;
/** 当前行校验错误列表。 */
errors?: string[];
/** 发布目标账号标识。 */
cookie_id: string;
/** 商品标题。 */
title: string;
/** 商品价格文本。 */
price: string;
/** 商品库存数量。 */
quantity: number;
/** 商品图片引用列表。 */
images: string[];
/** 商品发布类目。 */
category: CategoryRecommendationResponse['category'];
/** 发布后自动化配置。 */
automation?: Record<string, unknown>;
}
/** 商品批量发布预检响应。 */
export interface ItemPublishBatchPreviewResponse {
/** 预检流程是否完成。 */
success: boolean;
/** 后续启动发布使用的预检批次标识。 */
preview_id: string;
/** 预检总行数。 */
total: number;
/** 通过预检行数。 */
valid: number;
/** 未通过预检行数。 */
invalid: number;
/** 逐行预检结果。 */
rows: ItemPublishBatchPreviewRow[];
}
/** 商品批量发布任务启动或重试响应。 */
export interface BatchIDResponse {
/** 任务操作是否完成。 */
success: boolean;
/** 商品批量任务标识。 */
batch_id: string;
}
/** 商品批量发布任务取消响应。 */
export interface BatchCancelResponse {
/** 取消请求是否完成。 */
success: boolean;
/** 取消后的任务状态。 */
status: string;
}
/** 商品批量发布任务逐行详情。 */
export interface ItemPublishBatchRowResponse {
/** 明细行主键。 */
id: number;
/** 导入表格行号。 */
row_no: number;
/** 发布目标账号标识。 */
cookie_id: string;
/** 商品标题。 */
title: string;
/** 商品价格文本。 */
price: string;
/** 商品库存数量。 */
quantity: number;
/** 商品图片引用列表。 */
images: string[];
/** 商品发布类目。 */
category: CategoryRecommendationResponse['category'];
/** 发布后自动化配置。 */
automation: Record<string, unknown>;
/** 明细行状态。 */
status: string;
/** 发布成功后的平台商品标识。 */
item_id: string;
/** 发布成功后的商品地址。 */
item_url: string;
/** 明细行失败原因。 */
error_message: string;
/** 明细行失败类型。 */
failure_kind: string;
}
/** 商品批量发布任务详情响应。 */
export interface ItemPublishBatchResponse {
/** 批量任务标识。 */
id: string;
/** 批量任务状态。 */
status: string;
/** 原始上传文件名。 */
filename: string;
/** 明细行总数。 */
total: number;
/** 成功发布数量。 */
success: number;
/** 失败数量。 */
failed: number;
/** 待处理数量。 */
pending: number;
/** 运行中数量。 */
running: number;
/** 可重试数量。 */
retryable: number;
/** 明细行结果。 */
rows: ItemPublishBatchRowResponse[];
/** 批次统一发货地。 */
location?: Record<string, unknown>;
/** 创建时间。 */
created_at: string;
/** 更新时间。 */
updated_at: string;
}
/** 商品批量发布任务列表响应。 */
export interface ItemPublishBatchListResponse {
/** 当前用户的批量任务列表。 */
batches: ItemPublishBatchResponse[];
}
/** 简单资源创建接口的数值主键响应。 */
export interface MutationIDResponse {
/** 资源创建是否完成。 */
success: boolean;
/** 新资源数值主键。 */
id: number;
}
/** 简单变更接口的统一成功响应。 */
export interface OperationResponse {
/** 操作是否完成。 */
success: boolean;
/** 可选的操作说明。 */
message?: string;
/** 操作完成后是否需要重新登录。 */
requires_relogin?: boolean;
}
/** 通知渠道接口返回的原始具名 DTO。 */
export interface NotificationChannelResponse {
/** 通知渠道主键。 */
id: number;
/** 通知渠道名称。 */
name: string;
/** 通知渠道类型。 */
type: string;
/** 通知渠道配置 JSON。 */
config: string;
/** 订阅事件类型 JSON 或兼容文本。 */
event_types?: string;
/** 通知渠道是否启用。 */
enabled: boolean;
/** 所属用户主键。 */
user_id?: number;
}
/** 卡券列表接口的兼容包装响应。 */
export interface CardListResponse {
/** 当前用户卡券列表。 */
cards: Card[];
}