@astrasyncai/verification-gateway 5.14.0 → 5.15.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.
Files changed (98) hide show
  1. package/README.md +27 -17
  2. package/dist/adapters/express.d.mts +1 -1
  3. package/dist/adapters/express.d.ts +1 -1
  4. package/dist/adapters/express.js +477 -240
  5. package/dist/adapters/express.js.map +1 -1
  6. package/dist/adapters/express.mjs +477 -240
  7. package/dist/adapters/express.mjs.map +1 -1
  8. package/dist/adapters/mcp.d.mts +1 -1
  9. package/dist/adapters/mcp.d.ts +1 -1
  10. package/dist/adapters/mcp.js +20 -6
  11. package/dist/adapters/mcp.js.map +1 -1
  12. package/dist/adapters/mcp.mjs +20 -6
  13. package/dist/adapters/mcp.mjs.map +1 -1
  14. package/dist/adapters/nextjs.d.mts +1 -1
  15. package/dist/adapters/nextjs.d.ts +1 -1
  16. package/dist/adapters/nextjs.js +460 -239
  17. package/dist/adapters/nextjs.js.map +1 -1
  18. package/dist/adapters/nextjs.mjs +460 -239
  19. package/dist/adapters/nextjs.mjs.map +1 -1
  20. package/dist/adapters/sdk.d.mts +18 -10
  21. package/dist/adapters/sdk.d.ts +18 -10
  22. package/dist/adapters/sdk.js +80 -23
  23. package/dist/adapters/sdk.js.map +1 -1
  24. package/dist/adapters/sdk.mjs +80 -23
  25. package/dist/adapters/sdk.mjs.map +1 -1
  26. package/dist/agent/index.js +1 -1
  27. package/dist/agent/index.js.map +1 -1
  28. package/dist/agent/index.mjs +1 -1
  29. package/dist/agent/index.mjs.map +1 -1
  30. package/dist/bin/astrasync-claude-hook.js +55 -11
  31. package/dist/bin/astrasync-codex-hook.js +55 -11
  32. package/dist/bin/astrasync-guard.js +55 -11
  33. package/dist/bin/astrasync.js +288 -33
  34. package/dist/browser/background.js +50 -6
  35. package/dist/browser/background.js.map +1 -1
  36. package/dist/browser/background.mjs +60 -6
  37. package/dist/browser/background.mjs.map +1 -1
  38. package/dist/cli/index.js +1 -1
  39. package/dist/cli/index.js.map +1 -1
  40. package/dist/cli/index.mjs +1 -1
  41. package/dist/cli/index.mjs.map +1 -1
  42. package/dist/codex/index.js +55 -11
  43. package/dist/codex/index.js.map +1 -1
  44. package/dist/codex/index.mjs +65 -11
  45. package/dist/codex/index.mjs.map +1 -1
  46. package/dist/cursor/extension.js +55 -11
  47. package/dist/cursor/extension.js.map +1 -1
  48. package/dist/cursor/extension.mjs +65 -11
  49. package/dist/cursor/extension.mjs.map +1 -1
  50. package/dist/edge-config.d.mts +31 -2
  51. package/dist/edge-config.d.ts +31 -2
  52. package/dist/edge-config.js +35 -5
  53. package/dist/edge-config.js.map +1 -1
  54. package/dist/edge-config.mjs +32 -4
  55. package/dist/edge-config.mjs.map +1 -1
  56. package/dist/edge-core/index.d.mts +11 -2
  57. package/dist/edge-core/index.d.ts +11 -2
  58. package/dist/edge-core/index.js +93 -10
  59. package/dist/edge-core/index.js.map +1 -1
  60. package/dist/edge-core/index.mjs +91 -10
  61. package/dist/edge-core/index.mjs.map +1 -1
  62. package/dist/gateway/gateway.js +50 -6
  63. package/dist/gateway/gateway.js.map +1 -1
  64. package/dist/gateway/gateway.mjs +60 -6
  65. package/dist/gateway/gateway.mjs.map +1 -1
  66. package/dist/git-trigger/git-hooks.d.mts +1 -1
  67. package/dist/git-trigger/git-hooks.d.ts +1 -1
  68. package/dist/index.d.mts +1314 -34
  69. package/dist/index.d.ts +1314 -34
  70. package/dist/index.js +5116 -2612
  71. package/dist/index.js.map +1 -1
  72. package/dist/index.mjs +5063 -2614
  73. package/dist/index.mjs.map +1 -1
  74. package/dist/registration/index.d.mts +28 -2
  75. package/dist/registration/index.d.ts +28 -2
  76. package/dist/registration/index.js +18 -3
  77. package/dist/registration/index.js.map +1 -1
  78. package/dist/registration/index.mjs +15 -2
  79. package/dist/registration/index.mjs.map +1 -1
  80. package/dist/transport/index.d.mts +7 -5
  81. package/dist/transport/index.d.ts +7 -5
  82. package/dist/transport/index.js +61 -5
  83. package/dist/transport/index.js.map +1 -1
  84. package/dist/transport/index.mjs +67 -11
  85. package/dist/transport/index.mjs.map +1 -1
  86. package/dist/{types-C_b4QTyO.d.ts → types-DtJjlW4O.d.ts} +104 -10
  87. package/dist/{types-BCkwBA84.d.mts → types-Dxf9DBpr.d.mts} +106 -12
  88. package/dist/{types-BCkwBA84.d.ts → types-Dxf9DBpr.d.ts} +106 -12
  89. package/dist/{types-DlshIIR-.d.mts → types-Eg6VoBNH.d.mts} +104 -10
  90. package/dist/ui/index.d.mts +1 -1
  91. package/dist/ui/index.d.ts +1 -1
  92. package/dist/verify.d.mts +1 -1
  93. package/dist/verify.d.ts +1 -1
  94. package/dist/verify.js +20 -6
  95. package/dist/verify.js.map +1 -1
  96. package/dist/verify.mjs +20 -6
  97. package/dist/verify.mjs.map +1 -1
  98. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var SDK_VERSION = "5.14.0";
2
+ var SDK_VERSION = "5.15.0";
3
3
 
4
4
  // src/http.ts
5
5
  var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
@@ -344,6 +344,7 @@ async function callVerifyAccessAPI(config, request) {
344
344
  if (requestData.invocationProtocol) body.invocationProtocol = requestData.invocationProtocol;
345
345
  if (requestData.commercePhase) body.commercePhase = requestData.commercePhase;
346
346
  if (requestData.checkoutSessionId) body.checkoutSessionId = requestData.checkoutSessionId;
347
+ if (requestData.checkoutJwt) body.checkoutJwt = requestData.checkoutJwt;
347
348
  if (requestData.checkoutItems) body.checkoutItems = requestData.checkoutItems;
348
349
  if (requestData.buyerEmail) body.buyerEmail = requestData.buyerEmail;
349
350
  if (requestData.commerceArtifacts) body.commerceArtifacts = requestData.commerceArtifacts;
@@ -494,7 +495,8 @@ async function verify(config, request, options) {
494
495
  "[VerificationGateway] minTrustScore / minTrustScoreForFull are deprecated in v2.3.0 and have no effect. Server is now the single source of truth for access decisions (verified ID + runtime challenge + PDLSS + trust score). To gate access to an endpoint, configure the endpoint's trust_score_requirement server-side."
495
496
  );
496
497
  }
497
- if (mergedConfig.cacheTtl !== 0 && !options?.bypassCache) {
498
+ const uncacheable = Boolean(request.commerceArtifacts);
499
+ if (mergedConfig.cacheTtl !== 0 && !options?.bypassCache && !uncacheable) {
498
500
  const cached = getCachedResult(request, mergedConfig.counterpartyId);
499
501
  if (cached) {
500
502
  if (mergedConfig.debug) {
@@ -575,7 +577,10 @@ async function verify(config, request, options) {
575
577
  // MERCHANT caller only (bridge callers strip it before the agent plane).
576
578
  settlementToken: apiResponse.settlementToken,
577
579
  // 5.6.0: fulfilment contact — merchant-only lane, same strip rule.
578
- fulfilment: apiResponse.fulfilment
580
+ fulfilment: apiResponse.fulfilment,
581
+ mandates: apiResponse.mandates,
582
+ kyaToken: apiResponse.kyaToken,
583
+ aep: apiResponse.aep
579
584
  };
580
585
  return result2;
581
586
  }
@@ -585,7 +590,10 @@ async function verify(config, request, options) {
585
590
  trustScore: apiResponse.agent.trustScore,
586
591
  trustLevel: getTrustLevel(apiResponse.agent.trustScore),
587
592
  blockchainAnchored: apiResponse.agent.blockchainStatus === "anchored",
588
- status: apiResponse.agent.agentStatus
593
+ status: apiResponse.agent.agentStatus,
594
+ ...apiResponse.agent.protocolIdentities && {
595
+ protocolIdentities: apiResponse.agent.protocolIdentities
596
+ }
589
597
  } : void 0;
590
598
  const developer = apiResponse.developer ? {
591
599
  astradId: apiResponse.developer.kyaOwnerId,
@@ -636,7 +644,11 @@ async function verify(config, request, options) {
636
644
  settlementOutcome: apiResponse.settlementOutcome,
637
645
  settlementToken: apiResponse.settlementToken,
638
646
  // 5.6.0: fulfilment contact — merchant-only lane, same strip rule.
639
- fulfilment: apiResponse.fulfilment
647
+ fulfilment: apiResponse.fulfilment,
648
+ // 5.15.0: merchant-lane AP2 mandates + KYAPay identity token.
649
+ mandates: apiResponse.mandates,
650
+ kyaToken: apiResponse.kyaToken,
651
+ aep: apiResponse.aep
640
652
  };
641
653
  if (result.recommendation === "deny") {
642
654
  result.policyAllowed = false;
@@ -656,7 +668,9 @@ async function verify(config, request, options) {
656
668
  }
657
669
  const escalates = result.requiresStepUp === true || result.requiresApproval === true || result.recommendation === "step_up_required";
658
670
  if (mergedConfig.cacheTtl !== 0 && result.recommendation !== "deny" && !escalates) {
659
- cacheResult(request, result, mergedConfig.cacheTtl, mergedConfig.counterpartyId);
671
+ if (!uncacheable) {
672
+ cacheResult(request, result, mergedConfig.cacheTtl, mergedConfig.counterpartyId);
673
+ }
660
674
  }
661
675
  return result;
662
676
  }
@@ -676,6 +690,24 @@ async function quickVerify(config, credentials) {
676
690
  };
677
691
  }
678
692
 
693
+ // src/registration/errors.ts
694
+ var AstraSyncError = class extends Error {
695
+ constructor(message, statusCode, code) {
696
+ super(message);
697
+ this.name = "AstraSyncError";
698
+ this.statusCode = statusCode;
699
+ this.code = code;
700
+ }
701
+ };
702
+ var SettlementReportError = class extends AstraSyncError {
703
+ constructor(message, statusCode, code, issues) {
704
+ super(message, statusCode, code);
705
+ this.name = "SettlementReportError";
706
+ this.issues = issues;
707
+ this.retryable = statusCode === 0 || statusCode === 429 || statusCode >= 500;
708
+ }
709
+ };
710
+
679
711
  // src/adapters/sdk.ts
680
712
  var VerificationGatewayClient = class {
681
713
  constructor(options) {
@@ -783,6 +815,7 @@ var VerificationGatewayClient = class {
783
815
  commercePhase: "confirm",
784
816
  checkoutSessionId: options.checkoutSessionId,
785
817
  checkoutItems: options.checkoutItems,
818
+ ...options.checkoutJwt && { checkoutJwt: options.checkoutJwt },
786
819
  ...options.attemptId && { attemptId: options.attemptId },
787
820
  buyerEmail: options.buyerEmail,
788
821
  counterpartyUrl: options.counterpartyUrl,
@@ -796,28 +829,52 @@ var VerificationGatewayClient = class {
796
829
  );
797
830
  }
798
831
  /**
799
- * 5.5.0 (astra-pay): report a self-settled charge outcome back to the
800
- * platform — the other half of the `settlementToken` contract. Call after
801
- * your PaymentIntent reaches a terminal state so the buyer's dashboard,
802
- * /orders and the agent's poll surface reconcile. Authenticated with this
803
- * client's api key (must be the merchant's own). Amounts must match the
804
- * order EXACTLY (integer minor units) or the report is rejected whole
805
- * (409 amount_mismatch). Replays of the same terminal state are safe.
832
+ * Report a settlement outcome back to the platform. 5.14.1: AstraSync never
833
+ * charges — EVERY merchant settles the orders it is handed (card token,
834
+ * stablecoin voucher, or a protocol-native credential) and reports here, so
835
+ * the buyer's dashboard, /orders and the agent's poll surface reconcile.
836
+ * Identify the order by the confirm's `sessionId` or the `orderId` from
837
+ * `settlementOutcome`. A settled card charge carries `processorRef` (pi_…);
838
+ * a settled stablecoin transfer carries `txHash` (+ `chainId`). Amounts must
839
+ * match the order EXACTLY (integer minor units) or the report is rejected
840
+ * whole (409 amount_mismatch). Replays of the same terminal state are safe.
806
841
  */
807
842
  async reportSettlement(options) {
843
+ if (!options.sessionId && !options.orderId) {
844
+ throw new SettlementReportError(
845
+ "reportSettlement needs sessionId or orderId",
846
+ 400,
847
+ "VALIDATION"
848
+ );
849
+ }
808
850
  const base = this.config.apiBaseUrl.replace(/\/+$/, "");
809
- const res = await sdkFetch(`${base}/merchant/settlements/report`, {
810
- method: "POST",
811
- headers: {
812
- "Content-Type": "application/json",
813
- // Same auth pair as every backend call the SDK makes (verify.ts).
814
- ...this.config.apiKey ? { Authorization: `Bearer ${this.config.apiKey}`, "X-API-Key": this.config.apiKey } : {}
815
- },
816
- body: JSON.stringify(options)
817
- });
851
+ let res;
852
+ try {
853
+ res = await sdkFetch(`${base}/merchant/settlements/report`, {
854
+ method: "POST",
855
+ headers: {
856
+ "Content-Type": "application/json",
857
+ // Same auth pair as every backend call the SDK makes (verify.ts).
858
+ ...this.config.apiKey ? { Authorization: `Bearer ${this.config.apiKey}`, "X-API-Key": this.config.apiKey } : {}
859
+ },
860
+ body: JSON.stringify(options)
861
+ });
862
+ } catch (err) {
863
+ throw new SettlementReportError(
864
+ `reportSettlement failed: ${err instanceof Error ? err.message : String(err)}`,
865
+ 0,
866
+ "network_error"
867
+ );
868
+ }
818
869
  const json = await res.json().catch(() => ({}));
819
870
  if (!res.ok || !json.success || !json.data) {
820
- throw new Error(`reportSettlement failed (${res.status}): ${json.error ?? "unknown error"}`);
871
+ const code = json.code ?? json.error ?? "unknown_error";
872
+ throw new SettlementReportError(
873
+ `reportSettlement failed (${res.status}): ${code}`,
874
+ res.status,
875
+ code,
876
+ json.issues
877
+ );
821
878
  }
822
879
  return json.data;
823
880
  }