@dakota-xyz/ts-sdk 1.0.15

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.
package/dist/index.js ADDED
@@ -0,0 +1,2074 @@
1
+ 'use strict';
2
+
3
+ // src/client/environment.ts
4
+ var Environment = /* @__PURE__ */ ((Environment2) => {
5
+ Environment2["Sandbox"] = "sandbox";
6
+ Environment2["Production"] = "production";
7
+ Environment2["Development"] = "development";
8
+ Environment2["Local"] = "local";
9
+ return Environment2;
10
+ })(Environment || {});
11
+ var ENVIRONMENT_URLS = {
12
+ ["sandbox" /* Sandbox */]: "https://api.platform.sandbox.dakota.xyz",
13
+ ["production" /* Production */]: "https://api.platform.dakota.xyz",
14
+ ["development" /* Development */]: "https://api.platform.development.dakota.xyz",
15
+ ["local" /* Local */]: "http://localhost:6464"
16
+ };
17
+ function getEnvironmentURL(env) {
18
+ const url = ENVIRONMENT_URLS[env];
19
+ if (!url) {
20
+ throw new Error(`Unknown environment: ${env}`);
21
+ }
22
+ return url;
23
+ }
24
+
25
+ // src/client/errors.ts
26
+ var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
27
+ var APIError = class _APIError extends Error {
28
+ /** HTTP status code */
29
+ statusCode;
30
+ /** Machine-readable error code */
31
+ code;
32
+ /** Additional error details */
33
+ details;
34
+ /** Request ID for support tickets */
35
+ requestId;
36
+ /** Raw response body */
37
+ rawBody;
38
+ /** Whether this error is safe to retry */
39
+ retryable;
40
+ constructor(statusCode, code, message, options) {
41
+ super(message);
42
+ this.name = "APIError";
43
+ this.statusCode = statusCode;
44
+ this.code = code;
45
+ this.details = options?.details ?? null;
46
+ this.requestId = options?.requestId ?? null;
47
+ this.rawBody = options?.rawBody ?? null;
48
+ this.retryable = RETRYABLE_STATUS_CODES.has(statusCode);
49
+ if (Error.captureStackTrace) {
50
+ Error.captureStackTrace(this, _APIError);
51
+ }
52
+ }
53
+ /**
54
+ * Create an APIError from an HTTP response.
55
+ */
56
+ static async fromResponse(response) {
57
+ const requestId = response.headers.get("x-request-id");
58
+ let rawBody = null;
59
+ let code = `http_${response.status}`;
60
+ let message = response.statusText || "Unknown error";
61
+ let details = null;
62
+ try {
63
+ rawBody = await response.text();
64
+ const parsed = JSON.parse(rawBody);
65
+ if (parsed.type && typeof parsed.type === "string") {
66
+ const hashIndex = parsed.type.lastIndexOf("#");
67
+ if (hashIndex !== -1) {
68
+ code = parsed.type.substring(hashIndex + 1);
69
+ }
70
+ }
71
+ if (parsed.code) {
72
+ code = parsed.code;
73
+ }
74
+ if (parsed.title) {
75
+ message = parsed.title;
76
+ if (parsed.detail) {
77
+ message = `${parsed.title}: ${parsed.detail}`;
78
+ }
79
+ } else if (parsed.message) {
80
+ message = parsed.message;
81
+ } else if (parsed.detail) {
82
+ message = parsed.detail;
83
+ }
84
+ if (parsed.details && typeof parsed.details === "object") {
85
+ details = parsed.details;
86
+ }
87
+ } catch {
88
+ }
89
+ return new _APIError(response.status, code, message, {
90
+ details,
91
+ requestId,
92
+ rawBody
93
+ });
94
+ }
95
+ toString() {
96
+ if (this.code) {
97
+ return `APIError [${this.statusCode} ${this.code}]: ${this.message}`;
98
+ }
99
+ return `APIError [${this.statusCode}]: ${this.message}`;
100
+ }
101
+ };
102
+ var TransportError = class _TransportError extends Error {
103
+ /** The underlying error that caused this transport error */
104
+ cause;
105
+ constructor(message, cause) {
106
+ super(message);
107
+ this.name = "TransportError";
108
+ this.cause = cause;
109
+ if (Error.captureStackTrace) {
110
+ Error.captureStackTrace(this, _TransportError);
111
+ }
112
+ }
113
+ toString() {
114
+ if (this.cause) {
115
+ return `TransportError: ${this.message} (caused by: ${this.cause.message})`;
116
+ }
117
+ return `TransportError: ${this.message}`;
118
+ }
119
+ };
120
+ var ConfigurationError = class _ConfigurationError extends Error {
121
+ constructor(message) {
122
+ super(message);
123
+ this.name = "ConfigurationError";
124
+ if (Error.captureStackTrace) {
125
+ Error.captureStackTrace(this, _ConfigurationError);
126
+ }
127
+ }
128
+ };
129
+
130
+ // src/client/config.ts
131
+ var AuthMode = /* @__PURE__ */ ((AuthMode2) => {
132
+ AuthMode2["Auto"] = "auto";
133
+ AuthMode2["APIKey"] = "api_key";
134
+ AuthMode2["ApplicationToken"] = "application_token";
135
+ return AuthMode2;
136
+ })(AuthMode || {});
137
+ var DEFAULT_RETRY_POLICY = {
138
+ maxAttempts: 3,
139
+ initialBackoffMs: 200,
140
+ maxBackoffMs: 2e3
141
+ };
142
+ var noopLogger = {
143
+ debug: () => {
144
+ },
145
+ info: () => {
146
+ },
147
+ warn: () => {
148
+ },
149
+ error: () => {
150
+ }
151
+ };
152
+ var consoleLogger = {
153
+ debug: (msg, ...args) => console.debug(`[Dakota SDK] ${msg}`, ...args),
154
+ info: (msg, ...args) => console.info(`[Dakota SDK] ${msg}`, ...args),
155
+ warn: (msg, ...args) => console.warn(`[Dakota SDK] ${msg}`, ...args),
156
+ error: (msg, ...args) => console.error(`[Dakota SDK] ${msg}`, ...args)
157
+ };
158
+ function generateUUID() {
159
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
160
+ const r = Math.random() * 16 | 0;
161
+ const v = c === "x" ? r : r & 3 | 8;
162
+ return v.toString(16);
163
+ });
164
+ }
165
+ function resolveConfig(config) {
166
+ const authMode = config.authMode ?? "auto" /* Auto */;
167
+ if (authMode === "auto" /* Auto */) {
168
+ if (!config.apiKey && !config.applicationToken) {
169
+ throw new ConfigurationError("API key or application token is required");
170
+ }
171
+ } else if (authMode === "api_key" /* APIKey */) {
172
+ if (!config.apiKey) {
173
+ throw new ConfigurationError("API key is required when using AuthMode.APIKey");
174
+ }
175
+ } else if (authMode === "application_token" /* ApplicationToken */) {
176
+ if (!config.applicationToken) {
177
+ throw new ConfigurationError(
178
+ "Application token is required when using AuthMode.ApplicationToken"
179
+ );
180
+ }
181
+ }
182
+ let baseURL;
183
+ if (config.baseURL) {
184
+ baseURL = config.baseURL.replace(/\/$/, "");
185
+ try {
186
+ new URL(baseURL);
187
+ } catch {
188
+ throw new ConfigurationError("Invalid base URL");
189
+ }
190
+ } else {
191
+ const env = config.environment ?? "sandbox" /* Sandbox */;
192
+ baseURL = getEnvironmentURL(env);
193
+ }
194
+ const timeout = config.timeout ?? 15e3;
195
+ if (timeout <= 0) {
196
+ throw new ConfigurationError("Timeout must be greater than zero");
197
+ }
198
+ const retryPolicy = {
199
+ maxAttempts: config.retryPolicy?.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts,
200
+ initialBackoffMs: config.retryPolicy?.initialBackoffMs ?? DEFAULT_RETRY_POLICY.initialBackoffMs,
201
+ maxBackoffMs: config.retryPolicy?.maxBackoffMs ?? DEFAULT_RETRY_POLICY.maxBackoffMs
202
+ };
203
+ if (retryPolicy.maxAttempts <= 0) {
204
+ throw new ConfigurationError("Retry max attempts must be greater than zero");
205
+ }
206
+ if (retryPolicy.initialBackoffMs <= 0) {
207
+ throw new ConfigurationError("Retry initial backoff must be greater than zero");
208
+ }
209
+ if (retryPolicy.maxBackoffMs <= 0) {
210
+ throw new ConfigurationError("Retry max backoff must be greater than zero");
211
+ }
212
+ if (retryPolicy.maxBackoffMs < retryPolicy.initialBackoffMs) {
213
+ throw new ConfigurationError("Retry max backoff must be >= initial backoff");
214
+ }
215
+ return {
216
+ apiKey: config.apiKey ?? null,
217
+ applicationToken: config.applicationToken ?? null,
218
+ baseURL,
219
+ authMode,
220
+ timeout,
221
+ retryPolicy,
222
+ logger: config.logger ?? noopLogger,
223
+ automaticIdempotency: config.automaticIdempotency ?? true,
224
+ idempotencyKeyGenerator: config.idempotencyKeyGenerator ?? generateUUID,
225
+ fetch: config.fetch ?? globalThis.fetch
226
+ };
227
+ }
228
+
229
+ // src/client/transport.ts
230
+ var RETRYABLE_STATUS_CODES2 = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
231
+ var SAFE_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "PUT", "DELETE", "OPTIONS"]);
232
+ var Transport = class {
233
+ config;
234
+ constructor(config) {
235
+ this.config = config;
236
+ }
237
+ /**
238
+ * Make an HTTP request with automatic retry and error handling.
239
+ */
240
+ async request(options) {
241
+ const { method, path, body, query, headers, idempotencyKey, signal } = options;
242
+ const url = this.buildURL(path, query);
243
+ const requestHeaders = this.buildHeaders(method, path, headers, idempotencyKey);
244
+ const requestBody = body !== void 0 ? JSON.stringify(body) : void 0;
245
+ return this.executeWithRetry(url, {
246
+ method,
247
+ headers: requestHeaders,
248
+ body: requestBody,
249
+ signal
250
+ });
251
+ }
252
+ /**
253
+ * Build the full URL with query parameters.
254
+ */
255
+ buildURL(path, query) {
256
+ const url = new URL(path, this.config.baseURL);
257
+ if (query) {
258
+ for (const [key, value] of Object.entries(query)) {
259
+ if (value !== void 0) {
260
+ url.searchParams.set(key, String(value));
261
+ }
262
+ }
263
+ }
264
+ return url.toString();
265
+ }
266
+ /**
267
+ * Build request headers with authentication.
268
+ */
269
+ buildHeaders(method, path, customHeaders, idempotencyKey) {
270
+ const headers = {
271
+ "Content-Type": "application/json",
272
+ Accept: "application/json",
273
+ "User-Agent": "dakota-ts-sdk/1.0.0",
274
+ ...customHeaders
275
+ };
276
+ this.addAuthHeader(headers, path);
277
+ if (method === "POST") {
278
+ const key = idempotencyKey ?? (this.config.automaticIdempotency ? this.config.idempotencyKeyGenerator() : void 0);
279
+ if (key) {
280
+ headers["x-idempotency-key"] = key;
281
+ }
282
+ }
283
+ return headers;
284
+ }
285
+ /**
286
+ * Add authentication header based on auth mode and path.
287
+ */
288
+ addAuthHeader(headers, path) {
289
+ if (headers["x-api-key"] || headers["x-application-token"]) {
290
+ return;
291
+ }
292
+ const { authMode, apiKey, applicationToken } = this.config;
293
+ switch (authMode) {
294
+ case "api_key" /* APIKey */:
295
+ if (apiKey) {
296
+ headers["x-api-key"] = apiKey;
297
+ }
298
+ break;
299
+ case "application_token" /* ApplicationToken */:
300
+ if (applicationToken) {
301
+ headers["x-application-token"] = applicationToken;
302
+ }
303
+ break;
304
+ case "auto" /* Auto */:
305
+ default:
306
+ if (path.startsWith("/applications") && applicationToken) {
307
+ headers["x-application-token"] = applicationToken;
308
+ } else if (apiKey) {
309
+ headers["x-api-key"] = apiKey;
310
+ } else if (applicationToken) {
311
+ headers["x-application-token"] = applicationToken;
312
+ }
313
+ break;
314
+ }
315
+ }
316
+ /**
317
+ * Execute request with exponential backoff retry.
318
+ */
319
+ async executeWithRetry(url, init) {
320
+ const { maxAttempts, initialBackoffMs, maxBackoffMs } = this.config.retryPolicy;
321
+ const method = init.method ?? "GET";
322
+ let lastError;
323
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
324
+ try {
325
+ const controller = new AbortController();
326
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
327
+ const signal = init.signal ? this.mergeAbortSignals(init.signal, controller.signal) : controller.signal;
328
+ this.logRequest(method, url, attempt);
329
+ const response = await this.config.fetch(url, {
330
+ ...init,
331
+ signal
332
+ });
333
+ clearTimeout(timeoutId);
334
+ this.logResponse(method, url, response.status, attempt);
335
+ if (response.ok) {
336
+ if (response.status === 204) {
337
+ return void 0;
338
+ }
339
+ return await response.json();
340
+ }
341
+ const apiError = await APIError.fromResponse(response);
342
+ if (this.shouldRetry(response.status, method, init, attempt)) {
343
+ lastError = apiError;
344
+ const delay = this.calculateBackoff(attempt, response, initialBackoffMs, maxBackoffMs);
345
+ this.config.logger.warn(
346
+ `Request failed with ${response.status}, retrying in ${delay}ms (attempt ${attempt}/${maxAttempts})`
347
+ );
348
+ await this.sleep(delay);
349
+ continue;
350
+ }
351
+ throw apiError;
352
+ } catch (error) {
353
+ if (error instanceof APIError) {
354
+ throw error;
355
+ }
356
+ if (error instanceof Error && error.name === "AbortError") {
357
+ lastError = new TransportError("Request timed out", error);
358
+ } else if (error instanceof Error) {
359
+ lastError = new TransportError("Network error", error);
360
+ } else {
361
+ lastError = new TransportError("Unknown error");
362
+ }
363
+ if (this.shouldRetryNetworkError(method, init, attempt)) {
364
+ const delay = this.calculateBackoff(attempt, null, initialBackoffMs, maxBackoffMs);
365
+ this.config.logger.warn(
366
+ `Network error, retrying in ${delay}ms (attempt ${attempt}/${maxAttempts})`
367
+ );
368
+ await this.sleep(delay);
369
+ continue;
370
+ }
371
+ throw lastError;
372
+ }
373
+ }
374
+ throw lastError ?? new TransportError("Request failed after all retries");
375
+ }
376
+ /**
377
+ * Determine if a request should be retried based on status code.
378
+ */
379
+ shouldRetry(status, method, init, attempt) {
380
+ if (attempt >= this.config.retryPolicy.maxAttempts) {
381
+ return false;
382
+ }
383
+ if (!RETRYABLE_STATUS_CODES2.has(status)) {
384
+ return false;
385
+ }
386
+ if (SAFE_METHODS.has(method)) {
387
+ return true;
388
+ }
389
+ if (method === "POST" && init.headers) {
390
+ const headers = init.headers;
391
+ return !!headers["x-idempotency-key"];
392
+ }
393
+ return false;
394
+ }
395
+ /**
396
+ * Determine if a network error should be retried.
397
+ */
398
+ shouldRetryNetworkError(method, init, attempt) {
399
+ if (attempt >= this.config.retryPolicy.maxAttempts) {
400
+ return false;
401
+ }
402
+ if (SAFE_METHODS.has(method)) {
403
+ return true;
404
+ }
405
+ if (method === "POST" && init.headers) {
406
+ const headers = init.headers;
407
+ return !!headers["x-idempotency-key"];
408
+ }
409
+ return false;
410
+ }
411
+ /**
412
+ * Calculate backoff delay with jitter.
413
+ */
414
+ calculateBackoff(attempt, response, initialBackoffMs, maxBackoffMs) {
415
+ if (response) {
416
+ const retryAfter = response.headers.get("retry-after");
417
+ if (retryAfter) {
418
+ const seconds = parseInt(retryAfter, 10);
419
+ if (!isNaN(seconds)) {
420
+ return seconds * 1e3;
421
+ }
422
+ const date = Date.parse(retryAfter);
423
+ if (!isNaN(date)) {
424
+ return Math.max(0, date - Date.now());
425
+ }
426
+ }
427
+ }
428
+ const exponentialDelay = initialBackoffMs * Math.pow(2, attempt - 1);
429
+ const cappedDelay = Math.min(exponentialDelay, maxBackoffMs);
430
+ const jitter = cappedDelay * 0.2 * (Math.random() * 2 - 1);
431
+ return Math.round(cappedDelay + jitter);
432
+ }
433
+ /**
434
+ * Merge multiple abort signals.
435
+ */
436
+ mergeAbortSignals(signal1, signal2) {
437
+ const controller = new AbortController();
438
+ const abort = () => controller.abort();
439
+ signal1.addEventListener("abort", abort);
440
+ signal2.addEventListener("abort", abort);
441
+ if (signal1.aborted || signal2.aborted) {
442
+ controller.abort();
443
+ }
444
+ return controller.signal;
445
+ }
446
+ /**
447
+ * Sleep for the specified duration.
448
+ */
449
+ sleep(ms) {
450
+ return new Promise((resolve) => setTimeout(resolve, ms));
451
+ }
452
+ /**
453
+ * Log outgoing request.
454
+ */
455
+ logRequest(method, url, attempt) {
456
+ this.config.logger.debug(
457
+ `Request: ${method} ${url}${attempt > 1 ? ` (attempt ${attempt})` : ""}`
458
+ );
459
+ }
460
+ /**
461
+ * Log response.
462
+ */
463
+ logResponse(method, url, status, attempt) {
464
+ this.config.logger.debug(
465
+ `Response: ${method} ${url} -> ${status}${attempt > 1 ? ` (attempt ${attempt})` : ""}`
466
+ );
467
+ }
468
+ };
469
+
470
+ // src/client/pagination.ts
471
+ function defaultCursorExtractor(item) {
472
+ if (!item.id) {
473
+ throw new Error("Item does not have an id field for cursor extraction");
474
+ }
475
+ return item.id;
476
+ }
477
+ var PaginatedIterator = class {
478
+ fetcher;
479
+ cursorExtractor;
480
+ cursor;
481
+ buffer = [];
482
+ hasMore = true;
483
+ started = false;
484
+ constructor(fetcher, cursorExtractor) {
485
+ this.fetcher = fetcher;
486
+ this.cursorExtractor = cursorExtractor ?? defaultCursorExtractor;
487
+ }
488
+ /**
489
+ * Implement async iterator protocol.
490
+ */
491
+ [Symbol.asyncIterator]() {
492
+ return {
493
+ next: async () => {
494
+ const item = await this.next();
495
+ if (item === null) {
496
+ return { done: true, value: void 0 };
497
+ }
498
+ return { done: false, value: item };
499
+ }
500
+ };
501
+ }
502
+ /**
503
+ * Get the next item, or null if no more items.
504
+ */
505
+ async next() {
506
+ if (this.buffer.length > 0) {
507
+ return this.buffer.shift();
508
+ }
509
+ if (!this.hasMore && this.started) {
510
+ return null;
511
+ }
512
+ await this.fetchNextPage();
513
+ if (this.buffer.length > 0) {
514
+ return this.buffer.shift();
515
+ }
516
+ return null;
517
+ }
518
+ /**
519
+ * Collect all items into an array.
520
+ */
521
+ async toArray() {
522
+ const items = [];
523
+ for await (const item of this) {
524
+ items.push(item);
525
+ }
526
+ return items;
527
+ }
528
+ /**
529
+ * Get the first item, or null if none.
530
+ */
531
+ async first() {
532
+ return this.next();
533
+ }
534
+ /**
535
+ * Fetch the next page of results.
536
+ */
537
+ async fetchNextPage() {
538
+ this.started = true;
539
+ const response = await this.fetcher(this.cursor);
540
+ this.buffer = response.data ?? [];
541
+ if (this.buffer.length > 0) {
542
+ const lastItem = this.buffer[this.buffer.length - 1];
543
+ if (lastItem) {
544
+ this.cursor = this.cursorExtractor(lastItem);
545
+ }
546
+ }
547
+ this.hasMore = response.meta?.has_more_after ?? false;
548
+ }
549
+ };
550
+ function paginate(fetcher, cursorExtractor) {
551
+ return new PaginatedIterator(fetcher, cursorExtractor);
552
+ }
553
+
554
+ // src/client/resources/base.ts
555
+ var BaseResource = class {
556
+ transport;
557
+ constructor(transport) {
558
+ this.transport = transport;
559
+ }
560
+ /**
561
+ * Create a paginated iterator for a list endpoint.
562
+ */
563
+ paginate(path, params, cursorExtractor) {
564
+ const fetcher = async (cursor) => {
565
+ const query = {};
566
+ if (params) {
567
+ for (const [key, value] of Object.entries(params)) {
568
+ if (value !== void 0) {
569
+ query[key] = value;
570
+ }
571
+ }
572
+ }
573
+ if (cursor) {
574
+ query.starting_after = cursor;
575
+ }
576
+ const response = await this.transport.request({
577
+ method: "GET",
578
+ path,
579
+ query
580
+ });
581
+ return {
582
+ data: response.data ?? [],
583
+ meta: response.meta
584
+ };
585
+ };
586
+ return paginate(fetcher, cursorExtractor);
587
+ }
588
+ };
589
+
590
+ // src/client/resources/customers.ts
591
+ var CustomersResource = class extends BaseResource {
592
+ /**
593
+ * Create a new customer.
594
+ *
595
+ * Creates a customer record and initiates KYB onboarding.
596
+ * Returns a URL where the customer can complete verification.
597
+ *
598
+ * @param data - Customer creation data
599
+ * @returns Created customer with KYB onboarding URL
600
+ *
601
+ * @example
602
+ * ```typescript
603
+ * const customer = await client.customers.create({
604
+ * name: 'Acme Corp',
605
+ * customerType: 'business',
606
+ * externalId: 'your-internal-id',
607
+ * });
608
+ * console.log(customer.applicationUrl); // KYB onboarding URL
609
+ * ```
610
+ */
611
+ async create(data) {
612
+ return this.transport.request({
613
+ method: "POST",
614
+ path: "/customers",
615
+ body: data
616
+ });
617
+ }
618
+ /**
619
+ * List all customers.
620
+ *
621
+ * Returns a paginated async iterator over customer records.
622
+ *
623
+ * @param params - Optional filter and pagination parameters
624
+ * @returns Async iterator of customers
625
+ *
626
+ * @example
627
+ * ```typescript
628
+ * // Iterate through all customers
629
+ * for await (const customer of client.customers.list()) {
630
+ * console.log(customer.name);
631
+ * }
632
+ *
633
+ * // With filters
634
+ * const active = client.customers.list({ kyb_status: 'active' });
635
+ *
636
+ * // Collect all to array
637
+ * const all = await client.customers.list().toArray();
638
+ * ```
639
+ */
640
+ list(params) {
641
+ return this.paginate("/customers", params);
642
+ }
643
+ /**
644
+ * Get a customer by ID.
645
+ *
646
+ * @param customerId - Customer ID (KSUID)
647
+ * @returns Customer record
648
+ *
649
+ * @example
650
+ * ```typescript
651
+ * const customer = await client.customers.get('cust_abc123');
652
+ * console.log(customer.kybStatus);
653
+ * ```
654
+ */
655
+ async get(customerId) {
656
+ return this.transport.request({
657
+ method: "GET",
658
+ path: `/customers/${customerId}`
659
+ });
660
+ }
661
+ };
662
+
663
+ // src/client/resources/recipients.ts
664
+ var RecipientsResource = class extends BaseResource {
665
+ /**
666
+ * Create a new recipient for a customer.
667
+ *
668
+ * Recipients represent entities that can receive payments.
669
+ *
670
+ * @param customerId - Customer ID
671
+ * @param data - Recipient creation data
672
+ * @returns Created recipient
673
+ *
674
+ * @example
675
+ * ```typescript
676
+ * const recipient = await client.recipients.create(customerId, {
677
+ * name: 'Treasury Account',
678
+ * });
679
+ * ```
680
+ */
681
+ async create(customerId, data) {
682
+ return this.transport.request({
683
+ method: "POST",
684
+ path: `/customers/${customerId}/recipients`,
685
+ body: data
686
+ });
687
+ }
688
+ /**
689
+ * List recipients for a customer.
690
+ *
691
+ * @param customerId - Customer ID
692
+ * @param params - Pagination parameters
693
+ * @returns Async iterator of recipients
694
+ *
695
+ * @example
696
+ * ```typescript
697
+ * for await (const recipient of client.recipients.list(customerId)) {
698
+ * console.log(recipient.name);
699
+ * }
700
+ * ```
701
+ */
702
+ list(customerId, params) {
703
+ return this.paginate(`/customers/${customerId}/recipients`, params);
704
+ }
705
+ /**
706
+ * Get a recipient by ID.
707
+ *
708
+ * @param recipientId - Recipient ID
709
+ * @returns Recipient record
710
+ *
711
+ * @example
712
+ * ```typescript
713
+ * const recipient = await client.recipients.get(recipientId);
714
+ * ```
715
+ */
716
+ async get(recipientId) {
717
+ return this.transport.request({
718
+ method: "GET",
719
+ path: `/recipients/${recipientId}`
720
+ });
721
+ }
722
+ /**
723
+ * Update a recipient.
724
+ *
725
+ * @param recipientId - Recipient ID
726
+ * @param data - Update data
727
+ * @returns Updated recipient
728
+ *
729
+ * @example
730
+ * ```typescript
731
+ * const recipient = await client.recipients.update(recipientId, {
732
+ * name: 'Updated Name',
733
+ * });
734
+ * ```
735
+ */
736
+ async update(recipientId, data) {
737
+ return this.transport.request({
738
+ method: "PUT",
739
+ path: `/recipients/${recipientId}`,
740
+ body: data
741
+ });
742
+ }
743
+ };
744
+
745
+ // src/client/resources/destinations.ts
746
+ var DestinationsResource = class extends BaseResource {
747
+ /**
748
+ * Create a new destination for a recipient.
749
+ *
750
+ * Destinations can be bank accounts (fiat_us) or crypto wallets (crypto).
751
+ *
752
+ * @param recipientId - Recipient ID
753
+ * @param data - Destination creation data
754
+ * @returns Created destination
755
+ *
756
+ * @example
757
+ * ```typescript
758
+ * // Create a bank destination (for off-ramp)
759
+ * const bankDest = await client.destinations.create(recipientId, {
760
+ * destination_type: 'fiat_us',
761
+ * bank_name: 'Chase Bank',
762
+ * account_holder_name: 'Acme Corp',
763
+ * account_number: '123456789',
764
+ * routing_number: '021000021',
765
+ * account_type: 'checking',
766
+ * });
767
+ *
768
+ * // Create a crypto destination (for on-ramp)
769
+ * const cryptoDest = await client.destinations.create(recipientId, {
770
+ * destination_type: 'crypto',
771
+ * crypto_address: '0x742d35Cc6634C0532925a3b844Bc9e7595f...',
772
+ * network_id: 'ethereum-mainnet',
773
+ * });
774
+ * ```
775
+ */
776
+ async create(recipientId, data) {
777
+ return this.transport.request({
778
+ method: "POST",
779
+ path: `/recipients/${recipientId}/destinations`,
780
+ body: data
781
+ });
782
+ }
783
+ /**
784
+ * List destinations for a recipient.
785
+ *
786
+ * @param recipientId - Recipient ID
787
+ * @param params - Pagination parameters
788
+ * @returns Async iterator of destinations
789
+ *
790
+ * @example
791
+ * ```typescript
792
+ * for await (const dest of client.destinations.list(recipientId)) {
793
+ * console.log(dest);
794
+ * }
795
+ * ```
796
+ */
797
+ list(recipientId, params) {
798
+ return this.paginate(
799
+ `/recipients/${recipientId}/destinations`,
800
+ params,
801
+ (item) => item.destination_id
802
+ );
803
+ }
804
+ };
805
+
806
+ // src/client/resources/accounts.ts
807
+ var AccountsResource = class extends BaseResource {
808
+ /**
809
+ * Create a new account.
810
+ *
811
+ * Accounts define the flow of funds:
812
+ * - **onramp**: USD → crypto (customer sends USD, receives stablecoin)
813
+ * - **offramp**: crypto → USD (customer sends stablecoin, receives USD)
814
+ * - **swap**: crypto → crypto (stablecoin conversion)
815
+ *
816
+ * @param data - Account creation data
817
+ * @returns Created account
818
+ *
819
+ * @example
820
+ * ```typescript
821
+ * // Create an off-ramp account (crypto → USD)
822
+ * const offramp = await client.accounts.create({
823
+ * account_type: 'offramp',
824
+ * customer_id: customerId,
825
+ * fiat_destination_id: bankDestinationId,
826
+ * asset: 'USDC',
827
+ * network_id: 'ethereum-mainnet',
828
+ * rail: 'ach',
829
+ * capabilities: ['ach'],
830
+ * });
831
+ * // Returns: { crypto_address: '0x...' } - customer sends USDC here
832
+ *
833
+ * // Create an on-ramp account (USD → crypto)
834
+ * const onramp = await client.accounts.create({
835
+ * account_type: 'onramp',
836
+ * customer_id: customerId,
837
+ * crypto_destination_id: cryptoDestinationId,
838
+ * asset: 'USDC',
839
+ * network_id: 'ethereum-mainnet',
840
+ * rail: 'ach',
841
+ * capabilities: ['ach'],
842
+ * });
843
+ * // Returns: { bank_account: { bank_name, aba_routing_number, account_number } } - customer sends USD here
844
+ * ```
845
+ */
846
+ async create(data) {
847
+ return this.transport.request({
848
+ method: "POST",
849
+ path: "/accounts",
850
+ body: data
851
+ });
852
+ }
853
+ /**
854
+ * List accounts.
855
+ *
856
+ * @param params - Filter and pagination parameters
857
+ * @returns Async iterator of accounts
858
+ *
859
+ * @example
860
+ * ```typescript
861
+ * // List all accounts
862
+ * for await (const account of client.accounts.list()) {
863
+ * console.log(account);
864
+ * }
865
+ *
866
+ * // Filter by customer
867
+ * const customerAccounts = client.accounts.list({ customer_id: customerId });
868
+ * ```
869
+ */
870
+ list(params) {
871
+ return this.paginate("/accounts", params);
872
+ }
873
+ /**
874
+ * Get an account by ID.
875
+ *
876
+ * @param accountId - Account ID
877
+ * @returns Account record
878
+ *
879
+ * @example
880
+ * ```typescript
881
+ * const account = await client.accounts.get(accountId);
882
+ * ```
883
+ */
884
+ async get(accountId) {
885
+ return this.transport.request({
886
+ method: "GET",
887
+ path: `/accounts/${accountId}`
888
+ });
889
+ }
890
+ /**
891
+ * Update an account.
892
+ *
893
+ * @param accountId - Account ID
894
+ * @param data - Update data
895
+ * @returns Updated account
896
+ *
897
+ * @example
898
+ * ```typescript
899
+ * const account = await client.accounts.update(accountId, {
900
+ * status: 'inactive',
901
+ * });
902
+ * ```
903
+ */
904
+ async update(accountId, data) {
905
+ return this.transport.request({
906
+ method: "PATCH",
907
+ path: `/accounts/${accountId}`,
908
+ body: data
909
+ });
910
+ }
911
+ };
912
+
913
+ // src/client/resources/transactions.ts
914
+ var TransactionsResource = class extends BaseResource {
915
+ /**
916
+ * Create a one-off transaction.
917
+ *
918
+ * One-off transactions allow single transfers without setting up accounts.
919
+ *
920
+ * @param data - Transaction creation data
921
+ * @returns Created transaction
922
+ *
923
+ * @example
924
+ * ```typescript
925
+ * const tx = await client.transactions.create({
926
+ * customer_id: customerId,
927
+ * amount: '1000.00',
928
+ * source_asset: 'USDC',
929
+ * source_network_id: 'ethereum-mainnet',
930
+ * destination_id: destinationId,
931
+ * destination_asset: 'USD',
932
+ * destination_payment_rail: 'ach',
933
+ * payment_reference: 'Invoice #12345',
934
+ * });
935
+ *
936
+ * console.log(tx.crypto_address); // Send USDC here
937
+ * console.log(tx.status); // Transaction status
938
+ * ```
939
+ */
940
+ async create(data) {
941
+ return this.transport.request({
942
+ method: "POST",
943
+ path: "/transactions",
944
+ body: data
945
+ });
946
+ }
947
+ /**
948
+ * List one-off transactions.
949
+ *
950
+ * @param params - Filter and pagination parameters
951
+ * @returns Async iterator of transactions
952
+ *
953
+ * @example
954
+ * ```typescript
955
+ * // List all transactions
956
+ * for await (const tx of client.transactions.list()) {
957
+ * console.log(tx.id, tx.status);
958
+ * }
959
+ *
960
+ * // Filter by customer and status
961
+ * const completed = client.transactions.list({
962
+ * customer_id: customerId,
963
+ * status: 'completed',
964
+ * });
965
+ * ```
966
+ */
967
+ list(params) {
968
+ return this.paginate("/transactions", params);
969
+ }
970
+ /**
971
+ * Get a transaction by ID.
972
+ *
973
+ * @param transactionId - Transaction ID
974
+ * @returns Transaction record
975
+ *
976
+ * @example
977
+ * ```typescript
978
+ * const tx = await client.transactions.get(transactionId);
979
+ * console.log(tx.status);
980
+ * ```
981
+ */
982
+ async get(transactionId) {
983
+ return this.transport.request({
984
+ method: "GET",
985
+ path: `/transactions/${transactionId}`
986
+ });
987
+ }
988
+ /**
989
+ * Cancel a transaction.
990
+ *
991
+ * Only pending transactions can be cancelled.
992
+ *
993
+ * @param transactionId - Transaction ID
994
+ * @returns Cancelled transaction
995
+ *
996
+ * @example
997
+ * ```typescript
998
+ * const tx = await client.transactions.cancel(transactionId);
999
+ * console.log(tx.status); // 'cancelled'
1000
+ * ```
1001
+ */
1002
+ async cancel(transactionId) {
1003
+ return this.transport.request({
1004
+ method: "POST",
1005
+ path: `/transactions/${transactionId}/cancellations`
1006
+ });
1007
+ }
1008
+ };
1009
+ var AutoTransactionsResource = class extends BaseResource {
1010
+ /**
1011
+ * List auto transactions.
1012
+ *
1013
+ * @param params - Pagination parameters
1014
+ * @returns Async iterator of auto transactions
1015
+ */
1016
+ list(params) {
1017
+ return this.paginate("/auto-transactions", params);
1018
+ }
1019
+ /**
1020
+ * Get an auto transaction by ID.
1021
+ *
1022
+ * @param transactionId - Auto transaction ID
1023
+ * @returns Auto transaction record
1024
+ */
1025
+ async get(transactionId) {
1026
+ return this.transport.request({
1027
+ method: "GET",
1028
+ path: `/auto-transactions/${transactionId}`
1029
+ });
1030
+ }
1031
+ };
1032
+
1033
+ // src/client/resources/wallets.ts
1034
+ var WalletsResource = class extends BaseResource {
1035
+ /**
1036
+ * Create a new wallet.
1037
+ *
1038
+ * Creates a non-custodial multi-sig wallet for a customer.
1039
+ *
1040
+ * @param data - Wallet creation data
1041
+ * @returns Created wallet
1042
+ *
1043
+ * @example
1044
+ * ```typescript
1045
+ * const wallet = await client.wallets.create({
1046
+ * customer_id: customerId,
1047
+ * family: 'evm',
1048
+ * name: 'Treasury Wallet',
1049
+ * });
1050
+ * console.log(wallet.address);
1051
+ * ```
1052
+ */
1053
+ async create(data) {
1054
+ return this.transport.request({
1055
+ method: "POST",
1056
+ path: "/wallets",
1057
+ body: data
1058
+ });
1059
+ }
1060
+ /**
1061
+ * Get wallet balances.
1062
+ *
1063
+ * @param walletId - Wallet ID
1064
+ * @returns Array of balances
1065
+ *
1066
+ * @example
1067
+ * ```typescript
1068
+ * const balances = await client.wallets.getBalances(walletId);
1069
+ * for (const balance of balances) {
1070
+ * console.log(balance.asset, balance.amount);
1071
+ * }
1072
+ * ```
1073
+ */
1074
+ async getBalances(walletId) {
1075
+ const response = await this.transport.request({
1076
+ method: "GET",
1077
+ path: `/wallets/${walletId}/balances`
1078
+ });
1079
+ return response.data;
1080
+ }
1081
+ /**
1082
+ * Create a wallet transaction.
1083
+ *
1084
+ * @param walletId - Wallet ID
1085
+ * @param data - Transaction data
1086
+ * @returns Created transaction
1087
+ *
1088
+ * @example
1089
+ * ```typescript
1090
+ * const tx = await client.wallets.createTransaction(walletId, {
1091
+ * to: '0x...',
1092
+ * amount: '100.00',
1093
+ * asset: 'USDC',
1094
+ * network_id: 'ethereum-mainnet',
1095
+ * });
1096
+ * ```
1097
+ */
1098
+ async createTransaction(walletId, data) {
1099
+ return this.transport.request({
1100
+ method: "POST",
1101
+ path: `/wallets/${walletId}/transactions`,
1102
+ body: data
1103
+ });
1104
+ }
1105
+ };
1106
+
1107
+ // src/client/resources/events.ts
1108
+ var EventsResource = class extends BaseResource {
1109
+ /**
1110
+ * List events.
1111
+ *
1112
+ * Events track all platform activity and can be used for audit trails.
1113
+ *
1114
+ * @param params - Filter and pagination parameters
1115
+ * @returns Async iterator of events
1116
+ *
1117
+ * @example
1118
+ * ```typescript
1119
+ * for await (const event of client.events.list()) {
1120
+ * console.log(event.type, event.data);
1121
+ * }
1122
+ *
1123
+ * // Filter by event type
1124
+ * const customerEvents = client.events.list({
1125
+ * event_type: 'customer.created',
1126
+ * });
1127
+ * ```
1128
+ */
1129
+ list(params) {
1130
+ return this.paginate("/events", params);
1131
+ }
1132
+ /**
1133
+ * Get an event by ID.
1134
+ *
1135
+ * @param eventId - Event ID
1136
+ * @returns Event record
1137
+ *
1138
+ * @example
1139
+ * ```typescript
1140
+ * const event = await client.events.get(eventId);
1141
+ * ```
1142
+ */
1143
+ async get(eventId) {
1144
+ return this.transport.request({
1145
+ method: "GET",
1146
+ path: `/events/${eventId}`
1147
+ });
1148
+ }
1149
+ };
1150
+
1151
+ // src/client/resources/applications.ts
1152
+ var ApplicationsResource = class extends BaseResource {
1153
+ /**
1154
+ * List applications.
1155
+ *
1156
+ * @param params - Pagination parameters
1157
+ * @returns Async iterator of applications
1158
+ */
1159
+ list(params) {
1160
+ return this.paginate("/applications", params);
1161
+ }
1162
+ /**
1163
+ * Get an application by ID.
1164
+ *
1165
+ * @param applicationId - Application ID
1166
+ * @returns Application record
1167
+ */
1168
+ async get(applicationId) {
1169
+ return this.transport.request({
1170
+ method: "GET",
1171
+ path: `/applications/${applicationId}`
1172
+ });
1173
+ }
1174
+ /**
1175
+ * Submit an application for review.
1176
+ *
1177
+ * @param applicationId - Application ID
1178
+ * @param data - Submission data
1179
+ * @returns Submitted application
1180
+ */
1181
+ async submit(applicationId, data) {
1182
+ return this.transport.request({
1183
+ method: "POST",
1184
+ path: `/applications/${applicationId}/submissions`,
1185
+ body: data ?? {}
1186
+ });
1187
+ }
1188
+ /**
1189
+ * List associated individuals for an application.
1190
+ *
1191
+ * @param applicationId - Application ID
1192
+ * @param params - Pagination parameters
1193
+ * @returns Async iterator of individuals
1194
+ */
1195
+ listIndividuals(applicationId, params) {
1196
+ return this.paginate(
1197
+ `/applications/${applicationId}/associated-individuals`,
1198
+ params
1199
+ );
1200
+ }
1201
+ /**
1202
+ * Add an associated individual to an application.
1203
+ *
1204
+ * @param applicationId - Application ID
1205
+ * @param data - Individual data
1206
+ * @returns Created individual
1207
+ */
1208
+ async addIndividual(applicationId, data) {
1209
+ return this.transport.request({
1210
+ method: "POST",
1211
+ path: `/applications/${applicationId}/associated-individuals`,
1212
+ body: data
1213
+ });
1214
+ }
1215
+ /**
1216
+ * Get an associated individual.
1217
+ *
1218
+ * @param applicationId - Application ID
1219
+ * @param individualId - Individual ID
1220
+ * @returns Individual record
1221
+ */
1222
+ async getIndividual(applicationId, individualId) {
1223
+ return this.transport.request({
1224
+ method: "GET",
1225
+ path: `/applications/${applicationId}/associated-individuals/${individualId}`
1226
+ });
1227
+ }
1228
+ /**
1229
+ * Update an associated individual.
1230
+ *
1231
+ * @param applicationId - Application ID
1232
+ * @param individualId - Individual ID
1233
+ * @param data - Update data
1234
+ * @returns Updated individual
1235
+ */
1236
+ async updateIndividual(applicationId, individualId, data) {
1237
+ return this.transport.request({
1238
+ method: "PATCH",
1239
+ path: `/applications/${applicationId}/associated-individuals/${individualId}`,
1240
+ body: data
1241
+ });
1242
+ }
1243
+ /**
1244
+ * Delete an associated individual.
1245
+ *
1246
+ * @param applicationId - Application ID
1247
+ * @param individualId - Individual ID
1248
+ */
1249
+ async deleteIndividual(applicationId, individualId) {
1250
+ await this.transport.request({
1251
+ method: "DELETE",
1252
+ path: `/applications/${applicationId}/associated-individuals/${individualId}`
1253
+ });
1254
+ }
1255
+ /**
1256
+ * Update business details for an application.
1257
+ *
1258
+ * @param applicationId - Application ID
1259
+ * @param data - Business details
1260
+ * @returns Updated application
1261
+ */
1262
+ async updateBusinessDetails(applicationId, data) {
1263
+ return this.transport.request({
1264
+ method: "PATCH",
1265
+ path: `/applications/${applicationId}/business-details`,
1266
+ body: data
1267
+ });
1268
+ }
1269
+ /**
1270
+ * Get document upload URL for an application.
1271
+ *
1272
+ * @param applicationId - Application ID
1273
+ * @param data - Document metadata
1274
+ * @returns Upload URL and document ID
1275
+ */
1276
+ async getDocumentUploadUrl(applicationId, data) {
1277
+ return this.transport.request({
1278
+ method: "POST",
1279
+ path: `/applications/${applicationId}/document-uploads`,
1280
+ body: data
1281
+ });
1282
+ }
1283
+ };
1284
+
1285
+ // src/client/resources/policies.ts
1286
+ var PoliciesResource = class extends BaseResource {
1287
+ /**
1288
+ * Create a new policy.
1289
+ *
1290
+ * @param data - Policy creation data
1291
+ * @returns Created policy
1292
+ */
1293
+ async create(data) {
1294
+ return this.transport.request({
1295
+ method: "POST",
1296
+ path: "/policies",
1297
+ body: data
1298
+ });
1299
+ }
1300
+ /**
1301
+ * List policies.
1302
+ *
1303
+ * @param params - Pagination parameters
1304
+ * @returns Async iterator of policies
1305
+ */
1306
+ list(params) {
1307
+ return this.paginate("/policies", params);
1308
+ }
1309
+ /**
1310
+ * Get a policy by ID.
1311
+ *
1312
+ * @param policyId - Policy ID
1313
+ * @returns Policy record
1314
+ */
1315
+ async get(policyId) {
1316
+ return this.transport.request({
1317
+ method: "GET",
1318
+ path: `/policies/${policyId}`
1319
+ });
1320
+ }
1321
+ /**
1322
+ * Delete a policy.
1323
+ *
1324
+ * @param policyId - Policy ID
1325
+ */
1326
+ async delete(policyId) {
1327
+ await this.transport.request({
1328
+ method: "DELETE",
1329
+ path: `/policies/${policyId}`
1330
+ });
1331
+ }
1332
+ /**
1333
+ * Add a rule to a policy.
1334
+ *
1335
+ * @param policyId - Policy ID
1336
+ * @param data - Rule creation data
1337
+ * @returns Created rule
1338
+ */
1339
+ async addRule(policyId, data) {
1340
+ return this.transport.request({
1341
+ method: "POST",
1342
+ path: `/policies/${policyId}/rules`,
1343
+ body: data
1344
+ });
1345
+ }
1346
+ /**
1347
+ * Update a policy rule.
1348
+ *
1349
+ * @param policyId - Policy ID
1350
+ * @param ruleId - Rule ID
1351
+ * @param data - Update data
1352
+ * @returns Updated rule
1353
+ */
1354
+ async updateRule(policyId, ruleId, data) {
1355
+ return this.transport.request({
1356
+ method: "PATCH",
1357
+ path: `/policies/${policyId}/rules/${ruleId}`,
1358
+ body: data
1359
+ });
1360
+ }
1361
+ /**
1362
+ * Delete a policy rule.
1363
+ *
1364
+ * @param policyId - Policy ID
1365
+ * @param ruleId - Rule ID
1366
+ */
1367
+ async deleteRule(policyId, ruleId) {
1368
+ await this.transport.request({
1369
+ method: "DELETE",
1370
+ path: `/policies/${policyId}/rules/${ruleId}`
1371
+ });
1372
+ }
1373
+ /**
1374
+ * Attach a policy to a wallet.
1375
+ *
1376
+ * @param policyId - Policy ID
1377
+ * @param walletId - Wallet ID
1378
+ */
1379
+ async attachToWallet(policyId, walletId) {
1380
+ await this.transport.request({
1381
+ method: "PUT",
1382
+ path: `/policies/${policyId}/wallets/${walletId}`
1383
+ });
1384
+ }
1385
+ /**
1386
+ * Detach a policy from a wallet.
1387
+ *
1388
+ * @param policyId - Policy ID
1389
+ * @param walletId - Wallet ID
1390
+ */
1391
+ async detachFromWallet(policyId, walletId) {
1392
+ await this.transport.request({
1393
+ method: "DELETE",
1394
+ path: `/policies/${policyId}/wallets/${walletId}`
1395
+ });
1396
+ }
1397
+ };
1398
+
1399
+ // src/client/resources/signer-groups.ts
1400
+ var SignerGroupsResource = class extends BaseResource {
1401
+ /**
1402
+ * Create a new signer group.
1403
+ *
1404
+ * @param data - Signer group creation data
1405
+ * @returns Created signer group
1406
+ */
1407
+ async create(data) {
1408
+ return this.transport.request({
1409
+ method: "POST",
1410
+ path: "/signer-groups",
1411
+ body: data
1412
+ });
1413
+ }
1414
+ /**
1415
+ * List signer groups.
1416
+ *
1417
+ * @param params - Pagination parameters
1418
+ * @returns Async iterator of signer groups
1419
+ */
1420
+ list(params) {
1421
+ return this.paginate("/signer-groups", params);
1422
+ }
1423
+ /**
1424
+ * Get a signer group by ID.
1425
+ *
1426
+ * @param signerGroupId - Signer group ID
1427
+ * @returns Signer group record
1428
+ */
1429
+ async get(signerGroupId) {
1430
+ return this.transport.request({
1431
+ method: "GET",
1432
+ path: `/signer-groups/${signerGroupId}`
1433
+ });
1434
+ }
1435
+ /**
1436
+ * Add a signer to a group.
1437
+ *
1438
+ * @param signerGroupId - Signer group ID
1439
+ * @param data - Signer creation data
1440
+ * @returns Created signer
1441
+ */
1442
+ async addSigner(signerGroupId, data) {
1443
+ return this.transport.request({
1444
+ method: "POST",
1445
+ path: `/signer-groups/${signerGroupId}/signers`,
1446
+ body: data
1447
+ });
1448
+ }
1449
+ /**
1450
+ * Remove a signer from a group.
1451
+ *
1452
+ * @param signerGroupId - Signer group ID
1453
+ * @param signerId - Signer ID
1454
+ */
1455
+ async removeSigner(signerGroupId, signerId) {
1456
+ await this.transport.request({
1457
+ method: "DELETE",
1458
+ path: `/signer-groups/${signerGroupId}/signers/${signerId}`
1459
+ });
1460
+ }
1461
+ /**
1462
+ * Attach a signer group to a wallet.
1463
+ *
1464
+ * @param walletId - Wallet ID
1465
+ * @param signerGroupId - Signer group ID
1466
+ */
1467
+ async attachToWallet(walletId, signerGroupId) {
1468
+ await this.transport.request({
1469
+ method: "PUT",
1470
+ path: `/wallets/${walletId}/signer-groups/${signerGroupId}`
1471
+ });
1472
+ }
1473
+ /**
1474
+ * Detach a signer group from a wallet.
1475
+ *
1476
+ * @param walletId - Wallet ID
1477
+ * @param signerGroupId - Signer group ID
1478
+ */
1479
+ async detachFromWallet(walletId, signerGroupId) {
1480
+ await this.transport.request({
1481
+ method: "DELETE",
1482
+ path: `/wallets/${walletId}/signer-groups/${signerGroupId}`
1483
+ });
1484
+ }
1485
+ };
1486
+ var SignersResource = class extends BaseResource {
1487
+ /**
1488
+ * List all signers.
1489
+ *
1490
+ * @param params - Pagination parameters
1491
+ * @returns Async iterator of signers
1492
+ */
1493
+ list(params) {
1494
+ return this.paginate("/signers", params);
1495
+ }
1496
+ /**
1497
+ * Get a signer by public key.
1498
+ *
1499
+ * @param publicKey - Signer public key
1500
+ * @returns Signer record
1501
+ */
1502
+ async getByPublicKey(publicKey) {
1503
+ return this.transport.request({
1504
+ method: "GET",
1505
+ path: `/signers/${publicKey}`
1506
+ });
1507
+ }
1508
+ /**
1509
+ * Delete a signer by public key.
1510
+ *
1511
+ * Soft-deletes all signers with the given public key.
1512
+ *
1513
+ * @param publicKey - Signer public key
1514
+ */
1515
+ async delete(publicKey) {
1516
+ await this.transport.request({
1517
+ method: "DELETE",
1518
+ path: `/signers/${publicKey}`
1519
+ });
1520
+ }
1521
+ };
1522
+
1523
+ // src/client/resources/api-keys.ts
1524
+ var ApiKeysResource = class extends BaseResource {
1525
+ /**
1526
+ * Create a new API key.
1527
+ *
1528
+ * @param data - API key creation data
1529
+ * @returns Created API key (includes secret, only shown once)
1530
+ */
1531
+ async create(data) {
1532
+ return this.transport.request({
1533
+ method: "POST",
1534
+ path: "/api-keys",
1535
+ body: data
1536
+ });
1537
+ }
1538
+ /**
1539
+ * List API keys.
1540
+ *
1541
+ * @param params - Pagination parameters
1542
+ * @returns Async iterator of API keys
1543
+ */
1544
+ list(params) {
1545
+ return this.paginate("/api-keys", params);
1546
+ }
1547
+ /**
1548
+ * Delete an API key.
1549
+ *
1550
+ * @param apiKeyId - API key ID
1551
+ */
1552
+ async delete(apiKeyId) {
1553
+ await this.transport.request({
1554
+ method: "DELETE",
1555
+ path: `/api-keys/${apiKeyId}`
1556
+ });
1557
+ }
1558
+ };
1559
+
1560
+ // src/client/resources/users.ts
1561
+ var UsersResource = class extends BaseResource {
1562
+ /**
1563
+ * Create a new user.
1564
+ *
1565
+ * @param data - User creation data
1566
+ * @returns Created user
1567
+ */
1568
+ async create(data) {
1569
+ return this.transport.request({
1570
+ method: "POST",
1571
+ path: "/users",
1572
+ body: data
1573
+ });
1574
+ }
1575
+ /**
1576
+ * List users.
1577
+ *
1578
+ * @param params - Pagination parameters
1579
+ * @returns Async iterator of users
1580
+ */
1581
+ list(params) {
1582
+ return this.paginate("/users", params);
1583
+ }
1584
+ /**
1585
+ * Get a user by ID.
1586
+ *
1587
+ * @param userId - User ID
1588
+ * @returns User record
1589
+ */
1590
+ async get(userId) {
1591
+ return this.transport.request({
1592
+ method: "GET",
1593
+ path: `/users/${userId}`
1594
+ });
1595
+ }
1596
+ /**
1597
+ * Update a user.
1598
+ *
1599
+ * @param userId - User ID
1600
+ * @param data - Update data
1601
+ * @returns Updated user
1602
+ */
1603
+ async update(userId, data) {
1604
+ return this.transport.request({
1605
+ method: "PATCH",
1606
+ path: `/users/${userId}`,
1607
+ body: data
1608
+ });
1609
+ }
1610
+ /**
1611
+ * Delete a user.
1612
+ *
1613
+ * @param userId - User ID
1614
+ */
1615
+ async delete(userId) {
1616
+ await this.transport.request({
1617
+ method: "DELETE",
1618
+ path: `/users/${userId}`
1619
+ });
1620
+ }
1621
+ };
1622
+
1623
+ // src/client/resources/webhooks.ts
1624
+ var WebhooksResource = class extends BaseResource {
1625
+ /**
1626
+ * Create a new webhook target.
1627
+ *
1628
+ * @param data - Webhook target creation data
1629
+ * @returns Created webhook target
1630
+ */
1631
+ async createTarget(data) {
1632
+ return this.transport.request({
1633
+ method: "POST",
1634
+ path: "/webhooks/targets",
1635
+ body: data
1636
+ });
1637
+ }
1638
+ /**
1639
+ * List webhook targets.
1640
+ *
1641
+ * @param params - Pagination parameters
1642
+ * @returns Async iterator of webhook targets
1643
+ */
1644
+ listTargets(params) {
1645
+ return this.paginate("/webhooks/targets", params);
1646
+ }
1647
+ /**
1648
+ * Get a webhook target by ID.
1649
+ *
1650
+ * @param targetId - Webhook target ID
1651
+ * @returns Webhook target record
1652
+ */
1653
+ async getTarget(targetId) {
1654
+ return this.transport.request({
1655
+ method: "GET",
1656
+ path: `/webhooks/targets/${targetId}`
1657
+ });
1658
+ }
1659
+ /**
1660
+ * Update a webhook target.
1661
+ *
1662
+ * @param targetId - Webhook target ID
1663
+ * @param data - Update data
1664
+ * @returns Updated webhook target
1665
+ */
1666
+ async updateTarget(targetId, data) {
1667
+ return this.transport.request({
1668
+ method: "PATCH",
1669
+ path: `/webhooks/targets/${targetId}`,
1670
+ body: data
1671
+ });
1672
+ }
1673
+ /**
1674
+ * Delete a webhook target.
1675
+ *
1676
+ * @param targetId - Webhook target ID
1677
+ */
1678
+ async deleteTarget(targetId) {
1679
+ await this.transport.request({
1680
+ method: "DELETE",
1681
+ path: `/webhooks/targets/${targetId}`
1682
+ });
1683
+ }
1684
+ /**
1685
+ * List webhook events.
1686
+ *
1687
+ * @param params - Pagination parameters
1688
+ * @returns Async iterator of webhook events
1689
+ */
1690
+ listEvents(params) {
1691
+ return this.paginate("/webhooks", params);
1692
+ }
1693
+ /**
1694
+ * Get a webhook event by ID.
1695
+ *
1696
+ * @param eventId - Webhook event ID
1697
+ * @returns Webhook event record
1698
+ */
1699
+ async getEvent(eventId) {
1700
+ return this.transport.request({
1701
+ method: "GET",
1702
+ path: `/webhooks/${eventId}`
1703
+ });
1704
+ }
1705
+ /**
1706
+ * Replay a webhook event.
1707
+ *
1708
+ * @param eventId - Webhook event ID
1709
+ */
1710
+ async replayEvent(eventId) {
1711
+ await this.transport.request({
1712
+ method: "POST",
1713
+ path: `/webhooks/events/${eventId}/replay`
1714
+ });
1715
+ }
1716
+ };
1717
+
1718
+ // src/client/resources/info.ts
1719
+ var InfoResource = class extends BaseResource {
1720
+ /**
1721
+ * Get supported countries.
1722
+ *
1723
+ * @returns Array of supported countries
1724
+ *
1725
+ * @example
1726
+ * ```typescript
1727
+ * const countries = await client.info.getCountries();
1728
+ * ```
1729
+ */
1730
+ async getCountries() {
1731
+ const response = await this.transport.request({
1732
+ method: "GET",
1733
+ path: "/capabilities/countries"
1734
+ });
1735
+ return response.data;
1736
+ }
1737
+ /**
1738
+ * Get supported networks.
1739
+ *
1740
+ * @returns Array of supported networks
1741
+ *
1742
+ * @example
1743
+ * ```typescript
1744
+ * const networks = await client.info.getNetworks();
1745
+ * for (const network of networks) {
1746
+ * console.log(network.id, network.name);
1747
+ * }
1748
+ * ```
1749
+ */
1750
+ async getNetworks() {
1751
+ const response = await this.transport.request({
1752
+ method: "GET",
1753
+ path: "/capabilities/networks"
1754
+ });
1755
+ return response.data;
1756
+ }
1757
+ };
1758
+
1759
+ // src/client/resources/sandbox.ts
1760
+ var SandboxResource = class extends BaseResource {
1761
+ /**
1762
+ * Simulate an inbound payment event.
1763
+ *
1764
+ * Triggers a simulated payment event through the mock banking provider.
1765
+ * The required fields depend on the simulation `type`:
1766
+ *
1767
+ * | Type | Required Fields |
1768
+ * |------|-----------------|
1769
+ * | `ach_inbound`, `wire_inbound` | `account_id` |
1770
+ * | `crypto_inbound` | `wallet_id` |
1771
+ * | `*_outbound_*`, `*_reversal` | `movement_id` |
1772
+ *
1773
+ * @param data - Simulation request data
1774
+ * @returns Simulation response with ID and state
1775
+ *
1776
+ * @example Simulate ACH deposit to on-ramp
1777
+ * ```typescript
1778
+ * const result = await client.sandbox.simulateInbound({
1779
+ * simulation_id: `sim_${Date.now()}`,
1780
+ * type: 'ach_inbound',
1781
+ * account_id: 'acc_123',
1782
+ * amount: '1000.00',
1783
+ * currency: 'USD',
1784
+ * });
1785
+ * ```
1786
+ *
1787
+ * @example Simulate off-ramp ACH settlement
1788
+ * ```typescript
1789
+ * // After creating a one-off transaction for off-ramp testing
1790
+ * const tx = await client.transactions.create({
1791
+ * customer_id: 'cust_123',
1792
+ * amount: '100.00',
1793
+ * source_asset: 'USDC',
1794
+ * source_network_id: 'ethereum-sepolia',
1795
+ * destination_id: 'dest_456',
1796
+ * destination_asset: 'USD',
1797
+ * destination_payment_rail: 'ach',
1798
+ * });
1799
+ *
1800
+ * // Simulate the ACH settlement
1801
+ * await client.sandbox.simulateInbound({
1802
+ * simulation_id: `sim_${Date.now()}`,
1803
+ * type: 'ach_outbound_settled',
1804
+ * movement_id: tx.id,
1805
+ * amount: '100.00',
1806
+ * currency: 'USD',
1807
+ * });
1808
+ * ```
1809
+ *
1810
+ * @example Simulate crypto deposit to wallet
1811
+ * ```typescript
1812
+ * const result = await client.sandbox.simulateInbound({
1813
+ * simulation_id: `sim_${Date.now()}`,
1814
+ * type: 'crypto_inbound',
1815
+ * wallet_id: 'wallet_789',
1816
+ * amount: '500.00',
1817
+ * currency: 'USDC',
1818
+ * });
1819
+ * ```
1820
+ */
1821
+ async simulateInbound(data) {
1822
+ return this.transport.request({
1823
+ method: "POST",
1824
+ path: "/sandbox/simulate/inbound",
1825
+ body: data
1826
+ });
1827
+ }
1828
+ /**
1829
+ * Simulate an onboarding state transition.
1830
+ *
1831
+ * Drives KYB, KYC, or applicant account status through a sandbox transition
1832
+ * without waiting for real compliance review.
1833
+ *
1834
+ * **Important:** For full activation, you typically need TWO calls:
1835
+ * 1. `kyb_approve` - Approves the KYB application
1836
+ * 2. `applicant_activate` - Activates the applicant (triggers provisioning)
1837
+ *
1838
+ * @param data - Simulation request data
1839
+ * @returns Simulation response with previous and new state
1840
+ *
1841
+ * @example Approve KYB and activate applicant
1842
+ * ```typescript
1843
+ * // Step 1: Approve the KYB application
1844
+ * await client.sandbox.simulateOnboarding({
1845
+ * type: 'kyb_approve',
1846
+ * applicant_id: customer.application_id,
1847
+ * simulation_id: `sim_kyb_${Date.now()}`,
1848
+ * });
1849
+ *
1850
+ * // Step 2: Activate the applicant (triggers provisioning)
1851
+ * await client.sandbox.simulateOnboarding({
1852
+ * type: 'applicant_activate',
1853
+ * applicant_id: customer.application_id,
1854
+ * simulation_id: `sim_activate_${Date.now()}`,
1855
+ * });
1856
+ * ```
1857
+ *
1858
+ * @example Reject a KYB application
1859
+ * ```typescript
1860
+ * await client.sandbox.simulateOnboarding({
1861
+ * type: 'kyb_reject',
1862
+ * applicant_id: applicationId,
1863
+ * simulation_id: `sim_${Date.now()}`,
1864
+ * reason_code: 'MISSING_DOCUMENTS',
1865
+ * });
1866
+ * ```
1867
+ */
1868
+ async simulateOnboarding(data) {
1869
+ return this.transport.request({
1870
+ method: "POST",
1871
+ path: "/sandbox/simulate/onboarding",
1872
+ body: data
1873
+ });
1874
+ }
1875
+ /**
1876
+ * Get detailed simulation status and callback history.
1877
+ *
1878
+ * Returns the current state and callback delivery history for a sandbox simulation.
1879
+ * Use this to debug async flows and see whether callbacks have been delivered.
1880
+ *
1881
+ * @param simulationId - Simulation ID returned from simulateInbound/simulateOnboarding
1882
+ * @returns Full simulation inspection including state and callbacks
1883
+ *
1884
+ * @example
1885
+ * ```typescript
1886
+ * const inspection = await client.sandbox.getSimulation('sim_123');
1887
+ * console.log('State:', inspection.state);
1888
+ * console.log('Callbacks:', inspection.callbacks);
1889
+ * ```
1890
+ */
1891
+ async getSimulation(simulationId) {
1892
+ return this.transport.request({
1893
+ method: "GET",
1894
+ path: `/sandbox/simulations/${simulationId}`
1895
+ });
1896
+ }
1897
+ /**
1898
+ * Advance a stateful simulation to the next state.
1899
+ *
1900
+ * Some scenarios pause and wait for explicit advancement. Use this method
1901
+ * to continue a paused simulation with a specific action.
1902
+ *
1903
+ * @param simulationId - Simulation ID
1904
+ * @param data - Action to take (e.g., 'release', 'reject', 'confirm', 'expire')
1905
+ * @returns Updated simulation state
1906
+ *
1907
+ * @example
1908
+ * ```typescript
1909
+ * const result = await client.sandbox.advanceSimulation('sim_123', {
1910
+ * action: 'release',
1911
+ * });
1912
+ * console.log('New state:', result.new_state);
1913
+ * ```
1914
+ */
1915
+ async advanceSimulation(simulationId, data) {
1916
+ return this.transport.request({
1917
+ method: "POST",
1918
+ path: `/sandbox/simulations/${simulationId}/advance`,
1919
+ body: data
1920
+ });
1921
+ }
1922
+ /**
1923
+ * List available sandbox scenarios.
1924
+ *
1925
+ * Returns all simulation scenarios supported by the platform.
1926
+ * Use these scenario names in the `scenario` field of simulateInbound.
1927
+ *
1928
+ * @param params - Pagination parameters
1929
+ * @returns Async iterator of scenarios
1930
+ *
1931
+ * @example
1932
+ * ```typescript
1933
+ * const scenarios = await client.sandbox.listScenarios().toArray();
1934
+ * for (const scenario of scenarios) {
1935
+ * console.log(`${scenario.name}: ${scenario.description}`);
1936
+ * }
1937
+ * ```
1938
+ */
1939
+ listScenarios(params) {
1940
+ return this.paginate("/sandbox/scenarios", params);
1941
+ }
1942
+ };
1943
+
1944
+ // src/client/client.ts
1945
+ var DakotaClient = class {
1946
+ config;
1947
+ transport;
1948
+ // API Resources
1949
+ /** Customers API - manage customer records and KYB */
1950
+ customers;
1951
+ /** Recipients API - manage payment recipients */
1952
+ recipients;
1953
+ /** Destinations API - manage bank accounts and crypto wallets */
1954
+ destinations;
1955
+ /** Accounts API - manage on-ramp, off-ramp, and swap accounts */
1956
+ accounts;
1957
+ /** Transactions API - manage one-off transactions */
1958
+ transactions;
1959
+ /** Auto Transactions API - manage automated transactions */
1960
+ autoTransactions;
1961
+ /** Wallets API - manage non-custodial wallets */
1962
+ wallets;
1963
+ /** Events API - query platform events */
1964
+ events;
1965
+ /** Applications API - manage KYB applications */
1966
+ applications;
1967
+ /** Policies API - manage transaction policies */
1968
+ policies;
1969
+ /** Signer Groups API - manage multi-sig signer groups */
1970
+ signerGroups;
1971
+ /** Signers API - manage individual signers */
1972
+ signers;
1973
+ /** API Keys API - manage API keys */
1974
+ apiKeys;
1975
+ /** Users API - manage platform users */
1976
+ users;
1977
+ /** Webhooks API - manage webhook targets and events */
1978
+ webhooks;
1979
+ /** Info API - query platform capabilities */
1980
+ info;
1981
+ /** Sandbox API - testing simulations (sandbox only) */
1982
+ sandbox;
1983
+ /**
1984
+ * Create a new Dakota client.
1985
+ *
1986
+ * @param config - Client configuration
1987
+ * @throws ConfigurationError if configuration is invalid
1988
+ *
1989
+ * @example
1990
+ * ```typescript
1991
+ * // Basic usage (sandbox)
1992
+ * const client = new DakotaClient({
1993
+ * apiKey: 'your_api_key',
1994
+ * });
1995
+ *
1996
+ * // Production
1997
+ * const client = new DakotaClient({
1998
+ * apiKey: 'your_production_api_key',
1999
+ * environment: Environment.Production,
2000
+ * });
2001
+ *
2002
+ * // With custom configuration
2003
+ * const client = new DakotaClient({
2004
+ * apiKey: 'your_api_key',
2005
+ * timeout: 30000,
2006
+ * retryPolicy: {
2007
+ * maxAttempts: 5,
2008
+ * initialBackoffMs: 100,
2009
+ * maxBackoffMs: 5000,
2010
+ * },
2011
+ * logger: console,
2012
+ * });
2013
+ * ```
2014
+ */
2015
+ constructor(config) {
2016
+ this.config = resolveConfig(config);
2017
+ this.transport = new Transport(this.config);
2018
+ this.customers = new CustomersResource(this.transport);
2019
+ this.recipients = new RecipientsResource(this.transport);
2020
+ this.destinations = new DestinationsResource(this.transport);
2021
+ this.accounts = new AccountsResource(this.transport);
2022
+ this.transactions = new TransactionsResource(this.transport);
2023
+ this.autoTransactions = new AutoTransactionsResource(this.transport);
2024
+ this.wallets = new WalletsResource(this.transport);
2025
+ this.events = new EventsResource(this.transport);
2026
+ this.applications = new ApplicationsResource(this.transport);
2027
+ this.policies = new PoliciesResource(this.transport);
2028
+ this.signerGroups = new SignerGroupsResource(this.transport);
2029
+ this.signers = new SignersResource(this.transport);
2030
+ this.apiKeys = new ApiKeysResource(this.transport);
2031
+ this.users = new UsersResource(this.transport);
2032
+ this.webhooks = new WebhooksResource(this.transport);
2033
+ this.info = new InfoResource(this.transport);
2034
+ this.sandbox = new SandboxResource(this.transport);
2035
+ }
2036
+ /**
2037
+ * Get the resolved base URL.
2038
+ */
2039
+ get baseURL() {
2040
+ return this.config.baseURL;
2041
+ }
2042
+ };
2043
+
2044
+ exports.APIError = APIError;
2045
+ exports.AccountsResource = AccountsResource;
2046
+ exports.ApiKeysResource = ApiKeysResource;
2047
+ exports.ApplicationsResource = ApplicationsResource;
2048
+ exports.AuthMode = AuthMode;
2049
+ exports.AutoTransactionsResource = AutoTransactionsResource;
2050
+ exports.ConfigurationError = ConfigurationError;
2051
+ exports.CustomersResource = CustomersResource;
2052
+ exports.DEFAULT_RETRY_POLICY = DEFAULT_RETRY_POLICY;
2053
+ exports.DakotaClient = DakotaClient;
2054
+ exports.DestinationsResource = DestinationsResource;
2055
+ exports.Environment = Environment;
2056
+ exports.EventsResource = EventsResource;
2057
+ exports.InfoResource = InfoResource;
2058
+ exports.PaginatedIterator = PaginatedIterator;
2059
+ exports.PoliciesResource = PoliciesResource;
2060
+ exports.RecipientsResource = RecipientsResource;
2061
+ exports.SandboxResource = SandboxResource;
2062
+ exports.SignerGroupsResource = SignerGroupsResource;
2063
+ exports.SignersResource = SignersResource;
2064
+ exports.TransactionsResource = TransactionsResource;
2065
+ exports.TransportError = TransportError;
2066
+ exports.UsersResource = UsersResource;
2067
+ exports.WalletsResource = WalletsResource;
2068
+ exports.WebhooksResource = WebhooksResource;
2069
+ exports.consoleLogger = consoleLogger;
2070
+ exports.getEnvironmentURL = getEnvironmentURL;
2071
+ exports.noopLogger = noopLogger;
2072
+ exports.paginate = paginate;
2073
+ //# sourceMappingURL=index.js.map
2074
+ //# sourceMappingURL=index.js.map