import {z} from 'zod' export type GetApiV1CustomersCustomerIdTransfersTransactionIdArgs = {customer_id: string, transaction_id: string}; export type GetApiV1CustomersCustomerIdTransfersTransactionIdOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const transactionId = z.string(); export const idempotencyKey = z.string(); export const transferStatus = z.enum(["PENDING", "COMPLETED", "FAILED"]); export const assetName = z.string(); export const pid = z.string(); export const chronoDateTimeSchema = z.string(); export const internalTransferResponse = z.object({transaction_id: transactionId, idempotency_key: idempotencyKey, status: transferStatus, amount: z.string(), asset: assetName, from_customer_id: pid, from_account_id: z.string().nullable().optional(), to_customer_id: pid, to_account_id: z.string().nullable().optional(), memorandum: z.string().max(256).nullable().optional(), created_at: chronoDateTimeSchema, modified_at: chronoDateTimeSchema}); 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 /v1/customers/{customer_id}/transfers/{transaction_id} */ export const getApiV1CustomersCustomerIdTransfersTransactionId = async (args: GetApiV1CustomersCustomerIdTransfersTransactionIdArgs, options?: GetApiV1CustomersCustomerIdTransfersTransactionIdOptions) => { const {baseUrl = "https://api.1money.com", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Authorization !== undefined) headers.set('authorization', `Bearer ${Authorization}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/${encodeURIComponent(String(args.customer_id))}/transfers/${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(internalTransferResponse, await res.json()) };