import {z} from 'zod' export type GetApiWebhooksIncomingExternalPurchaseEventsIdArgs = {id: string}; export type GetApiWebhooksIncomingExternalPurchaseEventsIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const webhooksIncomingExternalPurchaseEventAttributes = z.object({id: z.number().int().optional(), public_id: z.string().optional(), workspace_id: z.number().int().optional(), external_purchase_endpoint_id: z.number().int().optional(), order_id: z.number().int().nullable().optional(), event_type: z.string().nullable().optional(), external_event_id: z.string().nullable().optional(), payload: z.unknown(), processed_at: z.string().nullable().optional(), processing_status: z.enum(["pending", "success", "processing_skipped", "decryption_failed", "processing_failed", "order_creation_failed", "refund_processing_failed", "chargeback_processing_failed", "duplicate_webhook_event", "creation_failed", "no_origin_order_processing_ignored", "null"]).nullable().optional(), processing_errors: z.string().nullable().optional(), created_at: z.string().optional(), updated_at: z.string().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 }; /** * Fetch Incoming External Purchase Event * * GET /webhooks/incoming/external_purchase_events/{id} * * Also accepts auth: OAuth2 */ export const getApiWebhooksIncomingExternalPurchaseEventsId = async (args: GetApiWebhooksIncomingExternalPurchaseEventsIdArgs, options?: GetApiWebhooksIncomingExternalPurchaseEventsIdOptions) => { 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 (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/webhooks/incoming/external_purchase_events/${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(webhooksIncomingExternalPurchaseEventAttributes, await res.json()) };