import {z} from 'zod' export type GetApiDisputeDisputesAlertEnrollmentsArgs = {'filter[id]'?: string | undefined, 'filter[workspaceId]'?: string | undefined, 'filter[providerId]'?: string | undefined, 'filter[providerConfigId]'?: string | undefined, 'filter[program]'?: string | undefined, 'filter[createdAt]'?: string | undefined, includeDescriptors?: boolean | undefined}; export type GetApiDisputeDisputesAlertEnrollmentsOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiDisputeDisputesAlertEnrollmentsResponse = z.object({links: z.object({self: z.string(), prev: z.string().optional(), next: z.string().optional(), first: z.string().optional(), last: z.string().optional()}).optional(), results: z.array(z.object({id: z.string(), createdAt: z.string(), updatedAt: z.string(), providerId: z.string(), providerConfigId: z.string(), program: z.enum(["Ethoca", "CDRN", "RDR", "SAFE", "TC40", "Discover", "AMEX", "JCB"]), ruleset: z.string().nullable().optional(), externalReference: z.string().nullable().optional(), activeDescriptorCount: z.number().int(), totalDescriptorCount: z.number().int(), descriptorDetails: z.array(z.object({id: z.string(), enrollmentId: z.string(), descriptor: z.string(), type: z.string(), status: z.enum(["Pending", "Processing", "InReview", "Enrolled", "Rejected", "Disabled", "Surpressed"]), bankMid: z.string().nullable().optional(), externalReference: z.string().nullable().optional(), unenrolRequestedAt: z.string().nullable().optional(), updatedBy: z.string().nullable().optional(), lastSyncedAt: z.string().nullable().optional(), createdAt: z.string(), updatedAt: z.string()})).optional(), lastError: z.string().nullable().optional(), lastPollAt: z.string().nullable().optional(), activatedAt: z.string().nullable().optional(), unenrollRequestedAt: z.string().nullable().optional()})).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 }; /** * List Dispute Alert Enrollments * * GET /dispute/disputes/alert-enrollments */ export const getApiDisputeDisputesAlertEnrollments = async (args: GetApiDisputeDisputesAlertEnrollmentsArgs, options?: GetApiDisputeDisputesAlertEnrollmentsOptions) => { const {baseUrl = "https://api.staging.payrails.io", fetch: fetchFn = fetch, BearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['filter[id]'] != null) query.append("filter[id]", String(args['filter[id]'])) if (args['filter[workspaceId]'] != null) query.append("filter[workspaceId]", String(args['filter[workspaceId]'])) if (args['filter[providerId]'] != null) query.append("filter[providerId]", String(args['filter[providerId]'])) if (args['filter[providerConfigId]'] != null) query.append("filter[providerConfigId]", String(args['filter[providerConfigId]'])) if (args['filter[program]'] != null) query.append("filter[program]", String(args['filter[program]'])) if (args['filter[createdAt]'] != null) query.append("filter[createdAt]", String(args['filter[createdAt]'])) if (args.includeDescriptors != null) query.append("includeDescriptors", String(args.includeDescriptors)) if (BearerToken !== undefined) headers.set('authorization', `Bearer ${BearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/dispute/disputes/alert-enrollments${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(getApiDisputeDisputesAlertEnrollmentsResponse, await res.json()) };