import {z} from 'zod' export type GetApiWebhooksWebhookIdNotificationsNotificationIdArgs = {includeData?: boolean | undefined, webhookId: string, notificationId: string}; export type GetApiWebhooksWebhookIdNotificationsNotificationIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const notificationStatus = z.enum(["COMPLETED", "FAILED", "IN_PROGRESS", "ON_HOLD"]); export const webhookEvent = z.enum(["transaction.created", "transaction.status.updated", "transaction.approval_status.updated", "transaction.network_records.processing_completed", "transaction.alert.stuck", "external_wallet.asset.added", "external_wallet.asset.removed", "internal_wallet.asset.added", "internal_wallet.asset.removed", "contract_wallet.asset.added", "contract_wallet.asset.removed", "vault_account.created", "vault_account.asset.added", "vault_account.asset.balance_updated", "vault_account.nft.balance_updated", "vault_account.bulk_create_job_started", "vault_account.bulk_create_job_ended", "vault_account.asset.bulk_add_job_started", "vault_account.asset.bulk_add_job_ended", "embedded_wallet.status.updated", "embedded_wallet.created", "embedded_wallet.asset.balance_updated", "embedded_wallet.asset.added", "embedded_wallet.account.created", "embedded_wallet.device.added", "onchain_data.updated", "connection.added", "connection.removed", "connection.request.waiting_peer_approval", "connection.request.rejected_by_peer", "exchange_account.connected", "fiat_account.connected", "connected_account.connected", "exchange_account.credentials_replaced", "connected_account.credentials_replaced", "ticket.created", "ticket.submitted", "ticket.expired", "ticket.canceled", "ticket.fulfilled", "ticket.counterparty.added", "ticket.counterparty_external_id.set", "ticket.note.added", "ticket.expires_at.set", "ticket.expires_in.set", "ticket.term.added", "ticket.term.updated", "ticket.term.deleted", "ticket.term.funded", "ticket.term.manually_funded", "ticket.term.funding_canceled", "ticket.term.funding_failed", "ticket.term.funding_completed", "ticket.term.transaction_status_changed", "settlement.created", "order.updated", "automation_execution.update"]); export const notificationWithData = z.object({id: z.string(), createdAt: z.number().int(), updatedAt: z.number().int(), status: notificationStatus, eventType: webhookEvent, resourceId: z.string().nullable().optional(), data: z.object({}).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 notification by id * * GET /webhooks/{webhookId}/notifications/{notificationId} */ export const getApiWebhooksWebhookIdNotificationsNotificationId = async (args: GetApiWebhooksWebhookIdNotificationsNotificationIdArgs, options?: GetApiWebhooksWebhookIdNotificationsNotificationIdOptions) => { const {baseUrl = "https://api.fireblocks.io/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.includeData != null) query.append("includeData", String(args.includeData)) const url = `${baseUrl.replace(/\/+$/, '')}/webhooks/${encodeURIComponent(String(args.webhookId))}/notifications/${encodeURIComponent(String(args.notificationId))}${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(notificationWithData, await res.json()) };