将工作流查询、配置、执行、差异、调试、目录和 DataLink 记录、表达式、审计分别归位。 门面保留显式导出,消除 tracker 及分支类型经聚合出口形成的循环,补充文件级循环检查。 同步总纲、层级文档与接口源码索引,交付完整整改报告。 验证:943 项测试通过,类型、版本和 README 审计通过;二进制和插件构建、验证与打包通过。 81 个迁移函数体保持一致,公共 SDK 导出名和三份生成规范与原始基线一致。
74 lines
3.1 KiB
TypeScript
74 lines
3.1 KiB
TypeScript
import { z } from "zod";
|
|
import type { KyInstance } from "ky";
|
|
import { PlatformSchema, DatalinkPlatformDetailSchema, type DatalinkPlatformDetail } from "./types.js";
|
|
|
|
function asRecord(value: unknown): Record<string, any> {
|
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value as Record<string, any> : {};
|
|
}
|
|
|
|
async function fetchEnabledPlatforms(client: KyInstance, corpId: string): Promise<unknown> {
|
|
const response = await client.get("api/v2/datalink/platform/search", { searchParams: { scope: "enable", corpId } });
|
|
return response.json();
|
|
}
|
|
|
|
/** 工作流使用的基础投影:保留缺少 items 时拒绝的既有契约。 */
|
|
export async function listBasicPlatforms(client: KyInstance, corpId: string) {
|
|
const json = await fetchEnabledPlatforms(client, corpId) as { items: unknown[] };
|
|
return z.array(PlatformSchema).parse(json.items);
|
|
}
|
|
|
|
function sanitizePlatformDetail(value: unknown): Record<string, unknown> {
|
|
const platform = asRecord(value);
|
|
const admin = Array.isArray(platform.admin)
|
|
? platform.admin.map((item) => {
|
|
const staff = asRecord(item);
|
|
return {
|
|
id: staff.id,
|
|
name: staff.name,
|
|
code: staff.code,
|
|
active: staff.active,
|
|
};
|
|
})
|
|
: platform.admin;
|
|
return { ...platform, admin };
|
|
}
|
|
|
|
/** 列出当前企业可见的启用自建应用。 */
|
|
export async function listPlatforms(client: KyInstance, corpId: string) {
|
|
const json = asRecord(await fetchEnabledPlatforms(client, corpId));
|
|
const items = Array.isArray(json.items) ? json.items.map(sanitizePlatformDetail) : [];
|
|
return z.array(DatalinkPlatformDetailSchema).parse(items);
|
|
}
|
|
|
|
/** 列出当前企业全量自建应用与模板平台(包含 HAB 模板与全部自建应用)。 */
|
|
export async function listAllPlatforms(client: KyInstance, corpId: string) {
|
|
const response = await client.get("api/v2/datalink/platform", {
|
|
searchParams: { corpId },
|
|
});
|
|
const json = asRecord(await response.json());
|
|
const rawList = Array.isArray(json) ? json : Array.isArray(json.items) ? json.items : [];
|
|
const items = rawList.map(sanitizePlatformDetail);
|
|
return z.array(DatalinkPlatformDetailSchema).parse(items);
|
|
}
|
|
|
|
/** 获取单个应用详情以及应用级人员/角色/部门权限。 */
|
|
export async function getPlatform(
|
|
client: KyInstance,
|
|
corpId: string,
|
|
platformId: string
|
|
): Promise<DatalinkPlatformDetail> {
|
|
const normalizedId = platformId.startsWith("$") ? platformId : `$${platformId}`;
|
|
const bareId = platformId.startsWith("$") ? platformId.slice(1) : platformId;
|
|
const response = await client.get(`api/v2/datalink/platform/${normalizedId}`, {
|
|
// 前端实际使用两个 join,并且详情接口要求同时传 id。
|
|
searchParams: new URLSearchParams([
|
|
["id", bareId],
|
|
["join", "icon.fileId,fileId,/v1/attachment/attachments"],
|
|
["corpId", corpId],
|
|
["join", "adminIds,admin,/v1/organization/staffs"],
|
|
]),
|
|
});
|
|
const json = asRecord(await response.json());
|
|
return DatalinkPlatformDetailSchema.parse(sanitizePlatformDetail(json.value ?? json.data ?? json));
|
|
}
|