@dakota-xyz/ts-sdk 1.6.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,11 +15,21 @@ declare enum WebhookEventType {
15
15
  ApiKeyDeleted = "api_key.deleted",
16
16
  CustomerCreated = "customer.created",
17
17
  CustomerUpdated = "customer.updated",
18
+ CustomerDeleted = "customer.deleted",
18
19
  CustomerKybLinkCreated = "customer.kyb_link.created",
19
20
  CustomerKybLinkUpdated = "customer.kyb_link.updated",
20
21
  CustomerKybStatusCreated = "customer.kyb_status.created",
21
22
  CustomerKybStatusUpdated = "customer.kyb_status.updated",
22
23
  CustomerKybApplicationSubmitted = "customer.kyb_application.submitted",
24
+ /**
25
+ * Emitted when a customer's standing for a capability (rail) changes. The
26
+ * payload is {@link CustomerCapabilityStatusUpdatedData}.
27
+ */
28
+ CustomerCapabilityStatusUpdated = "customer.capability_status.updated",
29
+ /** Payload is {@link FeePayoutDestinationUpdatedData}. */
30
+ FeePayoutDestinationUpdated = "fee_payout_destination.updated",
31
+ /** Payload is an empty object. */
32
+ FeePayoutDestinationDeleted = "fee_payout_destination.deleted",
23
33
  AutoAccountCreated = "auto_account.created",
24
34
  AutoAccountUpdated = "auto_account.updated",
25
35
  AutoAccountDeleted = "auto_account.deleted",
@@ -52,6 +62,12 @@ declare enum WebhookEventType {
52
62
  WalletTransactionCreated = "wallet.transaction.created",
53
63
  WalletTransactionUpdated = "wallet.transaction.updated",
54
64
  WalletDeposit = "wallet.deposit",
65
+ /**
66
+ * Emitted when a scheduled payment flips to the failed terminal state (the
67
+ * async agentic-payments actor's one silent state change). Its payload is
68
+ * {@link ScheduledPaymentFailedData}.
69
+ */
70
+ ScheduledPaymentFailed = "scheduled_payment.failed",
55
71
  /** @deprecated Use TransactionAutoCreated or TransactionOneOffCreated */
56
72
  TransactionCreated = "transaction.created",
57
73
  /** @deprecated Use TransactionAutoUpdated or TransactionOneOffUpdated */
@@ -67,16 +83,37 @@ declare enum WebhookEventType {
67
83
  /** @deprecated Use AutoAccountUpdated */
68
84
  AccountUpdated = "account.updated"
69
85
  }
86
+ /**
87
+ * Event payload container. `object` holds the resource the event is about;
88
+ * `previous_attributes`, when present, holds the prior values of the fields
89
+ * that changed on an update event.
90
+ */
91
+ interface WebhookEventData<T = unknown> {
92
+ /** The resource the event is about */
93
+ object: T;
94
+ /** Prior values of the fields that changed (update events only) */
95
+ previous_attributes?: Record<string, unknown>;
96
+ }
97
+ /**
98
+ * Request context that produced the event, when known.
99
+ */
100
+ interface WebhookEventRequest {
101
+ id?: string;
102
+ idempotency_key?: string;
103
+ }
70
104
  /**
71
105
  * Webhook event structure.
106
+ *
107
+ * Mirrors the platform's public event envelope: the resource the event is
108
+ * about lives under `data.object`, and `created` is the emission time in unix
109
+ * seconds. Earlier SDK versions typed the payload flat as `data`, which never
110
+ * matched what the platform actually sends.
72
111
  */
73
112
  interface WebhookEvent<T = unknown> {
74
113
  /** Unique event ID */
75
114
  id: string;
76
115
  /** Event type */
77
116
  type: string;
78
- /** Event data payload */
79
- data: T;
80
117
  /**
81
118
  * Unix timestamp (seconds) when the event was created.
82
119
  *
@@ -85,8 +122,105 @@ interface WebhookEvent<T = unknown> {
85
122
  * `created_at`, which was always `undefined` at runtime.
86
123
  */
87
124
  created: number;
88
- /** API version */
125
+ /** Envelope version (e.g. '1.0.0') */
89
126
  api_version?: string;
127
+ /** Event data payload */
128
+ data: WebhookEventData<T>;
129
+ /** Free-form metadata attached to the event, when present */
130
+ metadata?: Record<string, unknown>;
131
+ /** Request context that produced the event, when known */
132
+ request?: WebhookEventRequest;
133
+ }
134
+ /**
135
+ * KYB Link event data.
136
+ */
137
+ interface KybLinkData {
138
+ customer_id: string;
139
+ /** e.g. 'onboarding' */
140
+ link_type: string;
141
+ url: string;
142
+ status: string;
143
+ /** Unix seconds; omitted when the link does not expire */
144
+ expires_at?: number;
145
+ }
146
+ /**
147
+ * KYB Application Submitted event data.
148
+ */
149
+ interface KybApplicationSubmittedData {
150
+ customer_id: string;
151
+ application_id: string;
152
+ application_type: string;
153
+ }
154
+ /**
155
+ * Customer Deleted event data.
156
+ */
157
+ interface CustomerDeletedData {
158
+ customer_id: string;
159
+ }
160
+ /**
161
+ * A single outstanding capability requirement, keyed by an opaque join key
162
+ * (a terms id or a document type) — never a partner identifier.
163
+ */
164
+ interface CapabilityRequirement {
165
+ /** 'terms_acceptance' or 'document' */
166
+ type: string;
167
+ /** Opaque join key: a terms id (terms_acceptance) or a document type (document) */
168
+ key: string;
169
+ title: string;
170
+ /** 'required' blocks submission/unlock; 'requested' pre-empts an RFI, not blocking */
171
+ severity: string;
172
+ version?: string;
173
+ url?: string;
174
+ }
175
+ /**
176
+ * Customer Capability Status Updated event data.
177
+ *
178
+ * Emitted when a customer's standing for a capability (rail) changes; carries
179
+ * the capability, the new status, and the outstanding requirements.
180
+ */
181
+ interface CustomerCapabilityStatusUpdatedData {
182
+ customer_id: string;
183
+ capability: string;
184
+ /** e.g. 'available' | 'enabling' | 'action_required' */
185
+ status: string;
186
+ requirements: CapabilityRequirement[];
187
+ }
188
+ /**
189
+ * Fee Payout Destination Updated event data.
190
+ */
191
+ interface FeePayoutDestinationUpdatedData {
192
+ /** The destination kind — 'usdc_wallet' (developer-fee payouts are crypto-only) */
193
+ type: string;
194
+ }
195
+ /**
196
+ * Event payload for {@link WebhookEventType.ScheduledPaymentFailed}
197
+ * ('scheduled_payment.failed'), emitted when a scheduled payment flips to the
198
+ * failed terminal state.
199
+ *
200
+ * A successful scheduled fire already surfaces as wallet.transaction.created
201
+ * through the shared money path; failure is the actionable case (re-approve an
202
+ * expired mandate, fund the wallet, fix a destination), and `failure_reason`
203
+ * carries the humanized verdict while `failure_code` is the stable machine
204
+ * code.
205
+ *
206
+ * `payment_agent_id`, `recipient_id`, and `destination_id` are omitted for
207
+ * schedules that have no such linkage (a signer-native schedule, or one paying
208
+ * a bare address); `address` is always the crypto address the row pays.
209
+ */
210
+ interface ScheduledPaymentFailedData {
211
+ scheduled_payment_id: string;
212
+ signer_id: string;
213
+ wallet_id: string;
214
+ address: string;
215
+ amount: string;
216
+ asset: string;
217
+ network_id: string;
218
+ scheduled_at: number;
219
+ failure_code: string;
220
+ failure_reason: string;
221
+ payment_agent_id?: string;
222
+ recipient_id?: string;
223
+ destination_id?: string;
90
224
  }
91
225
  /**
92
226
  * Parse a webhook event from a JSON payload.
@@ -210,13 +344,13 @@ interface WebhookHeaders {
210
344
  * publicKey: process.env.WEBHOOK_PUBLIC_KEY!,
211
345
  * });
212
346
  *
213
- * // Register event handlers
347
+ * // Register event handlers. The resource lives under event.data.object.
214
348
  * handler.on(WebhookEventType.CustomerCreated, async (event) => {
215
- * console.log('Customer created:', event.data);
349
+ * console.log('Customer created:', event.data.object);
216
350
  * });
217
351
  *
218
352
  * handler.on('transaction.*', async (event) => {
219
- * console.log('Transaction event:', event.type, event.data);
353
+ * console.log('Transaction event:', event.type, event.data.object);
220
354
  * });
221
355
  *
222
356
  * handler.onDefault(async (event) => {
@@ -412,4 +546,4 @@ declare function verifySignature(payload: Uint8Array | string, signatureB64: str
412
546
  */
413
547
  declare function verifySignatureSync(payload: Uint8Array | string, signatureB64: string, timestampStr: string, publicKeyHex: string, toleranceSeconds?: number): void;
414
548
 
415
- export { DEFAULT_TIMESTAMP_TOLERANCE, type IdempotencyStore, MemoryIdempotencyStore, SIGNATURE_HEADER, SignatureVerificationError, TIMESTAMP_HEADER, type WebhookEvent, type WebhookEventHandler, WebhookEventType, WebhookHandler, type WebhookHandlerConfig, type WebhookHeaders, matchesEventType, parseEvent, parsePublicKey, parseSignature, validateTimestamp, verifySignature, verifySignatureSync };
549
+ export { type CapabilityRequirement, type CustomerCapabilityStatusUpdatedData, type CustomerDeletedData, DEFAULT_TIMESTAMP_TOLERANCE, type FeePayoutDestinationUpdatedData, type IdempotencyStore, type KybApplicationSubmittedData, type KybLinkData, MemoryIdempotencyStore, SIGNATURE_HEADER, type ScheduledPaymentFailedData, SignatureVerificationError, TIMESTAMP_HEADER, type WebhookEvent, type WebhookEventData, type WebhookEventHandler, type WebhookEventRequest, WebhookEventType, WebhookHandler, type WebhookHandlerConfig, type WebhookHeaders, matchesEventType, parseEvent, parsePublicKey, parseSignature, validateTimestamp, verifySignature, verifySignatureSync };
@@ -15,11 +15,21 @@ declare enum WebhookEventType {
15
15
  ApiKeyDeleted = "api_key.deleted",
16
16
  CustomerCreated = "customer.created",
17
17
  CustomerUpdated = "customer.updated",
18
+ CustomerDeleted = "customer.deleted",
18
19
  CustomerKybLinkCreated = "customer.kyb_link.created",
19
20
  CustomerKybLinkUpdated = "customer.kyb_link.updated",
20
21
  CustomerKybStatusCreated = "customer.kyb_status.created",
21
22
  CustomerKybStatusUpdated = "customer.kyb_status.updated",
22
23
  CustomerKybApplicationSubmitted = "customer.kyb_application.submitted",
24
+ /**
25
+ * Emitted when a customer's standing for a capability (rail) changes. The
26
+ * payload is {@link CustomerCapabilityStatusUpdatedData}.
27
+ */
28
+ CustomerCapabilityStatusUpdated = "customer.capability_status.updated",
29
+ /** Payload is {@link FeePayoutDestinationUpdatedData}. */
30
+ FeePayoutDestinationUpdated = "fee_payout_destination.updated",
31
+ /** Payload is an empty object. */
32
+ FeePayoutDestinationDeleted = "fee_payout_destination.deleted",
23
33
  AutoAccountCreated = "auto_account.created",
24
34
  AutoAccountUpdated = "auto_account.updated",
25
35
  AutoAccountDeleted = "auto_account.deleted",
@@ -52,6 +62,12 @@ declare enum WebhookEventType {
52
62
  WalletTransactionCreated = "wallet.transaction.created",
53
63
  WalletTransactionUpdated = "wallet.transaction.updated",
54
64
  WalletDeposit = "wallet.deposit",
65
+ /**
66
+ * Emitted when a scheduled payment flips to the failed terminal state (the
67
+ * async agentic-payments actor's one silent state change). Its payload is
68
+ * {@link ScheduledPaymentFailedData}.
69
+ */
70
+ ScheduledPaymentFailed = "scheduled_payment.failed",
55
71
  /** @deprecated Use TransactionAutoCreated or TransactionOneOffCreated */
56
72
  TransactionCreated = "transaction.created",
57
73
  /** @deprecated Use TransactionAutoUpdated or TransactionOneOffUpdated */
@@ -67,16 +83,37 @@ declare enum WebhookEventType {
67
83
  /** @deprecated Use AutoAccountUpdated */
68
84
  AccountUpdated = "account.updated"
69
85
  }
86
+ /**
87
+ * Event payload container. `object` holds the resource the event is about;
88
+ * `previous_attributes`, when present, holds the prior values of the fields
89
+ * that changed on an update event.
90
+ */
91
+ interface WebhookEventData<T = unknown> {
92
+ /** The resource the event is about */
93
+ object: T;
94
+ /** Prior values of the fields that changed (update events only) */
95
+ previous_attributes?: Record<string, unknown>;
96
+ }
97
+ /**
98
+ * Request context that produced the event, when known.
99
+ */
100
+ interface WebhookEventRequest {
101
+ id?: string;
102
+ idempotency_key?: string;
103
+ }
70
104
  /**
71
105
  * Webhook event structure.
106
+ *
107
+ * Mirrors the platform's public event envelope: the resource the event is
108
+ * about lives under `data.object`, and `created` is the emission time in unix
109
+ * seconds. Earlier SDK versions typed the payload flat as `data`, which never
110
+ * matched what the platform actually sends.
72
111
  */
73
112
  interface WebhookEvent<T = unknown> {
74
113
  /** Unique event ID */
75
114
  id: string;
76
115
  /** Event type */
77
116
  type: string;
78
- /** Event data payload */
79
- data: T;
80
117
  /**
81
118
  * Unix timestamp (seconds) when the event was created.
82
119
  *
@@ -85,8 +122,105 @@ interface WebhookEvent<T = unknown> {
85
122
  * `created_at`, which was always `undefined` at runtime.
86
123
  */
87
124
  created: number;
88
- /** API version */
125
+ /** Envelope version (e.g. '1.0.0') */
89
126
  api_version?: string;
127
+ /** Event data payload */
128
+ data: WebhookEventData<T>;
129
+ /** Free-form metadata attached to the event, when present */
130
+ metadata?: Record<string, unknown>;
131
+ /** Request context that produced the event, when known */
132
+ request?: WebhookEventRequest;
133
+ }
134
+ /**
135
+ * KYB Link event data.
136
+ */
137
+ interface KybLinkData {
138
+ customer_id: string;
139
+ /** e.g. 'onboarding' */
140
+ link_type: string;
141
+ url: string;
142
+ status: string;
143
+ /** Unix seconds; omitted when the link does not expire */
144
+ expires_at?: number;
145
+ }
146
+ /**
147
+ * KYB Application Submitted event data.
148
+ */
149
+ interface KybApplicationSubmittedData {
150
+ customer_id: string;
151
+ application_id: string;
152
+ application_type: string;
153
+ }
154
+ /**
155
+ * Customer Deleted event data.
156
+ */
157
+ interface CustomerDeletedData {
158
+ customer_id: string;
159
+ }
160
+ /**
161
+ * A single outstanding capability requirement, keyed by an opaque join key
162
+ * (a terms id or a document type) — never a partner identifier.
163
+ */
164
+ interface CapabilityRequirement {
165
+ /** 'terms_acceptance' or 'document' */
166
+ type: string;
167
+ /** Opaque join key: a terms id (terms_acceptance) or a document type (document) */
168
+ key: string;
169
+ title: string;
170
+ /** 'required' blocks submission/unlock; 'requested' pre-empts an RFI, not blocking */
171
+ severity: string;
172
+ version?: string;
173
+ url?: string;
174
+ }
175
+ /**
176
+ * Customer Capability Status Updated event data.
177
+ *
178
+ * Emitted when a customer's standing for a capability (rail) changes; carries
179
+ * the capability, the new status, and the outstanding requirements.
180
+ */
181
+ interface CustomerCapabilityStatusUpdatedData {
182
+ customer_id: string;
183
+ capability: string;
184
+ /** e.g. 'available' | 'enabling' | 'action_required' */
185
+ status: string;
186
+ requirements: CapabilityRequirement[];
187
+ }
188
+ /**
189
+ * Fee Payout Destination Updated event data.
190
+ */
191
+ interface FeePayoutDestinationUpdatedData {
192
+ /** The destination kind — 'usdc_wallet' (developer-fee payouts are crypto-only) */
193
+ type: string;
194
+ }
195
+ /**
196
+ * Event payload for {@link WebhookEventType.ScheduledPaymentFailed}
197
+ * ('scheduled_payment.failed'), emitted when a scheduled payment flips to the
198
+ * failed terminal state.
199
+ *
200
+ * A successful scheduled fire already surfaces as wallet.transaction.created
201
+ * through the shared money path; failure is the actionable case (re-approve an
202
+ * expired mandate, fund the wallet, fix a destination), and `failure_reason`
203
+ * carries the humanized verdict while `failure_code` is the stable machine
204
+ * code.
205
+ *
206
+ * `payment_agent_id`, `recipient_id`, and `destination_id` are omitted for
207
+ * schedules that have no such linkage (a signer-native schedule, or one paying
208
+ * a bare address); `address` is always the crypto address the row pays.
209
+ */
210
+ interface ScheduledPaymentFailedData {
211
+ scheduled_payment_id: string;
212
+ signer_id: string;
213
+ wallet_id: string;
214
+ address: string;
215
+ amount: string;
216
+ asset: string;
217
+ network_id: string;
218
+ scheduled_at: number;
219
+ failure_code: string;
220
+ failure_reason: string;
221
+ payment_agent_id?: string;
222
+ recipient_id?: string;
223
+ destination_id?: string;
90
224
  }
91
225
  /**
92
226
  * Parse a webhook event from a JSON payload.
@@ -210,13 +344,13 @@ interface WebhookHeaders {
210
344
  * publicKey: process.env.WEBHOOK_PUBLIC_KEY!,
211
345
  * });
212
346
  *
213
- * // Register event handlers
347
+ * // Register event handlers. The resource lives under event.data.object.
214
348
  * handler.on(WebhookEventType.CustomerCreated, async (event) => {
215
- * console.log('Customer created:', event.data);
349
+ * console.log('Customer created:', event.data.object);
216
350
  * });
217
351
  *
218
352
  * handler.on('transaction.*', async (event) => {
219
- * console.log('Transaction event:', event.type, event.data);
353
+ * console.log('Transaction event:', event.type, event.data.object);
220
354
  * });
221
355
  *
222
356
  * handler.onDefault(async (event) => {
@@ -412,4 +546,4 @@ declare function verifySignature(payload: Uint8Array | string, signatureB64: str
412
546
  */
413
547
  declare function verifySignatureSync(payload: Uint8Array | string, signatureB64: string, timestampStr: string, publicKeyHex: string, toleranceSeconds?: number): void;
414
548
 
415
- export { DEFAULT_TIMESTAMP_TOLERANCE, type IdempotencyStore, MemoryIdempotencyStore, SIGNATURE_HEADER, SignatureVerificationError, TIMESTAMP_HEADER, type WebhookEvent, type WebhookEventHandler, WebhookEventType, WebhookHandler, type WebhookHandlerConfig, type WebhookHeaders, matchesEventType, parseEvent, parsePublicKey, parseSignature, validateTimestamp, verifySignature, verifySignatureSync };
549
+ export { type CapabilityRequirement, type CustomerCapabilityStatusUpdatedData, type CustomerDeletedData, DEFAULT_TIMESTAMP_TOLERANCE, type FeePayoutDestinationUpdatedData, type IdempotencyStore, type KybApplicationSubmittedData, type KybLinkData, MemoryIdempotencyStore, SIGNATURE_HEADER, type ScheduledPaymentFailedData, SignatureVerificationError, TIMESTAMP_HEADER, type WebhookEvent, type WebhookEventData, type WebhookEventHandler, type WebhookEventRequest, WebhookEventType, WebhookHandler, type WebhookHandlerConfig, type WebhookHeaders, matchesEventType, parseEvent, parsePublicKey, parseSignature, validateTimestamp, verifySignature, verifySignatureSync };
@@ -551,11 +551,15 @@ var WebhookEventType = /* @__PURE__ */ ((WebhookEventType2) => {
551
551
  WebhookEventType2["ApiKeyDeleted"] = "api_key.deleted";
552
552
  WebhookEventType2["CustomerCreated"] = "customer.created";
553
553
  WebhookEventType2["CustomerUpdated"] = "customer.updated";
554
+ WebhookEventType2["CustomerDeleted"] = "customer.deleted";
554
555
  WebhookEventType2["CustomerKybLinkCreated"] = "customer.kyb_link.created";
555
556
  WebhookEventType2["CustomerKybLinkUpdated"] = "customer.kyb_link.updated";
556
557
  WebhookEventType2["CustomerKybStatusCreated"] = "customer.kyb_status.created";
557
558
  WebhookEventType2["CustomerKybStatusUpdated"] = "customer.kyb_status.updated";
558
559
  WebhookEventType2["CustomerKybApplicationSubmitted"] = "customer.kyb_application.submitted";
560
+ WebhookEventType2["CustomerCapabilityStatusUpdated"] = "customer.capability_status.updated";
561
+ WebhookEventType2["FeePayoutDestinationUpdated"] = "fee_payout_destination.updated";
562
+ WebhookEventType2["FeePayoutDestinationDeleted"] = "fee_payout_destination.deleted";
559
563
  WebhookEventType2["AutoAccountCreated"] = "auto_account.created";
560
564
  WebhookEventType2["AutoAccountUpdated"] = "auto_account.updated";
561
565
  WebhookEventType2["AutoAccountDeleted"] = "auto_account.deleted";
@@ -584,6 +588,7 @@ var WebhookEventType = /* @__PURE__ */ ((WebhookEventType2) => {
584
588
  WebhookEventType2["WalletTransactionCreated"] = "wallet.transaction.created";
585
589
  WebhookEventType2["WalletTransactionUpdated"] = "wallet.transaction.updated";
586
590
  WebhookEventType2["WalletDeposit"] = "wallet.deposit";
591
+ WebhookEventType2["ScheduledPaymentFailed"] = "scheduled_payment.failed";
587
592
  WebhookEventType2["TransactionCreated"] = "transaction.created";
588
593
  WebhookEventType2["TransactionUpdated"] = "transaction.updated";
589
594
  WebhookEventType2["TransactionCompleted"] = "transaction.completed";
@@ -603,8 +608,10 @@ function parseEvent(payload) {
603
608
  if (!event.type || typeof event.type !== "string") {
604
609
  throw new Error("Invalid event: missing or invalid type");
605
610
  }
606
- if (event.data === void 0) {
607
- throw new Error("Invalid event: missing data");
611
+ if (event.data === void 0 || event.data === null) {
612
+ event.data = { object: {} };
613
+ } else if (event.data.object === void 0 || event.data.object === null) {
614
+ event.data.object = {};
608
615
  }
609
616
  return event;
610
617
  } catch (error) {