feat(platform): sampleWorkflowData 使用 schema 校验并清理未使用导出
This commit is contained in:
1 parent
a4e23263aa
commit
49693bdbd7
2 files changed
+16
-21
No files matched your search
+16
-14
@@ -10,11 +10,13 @@ import {
|
||||
WorkflowDslSchema,
|
||||
StaffSchema,
|
||||
WebhookInfoSchema,
|
||||
} from "./types";
|
||||
WorkflowSampleDataSchema,
|
||||
} from "./types.js";
|
||||
import type { WorkflowState } from "./types.js";
|
||||
|
||||
// Helper to unwrap { data: T } response
|
||||
async function unwrap<T>(response: Response, schema: z.ZodType<T>): Promise<T> {
|
||||
const json = await response.json() as { data: unknown };
|
||||
const json = (await response.json()) as { data: unknown };
|
||||
return schema.parse(json.data);
|
||||
}
|
||||
|
||||
@@ -28,7 +30,7 @@ async function ok(response: Response): Promise<{ success: boolean }> {
|
||||
export async function listPlatforms(
|
||||
client: KyInstance,
|
||||
corpId: string
|
||||
): Promise<import("./types").Platform[]> {
|
||||
): Promise<import("./types.js").Platform[]> {
|
||||
const response = await client.get("api/v2/datalink/platform/search", {
|
||||
searchParams: { scope: "enable", corpId },
|
||||
});
|
||||
@@ -44,7 +46,7 @@ export async function listWorkflows(
|
||||
platformId: string,
|
||||
page: number = 1,
|
||||
pageSize: number = 20
|
||||
): Promise<import("./types").WorkflowPage> {
|
||||
): Promise<import("./types.js").WorkflowPage> {
|
||||
const response = await client.get("api/easo/pipelines/logs", {
|
||||
searchParams: {
|
||||
platformId,
|
||||
@@ -58,7 +60,7 @@ export async function listWorkflows(
|
||||
export async function getWorkflowStats(
|
||||
client: KyInstance,
|
||||
platformId: string
|
||||
): Promise<import("./types").WorkflowStats> {
|
||||
): Promise<import("./types.js").WorkflowStats> {
|
||||
const response = await client.get("api/easo/stats", {
|
||||
searchParams: { platformId },
|
||||
});
|
||||
@@ -67,7 +69,7 @@ export async function getWorkflowStats(
|
||||
|
||||
export async function getWorkflowCharge(
|
||||
client: KyInstance
|
||||
): Promise<import("./types").WorkflowCharge> {
|
||||
): Promise<import("./types.js").WorkflowCharge> {
|
||||
const response = await client.get("api/easo/charge");
|
||||
return unwrap(response, WorkflowChargeSchema);
|
||||
}
|
||||
@@ -77,7 +79,7 @@ export async function getWorkflowCharge(
|
||||
export async function getWorkflowDetail(
|
||||
client: KyInstance,
|
||||
pipelineId: string
|
||||
): Promise<import("./types").WorkflowDetail> {
|
||||
): Promise<import("./types.js").WorkflowDetail> {
|
||||
const response = await client.get(`api/easo/pipelines/${pipelineId}`);
|
||||
return unwrap(response, WorkflowDetailSchema);
|
||||
}
|
||||
@@ -87,7 +89,7 @@ export async function getWorkflowDetail(
|
||||
export async function toggleWorkflow(
|
||||
client: KyInstance,
|
||||
pipelineId: string,
|
||||
state: 0 | 1
|
||||
state: WorkflowState
|
||||
): Promise<{ success: boolean }> {
|
||||
const response = await client.put(`api/easo/pipelines/state/${pipelineId}`, {
|
||||
searchParams: { state: String(state) },
|
||||
@@ -101,7 +103,7 @@ export async function listRunningJobs(
|
||||
client: KyInstance,
|
||||
pipelineId: string,
|
||||
runType: "DEBUG" | "PROD" = "DEBUG"
|
||||
): Promise<import("./types").WorkflowJob[]> {
|
||||
): Promise<import("./types.js").WorkflowJob[]> {
|
||||
const response = await client.get("api/easo/jobs/running", {
|
||||
searchParams: { pipelineId, runType },
|
||||
});
|
||||
@@ -112,7 +114,7 @@ export async function listRunningJobs(
|
||||
|
||||
export async function listDsl(
|
||||
client: KyInstance
|
||||
): Promise<import("./types").WorkflowDsl[]> {
|
||||
): Promise<import("./types.js").WorkflowDsl[]> {
|
||||
const response = await client.get("api/easo/dsl/all");
|
||||
return unwrap(response, z.array(WorkflowDslSchema));
|
||||
}
|
||||
@@ -122,7 +124,7 @@ export async function listDsl(
|
||||
export async function listStaffs(
|
||||
client: KyInstance,
|
||||
external: boolean = false
|
||||
): Promise<import("./types").Staff[]> {
|
||||
): Promise<import("./types.js").Staff[]> {
|
||||
const response = await client.get("api/easo/common/staffs", {
|
||||
searchParams: { external: String(external) },
|
||||
});
|
||||
@@ -134,7 +136,7 @@ export async function listStaffs(
|
||||
export async function getWebhookInfo(
|
||||
client: KyInstance,
|
||||
pipelineId: string
|
||||
): Promise<import("./types").WebhookInfo> {
|
||||
): Promise<import("./types.js").WebhookInfo> {
|
||||
const response = await client.get(`api/webhook/${pipelineId}`);
|
||||
return unwrap(response, WebhookInfoSchema);
|
||||
}
|
||||
@@ -144,7 +146,7 @@ export async function getWebhookInfo(
|
||||
export async function sampleWorkflowData(
|
||||
client: KyInstance,
|
||||
pipelineId: string
|
||||
): Promise<unknown> {
|
||||
): Promise<import("./types.js").WorkflowSampleData> {
|
||||
const response = await client.post(`api/easo/pipelines/${pipelineId}/sampleData`);
|
||||
return response.json();
|
||||
return WorkflowSampleDataSchema.parse(await response.json());
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
import { z } from "zod";
|
||||
|
||||
// ── 通用包装 ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export const SealAiResponseSchema = <T extends z.ZodType>(dataSchema: T) =>
|
||||
z.object({
|
||||
data: dataSchema,
|
||||
});
|
||||
|
||||
// ── 认证 ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
export const HosecloudStaffSchema = z.object({
|
||||
|
||||
Reference in new issue
Block a user