import {z} from 'zod' export type GetApiApiMetadataWebhookIdArgs = {id: string}; export type GetApiApiMetadataWebhookIdOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const tag = z.object({key: z.string().optional(), type: z.string().optional(), value: z.string().optional()}); export const webhookExecutionHistory = z.object({eventId: z.string().optional(), matched: z.boolean().optional(), payload: z.string().optional(), timeStamp: z.number().int().optional(), workflowIds: z.array(z.string()).optional()}); export const webhookConfig = z.object({createdBy: z.string().optional(), evaluatorType: z.string().optional(), expression: z.string().optional(), headerKey: z.string().optional(), headers: z.record(z.string(), z.string()).optional(), id: z.string().optional(), name: z.string().optional(), receiverWorkflowNamesToVersions: z.record(z.string(), z.number().int()).optional(), secretKey: z.string().optional(), secretValue: z.string().optional(), sourcePlatform: z.string().optional(), tags: z.array(tag).optional(), urlVerified: z.boolean().optional(), verifier: z.enum(["SLACK_BASED", "SIGNATURE_BASED", "HEADER_BASED", "STRIPE", "TWITTER", "HMAC_BASED", "SENDGRID"]).optional(), webhookExecutionHistory: z.array(webhookExecutionHistory).optional(), workflowsToStart: z.record(z.string(), z.object({})).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * GET /api/metadata/webhook/{id} */ export const getApiApiMetadataWebhookId = async (args: GetApiApiMetadataWebhookIdArgs, options?: GetApiApiMetadataWebhookIdOptions) => { const {baseUrl = "https://developer.orkescloud.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("X-Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/metadata/webhook/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(webhookConfig, await res.json()) };