@coinbase/cdp-sdk
Version:
SDK for interacting with the Coinbase Developer Platform Wallet API
58 lines • 2.37 kB
JavaScript
;
/**
* @module Client
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebhooksClient = void 0;
const createWebhookSubscription_js_1 = require("../../actions/webhooks/createWebhookSubscription.js");
const analytics_js_1 = require("../../analytics.js");
const index_js_1 = require("../../openapi-client/index.js");
/**
* The namespace containing all webhook methods.
*/
class WebhooksClient {
/**
* Creates a webhook subscription for wallet transaction events.
*
* @param {CreateWebhookSubscriptionOptions} options - Parameters for creating the webhook subscription.
* @param {string} [options.description] - A description of the webhook subscription.
* @param {WebhookEventType[]} options.eventTypes - The event types to subscribe to.
* @param {string} options.targetUrl - The URL to deliver webhook events to.
* @param {Record<string, string>} [options.targetHeaders] - Additional headers to include in webhook requests.
* @param {boolean} [options.isEnabled] - Whether the subscription is enabled. Defaults to `true`.
* @param {Record<string, string>} [options.metadata] - Additional metadata for the subscription.
*
* @returns A promise that resolves to the created webhook subscription.
*
* @example
* ```ts
* const subscription = await cdp.webhooks.createSubscription({
* description: "Monitor wallet transactions",
* eventTypes: [
* "wallet.transaction.pending",
* "wallet.transaction.confirmed",
* "wallet.transaction.failed",
* ],
* targetUrl: "https://example.com/webhook",
* isEnabled: true,
* });
*
* console.log("Subscription ID:", subscription.subscriptionId);
* console.log("Secret:", subscription.secret);
* ```
*/
async createSubscription(options) {
analytics_js_1.Analytics.trackAction({
action: "create_webhook_subscription",
});
try {
return await (0, createWebhookSubscription_js_1.createWebhookSubscription)(index_js_1.CdpOpenApiClient, options);
}
catch (error) {
analytics_js_1.Analytics.trackError(error, "createWebhookSubscription");
throw error;
}
}
}
exports.WebhooksClient = WebhooksClient;
//# sourceMappingURL=webhooks.js.map