import {z} from 'zod' export type GetApiWalletWalletIdTransactionTransactionIdHistoryArgs = {walletId: unknown, transactionId: unknown, limit?: number | undefined, offset?: number | undefined, orderBy?: ('walletTransactionHistoryId,ASC' | 'walletTransactionHistoryId,DESC') | undefined}; export type GetApiWalletWalletIdTransactionTransactionIdHistoryOptions = {baseUrl?: string | undefined, eesAuthenticationClientId?: string | undefined, eesAuthenticationHash?: string | undefined, fetch?: typeof fetch | undefined}; export const locationEntity = z.object({storeId: z.string().optional(), storeParentId: z.string().optional()}); export const walletTransactionAccountsEntity = z.array(z.object({accountId: z.string().optional(), accountTransactionId: z.string().optional()})); export const walletTransactionHistoryEntity = z.object({walletTransactionHistoryId: z.string().optional(), walletTransactionId: z.string().optional(), identityId: z.string().optional(), identity: z.string().optional(), type: z.string().optional(), status: z.string().optional(), state: z.string().optional(), expiryDate: z.string().optional(), basket: z.array(z.object({contents: z.string().optional(), summary: z.string().optional(), payment: z.string().optional()})).optional(), location: z.array(locationEntity).optional(), accounts: walletTransactionAccountsEntity.optional(), meta: z.string().optional(), dateCreated: z.string().optional(), lastUpdated: z.string().optional()}); export const getApiWalletWalletIdTransactionTransactionIdHistoryResponse = z.object({limit: z.number().int().optional(), hasMoreResults: z.boolean().optional(), offset: z.number().int().optional(), orderBy: z.array(z.object({name: z.literal("walletTransactionHistoryId").optional(), order: z.enum(["ASC", "DESC"]).optional()})).optional(), results: z.array(walletTransactionHistoryEntity).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 }; /** * Get Wallet Transaction History * * GET /wallet/{walletId}/transaction/{transactionId}/history */ export const getApiWalletWalletIdTransactionTransactionIdHistory = async (args: GetApiWalletWalletIdTransactionTransactionIdHistoryArgs, options?: GetApiWalletWalletIdTransactionTransactionIdHistoryOptions) => { const {baseUrl = "https://wallet.uk.eagleeye.com/2.0", fetch: fetchFn = fetch, eesAuthenticationClientId, eesAuthenticationHash} = 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 (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (eesAuthenticationClientId !== undefined) headers.set("X-EES-AUTH-CLIENT-ID", eesAuthenticationClientId) if (eesAuthenticationHash !== undefined) headers.set("X-EES-AUTH-HASH", eesAuthenticationHash) const url = `${baseUrl.replace(/\/+$/, '')}/wallet/${encodeURIComponent(String(args.walletId))}/transaction/${encodeURIComponent(String(args.transactionId))}/history${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(getApiWalletWalletIdTransactionTransactionIdHistoryResponse, await res.json()) };