import {z} from 'zod' export type GetApiV1WebhookSubscriptionsIdArgs = {id: number}; export type GetApiV1WebhookSubscriptionsIdOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const revAppComponentsLink = z.object({rel: z.string().optional(), href: z.string().optional()}); export const revWebAPIModelsGetOrSearchOfRevAppModelsWebhookSubscription = z.object({ok: z.boolean().optional(), webhook_subscription_id: z.number().int().optional(), webhook_receiver_id: z.number().int().gte(1).lte(2147483647), event_type: z.enum(["ACCOUNTING_PERIOD_CLOSED", "ADJUSTMENT_STATUS_CHANGED", "AGENT_CREATED", "AGENT_UPDATED", "BILL_CREATED", "BILL_REVERSED", "BILL_THIRD_PARTY_PDF_DOWNLOADED", "CHILD_BILL_CREATED", "CHARGE_CREATED", "CONTACT_CREATED", "CONTACT_UPDATED", "CONTACT_DELETED", "CREDIT_CREATED", "CREDITCARD_EXPIRED", "CUSTOMER_AUTO_DEBIT_STATUS_CHANGED", "CUSTOMER_CREATED", "CUSTOMER_UPDATED", "CUSTOMER_STATUS_CHANGED", "INVENTORY_STATUS_CHANGED", "INVENTORY_CREATED", "INVENTORY_UPDATED", "INVENTORY_ASSIGNED", "INVENTORY_UNASSIGNED", "MRCS_POSTED", "NEW_USER", "ORDER_CREATED", "ORDER_UPDATED", "ORDER_STATUS_CHANGED", "PAYMENT_AUTO_DEBIT_FAILURE", "PAYMENT_AUTO_DEBIT_SUCCESS", "PAYMENT_BOUNCED", "PAYMENT_CREATED", "PAYMENT_REAPPLIED", "PAYMENT_REVERSED", "PAYMENT_REMINDER", "PAYMENT_VOID", "PRODUCT_CREATED", "PRODUCT_UPDATED", "RATING_COMPLETED", "REQUEST_APPROVED", "REQUEST_ASSIGNED", "REQUEST_CREATED", "REQUEST_STATUS_CHANGED", "SERVICE_CREATED", "SERVICE_UPDATED", "TASK_CREATED", "TASK_NOTE_ADDED", "TASK_STATUS_CANCELED", "TASK_STATUS_COMPLETED", "TASK_UPDATED", "TASK_STEP_CHANGED", "TICKET_CREATED", "TICKET_MERGED", "TICKET_NOTE_ADDED", "TICKET_UPDATED", "USER_PASSWORD_RESET", "USER_CREATED", "USER_STATUS_CHANGED"]), links: z.array(revAppComponentsLink).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 }; /** * View webhook subscription * * GET /v1/WebhookSubscriptions/{id} */ export const getApiV1WebhookSubscriptionsId = async (args: GetApiV1WebhookSubscriptionsIdArgs, options?: GetApiV1WebhookSubscriptionsIdOptions) => { const {baseUrl = "https://restapi.rev.io", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/WebhookSubscriptions/${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(revWebAPIModelsGetOrSearchOfRevAppModelsWebhookSubscription, await res.json()) };