UNPKG

@coinbase/cdp-sdk

Version:

SDK for interacting with the Coinbase Developer Platform Wallet API

203 lines (178 loc) 7.17 kB
/** * Generated by orval v7.21.0 🍺 * Do not edit manually. * Coinbase Developer Platform APIs * The Coinbase Developer Platform APIs - leading the world's transition onchain. * OpenAPI spec version: 2.0.0 */ import type { ListWebhookSubscriptionEventsParams, ListWebhookSubscriptionsParams, WebhookEventListResponse, WebhookSubscriptionListResponse, WebhookSubscriptionRequest, WebhookSubscriptionResponse, WebhookSubscriptionUpdateRequest, } from "../coinbaseDeveloperPlatformAPIs.schemas.js"; import { cdpApiClient } from "../../cdpApiClient.js"; type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1]; /** * Retrieve a paginated list of webhook subscriptions for the authenticated project. Returns subscriptions for all CDP product events (onchain, onramp/offramp, wallet, etc.) in descending order by creation time. ### Use Cases - Monitor all active webhook subscriptions across CDP products - Audit webhook configurations - Manage subscription lifecycle * @summary List webhook subscriptions */ export const listWebhookSubscriptions = ( params?: ListWebhookSubscriptionsParams, options?: SecondParameter<typeof cdpApiClient<WebhookSubscriptionListResponse>>, ) => { return cdpApiClient<WebhookSubscriptionListResponse>( { url: `/v2/data/webhooks/subscriptions`, method: "GET", params }, options, ); }; /** * Subscribe to real-time events across CDP products. ### Filtering Onchain events can utilize multi-label filtering to only receive events that match all the specified labels. Allows labels are: - `network` (required) — Blockchain network - `contract_address` — Smart contract address - `event_name` — Event name (e.g., "Transfer", "Burn") - `event_signature` — Event signature (e.g., "Transfer(address,address,uint256)") - `transaction_from` — Transaction sender address - `transaction_to` — Transaction recipient address - `params.*` — Any event parameter from the log event (e.g., `params.from`, `params.to`, `params.sender`, `params.tokenId`) For webhook types that aren't `onchain.*`, labels are ignored. ### Webhook Signature Verification All webhooks include an HMAC-SHA256 signed header for security. The signature is signed with the secret that is returned in the `secret` field when creating a subscription. Do not lose the secret, as you will not be able to recreate it. If you lose the secret, you will need to create a new subscription. See the [verification guide](https://docs.cdp.coinbase.com/onramp-&-offramp/webhooks#webhook-signature-verification) for implementation details. * @summary Create webhook subscription */ export const createWebhookSubscription = ( webhookSubscriptionRequest: WebhookSubscriptionRequest, options?: SecondParameter<typeof cdpApiClient<WebhookSubscriptionResponse>>, ) => { return cdpApiClient<WebhookSubscriptionResponse>( { url: `/v2/data/webhooks/subscriptions`, method: "POST", headers: { "Content-Type": "application/json" }, data: webhookSubscriptionRequest, }, options, ); }; /** * Retrieve detailed information about a specific webhook subscription including configuration, status, creation timestamp, and webhook signature secret. ### Response Includes - Subscription configuration and filters - Target URL and custom headers - Webhook signature secret for verification - Creation timestamp and status * @summary Get webhook subscription */ export const getWebhookSubscription = ( subscriptionId: string, options?: SecondParameter<typeof cdpApiClient<WebhookSubscriptionResponse>>, ) => { return cdpApiClient<WebhookSubscriptionResponse>( { url: `/v2/data/webhooks/subscriptions/${subscriptionId}`, method: "GET" }, options, ); }; /** * Update an existing webhook subscription's configuration including event types, target URL, filtering criteria, and enabled status. All required fields must be provided, even if they are not being changed. ### Common Updates - Change target URL or headers - Add/remove event type filters - Update multi-label filtering criteria - Enable/disable subscription * @summary Update webhook subscription */ export const updateWebhookSubscription = ( subscriptionId: string, webhookSubscriptionUpdateRequest: WebhookSubscriptionUpdateRequest, options?: SecondParameter<typeof cdpApiClient<WebhookSubscriptionResponse>>, ) => { return cdpApiClient<WebhookSubscriptionResponse>( { url: `/v2/data/webhooks/subscriptions/${subscriptionId}`, method: "PUT", headers: { "Content-Type": "application/json" }, data: webhookSubscriptionUpdateRequest, }, options, ); }; /** * Permanently delete a webhook subscription and stop all event deliveries. This action cannot be undone. ### Important Notes - All webhook deliveries will cease immediately - Subscription cannot be recovered after deletion - Consider disabling instead of deleting for temporary pauses * @summary Delete webhook subscription */ export const deleteWebhookSubscription = ( subscriptionId: string, options?: SecondParameter<typeof cdpApiClient<void>>, ) => { return cdpApiClient<void>( { url: `/v2/data/webhooks/subscriptions/${subscriptionId}`, method: "DELETE" }, options, ); }; /** * Retrieve webhook event delivery attempts for a specific subscription. Returns event deliveries in descending order by creation time (newest first), including delivery status, retry count, and response details. ### Use Cases - Debug webhook delivery failures and inspect response codes - Monitor delivery status and retry counts - Audit event delivery history for a subscription - Verify that expected events were sent to webhook URLs ### Filtering Use optional query parameters to narrow results: - `eventId` — find a specific event by ID - `minCreatedAt` / `maxCreatedAt` — filter by time range - `eventTypeNames` — filter by event type (comma-separated) **Note:** Results are limited to the 50 most recent events (newest first). No pagination is supported. * @summary List webhook subscription events */ export const listWebhookSubscriptionEvents = ( subscriptionId: string, params?: ListWebhookSubscriptionEventsParams, options?: SecondParameter<typeof cdpApiClient<WebhookEventListResponse>>, ) => { return cdpApiClient<WebhookEventListResponse>( { url: `/v2/data/webhooks/subscriptions/${subscriptionId}/events`, method: "GET", params }, options, ); }; export type ListWebhookSubscriptionsResult = NonNullable< Awaited<ReturnType<typeof listWebhookSubscriptions>> >; export type CreateWebhookSubscriptionResult = NonNullable< Awaited<ReturnType<typeof createWebhookSubscription>> >; export type GetWebhookSubscriptionResult = NonNullable< Awaited<ReturnType<typeof getWebhookSubscription>> >; export type UpdateWebhookSubscriptionResult = NonNullable< Awaited<ReturnType<typeof updateWebhookSubscription>> >; export type DeleteWebhookSubscriptionResult = NonNullable< Awaited<ReturnType<typeof deleteWebhookSubscription>> >; export type ListWebhookSubscriptionEventsResult = NonNullable< Awaited<ReturnType<typeof listWebhookSubscriptionEvents>> >;