import {z} from 'zod' export type GetApiWorkflowsWorkflowIdTriggersArgs = {workflow_id: string, after?: string | undefined, per_page?: number | undefined, sort_order?: ('asc' | 'desc') | undefined, sort_property?: ('id' | 'updated_at') | undefined}; export type GetApiWorkflowsWorkflowIdTriggersOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const workflowsTriggerAttributes = z.object({id: z.number().int().optional(), public_id: z.string().nullable().optional(), workflow_id: z.number().int().optional(), event_type_key: z.string().nullable().optional(), event_type_name: z.string().nullable().optional(), active: z.boolean().optional(), allow_anonymous_contacts: z.boolean().optional(), subscription_cancelation_reason: z.string().nullable().optional(), contacts_tag_id: z.number().int().nullable().optional(), funnel_id: z.number().int().nullable().optional(), page_id: z.number().int().nullable().optional(), product_id: z.number().int().nullable().optional(), cancellation_product_id: z.number().int().nullable().optional(), product_variant_id: z.number().int().nullable().optional(), cancellation_product_variant_id: z.number().int().nullable().optional(), subscription_variant_to_id: z.number().int().nullable().optional(), sales_pipelines_id: z.number().int().nullable().optional(), current_sales_pipelines_stage_id: z.number().int().nullable().optional(), appointments_calendar_id: z.number().int().nullable().optional(), appointments_event_type_id: z.number().int().nullable().optional(), course_id: z.number().int().nullable().optional(), courses_lesson_id: z.number().int().nullable().optional(), courses_section_id: z.number().int().nullable().optional(), community_id: z.number().int().nullable().optional(), communities_space_id: z.number().int().nullable().optional(), communities_space_group_id: z.number().int().nullable().optional(), emails_broadcasts_id: z.number().int().nullable().optional(), calendar_event_id: z.number().int().nullable().optional(), survey_workflow_id: z.number().int().nullable().optional(), workflows_step_id: z.number().int().nullable().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const getApiWorkflowsWorkflowIdTriggersResponse = z.array(workflowsTriggerAttributes); 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 }; /** * List Triggers * * GET /workflows/{workflow_id}/triggers */ export const getApiWorkflowsWorkflowIdTriggers = async (args: GetApiWorkflowsWorkflowIdTriggersArgs, options?: GetApiWorkflowsWorkflowIdTriggersOptions) => { const {baseUrl = "https://myworkspace.myclickfunnels.com/api/v2", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.after != null) query.append("after", String(args.after)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (args.sort_property != null) query.append("sort_property", String(args.sort_property)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/workflows/${encodeURIComponent(String(args.workflow_id))}/triggers${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(getApiWorkflowsWorkflowIdTriggersResponse, await res.json()) };