import {z} from 'zod' export type NotificationStatus = 'COMPLETED' | 'FAILED' | 'IN_PROGRESS' | 'ON_HOLD'; export type WebhookEvent = '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 type ResendByQueryRequest = {statuses?: Array | undefined, startTime?: number | undefined, endTime?: number | undefined, events?: Array | undefined, resourceId?: string | undefined}; export type CreateApiWebhooksWebhookIdNotificationsResendByQueryArgs = {'Idempotency-Key'?: string | undefined, webhookId: string, body: ResendByQueryRequest}; export type CreateApiWebhooksWebhookIdNotificationsResendByQueryOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const resendByQueryResponse = z.object({total: 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 }; /** * Resend notifications by query * * POST /webhooks/{webhookId}/notifications/resend_by_query */ export const createApiWebhooksWebhookIdNotificationsResendByQuery = async (args: CreateApiWebhooksWebhookIdNotificationsResendByQueryArgs, options?: CreateApiWebhooksWebhookIdNotificationsResendByQueryOptions) => { const {baseUrl = "https://api.fireblocks.io/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) const url = `${baseUrl.replace(/\/+$/, '')}/webhooks/${encodeURIComponent(String(args.webhookId))}/notifications/resend_by_query${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(resendByQueryResponse, await res.json()) };