@astrasyncai/verification-gateway 3.12.0 → 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 +85 -8
  6. package/dist/adapters/express.js.map +1 -1
  7. package/dist/adapters/express.mjs +85 -8
  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 +90 -8
  12. package/dist/adapters/mcp.js.map +1 -1
  13. package/dist/adapters/mcp.mjs +90 -8
  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 +86 -8
  18. package/dist/adapters/nextjs.js.map +1 -1
  19. package/dist/adapters/nextjs.mjs +86 -8
  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 +71 -8
  24. package/dist/adapters/sdk.js.map +1 -1
  25. package/dist/adapters/sdk.mjs +71 -8
  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 +71 -8
  30. package/dist/bin/astrasync-codex-hook.js +71 -8
  31. package/dist/bin/astrasync-guard.js +71 -8
  32. package/dist/bin/astrasync.js +71 -8
  33. package/dist/browser/background.js +71 -8
  34. package/dist/browser/background.js.map +1 -1
  35. package/dist/browser/background.mjs +71 -8
  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 +71 -8
  46. package/dist/codex/index.js.map +1 -1
  47. package/dist/codex/index.mjs +71 -8
  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 +71 -8
  54. package/dist/cursor/extension.js.map +1 -1
  55. package/dist/cursor/extension.mjs +71 -8
  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-B39o89gf.d.mts → express-BZajRs4i.d.mts} +1 -1
  60. package/dist/{express-BuxKNO_q.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 +71 -8
  64. package/dist/gateway/gateway.js.map +1 -1
  65. package/dist/gateway/gateway.mjs +71 -8
  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-DME3w3lf.d.mts → index-B0cyMZDL.d.mts} +1 -1
  70. package/dist/{index-CqydB4ks.d.mts → index-BRYteOqO.d.mts} +1 -1
  71. package/dist/{index-BG62SXso.d.ts → index-BZQdVqNw.d.ts} +1 -1
  72. package/dist/{index-CLHdqs2M.d.ts → index-adgKhujR.d.ts} +1 -1
  73. package/dist/index.d.mts +8 -8
  74. package/dist/index.d.ts +8 -8
  75. package/dist/index.js +119 -8
  76. package/dist/index.js.map +1 -1
  77. package/dist/index.mjs +119 -8
  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-Ddlw_J1J.d.ts → nextjs-D_iFf5k-.d.ts} +1 -1
  82. package/dist/{nextjs-D74W7wt-.d.mts → nextjs-DeUTnOBd.d.mts} +1 -1
  83. package/dist/{sdk-CT7gdkfR.d.ts → sdk-BM3mwEAq.d.ts} +1 -1
  84. package/dist/{sdk-Bn6bj7kt.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-BntuzEEn.d.mts → types-BcDf9Kk0.d.mts} +15 -0
  88. package/dist/{types-DHu7m9HI.d.ts → types-CHKCgDFC.d.ts} +1 -1
  89. package/dist/{types-Djw4GLtz.d.mts → types-DfnP7JiM.d.mts} +1 -1
  90. package/dist/{types-SDu4Llbe.d.ts → types-fTQD448H.d.ts} +15 -0
  91. package/dist/ui/index.d.mts +1 -1
  92. package/dist/ui/index.d.ts +1 -1
  93. package/dist/verify.d.mts +4 -2
  94. package/dist/verify.d.ts +4 -2
  95. package/dist/verify.js +76 -8
  96. package/dist/verify.js.map +1 -1
  97. package/dist/verify.mjs +75 -8
  98. package/dist/verify.mjs.map +1 -1
  99. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import { AstraSyncGateway } from '../gateway/gateway.mjs';
2
- import { A as AgentAction, I as InterceptResult, P as PDLSSContext, V as VerificationDecision } from '../types-Djw4GLtz.mjs';
3
- import '../types-BntuzEEn.mjs';
2
+ import { A as AgentAction, I as InterceptResult, P as PDLSSContext, V as VerificationDecision } from '../types-DfnP7JiM.mjs';
3
+ import '../types-BcDf9Kk0.mjs';
4
4
  import '../metadata-capture.mjs';
5
5
 
6
6
  /**
@@ -1,6 +1,6 @@
1
1
  import { AstraSyncGateway } from '../gateway/gateway.js';
2
- import { A as AgentAction, I as InterceptResult, P as PDLSSContext, V as VerificationDecision } from '../types-DHu7m9HI.js';
3
- import '../types-SDu4Llbe.js';
2
+ import { A as AgentAction, I as InterceptResult, P as PDLSSContext, V as VerificationDecision } from '../types-CHKCgDFC.js';
3
+ import '../types-fTQD448H.js';
4
4
  import '../metadata-capture.js';
5
5
 
6
6
  /**
@@ -1,4 +1,4 @@
1
1
  import 'express';
2
- import '../types-BntuzEEn.mjs';
3
- export { c as createMiddleware, a as extractAstraSyncCredentials } from '../express-B39o89gf.mjs';
2
+ import '../types-BcDf9Kk0.mjs';
3
+ export { c as createMiddleware, a as extractAstraSyncCredentials } from '../express-BZajRs4i.mjs';
4
4
  import '../metadata-capture.mjs';
@@ -1,4 +1,4 @@
1
1
  import 'express';
2
- import '../types-SDu4Llbe.js';
3
- export { c as createMiddleware, a as extractAstraSyncCredentials } from '../express-BuxKNO_q.js';
2
+ import '../types-fTQD448H.js';
3
+ export { c as createMiddleware, a as extractAstraSyncCredentials } from '../express-CjCUB1k7.js';
4
4
  import '../metadata-capture.js';
@@ -92,7 +92,7 @@ function getTrustLevel(score) {
92
92
  }
93
93
 
94
94
  // src/version.ts
95
- var SDK_VERSION = "3.12.0";
95
+ var SDK_VERSION = "4.0.0";
96
96
 
97
97
  // src/well-known.ts
98
98
  var CACHE_TTL_MS = 60 * 60 * 1e3;
@@ -170,7 +170,7 @@ var DEFAULT_CONFIG = {
170
170
  };
171
171
  var initCheckPerformed = false;
172
172
  var deprecationWarningShown = false;
173
- async function performInitCheck(apiBaseUrl, debug, strictInit) {
173
+ async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey) {
174
174
  initCheckPerformed = true;
175
175
  try {
176
176
  const probeUrl = `${apiBaseUrl}/agents/verify-access`;
@@ -187,6 +187,28 @@ async function performInitCheck(apiBaseUrl, debug, strictInit) {
187
187
  `[VerificationGateway] init check passed for ${apiBaseUrl} (content-type: ${contentType})`
188
188
  );
189
189
  }
190
+ if (apiKey) {
191
+ const selfCheck = await fetch(`${apiBaseUrl}/agents/verify-access/self-check`, {
192
+ headers: { Authorization: `Bearer ${apiKey}` }
193
+ });
194
+ if (selfCheck.status === 401) {
195
+ const body = await selfCheck.json().catch(() => ({}));
196
+ 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}` : "") + `.`;
197
+ if (strictInit) {
198
+ throw new Error(`${message} (strictInit=true)`);
199
+ }
200
+ console.error(message);
201
+ } else if (selfCheck.ok) {
202
+ const body = await selfCheck.json().catch(() => ({}));
203
+ if (typeof body.daysToExpiry === "number" && body.daysToExpiry <= 7) {
204
+ console.warn(
205
+ `[VerificationGateway] the configured AstraSync API key expires in ${body.daysToExpiry} day(s) \u2014 rotate it at Settings \u2192 Developer Tools before integrations start failing.`
206
+ );
207
+ } else if (debug) {
208
+ console.log("[VerificationGateway] API key self-check passed");
209
+ }
210
+ }
211
+ }
190
212
  } catch (err) {
191
213
  if (strictInit) {
192
214
  throw err;
@@ -298,8 +320,17 @@ function extractCredentials(headers, query) {
298
320
  function createGuidanceResponse(_config, reason, options = {}) {
299
321
  const source = options.source ?? "no_credentials";
300
322
  const isApiError = source === "api_error";
323
+ const isMisconfig = source === "merchant_misconfig";
301
324
  const urls = options.urls;
302
- const guidance = isApiError ? {
325
+ const guidance = isMisconfig ? {
326
+ 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.",
327
+ registrationUrl: urls?.registrationUrl ?? "",
328
+ documentationUrl: options.remediation?.docsUrl ?? urls?.documentationUrl ?? "",
329
+ steps: [
330
+ "Report the failure to the site operator \u2014 their AstraSync API key needs rotating",
331
+ "Do not retry: the failure is deterministic until the operator updates their key"
332
+ ]
333
+ } : isApiError ? {
303
334
  message: "Verification is temporarily unavailable. Retry with exponential backoff; if the issue persists, contact support with the correlationId.",
304
335
  registrationUrl: urls?.registrationUrl ?? "",
305
336
  documentationUrl: urls?.documentationUrl ?? "",
@@ -337,13 +368,22 @@ function createGuidanceResponse(_config, reason, options = {}) {
337
368
  // partners (and their custom onDenied handlers) can branch on
338
369
  // dimension. Without this, the synthesised stub was indistinguishable
339
370
  // from a real policy deny.
340
- failures: isApiError ? [
371
+ failures: isMisconfig ? [
372
+ {
373
+ dimension: "verify_access.merchant_misconfigured",
374
+ message: reason ?? "The integration API key was rejected by AstraSync",
375
+ guidance: guidance.message
376
+ }
377
+ ] : isApiError ? [
341
378
  {
342
379
  dimension: "verify_access.api_error",
343
380
  message: reason ?? "Verification temporarily unavailable",
344
381
  guidance: guidance.message
345
382
  }
346
383
  ] : void 0,
384
+ // 4.0.0: typed marker so adapters render the misconfig envelope (503 +
385
+ // MERCHANT_VERIFICATION_MISCONFIGURED) without string-matching.
386
+ ...isMisconfig && { misconfigured: true },
347
387
  correlationId: options.correlationId,
348
388
  attemptId: options.attemptId,
349
389
  verifiedAt: /* @__PURE__ */ new Date()
@@ -398,7 +438,8 @@ async function callVerifyAccessAPI(config, request) {
398
438
  const response = await fetch(`${config.apiBaseUrl}/agents/verify-access`, {
399
439
  method: "POST",
400
440
  headers,
401
- body: JSON.stringify(body)
441
+ body: JSON.stringify(body),
442
+ signal: AbortSignal.timeout(config.verifyTimeoutMs ?? 1e4)
402
443
  });
403
444
  const data = await response.json();
404
445
  if (response.status === 410) {
@@ -422,6 +463,17 @@ async function callVerifyAccessAPI(config, request) {
422
463
  };
423
464
  }
424
465
  if (!response.ok) {
466
+ if (response.status === 401) {
467
+ return {
468
+ success: false,
469
+ error: data.message || data.error || "Integration API key rejected",
470
+ misconfig: true,
471
+ misconfigCode: typeof data?.code === "string" ? data.code : void 0,
472
+ remediation: data?.remediation && typeof data.remediation === "object" ? data.remediation : void 0,
473
+ correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
474
+ attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
475
+ };
476
+ }
425
477
  return {
426
478
  success: false,
427
479
  error: data.message || data.error || `API returned ${response.status}`,
@@ -443,9 +495,19 @@ async function verify(config, request, options) {
443
495
  const urls = mergedConfig.apiBaseUrl ? getCachedWellKnownUrls(mergedConfig.apiBaseUrl) : void 0;
444
496
  if (!initCheckPerformed && !mergedConfig.disableInitChecks && mergedConfig.apiBaseUrl) {
445
497
  if (mergedConfig.strictInit) {
446
- await performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug, true);
498
+ await performInitCheck(
499
+ mergedConfig.apiBaseUrl,
500
+ mergedConfig.debug,
501
+ true,
502
+ mergedConfig.apiKey
503
+ );
447
504
  } else {
448
- void performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug, false);
505
+ void performInitCheck(
506
+ mergedConfig.apiBaseUrl,
507
+ mergedConfig.debug,
508
+ false,
509
+ mergedConfig.apiKey
510
+ );
449
511
  }
450
512
  }
451
513
  if (!deprecationWarningShown && (config.minTrustScore !== void 0 || config.minTrustScoreForFull !== void 0)) {
@@ -484,9 +546,10 @@ async function verify(config, request, options) {
484
546
  const serverDenialReasons = Array.isArray(rawServerDenialReasons) && rawServerDenialReasons.length > 0 ? rawServerDenialReasons : void 0;
485
547
  if (!apiResponse.success) {
486
548
  return createGuidanceResponse(mergedConfig, apiResponse.error, {
487
- source: "api_error",
549
+ source: apiResponse.misconfig ? "merchant_misconfig" : "api_error",
488
550
  correlationId: apiResponse.correlationId,
489
551
  attemptId: apiResponse.attemptId,
552
+ remediation: apiResponse.remediation,
490
553
  urls
491
554
  });
492
555
  }
@@ -1043,6 +1106,20 @@ function dedupeFailures(result) {
1043
1106
  }
1044
1107
  }
1045
1108
  function defaultOnDenied(result, _req, res) {
1109
+ if (result.misconfigured) {
1110
+ res.setHeader("X-Astra-Gateway-Mode", "enforced");
1111
+ res.status(503).json({
1112
+ success: false,
1113
+ error: {
1114
+ code: "MERCHANT_VERIFICATION_MISCONFIGURED",
1115
+ message: result.denialReasons?.[0] || "This site's AstraSync integration is misconfigured",
1116
+ guidance: result.guidance,
1117
+ failures: result.failures,
1118
+ correlationId: result.correlationId
1119
+ }
1120
+ });
1121
+ return;
1122
+ }
1046
1123
  const statusCode = !result.identityVerified ? 401 : 403;
1047
1124
  res.setHeader("X-Astra-Gateway-Mode", "enforced");
1048
1125
  res.status(statusCode).json({