断开快手后端旧依赖
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { getAgisoShopConfig } from '../platforms/agiso/shop-config-service.js'
|
||||
import { safeParseJson } from './admin-query-utils.js'
|
||||
import { normalizeAdminRole } from './admin-auth-service.js'
|
||||
import {
|
||||
@@ -224,13 +223,6 @@ export function resolveDisplayShopName(provider: unknown, shopId: unknown, shopN
|
||||
return ''
|
||||
}
|
||||
|
||||
if (String(provider || '').trim().toLowerCase() === 'agiso') {
|
||||
const configuredName = String(getAgisoShopConfig(normalizedShopId)?.shopName || '').trim()
|
||||
if (configuredName) {
|
||||
return configuredName
|
||||
}
|
||||
}
|
||||
|
||||
return normalizedShopId
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
export function normalizeAgisoMessageTemplate(value: unknown): string {
|
||||
return String(value || "")
|
||||
.replaceAll("\\r\\n", "\n")
|
||||
.replaceAll("\\n", "\n")
|
||||
.replaceAll("\r\n", "\n");
|
||||
}
|
||||
@@ -49,7 +49,7 @@ import {
|
||||
resolveAdminCloudtentaclesCredentialPayload,
|
||||
resolveAdminCloudtentaclesSessionPayload,
|
||||
} from "./cloudtentacles.js";
|
||||
import { normalizeAdminCloudtentaclesSourceConfigPayload } from "./writes.js";
|
||||
import { normalizeAdminCloudtentaclesSourceConfigPayload } from "./cloudtentacles-writes.js";
|
||||
import {
|
||||
mapAdminCloudtentaclesSession,
|
||||
mapAdminCloudtentaclesSourceConfig,
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
type JsonObject = Record<string, any>;
|
||||
|
||||
export function normalizeAdminCloudtentaclesSourceConfigPayload(
|
||||
payload: JsonObject = {}
|
||||
) {
|
||||
const sourceKey =
|
||||
String(payload.sourceKey || payload.key || "").trim() || "default";
|
||||
return {
|
||||
key: sourceKey,
|
||||
label: String(payload.label || "").trim(),
|
||||
enabled: payload.enabled !== false,
|
||||
baseUrl: String(payload.baseUrl || "").trim() || "https://123.207.217.176",
|
||||
username: String(payload.username || "").trim(),
|
||||
password: String(payload.password || "").trim(),
|
||||
phone: String(payload.phone || "").trim(),
|
||||
deviceId: String(payload.deviceId || "-").trim() || "-",
|
||||
deviceType: Number(payload.deviceType || 0),
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { normalizeAgisoMessageTemplate } from '../../platforms/agiso/xianyu/message-service.js'
|
||||
import { normalizeAgisoMessageTemplate } from './agiso-template.js'
|
||||
import { maskSecret } from './mappers.js'
|
||||
|
||||
type JsonObject = Record<string, any>
|
||||
|
||||
@@ -98,19 +98,3 @@ export function buildAdminAgisoMessagingSavePayload(
|
||||
shops: nextMap,
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeAdminCloudtentaclesSourceConfigPayload(payload: JsonObject = {}) {
|
||||
const sourceKey =
|
||||
String(payload.sourceKey || payload.key || "").trim() || "default";
|
||||
return {
|
||||
key: sourceKey,
|
||||
label: String(payload.label || "").trim(),
|
||||
enabled: payload.enabled !== false,
|
||||
baseUrl: String(payload.baseUrl || "").trim() || "https://123.207.217.176",
|
||||
username: String(payload.username || "").trim(),
|
||||
password: String(payload.password || "").trim(),
|
||||
phone: String(payload.phone || "").trim(),
|
||||
deviceId: String(payload.deviceId || "-").trim() || "-",
|
||||
deviceType: Number(payload.deviceType || 0),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,10 +5,7 @@ import {
|
||||
updateOrder,
|
||||
} from '../../repositories/order-repo.js'
|
||||
import { replaceOrderItems } from '../../repositories/order-item-repo.js'
|
||||
import { getClaimTokenById } from '../../repositories/claim-token-repo.js'
|
||||
import { buildClaimUrl } from '../claim/claim-service.js'
|
||||
import { syncDeliveryTasksForOrder } from './delivery-task-service.js'
|
||||
import { ensureAgisoXianyuClaimMessageDeliveredForTask } from '../platforms/agiso/xianyu/message-service.js'
|
||||
import { resolveOrderItemForFulfillment } from './product-match-service.js'
|
||||
import { nowIso } from '../../utils/time.js'
|
||||
import { logWebhook } from '../../utils/logger.js'
|
||||
@@ -51,6 +48,11 @@ type SourceOrderEvent = {
|
||||
|
||||
type UpsertOrderSourceOptions = {
|
||||
sourceLabel?: string
|
||||
handleClaimLinkTask?: (input: {
|
||||
event: SourceOrderEvent
|
||||
order: OrderRow
|
||||
task: TaskRow
|
||||
}) => Promise<Record<string, unknown> | null | undefined>
|
||||
}
|
||||
|
||||
type MessageDeliveryResult = {
|
||||
@@ -99,7 +101,7 @@ export async function upsertOrderFromWebhook(event: SourceOrderEvent): Promise<U
|
||||
|
||||
export async function upsertOrderFromSource(
|
||||
event: SourceOrderEvent,
|
||||
{ sourceLabel = 'source' }: UpsertOrderSourceOptions = {},
|
||||
{ sourceLabel = 'source', handleClaimLinkTask }: UpsertOrderSourceOptions = {},
|
||||
): Promise<UpsertOrderResult> {
|
||||
const now = nowIso()
|
||||
const exactExisting = await findOrderByPlatformOrderId({
|
||||
@@ -219,37 +221,28 @@ export async function upsertOrderFromSource(
|
||||
resolvedSkuCodes: configuredItems.map((item) => item.skuCode),
|
||||
})
|
||||
|
||||
for (const task of tasks) {
|
||||
const isClaimLinkTask = String(task.task_status || '') === 'link_generated'
|
||||
|| (
|
||||
String(task.executor_key || '').trim() === 'kuaishou_ct_assisted'
|
||||
&& ['pending_binding_prepare', 'waiting_binding', 'role_confirmed', 'dispatched_pending_return'].includes(String(task.task_status || '').trim())
|
||||
)
|
||||
if (handleClaimLinkTask) {
|
||||
for (const task of tasks) {
|
||||
const isClaimLinkTask = String(task.task_status || '') === 'link_generated'
|
||||
|| (
|
||||
String(task.executor_key || '').trim() === 'kuaishou_ct_assisted'
|
||||
&& ['pending_binding_prepare', 'waiting_binding', 'role_confirmed', 'dispatched_pending_return'].includes(String(task.task_status || '').trim())
|
||||
)
|
||||
|
||||
if (
|
||||
event.provider !== 'agiso'
|
||||
|| event.platform !== 'xianyu'
|
||||
|| !isClaimLinkTask
|
||||
|| !task.primary_claim_token_id
|
||||
) {
|
||||
continue
|
||||
if (!isClaimLinkTask || !task.primary_claim_token_id) {
|
||||
continue
|
||||
}
|
||||
|
||||
const result = await handleClaimLinkTask({ event, order, task })
|
||||
if (!result) {
|
||||
continue
|
||||
}
|
||||
|
||||
messageDeliveries.push({
|
||||
taskId: task.id,
|
||||
...result,
|
||||
})
|
||||
}
|
||||
|
||||
const claimToken = await getClaimTokenById(task.primary_claim_token_id)
|
||||
if (!claimToken) {
|
||||
continue
|
||||
}
|
||||
|
||||
const result = await ensureAgisoXianyuClaimMessageDeliveredForTask({
|
||||
order,
|
||||
task,
|
||||
claimUrl: buildClaimUrl(claimToken.token),
|
||||
expiredAt: claimToken.expired_at,
|
||||
})
|
||||
messageDeliveries.push({
|
||||
taskId: task.id,
|
||||
...result,
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import crypto from 'node:crypto'
|
||||
|
||||
import { runtimeConfig } from '../../config/runtime.js'
|
||||
import { getClaimTokenById } from '../../repositories/claim-token-repo.js'
|
||||
import { createWebhookEvent, updateWebhookEvent } from '../../repositories/webhook-event-repo.js'
|
||||
import { buildClaimUrl } from '../claim/claim-service.js'
|
||||
import { ensureAgisoXianyuClaimMessageDeliveredForTask } from '../platforms/agiso/xianyu/message-service.js'
|
||||
import { enrichAgisoXianyuTradeOrder } from '../platforms/agiso/xianyu/order-detail-service.js'
|
||||
import {
|
||||
extractAgisoTradeOrderItemSources,
|
||||
extractAgisoTradePayload,
|
||||
resolveAgisoTradePlatformOrderId,
|
||||
} from './agiso-trade-parsing.js'
|
||||
import { upsertOrderFromWebhook } from './order-service.js'
|
||||
import { upsertOrderFromSource, upsertOrderFromWebhook } from './order-service.js'
|
||||
import { hasConfiguredOrderItems } from './product-match-service.js'
|
||||
import { createHttpError } from '../../utils/http.js'
|
||||
import { parseJsonObject } from '../../utils/json.js'
|
||||
@@ -98,7 +101,7 @@ export async function executeAgisoTradeWebhookWithDeps(
|
||||
) {
|
||||
const updateEvent = deps.updateWebhookEvent || updateWebhookEvent
|
||||
const hasConfiguredItems = deps.hasConfiguredOrderItems || hasConfiguredOrderItems
|
||||
const upsertOrder = deps.upsertOrderFromWebhook || upsertOrderFromWebhook
|
||||
const upsertOrder = deps.upsertOrderFromWebhook || upsertAgisoOrderFromWebhook
|
||||
|
||||
try {
|
||||
if (!parsed.signatureValid) {
|
||||
@@ -287,6 +290,25 @@ export async function executeAgisoTradeWebhookWithDeps(
|
||||
}
|
||||
}
|
||||
|
||||
async function upsertAgisoOrderFromWebhook(event) {
|
||||
return upsertOrderFromSource(event, {
|
||||
sourceLabel: 'webhook',
|
||||
handleClaimLinkTask: async ({ order, task }) => {
|
||||
const claimToken = await getClaimTokenById(task.primary_claim_token_id)
|
||||
if (!claimToken) {
|
||||
return null
|
||||
}
|
||||
|
||||
return ensureAgisoXianyuClaimMessageDeliveredForTask({
|
||||
order,
|
||||
task,
|
||||
claimUrl: buildClaimUrl(claimToken.token),
|
||||
expiredAt: claimToken.expired_at,
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
async function enrichTradeBeforeUpsert(
|
||||
parsed,
|
||||
{ requestId = '', webhookEventId = null } = {},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import crypto from 'node:crypto'
|
||||
|
||||
import { runtimeConfig } from '../../../../config/runtime.js'
|
||||
import { normalizeAgisoMessageTemplate } from '../../../admin/platform-config/agiso-template.js'
|
||||
import { getAgisoMessagingDefaults, getAgisoShopConfigMap } from '../shop-config-service.js'
|
||||
import {
|
||||
createMessageDelivery,
|
||||
@@ -193,13 +194,6 @@ export async function ensureAgisoXianyuAutoDeliveryMessageDeliveredForTask({
|
||||
})
|
||||
}
|
||||
|
||||
export function normalizeAgisoMessageTemplate(value: unknown): string {
|
||||
return String(value || '')
|
||||
.replaceAll('\\r\\n', '\n')
|
||||
.replaceAll('\\n', '\n')
|
||||
.replaceAll('\r\n', '\n')
|
||||
}
|
||||
|
||||
async function deliverAgisoXianyuMessageForTask({
|
||||
order,
|
||||
task,
|
||||
|
||||
Reference in New Issue
Block a user