import {z} from 'zod' export type PydanticObjectId = string; export type GetApiV2GiftcardsProgramsProgramIdReportsEscheatmentArgs = {programId: PydanticObjectId | null, jurisdiction?: (string | null) | undefined, dormancy_days?: number | undefined, cardId?: (PydanticObjectId | null) | undefined, 'X-Eposn-Customer-Token'?: (string | null) | undefined, 'X-Eposn-Merchant-Token'?: (string | null) | undefined}; export type GetApiV2GiftcardsProgramsProgramIdReportsEscheatmentOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const escheatmentReportEntryResponse = z.object({cardId: z.string(), cardNumber: z.string(), balance: z.string(), lastActivityDate: z.string(), dormancyDays: z.number().int(), jurisdiction: z.string(), liabilityAmount: z.string(), customerEmail: z.string().nullable(), merchantId: z.string()}); export const escheatmentReportResponse = z.object({reportId: z.string(), generatedAt: z.string(), jurisdiction: z.string(), dormancyThresholdDays: z.number().int(), entries: z.array(escheatmentReportEntryResponse), totalLiability: z.string(), entriesCount: z.number().int()}); 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 }; /** * Getescheatmentreport * * GET /v2/giftcards/programs/{programId}/reports/escheatment */ export const getApiV2GiftcardsProgramsProgramIdReportsEscheatment = async (args: GetApiV2GiftcardsProgramsProgramIdReportsEscheatmentArgs, options?: GetApiV2GiftcardsProgramsProgramIdReportsEscheatmentOptions) => { const {baseUrl = "https://api.loyalty.dog", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.jurisdiction != null) query.append("jurisdiction", String(args.jurisdiction)) if (args.dormancy_days != null) query.append("dormancy_days", String(args.dormancy_days)) if (args.cardId != null) query.append("cardId", String(args.cardId)) if (args['X-Eposn-Customer-Token'] != null) headers.set("X-Eposn-Customer-Token", String(args['X-Eposn-Customer-Token'])) if (args['X-Eposn-Merchant-Token'] != null) headers.set("X-Eposn-Merchant-Token", String(args['X-Eposn-Merchant-Token'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/giftcards/programs/${encodeURIComponent(String(args.programId))}/reports/escheatment${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(escheatmentReportResponse, await res.json()) };