@kya-os/checkpoint-express 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -0
- package/README.md +137 -0
- package/dist/index.d.mts +469 -0
- package/dist/index.d.ts +469 -0
- package/dist/index.js +7520 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +7483 -0
- package/dist/index.mjs.map +1 -0
- package/dist/policy.d.mts +88 -0
- package/dist/policy.d.ts +88 -0
- package/dist/policy.js +74 -0
- package/dist/policy.js.map +1 -0
- package/dist/policy.mjs +49 -0
- package/dist/policy.mjs.map +1 -0
- package/package.json +92 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
import { PolicyConfig, PolicyEvaluationResult, PolicyEvaluationContext, DetectionResult } from '@kya-os/checkpoint-shared';
|
|
3
|
+
export { DEFAULT_POLICY, ENFORCEMENT_ACTIONS, PolicyConfig, PolicyEvaluationContext, PolicyEvaluationResult, createEvaluationContext, evaluatePolicy } from '@kya-os/checkpoint-shared';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Legacy policy module — Phase E throw-stub.
|
|
7
|
+
*
|
|
8
|
+
* Local policy evaluation (deny lists, allow lists, threshold checks)
|
|
9
|
+
* was the JS-side enforcement path; per the architect's no-JS-verify
|
|
10
|
+
* pin (Phase 1 review § Q4) it dies. The engine's `Decision` is now
|
|
11
|
+
* the single authoritative policy output — the orchestrator builds it
|
|
12
|
+
* from the customer's tenant policy (loaded via `PolicyEvaluator`
|
|
13
|
+
* adapter), and `withCheckpoint`'s response adapter renders it.
|
|
14
|
+
*
|
|
15
|
+
* Type exports (`PolicyMiddlewareConfig`, `PolicyConfig`, etc.) and
|
|
16
|
+
* shared-package re-exports (`evaluatePolicy`, `ENFORCEMENT_ACTIONS`,
|
|
17
|
+
* `DEFAULT_POLICY`) remain so customers' config types keep
|
|
18
|
+
* type-checking through the migration window. Function exports throw
|
|
19
|
+
* with a migration message at runtime.
|
|
20
|
+
*
|
|
21
|
+
* @deprecated Use `withCheckpoint` from `@kya-os/checkpoint-express`.
|
|
22
|
+
* Tenant policy is loaded by the engine's PolicyEvaluator adapter.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Policy middleware configuration (legacy type). Preserved so customer
|
|
27
|
+
* config types keep type-checking; the factories that consumed it now
|
|
28
|
+
* throw.
|
|
29
|
+
*/
|
|
30
|
+
interface PolicyMiddlewareConfig {
|
|
31
|
+
/** Local policy configuration (static). */
|
|
32
|
+
policy?: Partial<PolicyConfig>;
|
|
33
|
+
/** Fetch policy from AgentShield API. */
|
|
34
|
+
fetchPolicy?: {
|
|
35
|
+
projectId: string;
|
|
36
|
+
apiUrl?: string;
|
|
37
|
+
apiKey?: string;
|
|
38
|
+
cacheTtlSeconds?: number;
|
|
39
|
+
};
|
|
40
|
+
/** Fallback policy to use when fetch fails. */
|
|
41
|
+
fallbackPolicy?: Partial<PolicyConfig>;
|
|
42
|
+
/** Custom blocked response. */
|
|
43
|
+
blockedResponse?: {
|
|
44
|
+
status?: number;
|
|
45
|
+
message?: string;
|
|
46
|
+
headers?: Record<string, string>;
|
|
47
|
+
};
|
|
48
|
+
/** Default redirect URL for redirect actions. */
|
|
49
|
+
redirectUrl?: string;
|
|
50
|
+
/** Callback when policy decision is made. */
|
|
51
|
+
onPolicyDecision?: (req: Request, res: Response, decision: PolicyEvaluationResult, context: PolicyEvaluationContext) => void | Promise<void>;
|
|
52
|
+
/** Custom response handler for blocked requests. */
|
|
53
|
+
customBlockedResponse?: (req: Request, res: Response, decision: PolicyEvaluationResult) => void | Promise<void>;
|
|
54
|
+
/** Whether to fail open (allow) on policy evaluation errors. */
|
|
55
|
+
failOpen?: boolean;
|
|
56
|
+
/** Enable debug logging. */
|
|
57
|
+
debug?: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** @deprecated Use `withCheckpoint` — engine PolicyEvaluator owns this. */
|
|
60
|
+
declare function createContextFromDetection(_detection: DetectionResult, _req: Request): PolicyEvaluationContext;
|
|
61
|
+
/** @deprecated Use `withCheckpoint` — engine PolicyEvaluator owns this. */
|
|
62
|
+
declare function evaluatePolicyForDetection(_detection: DetectionResult, _req: Request, _policy: PolicyConfig): PolicyEvaluationResult;
|
|
63
|
+
/** @deprecated Use `withCheckpoint` — its response adapter owns this. */
|
|
64
|
+
declare function sendBlockedResponse(_res: Response, _decision: PolicyEvaluationResult, _config: PolicyMiddlewareConfig): void;
|
|
65
|
+
/** @deprecated Use `withCheckpoint` — its response adapter owns this. */
|
|
66
|
+
declare function sendRedirectResponse(_req: Request, _res: Response, _decision: PolicyEvaluationResult, _config: PolicyMiddlewareConfig, _detection?: {
|
|
67
|
+
detectedAgent?: {
|
|
68
|
+
name?: string;
|
|
69
|
+
};
|
|
70
|
+
}): void;
|
|
71
|
+
/** @deprecated Use `withCheckpoint` — its response adapter owns this. */
|
|
72
|
+
declare function sendChallengeResponse(_req: Request, _res: Response, _decision: PolicyEvaluationResult, _config: PolicyMiddlewareConfig, _detection?: {
|
|
73
|
+
detectedAgent?: {
|
|
74
|
+
name?: string;
|
|
75
|
+
};
|
|
76
|
+
}): void;
|
|
77
|
+
/** @deprecated Use `withCheckpoint` — engine + adapter compose this. */
|
|
78
|
+
declare function handlePolicyDecision(_req: Request, _res: Response, _decision: PolicyEvaluationResult, _config: PolicyMiddlewareConfig, _detection?: {
|
|
79
|
+
detectedAgent?: {
|
|
80
|
+
name?: string;
|
|
81
|
+
};
|
|
82
|
+
}): Promise<boolean>;
|
|
83
|
+
/** @deprecated Tenant policy now loads via the engine PolicyEvaluator. */
|
|
84
|
+
declare function getPolicy(_config: PolicyMiddlewareConfig): Promise<PolicyConfig>;
|
|
85
|
+
/** @deprecated Use `withCheckpoint` — engine + adapter compose this. */
|
|
86
|
+
declare function applyPolicy(_req: Request, _res: Response, _detection: DetectionResult, _config: PolicyMiddlewareConfig): Promise<boolean>;
|
|
87
|
+
|
|
88
|
+
export { type PolicyMiddlewareConfig, applyPolicy, createContextFromDetection, evaluatePolicyForDetection, getPolicy, handlePolicyDecision, sendBlockedResponse, sendChallengeResponse, sendRedirectResponse };
|
package/dist/policy.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
import { PolicyConfig, PolicyEvaluationResult, PolicyEvaluationContext, DetectionResult } from '@kya-os/checkpoint-shared';
|
|
3
|
+
export { DEFAULT_POLICY, ENFORCEMENT_ACTIONS, PolicyConfig, PolicyEvaluationContext, PolicyEvaluationResult, createEvaluationContext, evaluatePolicy } from '@kya-os/checkpoint-shared';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Legacy policy module — Phase E throw-stub.
|
|
7
|
+
*
|
|
8
|
+
* Local policy evaluation (deny lists, allow lists, threshold checks)
|
|
9
|
+
* was the JS-side enforcement path; per the architect's no-JS-verify
|
|
10
|
+
* pin (Phase 1 review § Q4) it dies. The engine's `Decision` is now
|
|
11
|
+
* the single authoritative policy output — the orchestrator builds it
|
|
12
|
+
* from the customer's tenant policy (loaded via `PolicyEvaluator`
|
|
13
|
+
* adapter), and `withCheckpoint`'s response adapter renders it.
|
|
14
|
+
*
|
|
15
|
+
* Type exports (`PolicyMiddlewareConfig`, `PolicyConfig`, etc.) and
|
|
16
|
+
* shared-package re-exports (`evaluatePolicy`, `ENFORCEMENT_ACTIONS`,
|
|
17
|
+
* `DEFAULT_POLICY`) remain so customers' config types keep
|
|
18
|
+
* type-checking through the migration window. Function exports throw
|
|
19
|
+
* with a migration message at runtime.
|
|
20
|
+
*
|
|
21
|
+
* @deprecated Use `withCheckpoint` from `@kya-os/checkpoint-express`.
|
|
22
|
+
* Tenant policy is loaded by the engine's PolicyEvaluator adapter.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Policy middleware configuration (legacy type). Preserved so customer
|
|
27
|
+
* config types keep type-checking; the factories that consumed it now
|
|
28
|
+
* throw.
|
|
29
|
+
*/
|
|
30
|
+
interface PolicyMiddlewareConfig {
|
|
31
|
+
/** Local policy configuration (static). */
|
|
32
|
+
policy?: Partial<PolicyConfig>;
|
|
33
|
+
/** Fetch policy from AgentShield API. */
|
|
34
|
+
fetchPolicy?: {
|
|
35
|
+
projectId: string;
|
|
36
|
+
apiUrl?: string;
|
|
37
|
+
apiKey?: string;
|
|
38
|
+
cacheTtlSeconds?: number;
|
|
39
|
+
};
|
|
40
|
+
/** Fallback policy to use when fetch fails. */
|
|
41
|
+
fallbackPolicy?: Partial<PolicyConfig>;
|
|
42
|
+
/** Custom blocked response. */
|
|
43
|
+
blockedResponse?: {
|
|
44
|
+
status?: number;
|
|
45
|
+
message?: string;
|
|
46
|
+
headers?: Record<string, string>;
|
|
47
|
+
};
|
|
48
|
+
/** Default redirect URL for redirect actions. */
|
|
49
|
+
redirectUrl?: string;
|
|
50
|
+
/** Callback when policy decision is made. */
|
|
51
|
+
onPolicyDecision?: (req: Request, res: Response, decision: PolicyEvaluationResult, context: PolicyEvaluationContext) => void | Promise<void>;
|
|
52
|
+
/** Custom response handler for blocked requests. */
|
|
53
|
+
customBlockedResponse?: (req: Request, res: Response, decision: PolicyEvaluationResult) => void | Promise<void>;
|
|
54
|
+
/** Whether to fail open (allow) on policy evaluation errors. */
|
|
55
|
+
failOpen?: boolean;
|
|
56
|
+
/** Enable debug logging. */
|
|
57
|
+
debug?: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** @deprecated Use `withCheckpoint` — engine PolicyEvaluator owns this. */
|
|
60
|
+
declare function createContextFromDetection(_detection: DetectionResult, _req: Request): PolicyEvaluationContext;
|
|
61
|
+
/** @deprecated Use `withCheckpoint` — engine PolicyEvaluator owns this. */
|
|
62
|
+
declare function evaluatePolicyForDetection(_detection: DetectionResult, _req: Request, _policy: PolicyConfig): PolicyEvaluationResult;
|
|
63
|
+
/** @deprecated Use `withCheckpoint` — its response adapter owns this. */
|
|
64
|
+
declare function sendBlockedResponse(_res: Response, _decision: PolicyEvaluationResult, _config: PolicyMiddlewareConfig): void;
|
|
65
|
+
/** @deprecated Use `withCheckpoint` — its response adapter owns this. */
|
|
66
|
+
declare function sendRedirectResponse(_req: Request, _res: Response, _decision: PolicyEvaluationResult, _config: PolicyMiddlewareConfig, _detection?: {
|
|
67
|
+
detectedAgent?: {
|
|
68
|
+
name?: string;
|
|
69
|
+
};
|
|
70
|
+
}): void;
|
|
71
|
+
/** @deprecated Use `withCheckpoint` — its response adapter owns this. */
|
|
72
|
+
declare function sendChallengeResponse(_req: Request, _res: Response, _decision: PolicyEvaluationResult, _config: PolicyMiddlewareConfig, _detection?: {
|
|
73
|
+
detectedAgent?: {
|
|
74
|
+
name?: string;
|
|
75
|
+
};
|
|
76
|
+
}): void;
|
|
77
|
+
/** @deprecated Use `withCheckpoint` — engine + adapter compose this. */
|
|
78
|
+
declare function handlePolicyDecision(_req: Request, _res: Response, _decision: PolicyEvaluationResult, _config: PolicyMiddlewareConfig, _detection?: {
|
|
79
|
+
detectedAgent?: {
|
|
80
|
+
name?: string;
|
|
81
|
+
};
|
|
82
|
+
}): Promise<boolean>;
|
|
83
|
+
/** @deprecated Tenant policy now loads via the engine PolicyEvaluator. */
|
|
84
|
+
declare function getPolicy(_config: PolicyMiddlewareConfig): Promise<PolicyConfig>;
|
|
85
|
+
/** @deprecated Use `withCheckpoint` — engine + adapter compose this. */
|
|
86
|
+
declare function applyPolicy(_req: Request, _res: Response, _detection: DetectionResult, _config: PolicyMiddlewareConfig): Promise<boolean>;
|
|
87
|
+
|
|
88
|
+
export { type PolicyMiddlewareConfig, applyPolicy, createContextFromDetection, evaluatePolicyForDetection, getPolicy, handlePolicyDecision, sendBlockedResponse, sendChallengeResponse, sendRedirectResponse };
|
package/dist/policy.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var checkpointShared = require('@kya-os/checkpoint-shared');
|
|
4
|
+
|
|
5
|
+
// src/policy.ts
|
|
6
|
+
var MIGRATION_MESSAGE = [
|
|
7
|
+
"[checkpoint-express] Local policy evaluation has been retired.",
|
|
8
|
+
"",
|
|
9
|
+
"Tenant policy now flows through the engine PolicyEvaluator adapter.",
|
|
10
|
+
"Configure it via withCheckpoint's `dashboardUrl` option:",
|
|
11
|
+
"",
|
|
12
|
+
" import { withCheckpoint } from '@kya-os/checkpoint-express';",
|
|
13
|
+
"",
|
|
14
|
+
" app.use(withCheckpoint({",
|
|
15
|
+
" tenantHost: 'your.tenant.example',",
|
|
16
|
+
" dashboardUrl: 'https://dashboard.checkpoint.example',",
|
|
17
|
+
" }));",
|
|
18
|
+
"",
|
|
19
|
+
"The engine`s `Decision` (Permit / Block / Redirect / Challenge / Instruct)",
|
|
20
|
+
"is the single authoritative policy output \u2014 the response adapter inside",
|
|
21
|
+
"`withCheckpoint` renders it. Custom block-response shapes belong in the",
|
|
22
|
+
"dashboard policy itself, not in middleware code."
|
|
23
|
+
].join("\n");
|
|
24
|
+
function createContextFromDetection(_detection, _req) {
|
|
25
|
+
throw new Error(MIGRATION_MESSAGE);
|
|
26
|
+
}
|
|
27
|
+
function evaluatePolicyForDetection(_detection, _req, _policy) {
|
|
28
|
+
throw new Error(MIGRATION_MESSAGE);
|
|
29
|
+
}
|
|
30
|
+
function sendBlockedResponse(_res, _decision, _config) {
|
|
31
|
+
throw new Error(MIGRATION_MESSAGE);
|
|
32
|
+
}
|
|
33
|
+
function sendRedirectResponse(_req, _res, _decision, _config, _detection) {
|
|
34
|
+
throw new Error(MIGRATION_MESSAGE);
|
|
35
|
+
}
|
|
36
|
+
function sendChallengeResponse(_req, _res, _decision, _config, _detection) {
|
|
37
|
+
throw new Error(MIGRATION_MESSAGE);
|
|
38
|
+
}
|
|
39
|
+
async function handlePolicyDecision(_req, _res, _decision, _config, _detection) {
|
|
40
|
+
throw new Error(MIGRATION_MESSAGE);
|
|
41
|
+
}
|
|
42
|
+
async function getPolicy(_config) {
|
|
43
|
+
throw new Error(MIGRATION_MESSAGE);
|
|
44
|
+
}
|
|
45
|
+
async function applyPolicy(_req, _res, _detection, _config) {
|
|
46
|
+
throw new Error(MIGRATION_MESSAGE);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Object.defineProperty(exports, "DEFAULT_POLICY", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function () { return checkpointShared.DEFAULT_POLICY; }
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(exports, "ENFORCEMENT_ACTIONS", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
get: function () { return checkpointShared.ENFORCEMENT_ACTIONS; }
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(exports, "createEvaluationContext", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function () { return checkpointShared.createEvaluationContext; }
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(exports, "evaluatePolicy", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function () { return checkpointShared.evaluatePolicy; }
|
|
64
|
+
});
|
|
65
|
+
exports.applyPolicy = applyPolicy;
|
|
66
|
+
exports.createContextFromDetection = createContextFromDetection;
|
|
67
|
+
exports.evaluatePolicyForDetection = evaluatePolicyForDetection;
|
|
68
|
+
exports.getPolicy = getPolicy;
|
|
69
|
+
exports.handlePolicyDecision = handlePolicyDecision;
|
|
70
|
+
exports.sendBlockedResponse = sendBlockedResponse;
|
|
71
|
+
exports.sendChallengeResponse = sendChallengeResponse;
|
|
72
|
+
exports.sendRedirectResponse = sendRedirectResponse;
|
|
73
|
+
//# sourceMappingURL=policy.js.map
|
|
74
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/policy.ts"],"names":[],"mappings":";;;;;AAsFA,IAAM,iBAAA,GAAoB;AAAA,EACxB,gEAAA;AAAA,EACA,EAAA;AAAA,EACA,qEAAA;AAAA,EACA,0DAAA;AAAA,EACA,EAAA;AAAA,EACA,gEAAA;AAAA,EACA,EAAA;AAAA,EACA,4BAAA;AAAA,EACA,wCAAA;AAAA,EACA,2DAAA;AAAA,EACA,QAAA;AAAA,EACA,EAAA;AAAA,EACA,4EAAA;AAAA,EACA,8EAAA;AAAA,EACA,yEAAA;AAAA,EACA;AACF,CAAA,CAAE,KAAK,IAAI,CAAA;AAOJ,SAAS,0BAAA,CACd,YACA,IAAA,EACyB;AACzB,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AAGO,SAAS,0BAAA,CACd,UAAA,EACA,IAAA,EACA,OAAA,EACwB;AACxB,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AAGO,SAAS,mBAAA,CACd,IAAA,EACA,SAAA,EACA,OAAA,EACM;AACN,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AAGO,SAAS,oBAAA,CACd,IAAA,EACA,IAAA,EACA,SAAA,EACA,SACA,UAAA,EACM;AACN,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AAGO,SAAS,qBAAA,CACd,IAAA,EACA,IAAA,EACA,SAAA,EACA,SACA,UAAA,EACM;AACN,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AAGA,eAAsB,oBAAA,CACpB,IAAA,EACA,IAAA,EACA,SAAA,EACA,SACA,UAAA,EACkB;AAClB,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AAGA,eAAsB,UAAU,OAAA,EAAwD;AACtF,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AAGA,eAAsB,WAAA,CACpB,IAAA,EACA,IAAA,EACA,UAAA,EACA,OAAA,EACkB;AAClB,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC","file":"policy.js","sourcesContent":["/**\n * Legacy policy module — Phase E throw-stub.\n *\n * Local policy evaluation (deny lists, allow lists, threshold checks)\n * was the JS-side enforcement path; per the architect's no-JS-verify\n * pin (Phase 1 review § Q4) it dies. The engine's `Decision` is now\n * the single authoritative policy output — the orchestrator builds it\n * from the customer's tenant policy (loaded via `PolicyEvaluator`\n * adapter), and `withCheckpoint`'s response adapter renders it.\n *\n * Type exports (`PolicyMiddlewareConfig`, `PolicyConfig`, etc.) and\n * shared-package re-exports (`evaluatePolicy`, `ENFORCEMENT_ACTIONS`,\n * `DEFAULT_POLICY`) remain so customers' config types keep\n * type-checking through the migration window. Function exports throw\n * with a migration message at runtime.\n *\n * @deprecated Use `withCheckpoint` from `@kya-os/checkpoint-express`.\n * Tenant policy is loaded by the engine's PolicyEvaluator adapter.\n */\n\nimport type { Request, Response } from 'express';\n\nimport type {\n PolicyConfig,\n PolicyEvaluationContext,\n PolicyEvaluationResult,\n DetectionResult,\n} from '@kya-os/checkpoint-shared';\n\n// Re-export shared policy types + helpers for convenience. Call sites\n// that destructure these continue to type-check; only the function-body\n// invocations of the legacy local-policy helpers (below) throw.\nexport {\n evaluatePolicy,\n createEvaluationContext,\n type PolicyConfig,\n type PolicyEvaluationContext,\n type PolicyEvaluationResult,\n ENFORCEMENT_ACTIONS,\n DEFAULT_POLICY,\n} from '@kya-os/checkpoint-shared';\n\n/**\n * Policy middleware configuration (legacy type). Preserved so customer\n * config types keep type-checking; the factories that consumed it now\n * throw.\n */\nexport interface PolicyMiddlewareConfig {\n /** Local policy configuration (static). */\n policy?: Partial<PolicyConfig>;\n /** Fetch policy from AgentShield API. */\n fetchPolicy?: {\n projectId: string;\n apiUrl?: string;\n apiKey?: string;\n cacheTtlSeconds?: number;\n };\n /** Fallback policy to use when fetch fails. */\n fallbackPolicy?: Partial<PolicyConfig>;\n /** Custom blocked response. */\n blockedResponse?: {\n status?: number;\n message?: string;\n headers?: Record<string, string>;\n };\n /** Default redirect URL for redirect actions. */\n redirectUrl?: string;\n /** Callback when policy decision is made. */\n onPolicyDecision?: (\n req: Request,\n res: Response,\n decision: PolicyEvaluationResult,\n context: PolicyEvaluationContext\n ) => void | Promise<void>;\n /** Custom response handler for blocked requests. */\n customBlockedResponse?: (\n req: Request,\n res: Response,\n decision: PolicyEvaluationResult\n ) => void | Promise<void>;\n /** Whether to fail open (allow) on policy evaluation errors. */\n failOpen?: boolean;\n /** Enable debug logging. */\n debug?: boolean;\n}\n\nconst MIGRATION_MESSAGE = [\n '[checkpoint-express] Local policy evaluation has been retired.',\n '',\n 'Tenant policy now flows through the engine PolicyEvaluator adapter.',\n \"Configure it via withCheckpoint's `dashboardUrl` option:\",\n '',\n \" import { withCheckpoint } from '@kya-os/checkpoint-express';\",\n '',\n ' app.use(withCheckpoint({',\n \" tenantHost: 'your.tenant.example',\",\n \" dashboardUrl: 'https://dashboard.checkpoint.example',\",\n ' }));',\n '',\n 'The engine`s `Decision` (Permit / Block / Redirect / Challenge / Instruct)',\n 'is the single authoritative policy output — the response adapter inside',\n '`withCheckpoint` renders it. Custom block-response shapes belong in the',\n 'dashboard policy itself, not in middleware code.',\n].join('\\n');\n\n// ---------------------------------------------------------------------------\n// Throw-stub function exports — names preserved, bodies retired.\n// ---------------------------------------------------------------------------\n\n/** @deprecated Use `withCheckpoint` — engine PolicyEvaluator owns this. */\nexport function createContextFromDetection(\n _detection: DetectionResult,\n _req: Request\n): PolicyEvaluationContext {\n throw new Error(MIGRATION_MESSAGE);\n}\n\n/** @deprecated Use `withCheckpoint` — engine PolicyEvaluator owns this. */\nexport function evaluatePolicyForDetection(\n _detection: DetectionResult,\n _req: Request,\n _policy: PolicyConfig\n): PolicyEvaluationResult {\n throw new Error(MIGRATION_MESSAGE);\n}\n\n/** @deprecated Use `withCheckpoint` — its response adapter owns this. */\nexport function sendBlockedResponse(\n _res: Response,\n _decision: PolicyEvaluationResult,\n _config: PolicyMiddlewareConfig\n): void {\n throw new Error(MIGRATION_MESSAGE);\n}\n\n/** @deprecated Use `withCheckpoint` — its response adapter owns this. */\nexport function sendRedirectResponse(\n _req: Request,\n _res: Response,\n _decision: PolicyEvaluationResult,\n _config: PolicyMiddlewareConfig,\n _detection?: { detectedAgent?: { name?: string } }\n): void {\n throw new Error(MIGRATION_MESSAGE);\n}\n\n/** @deprecated Use `withCheckpoint` — its response adapter owns this. */\nexport function sendChallengeResponse(\n _req: Request,\n _res: Response,\n _decision: PolicyEvaluationResult,\n _config: PolicyMiddlewareConfig,\n _detection?: { detectedAgent?: { name?: string } }\n): void {\n throw new Error(MIGRATION_MESSAGE);\n}\n\n/** @deprecated Use `withCheckpoint` — engine + adapter compose this. */\nexport async function handlePolicyDecision(\n _req: Request,\n _res: Response,\n _decision: PolicyEvaluationResult,\n _config: PolicyMiddlewareConfig,\n _detection?: { detectedAgent?: { name?: string } }\n): Promise<boolean> {\n throw new Error(MIGRATION_MESSAGE);\n}\n\n/** @deprecated Tenant policy now loads via the engine PolicyEvaluator. */\nexport async function getPolicy(_config: PolicyMiddlewareConfig): Promise<PolicyConfig> {\n throw new Error(MIGRATION_MESSAGE);\n}\n\n/** @deprecated Use `withCheckpoint` — engine + adapter compose this. */\nexport async function applyPolicy(\n _req: Request,\n _res: Response,\n _detection: DetectionResult,\n _config: PolicyMiddlewareConfig\n): Promise<boolean> {\n throw new Error(MIGRATION_MESSAGE);\n}\n"]}
|
package/dist/policy.mjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export { DEFAULT_POLICY, ENFORCEMENT_ACTIONS, createEvaluationContext, evaluatePolicy } from '@kya-os/checkpoint-shared';
|
|
2
|
+
|
|
3
|
+
// src/policy.ts
|
|
4
|
+
var MIGRATION_MESSAGE = [
|
|
5
|
+
"[checkpoint-express] Local policy evaluation has been retired.",
|
|
6
|
+
"",
|
|
7
|
+
"Tenant policy now flows through the engine PolicyEvaluator adapter.",
|
|
8
|
+
"Configure it via withCheckpoint's `dashboardUrl` option:",
|
|
9
|
+
"",
|
|
10
|
+
" import { withCheckpoint } from '@kya-os/checkpoint-express';",
|
|
11
|
+
"",
|
|
12
|
+
" app.use(withCheckpoint({",
|
|
13
|
+
" tenantHost: 'your.tenant.example',",
|
|
14
|
+
" dashboardUrl: 'https://dashboard.checkpoint.example',",
|
|
15
|
+
" }));",
|
|
16
|
+
"",
|
|
17
|
+
"The engine`s `Decision` (Permit / Block / Redirect / Challenge / Instruct)",
|
|
18
|
+
"is the single authoritative policy output \u2014 the response adapter inside",
|
|
19
|
+
"`withCheckpoint` renders it. Custom block-response shapes belong in the",
|
|
20
|
+
"dashboard policy itself, not in middleware code."
|
|
21
|
+
].join("\n");
|
|
22
|
+
function createContextFromDetection(_detection, _req) {
|
|
23
|
+
throw new Error(MIGRATION_MESSAGE);
|
|
24
|
+
}
|
|
25
|
+
function evaluatePolicyForDetection(_detection, _req, _policy) {
|
|
26
|
+
throw new Error(MIGRATION_MESSAGE);
|
|
27
|
+
}
|
|
28
|
+
function sendBlockedResponse(_res, _decision, _config) {
|
|
29
|
+
throw new Error(MIGRATION_MESSAGE);
|
|
30
|
+
}
|
|
31
|
+
function sendRedirectResponse(_req, _res, _decision, _config, _detection) {
|
|
32
|
+
throw new Error(MIGRATION_MESSAGE);
|
|
33
|
+
}
|
|
34
|
+
function sendChallengeResponse(_req, _res, _decision, _config, _detection) {
|
|
35
|
+
throw new Error(MIGRATION_MESSAGE);
|
|
36
|
+
}
|
|
37
|
+
async function handlePolicyDecision(_req, _res, _decision, _config, _detection) {
|
|
38
|
+
throw new Error(MIGRATION_MESSAGE);
|
|
39
|
+
}
|
|
40
|
+
async function getPolicy(_config) {
|
|
41
|
+
throw new Error(MIGRATION_MESSAGE);
|
|
42
|
+
}
|
|
43
|
+
async function applyPolicy(_req, _res, _detection, _config) {
|
|
44
|
+
throw new Error(MIGRATION_MESSAGE);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { applyPolicy, createContextFromDetection, evaluatePolicyForDetection, getPolicy, handlePolicyDecision, sendBlockedResponse, sendChallengeResponse, sendRedirectResponse };
|
|
48
|
+
//# sourceMappingURL=policy.mjs.map
|
|
49
|
+
//# sourceMappingURL=policy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/policy.ts"],"names":[],"mappings":";;;AAsFA,IAAM,iBAAA,GAAoB;AAAA,EACxB,gEAAA;AAAA,EACA,EAAA;AAAA,EACA,qEAAA;AAAA,EACA,0DAAA;AAAA,EACA,EAAA;AAAA,EACA,gEAAA;AAAA,EACA,EAAA;AAAA,EACA,4BAAA;AAAA,EACA,wCAAA;AAAA,EACA,2DAAA;AAAA,EACA,QAAA;AAAA,EACA,EAAA;AAAA,EACA,4EAAA;AAAA,EACA,8EAAA;AAAA,EACA,yEAAA;AAAA,EACA;AACF,CAAA,CAAE,KAAK,IAAI,CAAA;AAOJ,SAAS,0BAAA,CACd,YACA,IAAA,EACyB;AACzB,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AAGO,SAAS,0BAAA,CACd,UAAA,EACA,IAAA,EACA,OAAA,EACwB;AACxB,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AAGO,SAAS,mBAAA,CACd,IAAA,EACA,SAAA,EACA,OAAA,EACM;AACN,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AAGO,SAAS,oBAAA,CACd,IAAA,EACA,IAAA,EACA,SAAA,EACA,SACA,UAAA,EACM;AACN,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AAGO,SAAS,qBAAA,CACd,IAAA,EACA,IAAA,EACA,SAAA,EACA,SACA,UAAA,EACM;AACN,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AAGA,eAAsB,oBAAA,CACpB,IAAA,EACA,IAAA,EACA,SAAA,EACA,SACA,UAAA,EACkB;AAClB,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AAGA,eAAsB,UAAU,OAAA,EAAwD;AACtF,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AAGA,eAAsB,WAAA,CACpB,IAAA,EACA,IAAA,EACA,UAAA,EACA,OAAA,EACkB;AAClB,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC","file":"policy.mjs","sourcesContent":["/**\n * Legacy policy module — Phase E throw-stub.\n *\n * Local policy evaluation (deny lists, allow lists, threshold checks)\n * was the JS-side enforcement path; per the architect's no-JS-verify\n * pin (Phase 1 review § Q4) it dies. The engine's `Decision` is now\n * the single authoritative policy output — the orchestrator builds it\n * from the customer's tenant policy (loaded via `PolicyEvaluator`\n * adapter), and `withCheckpoint`'s response adapter renders it.\n *\n * Type exports (`PolicyMiddlewareConfig`, `PolicyConfig`, etc.) and\n * shared-package re-exports (`evaluatePolicy`, `ENFORCEMENT_ACTIONS`,\n * `DEFAULT_POLICY`) remain so customers' config types keep\n * type-checking through the migration window. Function exports throw\n * with a migration message at runtime.\n *\n * @deprecated Use `withCheckpoint` from `@kya-os/checkpoint-express`.\n * Tenant policy is loaded by the engine's PolicyEvaluator adapter.\n */\n\nimport type { Request, Response } from 'express';\n\nimport type {\n PolicyConfig,\n PolicyEvaluationContext,\n PolicyEvaluationResult,\n DetectionResult,\n} from '@kya-os/checkpoint-shared';\n\n// Re-export shared policy types + helpers for convenience. Call sites\n// that destructure these continue to type-check; only the function-body\n// invocations of the legacy local-policy helpers (below) throw.\nexport {\n evaluatePolicy,\n createEvaluationContext,\n type PolicyConfig,\n type PolicyEvaluationContext,\n type PolicyEvaluationResult,\n ENFORCEMENT_ACTIONS,\n DEFAULT_POLICY,\n} from '@kya-os/checkpoint-shared';\n\n/**\n * Policy middleware configuration (legacy type). Preserved so customer\n * config types keep type-checking; the factories that consumed it now\n * throw.\n */\nexport interface PolicyMiddlewareConfig {\n /** Local policy configuration (static). */\n policy?: Partial<PolicyConfig>;\n /** Fetch policy from AgentShield API. */\n fetchPolicy?: {\n projectId: string;\n apiUrl?: string;\n apiKey?: string;\n cacheTtlSeconds?: number;\n };\n /** Fallback policy to use when fetch fails. */\n fallbackPolicy?: Partial<PolicyConfig>;\n /** Custom blocked response. */\n blockedResponse?: {\n status?: number;\n message?: string;\n headers?: Record<string, string>;\n };\n /** Default redirect URL for redirect actions. */\n redirectUrl?: string;\n /** Callback when policy decision is made. */\n onPolicyDecision?: (\n req: Request,\n res: Response,\n decision: PolicyEvaluationResult,\n context: PolicyEvaluationContext\n ) => void | Promise<void>;\n /** Custom response handler for blocked requests. */\n customBlockedResponse?: (\n req: Request,\n res: Response,\n decision: PolicyEvaluationResult\n ) => void | Promise<void>;\n /** Whether to fail open (allow) on policy evaluation errors. */\n failOpen?: boolean;\n /** Enable debug logging. */\n debug?: boolean;\n}\n\nconst MIGRATION_MESSAGE = [\n '[checkpoint-express] Local policy evaluation has been retired.',\n '',\n 'Tenant policy now flows through the engine PolicyEvaluator adapter.',\n \"Configure it via withCheckpoint's `dashboardUrl` option:\",\n '',\n \" import { withCheckpoint } from '@kya-os/checkpoint-express';\",\n '',\n ' app.use(withCheckpoint({',\n \" tenantHost: 'your.tenant.example',\",\n \" dashboardUrl: 'https://dashboard.checkpoint.example',\",\n ' }));',\n '',\n 'The engine`s `Decision` (Permit / Block / Redirect / Challenge / Instruct)',\n 'is the single authoritative policy output — the response adapter inside',\n '`withCheckpoint` renders it. Custom block-response shapes belong in the',\n 'dashboard policy itself, not in middleware code.',\n].join('\\n');\n\n// ---------------------------------------------------------------------------\n// Throw-stub function exports — names preserved, bodies retired.\n// ---------------------------------------------------------------------------\n\n/** @deprecated Use `withCheckpoint` — engine PolicyEvaluator owns this. */\nexport function createContextFromDetection(\n _detection: DetectionResult,\n _req: Request\n): PolicyEvaluationContext {\n throw new Error(MIGRATION_MESSAGE);\n}\n\n/** @deprecated Use `withCheckpoint` — engine PolicyEvaluator owns this. */\nexport function evaluatePolicyForDetection(\n _detection: DetectionResult,\n _req: Request,\n _policy: PolicyConfig\n): PolicyEvaluationResult {\n throw new Error(MIGRATION_MESSAGE);\n}\n\n/** @deprecated Use `withCheckpoint` — its response adapter owns this. */\nexport function sendBlockedResponse(\n _res: Response,\n _decision: PolicyEvaluationResult,\n _config: PolicyMiddlewareConfig\n): void {\n throw new Error(MIGRATION_MESSAGE);\n}\n\n/** @deprecated Use `withCheckpoint` — its response adapter owns this. */\nexport function sendRedirectResponse(\n _req: Request,\n _res: Response,\n _decision: PolicyEvaluationResult,\n _config: PolicyMiddlewareConfig,\n _detection?: { detectedAgent?: { name?: string } }\n): void {\n throw new Error(MIGRATION_MESSAGE);\n}\n\n/** @deprecated Use `withCheckpoint` — its response adapter owns this. */\nexport function sendChallengeResponse(\n _req: Request,\n _res: Response,\n _decision: PolicyEvaluationResult,\n _config: PolicyMiddlewareConfig,\n _detection?: { detectedAgent?: { name?: string } }\n): void {\n throw new Error(MIGRATION_MESSAGE);\n}\n\n/** @deprecated Use `withCheckpoint` — engine + adapter compose this. */\nexport async function handlePolicyDecision(\n _req: Request,\n _res: Response,\n _decision: PolicyEvaluationResult,\n _config: PolicyMiddlewareConfig,\n _detection?: { detectedAgent?: { name?: string } }\n): Promise<boolean> {\n throw new Error(MIGRATION_MESSAGE);\n}\n\n/** @deprecated Tenant policy now loads via the engine PolicyEvaluator. */\nexport async function getPolicy(_config: PolicyMiddlewareConfig): Promise<PolicyConfig> {\n throw new Error(MIGRATION_MESSAGE);\n}\n\n/** @deprecated Use `withCheckpoint` — engine + adapter compose this. */\nexport async function applyPolicy(\n _req: Request,\n _res: Response,\n _detection: DetectionResult,\n _config: PolicyMiddlewareConfig\n): Promise<boolean> {\n throw new Error(MIGRATION_MESSAGE);\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kya-os/checkpoint-express",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Express.js middleware for Checkpoint — engine-backed AI agent detection and MCP-I verification",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"express",
|
|
7
|
+
"middleware",
|
|
8
|
+
"ai",
|
|
9
|
+
"agent",
|
|
10
|
+
"detection",
|
|
11
|
+
"security"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT OR Apache-2.0",
|
|
14
|
+
"author": "KnowThat.ai",
|
|
15
|
+
"homepage": "https://github.com/Know-That-Ai/agent-shield#readme",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/Know-That-Ai/agent-shield.git",
|
|
19
|
+
"directory": "packages/checkpoint-express"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/Know-That-Ai/agent-shield/issues"
|
|
23
|
+
},
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"module": "./dist/index.mjs",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.mjs",
|
|
31
|
+
"require": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./policy": {
|
|
34
|
+
"types": "./dist/policy.d.ts",
|
|
35
|
+
"import": "./dist/policy.mjs",
|
|
36
|
+
"require": "./dist/policy.js"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"README.md",
|
|
43
|
+
"CHANGELOG.md"
|
|
44
|
+
],
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18.0.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/express": "^4.17.21",
|
|
50
|
+
"@types/node": "^20.11.24",
|
|
51
|
+
"@vitest/coverage-v8": "^1.3.1",
|
|
52
|
+
"express": "^4.18.3",
|
|
53
|
+
"rimraf": "^5.0.5",
|
|
54
|
+
"tsup": "^8.0.2",
|
|
55
|
+
"typescript": "^5.4.2",
|
|
56
|
+
"vitest": "^1.3.1"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"express": "^4.18.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"@upstash/redis": {
|
|
63
|
+
"optional": true
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
},
|
|
69
|
+
"sideEffects": false,
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"@kya-os/checkpoint-shared": "1.0.0",
|
|
72
|
+
"@kya-os/checkpoint": "1.0.0"
|
|
73
|
+
},
|
|
74
|
+
"optionalDependencies": {
|
|
75
|
+
"@upstash/redis": "^1.35.0",
|
|
76
|
+
"@kya-os/checkpoint-wasm-runtime": "1.0.0"
|
|
77
|
+
},
|
|
78
|
+
"scripts": {
|
|
79
|
+
"build": "tsup",
|
|
80
|
+
"build:watch": "tsup --watch",
|
|
81
|
+
"dev": "tsup --watch",
|
|
82
|
+
"clean": "rimraf dist .tsbuildinfo",
|
|
83
|
+
"test": "vitest run",
|
|
84
|
+
"test:watch": "vitest",
|
|
85
|
+
"test:coverage": "vitest run --coverage",
|
|
86
|
+
"type-check": "tsc --noEmit",
|
|
87
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
88
|
+
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|
|
89
|
+
"format": "prettier --write \"src/**/*.{ts,tsx,json,md}\"",
|
|
90
|
+
"format:check": "prettier --check \"src/**/*.{ts,tsx,json,md}\""
|
|
91
|
+
}
|
|
92
|
+
}
|