@astrasyncai/verification-gateway 2.3.4 → 2.3.8
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.
- package/dist/adapter-interface/interface.d.mts +2 -2
- package/dist/adapter-interface/interface.d.ts +2 -2
- package/dist/adapters/express.d.mts +2 -2
- package/dist/adapters/express.d.ts +2 -2
- package/dist/adapters/express.js +101 -22
- package/dist/adapters/express.js.map +1 -1
- package/dist/adapters/express.mjs +100 -19
- package/dist/adapters/express.mjs.map +1 -1
- package/dist/adapters/mcp.d.mts +245 -0
- package/dist/adapters/mcp.d.ts +245 -0
- package/dist/adapters/mcp.js +619 -0
- package/dist/adapters/mcp.js.map +1 -0
- package/dist/adapters/mcp.mjs +585 -0
- package/dist/adapters/mcp.mjs.map +1 -0
- package/dist/adapters/nextjs.d.mts +2 -2
- package/dist/adapters/nextjs.d.ts +2 -2
- package/dist/adapters/nextjs.js +76 -4
- package/dist/adapters/nextjs.js.map +1 -1
- package/dist/adapters/nextjs.mjs +76 -4
- package/dist/adapters/nextjs.mjs.map +1 -1
- package/dist/adapters/sdk.d.mts +2 -2
- package/dist/adapters/sdk.d.ts +2 -2
- package/dist/adapters/sdk.js +22 -2
- package/dist/adapters/sdk.js.map +1 -1
- package/dist/adapters/sdk.mjs +22 -2
- package/dist/adapters/sdk.mjs.map +1 -1
- package/dist/agent/index.d.mts +2 -2
- package/dist/agent/index.d.ts +2 -2
- package/dist/browser/background.js +28 -2
- package/dist/browser/background.js.map +1 -1
- package/dist/browser/background.mjs +28 -2
- package/dist/browser/background.mjs.map +1 -1
- package/dist/browser/browser-adapter.d.mts +2 -2
- package/dist/browser/browser-adapter.d.ts +2 -2
- package/dist/cli/index.d.mts +2 -2
- package/dist/cli/index.d.ts +2 -2
- package/dist/cursor/cursor-adapter.d.mts +2 -2
- package/dist/cursor/cursor-adapter.d.ts +2 -2
- package/dist/cursor/extension.d.mts +2 -2
- package/dist/cursor/extension.d.ts +2 -2
- package/dist/cursor/extension.js +28 -2
- package/dist/cursor/extension.js.map +1 -1
- package/dist/cursor/extension.mjs +28 -2
- package/dist/cursor/extension.mjs.map +1 -1
- package/dist/{express-DtvJ6BGt.d.mts → express-BNWqDVIz.d.mts} +17 -14
- package/dist/{express-CraCA8_t.d.ts → express-BYup_4Jg.d.ts} +17 -14
- package/dist/gateway/gateway.d.mts +2 -2
- package/dist/gateway/gateway.d.ts +2 -2
- package/dist/gateway/gateway.js +28 -2
- package/dist/gateway/gateway.js.map +1 -1
- package/dist/gateway/gateway.mjs +28 -2
- package/dist/gateway/gateway.mjs.map +1 -1
- package/dist/git-trigger/git-hooks.d.mts +2 -2
- package/dist/git-trigger/git-hooks.d.ts +2 -2
- package/dist/{index-SEgnWzkf.d.mts → index-BHXa2WTO.d.mts} +1 -1
- package/dist/{index-BZ85CeEr.d.mts → index-CK4lNLVn.d.mts} +1 -1
- package/dist/{index--KzVRa32.d.ts → index-CSMpOcxV.d.ts} +1 -1
- package/dist/{index-BzAFmemy.d.ts → index-DN3ztP2d.d.ts} +1 -1
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +135 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +135 -21
- package/dist/index.mjs.map +1 -1
- package/dist/local-evaluator/evaluator.d.mts +2 -2
- package/dist/local-evaluator/evaluator.d.ts +2 -2
- package/dist/{nextjs-DZHAn9j-.d.mts → nextjs-Bzdfu8Eg.d.mts} +8 -2
- package/dist/{nextjs-B8o9C0t6.d.ts → nextjs-C4h_MpgK.d.ts} +8 -2
- package/dist/{sdk-CRSUFQH2.d.mts → sdk-CDdD7EcJ.d.mts} +1 -1
- package/dist/{sdk-BQ3olp3v.d.ts → sdk-Tzsn6s-O.d.ts} +1 -1
- package/dist/transport/index.d.mts +2 -2
- package/dist/transport/index.d.ts +2 -2
- package/dist/{types-osMd_dpT.d.ts → types-Bzp1SMaD.d.ts} +1 -1
- package/dist/{types-JMgPake9.d.mts → types-D_tmbDA_.d.mts} +75 -7
- package/dist/{types-JMgPake9.d.ts → types-D_tmbDA_.d.ts} +75 -7
- package/dist/{types-aN1UHhyy.d.mts → types-z-QVnG4b.d.mts} +1 -1
- package/dist/ui/index.d.mts +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/package.json +6 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AstraSyncGateway } from '../gateway/gateway.mjs';
|
|
2
|
-
import { V as VerificationDecision, P as PDLSSContext } from '../types-
|
|
3
|
-
import '../types-
|
|
2
|
+
import { V as VerificationDecision, P as PDLSSContext } from '../types-z-QVnG4b.mjs';
|
|
3
|
+
import '../types-D_tmbDA_.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Git Trigger — Enterprise git push / PR verification
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AstraSyncGateway } from '../gateway/gateway.js';
|
|
2
|
-
import { V as VerificationDecision, P as PDLSSContext } from '../types-
|
|
3
|
-
import '../types-
|
|
2
|
+
import { V as VerificationDecision, P as PDLSSContext } from '../types-Bzp1SMaD.js';
|
|
3
|
+
import '../types-D_tmbDA_.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Git Trigger — Enterprise git push / PR verification
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { b as AgentCredentials, G as GatewayConfig, a as AccessLevel, c as VerificationRequest, V as VerificationResult } from './types-
|
|
2
|
-
export { A as AstraSyncCredentials, d as CommerceShieldProps, C as CounterpartyType, e as EnhancedVerificationResult, E as ExpressMiddlewareOptions, f as GuidanceInfo, N as NextJsMiddlewareOptions, P as PDLSSInfo, g as ProtocolTransport, R as RouteAccessConfig, h as RuntimeChallengeResult, S as SDKOptions, T as TokenGuidance, i as TrustLevel, j as VerifiedAgent, k as VerifiedDeveloper, l as VerifiedOrganization } from './types-
|
|
3
|
-
export { A as ACCESS_LEVEL_DESCRIPTIONS, a as ACCESS_LEVEL_HIERARCHY, b as AccessCapabilities, D as DEFAULT_TRUST_THRESHOLDS, T as TRUST_LEVEL_RANGES, d as determineAccessLevel, g as getAccessLevelForScore, c as getCapabilities, e as getTrustLevel, h as hasMinimumAccess, s as sdk } from './sdk-
|
|
4
|
-
export { e as express } from './express-
|
|
5
|
-
export { n as nextjs } from './nextjs-
|
|
6
|
-
export { i as transport } from './index-
|
|
7
|
-
export { A as AgentClient, C as ChallengeHandler, i as agent, r as recordDecision } from './index-
|
|
1
|
+
import { b as AgentCredentials, G as GatewayConfig, a as AccessLevel, c as VerificationRequest, V as VerificationResult } from './types-D_tmbDA_.mjs';
|
|
2
|
+
export { A as AstraSyncCredentials, d as CommerceShieldProps, C as CounterpartyType, e as EnhancedVerificationResult, E as ExpressMiddlewareOptions, f as GuidanceInfo, N as NextJsMiddlewareOptions, P as PDLSSInfo, g as ProtocolTransport, R as RouteAccessConfig, h as RuntimeChallengeResult, S as SDKOptions, T as TokenGuidance, i as TrustLevel, j as VerifiedAgent, k as VerifiedDeveloper, l as VerifiedOrganization } from './types-D_tmbDA_.mjs';
|
|
3
|
+
export { A as ACCESS_LEVEL_DESCRIPTIONS, a as ACCESS_LEVEL_HIERARCHY, b as AccessCapabilities, D as DEFAULT_TRUST_THRESHOLDS, T as TRUST_LEVEL_RANGES, d as determineAccessLevel, g as getAccessLevelForScore, c as getCapabilities, e as getTrustLevel, h as hasMinimumAccess, s as sdk } from './sdk-CDdD7EcJ.mjs';
|
|
4
|
+
export { e as express } from './express-BNWqDVIz.mjs';
|
|
5
|
+
export { n as nextjs } from './nextjs-Bzdfu8Eg.mjs';
|
|
6
|
+
export { i as transport } from './index-BHXa2WTO.mjs';
|
|
7
|
+
export { A as AgentClient, C as ChallengeHandler, i as agent, r as recordDecision } from './index-CK4lNLVn.mjs';
|
|
8
8
|
import 'express';
|
|
9
9
|
import 'next/server';
|
|
10
10
|
import 'jose';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { b as AgentCredentials, G as GatewayConfig, a as AccessLevel, c as VerificationRequest, V as VerificationResult } from './types-
|
|
2
|
-
export { A as AstraSyncCredentials, d as CommerceShieldProps, C as CounterpartyType, e as EnhancedVerificationResult, E as ExpressMiddlewareOptions, f as GuidanceInfo, N as NextJsMiddlewareOptions, P as PDLSSInfo, g as ProtocolTransport, R as RouteAccessConfig, h as RuntimeChallengeResult, S as SDKOptions, T as TokenGuidance, i as TrustLevel, j as VerifiedAgent, k as VerifiedDeveloper, l as VerifiedOrganization } from './types-
|
|
3
|
-
export { A as ACCESS_LEVEL_DESCRIPTIONS, a as ACCESS_LEVEL_HIERARCHY, b as AccessCapabilities, D as DEFAULT_TRUST_THRESHOLDS, T as TRUST_LEVEL_RANGES, d as determineAccessLevel, g as getAccessLevelForScore, c as getCapabilities, e as getTrustLevel, h as hasMinimumAccess, s as sdk } from './sdk-
|
|
4
|
-
export { e as express } from './express-
|
|
5
|
-
export { n as nextjs } from './nextjs-
|
|
6
|
-
export { i as transport } from './index
|
|
7
|
-
export { A as AgentClient, C as ChallengeHandler, i as agent, r as recordDecision } from './index-
|
|
1
|
+
import { b as AgentCredentials, G as GatewayConfig, a as AccessLevel, c as VerificationRequest, V as VerificationResult } from './types-D_tmbDA_.js';
|
|
2
|
+
export { A as AstraSyncCredentials, d as CommerceShieldProps, C as CounterpartyType, e as EnhancedVerificationResult, E as ExpressMiddlewareOptions, f as GuidanceInfo, N as NextJsMiddlewareOptions, P as PDLSSInfo, g as ProtocolTransport, R as RouteAccessConfig, h as RuntimeChallengeResult, S as SDKOptions, T as TokenGuidance, i as TrustLevel, j as VerifiedAgent, k as VerifiedDeveloper, l as VerifiedOrganization } from './types-D_tmbDA_.js';
|
|
3
|
+
export { A as ACCESS_LEVEL_DESCRIPTIONS, a as ACCESS_LEVEL_HIERARCHY, b as AccessCapabilities, D as DEFAULT_TRUST_THRESHOLDS, T as TRUST_LEVEL_RANGES, d as determineAccessLevel, g as getAccessLevelForScore, c as getCapabilities, e as getTrustLevel, h as hasMinimumAccess, s as sdk } from './sdk-Tzsn6s-O.js';
|
|
4
|
+
export { e as express } from './express-BYup_4Jg.js';
|
|
5
|
+
export { n as nextjs } from './nextjs-C4h_MpgK.js';
|
|
6
|
+
export { i as transport } from './index-CSMpOcxV.js';
|
|
7
|
+
export { A as AgentClient, C as ChallengeHandler, i as agent, r as recordDecision } from './index-DN3ztP2d.js';
|
|
8
8
|
import 'express';
|
|
9
9
|
import 'next/server';
|
|
10
10
|
import 'jose';
|
package/dist/index.js
CHANGED
|
@@ -336,6 +336,23 @@ async function callVerifyAccessAPI(config, request) {
|
|
|
336
336
|
body: JSON.stringify(body)
|
|
337
337
|
});
|
|
338
338
|
const data = await response.json();
|
|
339
|
+
if (response.status === 410) {
|
|
340
|
+
return {
|
|
341
|
+
success: true,
|
|
342
|
+
access: {
|
|
343
|
+
allowed: false,
|
|
344
|
+
accessLevel: "none",
|
|
345
|
+
reason: "endpoint_deactivated",
|
|
346
|
+
failures: [
|
|
347
|
+
{
|
|
348
|
+
dimension: "endpoint.deactivated",
|
|
349
|
+
message: typeof data?.message === "string" ? data.message : "Endpoint has been deactivated",
|
|
350
|
+
guidance: typeof data?.guidance === "string" ? data.guidance : "Reactivate via POST /api/endpoints/{id}/reactivate, or update the URL on the calling agent."
|
|
351
|
+
}
|
|
352
|
+
]
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
}
|
|
339
356
|
if (!response.ok) {
|
|
340
357
|
return {
|
|
341
358
|
success: false,
|
|
@@ -386,10 +403,12 @@ async function verify(config, request) {
|
|
|
386
403
|
return createGuidanceResponse(mergedConfig, apiResponse.error);
|
|
387
404
|
}
|
|
388
405
|
if (!apiResponse.access?.allowed) {
|
|
406
|
+
const aggregatedFailures = apiResponse.access?.failures;
|
|
389
407
|
const result2 = {
|
|
390
408
|
verified: false,
|
|
391
409
|
accessLevel: "guidance",
|
|
392
|
-
denialReasons: apiResponse.access?.reason ? [apiResponse.access.reason] : ["Access denied"],
|
|
410
|
+
denialReasons: aggregatedFailures && aggregatedFailures.length > 0 ? aggregatedFailures.map((f) => f.message) : apiResponse.access?.reason ? [apiResponse.access.reason] : ["Access denied"],
|
|
411
|
+
failures: aggregatedFailures,
|
|
393
412
|
requiresStepUp: apiResponse.access?.requiresStepUp,
|
|
394
413
|
requiresApproval: apiResponse.access?.requiresApproval,
|
|
395
414
|
guidance: {
|
|
@@ -443,7 +462,8 @@ async function verify(config, request) {
|
|
|
443
462
|
runtimeChallenge: apiResponse.runtimeChallenge,
|
|
444
463
|
tokenGuidance: apiResponse.tokenGuidance,
|
|
445
464
|
recommendation: apiResponse.recommendation,
|
|
446
|
-
recommendationReasons: apiResponse.recommendationReasons
|
|
465
|
+
recommendationReasons: apiResponse.recommendationReasons,
|
|
466
|
+
warningHeader: apiResponse.warningHeader
|
|
447
467
|
};
|
|
448
468
|
if (result.recommendation === "deny") {
|
|
449
469
|
result.verified = false;
|
|
@@ -483,6 +503,25 @@ async function recordDecision(config, sessionId, decision, reason) {
|
|
|
483
503
|
}).catch(() => {
|
|
484
504
|
});
|
|
485
505
|
}
|
|
506
|
+
async function fetchRoutes(config, counterpartyId) {
|
|
507
|
+
if (!counterpartyId) return null;
|
|
508
|
+
const headers = { "Content-Type": "application/json" };
|
|
509
|
+
if (config.apiKey) {
|
|
510
|
+
headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
511
|
+
headers["X-API-Key"] = config.apiKey;
|
|
512
|
+
}
|
|
513
|
+
try {
|
|
514
|
+
const response = await fetch(
|
|
515
|
+
`${config.apiBaseUrl}/endpoints/${encodeURIComponent(counterpartyId)}/routes`,
|
|
516
|
+
{ method: "GET", headers }
|
|
517
|
+
);
|
|
518
|
+
if (!response.ok) return null;
|
|
519
|
+
const body = await response.json();
|
|
520
|
+
return body.data?.routes ?? [];
|
|
521
|
+
} catch {
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
486
525
|
async function reportCounterpartyPreCheckFailure(config, data) {
|
|
487
526
|
const apiBaseUrl = config.apiBaseUrl || DEFAULT_CONFIG.apiBaseUrl;
|
|
488
527
|
await fetch(`${apiBaseUrl}/verification-activity/counterparty-pre-check-failure`, {
|
|
@@ -508,9 +547,7 @@ async function quickVerify(config, credentials) {
|
|
|
508
547
|
var express_exports = {};
|
|
509
548
|
__export(express_exports, {
|
|
510
549
|
createMiddleware: () => createMiddleware,
|
|
511
|
-
extractAstraSyncCredentials: () => extractAstraSyncCredentials
|
|
512
|
-
requireAccess: () => requireAccess,
|
|
513
|
-
verifyOnly: () => verifyOnly
|
|
550
|
+
extractAstraSyncCredentials: () => extractAstraSyncCredentials
|
|
514
551
|
});
|
|
515
552
|
|
|
516
553
|
// src/transport/http.ts
|
|
@@ -683,28 +720,80 @@ function defaultOnDenied(result, _req, res) {
|
|
|
683
720
|
}
|
|
684
721
|
});
|
|
685
722
|
}
|
|
723
|
+
var DEFAULT_ROUTES_REFRESH_MS = 5 * 60 * 1e3;
|
|
686
724
|
function createMiddleware(options) {
|
|
687
725
|
const {
|
|
688
|
-
routes = [],
|
|
689
726
|
extractCredentials: customExtractCredentials,
|
|
690
727
|
extractPurpose: customExtractPurpose,
|
|
691
728
|
skipPaths = [],
|
|
692
729
|
onDenied = defaultOnDenied,
|
|
693
730
|
recordDecisions,
|
|
694
731
|
enableRuntimeChallenge = true,
|
|
732
|
+
routesRefreshMs = DEFAULT_ROUTES_REFRESH_MS,
|
|
695
733
|
...config
|
|
696
734
|
} = options;
|
|
735
|
+
let cachedRoutes = [];
|
|
736
|
+
let lastFetchAt = 0;
|
|
737
|
+
let refreshing = null;
|
|
738
|
+
let warnedNoCounterparty = false;
|
|
739
|
+
let warnedEmptyRoutes = false;
|
|
740
|
+
async function refreshRoutes() {
|
|
741
|
+
if (!config.counterpartyId) {
|
|
742
|
+
if (!warnedNoCounterparty) {
|
|
743
|
+
console.warn(
|
|
744
|
+
"[VerificationGateway] No counterpartyId configured \u2014 falling through (allow all). Per-route policy lives in the AstraSync dashboard now; register the endpoint and set counterpartyId in your middleware config to enforce policy."
|
|
745
|
+
);
|
|
746
|
+
warnedNoCounterparty = true;
|
|
747
|
+
}
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
const fetched = await fetchRoutes(config, config.counterpartyId);
|
|
751
|
+
if (fetched) {
|
|
752
|
+
cachedRoutes = fetched;
|
|
753
|
+
lastFetchAt = Date.now();
|
|
754
|
+
if (cachedRoutes.length === 0 && !warnedEmptyRoutes) {
|
|
755
|
+
const dashboard = config.dashboardUrl ?? "https://app.astrasync.ai";
|
|
756
|
+
console.warn(
|
|
757
|
+
`[VerificationGateway] No route policy configured for ${config.counterpartyId}. Gateway is in pass-through mode for ALL traffic until you add at least one route. Configure at ${dashboard}/dashboard/endpoints/${config.counterpartyId}/routes`
|
|
758
|
+
);
|
|
759
|
+
warnedEmptyRoutes = true;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
refreshing = refreshRoutes().finally(() => {
|
|
764
|
+
refreshing = null;
|
|
765
|
+
});
|
|
697
766
|
return async (req, res, next) => {
|
|
698
767
|
try {
|
|
699
768
|
const shouldSkip = skipPaths.some((pattern) => matchRoute(pattern, req.path));
|
|
700
769
|
if (shouldSkip) {
|
|
701
770
|
return next();
|
|
702
771
|
}
|
|
703
|
-
|
|
772
|
+
if (refreshing) {
|
|
773
|
+
await refreshing.catch(() => {
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
if (config.counterpartyId && Date.now() - lastFetchAt > routesRefreshMs) {
|
|
777
|
+
refreshing = refreshRoutes().finally(() => {
|
|
778
|
+
refreshing = null;
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
const routeConfig = findRouteConfig(cachedRoutes, req.path, req.method);
|
|
704
782
|
if (!routeConfig) {
|
|
783
|
+
if (config.setPassThroughHeader) {
|
|
784
|
+
res.setHeader("X-Astra-Gateway-Mode", "pass-through");
|
|
785
|
+
res.setHeader(
|
|
786
|
+
"X-Astra-Gateway-Reason",
|
|
787
|
+
cachedRoutes.length === 0 ? "no-policy" : "no-match"
|
|
788
|
+
);
|
|
789
|
+
}
|
|
705
790
|
return next();
|
|
706
791
|
}
|
|
707
792
|
if (routeConfig.minAccessLevel === "none") {
|
|
793
|
+
if (config.setPassThroughHeader) {
|
|
794
|
+
res.setHeader("X-Astra-Gateway-Mode", "pass-through");
|
|
795
|
+
res.setHeader("X-Astra-Gateway-Reason", "route-none");
|
|
796
|
+
}
|
|
708
797
|
return next();
|
|
709
798
|
}
|
|
710
799
|
const credentials = customExtractCredentials ? customExtractCredentials(req) : defaultExtractCredentials(req);
|
|
@@ -788,6 +877,10 @@ function createMiddleware(options) {
|
|
|
788
877
|
recordDecision(config, sessionId, "granted").catch(() => {
|
|
789
878
|
});
|
|
790
879
|
}
|
|
880
|
+
const enhancedResult = result;
|
|
881
|
+
if (enhancedResult.warningHeader) {
|
|
882
|
+
res.setHeader(enhancedResult.warningHeader.name, enhancedResult.warningHeader.value);
|
|
883
|
+
}
|
|
791
884
|
next();
|
|
792
885
|
} catch (error) {
|
|
793
886
|
console.error("[VerificationGateway] Middleware error:", error);
|
|
@@ -795,18 +888,6 @@ function createMiddleware(options) {
|
|
|
795
888
|
}
|
|
796
889
|
};
|
|
797
890
|
}
|
|
798
|
-
function requireAccess(minAccessLevel, options) {
|
|
799
|
-
return createMiddleware({
|
|
800
|
-
...options,
|
|
801
|
-
routes: [{ pattern: "*", method: "*", minAccessLevel }]
|
|
802
|
-
});
|
|
803
|
-
}
|
|
804
|
-
function verifyOnly(options) {
|
|
805
|
-
return createMiddleware({
|
|
806
|
-
...options,
|
|
807
|
-
routes: [{ pattern: "*", method: "*", minAccessLevel: "none" }]
|
|
808
|
-
});
|
|
809
|
-
}
|
|
810
891
|
|
|
811
892
|
// src/adapters/nextjs.ts
|
|
812
893
|
var nextjs_exports = {};
|
|
@@ -1030,14 +1111,38 @@ function generateCommerceShieldHtml(result, options) {
|
|
|
1030
1111
|
</html>
|
|
1031
1112
|
`.trim();
|
|
1032
1113
|
}
|
|
1114
|
+
var DEFAULT_ROUTES_REFRESH_MS2 = 5 * 60 * 1e3;
|
|
1033
1115
|
function createMiddleware2(options) {
|
|
1034
1116
|
const {
|
|
1035
|
-
routes = [],
|
|
1036
1117
|
skipPaths = [],
|
|
1037
1118
|
showCommerceShield = true,
|
|
1038
1119
|
enableRuntimeChallenge = true,
|
|
1120
|
+
routesRefreshMs = DEFAULT_ROUTES_REFRESH_MS2,
|
|
1039
1121
|
...config
|
|
1040
1122
|
} = options;
|
|
1123
|
+
let cachedRoutes = [];
|
|
1124
|
+
let lastFetchAt = 0;
|
|
1125
|
+
let refreshing = null;
|
|
1126
|
+
let warnedNoCounterparty = false;
|
|
1127
|
+
async function refreshRoutes() {
|
|
1128
|
+
if (!config.counterpartyId) {
|
|
1129
|
+
if (!warnedNoCounterparty) {
|
|
1130
|
+
console.warn(
|
|
1131
|
+
"[VerificationGateway/Next.js] No counterpartyId configured \u2014 falling through (allow all). Per-route policy lives in the AstraSync dashboard now; register the endpoint and set counterpartyId in your middleware config to enforce policy."
|
|
1132
|
+
);
|
|
1133
|
+
warnedNoCounterparty = true;
|
|
1134
|
+
}
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
const fetched = await fetchRoutes(config, config.counterpartyId);
|
|
1138
|
+
if (fetched) {
|
|
1139
|
+
cachedRoutes = fetched;
|
|
1140
|
+
lastFetchAt = Date.now();
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
refreshing = refreshRoutes().finally(() => {
|
|
1144
|
+
refreshing = null;
|
|
1145
|
+
});
|
|
1041
1146
|
return async function middleware(request) {
|
|
1042
1147
|
const { NextResponse } = await import("next/server");
|
|
1043
1148
|
const pathname = request.nextUrl.pathname;
|
|
@@ -1045,7 +1150,16 @@ function createMiddleware2(options) {
|
|
|
1045
1150
|
if (shouldSkip) {
|
|
1046
1151
|
return NextResponse.next();
|
|
1047
1152
|
}
|
|
1048
|
-
|
|
1153
|
+
if (refreshing) {
|
|
1154
|
+
await refreshing.catch(() => {
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
if (config.counterpartyId && Date.now() - lastFetchAt > routesRefreshMs) {
|
|
1158
|
+
refreshing = refreshRoutes().finally(() => {
|
|
1159
|
+
refreshing = null;
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
const routeConfig = findRouteConfig2(cachedRoutes, pathname, request.method);
|
|
1049
1163
|
if (!routeConfig) {
|
|
1050
1164
|
return NextResponse.next();
|
|
1051
1165
|
}
|