@astrasyncai/verification-gateway 2.2.0 → 2.2.3
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/README.md +64 -30
- 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 +37 -80
- package/dist/adapters/express.js.map +1 -1
- package/dist/adapters/express.mjs +37 -80
- package/dist/adapters/express.mjs.map +1 -1
- package/dist/adapters/nextjs.d.mts +2 -2
- package/dist/adapters/nextjs.d.ts +2 -2
- package/dist/adapters/nextjs.js +36 -100
- package/dist/adapters/nextjs.js.map +1 -1
- package/dist/adapters/nextjs.mjs +36 -100
- 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 +36 -44
- package/dist/adapters/sdk.js.map +1 -1
- package/dist/adapters/sdk.mjs +36 -44
- 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/agent/index.js +2 -2
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/index.mjs +2 -2
- package/dist/agent/index.mjs.map +1 -1
- package/dist/browser/background.js +36 -44
- package/dist/browser/background.js.map +1 -1
- package/dist/browser/background.mjs +36 -44
- 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 +36 -44
- package/dist/cursor/extension.js.map +1 -1
- package/dist/cursor/extension.mjs +36 -44
- package/dist/cursor/extension.mjs.map +1 -1
- package/dist/{express-DpwYW08E.d.ts → express-BtKlLI8U.d.ts} +2 -2
- package/dist/{express-C9KqJNWV.d.mts → express-DgwpS8Ha.d.mts} +2 -2
- package/dist/gateway/gateway.d.mts +2 -2
- package/dist/gateway/gateway.d.ts +2 -2
- package/dist/gateway/gateway.js +36 -44
- package/dist/gateway/gateway.js.map +1 -1
- package/dist/gateway/gateway.mjs +36 -44
- 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-BMZdjGT4.d.mts → index-AzhK20t0.d.mts} +2 -2
- package/dist/{index-gM-lgX_X.d.ts → index-Ba0Lvsjo.d.ts} +1 -1
- package/dist/{index-DlsYN3Et.d.mts → index-BaxpmTGA.d.mts} +1 -1
- package/dist/{index-Dm2xA6j1.d.ts → index-DpJS1JEI.d.ts} +2 -2
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +39 -98
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -98
- 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-yNzimC3a.d.ts → nextjs-B2kg19c1.d.ts} +1 -1
- package/dist/{nextjs-BEqidT0U.d.mts → nextjs-ZymQ8jDh.d.mts} +1 -1
- package/dist/{sdk-7fa9H0qa.d.mts → sdk-B7id0VFS.d.mts} +2 -2
- package/dist/{sdk-CP9C9Qu0.d.ts → sdk-Bso0FSI0.d.ts} +2 -2
- package/dist/transport/index.d.mts +2 -2
- package/dist/transport/index.d.ts +2 -2
- package/dist/{types-rigu2bH3.d.ts → types-BYKAY6Cc.d.ts} +1 -1
- package/dist/{types-DE0ooQJ6.d.mts → types-CgXPKUwi.d.mts} +1 -1
- package/dist/{types-CrVMq_Td.d.mts → types-DOrqNMgy.d.mts} +49 -10
- package/dist/{types-CrVMq_Td.d.ts → types-DOrqNMgy.d.ts} +49 -10
- package/dist/ui/index.d.mts +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/dist/webhooks.d.mts +59 -0
- package/dist/webhooks.d.ts +59 -0
- package/dist/webhooks.js +81 -0
- package/dist/webhooks.js.map +1 -0
- package/dist/webhooks.mjs +55 -0
- package/dist/webhooks.mjs.map +1 -0
- package/package.json +6 -1
package/dist/index.mjs
CHANGED
|
@@ -127,14 +127,36 @@ function getCapabilities(accessLevel) {
|
|
|
127
127
|
|
|
128
128
|
// src/verify.ts
|
|
129
129
|
var DEFAULT_CONFIG = {
|
|
130
|
-
apiBaseUrl: "https://
|
|
130
|
+
apiBaseUrl: "https://astrasync.ai/api",
|
|
131
131
|
defaultAccessLevel: "guidance",
|
|
132
|
-
minTrustScore
|
|
133
|
-
minTrustScoreForFull: 70,
|
|
132
|
+
// minTrustScore + minTrustScoreForFull deprecated in v2.3.0 — server decides.
|
|
134
133
|
cacheTtl: 300,
|
|
135
134
|
// 5 minutes
|
|
136
135
|
debug: false
|
|
137
136
|
};
|
|
137
|
+
var initCheckPerformed = false;
|
|
138
|
+
var deprecationWarningShown = false;
|
|
139
|
+
async function performInitCheck(apiBaseUrl, debug) {
|
|
140
|
+
initCheckPerformed = true;
|
|
141
|
+
try {
|
|
142
|
+
const probeUrl = `${apiBaseUrl}/agents/verify-access`;
|
|
143
|
+
const response = await fetch(probeUrl, { method: "HEAD" });
|
|
144
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
145
|
+
if (contentType.startsWith("text/html")) {
|
|
146
|
+
console.warn(
|
|
147
|
+
`[VerificationGateway] apiBaseUrl '${apiBaseUrl}' returned HTML (content-type: ${contentType}). This usually means apiBaseUrl is pointing at a marketing site instead of the API. Expected: 'https://astrasync.ai/api' (prod) or 'https://staging.astrasync.ai/api' (staging). Set disableInitChecks: true on GatewayConfig to silence this warning.`
|
|
148
|
+
);
|
|
149
|
+
} else if (debug) {
|
|
150
|
+
console.log(
|
|
151
|
+
`[VerificationGateway] init check passed for ${apiBaseUrl} (content-type: ${contentType})`
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
} catch (err) {
|
|
155
|
+
if (debug) {
|
|
156
|
+
console.log(`[VerificationGateway] init check failed (non-blocking): ${String(err)}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
138
160
|
var verificationCache = /* @__PURE__ */ new Map();
|
|
139
161
|
function getCacheKey(credentials) {
|
|
140
162
|
return `${credentials.astraId || ""}-${credentials.apiKey || ""}-${credentials.jwt || ""}`;
|
|
@@ -162,7 +184,7 @@ function clearCache() {
|
|
|
162
184
|
}
|
|
163
185
|
function extractCredentials(headers, query) {
|
|
164
186
|
const credentials = {};
|
|
165
|
-
const astraIdHeader = headers["x-astra-id"] || headers["X-Astra-Id"] || headers["X-ASTRA-ID"];
|
|
187
|
+
const astraIdHeader = headers["x-astra-id"] || headers["X-Astra-Id"] || headers["X-ASTRA-ID"] || headers["x-astra-agentid"] || headers["X-Astra-AgentId"] || headers["x-astra-agent-id"] || headers["X-Astra-Agent-Id"] || headers["X-ASTRA-AGENT-ID"];
|
|
166
188
|
if (astraIdHeader) {
|
|
167
189
|
credentials.astraId = Array.isArray(astraIdHeader) ? astraIdHeader[0] : astraIdHeader;
|
|
168
190
|
}
|
|
@@ -214,7 +236,7 @@ function createGuidanceResponse(config, reason) {
|
|
|
214
236
|
async function callVerifyAccessAPI(config, request) {
|
|
215
237
|
const { credentials, ...requestData } = request;
|
|
216
238
|
const body = {
|
|
217
|
-
agentId: credentials.astraId,
|
|
239
|
+
...credentials.astraId && { agentId: credentials.astraId },
|
|
218
240
|
purpose: requestData.purpose || "general"
|
|
219
241
|
};
|
|
220
242
|
if (requestData.action) body.action = requestData.action;
|
|
@@ -232,6 +254,7 @@ async function callVerifyAccessAPI(config, request) {
|
|
|
232
254
|
if (requestData.durationRequired) body.durationRequired = requestData.durationRequired;
|
|
233
255
|
if (requestData.counterpartyType) body.counterpartyType = requestData.counterpartyType;
|
|
234
256
|
if (requestData.counterpartyUrl) body.counterpartyUrl = requestData.counterpartyUrl;
|
|
257
|
+
if (config.counterpartyId) body.counterpartyId = config.counterpartyId;
|
|
235
258
|
if (requestData.runtimeChallengeOptions)
|
|
236
259
|
body.runtimeChallengeOptions = requestData.runtimeChallengeOptions;
|
|
237
260
|
if (requestData.callerMetadata || requestData.clientIp || requestData.userAgent) {
|
|
@@ -278,8 +301,14 @@ async function callVerifyAccessAPI(config, request) {
|
|
|
278
301
|
}
|
|
279
302
|
async function verify(config, request) {
|
|
280
303
|
const mergedConfig = { ...DEFAULT_CONFIG, ...config };
|
|
281
|
-
if (!
|
|
282
|
-
|
|
304
|
+
if (!initCheckPerformed && !mergedConfig.disableInitChecks && mergedConfig.apiBaseUrl) {
|
|
305
|
+
void performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug);
|
|
306
|
+
}
|
|
307
|
+
if (!deprecationWarningShown && (config.minTrustScore !== void 0 || config.minTrustScoreForFull !== void 0)) {
|
|
308
|
+
deprecationWarningShown = true;
|
|
309
|
+
console.warn(
|
|
310
|
+
"[VerificationGateway] minTrustScore / minTrustScoreForFull are deprecated in v2.3.0 and have no effect. Server is now the single source of truth for access-level decisions (the SDK reads access.accessLevel from the verify-access response). To gate access to an endpoint, configure the endpoint's trust_score_requirement server-side."
|
|
311
|
+
);
|
|
283
312
|
}
|
|
284
313
|
if (mergedConfig.cacheTtl && mergedConfig.cacheTtl > 0) {
|
|
285
314
|
const cached = getCachedResult(request.credentials);
|
|
@@ -351,13 +380,7 @@ async function verify(config, request) {
|
|
|
351
380
|
selfInstantiationAllowed: apiResponse.access.pdlss.selfInstantiationAllowed,
|
|
352
381
|
appliedPolicy: apiResponse.access.appliedPolicy
|
|
353
382
|
} : void 0;
|
|
354
|
-
const
|
|
355
|
-
const isOrgMember = false;
|
|
356
|
-
const accessLevel = determineAccessLevel(true, trustScore, isOrgMember, {
|
|
357
|
-
"read-only": 20,
|
|
358
|
-
standard: mergedConfig.minTrustScore || 40,
|
|
359
|
-
full: mergedConfig.minTrustScoreForFull || 70
|
|
360
|
-
});
|
|
383
|
+
const accessLevel = apiResponse.access?.accessLevel ?? "standard";
|
|
361
384
|
const result = {
|
|
362
385
|
verified: true,
|
|
363
386
|
accessLevel,
|
|
@@ -414,15 +437,6 @@ async function recordDecision(config, sessionId, decision, reason) {
|
|
|
414
437
|
}).catch(() => {
|
|
415
438
|
});
|
|
416
439
|
}
|
|
417
|
-
async function reportUnregisteredAttempt(config, data) {
|
|
418
|
-
const apiBaseUrl = config.apiBaseUrl || DEFAULT_CONFIG.apiBaseUrl;
|
|
419
|
-
await fetch(`${apiBaseUrl}/verification-activity/unregistered-attempt`, {
|
|
420
|
-
method: "POST",
|
|
421
|
-
headers: { "Content-Type": "application/json" },
|
|
422
|
-
body: JSON.stringify(data)
|
|
423
|
-
}).catch(() => {
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
440
|
async function reportCounterpartyPreCheckFailure(config, data) {
|
|
427
441
|
const apiBaseUrl = config.apiBaseUrl || DEFAULT_CONFIG.apiBaseUrl;
|
|
428
442
|
await fetch(`${apiBaseUrl}/verification-activity/counterparty-pre-check-failure`, {
|
|
@@ -648,32 +662,6 @@ function createMiddleware(options) {
|
|
|
648
662
|
return next();
|
|
649
663
|
}
|
|
650
664
|
const credentials = customExtractCredentials ? customExtractCredentials(req) : defaultExtractCredentials(req);
|
|
651
|
-
if (!hasCredentials(credentials) && routeConfig.minAccessLevel !== "guidance") {
|
|
652
|
-
const counterpartyUrl2 = config.counterpartyUrl || `${req.protocol}://${req.get("host")}`;
|
|
653
|
-
reportUnregisteredAttempt(config, {
|
|
654
|
-
counterpartyUrl: counterpartyUrl2,
|
|
655
|
-
counterpartyType: config.counterpartyType || "api",
|
|
656
|
-
sourceIp: req.ip,
|
|
657
|
-
userAgent: req.headers["user-agent"],
|
|
658
|
-
requestPath: req.path,
|
|
659
|
-
requestMethod: req.method
|
|
660
|
-
}).catch(() => {
|
|
661
|
-
});
|
|
662
|
-
const result2 = {
|
|
663
|
-
verified: false,
|
|
664
|
-
accessLevel: "none",
|
|
665
|
-
denialReasons: ["No agent credentials provided"],
|
|
666
|
-
guidance: {
|
|
667
|
-
message: "This endpoint requires agent verification. Please provide your ASTRA-ID.",
|
|
668
|
-
registrationUrl: `${config.apiBaseUrl?.replace("/api", "")}/register`,
|
|
669
|
-
documentationUrl: `${config.apiBaseUrl?.replace("/api", "")}/docs/agent-access`
|
|
670
|
-
},
|
|
671
|
-
verifiedAt: /* @__PURE__ */ new Date()
|
|
672
|
-
};
|
|
673
|
-
req.agentVerification = result2;
|
|
674
|
-
onDenied(result2, req, res);
|
|
675
|
-
return;
|
|
676
|
-
}
|
|
677
665
|
const purpose = customExtractPurpose ? customExtractPurpose(req) : defaultExtractPurpose(req);
|
|
678
666
|
const astraCreds = extractAstraSyncCredentials(req);
|
|
679
667
|
const counterpartyUrl = config.counterpartyUrl || `${req.protocol}://${req.get("host")}`;
|
|
@@ -1019,53 +1007,6 @@ function createMiddleware2(options) {
|
|
|
1019
1007
|
return NextResponse.next();
|
|
1020
1008
|
}
|
|
1021
1009
|
const credentials = extractCredentialsFromNextRequest(request);
|
|
1022
|
-
if (!hasCredentials(credentials) && routeConfig.minAccessLevel !== "guidance") {
|
|
1023
|
-
const counterpartyUrl2 = config.counterpartyUrl || request.nextUrl.origin;
|
|
1024
|
-
reportUnregisteredAttempt(config, {
|
|
1025
|
-
counterpartyUrl: counterpartyUrl2,
|
|
1026
|
-
counterpartyType: config.counterpartyType || "website",
|
|
1027
|
-
sourceIp: request.headers.get("x-forwarded-for") || request.headers.get("x-real-ip") || void 0,
|
|
1028
|
-
userAgent: request.headers.get("user-agent") || void 0,
|
|
1029
|
-
requestPath: pathname,
|
|
1030
|
-
requestMethod: request.method
|
|
1031
|
-
}).catch(() => {
|
|
1032
|
-
});
|
|
1033
|
-
const result2 = {
|
|
1034
|
-
verified: false,
|
|
1035
|
-
accessLevel: "none",
|
|
1036
|
-
denialReasons: ["No agent credentials provided"],
|
|
1037
|
-
guidance: {
|
|
1038
|
-
message: "This page requires agent verification.",
|
|
1039
|
-
registrationUrl: `${config.apiBaseUrl?.replace("/api", "")}/register`,
|
|
1040
|
-
documentationUrl: `${config.apiBaseUrl?.replace("/api", "")}/docs/agent-access`
|
|
1041
|
-
},
|
|
1042
|
-
verifiedAt: /* @__PURE__ */ new Date()
|
|
1043
|
-
};
|
|
1044
|
-
if (pathname.startsWith("/api/")) {
|
|
1045
|
-
return NextResponse.json(
|
|
1046
|
-
{
|
|
1047
|
-
success: false,
|
|
1048
|
-
error: {
|
|
1049
|
-
code: "UNAUTHORIZED",
|
|
1050
|
-
message: "No agent credentials provided",
|
|
1051
|
-
guidance: result2.guidance
|
|
1052
|
-
}
|
|
1053
|
-
},
|
|
1054
|
-
{ status: 401 }
|
|
1055
|
-
);
|
|
1056
|
-
}
|
|
1057
|
-
if (showCommerceShield) {
|
|
1058
|
-
return new NextResponse(generateCommerceShieldHtml(result2, options), {
|
|
1059
|
-
status: 200,
|
|
1060
|
-
headers: {
|
|
1061
|
-
"Content-Type": "text/html",
|
|
1062
|
-
"X-AstraSync-Verification": "commerce-shield"
|
|
1063
|
-
}
|
|
1064
|
-
});
|
|
1065
|
-
}
|
|
1066
|
-
const registerUrl = result2.guidance?.registrationUrl || "/register";
|
|
1067
|
-
return NextResponse.redirect(new URL(registerUrl, request.url));
|
|
1068
|
-
}
|
|
1069
1010
|
const counterpartyUrl = config.counterpartyUrl || request.nextUrl.origin;
|
|
1070
1011
|
const purpose = extractPurpose(request);
|
|
1071
1012
|
const astraCreds = extractAstraSyncCredentialsFromNextRequest(request);
|
|
@@ -3790,11 +3731,11 @@ var AgentClient = class _AgentClient {
|
|
|
3790
3731
|
constructor(config) {
|
|
3791
3732
|
this.credentials = {
|
|
3792
3733
|
agentId: config.agentId,
|
|
3793
|
-
verifyUrl: config.verifyUrl ?? "https://
|
|
3734
|
+
verifyUrl: config.verifyUrl ?? "https://astrasync.ai/api/agents/verify-access",
|
|
3794
3735
|
challengeUrl: config.challengeUrl,
|
|
3795
3736
|
pdlss: config.pdlss
|
|
3796
3737
|
};
|
|
3797
|
-
this.apiBaseUrl = config.apiBaseUrl ?? "https://
|
|
3738
|
+
this.apiBaseUrl = config.apiBaseUrl ?? "https://astrasync.ai/api";
|
|
3798
3739
|
this.apiKey = config.apiKey;
|
|
3799
3740
|
}
|
|
3800
3741
|
/**
|