import {z} from 'zod' export type GetApiLedgerSubaccountsSubAccountIdRefActivitiesActivityIdArgs = {subAccountIdRef: string, activityId: string}; export type GetApiLedgerSubaccountsSubAccountIdRefActivitiesActivityIdOptions = {baseUrl?: string | undefined, HMACAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const transactionActivityType = z.enum(["CASH_DEPOSIT", "CASH_PAYMENT", "ACCOUNT_NUMBER_DEPOSIT", "CRYPTO_WITHDRAWAL", "CRYPTO_DEPOSIT", "INTERNAL_TRANSFER", "OFFRAMP_DEPOSIT", "DEPOSIT_REVERSAL"]); export const activityDirection = z.enum(["CREDIT", "DEBIT"]); export const transactionStatus = z.enum(["PENDING", "IN_PROGRESS", "FAILED", "SUCCESS"]); export const activityAccountType = z.enum(["MAIN", "SUB_ACCOUNT", "OFFRAMP_ACCOUNT", "CARD_ACCOUNT"]); export const transactionActivity = z.object({id: z.string(), activityType: z.string(), type: transactionActivityType, direction: activityDirection, amount: z.number(), currency: z.string(), status: transactionStatus, reference: z.string().optional(), accountId: z.string(), accountType: activityAccountType, subAccountId: z.string().optional(), accountTransactionId: z.string().optional(), groupId: z.string().optional(), narration: z.string().optional(), activityAt: z.string(), underReview: z.boolean().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 a single sub-account transaction activity * * GET /ledger/subaccounts/{subAccountIdRef}/activities/{activityId} */ export const getApiLedgerSubaccountsSubAccountIdRefActivitiesActivityId = async (args: GetApiLedgerSubaccountsSubAccountIdRefActivitiesActivityIdArgs, options?: GetApiLedgerSubaccountsSubAccountIdRefActivitiesActivityIdOptions) => { const {baseUrl = "https://external.dev.onboardpay.co", fetch: fetchFn = fetch, HMACAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HMACAuth !== undefined) headers.set("x-api-key", HMACAuth) const url = `${baseUrl.replace(/\/+$/, '')}/ledger/subaccounts/${encodeURIComponent(String(args.subAccountIdRef))}/activities/${encodeURIComponent(String(args.activityId))}${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(transactionActivity, await res.json()) };