@astrasyncai/verification-gateway 5.19.0 → 5.21.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 (111) hide show
  1. package/CHANGELOG.md +130 -0
  2. package/README.md +53 -4
  3. package/dist/adapter-interface/interface.d.mts +2 -2
  4. package/dist/adapter-interface/interface.d.ts +2 -2
  5. package/dist/adapters/express.d.mts +1 -1
  6. package/dist/adapters/express.d.ts +1 -1
  7. package/dist/adapters/express.js +65 -16
  8. package/dist/adapters/express.js.map +1 -1
  9. package/dist/adapters/express.mjs +65 -16
  10. package/dist/adapters/express.mjs.map +1 -1
  11. package/dist/adapters/mcp.d.mts +23 -1
  12. package/dist/adapters/mcp.d.ts +23 -1
  13. package/dist/adapters/mcp.js +91 -16
  14. package/dist/adapters/mcp.js.map +1 -1
  15. package/dist/adapters/mcp.mjs +91 -16
  16. package/dist/adapters/mcp.mjs.map +1 -1
  17. package/dist/adapters/nextjs.d.mts +1 -1
  18. package/dist/adapters/nextjs.d.ts +1 -1
  19. package/dist/adapters/nextjs.js +57 -11
  20. package/dist/adapters/nextjs.js.map +1 -1
  21. package/dist/adapters/nextjs.mjs +57 -11
  22. package/dist/adapters/nextjs.mjs.map +1 -1
  23. package/dist/adapters/sdk.d.mts +35 -2
  24. package/dist/adapters/sdk.d.ts +35 -2
  25. package/dist/adapters/sdk.js +110 -11
  26. package/dist/adapters/sdk.js.map +1 -1
  27. package/dist/adapters/sdk.mjs +110 -11
  28. package/dist/adapters/sdk.mjs.map +1 -1
  29. package/dist/agent/index.d.mts +1 -1
  30. package/dist/agent/index.d.ts +1 -1
  31. package/dist/agent/index.js +1 -1
  32. package/dist/agent/index.js.map +1 -1
  33. package/dist/agent/index.mjs +1 -1
  34. package/dist/agent/index.mjs.map +1 -1
  35. package/dist/bin/astrasync-claude-hook.js +50 -12
  36. package/dist/bin/astrasync-codex-hook.js +50 -12
  37. package/dist/bin/astrasync-guard.js +50 -12
  38. package/dist/bin/astrasync.js +65 -13
  39. package/dist/browser/background.js +50 -12
  40. package/dist/browser/background.js.map +1 -1
  41. package/dist/browser/background.mjs +50 -12
  42. package/dist/browser/background.mjs.map +1 -1
  43. package/dist/cli/index.js +1 -1
  44. package/dist/cli/index.js.map +1 -1
  45. package/dist/cli/index.mjs +1 -1
  46. package/dist/cli/index.mjs.map +1 -1
  47. package/dist/codex/index.js +50 -12
  48. package/dist/codex/index.js.map +1 -1
  49. package/dist/codex/index.mjs +50 -12
  50. package/dist/codex/index.mjs.map +1 -1
  51. package/dist/cursor/extension.js +50 -12
  52. package/dist/cursor/extension.js.map +1 -1
  53. package/dist/cursor/extension.mjs +50 -12
  54. package/dist/cursor/extension.mjs.map +1 -1
  55. package/dist/edge-config.d.mts +1 -1
  56. package/dist/edge-config.d.ts +1 -1
  57. package/dist/edge-config.js +1 -1
  58. package/dist/edge-config.js.map +1 -1
  59. package/dist/edge-config.mjs +1 -1
  60. package/dist/edge-config.mjs.map +1 -1
  61. package/dist/edge-core/index.d.mts +1 -1
  62. package/dist/edge-core/index.d.ts +1 -1
  63. package/dist/edge-core/index.js +49 -11
  64. package/dist/edge-core/index.js.map +1 -1
  65. package/dist/edge-core/index.mjs +49 -11
  66. package/dist/edge-core/index.mjs.map +1 -1
  67. package/dist/gateway/gateway.d.mts +2 -2
  68. package/dist/gateway/gateway.d.ts +2 -2
  69. package/dist/gateway/gateway.js +50 -12
  70. package/dist/gateway/gateway.js.map +1 -1
  71. package/dist/gateway/gateway.mjs +50 -12
  72. package/dist/gateway/gateway.mjs.map +1 -1
  73. package/dist/git-trigger/git-hooks.d.mts +1 -1
  74. package/dist/git-trigger/git-hooks.d.ts +1 -1
  75. package/dist/index.d.mts +286 -8
  76. package/dist/index.d.ts +286 -8
  77. package/dist/index.js +532 -49
  78. package/dist/index.js.map +1 -1
  79. package/dist/index.mjs +522 -49
  80. package/dist/index.mjs.map +1 -1
  81. package/dist/local-evaluator/evaluator.d.mts +2 -2
  82. package/dist/local-evaluator/evaluator.d.ts +2 -2
  83. package/dist/registration/index.d.mts +11 -2
  84. package/dist/registration/index.d.ts +11 -2
  85. package/dist/registration/index.js +1 -1
  86. package/dist/registration/index.js.map +1 -1
  87. package/dist/registration/index.mjs +1 -1
  88. package/dist/registration/index.mjs.map +1 -1
  89. package/dist/transport/index.d.mts +1 -1
  90. package/dist/transport/index.d.ts +1 -1
  91. package/dist/transport/index.js +1 -1
  92. package/dist/transport/index.js.map +1 -1
  93. package/dist/transport/index.mjs +1 -1
  94. package/dist/transport/index.mjs.map +1 -1
  95. package/dist/{types-BoGjyon0.d.mts → types-B4zhOAlq.d.mts} +30 -1
  96. package/dist/{types-BRz2U0Pn.d.ts → types-B_HLhZ9n.d.ts} +1 -1
  97. package/dist/{types-BfILnheI.d.mts → types-CU17R4Nr.d.mts} +11 -0
  98. package/dist/{types-BfILnheI.d.ts → types-CU17R4Nr.d.ts} +11 -0
  99. package/dist/{types-eWyZuz-3.d.ts → types-CtBXnWuV.d.ts} +30 -1
  100. package/dist/{types-DqWPkiYl.d.mts → types-DHHyXtuZ.d.mts} +30 -1
  101. package/dist/{types-DqWPkiYl.d.ts → types-DHHyXtuZ.d.ts} +30 -1
  102. package/dist/{types-CfBpm3w5.d.mts → types-Djpz-L0w.d.mts} +1 -1
  103. package/dist/ui/index.d.mts +1 -1
  104. package/dist/ui/index.d.ts +1 -1
  105. package/dist/verify.d.mts +28 -3
  106. package/dist/verify.d.ts +28 -3
  107. package/dist/verify.js +71 -11
  108. package/dist/verify.js.map +1 -1
  109. package/dist/verify.mjs +69 -11
  110. package/dist/verify.mjs.map +1 -1
  111. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var SDK_VERSION = "5.19.0";
2
+ var SDK_VERSION = "5.21.0";
3
3
 
4
4
  // src/http.ts
5
5
  var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
@@ -207,6 +207,7 @@ function cacheResult(request, result, configuredTtl, counterpartyId) {
207
207
  }
208
208
  function clearCache() {
209
209
  verificationCache.clear();
210
+ inflightVerifies.clear();
210
211
  }
211
212
  function mcpGuidance(urls) {
212
213
  if (!urls?.mcpEndpoint) return void 0;
@@ -343,6 +344,9 @@ async function callVerifyAccessAPI(config, request) {
343
344
  if (requestData.enableRuntimeChallenge)
344
345
  body.enableRuntimeChallenge = requestData.enableRuntimeChallenge;
345
346
  if (requestData.routePolicy) body.routePolicy = requestData.routePolicy;
347
+ if (config.actingProof?.connectorToken) {
348
+ body.actingProof = { connectorToken: config.actingProof.connectorToken };
349
+ }
346
350
  if (requestData.approvalHeldByRoute) body.approvalHeldByRoute = true;
347
351
  if (requestData.createSession) body.createSession = requestData.createSession;
348
352
  if (requestData.durationRequired) body.durationRequired = requestData.durationRequired;
@@ -510,22 +514,43 @@ async function verify(config, request, options) {
510
514
  "[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."
511
515
  );
512
516
  }
513
- const uncacheable = Boolean(request.commerceArtifacts);
517
+ const uncacheable = Boolean(request.commerceArtifacts) || Boolean(mergedConfig.actingProof);
514
518
  if (mergedConfig.cacheTtl !== 0 && !options?.bypassCache && !uncacheable) {
515
519
  const cached = getCachedResult(request, mergedConfig.counterpartyId);
516
520
  if (cached) {
517
521
  if (mergedConfig.debug) {
518
522
  console.log("[VerificationGateway] Returning cached result");
519
523
  }
520
- const hit = { ...cached };
521
- if (request.attemptId) {
522
- hit.attemptId = request.attemptId;
523
- } else {
524
- delete hit.attemptId;
525
- }
526
- return hit;
524
+ return sharedVerdict(cached, request);
525
+ }
526
+ }
527
+ if (mergedConfig.cacheTtl !== 0 && !options?.bypassCache && !uncacheable) {
528
+ const key = getCacheKey(request, mergedConfig.counterpartyId);
529
+ const pending = inflightVerifies.get(key);
530
+ if (pending) return sharedVerdict(await pending, request);
531
+ const flight = verifyViaApi(mergedConfig, request, urls, uncacheable);
532
+ inflightVerifies.set(key, flight);
533
+ try {
534
+ return await flight;
535
+ } finally {
536
+ inflightVerifies.delete(key);
527
537
  }
528
538
  }
539
+ return verifyViaApi(mergedConfig, request, urls, uncacheable);
540
+ }
541
+ var inflightVerifies = /* @__PURE__ */ new Map();
542
+ var sharedVerdicts = /* @__PURE__ */ new WeakSet();
543
+ function sharedVerdict(source, request) {
544
+ const hit = { ...source };
545
+ if (request.attemptId) {
546
+ hit.attemptId = request.attemptId;
547
+ } else {
548
+ delete hit.attemptId;
549
+ }
550
+ sharedVerdicts.add(hit);
551
+ return hit;
552
+ }
553
+ async function verifyViaApi(mergedConfig, request, urls, uncacheable) {
529
554
  const enrichedRequest = { ...request };
530
555
  if (!enrichedRequest.counterpartyUrl && mergedConfig.counterpartyUrl) {
531
556
  enrichedRequest.counterpartyUrl = mergedConfig.counterpartyUrl;
@@ -604,7 +629,9 @@ async function verify(config, request, options) {
604
629
  fulfilment: apiResponse.fulfilment,
605
630
  mandates: apiResponse.mandates,
606
631
  kyaToken: apiResponse.kyaToken,
607
- aep: apiResponse.aep
632
+ aep: apiResponse.aep,
633
+ // 5.20.0 (round 29.1): non-fatal integration warnings (e.g. events_url_missing).
634
+ warnings: apiResponse.warnings
608
635
  };
609
636
  return result2;
610
637
  }
@@ -672,7 +699,9 @@ async function verify(config, request, options) {
672
699
  // 5.15.0: merchant-lane AP2 mandates + KYAPay identity token.
673
700
  mandates: apiResponse.mandates,
674
701
  kyaToken: apiResponse.kyaToken,
675
- aep: apiResponse.aep
702
+ aep: apiResponse.aep,
703
+ // 5.20.0 (round 29.1): non-fatal integration warnings (e.g. events_url_missing).
704
+ warnings: apiResponse.warnings
676
705
  };
677
706
  if (result.recommendation === "deny") {
678
707
  result.policyAllowed = false;
@@ -698,8 +727,18 @@ async function verify(config, request, options) {
698
727
  cacheResult(request, result, mergedConfig.cacheTtl, mergedConfig.counterpartyId);
699
728
  }
700
729
  }
730
+ notifyVerificationListeners(request, result);
701
731
  return result;
702
732
  }
733
+ var verificationListeners = /* @__PURE__ */ new Set();
734
+ function notifyVerificationListeners(request, result) {
735
+ for (const listener of verificationListeners) {
736
+ try {
737
+ listener(result, request);
738
+ } catch {
739
+ }
740
+ }
741
+ }
703
742
  async function quickVerify(config, credentials) {
704
743
  const result = await verify(config, {
705
744
  credentials,
@@ -959,6 +998,66 @@ var VerificationGatewayClient = class {
959
998
  }
960
999
  return json.data;
961
1000
  }
1001
+ /**
1002
+ * 5.20.0 (round 29.1): ask AstraSync to send ONE signed step-up event to the
1003
+ * endpoint's Events URL now — `POST /api/endpoints/:id/events/test`.
1004
+ * Delivered synchronously, outside the event outbox (random `eventId`, no
1005
+ * retries), signed with the endpoint's webhook secret like a real event.
1006
+ * The payload is synthetic (`approvalId: "test_…"`); a kit acknowledges and
1007
+ * ignores it.
1008
+ *
1009
+ * 5.21.0 (shops' item 48): synthetic only. Sending a real held approval's
1010
+ * payload (which releases or re-drives that checkout) is dashboard-only, so
1011
+ * a leaked API key can't do it.
1012
+ *
1013
+ * Resolves even when your endpoint refused the event (`delivered: false`,
1014
+ * with `responseCode` / `error`).
1015
+ */
1016
+ async sendTestEvent(endpointId, options) {
1017
+ return this.endpointCall("POST", endpointId, "/events/test", { type: options.type });
1018
+ }
1019
+ async endpointCall(method, endpointId, suffix, body) {
1020
+ const id = endpointId ?? this.config.counterpartyId;
1021
+ if (!id) {
1022
+ throw new AstraSyncError(
1023
+ "An endpoint id (ASTRAE-\u2026) is required: pass it, or set counterpartyId on the client",
1024
+ 400,
1025
+ "VALIDATION"
1026
+ );
1027
+ }
1028
+ if (!this.config.apiKey) {
1029
+ throw new AstraSyncError("This call needs the client apiKey", 401, "AUTH_REQUIRED");
1030
+ }
1031
+ const base = this.config.apiBaseUrl.replace(/\/+$/, "");
1032
+ const url = `${base}/endpoints/${encodeURIComponent(id)}${suffix}`;
1033
+ let res;
1034
+ try {
1035
+ res = await sdkFetch(url, {
1036
+ method,
1037
+ headers: {
1038
+ "Content-Type": "application/json",
1039
+ Authorization: `Bearer ${this.config.apiKey}`,
1040
+ "X-API-Key": this.config.apiKey
1041
+ },
1042
+ body: JSON.stringify(body),
1043
+ signal: AbortSignal.timeout(Math.max(this.timeout, 15e3))
1044
+ });
1045
+ } catch (err) {
1046
+ throw new AstraSyncError(
1047
+ `${method} ${suffix || "/endpoints/:id"} failed: ${err instanceof Error ? err.message : String(err)}`,
1048
+ 0,
1049
+ "network_error"
1050
+ );
1051
+ }
1052
+ const json = await res.json().catch(() => ({}));
1053
+ if (!res.ok || json.success === false || json.data === void 0) {
1054
+ const errObj = typeof json.error === "object" ? json.error : void 0;
1055
+ const code = json.code ?? errObj?.code ?? (typeof json.error === "string" ? json.error : "unknown_error");
1056
+ const message = json.message ?? errObj?.message ?? `HTTP ${res.status}`;
1057
+ throw new AstraSyncError(`${message} (${code})`, res.status, code);
1058
+ }
1059
+ return json.data;
1060
+ }
962
1061
  /**
963
1062
  * Quick verification — checks credentials and policy in one call.
964
1063
  *