API版本化:迁移密码与剩余公共入口
This commit is contained in:
1 parent
caecc09c79
commit
8d103b1cc0
13 files changed
+237
-35
No files matched your search
@@ -7,7 +7,7 @@ import {
|
||||
checkQRLoginStatus, completeQRVerification, generateQRLogin,
|
||||
createNotificationChannel, getAllAISettings, getAccountAISettings, updateAccountAISettings, fetchAIModels,
|
||||
getAccountDetails, getAccountRuntimeStatuses, updateAccountStatus,
|
||||
getAutomationIssues,
|
||||
getAutomationIssues, changePassword, createItem, deleteAccount, deleteOrder, deleteShippingRule, updateLoginCredentials,
|
||||
getItems, getItemDetail, syncItemsFromAccount,
|
||||
getItemPublishBatches, getItemPublishBatch, startItemPublishBatch,
|
||||
getNotificationChannels, getMessageNotifications, getAccountBindings,
|
||||
@@ -101,9 +101,9 @@ test('automation issue APIs expose and resolve quarantined work', async () => {
|
||||
await expect(getAutomationIssues()).resolves.toEqual({ runs: [{ id: 1 }], pending_tasks: [{ id: 2 }] });
|
||||
await resolveAutomationRun(1, 'continue');
|
||||
await resolveDeferredAutomationTask(2, 'retry');
|
||||
expect(fetchMock.mock.calls[1][0]).toBe('/automation-runs/1/resolve');
|
||||
expect(fetchMock.mock.calls[1][0]).toBe('/api/v1/automation-runs/1/resolve');
|
||||
expect(JSON.parse(fetchMock.mock.calls[1][1].body)).toEqual({ resolution: 'continue' });
|
||||
expect(fetchMock.mock.calls[2][0]).toBe('/automation-pending-tasks/2/resolve');
|
||||
expect(fetchMock.mock.calls[2][0]).toBe('/api/v1/automation-pending-tasks/2/resolve');
|
||||
});
|
||||
|
||||
test('order multipart requests use the shared authenticated form request path', async () => {
|
||||
@@ -175,7 +175,7 @@ test('getShippingRulesPage sends filters and preserves pagination metadata', asy
|
||||
});
|
||||
expect(result.data[0]).toMatchObject({ id: '7', name: '付款规则', enabled: false });
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
'/automation-rules?page=2&page_size=20&cookie_id=acc1&trigger_type=order_paid&enabled=false&search=%E5%95%86%E5%93%81',
|
||||
'/api/v1/automation-rules?page=2&page_size=20&cookie_id=acc1&trigger_type=order_paid&enabled=false&search=%E5%95%86%E5%93%81',
|
||||
expect.objectContaining({ method: 'GET', credentials: 'include' }),
|
||||
);
|
||||
});
|
||||
@@ -426,7 +426,7 @@ test('password login service uses upstream-compatible routes', async () => {
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await passwordLogin({ account_id: 'acc1', account: 'u', password: 'p' });
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(1, '/password-login', expect.objectContaining({
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(1, '/api/v1/password-login', expect.objectContaining({
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
}));
|
||||
@@ -438,10 +438,10 @@ test('password login service uses upstream-compatible routes', async () => {
|
||||
|
||||
const status = await checkPasswordLoginStatus('sid');
|
||||
expect(status.status).toBe('success');
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(2, '/password-login/check/sid', expect.objectContaining({ method: 'GET' }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/password-login/check/sid', expect.objectContaining({ method: 'GET' }));
|
||||
|
||||
await cancelPasswordLogin('sid');
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(3, '/password-login/cancel/sid', expect.objectContaining({ method: 'DELETE' }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(3, '/api/v1/password-login/cancel/sid', expect.objectContaining({ method: 'DELETE' }));
|
||||
});
|
||||
|
||||
test('getShippingRules exposes buyer reviewed gift rules as automation rules', async () => {
|
||||
@@ -617,7 +617,7 @@ test('updateShippingRule posts buyer reviewed gift payload to automation-rules',
|
||||
}],
|
||||
});
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith('/automation-rules', expect.objectContaining({
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/v1/automation-rules', expect.objectContaining({
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
}));
|
||||
@@ -1122,3 +1122,68 @@ const runVersionedQRLoginAPITest = async () => {
|
||||
};
|
||||
|
||||
test('QR login generation and polling use versioned routes', runVersionedQRLoginAPITest);
|
||||
|
||||
// 密码登录、会话凭证、账号删除、自动化以及剩余订单商品调用使用版本化入口。
|
||||
const runVersionedRemainingAPITest = async () => {
|
||||
// fetchMock 是剩余公共 API 请求的测试替身。
|
||||
const fetchMock = vi.fn()
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true }))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true }))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true }))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true, session_id: 'sid' }))
|
||||
.mockResolvedValueOnce(jsonResponse({ status: 'failed' }))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true }))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true }))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true }))
|
||||
.mockResolvedValueOnce(jsonResponse([]))
|
||||
.mockResolvedValueOnce(jsonResponse({ data: [], total: 0, page: 1, page_size: 10, total_pages: 0 }))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true }))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true }))
|
||||
.mockResolvedValueOnce(jsonResponse({ runs: [], pending_tasks: [] }))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true }))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true }));
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await changePassword('old-password', 'new-password');
|
||||
await updateLoginCredentials({ current_password: 'old-password', new_username: 'new-user' });
|
||||
await deleteAccount('acc1');
|
||||
await passwordLogin({ account_id: 'acc1', account: 'user', password: 'password' });
|
||||
await checkPasswordLoginStatus('sid');
|
||||
await cancelPasswordLogin('sid');
|
||||
await deleteOrder('order-1');
|
||||
await createItem('acc1', { item_title: '新商品' });
|
||||
await getShippingRules();
|
||||
await getShippingRulesPage();
|
||||
await updateShippingRule({ cookie_id: 'acc1', trigger_type: 'order_paid' });
|
||||
await deleteShippingRule('7');
|
||||
await getAutomationIssues();
|
||||
await resolveAutomationRun(1, 'retry');
|
||||
await resolveDeferredAutomationTask(2, 'dismiss');
|
||||
|
||||
// paths 是请求层实际发出的版本化 URL 顺序。
|
||||
const paths: unknown[] = [];
|
||||
// index 是当前请求调用在模拟调用列表中的位置。
|
||||
let index = 0;
|
||||
for (index = 0; index < fetchMock.mock.calls.length; index += 1) {
|
||||
paths.push(fetchMock.mock.calls[index][0]);
|
||||
}
|
||||
expect(paths).toEqual([
|
||||
'/api/v1/session/password',
|
||||
'/api/v1/session/credentials',
|
||||
'/api/v1/accounts/acc1',
|
||||
'/api/v1/password-login',
|
||||
'/api/v1/password-login/check/sid',
|
||||
'/api/v1/password-login/cancel/sid',
|
||||
'/api/v1/orders/order-1',
|
||||
'/api/v1/items/acc1',
|
||||
'/api/v1/automation-rules',
|
||||
'/api/v1/automation-rules?page=1&page_size=10',
|
||||
'/api/v1/automation-rules',
|
||||
'/api/v1/automation-rules/7',
|
||||
'/api/v1/automation-issues',
|
||||
'/api/v1/automation-runs/1/resolve',
|
||||
'/api/v1/automation-pending-tasks/2/resolve',
|
||||
]);
|
||||
};
|
||||
|
||||
test('remaining public APIs use versioned compatibility routes', runVersionedRemainingAPITest);
|
||||
+15
-15
@@ -35,7 +35,7 @@ export const logout = async (): Promise<ApiResponse> => {
|
||||
};
|
||||
|
||||
export const changePassword = async (currentPassword: string, newPassword: string): Promise<ApiResponse> => {
|
||||
return post('/change-password', { current_password: currentPassword, new_password: newPassword });
|
||||
return post('/api/v1/session/password', { current_password: currentPassword, new_password: newPassword });
|
||||
};
|
||||
|
||||
export const updateLoginCredentials = async (data: {
|
||||
@@ -43,7 +43,7 @@ export const updateLoginCredentials = async (data: {
|
||||
new_username: string;
|
||||
new_password?: string;
|
||||
}): Promise<ApiResponse & { requires_relogin?: boolean }> => {
|
||||
return put('/account/credentials', data);
|
||||
return put('/api/v1/session/credentials', data);
|
||||
};
|
||||
|
||||
// Accounts
|
||||
@@ -191,7 +191,7 @@ export const updateAccountStatus = async (id: string, enabled: boolean): Promise
|
||||
};
|
||||
|
||||
export const deleteAccount = async (id: string): Promise<OperationResponse> => {
|
||||
return del(`/cookies/${id}`);
|
||||
return del(`/api/v1/accounts/${id}`);
|
||||
};
|
||||
|
||||
export const updateAccountRemark = async (id: string, remark: string): Promise<OperationResponse> => {
|
||||
@@ -265,15 +265,15 @@ export const passwordLogin = async (data: {
|
||||
password: string;
|
||||
show_browser?: boolean;
|
||||
}): Promise<PasswordLoginStartResponse> => {
|
||||
return post('/password-login', data);
|
||||
return post('/api/v1/password-login', data);
|
||||
};
|
||||
|
||||
export const checkPasswordLoginStatus = async (sessionId: string, signal?: AbortSignal): Promise<PasswordLoginStatusResponse> => {
|
||||
return get(`/password-login/check/${sessionId}`, undefined, { signal, timeoutMs: 10_000 });
|
||||
return get(`/api/v1/password-login/check/${sessionId}`, undefined, { signal, timeoutMs: 10_000 });
|
||||
};
|
||||
|
||||
export const cancelPasswordLogin = async (sessionId: string): Promise<ApiResponse> => {
|
||||
return del(`/password-login/cancel/${sessionId}`);
|
||||
return del(`/api/v1/password-login/cancel/${sessionId}`);
|
||||
};
|
||||
|
||||
export const refreshAccountProfile = async (id: string): Promise<CookieProfileResponse> => {
|
||||
@@ -347,7 +347,7 @@ export const updateOrder = async (orderId: string, data: Partial<Order>): Promis
|
||||
};
|
||||
|
||||
export const deleteOrder = async (orderId: string): Promise<ApiResponse> => {
|
||||
return del(`/api/orders/${orderId}`);
|
||||
return del(`/api/v1/orders/${orderId}`);
|
||||
};
|
||||
|
||||
export const syncOrders = async (cookieId?: string, status?: string): Promise<OrderRefreshResponse> => {
|
||||
@@ -514,7 +514,7 @@ export const deleteItem = async (cookieId: string, itemId: string): Promise<Oper
|
||||
}
|
||||
|
||||
export const createItem = async (cookieId: string, data: Partial<Item>): Promise<OperationResponse> => {
|
||||
return post(`/items/${cookieId}`, data);
|
||||
return post(`/api/v1/items/${cookieId}`, data);
|
||||
}
|
||||
|
||||
export const publishItem = async (form: {
|
||||
@@ -668,7 +668,7 @@ const normalizeShippingRules = (rules: any[]): ShippingRule[] => rules.map((item
|
||||
}));
|
||||
|
||||
export const getShippingRules = async (): Promise<ShippingRule[]> => {
|
||||
const res = await get<AutomationRuleResponse[] | AutomationRulePageResponse>('/automation-rules');
|
||||
const res = await get<AutomationRuleResponse[] | AutomationRulePageResponse>('/api/v1/automation-rules');
|
||||
const rules = Array.isArray(res) ? res : (res.data || []);
|
||||
return normalizeShippingRules(rules);
|
||||
}
|
||||
@@ -690,7 +690,7 @@ export const getShippingRulesPage = async ({
|
||||
page = 1,
|
||||
pageSize = 10,
|
||||
}: ShippingRuleListParams = {}): Promise<PaginatedResponse<ShippingRule>> => {
|
||||
const res = await get<AutomationRuleResponse[] | AutomationRulePageResponse>('/automation-rules', {
|
||||
const res = await get<AutomationRuleResponse[] | AutomationRulePageResponse>('/api/v1/automation-rules', {
|
||||
page,
|
||||
page_size: pageSize,
|
||||
cookie_id: cookieId || undefined,
|
||||
@@ -780,10 +780,10 @@ export const updateShippingRule = async (rule: Partial<ShippingRule>): Promise<O
|
||||
sort_order: action.sort_order || index + 1,
|
||||
})),
|
||||
};
|
||||
return rule.id ? put(`/automation-rules/${rule.id}`, payload) : post('/automation-rules', payload);
|
||||
return rule.id ? put(`/api/v1/automation-rules/${rule.id}`, payload) : post('/api/v1/automation-rules', payload);
|
||||
}
|
||||
|
||||
export const deleteShippingRule = async (id: string): Promise<OperationResponse> => del(`/automation-rules/${id}`);
|
||||
export const deleteShippingRule = async (id: string): Promise<OperationResponse> => del(`/api/v1/automation-rules/${id}`);
|
||||
|
||||
export interface AutomationRunIssue {
|
||||
id: number;
|
||||
@@ -808,7 +808,7 @@ export interface DeferredAutomationIssue {
|
||||
}
|
||||
|
||||
export const getAutomationIssues = async (): Promise<{ runs: AutomationRunIssue[]; pending_tasks: DeferredAutomationIssue[] }> => {
|
||||
const result = await get<AutomationIssuesEnvelope>('/automation-issues');
|
||||
const result = await get<AutomationIssuesEnvelope>('/api/v1/automation-issues');
|
||||
return {
|
||||
runs: Array.isArray(result?.runs) ? result.runs : [],
|
||||
pending_tasks: Array.isArray(result?.pending_tasks) ? result.pending_tasks : [],
|
||||
@@ -816,10 +816,10 @@ export const getAutomationIssues = async (): Promise<{ runs: AutomationRunIssue[
|
||||
};
|
||||
|
||||
export const resolveAutomationRun = async (id: number, resolution: 'continue' | 'retry' | 'cancel'): Promise<OperationResponse> =>
|
||||
post(`/automation-runs/${id}/resolve`, { resolution });
|
||||
post(`/api/v1/automation-runs/${id}/resolve`, { resolution });
|
||||
|
||||
export const resolveDeferredAutomationTask = async (id: number, resolution: 'retry' | 'dismiss'): Promise<OperationResponse> =>
|
||||
post(`/automation-pending-tasks/${id}/resolve`, { resolution });
|
||||
post(`/api/v1/automation-pending-tasks/${id}/resolve`, { resolution });
|
||||
|
||||
// Rules - 关键词回复规则 (使用关键词API)
|
||||
type KeywordRowPayload = {
|
||||
|
||||
Reference in new issue
Block a user