import {z} from 'zod' export type GetApiPartnerWebhooksDeliveriesArgs = {limit?: number | undefined, offset?: number | undefined}; export type GetApiPartnerWebhooksDeliveriesOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const deliveryStatus = z.enum(["pending", "retrying", "in_progress", "succeeded", "failed_permanent"]); 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 webhookDeliveryResponse = z.object({id: z.string(), event_id: z.string(), subscription_id: z.string(), status: deliveryStatus, attempt_count: z.number().int(), next_attempt_at: z.string().nullable(), last_attempted_at: z.string().nullable(), created_time: z.string(), updated_time: z.string(), event_type: webhookEventType, entity_id: z.string().nullable(), resource_object: z.string().nullable(), resource_id: z.string().nullable(), sequence: z.number().int().nullable(), payload: z.record(z.string(), z.unknown())}); export const webhookDeliveryListResponse = z.object({items: z.array(webhookDeliveryResponse), total_count: z.number().int(), has_more: z.boolean()}); 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 Partner Webhook Deliveries * * GET /partner/webhooks/deliveries */ export const getApiPartnerWebhooksDeliveries = async (args: GetApiPartnerWebhooksDeliveriesArgs, options?: GetApiPartnerWebhooksDeliveriesOptions) => { 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.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (apiKeyAuth !== undefined) headers.set("x-api-key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/partner/webhooks/deliveries${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(webhookDeliveryListResponse, await res.json()) };