import {z} from 'zod' export type GetApiWalletWalletIdAccountAccountIdTransactionsArgs = {walletId: unknown, accountId: unknown, include?: (Array<'pointsIncreaseLedger' | 'pointsDecreaseLedger'>) | undefined, event?: ('ACTIVATE' | 'AUTOTOPUP' | 'BALANCE' | 'BLOCK' | 'CANCEL' | 'CLEARBALANCE' | 'CREATE' | 'CREDIT' | 'DEBIT' | 'DONATE' | 'DONATE_IN' | 'EXPIRY' | 'GIFT' | 'GIFT_IN' | 'GOODWILL' | 'INACTIVATE' | 'INVALIDATE' | 'LOAD' | 'PERISH' | 'REACTIVATE' | 'REDEEM' | 'REFUND' | 'REISSUE' | 'RESEND' | 'STAMP' | 'STOLEN' | 'TOPUP' | 'TRANSFER' | 'TRANSFER_IN' | 'UNBLOCK' | 'UNEXPIRE' | 'UNLOCK' | 'UNPERISH' | 'UNREDEEM' | 'UPDATE' | 'UPDATE_PASSPHRASE' | 'VERIFY' | 'VOID') | undefined, dateCreated?: string | undefined, lastUpdated?: string | undefined, parentAccountTransactionId?: unknown | undefined, accountTransactionId?: unknown | undefined, source?: unknown | undefined, orderBy?: ('accountTransactionId,ASC' | 'accountTransactionId,DESC' | 'dateCreated,ASC' | 'dateCreated,DESC') | undefined, limit?: number | undefined, offset?: number | undefined, walletTransactions?: boolean | undefined}; export type GetApiWalletWalletIdAccountAccountIdTransactionsOptions = {baseUrl?: string | undefined, eesAuthenticationClientId?: string | undefined, eesAuthenticationHash?: string | undefined, fetch?: typeof fetch | undefined}; export const accountTransactionBalancesHistoryEntity = z.object({available: z.number().int().optional(), refundable: z.number().int().optional(), current: z.number().int().optional(), lifetime: z.number().int().optional(), totalSpend: z.number().int().optional(), transactionCount: z.number().int().optional()}); export const accountStatusEntity = z.enum(["ACTIVE", "BLOCKED", "CANCELLED", "DELETED", "EXPIRED", "INACTIVE", "INVALIDATED", "LOCKED", "STOLEN", "USED", "SUSPENDED"]); export const datesEntity = z.object({start: z.string().optional(), end: z.string().optional()}); export const metaEntity = z.object({key1: z.string().optional(), key2: z.string().optional()}); export const accountBalancesEntity = z.object({available: z.number().int().optional(), refundable: z.number().int().optional(), totalSpend: z.number().int().optional(), totalUnits: z.number().int().optional(), transactionCount: z.number().int().optional(), current: z.number().int().optional(), usable: z.number().int().optional(), locked: z.number().int().optional(), lifetime: z.number().int().optional(), objectivesMet: z.number().int().optional()}); export const walletAccountRelationEntity = z.array(z.object({accountId: z.string(), dateCreated: z.string()})); export const accountOverridesEntity = z.object({continuity: z.object({qualification: z.object({totalTransactionUnits: z.number().int().optional(), totalTransactionSpend: z.number().int().optional(), totalTransactionCount: z.number().int().optional()}).optional()}).optional(), offer: z.object({qualification: z.object({minimumProductSpend: z.number().int().nullable().optional(), minimumUnits: z.number().int().nullable().optional(), minimumBasketSpend: z.number().int().nullable().optional()}).optional(), reward: z.object({creditAmount: z.number().int().optional(), step: z.number().int().optional(), floor: z.number().int().optional(), ceiling: z.number().int().nullable().optional(), multiplierValue: z.number().int().optional()}).optional()}).optional(), campaign: z.object({rules: z.object({couponLimit: z.number().int().optional()}).optional()}).optional(), reward: z.object({discountAmount: z.number().int().gte(1).optional(), finalAmount: z.number().int().gte(1).optional(), percentageAmount: z.number().gte(1).optional(), discountValue: z.number().int().gte(1).optional()}).optional()}); export const walletAccountEntity = z.object({accountId: z.string(), walletId: z.string(), campaignId: z.string(), type: z.enum(["ECOUPON", "VOUCHER", "STAMP_CARD", "PAPER", "DEBIT", "PLASTIC", "POINTS", "CONTINUITY", "STANDARD_SUBSCRIPTION", "QUEST"]), clientType: z.string(), status: accountStatusEntity, state: z.string(), dates: datesEntity, meta: metaEntity.optional(), balances: accountBalancesEntity, relationships: z.object({ENTITLEMENT: z.object({accountType: walletAccountRelationEntity.optional()}).optional(), ENTITLEMENT_OF: z.object({accountType: walletAccountRelationEntity.optional()}).optional(), OBJECTIVE: z.object({accountType: walletAccountRelationEntity.optional()}).optional(), OBJECTIVE_OF: z.object({accountType: walletAccountRelationEntity.optional()}).optional(), PROMOTION: z.object({accountType: walletAccountRelationEntity.optional()}).optional(), PROMOTION_OF: z.object({accountType: walletAccountRelationEntity.optional()}).optional(), BOUNCE_BACK_REWARD: z.object({accountType: walletAccountRelationEntity.optional()}).optional(), BOUNCE_BACK_REWARD_OF: z.object({accountType: walletAccountRelationEntity.optional()}).optional(), COUPON_STAMP_REWARD: z.object({accountType: walletAccountRelationEntity.optional()}).optional(), COUPON_STAMP_REWARD_OF: z.object({accountType: walletAccountRelationEntity.optional()}).optional(), LOYALTY_POINTS_REWARD_OF: z.object({accountType: walletAccountRelationEntity.optional()}).optional()}).optional(), overrides: accountOverridesEntity.optional(), dateCreated: z.string(), lastUpdated: z.string(), mobileWallet: z.string()}); export const walletAccountTransactionChildEntity = z.object({accountTransactionId: z.string().optional(), accountId: z.string().optional(), parentAccountTransactionId: z.string().optional(), event: z.enum(["ACTIVATE", "AUTOTOPUP", "BALANCE", "BLOCK", "CANCEL", "CREATE", "CREDIT", "DEBIT", "INACTIVATE", "INVALIDATE", "LOAD", "REACTIVATE", "REDEEM", "REFUND", "REISSUE", "RESEND", "SPEND", "STAMP", "STOLEN", "TOPUP", "TRANSFER", "TRANSFER_IN", "UNBLOCK", "UNLOCK", "UNREDEEM", "VERIFY", "VOID"]).optional(), value: z.number().int().optional(), source: z.string().optional(), transactionDetails: z.object({}).optional(), balancesBefore: accountTransactionBalancesHistoryEntity.optional(), balancesAfter: accountTransactionBalancesHistoryEntity.optional(), properties: z.object({}).optional(), dateCreated: z.string().optional(), lastUpdated: z.string().optional(), account: walletAccountEntity.optional(), children: z.unknown(), rewardAccounts: z.array(walletAccountEntity).nullable().optional()}); export const accountTransactionIncludedItem = z.object({type: z.string(), id: z.string().nullable().optional(), attributes: z.object({})}); export const getApiWalletWalletIdAccountAccountIdTransactionsResponse = z.object({limit: z.number().int().optional(), total: z.number().int().optional(), offset: z.number().int().optional(), orderBy: z.array(z.object({name: z.string().optional(), order: z.string().optional()})).optional(), results: z.array(z.object({accountTransactionId: z.string().optional(), accountId: z.string().optional(), parentAccountTransactionId: z.string().optional(), event: z.enum(["CREATE", "REDEEM", "UNLOCK", "UNREDEEM", "VERIFY", "ACTIVATE", "INACTIVATE", "REACTIVATE", "LOAD", "CREDIT", "DEBIT", "BALANCE", "INVALIDATE", "BLOCK", "UNBLOCK", "RESEND", "STOLEN", "CANCEL", "VOID", "REISSUE", "REFUND", "TRANSFER", "TRANSFER_IN", "TOPUP", "AUTOTOPUP", "STAMP", "SPEND"]).optional(), value: z.number().int().optional(), source: z.string().optional(), transactionDetails: z.object({}).optional(), balancesBefore: accountTransactionBalancesHistoryEntity.optional(), balancesAfter: accountTransactionBalancesHistoryEntity.optional(), properties: z.object({}).optional(), dateCreated: z.string().optional(), lastUpdated: z.string().optional(), account: walletAccountEntity.optional(), children: z.array(walletAccountTransactionChildEntity).optional(), rewardAccounts: z.array(z.union([walletAccountEntity, walletAccountTransactionChildEntity])).nullable().optional(), included: z.array(accountTransactionIncludedItem).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 }; /** * Get Account Transactions * * GET /wallet/{walletId}/account/{accountId}/transactions */ export const getApiWalletWalletIdAccountAccountIdTransactions = async (args: GetApiWalletWalletIdAccountAccountIdTransactionsArgs, options?: GetApiWalletWalletIdAccountAccountIdTransactionsOptions) => { 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") for (const item of args.include ?? []) query.append("include", String(item)) if (args.event != null) query.append("event", String(args.event)) if (args.dateCreated != null) query.append("dateCreated", String(args.dateCreated)) if (args.lastUpdated != null) query.append("lastUpdated", String(args.lastUpdated)) if (args.parentAccountTransactionId != null) query.append("parentAccountTransactionId", String(args.parentAccountTransactionId)) if (args.accountTransactionId != null) query.append("accountTransactionId", String(args.accountTransactionId)) if (args.source != null) query.append("source", String(args.source)) if (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.walletTransactions != null) query.append("walletTransactions", String(args.walletTransactions)) 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))}/account/${encodeURIComponent(String(args.accountId))}/transactions${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(getApiWalletWalletIdAccountAccountIdTransactionsResponse, await res.json()) };