收紧后端 TypeScript:统一 Json 类型与 TaskContext 契约
关闭 allowJs;集中 JsonObject 定义并替换分散 any 别名;parseTaskContext 返回 TaskContext;任务详情 API 标注 AdminTaskDetailView;测试减少 as any。
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
isClaimUidMatched,
|
||||
normalizeClaimUid,
|
||||
} from "../../claim/claim-identity.js";
|
||||
import { asJsonObject } from "../../../types/json.js";
|
||||
import {
|
||||
normalizeKuaishouCloudFlow,
|
||||
normalizeKuaishouCloudRoleInfo,
|
||||
@@ -26,13 +27,9 @@ export async function syncKuaishouCloudRoleInfoBeforeDispatch(
|
||||
String(input.errorCodePrefix || "kuaishou_cloud").trim() ||
|
||||
"kuaishou_cloud";
|
||||
const cloudContext =
|
||||
input.cloudContext && typeof input.cloudContext === "object"
|
||||
? input.cloudContext
|
||||
: {};
|
||||
asJsonObject(input.cloudContext);
|
||||
const taskContext =
|
||||
input.taskContext && typeof input.taskContext === "object"
|
||||
? input.taskContext
|
||||
: {};
|
||||
asJsonObject(input.taskContext);
|
||||
const flow = normalizeKuaishouCloudFlow(
|
||||
input.flow || taskContext.kuaishouCloudFulfillment
|
||||
);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { resolveCloudtentaclesConfig } from '../../platforms/cloudtentacles/helpers.js'
|
||||
import { maskCode as maskCodeValue, maskPhone as maskPhoneValue } from '../../../utils/masking.js'
|
||||
import { asJsonObject, type JsonObject } from '../../../types/json.js'
|
||||
|
||||
export type { JsonObject }
|
||||
|
||||
export const KUAISHOU_CLOUD_FIXED_VN_KEY = '1'
|
||||
|
||||
export type JsonObject = Record<string, any>
|
||||
|
||||
const KUAISHOU_CLOUD_EXECUTOR_KEYS = new Set(['kuaishou_ct_assisted', 'kuaishou-industry'])
|
||||
|
||||
export function isKuaishouCloudTask(task: unknown) {
|
||||
@@ -19,15 +20,15 @@ export function isIndustryEVoucherTask(task: unknown) {
|
||||
|
||||
export function normalizeKuaishouCloudFlow(value: unknown) {
|
||||
const source: JsonObject = value && typeof value === 'object' ? (value as JsonObject) : {}
|
||||
const binding = source.binding && typeof source.binding === 'object' ? source.binding : {}
|
||||
const role = source.role && typeof source.role === 'object' ? source.role : {}
|
||||
const purchase = source.purchase && typeof source.purchase === 'object' ? source.purchase : {}
|
||||
const dispatch = source.dispatch && typeof source.dispatch === 'object' ? source.dispatch : {}
|
||||
const binding = asJsonObject(source.binding)
|
||||
const role = asJsonObject(source.role)
|
||||
const purchase = asJsonObject(source.purchase)
|
||||
const dispatch = asJsonObject(source.dispatch)
|
||||
const returnNumber =
|
||||
source.returnNumber && typeof source.returnNumber === 'object' ? source.returnNumber : {}
|
||||
const consume = source.consume && typeof source.consume === 'object' ? source.consume : {}
|
||||
const ticket = source.ticket && typeof source.ticket === 'object' ? source.ticket : {}
|
||||
const rebind = source.rebind && typeof source.rebind === 'object' ? source.rebind : {}
|
||||
asJsonObject(source.returnNumber)
|
||||
const consume = asJsonObject(source.consume)
|
||||
const ticket = asJsonObject(source.ticket)
|
||||
const rebind = asJsonObject(source.rebind)
|
||||
const deliveryItems = normalizeDeliveryItems(source, binding)
|
||||
|
||||
const roleName = String(role.name || binding.roleName || '').trim()
|
||||
@@ -180,7 +181,7 @@ function normalizeRoleNameForCompare(value: unknown) {
|
||||
|
||||
export function normalizeKuaishouCloudDeliveryItems(value: unknown) {
|
||||
const source: JsonObject = value && typeof value === 'object' ? (value as JsonObject) : {}
|
||||
const binding = source.binding && typeof source.binding === 'object' ? source.binding : {}
|
||||
const binding = asJsonObject(source.binding)
|
||||
return normalizeDeliveryItems(source, binding)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { parseTaskContext as parseTaskContextValue } from "../../../utils/task-json.js";
|
||||
import type { TaskRow } from "../../../types/repository/rows.js";
|
||||
|
||||
type JsonObject = Record<string, any>;
|
||||
import type { JsonObject } from '../../../types/json.js'
|
||||
|
||||
export function normalizeActor(actor: unknown) {
|
||||
if (!actor || typeof actor !== "object") {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { parseTaskContext } from '../../../utils/task-json.js'
|
||||
import { nowIso } from '../../../utils/time.js'
|
||||
import { TASK_STATUS } from '../../../domain/task-status.js'
|
||||
import { appendUidToUrl, getClaimIdentityFromContext } from '../../claim/claim-identity.js'
|
||||
import type { JsonObject } from '../../../types/json.js'
|
||||
import {
|
||||
createKuaishouFeifeiOrder,
|
||||
queryKuaishouFeifeiOrder,
|
||||
@@ -17,8 +18,6 @@ import { buildKuaishouIndustryVoucherContext } from '../../platforms/kuaishou-in
|
||||
import { normalizeShortLinkPayload } from '../../short-links/short-link-service.js'
|
||||
import type { TaskRow } from '../../../types/repository/rows.js'
|
||||
|
||||
type JsonObject = Record<string, any>
|
||||
|
||||
export function isKuaishouFeifeiTask(task: Partial<TaskRow> | null | undefined) {
|
||||
return String(task?.executor_key || '').trim() === 'kuaishou_feifei'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user