84 lines
3.1 KiB
TypeScript
84 lines
3.1 KiB
TypeScript
import type {
|
||
CreateStoreRequest,
|
||
CursorPaginationMeta,
|
||
Store,
|
||
StoreOperationResponse,
|
||
UpdateStoreRequest,
|
||
} from '@atlas/contracts';
|
||
import { api } from '@/services/api';
|
||
|
||
export interface StoreListResult {
|
||
data: Store[];
|
||
meta: CursorPaginationMeta;
|
||
}
|
||
|
||
export interface UpdateStoreOptions {
|
||
/** 提交时的乐观锁版本,取自门店资源 revision */
|
||
revision: number;
|
||
}
|
||
|
||
/**
|
||
* 门店管理接口,契约见 docs/api/stores-and-platforms.md。
|
||
* 列表必须用 platform_id 查询参数(管理列表禁止携带 X-Atlas-Platform-Id header)。
|
||
*/
|
||
export const storesApi = {
|
||
list: (platformId: string, cursor?: string) =>
|
||
api.getList<Store, CursorPaginationMeta>('/stores', {
|
||
params: { platform_id: platformId, limit: 20, ...(cursor ? { cursor } : {}) },
|
||
}),
|
||
|
||
get: (storeId: string) => api.get<Store>(`/stores/${storeId}`),
|
||
|
||
/** 创建后店铺处于 verifying 状态,凭据验证由后台异步执行 */
|
||
create: (payload: CreateStoreRequest) =>
|
||
api.post<StoreOperationResponse>('/stores', payload, {
|
||
headers: { 'Idempotency-Key': crypto.randomUUID() },
|
||
}),
|
||
|
||
/**
|
||
* 编辑:If-Match 乐观锁。未传 api_key 返回更新后的店铺;
|
||
* 传入新 api_key 返回 202 与验证 operation(响应仍是 { store, operation })。
|
||
*/
|
||
update: (storeId: string, payload: UpdateStoreRequest, options: UpdateStoreOptions) =>
|
||
api.patch<Store | StoreOperationResponse>(`/stores/${storeId}`, payload, {
|
||
headers: {
|
||
'If-Match': `"${options.revision}"`,
|
||
'Idempotency-Key': crypto.randomUUID(),
|
||
},
|
||
}),
|
||
|
||
setDefault: (storeId: string) =>
|
||
api.post<Store>(`/stores/${storeId}/set-default`, undefined, {
|
||
headers: { 'Idempotency-Key': crypto.randomUUID() },
|
||
}),
|
||
|
||
requestCredentialVerification: (storeId: string) =>
|
||
api.post<StoreOperationResponse>(`/stores/${storeId}/credential-verifications`, undefined, {
|
||
headers: { 'Idempotency-Key': crypto.randomUUID() },
|
||
}),
|
||
|
||
requestWarehouseSync: (storeId: string) =>
|
||
api.post<StoreOperationResponse>(`/stores/${storeId}/warehouse-syncs`, undefined, {
|
||
headers: { 'Idempotency-Key': crypto.randomUUID() },
|
||
}),
|
||
|
||
/** 删除当前默认店铺时同平台还有其他店铺会返回 422 DEFAULT_STORE_REPLACEMENT_REQUIRED */
|
||
remove: (storeId: string) =>
|
||
api.delete<void>(`/stores/${storeId}`, {
|
||
headers: { 'Idempotency-Key': crypto.randomUUID() },
|
||
}),
|
||
|
||
/**
|
||
* 绑定水印模板,契约见 docs/api/stores-and-platforms.md(PUT /api/stores/{id}/watermark-binding)。
|
||
* 传 null 表示「暂不绑定」;模板必须是当前工作空间的活动模板,返回店铺水印摘要。
|
||
*/
|
||
bindWatermark: (storeId: string, templateId: string | null) =>
|
||
api.put<Store>(
|
||
`/stores/${storeId}/watermark-binding`,
|
||
{ template_id: templateId },
|
||
{
|
||
headers: { 'Idempotency-Key': crypto.randomUUID() },
|
||
}
|
||
),
|
||
};
|