@kya-os/checkpoint-nextjs 1.10.0 → 1.11.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 +245 -0
- package/README.md +205 -31
- package/dist/{adapt.mjs → adapt-BdQ9R7Iw.mjs} +15 -4
- package/dist/adapt-BdQ9R7Iw.mjs.map +1 -0
- package/dist/{adapt.js → adapt-CCSKGjVH.js} +34 -13
- package/dist/api-client-JHOrRUA_.d.mts +222 -0
- package/dist/api-client-JHOrRUA_.d.mts.map +1 -0
- package/dist/api-client-JHOrRUA_.d.ts +222 -0
- package/dist/api-client-JHOrRUA_.d.ts.map +1 -0
- package/dist/api-client.d.mts +2 -204
- package/dist/api-client.d.ts +2 -204
- package/dist/api-client.js +19 -18
- package/dist/api-client.mjs +20 -16
- package/dist/api-client.mjs.map +1 -1
- package/dist/api-middleware-BWjokNis.d.mts +131 -0
- package/dist/api-middleware-BWjokNis.d.mts.map +1 -0
- package/dist/{api-middleware-CDSh3TSE.js → api-middleware-Bf3xmM9W.js} +75 -63
- package/dist/{api-middleware-CMDRoQik.mjs → api-middleware-C-ngFX_8.mjs} +68 -38
- package/dist/api-middleware-C-ngFX_8.mjs.map +1 -0
- package/dist/api-middleware-DyLDqOYF.d.ts +131 -0
- package/dist/api-middleware-DyLDqOYF.d.ts.map +1 -0
- package/dist/api-middleware.d.mts +2 -152
- package/dist/api-middleware.d.ts +2 -152
- package/dist/api-middleware.js +1 -5
- package/dist/api-middleware.mjs +2 -3
- package/dist/cedar-wasm.d.mts +20 -0
- package/dist/cedar-wasm.d.mts.map +1 -0
- package/dist/cedar-wasm.d.ts +19 -0
- package/dist/cedar-wasm.d.ts.map +1 -0
- package/dist/cedar-wasm.js +24 -0
- package/dist/cedar-wasm.mjs +23 -0
- package/dist/cedar-wasm.mjs.map +1 -0
- package/dist/{config-Doe0Tn53.d.mts → config-CPP1RV0f.d.mts} +65 -29
- package/dist/config-CPP1RV0f.d.mts.map +1 -0
- package/dist/{config-CbAg2mze.d.ts → config-DVgOFxJs.d.ts} +66 -30
- package/dist/config-DVgOFxJs.d.ts.map +1 -0
- package/dist/engine-wasm.d.mts +20 -0
- package/dist/engine-wasm.d.mts.map +1 -0
- package/dist/engine-wasm.d.ts +19 -0
- package/dist/engine-wasm.d.ts.map +1 -0
- package/dist/engine-wasm.js +24 -0
- package/dist/engine-wasm.mjs +23 -0
- package/dist/engine-wasm.mjs.map +1 -0
- package/dist/index-edge.d.mts +8 -0
- package/dist/index-edge.d.ts +8 -0
- package/dist/index-edge.js +14 -0
- package/dist/index-edge.mjs +7 -0
- package/dist/index.d.mts +8 -10
- package/dist/index.d.ts +8 -10
- package/dist/index.js +20 -49
- package/dist/index.mjs +21 -8
- package/dist/index.mjs.map +1 -1
- package/dist/middleware-bundler.d.mts +1 -1
- package/dist/middleware-bundler.d.mts.map +1 -1
- package/dist/middleware-bundler.d.ts +1 -1
- package/dist/middleware-bundler.d.ts.map +1 -1
- package/dist/middleware-bundler.js +4 -4
- package/dist/middleware-bundler.mjs +4 -4
- package/dist/middleware-bundler.mjs.map +1 -1
- package/dist/middleware-core-B0jf5_Hm.mjs +264 -0
- package/dist/middleware-core-B0jf5_Hm.mjs.map +1 -0
- package/dist/middleware-core-Bol44X9C.d.ts +17 -0
- package/dist/middleware-core-Bol44X9C.d.ts.map +1 -0
- package/dist/middleware-core-CMc-2QkU.js +274 -0
- package/dist/middleware-core-DycsbHUd.d.mts +17 -0
- package/dist/middleware-core-DycsbHUd.d.mts.map +1 -0
- package/dist/middleware-edge.d.mts +11 -3
- package/dist/middleware-edge.d.mts.map +1 -1
- package/dist/middleware-edge.d.ts +11 -3
- package/dist/middleware-edge.d.ts.map +1 -1
- package/dist/middleware-edge.js +77 -24
- package/dist/middleware-edge.mjs +74 -23
- package/dist/middleware-edge.mjs.map +1 -1
- package/dist/{middleware-node-context-rgnc7UNR.js → middleware-node-context-591KsiYg.js} +8 -7
- package/dist/{middleware-node-context-BqPbf-fI.mjs → middleware-node-context-D_ZyUEcA.mjs} +6 -5
- package/dist/middleware-node-context-D_ZyUEcA.mjs.map +1 -0
- package/dist/middleware-node.d.mts +12 -3
- package/dist/middleware-node.d.mts.map +1 -0
- package/dist/middleware-node.d.ts +12 -3
- package/dist/middleware-node.d.ts.map +1 -0
- package/dist/middleware-node.js +13 -5
- package/dist/middleware-node.mjs +13 -5
- package/dist/middleware-node.mjs.map +1 -1
- package/dist/posture-outcome-Ccujx_9V.d.mts +14 -0
- package/dist/posture-outcome-Ccujx_9V.d.mts.map +1 -0
- package/dist/posture-outcome-Ccujx_9V.d.ts +14 -0
- package/dist/posture-outcome-Ccujx_9V.d.ts.map +1 -0
- package/dist/posture-outcome-DQ4fdMfq.mjs +21 -0
- package/dist/posture-outcome-DQ4fdMfq.mjs.map +1 -0
- package/dist/posture-outcome-DddsJtL8.js +25 -0
- package/dist/public-api-CYsHrTQI.d.ts +5 -0
- package/dist/public-api-DkG7pRE0.d.mts +5 -0
- package/dist/rolldown-runtime-C24Yb2bl.js +33 -0
- package/dist/utils-Cnwg0VrY.mjs +88 -0
- package/dist/utils-Cnwg0VrY.mjs.map +1 -0
- package/dist/utils-dyFxqlFI.js +104 -0
- package/package.json +27 -62
- package/EDGE_RUNTIME_WASM_SETUP.md +0 -342
- package/bin/setup-edge-wasm.js +0 -513
- package/dist/adapt.d.mts +0 -11
- package/dist/adapt.d.mts.map +0 -1
- package/dist/adapt.d.ts +0 -11
- package/dist/adapt.d.ts.map +0 -1
- package/dist/adapt.mjs.map +0 -1
- package/dist/api-client.d.mts.map +0 -1
- package/dist/api-client.d.ts.map +0 -1
- package/dist/api-middleware-CMDRoQik.mjs.map +0 -1
- package/dist/api-middleware.d.mts.map +0 -1
- package/dist/api-middleware.d.ts.map +0 -1
- package/dist/composed-policy-BCaNiVHv.d.mts +0 -98
- package/dist/composed-policy-BCaNiVHv.d.mts.map +0 -1
- package/dist/composed-policy-zzJYNFTb.d.ts +0 -98
- package/dist/composed-policy-zzJYNFTb.d.ts.map +0 -1
- package/dist/composed-policy.d.mts +0 -2
- package/dist/composed-policy.d.ts +0 -2
- package/dist/composed-policy.js +0 -136
- package/dist/composed-policy.mjs +0 -132
- package/dist/composed-policy.mjs.map +0 -1
- package/dist/config-CbAg2mze.d.ts.map +0 -1
- package/dist/config-Doe0Tn53.d.mts.map +0 -1
- package/dist/create-middleware.d.mts +0 -11
- package/dist/create-middleware.d.mts.map +0 -1
- package/dist/create-middleware.d.ts +0 -11
- package/dist/create-middleware.d.ts.map +0 -1
- package/dist/create-middleware.js +0 -39
- package/dist/create-middleware.mjs +0 -38
- package/dist/create-middleware.mjs.map +0 -1
- package/dist/edge/index.d.mts +0 -88
- package/dist/edge/index.d.mts.map +0 -1
- package/dist/edge/index.d.ts +0 -88
- package/dist/edge/index.d.ts.map +0 -1
- package/dist/edge/index.js +0 -362
- package/dist/edge/index.mjs +0 -362
- package/dist/edge/index.mjs.map +0 -1
- package/dist/edge-runtime-loader.d.mts +0 -49
- package/dist/edge-runtime-loader.d.mts.map +0 -1
- package/dist/edge-runtime-loader.d.ts +0 -49
- package/dist/edge-runtime-loader.d.ts.map +0 -1
- package/dist/edge-runtime-loader.js +0 -297
- package/dist/edge-runtime-loader.mjs +0 -292
- package/dist/edge-runtime-loader.mjs.map +0 -1
- package/dist/edge-wasm-middleware.d.mts +0 -43
- package/dist/edge-wasm-middleware.d.mts.map +0 -1
- package/dist/edge-wasm-middleware.d.ts +0 -43
- package/dist/edge-wasm-middleware.d.ts.map +0 -1
- package/dist/edge-wasm-middleware.js +0 -37
- package/dist/edge-wasm-middleware.mjs +0 -35
- package/dist/edge-wasm-middleware.mjs.map +0 -1
- package/dist/middleware-core-BYQP9FND.mjs +0 -165
- package/dist/middleware-core-BYQP9FND.mjs.map +0 -1
- package/dist/middleware-core-D6TijE6P.js +0 -175
- package/dist/middleware-node-CE4GevYs.d.ts +0 -20
- package/dist/middleware-node-CE4GevYs.d.ts.map +0 -1
- package/dist/middleware-node-DtyOuPta.d.mts +0 -20
- package/dist/middleware-node-DtyOuPta.d.mts.map +0 -1
- package/dist/middleware-node-context-BqPbf-fI.mjs.map +0 -1
- package/dist/middleware.d.mts +0 -25
- package/dist/middleware.d.mts.map +0 -1
- package/dist/middleware.d.ts +0 -25
- package/dist/middleware.d.ts.map +0 -1
- package/dist/middleware.js +0 -53
- package/dist/middleware.mjs +0 -51
- package/dist/middleware.mjs.map +0 -1
- package/dist/nodejs-wasm-loader.d.mts +0 -42
- package/dist/nodejs-wasm-loader.d.mts.map +0 -1
- package/dist/nodejs-wasm-loader.d.ts +0 -42
- package/dist/nodejs-wasm-loader.d.ts.map +0 -1
- package/dist/nodejs-wasm-loader.js +0 -70
- package/dist/nodejs-wasm-loader.mjs +0 -66
- package/dist/nodejs-wasm-loader.mjs.map +0 -1
- package/dist/policy.d.mts +0 -138
- package/dist/policy.d.mts.map +0 -1
- package/dist/policy.d.ts +0 -138
- package/dist/policy.d.ts.map +0 -1
- package/dist/policy.js +0 -236
- package/dist/policy.mjs +0 -205
- package/dist/policy.mjs.map +0 -1
- package/dist/session-tracker.d.mts +0 -50
- package/dist/session-tracker.d.mts.map +0 -1
- package/dist/session-tracker.d.ts +0 -50
- package/dist/session-tracker.d.ts.map +0 -1
- package/dist/session-tracker.js +0 -148
- package/dist/session-tracker.mjs +0 -147
- package/dist/session-tracker.mjs.map +0 -1
- package/dist/translate.d.mts +0 -48
- package/dist/translate.d.mts.map +0 -1
- package/dist/translate.d.ts +0 -48
- package/dist/translate.d.ts.map +0 -1
- package/dist/translate.js +0 -79
- package/dist/translate.mjs +0 -79
- package/dist/translate.mjs.map +0 -1
- package/dist/types-C0SkqLMM.d.mts +0 -102
- package/dist/types-C0SkqLMM.d.mts.map +0 -1
- package/dist/types-C7DNSCTO.d.ts +0 -102
- package/dist/types-C7DNSCTO.d.ts.map +0 -1
- package/dist/utils-Cj4XNhIY.mjs +0 -35
- package/dist/utils-Cj4XNhIY.mjs.map +0 -1
- package/dist/utils-DAisnYnI.js +0 -45
- package/dist/wasm-setup.d.mts +0 -47
- package/dist/wasm-setup.d.mts.map +0 -1
- package/dist/wasm-setup.d.ts +0 -47
- package/dist/wasm-setup.d.ts.map +0 -1
- package/dist/wasm-setup.js +0 -91
- package/dist/wasm-setup.mjs +0 -95
- package/dist/wasm-setup.mjs.map +0 -1
- package/wasm/agentshield_wasm.d.ts +0 -479
- package/wasm/agentshield_wasm.js +0 -1536
- package/wasm/agentshield_wasm_bg.wasm +0 -0
- package/wasm/package.json +0 -30
- package/wasm.d.ts +0 -21
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
let
|
|
1
|
+
let _kya_os_checkpoint_wasm_runtime_composed_policy = require("@kya-os/checkpoint-wasm-runtime/composed-policy");
|
|
2
|
+
let _kya_os_checkpoint_shared_policy_fetcher = require("@kya-os/checkpoint-shared/policy/fetcher");
|
|
3
3
|
|
|
4
4
|
//#region src/middleware-node-context.ts
|
|
5
5
|
/**
|
|
@@ -14,18 +14,19 @@ let _kya_os_checkpoint_shared = require("@kya-os/checkpoint-shared");
|
|
|
14
14
|
function buildComposedContext(config) {
|
|
15
15
|
if (config.composedPolicyEnforcer) return config.composedPolicyEnforcer;
|
|
16
16
|
if (!config.projectId) return null;
|
|
17
|
-
return
|
|
17
|
+
return (0, _kya_os_checkpoint_wasm_runtime_composed_policy.makeComposedPolicyContext)({
|
|
18
18
|
projectId: config.projectId,
|
|
19
|
-
fetcher: new
|
|
20
|
-
apiBaseUrl: config.dashboardUrl ?? config.baseUrl ??
|
|
19
|
+
fetcher: new _kya_os_checkpoint_shared_policy_fetcher.PolicyFetcher({
|
|
20
|
+
apiBaseUrl: config.dashboardUrl ?? config.baseUrl ?? _kya_os_checkpoint_wasm_runtime_composed_policy.DEFAULT_DASHBOARD_URL,
|
|
21
21
|
apiKey: config.apiKey,
|
|
22
|
-
cacheTtlSeconds: config.policyCacheTtlSeconds
|
|
22
|
+
cacheTtlSeconds: config.policyCacheTtlSeconds,
|
|
23
|
+
throwOnUnavailable: true
|
|
23
24
|
}),
|
|
24
25
|
compile: async (_language, source) => {
|
|
25
26
|
const { createPolicyEvaluator } = await import("@kya-os/checkpoint-wasm-runtime/policy");
|
|
26
27
|
return createPolicyEvaluator(source);
|
|
27
28
|
},
|
|
28
|
-
logger: config.debug ?
|
|
29
|
+
logger: config.debug ? _kya_os_checkpoint_wasm_runtime_composed_policy.consoleComposedPolicyLogger : void 0
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DEFAULT_DASHBOARD_URL, consoleComposedPolicyLogger, makeComposedPolicyContext } from "
|
|
2
|
-
import { PolicyFetcher } from "@kya-os/checkpoint-shared";
|
|
1
|
+
import { DEFAULT_DASHBOARD_URL, consoleComposedPolicyLogger, makeComposedPolicyContext } from "@kya-os/checkpoint-wasm-runtime/composed-policy";
|
|
2
|
+
import { PolicyFetcher } from "@kya-os/checkpoint-shared/policy/fetcher";
|
|
3
3
|
|
|
4
4
|
//#region src/middleware-node-context.ts
|
|
5
5
|
/**
|
|
@@ -17,9 +17,10 @@ function buildComposedContext(config) {
|
|
|
17
17
|
return makeComposedPolicyContext({
|
|
18
18
|
projectId: config.projectId,
|
|
19
19
|
fetcher: new PolicyFetcher({
|
|
20
|
-
apiBaseUrl: config.dashboardUrl ?? config.baseUrl ??
|
|
20
|
+
apiBaseUrl: config.dashboardUrl ?? config.baseUrl ?? DEFAULT_DASHBOARD_URL,
|
|
21
21
|
apiKey: config.apiKey,
|
|
22
|
-
cacheTtlSeconds: config.policyCacheTtlSeconds
|
|
22
|
+
cacheTtlSeconds: config.policyCacheTtlSeconds,
|
|
23
|
+
throwOnUnavailable: true
|
|
23
24
|
}),
|
|
24
25
|
compile: async (_language, source) => {
|
|
25
26
|
const { createPolicyEvaluator } = await import("@kya-os/checkpoint-wasm-runtime/policy");
|
|
@@ -31,4 +32,4 @@ function buildComposedContext(config) {
|
|
|
31
32
|
|
|
32
33
|
//#endregion
|
|
33
34
|
export { buildComposedContext as t };
|
|
34
|
-
//# sourceMappingURL=middleware-node-context-
|
|
35
|
+
//# sourceMappingURL=middleware-node-context-D_ZyUEcA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-node-context-D_ZyUEcA.mjs","names":[],"sources":["../src/middleware-node-context.ts"],"sourcesContent":["import { PolicyFetcher } from '@kya-os/checkpoint-shared/policy/fetcher';\nimport type { CheckpointConfig } from './config';\nimport {\n makeComposedPolicyContext,\n consoleComposedPolicyLogger,\n DEFAULT_DASHBOARD_URL,\n type ComposedPolicyContext,\n} from '@kya-os/checkpoint-wasm-runtime/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 throwOnUnavailable: true,\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,WAAW;GACrD,QAAQ,OAAO;GACf,iBAAiB,OAAO;GACxB,oBAAoB;EACtB,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"}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
import { t as CheckpointConfig } from "./config-
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { t as CheckpointConfig } from "./config-CPP1RV0f.mjs";
|
|
2
|
+
import { t as VERSION } from "./middleware-core-DycsbHUd.mjs";
|
|
3
|
+
//#region src/middleware-node.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* `withCheckpoint` on the Node.js runtime, bundled (`proxy.ts`, `middleware.ts`)
|
|
6
|
+
* or not. The engine's Node build loads its `.wasm` through `new URL(...,
|
|
7
|
+
* import.meta.url)`, which bundlers follow and copy.
|
|
8
|
+
*/
|
|
9
|
+
export declare function withCheckpoint(config: CheckpointConfig): (req: import("next/server").NextRequest, event?: Pick<import("next/server").NextFetchEvent, "waitUntil">) => Promise<import("next/server").NextResponse>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { type CheckpointConfig, VERSION };
|
|
12
|
+
//# sourceMappingURL=middleware-node.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-node.d.mts","names":[],"sources":["../src/middleware-node.ts"],"mappings":";;;;;;;;wBAUgB,eAAe,QAAQ,oBAAgB,2BAAA,aAAA,QAAA,2BAAA,iCAAA,8BAAA"}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
import { t as CheckpointConfig } from "./config-
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { t as CheckpointConfig } from "./config-DVgOFxJs.js";
|
|
2
|
+
import { t as VERSION } from "./middleware-core-Bol44X9C.js";
|
|
3
|
+
//#region src/middleware-node.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* `withCheckpoint` on the Node.js runtime, bundled (`proxy.ts`, `middleware.ts`)
|
|
6
|
+
* or not. The engine's Node build loads its `.wasm` through `new URL(...,
|
|
7
|
+
* import.meta.url)`, which bundlers follow and copy.
|
|
8
|
+
*/
|
|
9
|
+
export declare function withCheckpoint(config: CheckpointConfig): (req: import("next/server").NextRequest, event?: Pick<import("next/server").NextFetchEvent, "waitUntil">) => Promise<import("next/server").NextResponse>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { type CheckpointConfig, VERSION };
|
|
12
|
+
//# sourceMappingURL=middleware-node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-node.d.ts","names":[],"sources":["../src/middleware-node.ts"],"mappings":";;;;;;;;wBAUgB,eAAe,QAAQ,oBAAgB,2BAAA,aAAA,QAAA,2BAAA,iCAAA,8BAAA"}
|
package/dist/middleware-node.js
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_middleware_core = require('./middleware-core-
|
|
3
|
-
const require_middleware_node_context = require('./middleware-node-context-
|
|
4
|
-
let _kya_os_checkpoint_wasm_runtime_orchestrator = require("@kya-os/checkpoint-wasm-runtime/orchestrator");
|
|
2
|
+
const require_middleware_core = require('./middleware-core-CMc-2QkU.js');
|
|
3
|
+
const require_middleware_node_context = require('./middleware-node-context-591KsiYg.js');
|
|
5
4
|
|
|
6
5
|
//#region src/middleware-node.ts
|
|
7
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* `withCheckpoint` on the Node.js runtime, bundled (`proxy.ts`, `middleware.ts`)
|
|
8
|
+
* or not. The engine's Node build loads its `.wasm` through `new URL(...,
|
|
9
|
+
* import.meta.url)`, which bundlers follow and copy.
|
|
10
|
+
*/
|
|
8
11
|
function withCheckpoint(config) {
|
|
9
|
-
return require_middleware_core.makeNextMiddleware(
|
|
12
|
+
return require_middleware_core.makeNextMiddleware(config, {
|
|
10
13
|
runtime: "node",
|
|
14
|
+
loadEngine: async () => {
|
|
15
|
+
const orchestrator = await import("@kya-os/checkpoint-wasm-runtime/orchestrator/node");
|
|
16
|
+
await orchestrator.initEngine();
|
|
17
|
+
return orchestrator;
|
|
18
|
+
},
|
|
11
19
|
buildComposedContext: require_middleware_node_context.buildComposedContext
|
|
12
20
|
});
|
|
13
21
|
}
|
package/dist/middleware-node.mjs
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import { n as makeNextMiddleware, t as VERSION } from "./middleware-core-
|
|
2
|
-
import { t as buildComposedContext } from "./middleware-node-context-
|
|
3
|
-
import { renderDecisionAsResponse, verifyRequest } from "@kya-os/checkpoint-wasm-runtime/orchestrator";
|
|
1
|
+
import { n as makeNextMiddleware, t as VERSION } from "./middleware-core-B0jf5_Hm.mjs";
|
|
2
|
+
import { t as buildComposedContext } from "./middleware-node-context-D_ZyUEcA.mjs";
|
|
4
3
|
|
|
5
4
|
//#region src/middleware-node.ts
|
|
6
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* `withCheckpoint` on the Node.js runtime, bundled (`proxy.ts`, `middleware.ts`)
|
|
7
|
+
* or not. The engine's Node build loads its `.wasm` through `new URL(...,
|
|
8
|
+
* import.meta.url)`, which bundlers follow and copy.
|
|
9
|
+
*/
|
|
7
10
|
function withCheckpoint(config) {
|
|
8
|
-
return makeNextMiddleware(
|
|
11
|
+
return makeNextMiddleware(config, {
|
|
9
12
|
runtime: "node",
|
|
13
|
+
loadEngine: async () => {
|
|
14
|
+
const orchestrator = await import("@kya-os/checkpoint-wasm-runtime/orchestrator/node");
|
|
15
|
+
await orchestrator.initEngine();
|
|
16
|
+
return orchestrator;
|
|
17
|
+
},
|
|
10
18
|
buildComposedContext
|
|
11
19
|
});
|
|
12
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware-node.mjs","names":[],"sources":["../src/middleware-node.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"middleware-node.mjs","names":[],"sources":["../src/middleware-node.ts"],"sourcesContent":["import { makeNextMiddleware } from './middleware-core';\nimport { buildComposedContext } from './middleware-node-context';\nimport type { CheckpointConfig } from './config';\nexport type { CheckpointConfig } from './config';\n\n/**\n * `withCheckpoint` on the Node.js runtime, bundled (`proxy.ts`, `middleware.ts`)\n * or not. The engine's Node build loads its `.wasm` through `new URL(...,\n * import.meta.url)`, which bundlers follow and copy.\n */\nexport function withCheckpoint(config: CheckpointConfig) {\n return makeNextMiddleware(config, {\n runtime: 'node',\n // Pinned to the Node build whatever conditions a bundler resolves with.\n // Importing it does not read the `.wasm`; `initEngine` does, so a missing\n // or unreadable engine fails here, where it is logged and answered 503,\n // and the next request retries, instead of failing this module.\n loadEngine: async () => {\n const orchestrator = await import('@kya-os/checkpoint-wasm-runtime/orchestrator/node');\n await orchestrator.initEngine();\n return orchestrator;\n },\n buildComposedContext,\n });\n}\n\nexport { VERSION } from './middleware-core';\n"],"mappings":";;;;;;;;;AAUA,SAAgB,eAAe,QAA0B;CACvD,OAAO,mBAAmB,QAAQ;EAChC,SAAS;EAKT,YAAY,YAAY;GACtB,MAAM,eAAe,MAAM,OAAO;GAClC,MAAM,aAAa,WAAW;GAC9B,OAAO;EACT;EACA;CACF,CAAC;AACH"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BrowserPostureConfig } from "@kya-os/checkpoint-shared/browser-posture";
|
|
2
|
+
import { PostureHandlerView } from "@kya-os/checkpoint-wasm-runtime/composed-policy";
|
|
3
|
+
//#region src/posture-outcome.d.ts
|
|
4
|
+
type CheckpointPostureOutcome = PostureHandlerView;
|
|
5
|
+
interface CheckpointPostureOptions {
|
|
6
|
+
browserPosture: BrowserPostureConfig;
|
|
7
|
+
projectId: string;
|
|
8
|
+
}
|
|
9
|
+
declare function getCheckpointPostureOutcome(input: Request | Headers | {
|
|
10
|
+
headers: Headers;
|
|
11
|
+
}, options: CheckpointPostureOptions): Promise<CheckpointPostureOutcome>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { CheckpointPostureOutcome as n, getCheckpointPostureOutcome as r, CheckpointPostureOptions as t };
|
|
14
|
+
//# sourceMappingURL=posture-outcome-Ccujx_9V.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posture-outcome-Ccujx_9V.d.mts","names":[],"sources":["../src/posture-outcome.ts"],"mappings":";;;KAWY,2BAA2B;UAEtB;EACf,gBAAgB;EAChB;;iBASoB,4BACpB,OAAO,UAAU;EAAY,SAAS;GACtC,SAAS,2BACR,QAAQ"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BrowserPostureConfig } from "@kya-os/checkpoint-shared/browser-posture";
|
|
2
|
+
import { PostureHandlerView } from "@kya-os/checkpoint-wasm-runtime/composed-policy";
|
|
3
|
+
//#region src/posture-outcome.d.ts
|
|
4
|
+
type CheckpointPostureOutcome = PostureHandlerView;
|
|
5
|
+
interface CheckpointPostureOptions {
|
|
6
|
+
browserPosture: BrowserPostureConfig;
|
|
7
|
+
projectId: string;
|
|
8
|
+
}
|
|
9
|
+
declare function getCheckpointPostureOutcome(input: Request | Headers | {
|
|
10
|
+
headers: Headers;
|
|
11
|
+
}, options: CheckpointPostureOptions): Promise<CheckpointPostureOutcome>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { CheckpointPostureOutcome as n, getCheckpointPostureOutcome as r, CheckpointPostureOptions as t };
|
|
14
|
+
//# sourceMappingURL=posture-outcome-Ccujx_9V.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posture-outcome-Ccujx_9V.d.ts","names":[],"sources":["../src/posture-outcome.ts"],"mappings":";;;KAWY,2BAA2B;UAEtB;EACf,gBAAgB;EAChB;;iBASoB,4BACpB,OAAO,UAAU;EAAY,SAAS;GACtC,SAAS,2BACR,QAAQ"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { postureOutcomeFromRequest, postureRequestFromHeaders, validateBrowserPostureConfig } from "@kya-os/checkpoint-shared/browser-posture";
|
|
2
|
+
import { postureOutcomeView } from "@kya-os/checkpoint-wasm-runtime/composed-policy";
|
|
3
|
+
|
|
4
|
+
//#region src/posture-outcome.ts
|
|
5
|
+
function hasGet(input) {
|
|
6
|
+
return typeof input.get === "function";
|
|
7
|
+
}
|
|
8
|
+
const validatedProjects = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
async function getCheckpointPostureOutcome(input, options) {
|
|
10
|
+
if (!options.browserPosture) throw new Error("getCheckpointPostureOutcome requires the browserPosture config");
|
|
11
|
+
if (validatedProjects.get(options.browserPosture) !== options.projectId) {
|
|
12
|
+
validateBrowserPostureConfig(options.browserPosture, options.projectId);
|
|
13
|
+
validatedProjects.set(options.browserPosture, options.projectId);
|
|
14
|
+
}
|
|
15
|
+
const headers = hasGet(input) ? input : input.headers;
|
|
16
|
+
return postureOutcomeView(await postureOutcomeFromRequest(postureRequestFromHeaders((name) => headers.get(name)), options.browserPosture, options.projectId));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { getCheckpointPostureOutcome as t };
|
|
21
|
+
//# sourceMappingURL=posture-outcome-DQ4fdMfq.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posture-outcome-DQ4fdMfq.mjs","names":[],"sources":["../src/posture-outcome.ts"],"sourcesContent":["import {\n postureOutcomeFromRequest,\n postureRequestFromHeaders,\n validateBrowserPostureConfig,\n type BrowserPostureConfig,\n} from '@kya-os/checkpoint-shared/browser-posture';\nimport {\n postureOutcomeView,\n type PostureHandlerView,\n} from '@kya-os/checkpoint-wasm-runtime/composed-policy';\n\nexport type CheckpointPostureOutcome = PostureHandlerView;\n\nexport interface CheckpointPostureOptions {\n browserPosture: BrowserPostureConfig;\n projectId: string;\n}\n\nfunction hasGet(input: Request | Headers | { headers: Headers }): input is Headers {\n return typeof (input as Headers).get === 'function';\n}\n\nconst validatedProjects = new WeakMap<BrowserPostureConfig, string>();\n\nexport async function getCheckpointPostureOutcome(\n input: Request | Headers | { headers: Headers },\n options: CheckpointPostureOptions\n): Promise<CheckpointPostureOutcome> {\n if (!options.browserPosture) {\n throw new Error('getCheckpointPostureOutcome requires the browserPosture config');\n }\n if (validatedProjects.get(options.browserPosture) !== options.projectId) {\n validateBrowserPostureConfig(options.browserPosture, options.projectId);\n validatedProjects.set(options.browserPosture, options.projectId);\n }\n const headers = hasGet(input) ? input : input.headers;\n return postureOutcomeView(\n await postureOutcomeFromRequest(\n postureRequestFromHeaders((name) => headers.get(name)),\n options.browserPosture,\n options.projectId\n )\n );\n}\n"],"mappings":";;;;AAkBA,SAAS,OAAO,OAAmE;CACjF,OAAO,OAAQ,MAAkB,QAAQ;AAC3C;AAEA,MAAM,oCAAoB,IAAI,QAAsC;AAEpE,eAAsB,4BACpB,OACA,SACmC;CACnC,IAAI,CAAC,QAAQ,gBACX,MAAM,IAAI,MAAM,gEAAgE;CAElF,IAAI,kBAAkB,IAAI,QAAQ,cAAc,MAAM,QAAQ,WAAW;EACvE,6BAA6B,QAAQ,gBAAgB,QAAQ,SAAS;EACtE,kBAAkB,IAAI,QAAQ,gBAAgB,QAAQ,SAAS;CACjE;CACA,MAAM,UAAU,OAAO,KAAK,IAAI,QAAQ,MAAM;CAC9C,OAAO,mBACL,MAAM,0BACJ,2BAA2B,SAAS,QAAQ,IAAI,IAAI,CAAC,GACrD,QAAQ,gBACR,QAAQ,SACV,CACF;AACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
let _kya_os_checkpoint_shared_browser_posture = require("@kya-os/checkpoint-shared/browser-posture");
|
|
2
|
+
let _kya_os_checkpoint_wasm_runtime_composed_policy = require("@kya-os/checkpoint-wasm-runtime/composed-policy");
|
|
3
|
+
|
|
4
|
+
//#region src/posture-outcome.ts
|
|
5
|
+
function hasGet(input) {
|
|
6
|
+
return typeof input.get === "function";
|
|
7
|
+
}
|
|
8
|
+
const validatedProjects = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
async function getCheckpointPostureOutcome(input, options) {
|
|
10
|
+
if (!options.browserPosture) throw new Error("getCheckpointPostureOutcome requires the browserPosture config");
|
|
11
|
+
if (validatedProjects.get(options.browserPosture) !== options.projectId) {
|
|
12
|
+
(0, _kya_os_checkpoint_shared_browser_posture.validateBrowserPostureConfig)(options.browserPosture, options.projectId);
|
|
13
|
+
validatedProjects.set(options.browserPosture, options.projectId);
|
|
14
|
+
}
|
|
15
|
+
const headers = hasGet(input) ? input : input.headers;
|
|
16
|
+
return (0, _kya_os_checkpoint_wasm_runtime_composed_policy.postureOutcomeView)(await (0, _kya_os_checkpoint_shared_browser_posture.postureOutcomeFromRequest)((0, _kya_os_checkpoint_shared_browser_posture.postureRequestFromHeaders)((name) => headers.get(name)), options.browserPosture, options.projectId));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
Object.defineProperty(exports, 'getCheckpointPostureOutcome', {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () {
|
|
23
|
+
return getCheckpointPostureOutcome;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
Object.defineProperty(exports, '__toESM', {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return __toESM;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { resolveObservedClientAddress } from "@kya-os/checkpoint-shared/client-ip";
|
|
2
|
+
|
|
3
|
+
//#region src/utils.ts
|
|
4
|
+
/**
|
|
5
|
+
* Extract client IP address from a NextRequest.
|
|
6
|
+
* In Next.js 15+, the `ip` property was removed from NextRequest.
|
|
7
|
+
* Forwarded values require an authenticated deployment boundary. NextRequest
|
|
8
|
+
* exposes no socket peer, so arbitrary proxy profiles remain unavailable.
|
|
9
|
+
*
|
|
10
|
+
* @param request - The NextRequest object
|
|
11
|
+
* @returns The client IP address or undefined if not available
|
|
12
|
+
*/
|
|
13
|
+
function getClientIp(request, policy = { platform: "direct" }) {
|
|
14
|
+
const frameworkAddress = request.ip;
|
|
15
|
+
const onVercel = typeof process !== "undefined" && process.env?.VERCEL === "1";
|
|
16
|
+
const effectivePolicy = policy.platform === "vercel" && !onVercel ? { platform: "direct" } : policy;
|
|
17
|
+
const resolution = resolveObservedClientAddress({
|
|
18
|
+
headers: request.headers,
|
|
19
|
+
frameworkAddress,
|
|
20
|
+
vercelRuntime: onVercel,
|
|
21
|
+
policy: effectivePolicy
|
|
22
|
+
});
|
|
23
|
+
return resolution.trusted ? resolution.ip : void 0;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Safely extract the hostname from a URL string.
|
|
27
|
+
* Returns a friendly fallback when parsing fails so UX copy doesn't leak
|
|
28
|
+
* "undefined" or similar to end users.
|
|
29
|
+
*/
|
|
30
|
+
function safeHostname(url) {
|
|
31
|
+
try {
|
|
32
|
+
return new URL(url).hostname;
|
|
33
|
+
} catch {
|
|
34
|
+
return "this site";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const DROPPED_HEADERS = [
|
|
38
|
+
"cookie",
|
|
39
|
+
"authorization",
|
|
40
|
+
"proxy-authorization",
|
|
41
|
+
"x-api-key",
|
|
42
|
+
"x-vercel-protection-bypass",
|
|
43
|
+
"cf-access-jwt-assertion",
|
|
44
|
+
"cf-access-client-secret"
|
|
45
|
+
];
|
|
46
|
+
const CREDENTIAL_HEADER = /^(?!kya-|x-bot-token$)(?:.*-)?(?:authorization|auth|token|secret|password|api-?key|apikey|subscription-key|credential)s?(?:-.*)?$/;
|
|
47
|
+
const BEACON_COOKIE = "_as_beacon_session=";
|
|
48
|
+
const DELEGATION_BEARER = /^bearer\s+[\w-]+\.([\w-]+)\.[\w-]+$/i;
|
|
49
|
+
function isRecord(value) {
|
|
50
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
51
|
+
}
|
|
52
|
+
function hasDelegationType(type) {
|
|
53
|
+
return Array.isArray(type) && type.includes("DelegationCredential");
|
|
54
|
+
}
|
|
55
|
+
function isDelegationBearer(authorization) {
|
|
56
|
+
for (const candidate of (authorization ?? "").split(",")) {
|
|
57
|
+
const match = DELEGATION_BEARER.exec(candidate.trim());
|
|
58
|
+
if (!match) continue;
|
|
59
|
+
if (match[1].length > 16384) return true;
|
|
60
|
+
let claims;
|
|
61
|
+
try {
|
|
62
|
+
claims = JSON.parse(atob(match[1].replace(/-/g, "+").replace(/_/g, "/")));
|
|
63
|
+
} catch {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (!isRecord(claims)) continue;
|
|
67
|
+
if (hasDelegationType(claims.type)) return true;
|
|
68
|
+
const vc = claims.vc;
|
|
69
|
+
if (!isRecord(vc)) continue;
|
|
70
|
+
if (hasDelegationType(vc.type)) return true;
|
|
71
|
+
const subject = vc.credentialSubject;
|
|
72
|
+
if (isRecord(subject) && isRecord(subject.delegation)) return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
function relayHeaders(input) {
|
|
77
|
+
const headers = new Headers(input);
|
|
78
|
+
const relayed = Object.fromEntries([...headers].filter(([name]) => !DROPPED_HEADERS.includes(name) && !CREDENTIAL_HEADER.test(name)));
|
|
79
|
+
const beacon = (headers.get("cookie") ?? "").split(";").map((part) => part.trim()).filter((part) => part.startsWith(BEACON_COOKIE));
|
|
80
|
+
if (beacon.length) relayed.cookie = beacon.join("; ");
|
|
81
|
+
const authorization = headers.get("authorization");
|
|
82
|
+
if (isDelegationBearer(authorization)) relayed.authorization = authorization;
|
|
83
|
+
return relayed;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
export { relayHeaders as n, safeHostname as r, getClientIp as t };
|
|
88
|
+
//# sourceMappingURL=utils-Cnwg0VrY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-Cnwg0VrY.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Utility functions for @kya-os/checkpoint-nextjs\n */\n\nimport type { NextRequest } from 'next/server.js';\nimport {\n resolveObservedClientAddress,\n type ClientIpTrustPolicy,\n} from '@kya-os/checkpoint-shared/client-ip';\n\n/**\n * Extract client IP address from a NextRequest.\n * In Next.js 15+, the `ip` property was removed from NextRequest.\n * Forwarded values require an authenticated deployment boundary. NextRequest\n * exposes no socket peer, so arbitrary proxy profiles remain unavailable.\n *\n * @param request - The NextRequest object\n * @returns The client IP address or undefined if not available\n */\nexport function getClientIp(\n request: NextRequest,\n policy: ClientIpTrustPolicy = { platform: 'direct' }\n): string | undefined {\n const frameworkAddress = (request as unknown as { ip?: string }).ip;\n const onVercel = typeof process !== 'undefined' && process.env?.VERCEL === '1';\n const effectivePolicy: ClientIpTrustPolicy =\n policy.platform === 'vercel' && !onVercel ? { platform: 'direct' } : policy;\n const resolution = resolveObservedClientAddress({\n headers: request.headers,\n frameworkAddress,\n vercelRuntime: onVercel,\n policy: effectivePolicy,\n });\n return resolution.trusted ? resolution.ip : undefined;\n}\n\n/**\n * Safely extract the hostname from a URL string.\n * Returns a friendly fallback when parsing fails so UX copy doesn't leak\n * \"undefined\" or similar to end users.\n */\nexport function safeHostname(url: string): string {\n try {\n return new URL(url).hostname;\n } catch {\n return 'this site';\n }\n}\n\nconst DROPPED_HEADERS = [\n 'cookie',\n 'authorization',\n 'proxy-authorization',\n 'x-api-key',\n 'x-vercel-protection-bypass',\n 'cf-access-jwt-assertion',\n 'cf-access-client-secret',\n];\nconst CREDENTIAL_HEADER =\n /^(?!kya-|x-bot-token$)(?:.*-)?(?:authorization|auth|token|secret|password|api-?key|apikey|subscription-key|credential)s?(?:-.*)?$/;\nconst BEACON_COOKIE = '_as_beacon_session=';\nconst DELEGATION_BEARER = /^bearer\\s+[\\w-]+\\.([\\w-]+)\\.[\\w-]+$/i;\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction hasDelegationType(type: unknown): boolean {\n return Array.isArray(type) && type.includes('DelegationCredential');\n}\n\nfunction isDelegationBearer(authorization: string | null): authorization is string {\n for (const candidate of (authorization ?? '').split(',')) {\n const match = DELEGATION_BEARER.exec(candidate.trim());\n if (!match) continue;\n\n // Match the engine's conservative routing: oversized compact bearers must\n // reach it so it can fail closed without decoding an untrusted payload.\n if (match[1].length > 16 * 1024) return true;\n\n let claims: unknown;\n try {\n claims = JSON.parse(atob(match[1].replace(/-/g, '+').replace(/_/g, '/')));\n } catch {\n continue;\n }\n if (!isRecord(claims)) continue;\n if (hasDelegationType(claims.type)) return true;\n const vc = claims.vc;\n if (!isRecord(vc)) continue;\n if (hasDelegationType(vc.type)) return true;\n const subject = vc.credentialSubject;\n if (isRecord(subject) && isRecord(subject.delegation)) return true;\n }\n return false;\n}\n\nexport function relayHeaders(input: Record<string, string>): Record<string, string> {\n const headers = new Headers(input);\n const relayed = Object.fromEntries(\n [...headers].filter(\n ([name]) => !DROPPED_HEADERS.includes(name) && !CREDENTIAL_HEADER.test(name)\n )\n );\n const beacon = (headers.get('cookie') ?? '')\n .split(';')\n .map((part) => part.trim())\n .filter((part) => part.startsWith(BEACON_COOKIE));\n if (beacon.length) relayed.cookie = beacon.join('; ');\n const authorization = headers.get('authorization');\n if (isDelegationBearer(authorization)) relayed.authorization = authorization;\n return relayed;\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAgB,YACd,SACA,SAA8B,EAAE,UAAU,SAAS,GAC/B;CACpB,MAAM,mBAAoB,QAAuC;CACjE,MAAM,WAAW,OAAO,YAAY,eAAe,QAAQ,KAAK,WAAW;CAC3E,MAAM,kBACJ,OAAO,aAAa,YAAY,CAAC,WAAW,EAAE,UAAU,SAAS,IAAI;CACvE,MAAM,aAAa,6BAA6B;EAC9C,SAAS,QAAQ;EACjB;EACA,eAAe;EACf,QAAQ;CACV,CAAC;CACD,OAAO,WAAW,UAAU,WAAW,KAAK;AAC9C;;;;;;AAOA,SAAgB,aAAa,KAAqB;CAChD,IAAI;EACF,OAAO,IAAI,IAAI,GAAG,CAAC,CAAC;CACtB,QAAQ;EACN,OAAO;CACT;AACF;AAEA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,MAAM,oBACJ;AACF,MAAM,gBAAgB;AACtB,MAAM,oBAAoB;AAE1B,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,kBAAkB,MAAwB;CACjD,OAAO,MAAM,QAAQ,IAAI,KAAK,KAAK,SAAS,sBAAsB;AACpE;AAEA,SAAS,mBAAmB,eAAuD;CACjF,KAAK,MAAM,cAAc,iBAAiB,GAAE,CAAE,MAAM,GAAG,GAAG;EACxD,MAAM,QAAQ,kBAAkB,KAAK,UAAU,KAAK,CAAC;EACrD,IAAI,CAAC,OAAO;EAIZ,IAAI,MAAM,EAAE,CAAC,SAAS,OAAW,OAAO;EAExC,IAAI;EACJ,IAAI;GACF,SAAS,KAAK,MAAM,KAAK,MAAM,EAAE,CAAC,QAAQ,MAAM,GAAG,CAAC,CAAC,QAAQ,MAAM,GAAG,CAAC,CAAC;EAC1E,QAAQ;GACN;EACF;EACA,IAAI,CAAC,SAAS,MAAM,GAAG;EACvB,IAAI,kBAAkB,OAAO,IAAI,GAAG,OAAO;EAC3C,MAAM,KAAK,OAAO;EAClB,IAAI,CAAC,SAAS,EAAE,GAAG;EACnB,IAAI,kBAAkB,GAAG,IAAI,GAAG,OAAO;EACvC,MAAM,UAAU,GAAG;EACnB,IAAI,SAAS,OAAO,KAAK,SAAS,QAAQ,UAAU,GAAG,OAAO;CAChE;CACA,OAAO;AACT;AAEA,SAAgB,aAAa,OAAuD;CAClF,MAAM,UAAU,IAAI,QAAQ,KAAK;CACjC,MAAM,UAAU,OAAO,YACrB,CAAC,GAAG,OAAO,CAAC,CAAC,QACV,CAAC,UAAU,CAAC,gBAAgB,SAAS,IAAI,KAAK,CAAC,kBAAkB,KAAK,IAAI,CAC7E,CACF;CACA,MAAM,UAAU,QAAQ,IAAI,QAAQ,KAAK,GAAE,CACxC,MAAM,GAAG,CAAC,CACV,KAAK,SAAS,KAAK,KAAK,CAAC,CAAC,CAC1B,QAAQ,SAAS,KAAK,WAAW,aAAa,CAAC;CAClD,IAAI,OAAO,QAAQ,QAAQ,SAAS,OAAO,KAAK,IAAI;CACpD,MAAM,gBAAgB,QAAQ,IAAI,eAAe;CACjD,IAAI,mBAAmB,aAAa,GAAG,QAAQ,gBAAgB;CAC/D,OAAO;AACT"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
let _kya_os_checkpoint_shared_client_ip = require("@kya-os/checkpoint-shared/client-ip");
|
|
2
|
+
|
|
3
|
+
//#region src/utils.ts
|
|
4
|
+
/**
|
|
5
|
+
* Extract client IP address from a NextRequest.
|
|
6
|
+
* In Next.js 15+, the `ip` property was removed from NextRequest.
|
|
7
|
+
* Forwarded values require an authenticated deployment boundary. NextRequest
|
|
8
|
+
* exposes no socket peer, so arbitrary proxy profiles remain unavailable.
|
|
9
|
+
*
|
|
10
|
+
* @param request - The NextRequest object
|
|
11
|
+
* @returns The client IP address or undefined if not available
|
|
12
|
+
*/
|
|
13
|
+
function getClientIp(request, policy = { platform: "direct" }) {
|
|
14
|
+
const frameworkAddress = request.ip;
|
|
15
|
+
const onVercel = typeof process !== "undefined" && process.env?.VERCEL === "1";
|
|
16
|
+
const effectivePolicy = policy.platform === "vercel" && !onVercel ? { platform: "direct" } : policy;
|
|
17
|
+
const resolution = (0, _kya_os_checkpoint_shared_client_ip.resolveObservedClientAddress)({
|
|
18
|
+
headers: request.headers,
|
|
19
|
+
frameworkAddress,
|
|
20
|
+
vercelRuntime: onVercel,
|
|
21
|
+
policy: effectivePolicy
|
|
22
|
+
});
|
|
23
|
+
return resolution.trusted ? resolution.ip : void 0;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Safely extract the hostname from a URL string.
|
|
27
|
+
* Returns a friendly fallback when parsing fails so UX copy doesn't leak
|
|
28
|
+
* "undefined" or similar to end users.
|
|
29
|
+
*/
|
|
30
|
+
function safeHostname(url) {
|
|
31
|
+
try {
|
|
32
|
+
return new URL(url).hostname;
|
|
33
|
+
} catch {
|
|
34
|
+
return "this site";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const DROPPED_HEADERS = [
|
|
38
|
+
"cookie",
|
|
39
|
+
"authorization",
|
|
40
|
+
"proxy-authorization",
|
|
41
|
+
"x-api-key",
|
|
42
|
+
"x-vercel-protection-bypass",
|
|
43
|
+
"cf-access-jwt-assertion",
|
|
44
|
+
"cf-access-client-secret"
|
|
45
|
+
];
|
|
46
|
+
const CREDENTIAL_HEADER = /^(?!kya-|x-bot-token$)(?:.*-)?(?:authorization|auth|token|secret|password|api-?key|apikey|subscription-key|credential)s?(?:-.*)?$/;
|
|
47
|
+
const BEACON_COOKIE = "_as_beacon_session=";
|
|
48
|
+
const DELEGATION_BEARER = /^bearer\s+[\w-]+\.([\w-]+)\.[\w-]+$/i;
|
|
49
|
+
function isRecord(value) {
|
|
50
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
51
|
+
}
|
|
52
|
+
function hasDelegationType(type) {
|
|
53
|
+
return Array.isArray(type) && type.includes("DelegationCredential");
|
|
54
|
+
}
|
|
55
|
+
function isDelegationBearer(authorization) {
|
|
56
|
+
for (const candidate of (authorization ?? "").split(",")) {
|
|
57
|
+
const match = DELEGATION_BEARER.exec(candidate.trim());
|
|
58
|
+
if (!match) continue;
|
|
59
|
+
if (match[1].length > 16384) return true;
|
|
60
|
+
let claims;
|
|
61
|
+
try {
|
|
62
|
+
claims = JSON.parse(atob(match[1].replace(/-/g, "+").replace(/_/g, "/")));
|
|
63
|
+
} catch {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (!isRecord(claims)) continue;
|
|
67
|
+
if (hasDelegationType(claims.type)) return true;
|
|
68
|
+
const vc = claims.vc;
|
|
69
|
+
if (!isRecord(vc)) continue;
|
|
70
|
+
if (hasDelegationType(vc.type)) return true;
|
|
71
|
+
const subject = vc.credentialSubject;
|
|
72
|
+
if (isRecord(subject) && isRecord(subject.delegation)) return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
function relayHeaders(input) {
|
|
77
|
+
const headers = new Headers(input);
|
|
78
|
+
const relayed = Object.fromEntries([...headers].filter(([name]) => !DROPPED_HEADERS.includes(name) && !CREDENTIAL_HEADER.test(name)));
|
|
79
|
+
const beacon = (headers.get("cookie") ?? "").split(";").map((part) => part.trim()).filter((part) => part.startsWith(BEACON_COOKIE));
|
|
80
|
+
if (beacon.length) relayed.cookie = beacon.join("; ");
|
|
81
|
+
const authorization = headers.get("authorization");
|
|
82
|
+
if (isDelegationBearer(authorization)) relayed.authorization = authorization;
|
|
83
|
+
return relayed;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
Object.defineProperty(exports, 'getClientIp', {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () {
|
|
90
|
+
return getClientIp;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(exports, 'relayHeaders', {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
get: function () {
|
|
96
|
+
return relayHeaders;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(exports, 'safeHostname', {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
get: function () {
|
|
102
|
+
return safeHostname;
|
|
103
|
+
}
|
|
104
|
+
});
|