优化后端鉴权与日志安全
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
} from '../../open-91/shared.js'
|
||||
import { createHttpError } from '../../../utils/http.js'
|
||||
import { nowIso } from '../../../utils/time.js'
|
||||
import type { OrderItemRow, OrderRow } from '../../../types/repository-rows.js'
|
||||
|
||||
export const OPEN_91_PENDING_CONFIG_STATUS = 'pending_config'
|
||||
export const OPEN_91_MANUAL_FAILED_STATUS = 'manual_failed'
|
||||
@@ -68,7 +69,7 @@ export function buildOpen91SourceEvent(payload: JsonObject = {}, config: JsonObj
|
||||
}
|
||||
}
|
||||
|
||||
export async function upsertOpen91PendingOrder(payload = {}, config = {}) {
|
||||
export async function upsertOpen91PendingOrder(payload: JsonObject = {}, config: JsonObject = {}) {
|
||||
const event = buildOpen91SourceEvent(payload, config)
|
||||
const now = nowIso()
|
||||
const existing = await findOrderByPlatformOrderId({
|
||||
@@ -127,11 +128,11 @@ export async function upsertOpen91PendingOrder(payload = {}, config = {}) {
|
||||
return {
|
||||
order,
|
||||
orderItems,
|
||||
tasks: [],
|
||||
tasks: [] as JsonObject[],
|
||||
}
|
||||
}
|
||||
|
||||
export async function retryOpen91Order(orderId) {
|
||||
export async function retryOpen91Order(orderId: string | number) {
|
||||
const order = await getRequiredOpen91Order(orderId)
|
||||
const items = await listOrderItemsByOrderId(order.id)
|
||||
const event = buildOpen91SourceEventFromOrder(order, items)
|
||||
@@ -154,7 +155,7 @@ export async function retryOpen91Order(orderId) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function failOpen91Order(orderId, reason = '') {
|
||||
export async function failOpen91Order(orderId: string | number, reason = '') {
|
||||
const order = await getRequiredOpen91Order(orderId)
|
||||
const now = nowIso()
|
||||
const rawPayload = parseJsonObject(order.raw_payload_json)
|
||||
@@ -245,7 +246,7 @@ export async function listOpen91Orders({ page = 1, pageSize = 20, status = 'pend
|
||||
}
|
||||
}
|
||||
|
||||
export async function getRequiredOpen91Order(orderId) {
|
||||
export async function getRequiredOpen91Order(orderId: string | number) {
|
||||
const order = await getOrderById(Number(orderId))
|
||||
|
||||
if (!order || order.provider !== OPEN_91_PROVIDER || order.platform !== OPEN_91_PLATFORM) {
|
||||
@@ -258,11 +259,11 @@ export async function getRequiredOpen91Order(orderId) {
|
||||
return order
|
||||
}
|
||||
|
||||
function buildOpen91SourceEventFromOrder(order, items = []) {
|
||||
function buildOpen91SourceEventFromOrder(order: OrderRow, items: OrderItemRow[] = []) {
|
||||
const rawPayload = parseJsonObject(order.raw_payload_json)
|
||||
const body = parseJsonObject(rawPayload.body)
|
||||
const normalizedItems = Array.isArray(items) ? items : []
|
||||
const eventItems = normalizedItems.map((item) => {
|
||||
const eventItems = normalizedItems.map((item: OrderItemRow) => {
|
||||
const snapshot = parseJsonObject(item.item_snapshot_json)
|
||||
const productNo = String(snapshot.productNo || snapshot.externalSkuCode || item.sku_code || '').trim()
|
||||
|
||||
@@ -301,7 +302,7 @@ function buildOpen91SourceEventFromOrder(order, items = []) {
|
||||
}
|
||||
}
|
||||
|
||||
function mapOpen91AdminOrderRow(row) {
|
||||
function mapOpen91AdminOrderRow(row: JsonObject) {
|
||||
const rawPayload = parseJsonObject(row.raw_payload_json)
|
||||
const items = Array.isArray(row.items_json) ? row.items_json : []
|
||||
const firstItem = items[0] || {}
|
||||
@@ -327,7 +328,7 @@ function mapOpen91AdminOrderRow(row) {
|
||||
}
|
||||
}
|
||||
|
||||
function parseJsonObject(value) {
|
||||
function parseJsonObject(value: unknown): JsonObject {
|
||||
if (!value) {
|
||||
return {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user