@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
@@ -3936,7 +3936,7 @@ function getTrustLevel(score) {
3936
3936
  }
3937
3937
 
3938
3938
  // src/version.ts
3939
- var SDK_VERSION = "3.11.1";
3939
+ var SDK_VERSION = "4.0.0";
3940
3940
 
3941
3941
  // src/well-known.ts
3942
3942
  var CACHE_TTL_MS = 60 * 60 * 1e3;
@@ -3962,7 +3962,7 @@ var DEFAULT_CONFIG = {
3962
3962
  };
3963
3963
  var initCheckPerformed = false;
3964
3964
  var deprecationWarningShown = false;
3965
- async function performInitCheck(apiBaseUrl, debug, strictInit) {
3965
+ async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey) {
3966
3966
  initCheckPerformed = true;
3967
3967
  try {
3968
3968
  const probeUrl = `${apiBaseUrl}/agents/verify-access`;
@@ -3979,6 +3979,28 @@ async function performInitCheck(apiBaseUrl, debug, strictInit) {
3979
3979
  `[VerificationGateway] init check passed for ${apiBaseUrl} (content-type: ${contentType})`
3980
3980
  );
3981
3981
  }
3982
+ if (apiKey) {
3983
+ const selfCheck = await fetch(`${apiBaseUrl}/agents/verify-access/self-check`, {
3984
+ headers: { Authorization: `Bearer ${apiKey}` }
3985
+ });
3986
+ if (selfCheck.status === 401) {
3987
+ const body = await selfCheck.json().catch(() => ({}));
3988
+ 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}` : "") + `.`;
3989
+ if (strictInit) {
3990
+ throw new Error(`${message} (strictInit=true)`);
3991
+ }
3992
+ console.error(message);
3993
+ } else if (selfCheck.ok) {
3994
+ const body = await selfCheck.json().catch(() => ({}));
3995
+ if (typeof body.daysToExpiry === "number" && body.daysToExpiry <= 7) {
3996
+ console.warn(
3997
+ `[VerificationGateway] the configured AstraSync API key expires in ${body.daysToExpiry} day(s) \u2014 rotate it at Settings \u2192 Developer Tools before integrations start failing.`
3998
+ );
3999
+ } else if (debug) {
4000
+ console.log("[VerificationGateway] API key self-check passed");
4001
+ }
4002
+ }
4003
+ }
3982
4004
  } catch (err) {
3983
4005
  if (strictInit) {
3984
4006
  throw err;
@@ -4056,8 +4078,17 @@ function cacheResult(request, result, configuredTtl, counterpartyId) {
4056
4078
  function createGuidanceResponse(_config, reason, options = {}) {
4057
4079
  const source = options.source ?? "no_credentials";
4058
4080
  const isApiError = source === "api_error";
4081
+ const isMisconfig = source === "merchant_misconfig";
4059
4082
  const urls = options.urls;
4060
- const guidance = isApiError ? {
4083
+ const guidance = isMisconfig ? {
4084
+ 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.",
4085
+ registrationUrl: urls?.registrationUrl ?? "",
4086
+ documentationUrl: options.remediation?.docsUrl ?? urls?.documentationUrl ?? "",
4087
+ steps: [
4088
+ "Report the failure to the site operator \u2014 their AstraSync API key needs rotating",
4089
+ "Do not retry: the failure is deterministic until the operator updates their key"
4090
+ ]
4091
+ } : isApiError ? {
4061
4092
  message: "Verification is temporarily unavailable. Retry with exponential backoff; if the issue persists, contact support with the correlationId.",
4062
4093
  registrationUrl: urls?.registrationUrl ?? "",
4063
4094
  documentationUrl: urls?.documentationUrl ?? "",
@@ -4095,14 +4126,24 @@ function createGuidanceResponse(_config, reason, options = {}) {
4095
4126
  // partners (and their custom onDenied handlers) can branch on
4096
4127
  // dimension. Without this, the synthesised stub was indistinguishable
4097
4128
  // from a real policy deny.
4098
- failures: isApiError ? [
4129
+ failures: isMisconfig ? [
4130
+ {
4131
+ dimension: "verify_access.merchant_misconfigured",
4132
+ message: reason ?? "The integration API key was rejected by AstraSync",
4133
+ guidance: guidance.message
4134
+ }
4135
+ ] : isApiError ? [
4099
4136
  {
4100
4137
  dimension: "verify_access.api_error",
4101
4138
  message: reason ?? "Verification temporarily unavailable",
4102
4139
  guidance: guidance.message
4103
4140
  }
4104
4141
  ] : void 0,
4142
+ // 4.0.0: typed marker so adapters render the misconfig envelope (503 +
4143
+ // MERCHANT_VERIFICATION_MISCONFIGURED) without string-matching.
4144
+ ...isMisconfig && { misconfigured: true },
4105
4145
  correlationId: options.correlationId,
4146
+ attemptId: options.attemptId,
4106
4147
  verifiedAt: /* @__PURE__ */ new Date()
4107
4148
  };
4108
4149
  }
@@ -4132,6 +4173,8 @@ async function callVerifyAccessAPI(config, request) {
4132
4173
  body.runtimeChallengeOptions = requestData.runtimeChallengeOptions;
4133
4174
  if (requestData.invocationProtocol) body.invocationProtocol = requestData.invocationProtocol;
4134
4175
  if (requestData.commerceArtifacts) body.commerceArtifacts = requestData.commerceArtifacts;
4176
+ if (requestData.attemptId) body.attemptId = requestData.attemptId;
4177
+ if (requestData.considerationSet) body.considerationSet = requestData.considerationSet;
4135
4178
  body.sdkVersion = SDK_VERSION;
4136
4179
  if (requestData.callerMetadata || requestData.clientIp || requestData.userAgent) {
4137
4180
  const meta = {
@@ -4153,12 +4196,16 @@ async function callVerifyAccessAPI(config, request) {
4153
4196
  const response = await fetch(`${config.apiBaseUrl}/agents/verify-access`, {
4154
4197
  method: "POST",
4155
4198
  headers,
4156
- body: JSON.stringify(body)
4199
+ body: JSON.stringify(body),
4200
+ signal: AbortSignal.timeout(config.verifyTimeoutMs ?? 1e4)
4157
4201
  });
4158
4202
  const data = await response.json();
4159
4203
  if (response.status === 410) {
4160
4204
  return {
4161
4205
  success: true,
4206
+ // 3.12.0 (Trust Record): keep the server-echoed attempt handle even on
4207
+ // the synthesised 410 deny shape (echoed on every branch).
4208
+ attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0,
4162
4209
  access: {
4163
4210
  allowed: false,
4164
4211
  accessLevel: "none",
@@ -4174,10 +4221,22 @@ async function callVerifyAccessAPI(config, request) {
4174
4221
  };
4175
4222
  }
4176
4223
  if (!response.ok) {
4224
+ if (response.status === 401) {
4225
+ return {
4226
+ success: false,
4227
+ error: data.message || data.error || "Integration API key rejected",
4228
+ misconfig: true,
4229
+ misconfigCode: typeof data?.code === "string" ? data.code : void 0,
4230
+ remediation: data?.remediation && typeof data.remediation === "object" ? data.remediation : void 0,
4231
+ correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
4232
+ attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
4233
+ };
4234
+ }
4177
4235
  return {
4178
4236
  success: false,
4179
4237
  error: data.message || data.error || `API returned ${response.status}`,
4180
- correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0
4238
+ correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
4239
+ attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
4181
4240
  };
4182
4241
  }
4183
4242
  return data;
@@ -4194,9 +4253,19 @@ async function verify(config, request, options) {
4194
4253
  const urls = mergedConfig.apiBaseUrl ? getCachedWellKnownUrls(mergedConfig.apiBaseUrl) : void 0;
4195
4254
  if (!initCheckPerformed && !mergedConfig.disableInitChecks && mergedConfig.apiBaseUrl) {
4196
4255
  if (mergedConfig.strictInit) {
4197
- await performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug, true);
4256
+ await performInitCheck(
4257
+ mergedConfig.apiBaseUrl,
4258
+ mergedConfig.debug,
4259
+ true,
4260
+ mergedConfig.apiKey
4261
+ );
4198
4262
  } else {
4199
- void performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug, false);
4263
+ void performInitCheck(
4264
+ mergedConfig.apiBaseUrl,
4265
+ mergedConfig.debug,
4266
+ false,
4267
+ mergedConfig.apiKey
4268
+ );
4200
4269
  }
4201
4270
  }
4202
4271
  if (!deprecationWarningShown && (config.minTrustScore !== void 0 || config.minTrustScoreForFull !== void 0)) {
@@ -4211,7 +4280,13 @@ async function verify(config, request, options) {
4211
4280
  if (mergedConfig.debug) {
4212
4281
  console.log("[VerificationGateway] Returning cached result");
4213
4282
  }
4214
- return cached;
4283
+ const hit = { ...cached };
4284
+ if (request.attemptId) {
4285
+ hit.attemptId = request.attemptId;
4286
+ } else {
4287
+ delete hit.attemptId;
4288
+ }
4289
+ return hit;
4215
4290
  }
4216
4291
  }
4217
4292
  const enrichedRequest = { ...request };
@@ -4229,8 +4304,10 @@ async function verify(config, request, options) {
4229
4304
  const serverDenialReasons = Array.isArray(rawServerDenialReasons) && rawServerDenialReasons.length > 0 ? rawServerDenialReasons : void 0;
4230
4305
  if (!apiResponse.success) {
4231
4306
  return createGuidanceResponse(mergedConfig, apiResponse.error, {
4232
- source: "api_error",
4307
+ source: apiResponse.misconfig ? "merchant_misconfig" : "api_error",
4233
4308
  correlationId: apiResponse.correlationId,
4309
+ attemptId: apiResponse.attemptId,
4310
+ remediation: apiResponse.remediation,
4234
4311
  urls
4235
4312
  });
4236
4313
  }
@@ -4266,6 +4343,9 @@ async function verify(config, request, options) {
4266
4343
  // Anonymous traffic has no session → correlationId is the per-attempt
4267
4344
  // linking key (the sessionId-equivalent for anonymous callers).
4268
4345
  correlationId: apiResponse.correlationId,
4346
+ // 3.12.0 (Trust Record): server echoes the attempt-chain handle on
4347
+ // every branch — denials included (the funnel outlives one deny).
4348
+ attemptId: apiResponse.attemptId,
4269
4349
  recommendation: apiResponse.recommendation,
4270
4350
  recommendationReasons: apiResponse.recommendationReasons,
4271
4351
  stepUpApproval: apiResponse.stepUpApproval,
@@ -4317,6 +4397,8 @@ async function verify(config, request, options) {
4317
4397
  // v2.3.10 (defect #34, round-4): anonymous responses surface correlationId
4318
4398
  // (no session row exists for unverified callers).
4319
4399
  correlationId: apiResponse.correlationId,
4400
+ // 3.12.0 (Trust Record): server-echoed attempt-chain handle.
4401
+ attemptId: apiResponse.attemptId,
4320
4402
  runtimeChallenge: apiResponse.runtimeChallenge,
4321
4403
  tokenGuidance: apiResponse.tokenGuidance,
4322
4404
  recommendation: apiResponse.recommendation,