import {z} from 'zod' export type GetApiV1PaymentLinksIdTransactionsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1PaymentLinksIdTransactionsResponse = z.object({data: z.array(z.object({amlScreening: z.object({message: z.string().optional(), provider: z.string().optional(), status: z.string().optional()}).optional(), amount: z.string().optional(), amountPaid: z.string().optional(), amountUSD: z.string().nullable().optional(), asset: z.object({address: z.string().optional(), configurations: z.unknown(), createdAt: z.string().optional(), currency: z.string().optional(), decimals: z.number().optional(), id: z.string().optional(), isActive: z.boolean().optional(), isNative: z.boolean().optional(), name: z.string().optional(), network: z.string().optional(), standard: z.string().optional(), symbol: z.string().optional(), updatedAt: z.string().optional()}).optional(), assetSwept: z.boolean().optional(), assetSweptAmount: z.string().optional(), assetSweptAt: z.string().optional(), assetSweptGasFee: z.string().optional(), assetSweptHash: z.string().optional(), assetSweptRecipientAddress: z.string().optional(), assetSweptSenderAddress: z.string().optional(), blockHash: z.string().optional(), blockNumber: z.number().optional(), blockchain: z.object({configurations: z.unknown(), createdAt: z.string().optional(), derivationPath: z.string().optional(), id: z.string().optional(), isActive: z.boolean().optional(), isEvmCompatible: z.boolean().optional(), isL2: z.boolean().optional(), name: z.string().optional(), networkFeeModel: z.string().optional(), slug: z.string().optional(), symbol: z.string().optional(), tokenStandard: z.string().optional(), updatedAt: z.string().optional()}).optional(), chainId: z.number().optional(), confirmations: z.number().optional(), confirmed: z.boolean().optional(), createdAt: z.string().optional(), createdChannel: z.string().optional(), currency: z.string().optional(), customer: z.object({createdAt: z.string().optional(), email: z.string().optional(), id: z.string().optional(), name: z.string().nullable().optional(), network: z.string().optional(), phone: z.unknown(), status: z.string().optional(), updatedAt: z.string().optional()}).optional(), fee: z.unknown(), feeHash: z.unknown(), feeUSD: z.unknown(), gasFee: z.string().optional(), gasPrice: z.string().optional(), gasUsed: z.string().optional(), hash: z.string().optional(), id: z.string().optional(), isAutoSweep: z.boolean().optional(), metadata: z.unknown(), network: z.string().optional(), note: z.unknown(), rate: z.unknown(), rateUSD: z.string().nullable().optional(), reason: z.string().optional(), recipientAddress: z.string().optional(), reference: z.string().optional(), senderAddress: z.string().optional(), signedTransaction: z.unknown(), status: z.string().optional(), toAmount: z.unknown(), toCurrency: z.unknown(), tokenAddress: z.string().optional(), type: z.string().optional(), updatedAt: z.string().optional()})).optional(), message: z.string().optional(), meta: z.object({currentPage: z.number().optional(), itemCount: z.number().optional(), itemsPerPage: z.number().optional(), totalItems: z.number().optional(), totalPages: z.number().optional()}).optional(), statusCode: z.number().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 Transactions * * GET /v1/payment_links/{id}/transactions */ export const getApiV1PaymentLinksIdTransactions = async (options?: GetApiV1PaymentLinksIdTransactionsOptions) => { const {baseUrl = "https://api.blockradar.co", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("x-api-key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/payment_links/${encodeURIComponent(String(args.id))}/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(getApiV1PaymentLinksIdTransactionsResponse, await res.json()) };