@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,4 +1,4 @@
1
- import { T as TrustLevel, S as SDKOptions, d as VerificationResult, c as VerificationRequest } from '../types-BCkwBA84.mjs';
1
+ import { T as TrustLevel, S as SDKOptions, d as VerificationResult, c as VerificationRequest } from '../types-Blz520bR.mjs';
2
2
 
3
3
  /**
4
4
  * AstraSync Universal Verification Gateway — Trust Level helpers.
@@ -118,6 +118,8 @@ declare class VerificationGatewayClient {
118
118
  currency?: string;
119
119
  checkoutSessionId?: string;
120
120
  checkoutItems?: VerificationRequest['checkoutItems'];
121
+ /** 5.15.0: your signed checkout (AP2 checkout_jwt) — returns `mandates` at AP2 merchants. */
122
+ checkoutJwt?: string;
121
123
  /** 5.12.0: the `att_…` attempt-chain id from the bridge handoff body. */
122
124
  attemptId?: string;
123
125
  /** 5.6.0: alternate receipt/delivery email (transit-only) — omit to let
@@ -127,21 +129,27 @@ declare class VerificationGatewayClient {
127
129
  counterpartyType?: string;
128
130
  }): Promise<VerificationResult>;
129
131
  /**
130
- * 5.5.0 (astra-pay): report a self-settled charge outcome back to the
131
- * platform — the other half of the `settlementToken` contract. Call after
132
- * your PaymentIntent reaches a terminal state so the buyer's dashboard,
133
- * /orders and the agent's poll surface reconcile. Authenticated with this
134
- * client's api key (must be the merchant's own). Amounts must match the
135
- * order EXACTLY (integer minor units) or the report is rejected whole
136
- * (409 amount_mismatch). Replays of the same terminal state are safe.
132
+ * Report a settlement outcome back to the platform. 5.14.1: AstraSync never
133
+ * charges — EVERY merchant settles the orders it is handed (card token,
134
+ * stablecoin voucher, or a protocol-native credential) and reports here, so
135
+ * the buyer's dashboard, /orders and the agent's poll surface reconcile.
136
+ * Identify the order by the confirm's `sessionId` or the `orderId` from
137
+ * `settlementOutcome`. A settled card charge carries `processorRef` (pi_…);
138
+ * a settled stablecoin transfer carries `txHash` (+ `chainId`). Amounts must
139
+ * match the order EXACTLY (integer minor units) or the report is rejected
140
+ * whole (409 amount_mismatch). Replays of the same terminal state are safe.
137
141
  */
138
142
  reportSettlement(options: {
139
- sessionId: string;
143
+ sessionId?: string;
144
+ orderId?: string;
140
145
  status: 'settled' | 'declined' | 'failed';
141
146
  amountMinor: number;
142
147
  currency: string;
143
- /** Stripe PaymentIntent id — REQUIRED when status is 'settled'. */
148
+ /** Stripe PaymentIntent id (card) — this or `txHash` is required when settled. */
144
149
  processorRef?: string;
150
+ /** Stablecoin transfer transaction hash (0x…, 32 bytes). */
151
+ txHash?: string;
152
+ chainId?: number;
145
153
  failureCode?: string;
146
154
  }): Promise<{
147
155
  orderId: string;
@@ -1,4 +1,4 @@
1
- import { T as TrustLevel, S as SDKOptions, d as VerificationResult, c as VerificationRequest } from '../types-BCkwBA84.js';
1
+ import { T as TrustLevel, S as SDKOptions, d as VerificationResult, c as VerificationRequest } from '../types-Blz520bR.js';
2
2
 
3
3
  /**
4
4
  * AstraSync Universal Verification Gateway — Trust Level helpers.
@@ -118,6 +118,8 @@ declare class VerificationGatewayClient {
118
118
  currency?: string;
119
119
  checkoutSessionId?: string;
120
120
  checkoutItems?: VerificationRequest['checkoutItems'];
121
+ /** 5.15.0: your signed checkout (AP2 checkout_jwt) — returns `mandates` at AP2 merchants. */
122
+ checkoutJwt?: string;
121
123
  /** 5.12.0: the `att_…` attempt-chain id from the bridge handoff body. */
122
124
  attemptId?: string;
123
125
  /** 5.6.0: alternate receipt/delivery email (transit-only) — omit to let
@@ -127,21 +129,27 @@ declare class VerificationGatewayClient {
127
129
  counterpartyType?: string;
128
130
  }): Promise<VerificationResult>;
129
131
  /**
130
- * 5.5.0 (astra-pay): report a self-settled charge outcome back to the
131
- * platform — the other half of the `settlementToken` contract. Call after
132
- * your PaymentIntent reaches a terminal state so the buyer's dashboard,
133
- * /orders and the agent's poll surface reconcile. Authenticated with this
134
- * client's api key (must be the merchant's own). Amounts must match the
135
- * order EXACTLY (integer minor units) or the report is rejected whole
136
- * (409 amount_mismatch). Replays of the same terminal state are safe.
132
+ * Report a settlement outcome back to the platform. 5.14.1: AstraSync never
133
+ * charges — EVERY merchant settles the orders it is handed (card token,
134
+ * stablecoin voucher, or a protocol-native credential) and reports here, so
135
+ * the buyer's dashboard, /orders and the agent's poll surface reconcile.
136
+ * Identify the order by the confirm's `sessionId` or the `orderId` from
137
+ * `settlementOutcome`. A settled card charge carries `processorRef` (pi_…);
138
+ * a settled stablecoin transfer carries `txHash` (+ `chainId`). Amounts must
139
+ * match the order EXACTLY (integer minor units) or the report is rejected
140
+ * whole (409 amount_mismatch). Replays of the same terminal state are safe.
137
141
  */
138
142
  reportSettlement(options: {
139
- sessionId: string;
143
+ sessionId?: string;
144
+ orderId?: string;
140
145
  status: 'settled' | 'declined' | 'failed';
141
146
  amountMinor: number;
142
147
  currency: string;
143
- /** Stripe PaymentIntent id — REQUIRED when status is 'settled'. */
148
+ /** Stripe PaymentIntent id (card) — this or `txHash` is required when settled. */
144
149
  processorRef?: string;
150
+ /** Stablecoin transfer transaction hash (0x…, 32 bytes). */
151
+ txHash?: string;
152
+ chainId?: number;
145
153
  failureCode?: string;
146
154
  }): Promise<{
147
155
  orderId: string;
@@ -28,7 +28,7 @@ __export(sdk_exports, {
28
28
  module.exports = __toCommonJS(sdk_exports);
29
29
 
30
30
  // src/version.ts
31
- var SDK_VERSION = "5.14.0";
31
+ var SDK_VERSION = "5.16.0";
32
32
 
33
33
  // src/http.ts
34
34
  var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
@@ -188,6 +188,8 @@ function getCacheKey(request, counterpartyId) {
188
188
  request.durationRequired ?? "",
189
189
  request.invocationProtocol || "",
190
190
  request.enableRuntimeChallenge ? "1" : "0",
191
+ // 5.16.0: route policy changes the verdict (owners / challenge).
192
+ request.routePolicy ? JSON.stringify(request.routePolicy) : "",
191
193
  // callerMetadata fields contribute to risk model; include the ones
192
194
  // backend reads. sourceIp/userAgent/forwardedFor change per-request
193
195
  // so their inclusion effectively forces a re-check for any varying
@@ -363,6 +365,7 @@ async function callVerifyAccessAPI(config, request) {
363
365
  if (requestData.subAgentDepth !== void 0) body.subAgentDepth = requestData.subAgentDepth;
364
366
  if (requestData.enableRuntimeChallenge)
365
367
  body.enableRuntimeChallenge = requestData.enableRuntimeChallenge;
368
+ if (requestData.routePolicy) body.routePolicy = requestData.routePolicy;
366
369
  if (requestData.createSession) body.createSession = requestData.createSession;
367
370
  if (requestData.durationRequired) body.durationRequired = requestData.durationRequired;
368
371
  if (requestData.counterpartyType) body.counterpartyType = requestData.counterpartyType;
@@ -373,6 +376,7 @@ async function callVerifyAccessAPI(config, request) {
373
376
  if (requestData.invocationProtocol) body.invocationProtocol = requestData.invocationProtocol;
374
377
  if (requestData.commercePhase) body.commercePhase = requestData.commercePhase;
375
378
  if (requestData.checkoutSessionId) body.checkoutSessionId = requestData.checkoutSessionId;
379
+ if (requestData.checkoutJwt) body.checkoutJwt = requestData.checkoutJwt;
376
380
  if (requestData.checkoutItems) body.checkoutItems = requestData.checkoutItems;
377
381
  if (requestData.buyerEmail) body.buyerEmail = requestData.buyerEmail;
378
382
  if (requestData.commerceArtifacts) body.commerceArtifacts = requestData.commerceArtifacts;
@@ -523,7 +527,8 @@ async function verify(config, request, options) {
523
527
  "[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."
524
528
  );
525
529
  }
526
- if (mergedConfig.cacheTtl !== 0 && !options?.bypassCache) {
530
+ const uncacheable = Boolean(request.commerceArtifacts);
531
+ if (mergedConfig.cacheTtl !== 0 && !options?.bypassCache && !uncacheable) {
527
532
  const cached = getCachedResult(request, mergedConfig.counterpartyId);
528
533
  if (cached) {
529
534
  if (mergedConfig.debug) {
@@ -604,7 +609,10 @@ async function verify(config, request, options) {
604
609
  // MERCHANT caller only (bridge callers strip it before the agent plane).
605
610
  settlementToken: apiResponse.settlementToken,
606
611
  // 5.6.0: fulfilment contact — merchant-only lane, same strip rule.
607
- fulfilment: apiResponse.fulfilment
612
+ fulfilment: apiResponse.fulfilment,
613
+ mandates: apiResponse.mandates,
614
+ kyaToken: apiResponse.kyaToken,
615
+ aep: apiResponse.aep
608
616
  };
609
617
  return result2;
610
618
  }
@@ -614,7 +622,10 @@ async function verify(config, request, options) {
614
622
  trustScore: apiResponse.agent.trustScore,
615
623
  trustLevel: getTrustLevel(apiResponse.agent.trustScore),
616
624
  blockchainAnchored: apiResponse.agent.blockchainStatus === "anchored",
617
- status: apiResponse.agent.agentStatus
625
+ status: apiResponse.agent.agentStatus,
626
+ ...apiResponse.agent.protocolIdentities && {
627
+ protocolIdentities: apiResponse.agent.protocolIdentities
628
+ }
618
629
  } : void 0;
619
630
  const developer = apiResponse.developer ? {
620
631
  astradId: apiResponse.developer.kyaOwnerId,
@@ -665,7 +676,11 @@ async function verify(config, request, options) {
665
676
  settlementOutcome: apiResponse.settlementOutcome,
666
677
  settlementToken: apiResponse.settlementToken,
667
678
  // 5.6.0: fulfilment contact — merchant-only lane, same strip rule.
668
- fulfilment: apiResponse.fulfilment
679
+ fulfilment: apiResponse.fulfilment,
680
+ // 5.15.0: merchant-lane AP2 mandates + KYAPay identity token.
681
+ mandates: apiResponse.mandates,
682
+ kyaToken: apiResponse.kyaToken,
683
+ aep: apiResponse.aep
669
684
  };
670
685
  if (result.recommendation === "deny") {
671
686
  result.policyAllowed = false;
@@ -685,7 +700,9 @@ async function verify(config, request, options) {
685
700
  }
686
701
  const escalates = result.requiresStepUp === true || result.requiresApproval === true || result.recommendation === "step_up_required";
687
702
  if (mergedConfig.cacheTtl !== 0 && result.recommendation !== "deny" && !escalates) {
688
- cacheResult(request, result, mergedConfig.cacheTtl, mergedConfig.counterpartyId);
703
+ if (!uncacheable) {
704
+ cacheResult(request, result, mergedConfig.cacheTtl, mergedConfig.counterpartyId);
705
+ }
689
706
  }
690
707
  return result;
691
708
  }
@@ -705,6 +722,24 @@ async function quickVerify(config, credentials) {
705
722
  };
706
723
  }
707
724
 
725
+ // src/registration/errors.ts
726
+ var AstraSyncError = class extends Error {
727
+ constructor(message, statusCode, code) {
728
+ super(message);
729
+ this.name = "AstraSyncError";
730
+ this.statusCode = statusCode;
731
+ this.code = code;
732
+ }
733
+ };
734
+ var SettlementReportError = class extends AstraSyncError {
735
+ constructor(message, statusCode, code, issues) {
736
+ super(message, statusCode, code);
737
+ this.name = "SettlementReportError";
738
+ this.issues = issues;
739
+ this.retryable = statusCode === 0 || statusCode === 429 || statusCode >= 500;
740
+ }
741
+ };
742
+
708
743
  // src/adapters/sdk.ts
709
744
  var VerificationGatewayClient = class {
710
745
  constructor(options) {
@@ -812,6 +847,7 @@ var VerificationGatewayClient = class {
812
847
  commercePhase: "confirm",
813
848
  checkoutSessionId: options.checkoutSessionId,
814
849
  checkoutItems: options.checkoutItems,
850
+ ...options.checkoutJwt && { checkoutJwt: options.checkoutJwt },
815
851
  ...options.attemptId && { attemptId: options.attemptId },
816
852
  buyerEmail: options.buyerEmail,
817
853
  counterpartyUrl: options.counterpartyUrl,
@@ -825,28 +861,52 @@ var VerificationGatewayClient = class {
825
861
  );
826
862
  }
827
863
  /**
828
- * 5.5.0 (astra-pay): report a self-settled charge outcome back to the
829
- * platform — the other half of the `settlementToken` contract. Call after
830
- * your PaymentIntent reaches a terminal state so the buyer's dashboard,
831
- * /orders and the agent's poll surface reconcile. Authenticated with this
832
- * client's api key (must be the merchant's own). Amounts must match the
833
- * order EXACTLY (integer minor units) or the report is rejected whole
834
- * (409 amount_mismatch). Replays of the same terminal state are safe.
864
+ * Report a settlement outcome back to the platform. 5.14.1: AstraSync never
865
+ * charges — EVERY merchant settles the orders it is handed (card token,
866
+ * stablecoin voucher, or a protocol-native credential) and reports here, so
867
+ * the buyer's dashboard, /orders and the agent's poll surface reconcile.
868
+ * Identify the order by the confirm's `sessionId` or the `orderId` from
869
+ * `settlementOutcome`. A settled card charge carries `processorRef` (pi_…);
870
+ * a settled stablecoin transfer carries `txHash` (+ `chainId`). Amounts must
871
+ * match the order EXACTLY (integer minor units) or the report is rejected
872
+ * whole (409 amount_mismatch). Replays of the same terminal state are safe.
835
873
  */
836
874
  async reportSettlement(options) {
875
+ if (!options.sessionId && !options.orderId) {
876
+ throw new SettlementReportError(
877
+ "reportSettlement needs sessionId or orderId",
878
+ 400,
879
+ "VALIDATION"
880
+ );
881
+ }
837
882
  const base = this.config.apiBaseUrl.replace(/\/+$/, "");
838
- const res = await sdkFetch(`${base}/merchant/settlements/report`, {
839
- method: "POST",
840
- headers: {
841
- "Content-Type": "application/json",
842
- // Same auth pair as every backend call the SDK makes (verify.ts).
843
- ...this.config.apiKey ? { Authorization: `Bearer ${this.config.apiKey}`, "X-API-Key": this.config.apiKey } : {}
844
- },
845
- body: JSON.stringify(options)
846
- });
883
+ let res;
884
+ try {
885
+ res = await sdkFetch(`${base}/merchant/settlements/report`, {
886
+ method: "POST",
887
+ headers: {
888
+ "Content-Type": "application/json",
889
+ // Same auth pair as every backend call the SDK makes (verify.ts).
890
+ ...this.config.apiKey ? { Authorization: `Bearer ${this.config.apiKey}`, "X-API-Key": this.config.apiKey } : {}
891
+ },
892
+ body: JSON.stringify(options)
893
+ });
894
+ } catch (err) {
895
+ throw new SettlementReportError(
896
+ `reportSettlement failed: ${err instanceof Error ? err.message : String(err)}`,
897
+ 0,
898
+ "network_error"
899
+ );
900
+ }
847
901
  const json = await res.json().catch(() => ({}));
848
902
  if (!res.ok || !json.success || !json.data) {
849
- throw new Error(`reportSettlement failed (${res.status}): ${json.error ?? "unknown error"}`);
903
+ const code = json.code ?? json.error ?? "unknown_error";
904
+ throw new SettlementReportError(
905
+ `reportSettlement failed (${res.status}): ${code}`,
906
+ res.status,
907
+ code,
908
+ json.issues
909
+ );
850
910
  }
851
911
  return json.data;
852
912
  }