task-19: 拆分 shop-match / product-risk 模块 API 至 types/modules/shop-match.ts,java-modules.ts re-export
- product-risk 15 函数 + shop-match 17 函数 + 全套类型(含 ShopMatch 对 ProductRisk 的 type alias) - 保留模块的 PatrolDelete/QueryAsin/Withdraw alias 通过 import type 兜底引用 - QueryAsinCountryAsins 内联定义避免跨模块循环依赖 - 10 个测试:双模块 CRUD/preference/match/task 系列/progressBatch 双端/dashboard/skip-asins/download/export compat
This commit is contained in:
@@ -18,6 +18,13 @@ export * from "./types/modules/similar-asin.ts";
|
||||
export * from "./types/modules/appearance-patent.ts";
|
||||
export * from "./types/modules/delete-brand.ts";
|
||||
export * from "./types/modules/price-track.ts";
|
||||
export * from "./types/modules/shop-match.ts";
|
||||
import type {
|
||||
ProductRiskCandidateVo,
|
||||
ProductRiskDashboardVo,
|
||||
ProductRiskMatchShopsVo,
|
||||
ProductRiskShopQueueItem,
|
||||
} from "./types/modules/shop-match.ts";
|
||||
|
||||
const JAVA_API_PREFIX = "/newApi/api";
|
||||
|
||||
@@ -152,509 +159,6 @@ export async function uploadTempFileToJava(
|
||||
}
|
||||
|
||||
|
||||
/** 商品风险处理:备选店铺与匹配相关数据结构。 */
|
||||
export interface ProductRiskCandidateVo {
|
||||
id: number;
|
||||
shop_name: string;
|
||||
created_at?: string;
|
||||
}
|
||||
|
||||
export interface ProductRiskShopQueueItem {
|
||||
shopName: string;
|
||||
matched: boolean;
|
||||
shopId?: string;
|
||||
platform?: string;
|
||||
companyName?: string;
|
||||
openStoreUrl?: string;
|
||||
matchedUserId?: number;
|
||||
matchStatus?: string;
|
||||
matchMessage?: string;
|
||||
queryAsins?: QueryAsinCountryAsins[];
|
||||
skipAsinsByCountry?: Record<string, string[]>;
|
||||
skip_asins_by_country?: Record<string, string[]>;
|
||||
skipAsinDetailsByCountry?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
skip_asin_details_by_country?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
}
|
||||
|
||||
export interface ShopMatchResultRow {
|
||||
asin?: string;
|
||||
minimumPrice?: string;
|
||||
minimum_price?: string;
|
||||
status?: string;
|
||||
done?: boolean;
|
||||
}
|
||||
|
||||
export interface ShopMatchSubmitShopPayload {
|
||||
shopName?: string;
|
||||
error?: string;
|
||||
countries?: Record<string, ShopMatchResultRow[]>;
|
||||
skipAsinsByCountry?: Record<string, string[]>;
|
||||
skip_asins_by_country?: Record<string, string[]>;
|
||||
skipAsinDetailsByCountry?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
skip_asin_details_by_country?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
}
|
||||
|
||||
export interface ProductRiskMatchShopsVo {
|
||||
items: ProductRiskShopQueueItem[];
|
||||
}
|
||||
|
||||
export function listProductRiskCandidates() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ProductRiskCandidateVo[]>>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/candidates`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function addProductRiskCandidate(shopName: string) {
|
||||
return unwrapJavaResponse(
|
||||
post<
|
||||
JavaApiResponse<ProductRiskCandidateVo>,
|
||||
{ user_id: number; shop_name: string }
|
||||
>(`${JAVA_API_PREFIX}/product-risk-resolve/candidates`, {
|
||||
user_id: getCurrentUserId(),
|
||||
shop_name: shopName,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteProductRiskCandidate(id: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/candidates/${id}`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export interface ProductRiskCountryPreferenceVo {
|
||||
country_codes: string[];
|
||||
}
|
||||
|
||||
export function getProductRiskCountryPreference() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ProductRiskCountryPreferenceVo>>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/country-preference`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function putProductRiskCountryPreference(countryCodes: string[]) {
|
||||
return unwrapJavaResponse(
|
||||
put<
|
||||
JavaApiResponse<ProductRiskCountryPreferenceVo>,
|
||||
{ user_id: number; country_codes: string[] }
|
||||
>(`${JAVA_API_PREFIX}/product-risk-resolve/country-preference`, {
|
||||
user_id: getCurrentUserId(),
|
||||
country_codes: countryCodes,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function matchProductRiskShops(shopNames: string[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<
|
||||
JavaApiResponse<ProductRiskMatchShopsVo>,
|
||||
{ user_id: number; shop_names: string[] }
|
||||
>(`${JAVA_API_PREFIX}/product-risk-resolve/match-shops`, {
|
||||
user_id: getCurrentUserId(),
|
||||
shop_names: shopNames,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export interface ProductRiskDashboardVo {
|
||||
candidateCount: number;
|
||||
processedTaskCount: number;
|
||||
successTaskCount: number;
|
||||
failedTaskCount: number;
|
||||
}
|
||||
|
||||
export interface ProductRiskHistoryItem {
|
||||
resultId?: number;
|
||||
taskId?: number;
|
||||
shopName?: string;
|
||||
shopId?: string;
|
||||
platform?: string;
|
||||
companyName?: string;
|
||||
matched?: boolean;
|
||||
matchStatus?: string;
|
||||
matchMessage?: string;
|
||||
taskStatus?: string;
|
||||
success?: boolean;
|
||||
error?: string;
|
||||
outputFilename?: string;
|
||||
downloadUrl?: string;
|
||||
fileJobId?: number;
|
||||
fileStatus?: string;
|
||||
fileError?: string;
|
||||
fileReady?: boolean;
|
||||
scheduledAt?: string;
|
||||
skipAsinsByCountry?: Record<string, string[]>;
|
||||
skip_asins_by_country?: Record<string, string[]>;
|
||||
skipAsinDetailsByCountry?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
skip_asin_details_by_country?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
}
|
||||
|
||||
export interface ProductRiskHistoryVo {
|
||||
items: ProductRiskHistoryItem[];
|
||||
}
|
||||
|
||||
export interface ProductRiskTaskSummary {
|
||||
id?: number;
|
||||
taskNo?: string;
|
||||
status?: string;
|
||||
errorMessage?: string;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
finishedAt?: string;
|
||||
scheduledAt?: string;
|
||||
countryCodes?: string[];
|
||||
currentStageIndex?: number;
|
||||
activeStageIndex?: number;
|
||||
scheduleStages?: ShopMatchTaskStage[];
|
||||
}
|
||||
|
||||
export interface ProductRiskTaskDetailVo {
|
||||
task?: ProductRiskTaskSummary;
|
||||
items?: ProductRiskHistoryItem[];
|
||||
}
|
||||
|
||||
export interface ProductRiskTaskBatchVo {
|
||||
items: ProductRiskTaskDetailVo[];
|
||||
missingTaskIds?: number[];
|
||||
}
|
||||
|
||||
export interface ProductRiskPendingDeleteVo {
|
||||
removed: boolean;
|
||||
}
|
||||
|
||||
export interface ProductRiskCreateTaskVo {
|
||||
taskId: number;
|
||||
items: ProductRiskHistoryItem[];
|
||||
}
|
||||
|
||||
export type ShopMatchCandidateVo = ProductRiskCandidateVo;
|
||||
export type ShopMatchCountryPreferenceVo = ProductRiskCountryPreferenceVo;
|
||||
export type ShopMatchShopQueueItem = ProductRiskShopQueueItem;
|
||||
export type ShopMatchDashboardVo = ProductRiskDashboardVo;
|
||||
export type ShopMatchHistoryItem = ProductRiskHistoryItem;
|
||||
export type ShopMatchHistoryVo = ProductRiskHistoryVo;
|
||||
export type ShopMatchTaskDetailVo = ProductRiskTaskDetailVo;
|
||||
export type ShopMatchTaskBatchVo = ProductRiskTaskBatchVo;
|
||||
|
||||
export interface ShopMatchCreateTaskItem {
|
||||
shopName: string;
|
||||
matched: boolean;
|
||||
shopId?: string;
|
||||
platform?: string;
|
||||
companyName?: string;
|
||||
openStoreUrl?: string;
|
||||
matchedUserId?: number;
|
||||
matchStatus?: string;
|
||||
matchMessage?: string;
|
||||
}
|
||||
|
||||
export interface ShopMatchCreateTaskResultItem {
|
||||
resultId?: number;
|
||||
taskId?: number;
|
||||
shopName?: string;
|
||||
shopId?: string;
|
||||
platform?: string;
|
||||
companyName?: string;
|
||||
matched?: boolean;
|
||||
matchStatus?: string;
|
||||
matchMessage?: string;
|
||||
taskStatus?: string;
|
||||
success?: boolean;
|
||||
error?: string;
|
||||
outputFilename?: string;
|
||||
downloadUrl?: string;
|
||||
fileJobId?: number;
|
||||
fileStatus?: string;
|
||||
fileError?: string;
|
||||
fileReady?: boolean;
|
||||
scheduledAt?: string;
|
||||
}
|
||||
|
||||
export interface ShopMatchCreateTaskVo {
|
||||
taskId: number;
|
||||
items: ShopMatchCreateTaskResultItem[];
|
||||
}
|
||||
|
||||
export interface ShopMatchTaskStage {
|
||||
stageIndex?: number;
|
||||
scheduledAt?: string;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export function getProductRiskDashboard() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ProductRiskDashboardVo>>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/dashboard`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getProductRiskHistory() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ProductRiskHistoryVo>>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/history`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteProductRiskHistory(resultId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/history/${resultId}`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function createProductRiskTask(items: ProductRiskShopQueueItem[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<
|
||||
JavaApiResponse<ProductRiskCreateTaskVo>,
|
||||
{ user_id: number; items: ProductRiskShopQueueItem[] }
|
||||
>(`${JAVA_API_PREFIX}/product-risk-resolve/tasks`, {
|
||||
user_id: getCurrentUserId(),
|
||||
items,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteProductRiskTask(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/tasks/${taskId}`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deletePendingProductRiskShopResult(shopName: string) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<ProductRiskPendingDeleteVo>>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/pending-shop-result`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId(), shop_name: shopName },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getProductRiskTasksBatch(taskIds: number[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<ProductRiskTaskBatchVo>, { taskIds: number[] }>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/tasks/batch`,
|
||||
{ taskIds },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getProductRiskResultDownloadUrl(resultId: number) {
|
||||
return getJavaDownloadUrl(
|
||||
`/product-risk-resolve/results/${resultId}/download`,
|
||||
);
|
||||
}
|
||||
|
||||
export function listShopMatchCandidates() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ShopMatchCandidateVo[]>>(
|
||||
`${JAVA_API_PREFIX}/shop-match/candidates`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function addShopMatchCandidate(shopName: string) {
|
||||
return unwrapJavaResponse(
|
||||
post<
|
||||
JavaApiResponse<ShopMatchCandidateVo>,
|
||||
{ user_id: number; shop_name: string }
|
||||
>(`${JAVA_API_PREFIX}/shop-match/candidates`, {
|
||||
user_id: getCurrentUserId(),
|
||||
shop_name: shopName,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteShopMatchCandidate(id: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/shop-match/candidates/${id}`, {
|
||||
params: { user_id: getCurrentUserId() },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function getShopMatchCountryPreference() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ShopMatchCountryPreferenceVo>>(
|
||||
`${JAVA_API_PREFIX}/shop-match/country-preference`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function putShopMatchCountryPreference(countryCodes: string[]) {
|
||||
return unwrapJavaResponse(
|
||||
put<
|
||||
JavaApiResponse<ShopMatchCountryPreferenceVo>,
|
||||
{ user_id: number; country_codes: string[] }
|
||||
>(`${JAVA_API_PREFIX}/shop-match/country-preference`, {
|
||||
user_id: getCurrentUserId(),
|
||||
country_codes: countryCodes,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function matchShopMatchShops(shopNames: string[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<
|
||||
JavaApiResponse<ProductRiskMatchShopsVo>,
|
||||
{ user_id: number; shop_names: string[] }
|
||||
>(`${JAVA_API_PREFIX}/shop-match/match-shops`, {
|
||||
user_id: getCurrentUserId(),
|
||||
shop_names: shopNames,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function getShopMatchDashboard() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ShopMatchDashboardVo>>(
|
||||
`${JAVA_API_PREFIX}/shop-match/dashboard`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getShopMatchHistory() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ShopMatchHistoryVo>>(
|
||||
`${JAVA_API_PREFIX}/shop-match/history`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteShopMatchHistory(resultId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/shop-match/history/${resultId}`, {
|
||||
params: { user_id: getCurrentUserId() },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function createShopMatchTask(
|
||||
items: ShopMatchCreateTaskItem[],
|
||||
countryCodes: string[],
|
||||
scheduleTimes?: string[],
|
||||
) {
|
||||
return unwrapJavaResponse(
|
||||
post<
|
||||
JavaApiResponse<ShopMatchCreateTaskVo>,
|
||||
{ user_id: number; items: ShopMatchCreateTaskItem[]; country_codes: string[]; schedule_times?: string[] }
|
||||
>(`${JAVA_API_PREFIX}/shop-match/tasks`, {
|
||||
user_id: getCurrentUserId(),
|
||||
items,
|
||||
country_codes: countryCodes,
|
||||
schedule_times: scheduleTimes,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteShopMatchTask(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/shop-match/tasks/${taskId}`, {
|
||||
params: { user_id: getCurrentUserId() },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function activateShopMatchTask(taskId: number, stageIndex: number) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<null>, undefined>(
|
||||
`${JAVA_API_PREFIX}/shop-match/tasks/${taskId}/activate?user_id=${encodeURIComponent(String(getCurrentUserId()))}&stage_index=${encodeURIComponent(String(stageIndex))}`,
|
||||
undefined,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function completeShopMatchTaskStage(taskId: number, stageIndex: number) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<null>, { stage_index: number }>(
|
||||
`${JAVA_API_PREFIX}/shop-match/tasks/${taskId}/stage-finished?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
{ stage_index: stageIndex },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getShopMatchTasksBatch(taskIds: number[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<ShopMatchTaskBatchVo>, { taskIds: number[] }>(
|
||||
`${JAVA_API_PREFIX}/shop-match/tasks/batch`,
|
||||
{ taskIds },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getShopMatchResultDownloadUrl(resultId: number) {
|
||||
return getJavaDownloadUrl(`/shop-match/results/${resultId}/download`);
|
||||
}
|
||||
|
||||
export function getShopMatchTaskSkipAsinsPaginated(
|
||||
taskId: number,
|
||||
page: number = 1,
|
||||
pageSize: number = 1000,
|
||||
options: {
|
||||
shopName?: string | string[];
|
||||
countryCode?: string | string[];
|
||||
} = {},
|
||||
) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ShopMatchSkipAsinPageVo>>(
|
||||
`${JAVA_API_PREFIX}/shop-match/tasks/${taskId}/skip-asins/paginated`,
|
||||
{
|
||||
params: {
|
||||
page,
|
||||
page_size: pageSize,
|
||||
...(options.shopName ? { shop_name: options.shopName } : {}),
|
||||
...(options.countryCode ? { country_code: options.countryCode } : {}),
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export type PatrolDeleteCandidateVo = ProductRiskCandidateVo;
|
||||
export type PatrolDeleteDashboardVo = ProductRiskDashboardVo;
|
||||
export type PatrolDeleteShopQueueItem = ProductRiskShopQueueItem;
|
||||
@@ -1445,30 +949,6 @@ export function deleteWithdrawHistory(resultId: number) {
|
||||
);
|
||||
}
|
||||
|
||||
export function getShopMatchTaskProgressBatch(taskIds: number[]) {
|
||||
return postTaskProgressBatch<ShopMatchTaskBatchVo>(
|
||||
`${JAVA_API_PREFIX}/shop-match/tasks/progress/batch`,
|
||||
taskIds,
|
||||
);
|
||||
}
|
||||
|
||||
export function getProductRiskTaskProgressBatch(taskIds: number[]) {
|
||||
return postTaskProgressBatch<ProductRiskTaskBatchVo>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/tasks/progress/batch`,
|
||||
taskIds,
|
||||
);
|
||||
}
|
||||
|
||||
export interface ShopMatchSkipAsinPageVo {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
total: number;
|
||||
totalPages: number;
|
||||
queryAsins: QueryAsinCountryAsins[];
|
||||
skipAsinsByCountry: Record<string, string[]>;
|
||||
skipAsinDetailsByCountry: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
}
|
||||
|
||||
// ========== 视频复刻 / 图生视频 ==========
|
||||
|
||||
export interface ImageVideoDouyinCopyVo {
|
||||
|
||||
@@ -0,0 +1,597 @@
|
||||
import { get, post, put, del, type JavaApiResponse, unwrapJavaResponse } from '../../http.ts'
|
||||
import { buildJavaUrl, JAVA_API_PREFIX } from '../../url.ts'
|
||||
import { getCurrentUserId } from '../../user.ts'
|
||||
import { getJavaDownloadUrl } from '../../download-url.ts'
|
||||
import { getTaskProgressCacheTtlMs, getTaskProgressTimeoutMs } from '../../../task-progress-config.ts'
|
||||
import { createTaskProgressRequestCache } from '../../../task-progress-request-cache.ts'
|
||||
import { API_ENDPOINTS } from '../../endpoints.ts'
|
||||
|
||||
/** 与 query-asin 模块同构的共享行结构(避免跨模块循环依赖,类型内联) */
|
||||
export interface QueryAsinCountryAsins {
|
||||
country: string;
|
||||
asins: string[];
|
||||
}
|
||||
|
||||
/** 商品风险处理:备选店铺与匹配相关数据结构。 */
|
||||
export interface ProductRiskCandidateVo {
|
||||
id: number;
|
||||
shop_name: string;
|
||||
created_at?: string;
|
||||
}
|
||||
|
||||
export interface ProductRiskShopQueueItem {
|
||||
shopName: string;
|
||||
matched: boolean;
|
||||
shopId?: string;
|
||||
platform?: string;
|
||||
companyName?: string;
|
||||
openStoreUrl?: string;
|
||||
matchedUserId?: number;
|
||||
matchStatus?: string;
|
||||
matchMessage?: string;
|
||||
queryAsins?: QueryAsinCountryAsins[];
|
||||
skipAsinsByCountry?: Record<string, string[]>;
|
||||
skip_asins_by_country?: Record<string, string[]>;
|
||||
skipAsinDetailsByCountry?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
skip_asin_details_by_country?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
}
|
||||
|
||||
export interface ShopMatchResultRow {
|
||||
asin?: string;
|
||||
minimumPrice?: string;
|
||||
minimum_price?: string;
|
||||
status?: string;
|
||||
done?: boolean;
|
||||
}
|
||||
|
||||
export interface ShopMatchSubmitShopPayload {
|
||||
shopName?: string;
|
||||
error?: string;
|
||||
countries?: Record<string, ShopMatchResultRow[]>;
|
||||
skipAsinsByCountry?: Record<string, string[]>;
|
||||
skip_asins_by_country?: Record<string, string[]>;
|
||||
skipAsinDetailsByCountry?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
skip_asin_details_by_country?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
}
|
||||
|
||||
export interface ProductRiskMatchShopsVo {
|
||||
items: ProductRiskShopQueueItem[];
|
||||
}
|
||||
|
||||
export interface ProductRiskCountryPreferenceVo {
|
||||
country_codes: string[];
|
||||
}
|
||||
|
||||
export interface ProductRiskDashboardVo {
|
||||
candidateCount: number;
|
||||
processedTaskCount: number;
|
||||
successTaskCount: number;
|
||||
failedTaskCount: number;
|
||||
}
|
||||
|
||||
export interface ProductRiskHistoryItem {
|
||||
resultId?: number;
|
||||
taskId?: number;
|
||||
shopName?: string;
|
||||
shopId?: string;
|
||||
platform?: string;
|
||||
companyName?: string;
|
||||
matched?: boolean;
|
||||
matchStatus?: string;
|
||||
matchMessage?: string;
|
||||
taskStatus?: string;
|
||||
success?: boolean;
|
||||
error?: string;
|
||||
outputFilename?: string;
|
||||
downloadUrl?: string;
|
||||
fileJobId?: number;
|
||||
fileStatus?: string;
|
||||
fileError?: string;
|
||||
fileReady?: boolean;
|
||||
scheduledAt?: string;
|
||||
skipAsinsByCountry?: Record<string, string[]>;
|
||||
skip_asins_by_country?: Record<string, string[]>;
|
||||
skipAsinDetailsByCountry?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
skip_asin_details_by_country?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
}
|
||||
|
||||
export interface ProductRiskHistoryVo {
|
||||
items: ProductRiskHistoryItem[];
|
||||
}
|
||||
|
||||
export interface ProductRiskTaskSummary {
|
||||
id?: number;
|
||||
taskNo?: string;
|
||||
status?: string;
|
||||
errorMessage?: string;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
finishedAt?: string;
|
||||
scheduledAt?: string;
|
||||
countryCodes?: string[];
|
||||
currentStageIndex?: number;
|
||||
activeStageIndex?: number;
|
||||
scheduleStages?: ShopMatchTaskStage[];
|
||||
}
|
||||
|
||||
export interface ProductRiskTaskDetailVo {
|
||||
task?: ProductRiskTaskSummary;
|
||||
items?: ProductRiskHistoryItem[];
|
||||
}
|
||||
|
||||
export interface ProductRiskTaskBatchVo {
|
||||
items: ProductRiskTaskDetailVo[];
|
||||
missingTaskIds?: number[];
|
||||
}
|
||||
|
||||
export interface ProductRiskPendingDeleteVo {
|
||||
removed: boolean;
|
||||
}
|
||||
|
||||
export interface ProductRiskCreateTaskVo {
|
||||
taskId: number;
|
||||
items: ProductRiskHistoryItem[];
|
||||
}
|
||||
|
||||
export type ShopMatchCandidateVo = ProductRiskCandidateVo;
|
||||
export type ShopMatchCountryPreferenceVo = ProductRiskCountryPreferenceVo;
|
||||
export type ShopMatchShopQueueItem = ProductRiskShopQueueItem;
|
||||
export type ShopMatchDashboardVo = ProductRiskDashboardVo;
|
||||
export type ShopMatchHistoryItem = ProductRiskHistoryItem;
|
||||
export type ShopMatchHistoryVo = ProductRiskHistoryVo;
|
||||
export type ShopMatchTaskDetailVo = ProductRiskTaskDetailVo;
|
||||
export type ShopMatchTaskBatchVo = ProductRiskTaskBatchVo;
|
||||
|
||||
export interface ShopMatchCreateTaskItem {
|
||||
shopName: string;
|
||||
matched: boolean;
|
||||
shopId?: string;
|
||||
platform?: string;
|
||||
companyName?: string;
|
||||
openStoreUrl?: string;
|
||||
matchedUserId?: number;
|
||||
matchStatus?: string;
|
||||
matchMessage?: string;
|
||||
}
|
||||
|
||||
export interface ShopMatchCreateTaskResultItem {
|
||||
resultId?: number;
|
||||
taskId?: number;
|
||||
shopName?: string;
|
||||
shopId?: string;
|
||||
platform?: string;
|
||||
companyName?: string;
|
||||
matched?: boolean;
|
||||
matchStatus?: string;
|
||||
matchMessage?: string;
|
||||
taskStatus?: string;
|
||||
success?: boolean;
|
||||
error?: string;
|
||||
outputFilename?: string;
|
||||
downloadUrl?: string;
|
||||
fileJobId?: number;
|
||||
fileStatus?: string;
|
||||
fileError?: string;
|
||||
fileReady?: boolean;
|
||||
scheduledAt?: string;
|
||||
}
|
||||
|
||||
export interface ShopMatchCreateTaskVo {
|
||||
taskId: number;
|
||||
items: ShopMatchCreateTaskResultItem[];
|
||||
}
|
||||
|
||||
export interface ShopMatchTaskStage {
|
||||
stageIndex?: number;
|
||||
scheduledAt?: string;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export interface ShopMatchSkipAsinPageVo {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
total: number;
|
||||
totalPages: number;
|
||||
queryAsins: QueryAsinCountryAsins[];
|
||||
skipAsinsByCountry: Record<string, string[]>;
|
||||
skipAsinDetailsByCountry: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
}
|
||||
|
||||
const taskProgressResponseCache = createTaskProgressRequestCache<unknown>({
|
||||
ttlMs: () => getTaskProgressCacheTtlMs(),
|
||||
maxEntries: 100,
|
||||
maxInflight: 16,
|
||||
});
|
||||
|
||||
function normalizeTaskIds(taskIds: number[]) {
|
||||
return Array.from(
|
||||
new Set(
|
||||
(taskIds || [])
|
||||
.map((taskId) => Number(taskId))
|
||||
.filter((taskId) => Number.isFinite(taskId) && taskId > 0),
|
||||
),
|
||||
).sort((left, right) => left - right);
|
||||
}
|
||||
|
||||
function buildTaskProgressRequestKey(path: string, taskIds: number[]) {
|
||||
return `${path}::${taskIds.join(",")}`;
|
||||
}
|
||||
|
||||
async function postTaskProgressBatch<T>(
|
||||
path: string,
|
||||
taskIds: number[],
|
||||
) {
|
||||
const normalizedTaskIds = normalizeTaskIds(taskIds);
|
||||
if (!normalizedTaskIds.length) {
|
||||
return { items: [], missingTaskIds: [] } as T;
|
||||
}
|
||||
|
||||
const cacheKey = buildTaskProgressRequestKey(path, normalizedTaskIds);
|
||||
const cached = taskProgressResponseCache.get(cacheKey);
|
||||
if (cached !== undefined) {
|
||||
return cached as T;
|
||||
}
|
||||
|
||||
const inflight = taskProgressResponseCache.getInflight(cacheKey);
|
||||
if (inflight) {
|
||||
return (await inflight) as T;
|
||||
}
|
||||
|
||||
const requestPromise = unwrapJavaResponse(
|
||||
post<JavaApiResponse<T>, { taskIds: number[] }>(path, { taskIds: normalizedTaskIds }, {
|
||||
timeout: getTaskProgressTimeoutMs(),
|
||||
}),
|
||||
)
|
||||
.then((data) => {
|
||||
taskProgressResponseCache.set(cacheKey, data);
|
||||
return data;
|
||||
})
|
||||
.finally(() => {
|
||||
taskProgressResponseCache.endInflight(cacheKey);
|
||||
});
|
||||
|
||||
taskProgressResponseCache.startInflight(cacheKey, requestPromise);
|
||||
return requestPromise;
|
||||
}
|
||||
|
||||
export function listProductRiskCandidates() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ProductRiskCandidateVo[]>>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/candidates`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function addProductRiskCandidate(shopName: string) {
|
||||
return unwrapJavaResponse(
|
||||
post<
|
||||
JavaApiResponse<ProductRiskCandidateVo>,
|
||||
{ user_id: number; shop_name: string }
|
||||
>(`${JAVA_API_PREFIX}/product-risk-resolve/candidates`, {
|
||||
user_id: getCurrentUserId(),
|
||||
shop_name: shopName,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteProductRiskCandidate(id: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/candidates/${id}`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getProductRiskCountryPreference() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ProductRiskCountryPreferenceVo>>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/country-preference`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function putProductRiskCountryPreference(countryCodes: string[]) {
|
||||
return unwrapJavaResponse(
|
||||
put<
|
||||
JavaApiResponse<ProductRiskCountryPreferenceVo>,
|
||||
{ user_id: number; country_codes: string[] }
|
||||
>(`${JAVA_API_PREFIX}/product-risk-resolve/country-preference`, {
|
||||
user_id: getCurrentUserId(),
|
||||
country_codes: countryCodes,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function matchProductRiskShops(shopNames: string[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<
|
||||
JavaApiResponse<ProductRiskMatchShopsVo>,
|
||||
{ user_id: number; shop_names: string[] }
|
||||
>(`${JAVA_API_PREFIX}/product-risk-resolve/match-shops`, {
|
||||
user_id: getCurrentUserId(),
|
||||
shop_names: shopNames,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function getProductRiskDashboard() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ProductRiskDashboardVo>>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/dashboard`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getProductRiskHistory() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ProductRiskHistoryVo>>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/history`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteProductRiskHistory(resultId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/history/${resultId}`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function createProductRiskTask(items: ProductRiskShopQueueItem[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<
|
||||
JavaApiResponse<ProductRiskCreateTaskVo>,
|
||||
{ user_id: number; items: ProductRiskShopQueueItem[] }
|
||||
>(`${JAVA_API_PREFIX}/product-risk-resolve/tasks`, {
|
||||
user_id: getCurrentUserId(),
|
||||
items,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteProductRiskTask(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/tasks/${taskId}`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deletePendingProductRiskShopResult(shopName: string) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<ProductRiskPendingDeleteVo>>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/pending-shop-result`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId(), shop_name: shopName },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getProductRiskTasksBatch(taskIds: number[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<ProductRiskTaskBatchVo>, { taskIds: number[] }>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/tasks/batch`,
|
||||
{ taskIds },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getProductRiskResultDownloadUrl(resultId: number) {
|
||||
return getJavaDownloadUrl(
|
||||
`/product-risk-resolve/results/${resultId}/download`,
|
||||
);
|
||||
}
|
||||
|
||||
export function getProductRiskTaskProgressBatch(taskIds: number[]) {
|
||||
return postTaskProgressBatch<ProductRiskTaskBatchVo>(
|
||||
`${JAVA_API_PREFIX}/product-risk-resolve/tasks/progress/batch`,
|
||||
taskIds,
|
||||
);
|
||||
}
|
||||
|
||||
export function listShopMatchCandidates() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ShopMatchCandidateVo[]>>(
|
||||
`${JAVA_API_PREFIX}/shop-match/candidates`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function addShopMatchCandidate(shopName: string) {
|
||||
return unwrapJavaResponse(
|
||||
post<
|
||||
JavaApiResponse<ShopMatchCandidateVo>,
|
||||
{ user_id: number; shop_name: string }
|
||||
>(`${JAVA_API_PREFIX}/shop-match/candidates`, {
|
||||
user_id: getCurrentUserId(),
|
||||
shop_name: shopName,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteShopMatchCandidate(id: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/shop-match/candidates/${id}`, {
|
||||
params: { user_id: getCurrentUserId() },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function getShopMatchCountryPreference() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ShopMatchCountryPreferenceVo>>(
|
||||
`${JAVA_API_PREFIX}/shop-match/country-preference`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function putShopMatchCountryPreference(countryCodes: string[]) {
|
||||
return unwrapJavaResponse(
|
||||
put<
|
||||
JavaApiResponse<ShopMatchCountryPreferenceVo>,
|
||||
{ user_id: number; country_codes: string[] }
|
||||
>(`${JAVA_API_PREFIX}/shop-match/country-preference`, {
|
||||
user_id: getCurrentUserId(),
|
||||
country_codes: countryCodes,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function matchShopMatchShops(shopNames: string[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<
|
||||
JavaApiResponse<ProductRiskMatchShopsVo>,
|
||||
{ user_id: number; shop_names: string[] }
|
||||
>(`${JAVA_API_PREFIX}/shop-match/match-shops`, {
|
||||
user_id: getCurrentUserId(),
|
||||
shop_names: shopNames,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function getShopMatchDashboard() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ShopMatchDashboardVo>>(
|
||||
`${JAVA_API_PREFIX}/shop-match/dashboard`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getShopMatchHistory() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ShopMatchHistoryVo>>(
|
||||
`${JAVA_API_PREFIX}/shop-match/history`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteShopMatchHistory(resultId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/shop-match/history/${resultId}`, {
|
||||
params: { user_id: getCurrentUserId() },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function createShopMatchTask(
|
||||
items: ShopMatchCreateTaskItem[],
|
||||
countryCodes: string[],
|
||||
scheduleTimes?: string[],
|
||||
) {
|
||||
return unwrapJavaResponse(
|
||||
post<
|
||||
JavaApiResponse<ShopMatchCreateTaskVo>,
|
||||
{ user_id: number; items: ShopMatchCreateTaskItem[]; country_codes: string[]; schedule_times?: string[] }
|
||||
>(`${JAVA_API_PREFIX}/shop-match/tasks`, {
|
||||
user_id: getCurrentUserId(),
|
||||
items,
|
||||
country_codes: countryCodes,
|
||||
schedule_times: scheduleTimes,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteShopMatchTask(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/shop-match/tasks/${taskId}`, {
|
||||
params: { user_id: getCurrentUserId() },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function activateShopMatchTask(taskId: number, stageIndex: number) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<null>, undefined>(
|
||||
`${JAVA_API_PREFIX}/shop-match/tasks/${taskId}/activate?user_id=${encodeURIComponent(String(getCurrentUserId()))}&stage_index=${encodeURIComponent(String(stageIndex))}`,
|
||||
undefined,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function completeShopMatchTaskStage(taskId: number, stageIndex: number) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<null>, { stage_index: number }>(
|
||||
`${JAVA_API_PREFIX}/shop-match/tasks/${taskId}/stage-finished?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
{ stage_index: stageIndex },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getShopMatchTasksBatch(taskIds: number[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<ShopMatchTaskBatchVo>, { taskIds: number[] }>(
|
||||
`${JAVA_API_PREFIX}/shop-match/tasks/batch`,
|
||||
{ taskIds },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getShopMatchResultDownloadUrl(resultId: number) {
|
||||
return getJavaDownloadUrl(`/shop-match/results/${resultId}/download`);
|
||||
}
|
||||
|
||||
export function getShopMatchTaskSkipAsinsPaginated(
|
||||
taskId: number,
|
||||
page: number = 1,
|
||||
pageSize: number = 1000,
|
||||
options: {
|
||||
shopName?: string | string[];
|
||||
countryCode?: string | string[];
|
||||
} = {},
|
||||
) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<ShopMatchSkipAsinPageVo>>(
|
||||
`${JAVA_API_PREFIX}/shop-match/tasks/${taskId}/skip-asins/paginated`,
|
||||
{
|
||||
params: {
|
||||
page,
|
||||
page_size: pageSize,
|
||||
...(options.shopName ? { shop_name: options.shopName } : {}),
|
||||
...(options.countryCode ? { country_code: options.countryCode } : {}),
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getShopMatchTaskProgressBatch(taskIds: number[]) {
|
||||
return postTaskProgressBatch<ShopMatchTaskBatchVo>(
|
||||
`${JAVA_API_PREFIX}/shop-match/tasks/progress/batch`,
|
||||
taskIds,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user