删除旧履约配置逻辑
This commit is contained in:
@@ -3,7 +3,6 @@ import assert from 'node:assert/strict'
|
||||
|
||||
import {
|
||||
mapAdminCloudtentaclesSession,
|
||||
mapAdminKuaishouCloudFulfillmentSource,
|
||||
mapAdminKuaishouEticketSourceConfig,
|
||||
maskPhone,
|
||||
maskSecret,
|
||||
@@ -69,54 +68,3 @@ test('mapAdminCloudtentaclesSession derives masked fields and token presence', (
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
test('mapAdminKuaishouCloudFulfillmentSource normalizes items and defaults', () => {
|
||||
assert.deepEqual(
|
||||
mapAdminKuaishouCloudFulfillmentSource({
|
||||
enabled: true,
|
||||
items: [
|
||||
{
|
||||
id: ' item-1 ',
|
||||
provider: '',
|
||||
platform: '',
|
||||
cloudSourceKeys: [' account_a ', 'account_b'],
|
||||
cloudSkuId: '0',
|
||||
autoConsumeAfterDispatch: true,
|
||||
kuaishouConsumeShopId: ' ks1 ',
|
||||
notes: ' note ',
|
||||
},
|
||||
],
|
||||
}),
|
||||
{
|
||||
enabled: true,
|
||||
items: [
|
||||
{
|
||||
id: 'item-1',
|
||||
enabled: true,
|
||||
priority: 100,
|
||||
provider: '91kaquan',
|
||||
platform: 'kuaishou',
|
||||
shopId: '',
|
||||
internalSkuCode: '',
|
||||
internalSkuName: '',
|
||||
externalSkuCode: '',
|
||||
externalItemId: '',
|
||||
externalSkuName: '',
|
||||
resolvedSkuName: '',
|
||||
cloudSourceKeys: ['account_a', 'account_b'],
|
||||
cloudSkuId: 0,
|
||||
cloudSkuName: '',
|
||||
deliveryItems: [],
|
||||
vnKey: '',
|
||||
autoBuyEnabled: true,
|
||||
minAssetReserve: 0,
|
||||
autoReturnNumberAfterDispatch: false,
|
||||
autoConsumeAfterDispatch: true,
|
||||
kuaishouConsumeShopId: 'ks1',
|
||||
kuaishouConsumeShopName: '',
|
||||
notes: 'note',
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
@@ -60,85 +60,3 @@ export function mapAdminCloudtentaclesSession(session: JsonObject = {}) {
|
||||
hasToken: Boolean(String(session.token || "").trim()),
|
||||
};
|
||||
}
|
||||
|
||||
export function mapAdminKuaishouCloudFulfillmentItem(item: JsonObject = {}) {
|
||||
const deliveryItems = normalizeDeliveryItems(item);
|
||||
return {
|
||||
id: String(item.id || "").trim(),
|
||||
enabled: item.enabled !== false,
|
||||
priority: Number(item.priority || 100) || 100,
|
||||
provider: String(item.provider || "91kaquan").trim() || "91kaquan",
|
||||
platform: String(item.platform || "kuaishou").trim() || "kuaishou",
|
||||
shopId: String(item.shopId || "").trim(),
|
||||
internalSkuCode: String(item.internalSkuCode || "").trim(),
|
||||
internalSkuName: String(item.internalSkuName || "").trim(),
|
||||
externalSkuCode: String(item.externalSkuCode || "").trim(),
|
||||
externalItemId: String(item.externalItemId || "").trim(),
|
||||
externalSkuName: String(item.externalSkuName || "").trim(),
|
||||
resolvedSkuName: String(item.resolvedSkuName || "").trim(),
|
||||
cloudSourceKeys: Array.isArray(item.cloudSourceKeys)
|
||||
? item.cloudSourceKeys
|
||||
.map((value) => String(value || "").trim())
|
||||
.filter(Boolean)
|
||||
: [],
|
||||
cloudSkuId: Number(item.cloudSkuId || 0) || 0,
|
||||
cloudSkuName: String(item.cloudSkuName || "").trim(),
|
||||
deliveryItems,
|
||||
vnKey: String(item.vnKey || "").trim(),
|
||||
autoBuyEnabled: item.autoBuyEnabled !== false,
|
||||
minAssetReserve: Number(item.minAssetReserve || 0) || 0,
|
||||
autoReturnNumberAfterDispatch: item.autoReturnNumberAfterDispatch === true,
|
||||
autoConsumeAfterDispatch: item.autoConsumeAfterDispatch === true,
|
||||
kuaishouConsumeShopId: String(item.kuaishouConsumeShopId || "").trim(),
|
||||
kuaishouConsumeShopName: String(item.kuaishouConsumeShopName || "").trim(),
|
||||
notes: String(item.notes || "").trim(),
|
||||
};
|
||||
}
|
||||
|
||||
export function mapAdminKuaishouCloudFulfillmentSource(config: JsonObject = {}) {
|
||||
return {
|
||||
enabled: config.enabled !== false,
|
||||
items: (Array.isArray(config.items) ? config.items : []).map((item) =>
|
||||
mapAdminKuaishouCloudFulfillmentItem(item)
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeDeliveryItems(item: JsonObject = {}) {
|
||||
const rawItems = Array.isArray(item.deliveryItems) ? item.deliveryItems : [];
|
||||
const normalizedItems = rawItems
|
||||
.map((value) => normalizeDeliveryItem(value))
|
||||
.filter(Boolean);
|
||||
|
||||
if (normalizedItems.length > 0) {
|
||||
return normalizedItems;
|
||||
}
|
||||
|
||||
const cloudSkuId = Number(item.cloudSkuId || 0) || 0;
|
||||
if (cloudSkuId <= 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
cloudSkuId,
|
||||
cloudSkuName: String(item.cloudSkuName || "").trim(),
|
||||
quantity: 1,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function normalizeDeliveryItem(value: unknown) {
|
||||
const source = value && typeof value === "object" ? value as JsonObject : {};
|
||||
const cloudSkuId = Number(source.cloudSkuId || source.skuId || 0) || 0;
|
||||
if (cloudSkuId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const quantity = Number(source.quantity || 1) || 1;
|
||||
return {
|
||||
cloudSkuId,
|
||||
cloudSkuName: String(source.cloudSkuName || source.skuName || "").trim(),
|
||||
quantity: Math.max(1, Math.round(quantity)),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
import {
|
||||
getKuaishouCloudFulfillmentConfig,
|
||||
getKuaishouCloudFulfillmentFilePath,
|
||||
saveKuaishouCloudFulfillmentConfig,
|
||||
} from '../../order/kuaishou-cloud-fulfillment-config-service.js'
|
||||
import { mapAdminKuaishouCloudFulfillmentSource } from './cloudtentacles/mappers.js'
|
||||
|
||||
type JsonObject = Record<string, any>
|
||||
|
||||
export function getAdminKuaishouCloudFulfillmentConfig() {
|
||||
const config = getKuaishouCloudFulfillmentConfig()
|
||||
|
||||
return {
|
||||
filePath: getKuaishouCloudFulfillmentFilePath(),
|
||||
source: mapAdminKuaishouCloudFulfillmentSource(config),
|
||||
}
|
||||
}
|
||||
|
||||
/** @param {AdminKuaishouCloudFulfillmentConfigInput} [payload] */
|
||||
export async function updateAdminKuaishouCloudFulfillmentConfig(
|
||||
payload: JsonObject = {},
|
||||
) {
|
||||
const saved = saveKuaishouCloudFulfillmentConfig({
|
||||
enabled: payload.enabled !== false,
|
||||
items: Array.isArray(payload.items) ? payload.items : [],
|
||||
})
|
||||
|
||||
return {
|
||||
filePath: getKuaishouCloudFulfillmentFilePath(),
|
||||
source: mapAdminKuaishouCloudFulfillmentSource(saved),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user