ts类型检查

This commit is contained in:
yml
2026-05-04 09:43:38 +08:00
parent a914b7b828
commit 66261e56d1
23 changed files with 223 additions and 76 deletions
@@ -66,7 +66,7 @@ export async function syncDeliveryTasksForOrder(order, orderItems) {
executorKey: String(profile.executor_key || 'manual_dispatch'),
taskStatus: initialStatus,
inventoryStatus: profile.requires_claim ? 'pending' : 'not_required',
deliveryStatus: initialStatus === 'redeemed' ? 'delivered' : 'pending',
deliveryStatus: 'pending',
resultCode: '',
resultMessage: '',
claimToken: '',
@@ -1,11 +1,34 @@
import { resolveFulfillmentBinding } from '../../repositories/fulfillment-profile-repo.js'
import { resolveProductMatchRule } from '../../repositories/product-match-rule-repo.js'
/**
* @typedef {{
* itemId?: string
* externalItemId?: string
* skuCode?: string
* skuName?: string
* externalSkuCode?: string
* externalSkuName?: string
* quantity?: number
* spec?: Record<string, unknown>
* snapshot?: Record<string, unknown>
* [key: string]: unknown
* }} FulfillmentItem
*/
/**
* @param {{
* provider?: string
* platform?: string
* shopId?: string
* item?: FulfillmentItem
* }} params
*/
export async function resolveOrderItemForFulfillment({
provider = '',
platform = '',
shopId = '',
item = {},
item = /** @type {FulfillmentItem} */ ({}),
}) {
const candidate = await resolveConfiguredItemCandidate({
provider,
@@ -61,6 +84,14 @@ export async function resolveOrderItemForFulfillment({
}
}
/**
* @param {{
* provider?: string
* platform?: string
* shopId?: string
* items?: FulfillmentItem[]
* }} params
*/
export async function hasConfiguredOrderItems({
provider = '',
platform = '',
@@ -104,7 +135,7 @@ async function resolveConfiguredItemCandidate({
provider = '',
platform = '',
shopId = '',
item = {},
item = /** @type {FulfillmentItem} */ ({}),
}) {
const externalItemId = pickFirstNonEmpty([
item.externalItemId,
@@ -166,7 +197,8 @@ function readConfigValue(rawValue, key) {
return ''
}
return String(parsed[key] || '').trim()
const config = /** @type {Record<string, unknown>} */ (parsed)
return String(config[key] || '').trim()
}
function safeParseJson(rawValue) {
@@ -177,6 +209,10 @@ function safeParseJson(rawValue) {
}
}
/**
* @param {unknown} value
* @returns {value is Record<string, unknown>}
*/
function isPlainObject(value) {
return Object.prototype.toString.call(value) === '[object Object]'
}