@dakota-xyz/ts-sdk 1.3.1 → 1.6.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.
package/dist/index.js CHANGED
@@ -229,6 +229,7 @@ function resolveConfig(config) {
229
229
  // src/client/transport.ts
230
230
  var RETRYABLE_STATUS_CODES2 = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
231
231
  var SAFE_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "PUT", "DELETE", "OPTIONS"]);
232
+ var IDEMPOTENT_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
232
233
  var Transport = class {
233
234
  config;
234
235
  constructor(config) {
@@ -274,7 +275,7 @@ var Transport = class {
274
275
  ...customHeaders
275
276
  };
276
277
  this.addAuthHeader(headers, path);
277
- if (method === "POST") {
278
+ if (IDEMPOTENT_METHODS.has(method)) {
278
279
  const key = idempotencyKey ?? (this.config.automaticIdempotency ? this.config.idempotencyKeyGenerator() : void 0);
279
280
  if (key) {
280
281
  headers["x-idempotency-key"] = key;
@@ -386,7 +387,7 @@ var Transport = class {
386
387
  if (SAFE_METHODS.has(method)) {
387
388
  return true;
388
389
  }
389
- if (method === "POST" && init.headers) {
390
+ if (IDEMPOTENT_METHODS.has(method) && init.headers) {
390
391
  const headers = init.headers;
391
392
  return !!headers["x-idempotency-key"];
392
393
  }
@@ -402,7 +403,7 @@ var Transport = class {
402
403
  if (SAFE_METHODS.has(method)) {
403
404
  return true;
404
405
  }
405
- if (method === "POST" && init.headers) {
406
+ if (IDEMPOTENT_METHODS.has(method) && init.headers) {
406
407
  const headers = init.headers;
407
408
  return !!headers["x-idempotency-key"];
408
409
  }
@@ -613,6 +614,15 @@ var CustomersResource = class extends BaseResource {
613
614
  * { idempotencyKey: 'create-acme-corp-001' }
614
615
  * );
615
616
  * console.log(customer.applicationUrl); // KYB onboarding URL
617
+ *
618
+ * // Designate as a sub-client at creation (ENG-2454).
619
+ * // `is_sub_client` can only be set here — a regular customer cannot
620
+ * // be promoted afterwards. Cannot be combined with `sub_client_id`.
621
+ * const subClient = await client.customers.create({
622
+ * name: 'Partner Corp',
623
+ * customer_type: 'business',
624
+ * is_sub_client: true,
625
+ * });
616
626
  * ```
617
627
  */
618
628
  async create(data, options) {
@@ -855,30 +865,39 @@ var DestinationsResource = class extends BaseResource {
855
865
  /**
856
866
  * Create a new destination for a recipient.
857
867
  *
858
- * Destinations can be bank accounts (fiat_us) or crypto wallets (crypto).
868
+ * Destinations can be bank accounts (fiat_us / fiat_iban) or crypto
869
+ * wallets (crypto).
870
+ *
871
+ * The platform returns just `{ id }` here (per `IDResponse`), not the
872
+ * full destination object. Call `destinations.list(recipientId)` if
873
+ * you need the rest of the fields.
859
874
  *
860
875
  * @param recipientId - Recipient ID
861
876
  * @param data - Destination creation data
862
- * @returns Created destination
877
+ * @returns `{ id }` of the newly-created destination
863
878
  *
864
879
  * @example
865
880
  * ```typescript
866
- * // Create a bank destination (for off-ramp)
867
- * const bankDest = await client.destinations.create(recipientId, {
868
- * destination_type: 'fiat_us',
869
- * bank_name: 'Chase Bank',
870
- * account_holder_name: 'Acme Corp',
871
- * account_number: '123456789',
872
- * routing_number: '021000021',
873
- * account_type: 'checking',
874
- * });
875
- *
876
- * // Create a crypto destination (for on-ramp)
881
+ * // Crypto destination (for on-ramp)
877
882
  * const cryptoDest = await client.destinations.create(recipientId, {
878
883
  * destination_type: 'crypto',
884
+ * name: 'Treasury USDC',
879
885
  * crypto_address: '0x742d35Cc6634C0532925a3b844Bc9e7595f...',
880
886
  * network_id: 'ethereum-mainnet',
881
887
  * });
888
+ * // → cryptoDest.id
889
+ *
890
+ * // Fiat US destination (for off-ramp)
891
+ * const bankDest = await client.destinations.create(recipientId, {
892
+ * destination_type: 'fiat_us',
893
+ * name: 'Acme Chase Checking',
894
+ * bank_name: 'JPMorgan Chase',
895
+ * account_holder_name: 'Acme Corp',
896
+ * account_number: '000123456789',
897
+ * aba_routing_number: '021000021',
898
+ * account_type: 'checking',
899
+ * });
900
+ * // → bankDest.id
882
901
  * ```
883
902
  */
884
903
  async create(recipientId, data, options) {
@@ -1114,6 +1133,13 @@ var TransactionsResource = class extends BaseResource {
1114
1133
  * customer_id: customerId,
1115
1134
  * status: 'completed',
1116
1135
  * });
1136
+ *
1137
+ * // Wallet-scoped filters (require transaction_type: 'wallet')
1138
+ * const sent = client.transactions.list({
1139
+ * transaction_type: 'wallet',
1140
+ * wallet_id: walletId,
1141
+ * direction: 'out',
1142
+ * });
1117
1143
  * ```
1118
1144
  */
1119
1145
  list(params) {
@@ -1255,40 +1281,76 @@ var WalletsResource = class extends BaseResource {
1255
1281
  /**
1256
1282
  * Get wallet balances.
1257
1283
  *
1284
+ * Returns the platform's full `WalletBalances` response: the wallet id,
1285
+ * its on-chain address, every per-asset balance, and a pre-computed
1286
+ * `total_amount_usd` across all assets. The previous return shape
1287
+ * (`WalletBalance[]`) silently dropped `address` and `total_amount_usd`,
1288
+ * forcing callers to do a second `wallets.get()` and sum the balances
1289
+ * by hand. This is a small breaking change with a one-line migration
1290
+ * (`balances` → `balances.balances`); the prior shape had been broken
1291
+ * since 1.3.x anyway.
1292
+ *
1258
1293
  * @param walletId - Wallet ID
1259
- * @returns Array of balances
1294
+ * @returns `{ wallet_id, address, balances, total_amount_usd }`
1260
1295
  *
1261
1296
  * @example
1262
1297
  * ```typescript
1263
- * const balances = await client.wallets.getBalances(walletId);
1264
- * for (const balance of balances) {
1265
- * console.log(balance.asset, balance.amount);
1298
+ * const { address, total_amount_usd, balances } =
1299
+ * await client.wallets.getBalances(walletId);
1300
+ * console.log(`${address} → $${total_amount_usd}`);
1301
+ * for (const b of balances) {
1302
+ * console.log(b.asset.id, b.amount_usd);
1266
1303
  * }
1267
1304
  * ```
1268
1305
  */
1269
1306
  async getBalances(walletId) {
1270
- const response = await this.transport.request({
1307
+ return this.transport.request({
1271
1308
  method: "GET",
1272
1309
  path: `/wallets/${walletId}/balances`
1273
1310
  });
1274
- return response.data;
1275
1311
  }
1276
1312
  /**
1277
- * Create a wallet transaction.
1313
+ * Send a transaction from a wallet.
1314
+ *
1315
+ * The platform expects an **endorsed request** envelope —
1316
+ * `{ signatures, intent }` — at this endpoint. Build the
1317
+ * `SendTransactionIntent`, canonicalize it per RFC 8785 (JCS), sign
1318
+ * with the wallet's signer-group ECDSA P-256 key, base64-encode the
1319
+ * DER signature, then post the envelope.
1278
1320
  *
1279
1321
  * @param walletId - Wallet ID
1280
- * @param data - Transaction data
1322
+ * @param data - Endorsed wallet transaction request: `{ signatures, intent }`
1281
1323
  * @returns Created transaction
1282
1324
  *
1283
1325
  * @example
1284
1326
  * ```typescript
1327
+ * import canonicalize from 'canonicalize';
1328
+ * import { createSign, createPrivateKey, randomUUID } from 'node:crypto';
1329
+ *
1330
+ * const intent = {
1331
+ * wallet_id: walletId,
1332
+ * caip2: 'eip155:1', // 11155111 for sepolia
1333
+ * operation: {
1334
+ * kind: 'transfer',
1335
+ * from: wallet.address,
1336
+ * to: '0x...',
1337
+ * amount: '100.00',
1338
+ * asset_id: 'USDC',
1339
+ * },
1340
+ * idempotency_key: randomUUID(),
1341
+ * };
1342
+ * const canonical = canonicalize(intent)!;
1343
+ * const sig = createSign('SHA256').update(canonical).sign({
1344
+ * key: createPrivateKey({ key: privateKeyDer, format: 'der', type: 'pkcs8' }),
1345
+ * dsaEncoding: 'der',
1346
+ * });
1285
1347
  * const tx = await client.wallets.createTransaction(walletId, {
1286
- * to: '0x...',
1287
- * amount: '100.00',
1288
- * asset: 'USDC',
1289
- * network_id: 'ethereum-mainnet',
1348
+ * signatures: [sig.toString('base64')],
1349
+ * intent,
1290
1350
  * });
1291
1351
  * ```
1352
+ *
1353
+ * @see https://docs.dakota.xyz/documentation/signing-guide
1292
1354
  */
1293
1355
  async createTransaction(walletId, data, options) {
1294
1356
  return this.transport.request({
@@ -1686,12 +1748,19 @@ var PoliciesResource = class extends BaseResource {
1686
1748
  /**
1687
1749
  * Delete a policy.
1688
1750
  *
1751
+ * Endorsed endpoint — `options.endorsement` must contain a signed
1752
+ * `DeletePolicyIntent`. The server rejects requests without a valid
1753
+ * endorsement body.
1754
+ *
1689
1755
  * @param policyId - Policy ID
1756
+ * @param options - Request options (must include `endorsement`)
1690
1757
  */
1691
- async delete(policyId) {
1758
+ async delete(policyId, options) {
1692
1759
  await this.transport.request({
1693
1760
  method: "DELETE",
1694
- path: `/policies/${policyId}`
1761
+ path: `/policies/${policyId}`,
1762
+ body: options?.endorsement,
1763
+ idempotencyKey: options?.idempotencyKey
1695
1764
  });
1696
1765
  }
1697
1766
  /**
@@ -1705,7 +1774,7 @@ var PoliciesResource = class extends BaseResource {
1705
1774
  return this.transport.request({
1706
1775
  method: "POST",
1707
1776
  path: `/policies/${policyId}/rules`,
1708
- body: data,
1777
+ body: options?.endorsement ?? data,
1709
1778
  idempotencyKey: options?.idempotencyKey
1710
1779
  });
1711
1780
  }
@@ -1721,20 +1790,27 @@ var PoliciesResource = class extends BaseResource {
1721
1790
  return this.transport.request({
1722
1791
  method: "PATCH",
1723
1792
  path: `/policies/${policyId}/rules/${ruleId}`,
1724
- body: data,
1793
+ body: options?.endorsement ?? data,
1725
1794
  idempotencyKey: options?.idempotencyKey
1726
1795
  });
1727
1796
  }
1728
1797
  /**
1729
1798
  * Delete a policy rule.
1730
1799
  *
1800
+ * Endorsed endpoint — `options.endorsement` must contain a signed
1801
+ * `RemovePolicyRuleIntent`. The server rejects requests without a valid
1802
+ * endorsement body.
1803
+ *
1731
1804
  * @param policyId - Policy ID
1732
1805
  * @param ruleId - Rule ID
1806
+ * @param options - Request options (must include `endorsement`)
1733
1807
  */
1734
- async deleteRule(policyId, ruleId) {
1808
+ async deleteRule(policyId, ruleId, options) {
1735
1809
  await this.transport.request({
1736
1810
  method: "DELETE",
1737
- path: `/policies/${policyId}/rules/${ruleId}`
1811
+ path: `/policies/${policyId}/rules/${ruleId}`,
1812
+ body: options?.endorsement,
1813
+ idempotencyKey: options?.idempotencyKey
1738
1814
  });
1739
1815
  }
1740
1816
  /**
@@ -1754,26 +1830,39 @@ var PoliciesResource = class extends BaseResource {
1754
1830
  /**
1755
1831
  * Attach a policy to a wallet.
1756
1832
  *
1833
+ * Endorsed endpoint — `options.endorsement` must contain a signed
1834
+ * `AttachPolicyToWalletIntent`. The server rejects requests without a
1835
+ * valid endorsement body.
1836
+ *
1757
1837
  * @param policyId - Policy ID
1758
1838
  * @param walletId - Wallet ID
1839
+ * @param options - Request options (must include `endorsement`)
1759
1840
  */
1760
1841
  async attachToWallet(policyId, walletId, options) {
1761
1842
  await this.transport.request({
1762
1843
  method: "PUT",
1763
1844
  path: `/policies/${policyId}/wallets/${walletId}`,
1845
+ body: options?.endorsement,
1764
1846
  idempotencyKey: options?.idempotencyKey
1765
1847
  });
1766
1848
  }
1767
1849
  /**
1768
1850
  * Detach a policy from a wallet.
1769
1851
  *
1852
+ * Endorsed endpoint — `options.endorsement` must contain a signed
1853
+ * `DetachPolicyFromWalletIntent`. The server rejects requests without a
1854
+ * valid endorsement body.
1855
+ *
1770
1856
  * @param policyId - Policy ID
1771
1857
  * @param walletId - Wallet ID
1858
+ * @param options - Request options (must include `endorsement`)
1772
1859
  */
1773
- async detachFromWallet(policyId, walletId) {
1860
+ async detachFromWallet(policyId, walletId, options) {
1774
1861
  await this.transport.request({
1775
1862
  method: "DELETE",
1776
- path: `/policies/${policyId}/wallets/${walletId}`
1863
+ path: `/policies/${policyId}/wallets/${walletId}`,
1864
+ body: options?.endorsement,
1865
+ idempotencyKey: options?.idempotencyKey
1777
1866
  });
1778
1867
  }
1779
1868
  };
@@ -1859,26 +1948,39 @@ var SignerGroupsResource = class extends BaseResource {
1859
1948
  /**
1860
1949
  * Attach a signer group to a wallet.
1861
1950
  *
1951
+ * Endorsed endpoint — `options.endorsement` must contain a signed
1952
+ * `AttachGroupToWalletIntent`. The server rejects requests without a
1953
+ * valid endorsement body.
1954
+ *
1862
1955
  * @param walletId - Wallet ID
1863
1956
  * @param signerGroupId - Signer group ID
1957
+ * @param options - Request options (must include `endorsement`)
1864
1958
  */
1865
1959
  async attachToWallet(walletId, signerGroupId, options) {
1866
1960
  await this.transport.request({
1867
1961
  method: "PUT",
1868
1962
  path: `/wallets/${walletId}/signer-groups/${signerGroupId}`,
1963
+ body: options?.endorsement,
1869
1964
  idempotencyKey: options?.idempotencyKey
1870
1965
  });
1871
1966
  }
1872
1967
  /**
1873
1968
  * Detach a signer group from a wallet.
1874
1969
  *
1970
+ * Endorsed endpoint — `options.endorsement` must contain a signed
1971
+ * `DetachGroupFromWalletIntent`. The server rejects requests without a
1972
+ * valid endorsement body.
1973
+ *
1875
1974
  * @param walletId - Wallet ID
1876
1975
  * @param signerGroupId - Signer group ID
1976
+ * @param options - Request options (must include `endorsement`)
1877
1977
  */
1878
- async detachFromWallet(walletId, signerGroupId) {
1978
+ async detachFromWallet(walletId, signerGroupId, options) {
1879
1979
  await this.transport.request({
1880
1980
  method: "DELETE",
1881
- path: `/wallets/${walletId}/signer-groups/${signerGroupId}`
1981
+ path: `/wallets/${walletId}/signer-groups/${signerGroupId}`,
1982
+ body: options?.endorsement,
1983
+ idempotencyKey: options?.idempotencyKey
1882
1984
  });
1883
1985
  }
1884
1986
  /**
@@ -2185,11 +2287,10 @@ var InfoResource = class extends BaseResource {
2185
2287
  * ```
2186
2288
  */
2187
2289
  async getCountries() {
2188
- const response = await this.transport.request({
2290
+ return this.transport.request({
2189
2291
  method: "GET",
2190
2292
  path: "/capabilities/countries"
2191
2293
  });
2192
- return response.data;
2193
2294
  }
2194
2295
  /**
2195
2296
  * Get supported networks.
@@ -2205,11 +2306,10 @@ var InfoResource = class extends BaseResource {
2205
2306
  * ```
2206
2307
  */
2207
2308
  async getNetworks() {
2208
- const response = await this.transport.request({
2309
+ return this.transport.request({
2209
2310
  method: "GET",
2210
2311
  path: "/capabilities/networks"
2211
2312
  });
2212
- return response.data;
2213
2313
  }
2214
2314
  };
2215
2315