@astrasyncai/verification-gateway 5.14.0 → 5.16.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 (100) hide show
  1. package/README.md +36 -18
  2. package/dist/adapters/express.d.mts +1 -1
  3. package/dist/adapters/express.d.ts +1 -1
  4. package/dist/adapters/express.js +492 -240
  5. package/dist/adapters/express.js.map +1 -1
  6. package/dist/adapters/express.mjs +492 -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 +23 -6
  11. package/dist/adapters/mcp.js.map +1 -1
  12. package/dist/adapters/mcp.mjs +23 -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 +475 -239
  17. package/dist/adapters/nextjs.js.map +1 -1
  18. package/dist/adapters/nextjs.mjs +475 -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 +83 -23
  23. package/dist/adapters/sdk.js.map +1 -1
  24. package/dist/adapters/sdk.mjs +83 -23
  25. package/dist/adapters/sdk.mjs.map +1 -1
  26. package/dist/agent/index.d.mts +69 -54
  27. package/dist/agent/index.d.ts +69 -54
  28. package/dist/agent/index.js +24 -14
  29. package/dist/agent/index.js.map +1 -1
  30. package/dist/agent/index.mjs +24 -14
  31. package/dist/agent/index.mjs.map +1 -1
  32. package/dist/bin/astrasync-claude-hook.js +58 -11
  33. package/dist/bin/astrasync-codex-hook.js +58 -11
  34. package/dist/bin/astrasync-guard.js +177 -11
  35. package/dist/bin/astrasync.js +433 -38
  36. package/dist/browser/background.js +53 -6
  37. package/dist/browser/background.js.map +1 -1
  38. package/dist/browser/background.mjs +63 -6
  39. package/dist/browser/background.mjs.map +1 -1
  40. package/dist/cli/index.js +1 -1
  41. package/dist/cli/index.js.map +1 -1
  42. package/dist/cli/index.mjs +1 -1
  43. package/dist/cli/index.mjs.map +1 -1
  44. package/dist/codex/index.js +58 -11
  45. package/dist/codex/index.js.map +1 -1
  46. package/dist/codex/index.mjs +68 -11
  47. package/dist/codex/index.mjs.map +1 -1
  48. package/dist/cursor/extension.js +58 -11
  49. package/dist/cursor/extension.js.map +1 -1
  50. package/dist/cursor/extension.mjs +68 -11
  51. package/dist/cursor/extension.mjs.map +1 -1
  52. package/dist/edge-config.d.mts +31 -2
  53. package/dist/edge-config.d.ts +31 -2
  54. package/dist/edge-config.js +35 -5
  55. package/dist/edge-config.js.map +1 -1
  56. package/dist/edge-config.mjs +32 -4
  57. package/dist/edge-config.mjs.map +1 -1
  58. package/dist/edge-core/index.d.mts +11 -2
  59. package/dist/edge-core/index.d.ts +11 -2
  60. package/dist/edge-core/index.js +97 -11
  61. package/dist/edge-core/index.js.map +1 -1
  62. package/dist/edge-core/index.mjs +95 -11
  63. package/dist/edge-core/index.mjs.map +1 -1
  64. package/dist/gateway/gateway.js +53 -6
  65. package/dist/gateway/gateway.js.map +1 -1
  66. package/dist/gateway/gateway.mjs +63 -6
  67. package/dist/gateway/gateway.mjs.map +1 -1
  68. package/dist/git-trigger/git-hooks.d.mts +1 -1
  69. package/dist/git-trigger/git-hooks.d.ts +1 -1
  70. package/dist/index.d.mts +1407 -88
  71. package/dist/index.d.ts +1407 -88
  72. package/dist/index.js +5148 -2616
  73. package/dist/index.js.map +1 -1
  74. package/dist/index.mjs +5094 -2618
  75. package/dist/index.mjs.map +1 -1
  76. package/dist/registration/index.d.mts +28 -2
  77. package/dist/registration/index.d.ts +28 -2
  78. package/dist/registration/index.js +18 -3
  79. package/dist/registration/index.js.map +1 -1
  80. package/dist/registration/index.mjs +15 -2
  81. package/dist/registration/index.mjs.map +1 -1
  82. package/dist/transport/index.d.mts +7 -5
  83. package/dist/transport/index.d.ts +7 -5
  84. package/dist/transport/index.js +61 -5
  85. package/dist/transport/index.js.map +1 -1
  86. package/dist/transport/index.mjs +67 -11
  87. package/dist/transport/index.mjs.map +1 -1
  88. package/dist/{types-BCkwBA84.d.mts → types-Blz520bR.d.mts} +116 -12
  89. package/dist/{types-BCkwBA84.d.ts → types-Blz520bR.d.ts} +116 -12
  90. package/dist/{types-C_b4QTyO.d.ts → types-Bm1QvGqI.d.ts} +114 -10
  91. package/dist/{types-DlshIIR-.d.mts → types-DBe4hgfT.d.mts} +114 -10
  92. package/dist/ui/index.d.mts +1 -1
  93. package/dist/ui/index.d.ts +1 -1
  94. package/dist/verify.d.mts +1 -1
  95. package/dist/verify.d.ts +1 -1
  96. package/dist/verify.js +23 -6
  97. package/dist/verify.js.map +1 -1
  98. package/dist/verify.mjs +23 -6
  99. package/dist/verify.mjs.map +1 -1
  100. 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.16.0";
3
3
 
4
4
  // src/http.ts
5
5
  var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
@@ -159,6 +159,8 @@ function getCacheKey(request, counterpartyId) {
159
159
  request.durationRequired ?? "",
160
160
  request.invocationProtocol || "",
161
161
  request.enableRuntimeChallenge ? "1" : "0",
162
+ // 5.16.0: route policy changes the verdict (owners / challenge).
163
+ request.routePolicy ? JSON.stringify(request.routePolicy) : "",
162
164
  // callerMetadata fields contribute to risk model; include the ones
163
165
  // backend reads. sourceIp/userAgent/forwardedFor change per-request
164
166
  // so their inclusion effectively forces a re-check for any varying
@@ -334,6 +336,7 @@ async function callVerifyAccessAPI(config, request) {
334
336
  if (requestData.subAgentDepth !== void 0) body.subAgentDepth = requestData.subAgentDepth;
335
337
  if (requestData.enableRuntimeChallenge)
336
338
  body.enableRuntimeChallenge = requestData.enableRuntimeChallenge;
339
+ if (requestData.routePolicy) body.routePolicy = requestData.routePolicy;
337
340
  if (requestData.createSession) body.createSession = requestData.createSession;
338
341
  if (requestData.durationRequired) body.durationRequired = requestData.durationRequired;
339
342
  if (requestData.counterpartyType) body.counterpartyType = requestData.counterpartyType;
@@ -344,6 +347,7 @@ async function callVerifyAccessAPI(config, request) {
344
347
  if (requestData.invocationProtocol) body.invocationProtocol = requestData.invocationProtocol;
345
348
  if (requestData.commercePhase) body.commercePhase = requestData.commercePhase;
346
349
  if (requestData.checkoutSessionId) body.checkoutSessionId = requestData.checkoutSessionId;
350
+ if (requestData.checkoutJwt) body.checkoutJwt = requestData.checkoutJwt;
347
351
  if (requestData.checkoutItems) body.checkoutItems = requestData.checkoutItems;
348
352
  if (requestData.buyerEmail) body.buyerEmail = requestData.buyerEmail;
349
353
  if (requestData.commerceArtifacts) body.commerceArtifacts = requestData.commerceArtifacts;
@@ -494,7 +498,8 @@ async function verify(config, request, options) {
494
498
  "[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
499
  );
496
500
  }
497
- if (mergedConfig.cacheTtl !== 0 && !options?.bypassCache) {
501
+ const uncacheable = Boolean(request.commerceArtifacts);
502
+ if (mergedConfig.cacheTtl !== 0 && !options?.bypassCache && !uncacheable) {
498
503
  const cached = getCachedResult(request, mergedConfig.counterpartyId);
499
504
  if (cached) {
500
505
  if (mergedConfig.debug) {
@@ -575,7 +580,10 @@ async function verify(config, request, options) {
575
580
  // MERCHANT caller only (bridge callers strip it before the agent plane).
576
581
  settlementToken: apiResponse.settlementToken,
577
582
  // 5.6.0: fulfilment contact — merchant-only lane, same strip rule.
578
- fulfilment: apiResponse.fulfilment
583
+ fulfilment: apiResponse.fulfilment,
584
+ mandates: apiResponse.mandates,
585
+ kyaToken: apiResponse.kyaToken,
586
+ aep: apiResponse.aep
579
587
  };
580
588
  return result2;
581
589
  }
@@ -585,7 +593,10 @@ async function verify(config, request, options) {
585
593
  trustScore: apiResponse.agent.trustScore,
586
594
  trustLevel: getTrustLevel(apiResponse.agent.trustScore),
587
595
  blockchainAnchored: apiResponse.agent.blockchainStatus === "anchored",
588
- status: apiResponse.agent.agentStatus
596
+ status: apiResponse.agent.agentStatus,
597
+ ...apiResponse.agent.protocolIdentities && {
598
+ protocolIdentities: apiResponse.agent.protocolIdentities
599
+ }
589
600
  } : void 0;
590
601
  const developer = apiResponse.developer ? {
591
602
  astradId: apiResponse.developer.kyaOwnerId,
@@ -636,7 +647,11 @@ async function verify(config, request, options) {
636
647
  settlementOutcome: apiResponse.settlementOutcome,
637
648
  settlementToken: apiResponse.settlementToken,
638
649
  // 5.6.0: fulfilment contact — merchant-only lane, same strip rule.
639
- fulfilment: apiResponse.fulfilment
650
+ fulfilment: apiResponse.fulfilment,
651
+ // 5.15.0: merchant-lane AP2 mandates + KYAPay identity token.
652
+ mandates: apiResponse.mandates,
653
+ kyaToken: apiResponse.kyaToken,
654
+ aep: apiResponse.aep
640
655
  };
641
656
  if (result.recommendation === "deny") {
642
657
  result.policyAllowed = false;
@@ -656,7 +671,9 @@ async function verify(config, request, options) {
656
671
  }
657
672
  const escalates = result.requiresStepUp === true || result.requiresApproval === true || result.recommendation === "step_up_required";
658
673
  if (mergedConfig.cacheTtl !== 0 && result.recommendation !== "deny" && !escalates) {
659
- cacheResult(request, result, mergedConfig.cacheTtl, mergedConfig.counterpartyId);
674
+ if (!uncacheable) {
675
+ cacheResult(request, result, mergedConfig.cacheTtl, mergedConfig.counterpartyId);
676
+ }
660
677
  }
661
678
  return result;
662
679
  }
@@ -676,6 +693,24 @@ async function quickVerify(config, credentials) {
676
693
  };
677
694
  }
678
695
 
696
+ // src/registration/errors.ts
697
+ var AstraSyncError = class extends Error {
698
+ constructor(message, statusCode, code) {
699
+ super(message);
700
+ this.name = "AstraSyncError";
701
+ this.statusCode = statusCode;
702
+ this.code = code;
703
+ }
704
+ };
705
+ var SettlementReportError = class extends AstraSyncError {
706
+ constructor(message, statusCode, code, issues) {
707
+ super(message, statusCode, code);
708
+ this.name = "SettlementReportError";
709
+ this.issues = issues;
710
+ this.retryable = statusCode === 0 || statusCode === 429 || statusCode >= 500;
711
+ }
712
+ };
713
+
679
714
  // src/adapters/sdk.ts
680
715
  var VerificationGatewayClient = class {
681
716
  constructor(options) {
@@ -783,6 +818,7 @@ var VerificationGatewayClient = class {
783
818
  commercePhase: "confirm",
784
819
  checkoutSessionId: options.checkoutSessionId,
785
820
  checkoutItems: options.checkoutItems,
821
+ ...options.checkoutJwt && { checkoutJwt: options.checkoutJwt },
786
822
  ...options.attemptId && { attemptId: options.attemptId },
787
823
  buyerEmail: options.buyerEmail,
788
824
  counterpartyUrl: options.counterpartyUrl,
@@ -796,28 +832,52 @@ var VerificationGatewayClient = class {
796
832
  );
797
833
  }
798
834
  /**
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.
835
+ * Report a settlement outcome back to the platform. 5.14.1: AstraSync never
836
+ * charges — EVERY merchant settles the orders it is handed (card token,
837
+ * stablecoin voucher, or a protocol-native credential) and reports here, so
838
+ * the buyer's dashboard, /orders and the agent's poll surface reconcile.
839
+ * Identify the order by the confirm's `sessionId` or the `orderId` from
840
+ * `settlementOutcome`. A settled card charge carries `processorRef` (pi_…);
841
+ * a settled stablecoin transfer carries `txHash` (+ `chainId`). Amounts must
842
+ * match the order EXACTLY (integer minor units) or the report is rejected
843
+ * whole (409 amount_mismatch). Replays of the same terminal state are safe.
806
844
  */
807
845
  async reportSettlement(options) {
846
+ if (!options.sessionId && !options.orderId) {
847
+ throw new SettlementReportError(
848
+ "reportSettlement needs sessionId or orderId",
849
+ 400,
850
+ "VALIDATION"
851
+ );
852
+ }
808
853
  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
- });
854
+ let res;
855
+ try {
856
+ res = await sdkFetch(`${base}/merchant/settlements/report`, {
857
+ method: "POST",
858
+ headers: {
859
+ "Content-Type": "application/json",
860
+ // Same auth pair as every backend call the SDK makes (verify.ts).
861
+ ...this.config.apiKey ? { Authorization: `Bearer ${this.config.apiKey}`, "X-API-Key": this.config.apiKey } : {}
862
+ },
863
+ body: JSON.stringify(options)
864
+ });
865
+ } catch (err) {
866
+ throw new SettlementReportError(
867
+ `reportSettlement failed: ${err instanceof Error ? err.message : String(err)}`,
868
+ 0,
869
+ "network_error"
870
+ );
871
+ }
818
872
  const json = await res.json().catch(() => ({}));
819
873
  if (!res.ok || !json.success || !json.data) {
820
- throw new Error(`reportSettlement failed (${res.status}): ${json.error ?? "unknown error"}`);
874
+ const code = json.code ?? json.error ?? "unknown_error";
875
+ throw new SettlementReportError(
876
+ `reportSettlement failed (${res.status}): ${code}`,
877
+ res.status,
878
+ code,
879
+ json.issues
880
+ );
821
881
  }
822
882
  return json.data;
823
883
  }