@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
@@ -1,3 +1,3 @@
1
- import '../types-sy3tq8lp.mjs';
2
- export { V as VerificationGatewayClient, c as createClient, e as getCapabilities, f as getTrustLevel, h as hasMinimumAccess, v as verifyOnce } from '../sdk-CZkbSOeO.mjs';
1
+ import '../types-BcDf9Kk0.mjs';
2
+ export { V as VerificationGatewayClient, c as createClient, e as getCapabilities, f as getTrustLevel, h as hasMinimumAccess, v as verifyOnce } from '../sdk-_il1Q41f.mjs';
3
3
  import '../metadata-capture.mjs';
@@ -1,3 +1,3 @@
1
- import '../types-9tns4wyl.js';
2
- export { V as VerificationGatewayClient, c as createClient, e as getCapabilities, f as getTrustLevel, h as hasMinimumAccess, v as verifyOnce } from '../sdk-H0JCLW2y.js';
1
+ import '../types-fTQD448H.js';
2
+ export { V as VerificationGatewayClient, c as createClient, e as getCapabilities, f as getTrustLevel, h as hasMinimumAccess, v as verifyOnce } from '../sdk-BM3mwEAq.js';
3
3
  import '../metadata-capture.js';
@@ -109,7 +109,7 @@ function getCapabilities(accessLevel) {
109
109
  }
110
110
 
111
111
  // src/version.ts
112
- var SDK_VERSION = "3.11.1";
112
+ var SDK_VERSION = "4.0.0";
113
113
 
114
114
  // src/well-known.ts
115
115
  var CACHE_TTL_MS = 60 * 60 * 1e3;
@@ -135,7 +135,7 @@ var DEFAULT_CONFIG = {
135
135
  };
136
136
  var initCheckPerformed = false;
137
137
  var deprecationWarningShown = false;
138
- async function performInitCheck(apiBaseUrl, debug, strictInit) {
138
+ async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey) {
139
139
  initCheckPerformed = true;
140
140
  try {
141
141
  const probeUrl = `${apiBaseUrl}/agents/verify-access`;
@@ -152,6 +152,28 @@ async function performInitCheck(apiBaseUrl, debug, strictInit) {
152
152
  `[VerificationGateway] init check passed for ${apiBaseUrl} (content-type: ${contentType})`
153
153
  );
154
154
  }
155
+ if (apiKey) {
156
+ const selfCheck = await fetch(`${apiBaseUrl}/agents/verify-access/self-check`, {
157
+ headers: { Authorization: `Bearer ${apiKey}` }
158
+ });
159
+ if (selfCheck.status === 401) {
160
+ const body = await selfCheck.json().catch(() => ({}));
161
+ 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}` : "") + `.`;
162
+ if (strictInit) {
163
+ throw new Error(`${message} (strictInit=true)`);
164
+ }
165
+ console.error(message);
166
+ } else if (selfCheck.ok) {
167
+ const body = await selfCheck.json().catch(() => ({}));
168
+ if (typeof body.daysToExpiry === "number" && body.daysToExpiry <= 7) {
169
+ console.warn(
170
+ `[VerificationGateway] the configured AstraSync API key expires in ${body.daysToExpiry} day(s) \u2014 rotate it at Settings \u2192 Developer Tools before integrations start failing.`
171
+ );
172
+ } else if (debug) {
173
+ console.log("[VerificationGateway] API key self-check passed");
174
+ }
175
+ }
176
+ }
155
177
  } catch (err) {
156
178
  if (strictInit) {
157
179
  throw err;
@@ -232,8 +254,17 @@ function clearCache() {
232
254
  function createGuidanceResponse(_config, reason, options = {}) {
233
255
  const source = options.source ?? "no_credentials";
234
256
  const isApiError = source === "api_error";
257
+ const isMisconfig = source === "merchant_misconfig";
235
258
  const urls = options.urls;
236
- const guidance = isApiError ? {
259
+ const guidance = isMisconfig ? {
260
+ 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.",
261
+ registrationUrl: urls?.registrationUrl ?? "",
262
+ documentationUrl: options.remediation?.docsUrl ?? urls?.documentationUrl ?? "",
263
+ steps: [
264
+ "Report the failure to the site operator \u2014 their AstraSync API key needs rotating",
265
+ "Do not retry: the failure is deterministic until the operator updates their key"
266
+ ]
267
+ } : isApiError ? {
237
268
  message: "Verification is temporarily unavailable. Retry with exponential backoff; if the issue persists, contact support with the correlationId.",
238
269
  registrationUrl: urls?.registrationUrl ?? "",
239
270
  documentationUrl: urls?.documentationUrl ?? "",
@@ -271,14 +302,24 @@ function createGuidanceResponse(_config, reason, options = {}) {
271
302
  // partners (and their custom onDenied handlers) can branch on
272
303
  // dimension. Without this, the synthesised stub was indistinguishable
273
304
  // from a real policy deny.
274
- failures: isApiError ? [
305
+ failures: isMisconfig ? [
306
+ {
307
+ dimension: "verify_access.merchant_misconfigured",
308
+ message: reason ?? "The integration API key was rejected by AstraSync",
309
+ guidance: guidance.message
310
+ }
311
+ ] : isApiError ? [
275
312
  {
276
313
  dimension: "verify_access.api_error",
277
314
  message: reason ?? "Verification temporarily unavailable",
278
315
  guidance: guidance.message
279
316
  }
280
317
  ] : void 0,
318
+ // 4.0.0: typed marker so adapters render the misconfig envelope (503 +
319
+ // MERCHANT_VERIFICATION_MISCONFIGURED) without string-matching.
320
+ ...isMisconfig && { misconfigured: true },
281
321
  correlationId: options.correlationId,
322
+ attemptId: options.attemptId,
282
323
  verifiedAt: /* @__PURE__ */ new Date()
283
324
  };
284
325
  }
@@ -308,6 +349,8 @@ async function callVerifyAccessAPI(config, request) {
308
349
  body.runtimeChallengeOptions = requestData.runtimeChallengeOptions;
309
350
  if (requestData.invocationProtocol) body.invocationProtocol = requestData.invocationProtocol;
310
351
  if (requestData.commerceArtifacts) body.commerceArtifacts = requestData.commerceArtifacts;
352
+ if (requestData.attemptId) body.attemptId = requestData.attemptId;
353
+ if (requestData.considerationSet) body.considerationSet = requestData.considerationSet;
311
354
  body.sdkVersion = SDK_VERSION;
312
355
  if (requestData.callerMetadata || requestData.clientIp || requestData.userAgent) {
313
356
  const meta = {
@@ -329,12 +372,16 @@ async function callVerifyAccessAPI(config, request) {
329
372
  const response = await fetch(`${config.apiBaseUrl}/agents/verify-access`, {
330
373
  method: "POST",
331
374
  headers,
332
- body: JSON.stringify(body)
375
+ body: JSON.stringify(body),
376
+ signal: AbortSignal.timeout(config.verifyTimeoutMs ?? 1e4)
333
377
  });
334
378
  const data = await response.json();
335
379
  if (response.status === 410) {
336
380
  return {
337
381
  success: true,
382
+ // 3.12.0 (Trust Record): keep the server-echoed attempt handle even on
383
+ // the synthesised 410 deny shape (echoed on every branch).
384
+ attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0,
338
385
  access: {
339
386
  allowed: false,
340
387
  accessLevel: "none",
@@ -350,10 +397,22 @@ async function callVerifyAccessAPI(config, request) {
350
397
  };
351
398
  }
352
399
  if (!response.ok) {
400
+ if (response.status === 401) {
401
+ return {
402
+ success: false,
403
+ error: data.message || data.error || "Integration API key rejected",
404
+ misconfig: true,
405
+ misconfigCode: typeof data?.code === "string" ? data.code : void 0,
406
+ remediation: data?.remediation && typeof data.remediation === "object" ? data.remediation : void 0,
407
+ correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
408
+ attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
409
+ };
410
+ }
353
411
  return {
354
412
  success: false,
355
413
  error: data.message || data.error || `API returned ${response.status}`,
356
- correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0
414
+ correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
415
+ attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
357
416
  };
358
417
  }
359
418
  return data;
@@ -370,9 +429,19 @@ async function verify(config, request, options) {
370
429
  const urls = mergedConfig.apiBaseUrl ? getCachedWellKnownUrls(mergedConfig.apiBaseUrl) : void 0;
371
430
  if (!initCheckPerformed && !mergedConfig.disableInitChecks && mergedConfig.apiBaseUrl) {
372
431
  if (mergedConfig.strictInit) {
373
- await performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug, true);
432
+ await performInitCheck(
433
+ mergedConfig.apiBaseUrl,
434
+ mergedConfig.debug,
435
+ true,
436
+ mergedConfig.apiKey
437
+ );
374
438
  } else {
375
- void performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug, false);
439
+ void performInitCheck(
440
+ mergedConfig.apiBaseUrl,
441
+ mergedConfig.debug,
442
+ false,
443
+ mergedConfig.apiKey
444
+ );
376
445
  }
377
446
  }
378
447
  if (!deprecationWarningShown && (config.minTrustScore !== void 0 || config.minTrustScoreForFull !== void 0)) {
@@ -387,7 +456,13 @@ async function verify(config, request, options) {
387
456
  if (mergedConfig.debug) {
388
457
  console.log("[VerificationGateway] Returning cached result");
389
458
  }
390
- return cached;
459
+ const hit = { ...cached };
460
+ if (request.attemptId) {
461
+ hit.attemptId = request.attemptId;
462
+ } else {
463
+ delete hit.attemptId;
464
+ }
465
+ return hit;
391
466
  }
392
467
  }
393
468
  const enrichedRequest = { ...request };
@@ -405,8 +480,10 @@ async function verify(config, request, options) {
405
480
  const serverDenialReasons = Array.isArray(rawServerDenialReasons) && rawServerDenialReasons.length > 0 ? rawServerDenialReasons : void 0;
406
481
  if (!apiResponse.success) {
407
482
  return createGuidanceResponse(mergedConfig, apiResponse.error, {
408
- source: "api_error",
483
+ source: apiResponse.misconfig ? "merchant_misconfig" : "api_error",
409
484
  correlationId: apiResponse.correlationId,
485
+ attemptId: apiResponse.attemptId,
486
+ remediation: apiResponse.remediation,
410
487
  urls
411
488
  });
412
489
  }
@@ -442,6 +519,9 @@ async function verify(config, request, options) {
442
519
  // Anonymous traffic has no session → correlationId is the per-attempt
443
520
  // linking key (the sessionId-equivalent for anonymous callers).
444
521
  correlationId: apiResponse.correlationId,
522
+ // 3.12.0 (Trust Record): server echoes the attempt-chain handle on
523
+ // every branch — denials included (the funnel outlives one deny).
524
+ attemptId: apiResponse.attemptId,
445
525
  recommendation: apiResponse.recommendation,
446
526
  recommendationReasons: apiResponse.recommendationReasons,
447
527
  stepUpApproval: apiResponse.stepUpApproval,
@@ -493,6 +573,8 @@ async function verify(config, request, options) {
493
573
  // v2.3.10 (defect #34, round-4): anonymous responses surface correlationId
494
574
  // (no session row exists for unverified callers).
495
575
  correlationId: apiResponse.correlationId,
576
+ // 3.12.0 (Trust Record): server-echoed attempt-chain handle.
577
+ attemptId: apiResponse.attemptId,
496
578
  runtimeChallenge: apiResponse.runtimeChallenge,
497
579
  tokenGuidance: apiResponse.tokenGuidance,
498
580
  recommendation: apiResponse.recommendation,