@aura-payments/sdk 2.1.1 → 2.3.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
@@ -252,8 +252,8 @@ async function withTimeout(promise, timeoutMs, timeoutMessage) {
252
252
  }
253
253
 
254
254
  // src/resources/escrows.ts
255
- function isEscrowDeployed(e) {
256
- if (e.blockchain?.deployed) return true;
255
+ function isEscrowFundable(e) {
256
+ if (e.blockchain?.deployed || e.blockchain?.ready) return true;
257
257
  return ["deployed", "funded", "locked", "released"].includes(e.state ?? "");
258
258
  }
259
259
  function isEscrowFunded(e) {
@@ -338,11 +338,12 @@ var Escrows = class {
338
338
  * Receive USDC and split it across recipients in a single call (board D4).
339
339
  *
340
340
  * Composes the existing, crash-safe escrow path:
341
- * create → poll-until-deployed → pre-flight balance → fund → poll-until-funded → release.
341
+ * create → poll-until-fundable (deployed or completed Circle-only fallback) → pre-flight balance → fund → poll-until-funded → release.
342
342
  *
343
343
  * Funds move from an Aura wallet owned by `payerOwnerId` (the agent itself or a
344
344
  * counterparty). The result's `stage` makes a partial run explicit:
345
- * - `created` — deployment didn't confirm within `waitForDeploymentMs`
345
+ * - `created` — deploy outcome not definitive within `waitForDeploymentMs`
346
+ * (neither deployed nor the completed Circle-only fallback)
346
347
  * - `deployed` — payer wallet lacks funds (see `fundingRequired`); no money moved
347
348
  * - `funded` — funded but not released (`autoRelease:false`, or funding didn't
348
349
  * settle within `waitForFundingMs` → `fundingPending: true`)
@@ -389,12 +390,12 @@ var Escrows = class {
389
390
  const escrowId = created.escrowId;
390
391
  const deployed = await this.pollEscrowUntil(
391
392
  escrowId,
392
- isEscrowDeployed,
393
+ isEscrowFundable,
393
394
  waitForDeploymentMs,
394
395
  pollMs,
395
396
  created
396
397
  );
397
- if (!isEscrowDeployed(deployed)) {
398
+ if (!isEscrowFundable(deployed)) {
398
399
  return {
399
400
  stage: "created",
400
401
  escrow: deployed,
@@ -402,7 +403,7 @@ var Escrows = class {
402
403
  deploymentPending: true
403
404
  };
404
405
  }
405
- const payerWalletId = deployed.buyerWalletId;
406
+ const payerWalletId = deployed.buyerWalletId ?? deployed.buyerWallet?.walletId;
406
407
  const balance = await this.client.wallets.getBalance(payerWalletId);
407
408
  if (parseUsdc(balance.balance.usdc) < parseUsdc(amount)) {
408
409
  return {
@@ -479,6 +480,74 @@ var Escrows = class {
479
480
  );
480
481
  }
481
482
  };
483
+
484
+ // src/resources/insights.ts
485
+ var Insights = class {
486
+ constructor(client) {
487
+ this.client = client;
488
+ }
489
+ /**
490
+ * Revenue, transactions, active escrows and commissions for a period, each
491
+ * with its change against the prior period.
492
+ *
493
+ * The route defaults to `7d`. `start` and `end` are ISO 8601 datetimes and are
494
+ * both required when `period` is `'custom'`.
495
+ */
496
+ async overview(period, start, end) {
497
+ const query = new URLSearchParams();
498
+ if (period !== void 0) query.set("period", period);
499
+ if (start !== void 0) query.set("start", start);
500
+ if (end !== void 0) query.set("end", end);
501
+ const qs = query.toString();
502
+ return this.client["request"](
503
+ "GET",
504
+ qs ? `/v1/insights/overview?${qs}` : "/v1/insights/overview"
505
+ );
506
+ }
507
+ /**
508
+ * Forecast a metric over a horizon. Gated to Growth+ plans; lower tiers
509
+ * surface a 403 `AuraAPIError`.
510
+ */
511
+ async forecast(params) {
512
+ const query = new URLSearchParams();
513
+ query.set("metric", params.metric);
514
+ if (params.algorithm !== void 0) query.set("algorithm", params.algorithm);
515
+ if (params.period !== void 0) query.set("period", params.period);
516
+ if (params.horizon !== void 0) query.set("horizon", params.horizon.toString());
517
+ if (params.includeHistory !== void 0) {
518
+ query.set("includeHistory", String(params.includeHistory));
519
+ }
520
+ if (params.historyPeriods !== void 0) {
521
+ query.set("historyPeriods", params.historyPeriods.toString());
522
+ }
523
+ return this.client["request"](
524
+ "GET",
525
+ `/v1/insights/forecast?${query.toString()}`
526
+ );
527
+ }
528
+ /**
529
+ * Query the account audit log by action, actor, resource and date range.
530
+ *
531
+ * The route defaults to `range: '30d'`, `page: 1`, `limit: 50`.
532
+ */
533
+ async audit(params) {
534
+ const query = new URLSearchParams();
535
+ if (params?.action !== void 0) query.set("action", params.action);
536
+ if (params?.actor !== void 0) query.set("actor", params.actor);
537
+ if (params?.resourceType !== void 0) query.set("resourceType", params.resourceType);
538
+ if (params?.resourceId !== void 0) query.set("resourceId", params.resourceId);
539
+ if (params?.range !== void 0) query.set("range", params.range);
540
+ if (params?.start !== void 0) query.set("start", params.start);
541
+ if (params?.end !== void 0) query.set("end", params.end);
542
+ if (params?.page !== void 0) query.set("page", params.page.toString());
543
+ if (params?.limit !== void 0) query.set("limit", params.limit.toString());
544
+ const qs = query.toString();
545
+ return this.client["request"](
546
+ "GET",
547
+ qs ? `/v1/insights/audit?${qs}` : "/v1/insights/audit"
548
+ );
549
+ }
550
+ };
482
551
  var Mandates = class {
483
552
  constructor(client) {
484
553
  this.client = client;
@@ -604,6 +673,24 @@ var Policies = class {
604
673
  }
605
674
  };
606
675
 
676
+ // src/resources/treasury.ts
677
+ var Treasury = class {
678
+ constructor(client) {
679
+ this.client = client;
680
+ }
681
+ /**
682
+ * Analyze treasury balances, escrow exposure and pending payouts, and return
683
+ * an AI recommendation. Moves no funds.
684
+ *
685
+ * A POST with no body — the platform derives everything from the authenticated
686
+ * account. Gated to Growth+ plans; lower tiers surface a 403 `AuraAPIError`
687
+ * with code `feature_not_available`.
688
+ */
689
+ async optimize() {
690
+ return this.client["request"]("POST", "/v1/treasury/optimize");
691
+ }
692
+ };
693
+
607
694
  // src/resources/wallets.ts
608
695
  var Wallets = class {
609
696
  constructor(client) {
@@ -806,6 +893,73 @@ var Webhooks = class {
806
893
  }
807
894
  };
808
895
 
896
+ // src/resources/withdrawals.ts
897
+ var Withdrawals = class {
898
+ constructor(client) {
899
+ this.client = client;
900
+ }
901
+ /**
902
+ * Get a single withdrawal, including status, fees, destination and tx hash.
903
+ */
904
+ async get(withdrawalId) {
905
+ return this.client["request"](
906
+ "GET",
907
+ `/v1/withdrawals/${encodeURIComponent(withdrawalId)}`
908
+ );
909
+ }
910
+ /**
911
+ * List withdrawals for the account, most recent first.
912
+ *
913
+ * Returns the whole `{withdrawals, pagination}` envelope — this route does not
914
+ * use the `{success,data}` wrapper, so pagination metadata is preserved.
915
+ */
916
+ async list(params) {
917
+ const query = new URLSearchParams();
918
+ if (params?.limit !== void 0) query.set("limit", params.limit.toString());
919
+ if (params?.offset !== void 0) query.set("offset", params.offset.toString());
920
+ if (params?.status !== void 0) query.set("status", params.status);
921
+ if (params?.chain !== void 0) query.set("chain", params.chain);
922
+ if (params?.fromDate !== void 0) query.set("fromDate", params.fromDate);
923
+ if (params?.toDate !== void 0) query.set("toDate", params.toDate);
924
+ const qs = query.toString();
925
+ return this.client["request"](
926
+ "GET",
927
+ qs ? `/v1/withdrawals?${qs}` : "/v1/withdrawals"
928
+ );
929
+ }
930
+ /**
931
+ * Preview fees and net amount for a withdrawal WITHOUT creating it.
932
+ *
933
+ * `params.exchange` is required by the route when `destinationType` is
934
+ * `'exchange'`; cross-chain estimates (source ≠ destination) add a CCTP
935
+ * bridge fee and only the supported routes are accepted.
936
+ */
937
+ async estimate(params) {
938
+ return this.client["request"](
939
+ "POST",
940
+ "/v1/withdrawals/estimate",
941
+ params
942
+ );
943
+ }
944
+ /**
945
+ * Get the account's KYC-tier withdrawal limits and remaining allowance.
946
+ */
947
+ async limits() {
948
+ return this.client["request"]("GET", "/v1/withdrawals/limits");
949
+ }
950
+ /**
951
+ * Validate a destination address for a chain. Moves no funds; when `amount` is
952
+ * supplied the response also carries a fee preview.
953
+ */
954
+ async validate(params) {
955
+ return this.client["request"](
956
+ "POST",
957
+ "/v1/withdrawals/validate",
958
+ params
959
+ );
960
+ }
961
+ };
962
+
809
963
  // src/client.ts
810
964
  var AuraClient = class _AuraClient {
811
965
  constructor(config) {
@@ -823,6 +977,9 @@ var AuraClient = class _AuraClient {
823
977
  this.agents = new Agents(this);
824
978
  this.policies = new Policies(this);
825
979
  this.mandates = new Mandates(this);
980
+ this.withdrawals = new Withdrawals(this);
981
+ this.treasury = new Treasury(this);
982
+ this.insights = new Insights(this);
826
983
  }
827
984
  /**
828
985
  * Normalize the base URL so resource paths like `/v1/escrow` reach the
@@ -997,11 +1154,14 @@ exports.AuraRateLimitError = AuraRateLimitError;
997
1154
  exports.AuraTimeoutError = AuraTimeoutError;
998
1155
  exports.AuraValidationError = AuraValidationError;
999
1156
  exports.Escrows = Escrows;
1157
+ exports.Insights = Insights;
1000
1158
  exports.MandateSignature = MandateSignature;
1001
1159
  exports.Mandates = Mandates;
1002
1160
  exports.Policies = Policies;
1161
+ exports.Treasury = Treasury;
1003
1162
  exports.Wallets = Wallets;
1004
1163
  exports.Webhooks = Webhooks;
1164
+ exports.Withdrawals = Withdrawals;
1005
1165
  exports.calculateBackoff = calculateBackoff;
1006
1166
  exports.generateIdempotencyKey = generateIdempotencyKey;
1007
1167
  exports.isAuraAPIError = isAuraAPIError;
package/dist/index.mjs CHANGED
@@ -250,8 +250,8 @@ async function withTimeout(promise, timeoutMs, timeoutMessage) {
250
250
  }
251
251
 
252
252
  // src/resources/escrows.ts
253
- function isEscrowDeployed(e) {
254
- if (e.blockchain?.deployed) return true;
253
+ function isEscrowFundable(e) {
254
+ if (e.blockchain?.deployed || e.blockchain?.ready) return true;
255
255
  return ["deployed", "funded", "locked", "released"].includes(e.state ?? "");
256
256
  }
257
257
  function isEscrowFunded(e) {
@@ -336,11 +336,12 @@ var Escrows = class {
336
336
  * Receive USDC and split it across recipients in a single call (board D4).
337
337
  *
338
338
  * Composes the existing, crash-safe escrow path:
339
- * create → poll-until-deployed → pre-flight balance → fund → poll-until-funded → release.
339
+ * create → poll-until-fundable (deployed or completed Circle-only fallback) → pre-flight balance → fund → poll-until-funded → release.
340
340
  *
341
341
  * Funds move from an Aura wallet owned by `payerOwnerId` (the agent itself or a
342
342
  * counterparty). The result's `stage` makes a partial run explicit:
343
- * - `created` — deployment didn't confirm within `waitForDeploymentMs`
343
+ * - `created` — deploy outcome not definitive within `waitForDeploymentMs`
344
+ * (neither deployed nor the completed Circle-only fallback)
344
345
  * - `deployed` — payer wallet lacks funds (see `fundingRequired`); no money moved
345
346
  * - `funded` — funded but not released (`autoRelease:false`, or funding didn't
346
347
  * settle within `waitForFundingMs` → `fundingPending: true`)
@@ -387,12 +388,12 @@ var Escrows = class {
387
388
  const escrowId = created.escrowId;
388
389
  const deployed = await this.pollEscrowUntil(
389
390
  escrowId,
390
- isEscrowDeployed,
391
+ isEscrowFundable,
391
392
  waitForDeploymentMs,
392
393
  pollMs,
393
394
  created
394
395
  );
395
- if (!isEscrowDeployed(deployed)) {
396
+ if (!isEscrowFundable(deployed)) {
396
397
  return {
397
398
  stage: "created",
398
399
  escrow: deployed,
@@ -400,7 +401,7 @@ var Escrows = class {
400
401
  deploymentPending: true
401
402
  };
402
403
  }
403
- const payerWalletId = deployed.buyerWalletId;
404
+ const payerWalletId = deployed.buyerWalletId ?? deployed.buyerWallet?.walletId;
404
405
  const balance = await this.client.wallets.getBalance(payerWalletId);
405
406
  if (parseUsdc(balance.balance.usdc) < parseUsdc(amount)) {
406
407
  return {
@@ -477,6 +478,74 @@ var Escrows = class {
477
478
  );
478
479
  }
479
480
  };
481
+
482
+ // src/resources/insights.ts
483
+ var Insights = class {
484
+ constructor(client) {
485
+ this.client = client;
486
+ }
487
+ /**
488
+ * Revenue, transactions, active escrows and commissions for a period, each
489
+ * with its change against the prior period.
490
+ *
491
+ * The route defaults to `7d`. `start` and `end` are ISO 8601 datetimes and are
492
+ * both required when `period` is `'custom'`.
493
+ */
494
+ async overview(period, start, end) {
495
+ const query = new URLSearchParams();
496
+ if (period !== void 0) query.set("period", period);
497
+ if (start !== void 0) query.set("start", start);
498
+ if (end !== void 0) query.set("end", end);
499
+ const qs = query.toString();
500
+ return this.client["request"](
501
+ "GET",
502
+ qs ? `/v1/insights/overview?${qs}` : "/v1/insights/overview"
503
+ );
504
+ }
505
+ /**
506
+ * Forecast a metric over a horizon. Gated to Growth+ plans; lower tiers
507
+ * surface a 403 `AuraAPIError`.
508
+ */
509
+ async forecast(params) {
510
+ const query = new URLSearchParams();
511
+ query.set("metric", params.metric);
512
+ if (params.algorithm !== void 0) query.set("algorithm", params.algorithm);
513
+ if (params.period !== void 0) query.set("period", params.period);
514
+ if (params.horizon !== void 0) query.set("horizon", params.horizon.toString());
515
+ if (params.includeHistory !== void 0) {
516
+ query.set("includeHistory", String(params.includeHistory));
517
+ }
518
+ if (params.historyPeriods !== void 0) {
519
+ query.set("historyPeriods", params.historyPeriods.toString());
520
+ }
521
+ return this.client["request"](
522
+ "GET",
523
+ `/v1/insights/forecast?${query.toString()}`
524
+ );
525
+ }
526
+ /**
527
+ * Query the account audit log by action, actor, resource and date range.
528
+ *
529
+ * The route defaults to `range: '30d'`, `page: 1`, `limit: 50`.
530
+ */
531
+ async audit(params) {
532
+ const query = new URLSearchParams();
533
+ if (params?.action !== void 0) query.set("action", params.action);
534
+ if (params?.actor !== void 0) query.set("actor", params.actor);
535
+ if (params?.resourceType !== void 0) query.set("resourceType", params.resourceType);
536
+ if (params?.resourceId !== void 0) query.set("resourceId", params.resourceId);
537
+ if (params?.range !== void 0) query.set("range", params.range);
538
+ if (params?.start !== void 0) query.set("start", params.start);
539
+ if (params?.end !== void 0) query.set("end", params.end);
540
+ if (params?.page !== void 0) query.set("page", params.page.toString());
541
+ if (params?.limit !== void 0) query.set("limit", params.limit.toString());
542
+ const qs = query.toString();
543
+ return this.client["request"](
544
+ "GET",
545
+ qs ? `/v1/insights/audit?${qs}` : "/v1/insights/audit"
546
+ );
547
+ }
548
+ };
480
549
  var Mandates = class {
481
550
  constructor(client) {
482
551
  this.client = client;
@@ -602,6 +671,24 @@ var Policies = class {
602
671
  }
603
672
  };
604
673
 
674
+ // src/resources/treasury.ts
675
+ var Treasury = class {
676
+ constructor(client) {
677
+ this.client = client;
678
+ }
679
+ /**
680
+ * Analyze treasury balances, escrow exposure and pending payouts, and return
681
+ * an AI recommendation. Moves no funds.
682
+ *
683
+ * A POST with no body — the platform derives everything from the authenticated
684
+ * account. Gated to Growth+ plans; lower tiers surface a 403 `AuraAPIError`
685
+ * with code `feature_not_available`.
686
+ */
687
+ async optimize() {
688
+ return this.client["request"]("POST", "/v1/treasury/optimize");
689
+ }
690
+ };
691
+
605
692
  // src/resources/wallets.ts
606
693
  var Wallets = class {
607
694
  constructor(client) {
@@ -804,6 +891,73 @@ var Webhooks = class {
804
891
  }
805
892
  };
806
893
 
894
+ // src/resources/withdrawals.ts
895
+ var Withdrawals = class {
896
+ constructor(client) {
897
+ this.client = client;
898
+ }
899
+ /**
900
+ * Get a single withdrawal, including status, fees, destination and tx hash.
901
+ */
902
+ async get(withdrawalId) {
903
+ return this.client["request"](
904
+ "GET",
905
+ `/v1/withdrawals/${encodeURIComponent(withdrawalId)}`
906
+ );
907
+ }
908
+ /**
909
+ * List withdrawals for the account, most recent first.
910
+ *
911
+ * Returns the whole `{withdrawals, pagination}` envelope — this route does not
912
+ * use the `{success,data}` wrapper, so pagination metadata is preserved.
913
+ */
914
+ async list(params) {
915
+ const query = new URLSearchParams();
916
+ if (params?.limit !== void 0) query.set("limit", params.limit.toString());
917
+ if (params?.offset !== void 0) query.set("offset", params.offset.toString());
918
+ if (params?.status !== void 0) query.set("status", params.status);
919
+ if (params?.chain !== void 0) query.set("chain", params.chain);
920
+ if (params?.fromDate !== void 0) query.set("fromDate", params.fromDate);
921
+ if (params?.toDate !== void 0) query.set("toDate", params.toDate);
922
+ const qs = query.toString();
923
+ return this.client["request"](
924
+ "GET",
925
+ qs ? `/v1/withdrawals?${qs}` : "/v1/withdrawals"
926
+ );
927
+ }
928
+ /**
929
+ * Preview fees and net amount for a withdrawal WITHOUT creating it.
930
+ *
931
+ * `params.exchange` is required by the route when `destinationType` is
932
+ * `'exchange'`; cross-chain estimates (source ≠ destination) add a CCTP
933
+ * bridge fee and only the supported routes are accepted.
934
+ */
935
+ async estimate(params) {
936
+ return this.client["request"](
937
+ "POST",
938
+ "/v1/withdrawals/estimate",
939
+ params
940
+ );
941
+ }
942
+ /**
943
+ * Get the account's KYC-tier withdrawal limits and remaining allowance.
944
+ */
945
+ async limits() {
946
+ return this.client["request"]("GET", "/v1/withdrawals/limits");
947
+ }
948
+ /**
949
+ * Validate a destination address for a chain. Moves no funds; when `amount` is
950
+ * supplied the response also carries a fee preview.
951
+ */
952
+ async validate(params) {
953
+ return this.client["request"](
954
+ "POST",
955
+ "/v1/withdrawals/validate",
956
+ params
957
+ );
958
+ }
959
+ };
960
+
807
961
  // src/client.ts
808
962
  var AuraClient = class _AuraClient {
809
963
  constructor(config) {
@@ -821,6 +975,9 @@ var AuraClient = class _AuraClient {
821
975
  this.agents = new Agents(this);
822
976
  this.policies = new Policies(this);
823
977
  this.mandates = new Mandates(this);
978
+ this.withdrawals = new Withdrawals(this);
979
+ this.treasury = new Treasury(this);
980
+ this.insights = new Insights(this);
824
981
  }
825
982
  /**
826
983
  * Normalize the base URL so resource paths like `/v1/escrow` reach the
@@ -983,4 +1140,4 @@ var AuraClient = class _AuraClient {
983
1140
  }
984
1141
  };
985
1142
 
986
- export { Agents, AuraAPIError, AuraAuthenticationError, AuraClient, AuraError, AuraFaucetUnavailableError, AuraNetworkError, AuraNotFoundError, AuraRateLimitError, AuraTimeoutError, AuraValidationError, Escrows, MandateSignature, Mandates, Policies, Wallets, Webhooks, calculateBackoff, generateIdempotencyKey, isAuraAPIError, isAuraError, isAuraFaucetUnavailableError, isAuraNetworkError, isAuraTimeoutError, isRetryableError, retryWithBackoff, withTimeout };
1143
+ export { Agents, AuraAPIError, AuraAuthenticationError, AuraClient, AuraError, AuraFaucetUnavailableError, AuraNetworkError, AuraNotFoundError, AuraRateLimitError, AuraTimeoutError, AuraValidationError, Escrows, Insights, MandateSignature, Mandates, Policies, Treasury, Wallets, Webhooks, Withdrawals, calculateBackoff, generateIdempotencyKey, isAuraAPIError, isAuraError, isAuraFaucetUnavailableError, isAuraNetworkError, isAuraTimeoutError, isRetryableError, retryWithBackoff, withTimeout };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aura-payments/sdk",
3
- "version": "2.1.1",
3
+ "version": "2.3.0",
4
4
  "description": "TypeScript SDK for Aura Payments Platform",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",