@astrasyncai/verification-gateway 5.13.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 +504 -249
  5. package/dist/adapters/express.js.map +1 -1
  6. package/dist/adapters/express.mjs +504 -249
  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 +487 -248
  17. package/dist/adapters/nextjs.js.map +1 -1
  18. package/dist/adapters/nextjs.mjs +487 -248
  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 +82 -20
  31. package/dist/bin/astrasync-codex-hook.js +82 -20
  32. package/dist/bin/astrasync-guard.js +82 -20
  33. package/dist/bin/astrasync.js +316 -43
  34. package/dist/browser/background.js +77 -15
  35. package/dist/browser/background.js.map +1 -1
  36. package/dist/browser/background.mjs +87 -15
  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 +82 -20
  43. package/dist/codex/index.js.map +1 -1
  44. package/dist/codex/index.mjs +92 -20
  45. package/dist/codex/index.mjs.map +1 -1
  46. package/dist/cursor/extension.js +82 -20
  47. package/dist/cursor/extension.js.map +1 -1
  48. package/dist/cursor/extension.mjs +92 -20
  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 +43 -6
  57. package/dist/edge-core/index.d.ts +43 -6
  58. package/dist/edge-core/index.js +120 -19
  59. package/dist/edge-core/index.js.map +1 -1
  60. package/dist/edge-core/index.mjs +118 -19
  61. package/dist/edge-core/index.mjs.map +1 -1
  62. package/dist/gateway/gateway.js +77 -15
  63. package/dist/gateway/gateway.js.map +1 -1
  64. package/dist/gateway/gateway.mjs +87 -15
  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 +5143 -2621
  71. package/dist/index.js.map +1 -1
  72. package/dist/index.mjs +5090 -2623
  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.13.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}`;
@@ -19,6 +19,29 @@ function withUserAgent(initHeaders) {
19
19
  }
20
20
  var sdkFetch = (input, init) => fetch(input, { ...init, headers: withUserAgent(init?.headers) });
21
21
 
22
+ // src/route-pattern.ts
23
+ function routePatternToRegExp(pattern, opts = {}) {
24
+ let source = "";
25
+ for (let i = 0; i < pattern.length; i++) {
26
+ const ch = pattern[i];
27
+ if (ch === "*") {
28
+ source += ".*";
29
+ } else if (ch === ":" && /[A-Za-z_]/.test(pattern[i + 1] ?? "") && (i === 0 || pattern[i - 1] === "/")) {
30
+ let j = i + 1;
31
+ while (j < pattern.length && /[A-Za-z0-9_]/.test(pattern[j])) j++;
32
+ source += "[^/]+";
33
+ i = j - 1;
34
+ } else {
35
+ source += ch.replace(/[.+?^${}()|[\]\\/]/g, "\\$&");
36
+ }
37
+ }
38
+ try {
39
+ return new RegExp(`^${source}$`, opts.caseInsensitive ? "i" : "");
40
+ } catch {
41
+ return null;
42
+ }
43
+ }
44
+
22
45
  // src/edge-config.ts
23
46
  var DEFAULT_EDGE_CONFIG = Object.freeze({
24
47
  version: 1,
@@ -37,8 +60,7 @@ function matchEdgePathRule(rules, path) {
37
60
  return void 0;
38
61
  }
39
62
  function globToRegExp(pattern) {
40
- const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
41
- return new RegExp(`^${escaped}$`, "i");
63
+ return routePatternToRegExp(pattern, { caseInsensitive: true }) ?? /$^/;
42
64
  }
43
65
 
44
66
  // src/metadata-capture.ts
@@ -683,6 +705,7 @@ async function callVerifyAccessAPI(config, request) {
683
705
  if (requestData.invocationProtocol) body.invocationProtocol = requestData.invocationProtocol;
684
706
  if (requestData.commercePhase) body.commercePhase = requestData.commercePhase;
685
707
  if (requestData.checkoutSessionId) body.checkoutSessionId = requestData.checkoutSessionId;
708
+ if (requestData.checkoutJwt) body.checkoutJwt = requestData.checkoutJwt;
686
709
  if (requestData.checkoutItems) body.checkoutItems = requestData.checkoutItems;
687
710
  if (requestData.buyerEmail) body.buyerEmail = requestData.buyerEmail;
688
711
  if (requestData.commerceArtifacts) body.commerceArtifacts = requestData.commerceArtifacts;
@@ -833,7 +856,8 @@ async function verify(config, request, options) {
833
856
  "[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."
834
857
  );
835
858
  }
836
- if (mergedConfig.cacheTtl !== 0 && !options?.bypassCache) {
859
+ const uncacheable = Boolean(request.commerceArtifacts);
860
+ if (mergedConfig.cacheTtl !== 0 && !options?.bypassCache && !uncacheable) {
837
861
  const cached = getCachedResult(request, mergedConfig.counterpartyId);
838
862
  if (cached) {
839
863
  if (mergedConfig.debug) {
@@ -914,7 +938,10 @@ async function verify(config, request, options) {
914
938
  // MERCHANT caller only (bridge callers strip it before the agent plane).
915
939
  settlementToken: apiResponse.settlementToken,
916
940
  // 5.6.0: fulfilment contact — merchant-only lane, same strip rule.
917
- fulfilment: apiResponse.fulfilment
941
+ fulfilment: apiResponse.fulfilment,
942
+ mandates: apiResponse.mandates,
943
+ kyaToken: apiResponse.kyaToken,
944
+ aep: apiResponse.aep
918
945
  };
919
946
  return result2;
920
947
  }
@@ -924,7 +951,10 @@ async function verify(config, request, options) {
924
951
  trustScore: apiResponse.agent.trustScore,
925
952
  trustLevel: getTrustLevel(apiResponse.agent.trustScore),
926
953
  blockchainAnchored: apiResponse.agent.blockchainStatus === "anchored",
927
- status: apiResponse.agent.agentStatus
954
+ status: apiResponse.agent.agentStatus,
955
+ ...apiResponse.agent.protocolIdentities && {
956
+ protocolIdentities: apiResponse.agent.protocolIdentities
957
+ }
928
958
  } : void 0;
929
959
  const developer = apiResponse.developer ? {
930
960
  astradId: apiResponse.developer.kyaOwnerId,
@@ -975,7 +1005,11 @@ async function verify(config, request, options) {
975
1005
  settlementOutcome: apiResponse.settlementOutcome,
976
1006
  settlementToken: apiResponse.settlementToken,
977
1007
  // 5.6.0: fulfilment contact — merchant-only lane, same strip rule.
978
- fulfilment: apiResponse.fulfilment
1008
+ fulfilment: apiResponse.fulfilment,
1009
+ // 5.15.0: merchant-lane AP2 mandates + KYAPay identity token.
1010
+ mandates: apiResponse.mandates,
1011
+ kyaToken: apiResponse.kyaToken,
1012
+ aep: apiResponse.aep
979
1013
  };
980
1014
  if (result.recommendation === "deny") {
981
1015
  result.policyAllowed = false;
@@ -995,7 +1029,9 @@ async function verify(config, request, options) {
995
1029
  }
996
1030
  const escalates = result.requiresStepUp === true || result.requiresApproval === true || result.recommendation === "step_up_required";
997
1031
  if (mergedConfig.cacheTtl !== 0 && result.recommendation !== "deny" && !escalates) {
998
- cacheResult(request, result, mergedConfig.cacheTtl, mergedConfig.counterpartyId);
1032
+ if (!uncacheable) {
1033
+ cacheResult(request, result, mergedConfig.cacheTtl, mergedConfig.counterpartyId);
1034
+ }
999
1035
  }
1000
1036
  return result;
1001
1037
  }
@@ -1194,7 +1230,7 @@ function detectCommerce(req, host) {
1194
1230
  };
1195
1231
  }
1196
1232
  }
1197
- if (authHeader && /^Payment\s+/i.test(authHeader)) {
1233
+ if (authHeader && /^Payment\s+/i.test(authHeader) || headerValue(req, "payment-authorization")) {
1198
1234
  return {
1199
1235
  protocol: "mpp",
1200
1236
  artifacts: {
@@ -1209,7 +1245,7 @@ function detectCommerce(req, host) {
1209
1245
  evidence: truncated
1210
1246
  };
1211
1247
  }
1212
- if (headerValue(req, "x-payment")) {
1248
+ if (headerValue(req, "payment-signature") || headerValue(req, "x-payment")) {
1213
1249
  return {
1214
1250
  protocol: "x402",
1215
1251
  artifacts: {
@@ -1534,6 +1570,11 @@ async function withBudget(promise, ms) {
1534
1570
  if (timer) clearTimeout(timer);
1535
1571
  }
1536
1572
  }
1573
+ var CONTAINER_ID = (() => {
1574
+ const c = globalThis.crypto;
1575
+ if (c?.randomUUID) return c.randomUUID();
1576
+ return `c-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;
1577
+ })();
1537
1578
  var destKeyOf = (d) => `${d.apiBaseUrl}\0${d.apiKey ?? ""}\0${d.counterparty}\0${d.adapter ?? ""}`;
1538
1579
  var BeaconBuffer = class {
1539
1580
  constructor(options = {}) {
@@ -1541,6 +1582,7 @@ var BeaconBuffer = class {
1541
1582
  this.droppedSinceLast = 0;
1542
1583
  this.droppedTotal = 0;
1543
1584
  this.deliveredTotal = 0;
1585
+ this.enqueuedTotal = 0;
1544
1586
  this.backoffUntil = 0;
1545
1587
  this.collapse = /* @__PURE__ */ new Map();
1546
1588
  /** Keys the backend answered 401 for — later batches go unauthenticated. */
@@ -1553,13 +1595,16 @@ var BeaconBuffer = class {
1553
1595
  collapseMaxKeys: options.collapseMaxKeys ?? 1e3,
1554
1596
  requestTimeoutMs: options.requestTimeoutMs ?? 1e4,
1555
1597
  retryBackoffMs: options.retryBackoffMs ?? 1e3,
1598
+ holdRepeats: options.holdRepeats ?? false,
1599
+ containerId: options.containerId ?? CONTAINER_ID,
1556
1600
  now: options.now ?? Date.now
1557
1601
  };
1558
1602
  }
1559
1603
  /**
1560
1604
  * Queue one beacon. With a `collapseKey`, a repeat inside the window is
1561
- * merged into a held aggregate (sent when the window closes) instead of
1562
- * becoming its own item.
1605
+ * merged into this key's item while that item is still queued (not yet in
1606
+ * flight). Once it has left, the repeat becomes a new item, sendable on
1607
+ * this flush — nothing waits for a later invocation (round 27.6).
1563
1608
  */
1564
1609
  enqueue(dest, item, collapseKey) {
1565
1610
  const now = this.opts.now();
@@ -1572,12 +1617,15 @@ var BeaconBuffer = class {
1572
1617
  return;
1573
1618
  }
1574
1619
  }
1575
- const held = this.push(
1576
- dest,
1577
- { ...item, repeatCount: 1 },
1578
- entry.firstSeenAt + this.opts.collapseWindowMs
1579
- );
1580
- entry.held = held;
1620
+ if (this.opts.holdRepeats) {
1621
+ entry.held = this.push(
1622
+ dest,
1623
+ { ...item, repeatCount: 1 },
1624
+ entry.firstSeenAt + this.opts.collapseWindowMs
1625
+ );
1626
+ return;
1627
+ }
1628
+ entry.first = this.push(dest, { ...item, repeatCount: 1 }, now);
1581
1629
  return;
1582
1630
  }
1583
1631
  this.collapse.delete(collapseKey);
@@ -1613,6 +1661,7 @@ var BeaconBuffer = class {
1613
1661
  droppedSinceLast: this.droppedSinceLast,
1614
1662
  droppedTotal: this.droppedTotal,
1615
1663
  deliveredTotal: this.deliveredTotal,
1664
+ enqueuedTotal: this.enqueuedTotal,
1616
1665
  flushing: this.inFlight !== void 0
1617
1666
  };
1618
1667
  }
@@ -1627,6 +1676,7 @@ var BeaconBuffer = class {
1627
1676
  inFlight: false
1628
1677
  };
1629
1678
  this.queue.push(entry);
1679
+ this.enqueuedTotal += 1;
1630
1680
  return entry;
1631
1681
  }
1632
1682
  dropOldest() {
@@ -1672,7 +1722,11 @@ var BeaconBuffer = class {
1672
1722
  droppedSinceLast: reportedDropped,
1673
1723
  queueDepth: this.queue.length,
1674
1724
  adapter: dest.adapter ?? "edge-core",
1675
- version: SDK_VERSION
1725
+ version: SDK_VERSION,
1726
+ containerId: this.opts.containerId,
1727
+ enqueuedTotal: this.enqueuedTotal,
1728
+ deliveredTotal: this.deliveredTotal,
1729
+ droppedTotal: this.droppedTotal
1676
1730
  };
1677
1731
  const controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
1678
1732
  const response = await withBudget(
@@ -1853,6 +1907,7 @@ function outcomeFromVerifyResult(classification, result) {
1853
1907
  outcome.reasons = ["step-up approval required"];
1854
1908
  outcome.stepUp = {
1855
1909
  pollUrl: result.stepUpApproval?.pollUrl,
1910
+ approvalUrl: result.stepUpApproval?.approvalUrl,
1856
1911
  expiresAt: result.stepUpApproval?.expiresAt
1857
1912
  };
1858
1913
  return outcome;
@@ -1998,6 +2053,20 @@ async function evaluateEdgeRequest(options, req, config, apiKey) {
1998
2053
  if (classification.tier === "human" || classification.tier === "self") {
1999
2054
  return { policy, classification, application: passUntouched() };
2000
2055
  }
2056
+ const tls = checkMinTls(req, config.minTls);
2057
+ if (tls) {
2058
+ if (policy.mode === "enforce") {
2059
+ options.log?.(
2060
+ "info",
2061
+ `TLS ${tls.negotiated} below ${tls.minimum}: ${req.method} ${req.uri}`
2062
+ );
2063
+ return { policy, classification, application: tlsUpgradeRequired(tls) };
2064
+ }
2065
+ options.log?.(
2066
+ "info",
2067
+ `[OBSERVE] would have required TLS ${tls.minimum} (got ${tls.negotiated}): ${req.method} ${req.uri}`
2068
+ );
2069
+ }
2001
2070
  const outcome = await runTier(options, req, classification, policy, apiKey, {
2002
2071
  sampling: policy.sampling ?? config.sampling,
2003
2072
  queryValueAllowlist: config.queryValueAllowlist
@@ -2022,6 +2091,34 @@ async function evaluateEdgeRequest(options, req, config, apiKey) {
2022
2091
  return { policy, application: passUntouched() };
2023
2092
  }
2024
2093
  }
2094
+ function negotiatedTlsVersion(req) {
2095
+ const raw = req.connection?.tlsVersion ?? headerValue(req, "cloudfront-viewer-tls");
2096
+ const m = raw ? /^TLSv(1(?:\.\d)?)/i.exec(raw) : null;
2097
+ return m ? m[1] === "1" ? "1.0" : m[1] : null;
2098
+ }
2099
+ function checkMinTls(req, minTls) {
2100
+ if (!minTls) return null;
2101
+ const negotiated = negotiatedTlsVersion(req);
2102
+ if (!negotiated) return null;
2103
+ return Number(negotiated) < Number(minTls) ? { minimum: minTls, negotiated } : null;
2104
+ }
2105
+ function tlsUpgradeRequired(v) {
2106
+ return {
2107
+ action: "respond",
2108
+ status: 426,
2109
+ headers: {
2110
+ "content-type": "application/json",
2111
+ upgrade: `TLS/${v.minimum}`,
2112
+ connection: "Upgrade"
2113
+ },
2114
+ bodyJson: {
2115
+ error: "tls_version_too_low",
2116
+ minimum: `TLS ${v.minimum}`,
2117
+ negotiated: `TLS ${v.negotiated}`,
2118
+ message: `This endpoint requires TLS ${v.minimum} or later for agent requests. Reconnect with TLS ${v.minimum}.`
2119
+ }
2120
+ };
2121
+ }
2025
2122
  export {
2026
2123
  ASAT_HEADERS,
2027
2124
  BeaconBuffer,
@@ -2031,12 +2128,14 @@ export {
2031
2128
  buildManualReviewBody,
2032
2129
  buildObservedMetadata,
2033
2130
  buildVerificationRequest,
2131
+ checkMinTls,
2034
2132
  classify,
2035
2133
  detectCommerce,
2036
2134
  emitBeacon,
2037
2135
  evaluateEdgeRequest,
2038
2136
  getBeaconBuffer,
2039
2137
  headerValue,
2138
+ negotiatedTlsVersion,
2040
2139
  outcomeFromVerifyResult,
2041
2140
  passUntouched,
2042
2141
  requestUrl,