diff --git a/src/domains/platform/api.ts b/src/domains/platform/api.ts index 70751ad..19ec362 100644 --- a/src/domains/platform/api.ts +++ b/src/domains/platform/api.ts @@ -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(response: Response, schema: z.ZodType): Promise { - 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 { +): Promise { 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 { +): Promise { 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 { +): Promise { 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 { +): Promise { 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 { +): Promise { 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 { +): Promise { 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 { +): Promise { 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 { +): Promise { 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 { +): Promise { 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 { +): Promise { const response = await client.post(`api/easo/pipelines/${pipelineId}/sampleData`); - return response.json(); + return WorkflowSampleDataSchema.parse(await response.json()); } diff --git a/src/domains/sealai/types.ts b/src/domains/sealai/types.ts index 85428ae..10b7a22 100644 --- a/src/domains/sealai/types.ts +++ b/src/domains/sealai/types.ts @@ -1,12 +1,5 @@ import { z } from "zod"; -// ── 通用包装 ────────────────────────────────────────────────────────────────── - -export const SealAiResponseSchema = (dataSchema: T) => - z.object({ - data: dataSchema, - }); - // ── 认证 ────────────────────────────────────────────────────────────────────── export const HosecloudStaffSchema = z.object({