import {z} from 'zod' export type GetApiV1WalletsWalletIdWebhooksArgs = {page?: string | undefined, limit?: string | undefined}; export type GetApiV1WalletsWalletIdWebhooksOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1WalletsWalletIdWebhooksResponse = z.object({data: z.array(z.object({attempts: z.number().optional(), createdAt: z.string().optional(), event: z.string().optional(), id: z.string().optional(), payload: z.object({address: z.object({}).nullable().optional(), amlScreening: z.object({message: z.string().optional(), provider: z.string().optional(), status: z.string().optional()}).optional(), amount: z.string().optional(), amountPaid: z.string().optional(), asset: z.object({address: z.string().optional(), createdAt: z.string().optional(), decimals: z.number().optional(), id: z.string().optional(), isActive: 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().nullable().optional(), assetSweptAmount: z.string().nullable().optional(), assetSweptAt: z.string().nullable().optional(), assetSweptGasFee: z.string().nullable().optional(), assetSweptHash: z.string().nullable().optional(), assetSweptRecipientAddress: z.string().nullable().optional(), assetSweptSenderAddress: z.string().nullable().optional(), blockHash: z.string().optional(), blockNumber: z.number().optional(), blockchain: z.object({createdAt: z.string().optional(), derivationPath: z.string().optional(), id: z.string().optional(), isActive: z.boolean().optional(), isEvmCompatible: z.boolean().optional(), name: z.string().optional(), slug: z.string().optional(), symbol: z.string().optional(), tokenStandard: z.string().optional(), updatedAt: z.string().optional()}).optional(), confirmations: z.number().optional(), confirmed: z.boolean().optional(), createdAt: z.string().optional(), currency: z.string().optional(), gasFee: z.string().optional(), gasPrice: z.string().optional(), gasUsed: z.string().optional(), hash: z.string().optional(), id: z.string().optional(), metadata: z.unknown(), network: z.string().optional(), note: z.unknown(), reason: z.string().nullable().optional(), recipientAddress: z.string().optional(), reference: z.string().optional(), senderAddress: z.string().optional(), status: z.string().optional(), type: z.string().optional(), updatedAt: z.string().optional(), wallet: z.object({address: z.string().optional(), business: z.object({createdAt: z.string().optional(), id: z.string().optional(), name: z.string().optional(), sector: z.string().optional(), status: z.string().optional(), updatedAt: z.string().optional()}).optional(), createdAt: z.string().optional(), derivationPath: z.string().optional(), description: z.string().optional(), id: z.string().optional(), isActive: z.boolean().optional(), name: z.string().optional(), network: z.string().optional(), updatedAt: z.string().optional()}).optional()}).optional(), reference: z.string().optional(), response: z.union([z.object({status: z.number().optional(), text: z.string().optional()}), z.string(), z.string(), z.string()]).optional(), status: z.string().optional(), updatedAt: z.string().optional(), url: 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 }; /** * Webhooks Logs * * GET /v1/wallets/{walletId}/webhooks */ export const getApiV1WalletsWalletIdWebhooks = async (args: GetApiV1WalletsWalletIdWebhooksArgs, options?: GetApiV1WalletsWalletIdWebhooksOptions) => { 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 (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (apiKey !== undefined) headers.set("x-api-key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/wallets/${encodeURIComponent(String(args.walletId))}/webhooks${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(getApiV1WalletsWalletIdWebhooksResponse, await res.json()) };