import {z} from 'zod' export type GetApiWebhooksSubscriptionsArgs = {'x-entity-id'?: string | undefined}; export type GetApiWebhooksSubscriptionsOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const webhookEventType = z.enum(["ach_transfer.created", "ach_transfer.updated", "wire_transfer.created", "wire_transfer.updated", "book_transfer.created", "book_transfer.updated", "international_payment.created", "international_payment.updated", "inbound_ach_transfer.created", "inbound_ach_transfer.updated", "inbound_wire_transfer.created", "inbound_wire_transfer.updated", "check_deposit.created", "check_deposit.updated", "global_account_transfer.created", "crypto_transfer.created", "crypto_transfer.updated", "account.created", "account.updated", "card.created", "card.updated", "bill.created", "bill.updated", "onboarding_consent.updated", "info_request.created", "info_request.updated", "application.created", "application.under_review", "application.submitted", "application.approved", "application.rejected", "identity_verification.action_required", "identity_verification.approved", "identity_verification.rejected", "message.attempt.exhausted", "webhook.test"]); export const webhookPayloadMode = z.enum(["snapshot", "thin"]); export const webhookSubscriptionResponse = z.object({account_id: z.string().nullable().optional(), id: z.string(), name: z.string(), url: z.string(), is_enabled: z.boolean(), event_types: z.array(webhookEventType).nullable(), payload_mode: webhookPayloadMode, created_time: z.string(), updated_time: z.string()}); export const getApiWebhooksSubscriptionsResponse = z.array(webhookSubscriptionResponse); 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 Webhook Subscriptions * * GET /webhooks/subscriptions */ export const getApiWebhooksSubscriptions = async (args: GetApiWebhooksSubscriptionsArgs, options?: GetApiWebhooksSubscriptionsOptions) => { const {baseUrl = "https://api.meow.com/v1", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-entity-id'] != null) headers.set("x-entity-id", String(args['x-entity-id'])) if (apiKeyAuth !== undefined) headers.set("x-api-key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/webhooks/subscriptions${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(getApiWebhooksSubscriptionsResponse, await res.json()) };