@astrasyncai/verification-gateway 3.11.1 → 4.0.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 (99) hide show
  1. package/dist/adapter-interface/interface.d.mts +2 -2
  2. package/dist/adapter-interface/interface.d.ts +2 -2
  3. package/dist/adapters/express.d.mts +2 -2
  4. package/dist/adapters/express.d.ts +2 -2
  5. package/dist/adapters/express.js +106 -10
  6. package/dist/adapters/express.js.map +1 -1
  7. package/dist/adapters/express.mjs +106 -10
  8. package/dist/adapters/express.mjs.map +1 -1
  9. package/dist/adapters/mcp.d.mts +1 -1
  10. package/dist/adapters/mcp.d.ts +1 -1
  11. package/dist/adapters/mcp.js +111 -10
  12. package/dist/adapters/mcp.js.map +1 -1
  13. package/dist/adapters/mcp.mjs +111 -10
  14. package/dist/adapters/mcp.mjs.map +1 -1
  15. package/dist/adapters/nextjs.d.mts +2 -2
  16. package/dist/adapters/nextjs.d.ts +2 -2
  17. package/dist/adapters/nextjs.js +107 -10
  18. package/dist/adapters/nextjs.js.map +1 -1
  19. package/dist/adapters/nextjs.mjs +107 -10
  20. package/dist/adapters/nextjs.mjs.map +1 -1
  21. package/dist/adapters/sdk.d.mts +2 -2
  22. package/dist/adapters/sdk.d.ts +2 -2
  23. package/dist/adapters/sdk.js +92 -10
  24. package/dist/adapters/sdk.js.map +1 -1
  25. package/dist/adapters/sdk.mjs +92 -10
  26. package/dist/adapters/sdk.mjs.map +1 -1
  27. package/dist/agent/index.d.mts +2 -2
  28. package/dist/agent/index.d.ts +2 -2
  29. package/dist/bin/astrasync-claude-hook.js +92 -10
  30. package/dist/bin/astrasync-codex-hook.js +92 -10
  31. package/dist/bin/astrasync-guard.js +92 -10
  32. package/dist/bin/astrasync.js +93 -10
  33. package/dist/browser/background.js +92 -10
  34. package/dist/browser/background.js.map +1 -1
  35. package/dist/browser/background.mjs +92 -10
  36. package/dist/browser/background.mjs.map +1 -1
  37. package/dist/browser/browser-adapter.d.mts +2 -2
  38. package/dist/browser/browser-adapter.d.ts +2 -2
  39. package/dist/claude-code/claude-code-adapter.d.mts +2 -2
  40. package/dist/claude-code/claude-code-adapter.d.ts +2 -2
  41. package/dist/cli/index.d.mts +2 -2
  42. package/dist/cli/index.d.ts +2 -2
  43. package/dist/codex/index.d.mts +2 -2
  44. package/dist/codex/index.d.ts +2 -2
  45. package/dist/codex/index.js +92 -10
  46. package/dist/codex/index.js.map +1 -1
  47. package/dist/codex/index.mjs +92 -10
  48. package/dist/codex/index.mjs.map +1 -1
  49. package/dist/cursor/cursor-adapter.d.mts +2 -2
  50. package/dist/cursor/cursor-adapter.d.ts +2 -2
  51. package/dist/cursor/extension.d.mts +2 -2
  52. package/dist/cursor/extension.d.ts +2 -2
  53. package/dist/cursor/extension.js +92 -10
  54. package/dist/cursor/extension.js.map +1 -1
  55. package/dist/cursor/extension.mjs +92 -10
  56. package/dist/cursor/extension.mjs.map +1 -1
  57. package/dist/edge-config.d.mts +1 -1
  58. package/dist/edge-config.d.ts +1 -1
  59. package/dist/{express-DCXa1oqj.d.mts → express-BZajRs4i.d.mts} +1 -1
  60. package/dist/{express-ClNtDhhc.d.ts → express-CjCUB1k7.d.ts} +1 -1
  61. package/dist/gateway/gateway.d.mts +2 -2
  62. package/dist/gateway/gateway.d.ts +2 -2
  63. package/dist/gateway/gateway.js +92 -10
  64. package/dist/gateway/gateway.js.map +1 -1
  65. package/dist/gateway/gateway.mjs +92 -10
  66. package/dist/gateway/gateway.mjs.map +1 -1
  67. package/dist/git-trigger/git-hooks.d.mts +2 -2
  68. package/dist/git-trigger/git-hooks.d.ts +2 -2
  69. package/dist/{index-BrNKDmiR.d.mts → index-B0cyMZDL.d.mts} +1 -1
  70. package/dist/{index-Dr_XiN65.d.mts → index-BRYteOqO.d.mts} +1 -1
  71. package/dist/{index-CfHurO1P.d.ts → index-BZQdVqNw.d.ts} +1 -1
  72. package/dist/{index-D2ztkumS.d.ts → index-adgKhujR.d.ts} +1 -1
  73. package/dist/index.d.mts +9 -9
  74. package/dist/index.d.ts +9 -9
  75. package/dist/index.js +160 -10
  76. package/dist/index.js.map +1 -1
  77. package/dist/index.mjs +159 -10
  78. package/dist/index.mjs.map +1 -1
  79. package/dist/local-evaluator/evaluator.d.mts +2 -2
  80. package/dist/local-evaluator/evaluator.d.ts +2 -2
  81. package/dist/{nextjs-CEBVBsdi.d.ts → nextjs-D_iFf5k-.d.ts} +1 -1
  82. package/dist/{nextjs-DcQIk6Zj.d.mts → nextjs-DeUTnOBd.d.mts} +1 -1
  83. package/dist/{sdk-H0JCLW2y.d.ts → sdk-BM3mwEAq.d.ts} +1 -1
  84. package/dist/{sdk-CZkbSOeO.d.mts → sdk-_il1Q41f.d.mts} +1 -1
  85. package/dist/transport/index.d.mts +2 -2
  86. package/dist/transport/index.d.ts +2 -2
  87. package/dist/{types-sy3tq8lp.d.mts → types-BcDf9Kk0.d.mts} +118 -1
  88. package/dist/{types-DhFPiZ3t.d.ts → types-CHKCgDFC.d.ts} +1 -1
  89. package/dist/{types-cQVCMeNV.d.mts → types-DfnP7JiM.d.mts} +1 -1
  90. package/dist/{types-9tns4wyl.d.ts → types-fTQD448H.d.ts} +118 -1
  91. package/dist/ui/index.d.mts +1 -1
  92. package/dist/ui/index.d.ts +1 -1
  93. package/dist/verify.d.mts +15 -2
  94. package/dist/verify.d.ts +15 -2
  95. package/dist/verify.js +117 -10
  96. package/dist/verify.js.map +1 -1
  97. package/dist/verify.mjs +115 -10
  98. package/dist/verify.mjs.map +1 -1
  99. package/package.json +1 -1
@@ -3672,7 +3672,7 @@ function getTrustLevel(score) {
3672
3672
  }
3673
3673
 
3674
3674
  // src/version.ts
3675
- var SDK_VERSION = "3.11.1";
3675
+ var SDK_VERSION = "4.0.0";
3676
3676
 
3677
3677
  // src/well-known.ts
3678
3678
  var CACHE_TTL_MS = 60 * 60 * 1e3;
@@ -3698,7 +3698,7 @@ var DEFAULT_CONFIG = {
3698
3698
  };
3699
3699
  var initCheckPerformed = false;
3700
3700
  var deprecationWarningShown = false;
3701
- async function performInitCheck(apiBaseUrl, debug, strictInit) {
3701
+ async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey) {
3702
3702
  initCheckPerformed = true;
3703
3703
  try {
3704
3704
  const probeUrl = `${apiBaseUrl}/agents/verify-access`;
@@ -3715,6 +3715,28 @@ async function performInitCheck(apiBaseUrl, debug, strictInit) {
3715
3715
  `[VerificationGateway] init check passed for ${apiBaseUrl} (content-type: ${contentType})`
3716
3716
  );
3717
3717
  }
3718
+ if (apiKey) {
3719
+ const selfCheck = await fetch(`${apiBaseUrl}/agents/verify-access/self-check`, {
3720
+ headers: { Authorization: `Bearer ${apiKey}` }
3721
+ });
3722
+ if (selfCheck.status === 401) {
3723
+ const body = await selfCheck.json().catch(() => ({}));
3724
+ const message = `[VerificationGateway] the configured AstraSync API key was REJECTED at startup (${body.code ?? "api_key_invalid"}: ${body.message ?? "invalid key"}). Every inbound agent will be turned away until the key is rotated` + (body.remediation?.manageUrl ? ` at ${body.remediation.manageUrl}` : "") + `.`;
3725
+ if (strictInit) {
3726
+ throw new Error(`${message} (strictInit=true)`);
3727
+ }
3728
+ console.error(message);
3729
+ } else if (selfCheck.ok) {
3730
+ const body = await selfCheck.json().catch(() => ({}));
3731
+ if (typeof body.daysToExpiry === "number" && body.daysToExpiry <= 7) {
3732
+ console.warn(
3733
+ `[VerificationGateway] the configured AstraSync API key expires in ${body.daysToExpiry} day(s) \u2014 rotate it at Settings \u2192 Developer Tools before integrations start failing.`
3734
+ );
3735
+ } else if (debug) {
3736
+ console.log("[VerificationGateway] API key self-check passed");
3737
+ }
3738
+ }
3739
+ }
3718
3740
  } catch (err) {
3719
3741
  if (strictInit) {
3720
3742
  throw err;
@@ -3792,8 +3814,17 @@ function cacheResult(request, result, configuredTtl, counterpartyId) {
3792
3814
  function createGuidanceResponse(_config, reason, options = {}) {
3793
3815
  const source = options.source ?? "no_credentials";
3794
3816
  const isApiError = source === "api_error";
3817
+ const isMisconfig = source === "merchant_misconfig";
3795
3818
  const urls = options.urls;
3796
- const guidance = isApiError ? {
3819
+ const guidance = isMisconfig ? {
3820
+ message: "This site's AstraSync integration is misconfigured (its API key was revoked, expired, or rotated). Your identity and the AstraSync platform are fine \u2014 contact the site operator. Retrying will not help.",
3821
+ registrationUrl: urls?.registrationUrl ?? "",
3822
+ documentationUrl: options.remediation?.docsUrl ?? urls?.documentationUrl ?? "",
3823
+ steps: [
3824
+ "Report the failure to the site operator \u2014 their AstraSync API key needs rotating",
3825
+ "Do not retry: the failure is deterministic until the operator updates their key"
3826
+ ]
3827
+ } : isApiError ? {
3797
3828
  message: "Verification is temporarily unavailable. Retry with exponential backoff; if the issue persists, contact support with the correlationId.",
3798
3829
  registrationUrl: urls?.registrationUrl ?? "",
3799
3830
  documentationUrl: urls?.documentationUrl ?? "",
@@ -3831,14 +3862,24 @@ function createGuidanceResponse(_config, reason, options = {}) {
3831
3862
  // partners (and their custom onDenied handlers) can branch on
3832
3863
  // dimension. Without this, the synthesised stub was indistinguishable
3833
3864
  // from a real policy deny.
3834
- failures: isApiError ? [
3865
+ failures: isMisconfig ? [
3866
+ {
3867
+ dimension: "verify_access.merchant_misconfigured",
3868
+ message: reason ?? "The integration API key was rejected by AstraSync",
3869
+ guidance: guidance.message
3870
+ }
3871
+ ] : isApiError ? [
3835
3872
  {
3836
3873
  dimension: "verify_access.api_error",
3837
3874
  message: reason ?? "Verification temporarily unavailable",
3838
3875
  guidance: guidance.message
3839
3876
  }
3840
3877
  ] : void 0,
3878
+ // 4.0.0: typed marker so adapters render the misconfig envelope (503 +
3879
+ // MERCHANT_VERIFICATION_MISCONFIGURED) without string-matching.
3880
+ ...isMisconfig && { misconfigured: true },
3841
3881
  correlationId: options.correlationId,
3882
+ attemptId: options.attemptId,
3842
3883
  verifiedAt: /* @__PURE__ */ new Date()
3843
3884
  };
3844
3885
  }
@@ -3868,6 +3909,8 @@ async function callVerifyAccessAPI(config, request) {
3868
3909
  body.runtimeChallengeOptions = requestData.runtimeChallengeOptions;
3869
3910
  if (requestData.invocationProtocol) body.invocationProtocol = requestData.invocationProtocol;
3870
3911
  if (requestData.commerceArtifacts) body.commerceArtifacts = requestData.commerceArtifacts;
3912
+ if (requestData.attemptId) body.attemptId = requestData.attemptId;
3913
+ if (requestData.considerationSet) body.considerationSet = requestData.considerationSet;
3871
3914
  body.sdkVersion = SDK_VERSION;
3872
3915
  if (requestData.callerMetadata || requestData.clientIp || requestData.userAgent) {
3873
3916
  const meta = {
@@ -3889,12 +3932,16 @@ async function callVerifyAccessAPI(config, request) {
3889
3932
  const response = await fetch(`${config.apiBaseUrl}/agents/verify-access`, {
3890
3933
  method: "POST",
3891
3934
  headers,
3892
- body: JSON.stringify(body)
3935
+ body: JSON.stringify(body),
3936
+ signal: AbortSignal.timeout(config.verifyTimeoutMs ?? 1e4)
3893
3937
  });
3894
3938
  const data = await response.json();
3895
3939
  if (response.status === 410) {
3896
3940
  return {
3897
3941
  success: true,
3942
+ // 3.12.0 (Trust Record): keep the server-echoed attempt handle even on
3943
+ // the synthesised 410 deny shape (echoed on every branch).
3944
+ attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0,
3898
3945
  access: {
3899
3946
  allowed: false,
3900
3947
  accessLevel: "none",
@@ -3910,10 +3957,22 @@ async function callVerifyAccessAPI(config, request) {
3910
3957
  };
3911
3958
  }
3912
3959
  if (!response.ok) {
3960
+ if (response.status === 401) {
3961
+ return {
3962
+ success: false,
3963
+ error: data.message || data.error || "Integration API key rejected",
3964
+ misconfig: true,
3965
+ misconfigCode: typeof data?.code === "string" ? data.code : void 0,
3966
+ remediation: data?.remediation && typeof data.remediation === "object" ? data.remediation : void 0,
3967
+ correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
3968
+ attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
3969
+ };
3970
+ }
3913
3971
  return {
3914
3972
  success: false,
3915
3973
  error: data.message || data.error || `API returned ${response.status}`,
3916
- correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0
3974
+ correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
3975
+ attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
3917
3976
  };
3918
3977
  }
3919
3978
  return data;
@@ -3930,9 +3989,19 @@ async function verify(config, request, options) {
3930
3989
  const urls = mergedConfig.apiBaseUrl ? getCachedWellKnownUrls(mergedConfig.apiBaseUrl) : void 0;
3931
3990
  if (!initCheckPerformed && !mergedConfig.disableInitChecks && mergedConfig.apiBaseUrl) {
3932
3991
  if (mergedConfig.strictInit) {
3933
- await performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug, true);
3992
+ await performInitCheck(
3993
+ mergedConfig.apiBaseUrl,
3994
+ mergedConfig.debug,
3995
+ true,
3996
+ mergedConfig.apiKey
3997
+ );
3934
3998
  } else {
3935
- void performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug, false);
3999
+ void performInitCheck(
4000
+ mergedConfig.apiBaseUrl,
4001
+ mergedConfig.debug,
4002
+ false,
4003
+ mergedConfig.apiKey
4004
+ );
3936
4005
  }
3937
4006
  }
3938
4007
  if (!deprecationWarningShown && (config.minTrustScore !== void 0 || config.minTrustScoreForFull !== void 0)) {
@@ -3947,7 +4016,13 @@ async function verify(config, request, options) {
3947
4016
  if (mergedConfig.debug) {
3948
4017
  console.log("[VerificationGateway] Returning cached result");
3949
4018
  }
3950
- return cached;
4019
+ const hit = { ...cached };
4020
+ if (request.attemptId) {
4021
+ hit.attemptId = request.attemptId;
4022
+ } else {
4023
+ delete hit.attemptId;
4024
+ }
4025
+ return hit;
3951
4026
  }
3952
4027
  }
3953
4028
  const enrichedRequest = { ...request };
@@ -3965,8 +4040,10 @@ async function verify(config, request, options) {
3965
4040
  const serverDenialReasons = Array.isArray(rawServerDenialReasons) && rawServerDenialReasons.length > 0 ? rawServerDenialReasons : void 0;
3966
4041
  if (!apiResponse.success) {
3967
4042
  return createGuidanceResponse(mergedConfig, apiResponse.error, {
3968
- source: "api_error",
4043
+ source: apiResponse.misconfig ? "merchant_misconfig" : "api_error",
3969
4044
  correlationId: apiResponse.correlationId,
4045
+ attemptId: apiResponse.attemptId,
4046
+ remediation: apiResponse.remediation,
3970
4047
  urls
3971
4048
  });
3972
4049
  }
@@ -4002,6 +4079,9 @@ async function verify(config, request, options) {
4002
4079
  // Anonymous traffic has no session → correlationId is the per-attempt
4003
4080
  // linking key (the sessionId-equivalent for anonymous callers).
4004
4081
  correlationId: apiResponse.correlationId,
4082
+ // 3.12.0 (Trust Record): server echoes the attempt-chain handle on
4083
+ // every branch — denials included (the funnel outlives one deny).
4084
+ attemptId: apiResponse.attemptId,
4005
4085
  recommendation: apiResponse.recommendation,
4006
4086
  recommendationReasons: apiResponse.recommendationReasons,
4007
4087
  stepUpApproval: apiResponse.stepUpApproval,
@@ -4053,6 +4133,8 @@ async function verify(config, request, options) {
4053
4133
  // v2.3.10 (defect #34, round-4): anonymous responses surface correlationId
4054
4134
  // (no session row exists for unverified callers).
4055
4135
  correlationId: apiResponse.correlationId,
4136
+ // 3.12.0 (Trust Record): server-echoed attempt-chain handle.
4137
+ attemptId: apiResponse.attemptId,
4056
4138
  runtimeChallenge: apiResponse.runtimeChallenge,
4057
4139
  tokenGuidance: apiResponse.tokenGuidance,
4058
4140
  recommendation: apiResponse.recommendation,