import {z} from 'zod' export type EventSourceUpdate = {name?: (string | null) | undefined, description?: (string | null) | undefined, configuration?: (Record | null) | undefined, is_active?: (boolean | null) | undefined}; export type UpdateApiApiV1EventSourcesEventSourceIdArgs = {event_source_id: string, body: EventSourceUpdate}; export type UpdateApiApiV1EventSourcesEventSourceIdOptions = {baseUrl: string, CookieOAuth2TokenBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const userResponseBody = z.object({created: z.string(), updated: z.string(), active: z.boolean().optional(), activation_token: z.string().max(255).nullable().optional(), full_name: z.string().max(255).optional(), email_opted_in: z.boolean().nullable().optional(), is_service_account: z.boolean(), is_admin: z.boolean()}); export const userResponseMetadata = z.object({email: z.string().max(255).nullable().optional(), external_user_id: z.string().nullable().optional(), user_metadata: z.object({}).optional()}); export const userResponseResources = z.record(z.string(), z.unknown()); export const userResponse = z.object({body: userResponseBody.nullable().optional(), metadata: userResponseMetadata.nullable().optional(), resources: userResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const zenmlEnumsPluginSubType2 = z.enum(["webhook", "pipeline_run"]); export const eventSourceResponseBody = z.object({created: z.string(), updated: z.string(), user: userResponse.nullable().optional(), flavor: z.string().max(255), plugin_subtype: zenmlEnumsPluginSubType2, is_active: z.boolean()}); export const workspaceResponseBody = z.object({created: z.string(), updated: z.string()}); export const workspaceResponseMetadata = z.object({description: z.string().max(255).optional()}); export const workspaceResponseResources = z.record(z.string(), z.unknown()); export const workspaceResponse = z.object({body: workspaceResponseBody.nullable().optional(), metadata: workspaceResponseMetadata.nullable().optional(), resources: workspaceResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const eventSourceResponseMetadata = z.object({workspace: workspaceResponse, description: z.string().max(255).optional(), configuration: z.object({})}); export const triggerResponseBody = z.object({created: z.string(), updated: z.string(), user: userResponse.nullable().optional(), action_flavor: z.string().max(255), action_subtype: z.string(), event_source_flavor: z.string().max(255).nullable().optional(), event_source_subtype: z.string().max(255).nullable().optional(), is_active: z.boolean()}); export const schedule = z.object({name: z.string().nullable().optional(), cron_expression: z.string().nullable().optional(), start_time: z.string().nullable().optional(), end_time: z.string().nullable().optional(), interval_second: z.string().nullable().optional(), catchup: z.boolean().optional(), run_once_start_time: z.string().nullable().optional()}); export const triggerResponseMetadata = z.object({workspace: workspaceResponse, description: z.string().max(255).optional(), event_filter: z.object({}).nullable().optional(), schedule: schedule.nullable().optional()}); export const actionResponseBody = z.object({created: z.string(), updated: z.string(), user: userResponse.nullable().optional(), flavor: z.string().max(255), plugin_subtype: z.enum(["webhook", "pipeline_run"]).max(255)}); export const actionResponseMetadata = z.object({workspace: workspaceResponse, description: z.string().max(255).optional(), configuration: z.object({}), auth_window: z.number().int()}); export const actionResponseResources = z.object({service_account: userResponse}).and(z.record(z.string(), z.unknown())); export const actionResponse = z.object({body: actionResponseBody.nullable().optional(), metadata: actionResponseMetadata.nullable().optional(), resources: actionResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const triggerExecutionResponseBody = z.object({created: z.string(), updated: z.string()}); export const triggerExecutionResponseMetadata = z.object({event_metadata: z.object({}).optional()}); export const triggerExecutionResponseResources = z.object({trigger: z.lazy(() => triggerResponse)}).and(z.record(z.string(), z.unknown())); export const triggerExecutionResponse = z.object({body: triggerExecutionResponseBody.nullable().optional(), metadata: triggerExecutionResponseMetadata.nullable().optional(), resources: triggerExecutionResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional()}); export const pageTriggerExecutionResponse = z.object({index: z.number().int().gt(0), max_size: z.number().int().gt(0), total_pages: z.number().int().gte(0), total: z.number().int().gte(0), items: z.array(triggerExecutionResponse)}); export const triggerResponseResources = z.object({action: actionResponse, event_source: z.lazy(() => eventSourceResponse.nullable().optional()), executions: pageTriggerExecutionResponse}).and(z.record(z.string(), z.unknown())); export const triggerResponse: z.ZodType = z.object({body: triggerResponseBody.nullable().optional(), metadata: triggerResponseMetadata.nullable().optional(), resources: triggerResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const pageTriggerResponse = z.object({index: z.number().int().gt(0), max_size: z.number().int().gt(0), total_pages: z.number().int().gte(0), total: z.number().int().gte(0), items: z.array(triggerResponse)}); export const eventSourceResponseResources = z.object({triggers: pageTriggerResponse}).and(z.record(z.string(), z.unknown())); export const eventSourceResponse: z.ZodType = z.object({body: eventSourceResponseBody.nullable().optional(), metadata: eventSourceResponseMetadata.nullable().optional(), resources: eventSourceResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); 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 }; /** * Update Event Source * * PUT /api/v1/event-sources/{event_source_id} */ export const updateApiApiV1EventSourcesEventSourceId = async (args: UpdateApiApiV1EventSourcesEventSourceIdArgs, options: UpdateApiApiV1EventSourcesEventSourceIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, CookieOAuth2TokenBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (CookieOAuth2TokenBearer !== undefined) headers.set('authorization', `Bearer ${CookieOAuth2TokenBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/event-sources/${encodeURIComponent(String(args.event_source_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(eventSourceResponse, await res.json()) };