API契约:收尾兼容响应并审计版本入口
This commit is contained in:
1 parent
929b3fd8a9
commit
6ff3499ca9
8 files changed
+317
-37
No files matched your search
+25
-25
@@ -3,8 +3,8 @@ import {
|
||||
LoginResponse, AccountDetail, AccountSummaryResponse, Order, PaginatedResponse,
|
||||
AdminStats, DashboardStats, Card, SystemSettings, ApiResponse, OrderAnalytics,
|
||||
Item, AIReplySettings, ShippingRule, ReplyRule, DefaultReply, AutomationAction, AutomationTriggerType,
|
||||
NotificationChannel, NotificationEventType, AccountTaskSettings, ChatSession, ChatMessage,
|
||||
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, KeywordTypedResponse, DefaultReplyResponse, AccountTaskSettingsResponse, AccountTaskRunResponseEnvelope, AdminStatsResponse, DashboardStatsResponse, OrderAnalyticsResponse, QRLoginGenerateResponse, ValidOrderResponse, ValidOrdersResponse
|
||||
NotificationChannel, NotificationEventType, AccountTaskSettings, ChatSession, ChatMessage, ItemListEnvelope, AutomationIssuesEnvelope,
|
||||
CookieSettingsResponse, CookieProfileResponse, ItemPublishResponse, ItemSyncResponse, OrderDTOResponse, OrderDetailResponse, OrderSingleRefreshResponse, OrderBatchResponse, OrderRefreshResponse, AutomationRuleResponse, AutomationRulePageResponse, AIReplySettingsResponse, AIModelsResponse, UserSettingResponse, CardBatchResponse, CardAppendResponse, CategoryRecommendationResponse, ItemPublishBatchPreviewResponse, ItemPublishBatchListResponse, BatchIDResponse, ItemPublishBatchResponse, BatchCancelResponse, MutationIDResponse, OperationResponse, NotificationChannelResponse, NotificationBinding, AccountBindingsResponse, CardListResponse, KeywordTypedResponse, DefaultReplyResponse, AccountTaskSettingsResponse, AccountTaskRunResponseEnvelope, AdminStatsResponse, DashboardStatsResponse, OrderAnalyticsResponse, QRLoginGenerateResponse, QRLoginStatusResponse, QRLoginVerificationResponse, ValidOrderResponse, ValidOrdersResponse
|
||||
} from '../types';
|
||||
import { formatLocalDate } from '../dateRange';
|
||||
|
||||
@@ -168,37 +168,37 @@ export const generateQRLogin = async (options?: RequestControlOptions): Promise<
|
||||
return post('/qr-login/generate', undefined, { ...options, timeoutMs: options?.timeoutMs ?? 130_000 });
|
||||
};
|
||||
|
||||
export const checkQRLoginStatus = async (sessionId: string, signal?: AbortSignal): Promise<any> => {
|
||||
export const checkQRLoginStatus = async (sessionId: string, signal?: AbortSignal): Promise<QRLoginStatusResponse> => {
|
||||
return get(`/qr-login/check/${sessionId}`, undefined, { signal, timeoutMs: 10_000 });
|
||||
};
|
||||
|
||||
export const completeQRVerification = async (
|
||||
sessionId: string,
|
||||
targetAccountId?: string,
|
||||
): Promise<{
|
||||
success: boolean;
|
||||
account_id?: string;
|
||||
scanned_account_id?: string;
|
||||
message?: string;
|
||||
}> => {
|
||||
): Promise<QRLoginVerificationResponse> => {
|
||||
return post(`/qr-login/complete-verification/${sessionId}`, {
|
||||
target_account_id: targetAccountId || '',
|
||||
});
|
||||
};
|
||||
|
||||
export const updateAccountStatus = async (id: string, enabled: boolean): Promise<any> => {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export const updateAccountStatus = async (id: string, enabled: boolean): Promise<OperationResponse> => {
|
||||
return put(`/cookies/${id}/status`, { enabled });
|
||||
};
|
||||
|
||||
export const deleteAccount = async (id: string): Promise<any> => {
|
||||
export const deleteAccount = async (id: string): Promise<OperationResponse> => {
|
||||
return del(`/cookies/${id}`);
|
||||
};
|
||||
|
||||
export const updateAccountRemark = async (id: string, remark: string): Promise<any> => {
|
||||
export const updateAccountRemark = async (id: string, remark: string): Promise<OperationResponse> => {
|
||||
return put(`/cookies/${id}/remark`, { remark });
|
||||
};
|
||||
|
||||
export const updateAccountAutoConfirm = async (id: string, autoConfirm: boolean): Promise<any> => {
|
||||
export const updateAccountAutoConfirm = async (id: string, autoConfirm: boolean): Promise<OperationResponse> => {
|
||||
return put(`/cookies/${id}/auto-confirm`, { auto_confirm: autoConfirm });
|
||||
};
|
||||
|
||||
@@ -206,7 +206,7 @@ export const updateAccountPauseDuration = async (id: string, pauseDuration: numb
|
||||
return put(`/cookies/${id}/pause-duration`, { pause_duration: pauseDuration });
|
||||
};
|
||||
|
||||
export const updateAccountCookie = async (id: string, value: string, loginMethod?: string): Promise<any> => {
|
||||
export const updateAccountCookie = async (id: string, value: string, loginMethod?: string): Promise<OperationResponse> => {
|
||||
return put(`/cookies/${id}`, { id, value, login_method: loginMethod });
|
||||
};
|
||||
|
||||
@@ -285,7 +285,7 @@ export const updateAccountLoginInfo = async (id: string, data: {
|
||||
login_password?: string;
|
||||
clear_password?: boolean;
|
||||
show_browser?: boolean;
|
||||
}): Promise<any> => {
|
||||
}): Promise<OperationResponse> => {
|
||||
return put(`/cookies/${id}/login-info`, data);
|
||||
};
|
||||
|
||||
@@ -350,7 +350,7 @@ export const deleteOrder = async (orderId: string): Promise<ApiResponse> => {
|
||||
return del(`/api/orders/${orderId}`);
|
||||
};
|
||||
|
||||
export const syncOrders = async (cookieId?: string, status?: string): Promise<any> => {
|
||||
export const syncOrders = async (cookieId?: string, status?: string): Promise<OrderRefreshResponse> => {
|
||||
const formData = new FormData();
|
||||
if (cookieId) formData.append('cookie_id', cookieId);
|
||||
if (status) formData.append('status', status);
|
||||
@@ -494,7 +494,7 @@ const normalizeBooleanFlag = (value: unknown): boolean =>
|
||||
value === true || value === 1 || value === '1';
|
||||
|
||||
export const getItems = async (cookieId?: string): Promise<Item[]> => {
|
||||
const res = await get<any>('/items', cookieId ? { cookie_id: cookieId } : undefined);
|
||||
const res = await get<Item[] | ItemListEnvelope>('/items', cookieId ? { cookie_id: cookieId } : undefined);
|
||||
const items = Array.isArray(res) ? res : (res.items || []);
|
||||
return items.map((item: any) => ({
|
||||
...item,
|
||||
@@ -509,11 +509,11 @@ export const syncItemsFromAccount = async (cookieId: string): Promise<ItemSyncRe
|
||||
return post('/items/get-all-from-account', { cookie_id: cookieId });
|
||||
}
|
||||
|
||||
export const deleteItem = async (cookieId: string, itemId: string): Promise<any> => {
|
||||
export const deleteItem = async (cookieId: string, itemId: string): Promise<OperationResponse> => {
|
||||
return del(`/items/${cookieId}/${itemId}`);
|
||||
}
|
||||
|
||||
export const createItem = async (cookieId: string, data: any): Promise<any> => {
|
||||
export const createItem = async (cookieId: string, data: Partial<Item>): Promise<OperationResponse> => {
|
||||
return post(`/items/${cookieId}`, data);
|
||||
}
|
||||
|
||||
@@ -617,7 +617,7 @@ export const retryFailedItemPublishBatch = async (batchId: string): Promise<Batc
|
||||
return post(`/items/publish-batches/${batchId}/retry-failed`, {});
|
||||
}
|
||||
|
||||
export const updateItem = async (cookieId: string, itemId: string, data: Partial<Item>): Promise<any> => {
|
||||
export const updateItem = async (cookieId: string, itemId: string, data: Partial<Item>): Promise<OperationResponse> => {
|
||||
return put(`/items/${cookieId}/${itemId}`, data);
|
||||
}
|
||||
|
||||
@@ -727,7 +727,7 @@ const orderAutomationActions = (triggerType: string, actions: AutomationAction[]
|
||||
];
|
||||
};
|
||||
|
||||
export const updateShippingRule = async (rule: Partial<ShippingRule>): Promise<any> => {
|
||||
export const updateShippingRule = async (rule: Partial<ShippingRule>): Promise<OperationResponse | MutationIDResponse> => {
|
||||
const triggerType = rule.trigger_type || 'order_paid';
|
||||
const triggerName: Record<string, string> = {
|
||||
order_paid: '付款后自动发货',
|
||||
@@ -783,7 +783,7 @@ export const updateShippingRule = async (rule: Partial<ShippingRule>): Promise<a
|
||||
return rule.id ? put(`/automation-rules/${rule.id}`, payload) : post('/automation-rules', payload);
|
||||
}
|
||||
|
||||
export const deleteShippingRule = async (id: string): Promise<any> => del(`/automation-rules/${id}`);
|
||||
export const deleteShippingRule = async (id: string): Promise<OperationResponse> => del(`/automation-rules/${id}`);
|
||||
|
||||
export interface AutomationRunIssue {
|
||||
id: number;
|
||||
@@ -808,17 +808,17 @@ export interface DeferredAutomationIssue {
|
||||
}
|
||||
|
||||
export const getAutomationIssues = async (): Promise<{ runs: AutomationRunIssue[]; pending_tasks: DeferredAutomationIssue[] }> => {
|
||||
const result = await get<any>('/automation-issues');
|
||||
const result = await get<AutomationIssuesEnvelope>('/automation-issues');
|
||||
return {
|
||||
runs: Array.isArray(result?.runs) ? result.runs : [],
|
||||
pending_tasks: Array.isArray(result?.pending_tasks) ? result.pending_tasks : [],
|
||||
};
|
||||
};
|
||||
|
||||
export const resolveAutomationRun = async (id: number, resolution: 'continue' | 'retry' | 'cancel'): Promise<any> =>
|
||||
export const resolveAutomationRun = async (id: number, resolution: 'continue' | 'retry' | 'cancel'): Promise<OperationResponse> =>
|
||||
post(`/automation-runs/${id}/resolve`, { resolution });
|
||||
|
||||
export const resolveDeferredAutomationTask = async (id: number, resolution: 'retry' | 'dismiss'): Promise<any> =>
|
||||
export const resolveDeferredAutomationTask = async (id: number, resolution: 'retry' | 'dismiss'): Promise<OperationResponse> =>
|
||||
post(`/automation-pending-tasks/${id}/resolve`, { resolution });
|
||||
|
||||
// Rules - 关键词回复规则 (使用关键词API)
|
||||
|
||||
@@ -1238,3 +1238,139 @@ export interface QRLoginGenerateResponse {
|
||||
/** 可选的提示文本。 */
|
||||
message?: string;
|
||||
}
|
||||
|
||||
/** 二维码登录状态响应。 */
|
||||
export interface QRLoginStatusResponse {
|
||||
/** 当前二维码会话状态。 */
|
||||
status: string;
|
||||
/** 扫码登录会话标识。 */
|
||||
session_id?: string;
|
||||
/** 平台账号标识。 */
|
||||
unb?: string;
|
||||
/** 持久化后的本地账号标识。 */
|
||||
account_id?: string;
|
||||
/** 是否新建了本地账号。 */
|
||||
is_new_account?: boolean;
|
||||
/** 状态提示文本。 */
|
||||
message?: string;
|
||||
/** 兼容上游可能扩展的非敏感状态字段。 */
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
/** 二维码验证完成响应。 */
|
||||
export interface QRLoginVerificationResponse {
|
||||
/** 验证结果是否成功。 */
|
||||
success: boolean;
|
||||
/** 平台账号标识。 */
|
||||
unb?: string;
|
||||
/** 持久化后的本地账号标识。 */
|
||||
account_id?: string;
|
||||
/** 是否新建了本地账号。 */
|
||||
is_new_account?: boolean;
|
||||
/** 扫码账号与目标账号不一致时的提示标识。 */
|
||||
scanned_account_id?: string;
|
||||
/** 验证结果提示文本。 */
|
||||
message?: string;
|
||||
}
|
||||
|
||||
/** 订单列表刷新逐项结果。 */
|
||||
export interface OrderRefreshResultResponse {
|
||||
/** 结果所属账号标识。 */
|
||||
cookie_id?: string;
|
||||
/** 当前处理阶段。 */
|
||||
stage?: string;
|
||||
/** 当前项是否处理成功。 */
|
||||
success: boolean;
|
||||
/** 结果说明。 */
|
||||
message?: string;
|
||||
/** 发现的新订单数量。 */
|
||||
discovered?: number;
|
||||
/** 更新的订单数量。 */
|
||||
updated?: number;
|
||||
/** 标记删除的订单数量。 */
|
||||
soft_deleted?: number;
|
||||
/** 订单平台标识。 */
|
||||
order_id?: string;
|
||||
/** 结果错误说明。 */
|
||||
error?: string;
|
||||
}
|
||||
|
||||
/** 订单列表刷新统计摘要。 */
|
||||
export interface OrderRefreshSummaryResponse {
|
||||
/** 发现的新订单数量。 */
|
||||
discovered: number;
|
||||
/** 订单列表更新数量。 */
|
||||
list_updated: number;
|
||||
/** 标记删除数量。 */
|
||||
soft_deleted: number;
|
||||
/** 需要补全详情的订单数量。 */
|
||||
detail_total: number;
|
||||
/** 本次处理订单总数。 */
|
||||
total: number;
|
||||
/** 状态发生变化数量。 */
|
||||
updated: number;
|
||||
/** 状态未变化数量。 */
|
||||
no_change: number;
|
||||
/** 刷新失败数量。 */
|
||||
failed: number;
|
||||
}
|
||||
|
||||
/** 订单列表刷新响应。 */
|
||||
export interface OrderRefreshResponse {
|
||||
/** 是否存在部分失败。 */
|
||||
partial_failure: boolean;
|
||||
/** 刷新结果说明。 */
|
||||
message: string;
|
||||
/** 刷新统计摘要。 */
|
||||
summary: OrderRefreshSummaryResponse;
|
||||
/** 逐项兼容结果。 */
|
||||
results: OrderRefreshResultResponse[];
|
||||
}
|
||||
|
||||
// ItemListEnvelope 是商品列表接口的兼容分页响应。
|
||||
export interface ItemListEnvelope {
|
||||
/** items 是兼容分页响应中的商品列表。 */
|
||||
items?: Item[];
|
||||
}
|
||||
|
||||
// AutomationIssuesEnvelope 是自动化异常接口的兼容响应。
|
||||
export interface AutomationIssuesEnvelope {
|
||||
/** runs 是待处理的自动化运行记录。 */
|
||||
runs?: Array<{
|
||||
/** 记录标识。 */
|
||||
id: number;
|
||||
/** 所属账号标识。 */
|
||||
cookie_id: string;
|
||||
/** 所属订单标识。 */
|
||||
order_id: string;
|
||||
/** 自动化触发类型。 */
|
||||
trigger_type: string;
|
||||
/** 外部错误说明。 */
|
||||
error_message: string;
|
||||
/** 异常类别。 */
|
||||
issue_kind: 'external_result_unknown' | 'invalid_snapshot' | 'rule_unavailable' | 'partial_failure' | 'execution_failed';
|
||||
/** 允许的处理动作。 */
|
||||
allowed_resolutions: Array<'continue' | 'retry' | 'cancel'>;
|
||||
/** 当前动作游标。 */
|
||||
action_cursor: number;
|
||||
/** 已发送数量。 */
|
||||
sent_count: number;
|
||||
/** 更新时间。 */
|
||||
updated_at: string;
|
||||
}>;
|
||||
/** pending_tasks 是延迟自动化任务列表。 */
|
||||
pending_tasks?: Array<{
|
||||
/** 任务标识。 */
|
||||
id: number;
|
||||
/** 所属账号标识。 */
|
||||
cookie_id: string;
|
||||
/** 自动化触发类型。 */
|
||||
trigger_type: string;
|
||||
/** 错误说明。 */
|
||||
error_message: string;
|
||||
/** 当前重试次数。 */
|
||||
attempt_count: number;
|
||||
/** 更新时间。 */
|
||||
updated_at: string;
|
||||
}>;
|
||||
}
|
||||
Reference in new issue
Block a user