@kya-os/checkpoint-nextjs 1.7.1 → 1.10.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.
- package/CHANGELOG.md +107 -0
- package/EDGE_RUNTIME_WASM_SETUP.md +11 -11
- package/README.md +144 -251
- package/bin/setup-edge-wasm.js +9 -1
- package/dist/adapt.d.mts +6 -34
- package/dist/adapt.d.mts.map +1 -0
- package/dist/adapt.d.ts +6 -34
- package/dist/adapt.d.ts.map +1 -0
- package/dist/adapt.js +79 -49
- package/dist/adapt.mjs +78 -46
- package/dist/adapt.mjs.map +1 -0
- package/dist/api-client.d.mts +150 -150
- package/dist/api-client.d.mts.map +1 -0
- package/dist/api-client.d.ts +150 -150
- package/dist/api-client.d.ts.map +1 -0
- package/dist/api-client.js +218 -204
- package/dist/api-client.mjs +217 -201
- package/dist/api-client.mjs.map +1 -0
- package/dist/api-middleware-CDSh3TSE.js +379 -0
- package/dist/api-middleware-CMDRoQik.mjs +357 -0
- package/dist/api-middleware-CMDRoQik.mjs.map +1 -0
- package/dist/api-middleware.d.mts +117 -129
- package/dist/api-middleware.d.mts.map +1 -0
- package/dist/api-middleware.d.ts +117 -129
- package/dist/api-middleware.d.ts.map +1 -0
- package/dist/api-middleware.js +8 -540
- package/dist/api-middleware.mjs +3 -534
- package/dist/composed-policy-BCaNiVHv.d.mts +98 -0
- package/dist/composed-policy-BCaNiVHv.d.mts.map +1 -0
- package/dist/composed-policy-zzJYNFTb.d.ts +98 -0
- package/dist/composed-policy-zzJYNFTb.d.ts.map +1 -0
- package/dist/composed-policy.d.mts +2 -115
- package/dist/composed-policy.d.ts +2 -115
- package/dist/composed-policy.js +122 -88
- package/dist/composed-policy.mjs +121 -85
- package/dist/composed-policy.mjs.map +1 -0
- package/dist/config-CbAg2mze.d.ts +255 -0
- package/dist/config-CbAg2mze.d.ts.map +1 -0
- package/dist/config-Doe0Tn53.d.mts +255 -0
- package/dist/config-Doe0Tn53.d.mts.map +1 -0
- package/dist/create-middleware.d.mts +7 -18
- package/dist/create-middleware.d.mts.map +1 -0
- package/dist/create-middleware.d.ts +7 -18
- package/dist/create-middleware.d.ts.map +1 -0
- package/dist/create-middleware.js +36 -31
- package/dist/create-middleware.mjs +35 -28
- package/dist/create-middleware.mjs.map +1 -0
- package/dist/edge/index.d.mts +64 -86
- package/dist/edge/index.d.mts.map +1 -0
- package/dist/edge/index.d.ts +64 -86
- package/dist/edge/index.d.ts.map +1 -0
- package/dist/edge/index.js +349 -275
- package/dist/edge/index.mjs +348 -272
- package/dist/edge/index.mjs.map +1 -0
- package/dist/edge-runtime-loader.d.mts +37 -63
- package/dist/edge-runtime-loader.d.mts.map +1 -0
- package/dist/edge-runtime-loader.d.ts +37 -63
- package/dist/edge-runtime-loader.d.ts.map +1 -0
- package/dist/edge-runtime-loader.js +268 -225
- package/dist/edge-runtime-loader.mjs +267 -222
- package/dist/edge-runtime-loader.mjs.map +1 -0
- package/dist/edge-wasm-middleware.d.mts +27 -46
- package/dist/edge-wasm-middleware.d.mts.map +1 -0
- package/dist/edge-wasm-middleware.d.ts +27 -46
- package/dist/edge-wasm-middleware.d.ts.map +1 -0
- package/dist/edge-wasm-middleware.js +26 -15
- package/dist/edge-wasm-middleware.mjs +25 -12
- package/dist/edge-wasm-middleware.mjs.map +1 -0
- package/dist/index.d.mts +10 -17
- package/dist/index.d.ts +10 -17
- package/dist/index.js +55 -1224
- package/dist/index.mjs +16 -1193
- package/dist/index.mjs.map +1 -0
- package/dist/middleware-bundler.d.mts +7 -0
- package/dist/middleware-bundler.d.mts.map +1 -0
- package/dist/middleware-bundler.d.ts +7 -0
- package/dist/middleware-bundler.d.ts.map +1 -0
- package/dist/middleware-bundler.js +16 -0
- package/dist/middleware-bundler.mjs +16 -0
- package/dist/middleware-bundler.mjs.map +1 -0
- package/dist/middleware-core-BYQP9FND.mjs +165 -0
- package/dist/middleware-core-BYQP9FND.mjs.map +1 -0
- package/dist/middleware-core-D6TijE6P.js +175 -0
- package/dist/middleware-edge.d.mts +8 -50
- package/dist/middleware-edge.d.mts.map +1 -0
- package/dist/middleware-edge.d.ts +8 -50
- package/dist/middleware-edge.d.ts.map +1 -0
- package/dist/middleware-edge.js +41 -307
- package/dist/middleware-edge.mjs +39 -299
- package/dist/middleware-edge.mjs.map +1 -0
- package/dist/middleware-node-CE4GevYs.d.ts +20 -0
- package/dist/middleware-node-CE4GevYs.d.ts.map +1 -0
- package/dist/middleware-node-DtyOuPta.d.mts +20 -0
- package/dist/middleware-node-DtyOuPta.d.mts.map +1 -0
- package/dist/middleware-node-context-BqPbf-fI.mjs +34 -0
- package/dist/middleware-node-context-BqPbf-fI.mjs.map +1 -0
- package/dist/middleware-node-context-rgnc7UNR.js +38 -0
- package/dist/middleware-node.d.mts +3 -63
- package/dist/middleware-node.d.ts +3 -63
- package/dist/middleware-node.js +13 -308
- package/dist/middleware-node.mjs +12 -301
- package/dist/middleware-node.mjs.map +1 -0
- package/dist/middleware.d.mts +8 -28
- package/dist/middleware.d.mts.map +1 -0
- package/dist/middleware.d.ts +8 -28
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +43 -9
- package/dist/middleware.mjs +42 -6
- package/dist/middleware.mjs.map +1 -0
- package/dist/nodejs-wasm-loader.d.mts +8 -7
- package/dist/nodejs-wasm-loader.d.mts.map +1 -0
- package/dist/nodejs-wasm-loader.d.ts +8 -7
- package/dist/nodejs-wasm-loader.d.ts.map +1 -0
- package/dist/nodejs-wasm-loader.js +53 -19
- package/dist/nodejs-wasm-loader.mjs +52 -16
- package/dist/nodejs-wasm-loader.mjs.map +1 -0
- package/dist/policy.d.mts +86 -110
- package/dist/policy.d.mts.map +1 -0
- package/dist/policy.d.ts +86 -110
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +203 -160
- package/dist/policy.mjs +183 -147
- package/dist/policy.mjs.map +1 -0
- package/dist/session-tracker.d.mts +42 -47
- package/dist/session-tracker.d.mts.map +1 -0
- package/dist/session-tracker.d.ts +42 -47
- package/dist/session-tracker.d.ts.map +1 -0
- package/dist/session-tracker.js +141 -163
- package/dist/session-tracker.mjs +140 -160
- package/dist/session-tracker.mjs.map +1 -0
- package/dist/translate.d.mts +18 -30
- package/dist/translate.d.mts.map +1 -0
- package/dist/translate.d.ts +18 -30
- package/dist/translate.d.ts.map +1 -0
- package/dist/translate.js +70 -34
- package/dist/translate.mjs +70 -32
- package/dist/translate.mjs.map +1 -0
- package/dist/types-C0SkqLMM.d.mts +102 -0
- package/dist/types-C0SkqLMM.d.mts.map +1 -0
- package/dist/types-C7DNSCTO.d.ts +102 -0
- package/dist/types-C7DNSCTO.d.ts.map +1 -0
- package/dist/utils-Cj4XNhIY.mjs +35 -0
- package/dist/utils-Cj4XNhIY.mjs.map +1 -0
- package/dist/utils-DAisnYnI.js +45 -0
- package/dist/wasm-setup.d.mts +6 -5
- package/dist/wasm-setup.d.mts.map +1 -0
- package/dist/wasm-setup.d.ts +6 -5
- package/dist/wasm-setup.d.ts.map +1 -0
- package/dist/wasm-setup.js +82 -113
- package/dist/wasm-setup.mjs +85 -108
- package/dist/wasm-setup.mjs.map +1 -0
- package/package.json +22 -15
- package/dist/config-DAwIA4DB.d.mts +0 -214
- package/dist/config-DyU4l5er.d.ts +0 -214
- package/dist/types-D9RQvPNy.d.mts +0 -105
- package/dist/types-D9RQvPNy.d.ts +0 -105
package/dist/middleware-edge.mjs
CHANGED
|
@@ -1,304 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import { NextResponse } from 'next/server';
|
|
7
|
-
import { makeComposedPolicyCache, evaluateComposedPolicy, verifyResultToAuthorizeInput } from '@kya-os/checkpoint-wasm-runtime/composed-policy';
|
|
8
|
-
import '@kya-os/checkpoint-wasm-runtime/orchestrator';
|
|
9
|
-
import { makeSystemClock, makePolicyEvaluator, makeReputationOracle, makeStatusListCache, makeDidResolver } from '@kya-os/checkpoint-wasm-runtime/adapters';
|
|
10
|
-
import { makeDetectionReporter } from '@kya-os/checkpoint-wasm-runtime/reporter';
|
|
1
|
+
import { DEFAULT_DASHBOARD_URL, consoleComposedPolicyLogger, makeComposedPolicyContext } from "./composed-policy.mjs";
|
|
2
|
+
import { n as makeNextMiddleware } from "./middleware-core-BYQP9FND.mjs";
|
|
3
|
+
import { PolicyFetcher } from "@kya-os/checkpoint-shared";
|
|
4
|
+
import { initEngineEdge, renderDecisionAsResponse, verifyRequestEdge } from "@kya-os/checkpoint-wasm-runtime/orchestrator/edge";
|
|
5
|
+
import { evaluatePolicy as evaluatePolicy$1, initPolicyEvaluatorEdge } from "@kya-os/checkpoint-wasm-runtime/policy-edge";
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const clientAcceptsHtml = acceptsHtml(req.headers);
|
|
15
|
-
const verdictCookie = encodeVerdictCookie(rendered);
|
|
16
|
-
const shape = classifyResponseShape(rendered, clientAcceptsHtml);
|
|
17
|
-
switch (shape) {
|
|
18
|
-
case "pass-through": {
|
|
19
|
-
const res = NextResponse.next();
|
|
20
|
-
applyHeaders(res, rendered.headers);
|
|
21
|
-
setVerdictCookie(res, verdictCookie);
|
|
22
|
-
return res;
|
|
23
|
-
}
|
|
24
|
-
case "redirect": {
|
|
25
|
-
const target = new URL(rendered.headers.Location);
|
|
26
|
-
const res = NextResponse.redirect(target);
|
|
27
|
-
applyHeaders(res, rendered.headers);
|
|
28
|
-
setVerdictCookie(res, verdictCookie);
|
|
29
|
-
return res;
|
|
30
|
-
}
|
|
31
|
-
case "html-block": {
|
|
32
|
-
const blockedUrl = new URL(BLOCKED_PATH, req.url);
|
|
33
|
-
const res = NextResponse.rewrite(blockedUrl, { status: 200 });
|
|
34
|
-
applyHeaders(res, rendered.headers);
|
|
35
|
-
setVerdictCookie(res, verdictCookie);
|
|
36
|
-
return res;
|
|
37
|
-
}
|
|
38
|
-
case "json-block": {
|
|
39
|
-
const body = rendered.body ?? {};
|
|
40
|
-
const res = NextResponse.json(body, { status: rendered.status });
|
|
41
|
-
applyHeaders(res, rendered.headers);
|
|
42
|
-
setVerdictCookie(res, verdictCookie);
|
|
43
|
-
return res;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function setVerdictCookie(res, value) {
|
|
48
|
-
res.cookies.set({
|
|
49
|
-
name: VERDICT_COOKIE_NAME,
|
|
50
|
-
value,
|
|
51
|
-
path: "/",
|
|
52
|
-
sameSite: "lax",
|
|
53
|
-
httpOnly: false
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
function applyHeaders(res, headers) {
|
|
57
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
58
|
-
res.headers.set(key, value);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
var DEFAULT_DASHBOARD_URL = "https://kya.vouched.id";
|
|
62
|
-
var NOOP_LOGGER = {
|
|
63
|
-
shadowDivergence: () => {
|
|
64
|
-
},
|
|
65
|
-
evaluationError: () => {
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
function makeComposedPolicyContext(opts) {
|
|
69
|
-
const { projectId, fetcher } = opts;
|
|
70
|
-
const cache = makeComposedPolicyCache({ compile: opts.compile, cacheMax: opts.cacheMax });
|
|
71
|
-
const logger = opts.logger ?? NOOP_LOGGER;
|
|
72
|
-
return {
|
|
73
|
-
async apply(result, path) {
|
|
74
|
-
const structured = { decision: result.decision, acted: false };
|
|
75
|
-
const policy = await fetcher.getPolicy(projectId);
|
|
76
|
-
const outcome = await evaluateComposedPolicy({
|
|
77
|
-
cache,
|
|
78
|
-
projectId,
|
|
79
|
-
flags: {
|
|
80
|
-
policyLanguage: policy.policyLanguage,
|
|
81
|
-
policySourceText: policy.policySourceText,
|
|
82
|
-
engineEnforcementEnabled: policy.engineEnforcementEnabled,
|
|
83
|
-
enabled: policy.enabled
|
|
84
|
-
},
|
|
85
|
-
authorizeInput: verifyResultToAuthorizeInput(result, { tenantId: projectId, path }),
|
|
86
|
-
baselineDecisionKind: result.decision.kind
|
|
87
|
-
});
|
|
88
|
-
if ((outcome.status === "acting" || outcome.status === "shadow") && outcome.diverged) {
|
|
89
|
-
logger.shadowDivergence({
|
|
90
|
-
projectId,
|
|
91
|
-
path,
|
|
92
|
-
engineDecision: outcome.engineDecision.kind,
|
|
93
|
-
structuredDecision: result.decision.kind,
|
|
94
|
-
detectionClass: result.detectionDetail.detectionClass.type,
|
|
95
|
-
verificationMethod: result.detectionDetail.verificationMethod,
|
|
96
|
-
confidence: result.detectionDetail.confidence,
|
|
97
|
-
agentName: result.detectionDetail.detectedAgent?.name
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
if (outcome.status === "error") {
|
|
101
|
-
logger.evaluationError(projectId, outcome.error);
|
|
102
|
-
return structured;
|
|
103
|
-
}
|
|
104
|
-
if (outcome.status === "acting") {
|
|
105
|
-
return {
|
|
106
|
-
decision: outcome.engineDecision,
|
|
107
|
-
acted: true,
|
|
108
|
-
// Echo the SSOT revision pin with the decision it produced (#3246
|
|
109
|
-
// PR5). Conditional spread: absent upstream stays absent here.
|
|
110
|
-
...policy.policySourceHash ? { composedBlobHash: policy.policySourceHash } : {}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
return structured;
|
|
114
|
-
},
|
|
115
|
-
async trustedDelegationRoots() {
|
|
116
|
-
const policy = await fetcher.getPolicy(projectId);
|
|
117
|
-
return policy.trustedDelegationRoots ?? [];
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
async function resolveTrustedDelegationRootsForRequest(resolver, headers) {
|
|
122
|
-
if (!resolver) return void 0;
|
|
123
|
-
if (!requestCarriesDelegationProof(headers)) return void 0;
|
|
124
|
-
const roots = await resolver();
|
|
125
|
-
return roots.length > 0 ? roots : void 0;
|
|
126
|
-
}
|
|
127
|
-
async function applyComposedPolicy(context, result, path) {
|
|
128
|
-
if (!context) return;
|
|
129
|
-
try {
|
|
130
|
-
const outcome = await context.apply(result, path);
|
|
131
|
-
if (outcome.acted) {
|
|
132
|
-
result.decision = outcome.decision;
|
|
133
|
-
if (outcome.composedBlobHash) {
|
|
134
|
-
result.composedBlobHash = outcome.composedBlobHash;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
} catch {
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
var consoleComposedPolicyLogger = {
|
|
141
|
-
shadowDivergence(info) {
|
|
142
|
-
console.warn("[checkpoint/composed-policy] shadow-divergence", info);
|
|
143
|
-
},
|
|
144
|
-
evaluationError(projectId, error) {
|
|
145
|
-
console.error(
|
|
146
|
-
`[checkpoint/composed-policy] evaluation failed for ${projectId}; using structured decision:`,
|
|
147
|
-
error
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
// src/translate.ts
|
|
153
|
-
async function nextRequestToHttpLike(req, opts = {}) {
|
|
154
|
-
const url = new URL(req.url);
|
|
155
|
-
const body = await tryDrainJsonBody(req, opts);
|
|
156
|
-
return {
|
|
157
|
-
method: req.method,
|
|
158
|
-
// Path + query only — orchestrator's URL parsing expects no scheme/host.
|
|
159
|
-
url: url.pathname + url.search,
|
|
160
|
-
headers: headersToRecord(req.headers),
|
|
161
|
-
body,
|
|
162
|
-
remoteAddress: extractRemoteAddress(req)
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
async function tryDrainJsonBody(req, opts) {
|
|
166
|
-
if (opts.drainJsonBody === false) return null;
|
|
167
|
-
const contentType = req.headers.get("content-type") ?? "";
|
|
168
|
-
if (!contentType.toLowerCase().includes("application/json")) return null;
|
|
169
|
-
try {
|
|
170
|
-
return await req.clone().text();
|
|
171
|
-
} catch {
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
function headersToRecord(headers) {
|
|
176
|
-
const out = {};
|
|
177
|
-
headers.forEach((value, key) => {
|
|
178
|
-
out[key.toLowerCase()] = value;
|
|
179
|
-
});
|
|
180
|
-
return out;
|
|
181
|
-
}
|
|
182
|
-
function extractRemoteAddress(req) {
|
|
183
|
-
const xff = req.headers.get("x-forwarded-for");
|
|
184
|
-
if (xff) {
|
|
185
|
-
const first = xff.split(",")[0]?.trim();
|
|
186
|
-
if (first) return first;
|
|
187
|
-
}
|
|
188
|
-
const maybeIp = req.ip;
|
|
189
|
-
return maybeIp;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// src/middleware-node.ts
|
|
193
|
-
var SDK_NAME = "@kya-os/checkpoint-nextjs";
|
|
194
|
-
var VERSION = "1.7.1";
|
|
195
|
-
function buildReporter(config, runtime = "node") {
|
|
196
|
-
if (!config.apiKey) return null;
|
|
197
|
-
return makeDetectionReporter({
|
|
198
|
-
apiKey: config.apiKey,
|
|
199
|
-
baseUrl: config.baseUrl,
|
|
200
|
-
debug: config.debug,
|
|
201
|
-
// Self-identify (incl. node-vs-edge) so the dashboard can version-gate
|
|
202
|
-
// enforcement. Next.js EDGE composed enforcement is opt-in (needs
|
|
203
|
-
// `cedarWasmModule`), so the dashboard shows it as opt-in, never "Enforcing".
|
|
204
|
-
sdk: { name: SDK_NAME, version: VERSION, runtime }
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
function buildTrustedRootsResolver(config, composed) {
|
|
208
|
-
if (composed?.trustedDelegationRoots) {
|
|
209
|
-
return () => composed.trustedDelegationRoots();
|
|
210
|
-
}
|
|
211
|
-
if (!config.projectId) return null;
|
|
212
|
-
const fetcher = new PolicyFetcher({
|
|
213
|
-
apiBaseUrl: config.dashboardUrl ?? config.baseUrl ?? DEFAULT_DASHBOARD_URL,
|
|
214
|
-
apiKey: config.apiKey,
|
|
215
|
-
cacheTtlSeconds: config.policyCacheTtlSeconds
|
|
216
|
-
});
|
|
217
|
-
const projectId = config.projectId;
|
|
218
|
-
return async () => (await fetcher.getPolicy(projectId)).trustedDelegationRoots ?? [];
|
|
219
|
-
}
|
|
220
|
-
function extractReporterContext(req) {
|
|
221
|
-
return {
|
|
222
|
-
userAgent: req.headers.get("user-agent") ?? void 0,
|
|
223
|
-
ipAddress: req.headers.get("x-forwarded-for")?.split(",")[0]?.trim() ?? req.headers.get("x-real-ip") ?? void 0,
|
|
224
|
-
path: req.nextUrl.pathname,
|
|
225
|
-
url: req.nextUrl.href,
|
|
226
|
-
method: req.method
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
function buildVerifyOpts(config) {
|
|
230
|
-
const overrides = config.adapters ?? {};
|
|
231
|
-
return {
|
|
232
|
-
didResolver: overrides.didResolver ?? makeDidResolver(),
|
|
233
|
-
statusListCache: overrides.statusListCache ?? makeStatusListCache(),
|
|
234
|
-
reputationOracle: overrides.reputationOracle ?? makeReputationOracle({ argusUrl: config.argusUrl }),
|
|
235
|
-
policyEvaluator: overrides.policyEvaluator ?? makePolicyEvaluator({ dashboardUrl: config.dashboardUrl }),
|
|
236
|
-
clock: makeSystemClock(),
|
|
237
|
-
tenantHost: config.tenantHost,
|
|
238
|
-
enforcementMode: config.enforcementMode ?? "enforce",
|
|
239
|
-
reputationBaseline: config.reputationBaseline,
|
|
240
|
-
argusUrl: config.argusUrl,
|
|
241
|
-
legacyEnvelopeFallback: config.legacyEnvelopeFallback ?? false,
|
|
242
|
-
engineConfig: config.engineConfig
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// src/middleware-edge.ts
|
|
7
|
+
//#region src/middleware-edge.ts
|
|
8
|
+
/** Edge host: eagerly initialize its engine and opt into Cedar only when wired. */
|
|
247
9
|
function withCheckpoint(config) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
await applyComposedPolicy(composed, result, req.nextUrl.pathname);
|
|
265
|
-
if (reporter) {
|
|
266
|
-
const reportPromise = reporter(result, extractReporterContext(req));
|
|
267
|
-
if (event) {
|
|
268
|
-
event.waitUntil(reportPromise);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
await dispatchOnResult(config, result, req);
|
|
272
|
-
const bodyReadable200 = selectBodyReadable200(
|
|
273
|
-
config.delegationChallengeMode ?? "spec-401",
|
|
274
|
-
req.headers,
|
|
275
|
-
result.detectionDetail.detectionClass
|
|
276
|
-
);
|
|
277
|
-
const rendered = renderDecisionAsResponse(result, { bodyReadable200 });
|
|
278
|
-
return adaptToNextResponse(rendered, req);
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
async function dispatchOnResult(config, result, req) {
|
|
282
|
-
if (!config.onResult) return;
|
|
283
|
-
try {
|
|
284
|
-
await config.onResult(result, req);
|
|
285
|
-
} catch {
|
|
286
|
-
}
|
|
287
|
-
}
|
|
10
|
+
initEngineEdge();
|
|
11
|
+
return makeNextMiddleware(verifyRequestEdge, renderDecisionAsResponse, config, {
|
|
12
|
+
runtime: "edge",
|
|
13
|
+
buildComposedContext
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Build the EDGE-runtime composed-policy context. Unlike Node, edge composed
|
|
18
|
+
* enforcement is CONSUMER-OPT-IN: it requires `cedarWasmModule` to be wired so
|
|
19
|
+
* the ~2 MB cedar binary is never forced into every consumer's Edge Middleware
|
|
20
|
+
* bundle, and so the unproven `new URL('…cedar…')` fallback fetch is never
|
|
21
|
+
* reached. Without it the seam stays inert — edge behaves exactly as 1.4.0.
|
|
22
|
+
* When wired, the cedar-web module is registered once via
|
|
23
|
+
* `initPolicyEvaluatorEdge`, and the async `evaluatePolicy` compiler is injected
|
|
24
|
+
* into the shared core (its single-flight cache absorbs the async compile).
|
|
25
|
+
*/
|
|
288
26
|
function buildComposedContext(config) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
27
|
+
if (config.composedPolicyEnforcer) return config.composedPolicyEnforcer;
|
|
28
|
+
if (!config.projectId || !config.cedarWasmModule) return null;
|
|
29
|
+
initPolicyEvaluatorEdge(config.cedarWasmModule);
|
|
30
|
+
return makeComposedPolicyContext({
|
|
31
|
+
projectId: config.projectId,
|
|
32
|
+
fetcher: new PolicyFetcher({
|
|
33
|
+
apiBaseUrl: config.dashboardUrl ?? config.baseUrl ?? "https://kya.vouched.id",
|
|
34
|
+
apiKey: config.apiKey,
|
|
35
|
+
cacheTtlSeconds: config.policyCacheTtlSeconds
|
|
36
|
+
}),
|
|
37
|
+
compile: (language, source) => evaluatePolicy$1(language, source),
|
|
38
|
+
logger: config.debug ? consoleComposedPolicyLogger : void 0
|
|
39
|
+
});
|
|
302
40
|
}
|
|
303
41
|
|
|
304
|
-
|
|
42
|
+
//#endregion
|
|
43
|
+
export { initEngineEdge, initPolicyEvaluatorEdge, withCheckpoint };
|
|
44
|
+
//# sourceMappingURL=middleware-edge.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-edge.mjs","names":["evaluatePolicy"],"sources":["../src/middleware-edge.ts"],"sourcesContent":["/** Edge host: eagerly initialize its engine and opt into Cedar only when wired. */\nimport {\n initEngineEdge,\n renderDecisionAsResponse,\n verifyRequestEdge,\n} from '@kya-os/checkpoint-wasm-runtime/orchestrator/edge';\nimport {\n evaluatePolicy,\n initPolicyEvaluatorEdge,\n} from '@kya-os/checkpoint-wasm-runtime/policy-edge';\nimport { PolicyFetcher } from '@kya-os/checkpoint-shared';\nimport {\n makeComposedPolicyContext,\n consoleComposedPolicyLogger,\n DEFAULT_DASHBOARD_URL,\n type ComposedPolicyContext,\n} from './composed-policy';\nimport { makeNextMiddleware } from './middleware-core';\nimport type { CheckpointConfig } from './config';\nexport type { CheckpointConfig } from './config';\n\nexport function withCheckpoint(config: CheckpointConfig) {\n // The first request awaits this same idempotent initialization promise.\n void initEngineEdge();\n return makeNextMiddleware(verifyRequestEdge, renderDecisionAsResponse, config, {\n runtime: 'edge',\n buildComposedContext,\n });\n}\n\n/**\n * Build the EDGE-runtime composed-policy context. Unlike Node, edge composed\n * enforcement is CONSUMER-OPT-IN: it requires `cedarWasmModule` to be wired so\n * the ~2 MB cedar binary is never forced into every consumer's Edge Middleware\n * bundle, and so the unproven `new URL('…cedar…')` fallback fetch is never\n * reached. Without it the seam stays inert — edge behaves exactly as 1.4.0.\n * When wired, the cedar-web module is registered once via\n * `initPolicyEvaluatorEdge`, and the async `evaluatePolicy` compiler is injected\n * into the shared core (its single-flight cache absorbs the async compile).\n */\nfunction buildComposedContext(config: CheckpointConfig): ComposedPolicyContext | null {\n if (config.composedPolicyEnforcer) return config.composedPolicyEnforcer;\n if (!config.projectId || !config.cedarWasmModule) return null;\n initPolicyEvaluatorEdge(config.cedarWasmModule);\n return makeComposedPolicyContext({\n projectId: config.projectId,\n fetcher: new PolicyFetcher({\n apiBaseUrl: config.dashboardUrl ?? config.baseUrl ?? DEFAULT_DASHBOARD_URL,\n apiKey: config.apiKey,\n cacheTtlSeconds: config.policyCacheTtlSeconds,\n }),\n compile: (language, source) => evaluatePolicy(language, source),\n logger: config.debug ? consoleComposedPolicyLogger : undefined,\n });\n}\n\n// Allow hosts to initialize their WASM modules explicitly at startup.\nexport { initEngineEdge, initPolicyEvaluatorEdge };\n"],"mappings":";;;;;;;;AAqBA,SAAgB,eAAe,QAA0B;CAEvD,AAAK,eAAe;CACpB,OAAO,mBAAmB,mBAAmB,0BAA0B,QAAQ;EAC7E,SAAS;EACT;CACF,CAAC;AACH;;;;;;;;;;;AAYA,SAAS,qBAAqB,QAAwD;CACpF,IAAI,OAAO,wBAAwB,OAAO,OAAO;CACjD,IAAI,CAAC,OAAO,aAAa,CAAC,OAAO,iBAAiB,OAAO;CACzD,wBAAwB,OAAO,eAAe;CAC9C,OAAO,0BAA0B;EAC/B,WAAW,OAAO;EAClB,SAAS,IAAI,cAAc;GACzB,YAAY,OAAO,gBAAgB,OAAO;GAC1C,QAAQ,OAAO;GACf,iBAAiB,OAAO;EAC1B,CAAC;EACD,UAAU,UAAU,WAAWA,iBAAe,UAAU,MAAM;EAC9D,QAAQ,OAAO,QAAQ,8BAA8B;CACvD,CAAC;AACH"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "./composed-policy-zzJYNFTb.js";
|
|
2
|
+
import { t as CheckpointConfig } from "./config-CbAg2mze.js";
|
|
3
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
4
|
+
import { IncomingHttpLike } from "@kya-os/checkpoint-wasm-runtime/orchestrator";
|
|
5
|
+
import { VerifyResult } from "@kya-os/checkpoint-wasm-runtime/engine";
|
|
6
|
+
//#region src/middleware-core.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Installed SDK version, self-reported to the detection reporter so the
|
|
9
|
+
* dashboard can version-gate "composed policy enforces here". MUST equal
|
|
10
|
+
* `package.json` version — pinned by a unit test (the old hardcoded `0.1.0` had
|
|
11
|
+
* drifted). Re-exported as `VERSION` from the package index.
|
|
12
|
+
*/
|
|
13
|
+
declare const VERSION = "1.10.0";
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/middleware-node.d.ts
|
|
16
|
+
/** Node host with native filesystem WASM loading. */
|
|
17
|
+
declare function withCheckpoint(config: CheckpointConfig): (req: import("next/server").NextRequest, event?: Pick<import("next/server").NextFetchEvent, "waitUntil">) => Promise<import("next/server").NextResponse>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { VERSION as n, withCheckpoint as t };
|
|
20
|
+
//# sourceMappingURL=middleware-node-CE4GevYs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-node-CE4GevYs.d.ts","names":[],"sources":["../src/middleware-core.ts","../src/middleware-node.ts"],"mappings":";;;;;;;;;;;;cA+Ka;;;;iBCrKG,eAAe,QAAQ,oBAAgB,2BAAA,aAAA,QAAA,2BAAA,iCAAA,8BAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "./composed-policy-BCaNiVHv.mjs";
|
|
2
|
+
import { t as CheckpointConfig } from "./config-Doe0Tn53.mjs";
|
|
3
|
+
import { IncomingHttpLike, renderDecisionAsResponse } from "@kya-os/checkpoint-wasm-runtime/orchestrator";
|
|
4
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
5
|
+
import { VerifyResult } from "@kya-os/checkpoint-wasm-runtime/engine";
|
|
6
|
+
//#region src/middleware-core.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Installed SDK version, self-reported to the detection reporter so the
|
|
9
|
+
* dashboard can version-gate "composed policy enforces here". MUST equal
|
|
10
|
+
* `package.json` version — pinned by a unit test (the old hardcoded `0.1.0` had
|
|
11
|
+
* drifted). Re-exported as `VERSION` from the package index.
|
|
12
|
+
*/
|
|
13
|
+
declare const VERSION = "1.10.0";
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/middleware-node.d.ts
|
|
16
|
+
/** Node host with native filesystem WASM loading. */
|
|
17
|
+
declare function withCheckpoint(config: CheckpointConfig): (req: import("next/server").NextRequest, event?: Pick<import("next/server").NextFetchEvent, "waitUntil">) => Promise<import("next/server").NextResponse>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { VERSION as n, withCheckpoint as t };
|
|
20
|
+
//# sourceMappingURL=middleware-node-DtyOuPta.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-node-DtyOuPta.d.mts","names":[],"sources":["../src/middleware-core.ts","../src/middleware-node.ts"],"mappings":";;;;;;;;;;;;cA+Ka;;;;iBCrKG,eAAe,QAAQ,oBAAgB,2BAAA,aAAA,QAAA,2BAAA,iCAAA,8BAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DEFAULT_DASHBOARD_URL, consoleComposedPolicyLogger, makeComposedPolicyContext } from "./composed-policy.mjs";
|
|
2
|
+
import { PolicyFetcher } from "@kya-os/checkpoint-shared";
|
|
3
|
+
|
|
4
|
+
//#region src/middleware-node-context.ts
|
|
5
|
+
/**
|
|
6
|
+
* Build the Node-runtime composed-policy context. Prefers an injected enforcer
|
|
7
|
+
* (advanced/testing); otherwise constructs one from `projectId` with the SYNC
|
|
8
|
+
* `createPolicyEvaluator` compiler (loads the cedar-nodejs glue lazily on first
|
|
9
|
+
* use — no init handshake, never bundled into the edge build). Returns `null`
|
|
10
|
+
* when composed enforcement isn't configured (back-compat). The composed-policy
|
|
11
|
+
* fetch honors `dashboardUrl ?? baseUrl ?? default` (the documented policy-fetch
|
|
12
|
+
* base).
|
|
13
|
+
*/
|
|
14
|
+
function buildComposedContext(config) {
|
|
15
|
+
if (config.composedPolicyEnforcer) return config.composedPolicyEnforcer;
|
|
16
|
+
if (!config.projectId) return null;
|
|
17
|
+
return makeComposedPolicyContext({
|
|
18
|
+
projectId: config.projectId,
|
|
19
|
+
fetcher: new PolicyFetcher({
|
|
20
|
+
apiBaseUrl: config.dashboardUrl ?? config.baseUrl ?? "https://kya.vouched.id",
|
|
21
|
+
apiKey: config.apiKey,
|
|
22
|
+
cacheTtlSeconds: config.policyCacheTtlSeconds
|
|
23
|
+
}),
|
|
24
|
+
compile: async (_language, source) => {
|
|
25
|
+
const { createPolicyEvaluator } = await import("@kya-os/checkpoint-wasm-runtime/policy");
|
|
26
|
+
return createPolicyEvaluator(source);
|
|
27
|
+
},
|
|
28
|
+
logger: config.debug ? consoleComposedPolicyLogger : void 0
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { buildComposedContext as t };
|
|
34
|
+
//# sourceMappingURL=middleware-node-context-BqPbf-fI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-node-context-BqPbf-fI.mjs","names":[],"sources":["../src/middleware-node-context.ts"],"sourcesContent":["import { PolicyFetcher } from '@kya-os/checkpoint-shared';\nimport type { CheckpointConfig } from './config';\nimport {\n makeComposedPolicyContext,\n consoleComposedPolicyLogger,\n DEFAULT_DASHBOARD_URL,\n type ComposedPolicyContext,\n} from './composed-policy';\n\n/**\n * Build the Node-runtime composed-policy context. Prefers an injected enforcer\n * (advanced/testing); otherwise constructs one from `projectId` with the SYNC\n * `createPolicyEvaluator` compiler (loads the cedar-nodejs glue lazily on first\n * use — no init handshake, never bundled into the edge build). Returns `null`\n * when composed enforcement isn't configured (back-compat). The composed-policy\n * fetch honors `dashboardUrl ?? baseUrl ?? default` (the documented policy-fetch\n * base).\n */\nexport function buildComposedContext(config: CheckpointConfig): ComposedPolicyContext | null {\n if (config.composedPolicyEnforcer) return config.composedPolicyEnforcer;\n if (!config.projectId) return null;\n return makeComposedPolicyContext({\n projectId: config.projectId,\n fetcher: new PolicyFetcher({\n apiBaseUrl: config.dashboardUrl ?? config.baseUrl ?? DEFAULT_DASHBOARD_URL,\n apiKey: config.apiKey,\n cacheTtlSeconds: config.policyCacheTtlSeconds,\n }),\n // Load the Node policy compiler only on first use. This module is imported\n // exclusively by the Node and bundler hosts, never by the Edge pipeline.\n compile: async (_language, source) => {\n const { createPolicyEvaluator } = await import('@kya-os/checkpoint-wasm-runtime/policy');\n return createPolicyEvaluator(source);\n },\n logger: config.debug ? consoleComposedPolicyLogger : undefined,\n });\n}\n"],"mappings":";;;;;;;;;;;;;AAkBA,SAAgB,qBAAqB,QAAwD;CAC3F,IAAI,OAAO,wBAAwB,OAAO,OAAO;CACjD,IAAI,CAAC,OAAO,WAAW,OAAO;CAC9B,OAAO,0BAA0B;EAC/B,WAAW,OAAO;EAClB,SAAS,IAAI,cAAc;GACzB,YAAY,OAAO,gBAAgB,OAAO;GAC1C,QAAQ,OAAO;GACf,iBAAiB,OAAO;EAC1B,CAAC;EAGD,SAAS,OAAO,WAAW,WAAW;GACpC,MAAM,EAAE,0BAA0B,MAAM,OAAO;GAC/C,OAAO,sBAAsB,MAAM;EACrC;EACA,QAAQ,OAAO,QAAQ,8BAA8B;CACvD,CAAC;AACH"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const require_composed_policy = require('./composed-policy.js');
|
|
2
|
+
let _kya_os_checkpoint_shared = require("@kya-os/checkpoint-shared");
|
|
3
|
+
|
|
4
|
+
//#region src/middleware-node-context.ts
|
|
5
|
+
/**
|
|
6
|
+
* Build the Node-runtime composed-policy context. Prefers an injected enforcer
|
|
7
|
+
* (advanced/testing); otherwise constructs one from `projectId` with the SYNC
|
|
8
|
+
* `createPolicyEvaluator` compiler (loads the cedar-nodejs glue lazily on first
|
|
9
|
+
* use — no init handshake, never bundled into the edge build). Returns `null`
|
|
10
|
+
* when composed enforcement isn't configured (back-compat). The composed-policy
|
|
11
|
+
* fetch honors `dashboardUrl ?? baseUrl ?? default` (the documented policy-fetch
|
|
12
|
+
* base).
|
|
13
|
+
*/
|
|
14
|
+
function buildComposedContext(config) {
|
|
15
|
+
if (config.composedPolicyEnforcer) return config.composedPolicyEnforcer;
|
|
16
|
+
if (!config.projectId) return null;
|
|
17
|
+
return require_composed_policy.makeComposedPolicyContext({
|
|
18
|
+
projectId: config.projectId,
|
|
19
|
+
fetcher: new _kya_os_checkpoint_shared.PolicyFetcher({
|
|
20
|
+
apiBaseUrl: config.dashboardUrl ?? config.baseUrl ?? "https://kya.vouched.id",
|
|
21
|
+
apiKey: config.apiKey,
|
|
22
|
+
cacheTtlSeconds: config.policyCacheTtlSeconds
|
|
23
|
+
}),
|
|
24
|
+
compile: async (_language, source) => {
|
|
25
|
+
const { createPolicyEvaluator } = await import("@kya-os/checkpoint-wasm-runtime/policy");
|
|
26
|
+
return createPolicyEvaluator(source);
|
|
27
|
+
},
|
|
28
|
+
logger: config.debug ? require_composed_policy.consoleComposedPolicyLogger : void 0
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
Object.defineProperty(exports, 'buildComposedContext', {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function () {
|
|
36
|
+
return buildComposedContext;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
@@ -1,63 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import { DetectionReporter, ReporterContext } from '@kya-os/checkpoint-wasm-runtime/reporter';
|
|
5
|
-
import { C as CheckpointConfig } from './config-DAwIA4DB.mjs';
|
|
6
|
-
import { ComposedPolicyContext, TrustedDelegationRootsResolver } from './composed-policy.mjs';
|
|
7
|
-
import '@kya-os/checkpoint-shared';
|
|
8
|
-
import '@kya-os/checkpoint-wasm-runtime/composed-policy';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Build the Checkpoint middleware. Returns a function `(req) => NextResponse`
|
|
12
|
-
* suitable for `export default withCheckpoint({...})` in `middleware.ts`.
|
|
13
|
-
*
|
|
14
|
-
* Every verification decision flows through the Rust `kya-os-engine`
|
|
15
|
-
* via WASM. The TS layer translates request shape, calls
|
|
16
|
-
* `verifyRequest`, and translates the verdict to `NextResponse`. No
|
|
17
|
-
* verification logic lives in this file.
|
|
18
|
-
*/
|
|
19
|
-
declare function withCheckpoint(config: CheckpointConfig): (req: NextRequest, event?: NextFetchEvent) => Promise<NextResponse>;
|
|
20
|
-
/**
|
|
21
|
-
* Installed SDK version, self-reported to the detection reporter so the
|
|
22
|
-
* dashboard can version-gate "composed policy enforces here". MUST equal
|
|
23
|
-
* `package.json` version — pinned by a unit test (the old hardcoded `0.1.0` had
|
|
24
|
-
* drifted). Re-exported as `VERSION` from the package index.
|
|
25
|
-
*/
|
|
26
|
-
declare const VERSION = "1.7.1";
|
|
27
|
-
declare function buildReporter(config: CheckpointConfig, runtime?: 'node' | 'edge'): DetectionReporter | null;
|
|
28
|
-
/**
|
|
29
|
-
* Build the per-factory trusted-delegation-roots resolver (P2 / DR-1). Root
|
|
30
|
-
* pinning is a security concern INDEPENDENT of composed Cedar enforcement, so it
|
|
31
|
-
* must resolve wherever a `projectId` exists — including Edge setups that never
|
|
32
|
-
* wire `cedarWasmModule` (where `buildComposedContext` returns null). Prefers the
|
|
33
|
-
* composed context's accessor (reuses its cached fetcher / honors an injected
|
|
34
|
-
* enforcer); otherwise falls back to a `projectId`-only policy fetch. Returns
|
|
35
|
-
* `null` when no source is configured (no roots → engine open default).
|
|
36
|
-
*/
|
|
37
|
-
declare function buildTrustedRootsResolver(config: CheckpointConfig, composed: ComposedPolicyContext | null): TrustedDelegationRootsResolver | null;
|
|
38
|
-
/**
|
|
39
|
-
* Pull the request context the dashboard's `/api/v1/log-detection`
|
|
40
|
-
* endpoint expects out of a `NextRequest`. Works under both Node and
|
|
41
|
-
* Edge runtimes — no runtime-specific APIs.
|
|
42
|
-
*/
|
|
43
|
-
declare function extractReporterContext(req: NextRequest): ReporterContext;
|
|
44
|
-
/**
|
|
45
|
-
* Compose adapter defaults with caller-supplied overrides. Factored
|
|
46
|
-
* out so the Edge entry (which uses the same composition) can reuse
|
|
47
|
-
* the shape.
|
|
48
|
-
*/
|
|
49
|
-
declare function buildVerifyOpts(config: CheckpointConfig): {
|
|
50
|
-
didResolver: _kya_os_checkpoint_wasm_runtime_adapters.DidResolverAdapter;
|
|
51
|
-
statusListCache: _kya_os_checkpoint_wasm_runtime_adapters.StatusListCacheAdapter;
|
|
52
|
-
reputationOracle: _kya_os_checkpoint_wasm_runtime_adapters.ReputationOracleAdapter;
|
|
53
|
-
policyEvaluator: _kya_os_checkpoint_wasm_runtime_adapters.PolicyEvaluatorAdapter;
|
|
54
|
-
clock: _kya_os_checkpoint_wasm_runtime_adapters.ClockAdapter;
|
|
55
|
-
tenantHost: string;
|
|
56
|
-
enforcementMode: _kya_os_checkpoint_wasm_runtime_engine.EnforcementMode;
|
|
57
|
-
reputationBaseline: number | undefined;
|
|
58
|
-
argusUrl: string | undefined;
|
|
59
|
-
legacyEnvelopeFallback: boolean;
|
|
60
|
-
engineConfig: _kya_os_checkpoint_wasm_runtime_engine.EngineConfig | undefined;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export { CheckpointConfig, VERSION, buildReporter as _buildReporter, buildTrustedRootsResolver as _buildTrustedRootsResolver, buildVerifyOpts as _buildVerifyOpts, extractReporterContext as _extractReporterContext, withCheckpoint };
|
|
1
|
+
import { t as CheckpointConfig } from "./config-Doe0Tn53.mjs";
|
|
2
|
+
import { n as VERSION, t as withCheckpoint } from "./middleware-node-DtyOuPta.mjs";
|
|
3
|
+
export { type CheckpointConfig, VERSION, withCheckpoint };
|
|
@@ -1,63 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import { DetectionReporter, ReporterContext } from '@kya-os/checkpoint-wasm-runtime/reporter';
|
|
5
|
-
import { C as CheckpointConfig } from './config-DyU4l5er.js';
|
|
6
|
-
import { ComposedPolicyContext, TrustedDelegationRootsResolver } from './composed-policy.js';
|
|
7
|
-
import '@kya-os/checkpoint-shared';
|
|
8
|
-
import '@kya-os/checkpoint-wasm-runtime/composed-policy';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Build the Checkpoint middleware. Returns a function `(req) => NextResponse`
|
|
12
|
-
* suitable for `export default withCheckpoint({...})` in `middleware.ts`.
|
|
13
|
-
*
|
|
14
|
-
* Every verification decision flows through the Rust `kya-os-engine`
|
|
15
|
-
* via WASM. The TS layer translates request shape, calls
|
|
16
|
-
* `verifyRequest`, and translates the verdict to `NextResponse`. No
|
|
17
|
-
* verification logic lives in this file.
|
|
18
|
-
*/
|
|
19
|
-
declare function withCheckpoint(config: CheckpointConfig): (req: NextRequest, event?: NextFetchEvent) => Promise<NextResponse>;
|
|
20
|
-
/**
|
|
21
|
-
* Installed SDK version, self-reported to the detection reporter so the
|
|
22
|
-
* dashboard can version-gate "composed policy enforces here". MUST equal
|
|
23
|
-
* `package.json` version — pinned by a unit test (the old hardcoded `0.1.0` had
|
|
24
|
-
* drifted). Re-exported as `VERSION` from the package index.
|
|
25
|
-
*/
|
|
26
|
-
declare const VERSION = "1.7.1";
|
|
27
|
-
declare function buildReporter(config: CheckpointConfig, runtime?: 'node' | 'edge'): DetectionReporter | null;
|
|
28
|
-
/**
|
|
29
|
-
* Build the per-factory trusted-delegation-roots resolver (P2 / DR-1). Root
|
|
30
|
-
* pinning is a security concern INDEPENDENT of composed Cedar enforcement, so it
|
|
31
|
-
* must resolve wherever a `projectId` exists — including Edge setups that never
|
|
32
|
-
* wire `cedarWasmModule` (where `buildComposedContext` returns null). Prefers the
|
|
33
|
-
* composed context's accessor (reuses its cached fetcher / honors an injected
|
|
34
|
-
* enforcer); otherwise falls back to a `projectId`-only policy fetch. Returns
|
|
35
|
-
* `null` when no source is configured (no roots → engine open default).
|
|
36
|
-
*/
|
|
37
|
-
declare function buildTrustedRootsResolver(config: CheckpointConfig, composed: ComposedPolicyContext | null): TrustedDelegationRootsResolver | null;
|
|
38
|
-
/**
|
|
39
|
-
* Pull the request context the dashboard's `/api/v1/log-detection`
|
|
40
|
-
* endpoint expects out of a `NextRequest`. Works under both Node and
|
|
41
|
-
* Edge runtimes — no runtime-specific APIs.
|
|
42
|
-
*/
|
|
43
|
-
declare function extractReporterContext(req: NextRequest): ReporterContext;
|
|
44
|
-
/**
|
|
45
|
-
* Compose adapter defaults with caller-supplied overrides. Factored
|
|
46
|
-
* out so the Edge entry (which uses the same composition) can reuse
|
|
47
|
-
* the shape.
|
|
48
|
-
*/
|
|
49
|
-
declare function buildVerifyOpts(config: CheckpointConfig): {
|
|
50
|
-
didResolver: _kya_os_checkpoint_wasm_runtime_adapters.DidResolverAdapter;
|
|
51
|
-
statusListCache: _kya_os_checkpoint_wasm_runtime_adapters.StatusListCacheAdapter;
|
|
52
|
-
reputationOracle: _kya_os_checkpoint_wasm_runtime_adapters.ReputationOracleAdapter;
|
|
53
|
-
policyEvaluator: _kya_os_checkpoint_wasm_runtime_adapters.PolicyEvaluatorAdapter;
|
|
54
|
-
clock: _kya_os_checkpoint_wasm_runtime_adapters.ClockAdapter;
|
|
55
|
-
tenantHost: string;
|
|
56
|
-
enforcementMode: _kya_os_checkpoint_wasm_runtime_engine.EnforcementMode;
|
|
57
|
-
reputationBaseline: number | undefined;
|
|
58
|
-
argusUrl: string | undefined;
|
|
59
|
-
legacyEnvelopeFallback: boolean;
|
|
60
|
-
engineConfig: _kya_os_checkpoint_wasm_runtime_engine.EngineConfig | undefined;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export { CheckpointConfig, VERSION, buildReporter as _buildReporter, buildTrustedRootsResolver as _buildTrustedRootsResolver, buildVerifyOpts as _buildVerifyOpts, extractReporterContext as _extractReporterContext, withCheckpoint };
|
|
1
|
+
import { t as CheckpointConfig } from "./config-CbAg2mze.js";
|
|
2
|
+
import { n as VERSION, t as withCheckpoint } from "./middleware-node-CE4GevYs.js";
|
|
3
|
+
export { type CheckpointConfig, VERSION, withCheckpoint };
|