import {z} from 'zod' export type GetApiV2PaymentCardsPaymentCardIdTransactionsTransactionIdArgs = {payment_card_id: string, transaction_id: string, search?: string | undefined}; export type GetApiV2PaymentCardsPaymentCardIdTransactionsTransactionIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const paymentCardTransactionList = z.object({id: z.string(), status: z.string(), amount: z.string(), posted_at: z.string().nullable(), effective_at: z.string().nullable(), description: z.string().nullable(), direction: z.string(), mcc: z.string().nullable().optional(), merchant_category: z.string().nullable().optional(), merchant_name: z.string().nullable().optional(), merchant_id: z.string().nullable().optional(), transaction_type: z.string().nullable().optional(), related_transaction_id: z.string().nullable().optional(), payment_outstanding: z.string().nullable().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 Payment Card Transaction * * GET /v2/payment-cards/{payment_card_id}/transactions/{transaction_id} */ export const getApiV2PaymentCardsPaymentCardIdTransactionsTransactionId = async (args: GetApiV2PaymentCardsPaymentCardIdTransactionsTransactionIdArgs, options?: GetApiV2PaymentCardsPaymentCardIdTransactionsTransactionIdOptions) => { const {baseUrl = "https://api.upwardli.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.search != null) query.append("search", String(args.search)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/payment-cards/${encodeURIComponent(String(args.payment_card_id))}/transactions/${encodeURIComponent(String(args.transaction_id))}${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(paymentCardTransactionList, await res.json()) };