收紧后端 TypeScript:统一 Json 类型与 TaskContext 契约
关闭 allowJs;集中 JsonObject 定义并替换分散 any 别名;parseTaskContext 返回 TaskContext;任务详情 API 标注 AdminTaskDetailView;测试减少 as any。
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
import crypto from 'node:crypto'
|
||||
import type { JsonObject } from '../../types/json.js'
|
||||
|
||||
import { createHttpError } from '../../utils/http.js'
|
||||
import { assertOpen91Config } from './config.js'
|
||||
import { normalizeOpen91String } from './payload.js'
|
||||
|
||||
type JsonObject = Record<string, any>
|
||||
|
||||
export function buildOpen91SignSource(params: JsonObject = {}, { secret } = assertOpen91Config()) {
|
||||
const entries = Object.entries(params)
|
||||
.filter(([key]) => key !== 'sign')
|
||||
|
||||
@@ -3,6 +3,7 @@ import { listKuaishouIndustryVouchersByOid } from '../../repositories/kuaishou-i
|
||||
import { listTasksByOrderId } from '../../repositories/task-repo.js'
|
||||
import { resolveTaskDeliveryLink } from '../fulfillment/delivery-link-service.js'
|
||||
import { logIntegration } from '../../utils/logger.js'
|
||||
import { asJsonObject, type JsonObject } from '../../types/json.js'
|
||||
import {
|
||||
OPEN_91_MANUAL_FAILED_STATUS,
|
||||
OPEN_91_PENDING_CONFIG_STATUS,
|
||||
@@ -32,8 +33,6 @@ import {
|
||||
} from './response.js'
|
||||
import type { KuaishouIndustryVoucherRow, OrderRow, TaskRow } from '../../types/repository/rows.js'
|
||||
|
||||
type JsonObject = Record<string, any>
|
||||
|
||||
export async function queryOpen91Order(payload: JsonObject = {}, { requestId = '' } = {}) {
|
||||
const config = assertOpen91Config()
|
||||
const normalized = normalizeOpen91QueryPayload(payload)
|
||||
@@ -245,7 +244,7 @@ function parseJsonObject(value: unknown): JsonObject {
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(String(value || '{}'))
|
||||
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {}
|
||||
return asJsonObject(parsed)
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { createHttpError } from '../../utils/http.js'
|
||||
import { assertOpen91Config } from './config.js'
|
||||
|
||||
type JsonObject = Record<string, any>
|
||||
import type { JsonObject } from '../../types/json.js'
|
||||
|
||||
export function normalizeOpen91String(value: unknown) {
|
||||
return String(value || '').trim()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { JsonObject } from '../../types/json.js'
|
||||
import {
|
||||
OPEN_91_DEFAULT_FAIL_CODE,
|
||||
OPEN_91_SUCCESS_MESSAGE,
|
||||
@@ -5,8 +6,6 @@ import {
|
||||
import { isOpen91FailedTaskStatus } from '../../domain/task-status.js'
|
||||
import { normalizeOpen91String } from './payload.js'
|
||||
|
||||
type JsonObject = Record<string, any>
|
||||
|
||||
export function buildOpen91SuccessResponse(data: unknown, message = OPEN_91_SUCCESS_MESSAGE) {
|
||||
return {
|
||||
code: 200,
|
||||
|
||||
Reference in New Issue
Block a user