import {z} from 'zod' export type GetApiWalletWalletIdAccountAccountIdPointsAvailableArgs = {walletId: unknown, accountId: unknown, 'orderBy[]'?: unknown | undefined}; export type GetApiWalletWalletIdAccountAccountIdPointsAvailableOptions = {baseUrl?: string | undefined, eesAuthenticationClientId?: string | undefined, eesAuthenticationHash?: string | undefined, fetch?: typeof fetch | undefined}; export const accountPointsAvailableEntity = z.object({points: z.number().int().optional(), records: z.number().int().optional(), validTo: z.string().optional()}); export const getApiWalletWalletIdAccountAccountIdPointsAvailableResponse = z.object({limit: z.number().int().optional(), total: z.number().int().optional(), totalRecords: z.number().int().optional(), offset: z.number().int().optional(), orderBy: z.array(z.object({name: z.string().optional(), order: z.enum(["ASC", "DESC"]).optional()})).optional(), results: z.array(accountPointsAvailableEntity).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 }; /** * Retrieve Available Loyalty Points * * GET /wallet/{walletId}/account/{accountId}/points/available */ export const getApiWalletWalletIdAccountAccountIdPointsAvailable = async (args: GetApiWalletWalletIdAccountAccountIdPointsAvailableArgs, options?: GetApiWalletWalletIdAccountAccountIdPointsAvailableOptions) => { 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['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))}/account/${encodeURIComponent(String(args.accountId))}/points/available${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(getApiWalletWalletIdAccountAccountIdPointsAvailableResponse, await res.json()) };