@o3co/auth.policy-verifier.cedar-wasm 0.0.1 → 0.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/dist/index.d.mts +3 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +15 -0
- package/dist/wasmEngine.d.mts +24 -0
- package/dist/wasmEngine.d.mts.map +1 -0
- package/dist/wasmEngine.mjs +57 -0
- package/package.json +3 -3
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAiBA,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 1o1 Co. Ltd.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { registerCedarEngine } from "@o3co/auth.policy-verifier.cedar";
|
|
4
|
+
import { cedarWasmEngine } from "./wasmEngine.mjs";
|
|
5
|
+
/*
|
|
6
|
+
* Registered here, at module scope: importing this package is all a
|
|
7
|
+
* deployment does to make `engine = "wasm"` — and the engine-less default —
|
|
8
|
+
* resolve to the in-process evaluator. An import runs this module body to
|
|
9
|
+
* completion before anything that imported it continues, and `createApp`
|
|
10
|
+
* builds no collector until every module is initialized, so the registration
|
|
11
|
+
* is in place before the first `CedarPolicyRuleCollector` is constructed. The
|
|
12
|
+
* same shape, and the same reasoning, as cedar's attribute key reservation.
|
|
13
|
+
*/
|
|
14
|
+
registerCedarEngine(cedarWasmEngine);
|
|
15
|
+
export { CEDAR_WASM_ENGINE_NAME, cedarWasmEngine } from "./wasmEngine.mjs";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type CedarEngine, type PolicySource, type SyncCedarPolicySet } from "@o3co/auth.policy-verifier.cedar";
|
|
2
|
+
/** The name this engine registers under, and the config value that selects it. */
|
|
3
|
+
export declare const CEDAR_WASM_ENGINE_NAME: "wasm";
|
|
4
|
+
/** The wasm engine's own type: it loads synchronously and answers synchronously. */
|
|
5
|
+
export interface CedarWasmEngine extends CedarEngine {
|
|
6
|
+
readonly name: typeof CEDAR_WASM_ENGINE_NAME;
|
|
7
|
+
load(source: PolicySource): SyncCedarPolicySet;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The in-process Cedar engine: the official `@cedar-policy/cedar-wasm`
|
|
11
|
+
* bindings behind the `CedarEngine` port.
|
|
12
|
+
*
|
|
13
|
+
* `load` parse-checks every file individually — so a syntax error names the
|
|
14
|
+
* file that contains it — then compiles the concatenated set once, at boot,
|
|
15
|
+
* into wasm memory under a per-load id. `isAuthorized` references that id per
|
|
16
|
+
* request and re-parses nothing; the call is synchronous, deterministic, and a
|
|
17
|
+
* few tens of microseconds, so the policy set answers as a plain `Rule`.
|
|
18
|
+
*
|
|
19
|
+
* What this engine costs is paid at import: the wasm module (about 12 MB on
|
|
20
|
+
* disk) is instantiated when the bindings load. That is why it lives in its
|
|
21
|
+
* own package — a deployment that evaluates out of process never carries it.
|
|
22
|
+
*/
|
|
23
|
+
export declare const cedarWasmEngine: CedarWasmEngine;
|
|
24
|
+
//# sourceMappingURL=wasmEngine.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasmEngine.d.mts","sourceRoot":"","sources":["../src/wasmEngine.mts"],"names":[],"mappings":"AASA,OAAO,EAEN,KAAK,WAAW,EAGhB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,MAAM,kCAAkC,CAAC;AAE1C,kFAAkF;AAClF,eAAO,MAAM,sBAAsB,EAAG,MAAe,CAAC;AAEtD,oFAAoF;AACpF,MAAM,WAAW,eAAgB,SAAQ,WAAW;IACnD,QAAQ,CAAC,IAAI,EAAE,OAAO,sBAAsB,CAAC;IAC7C,IAAI,CAAC,MAAM,EAAE,YAAY,GAAG,kBAAkB,CAAC;CAC/C;AAKD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe,EAAE,eAsC7B,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 1o1 Co. Ltd.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { checkParsePolicySet, preparsePolicySet, statefulIsAuthorized, } from "@cedar-policy/cedar-wasm/nodejs";
|
|
4
|
+
import { CedarEngineError, } from "@o3co/auth.policy-verifier.cedar";
|
|
5
|
+
/** The name this engine registers under, and the config value that selects it. */
|
|
6
|
+
export const CEDAR_WASM_ENGINE_NAME = "wasm";
|
|
7
|
+
/** Distinguishes concurrently-loaded policy sets inside the one wasm instance. */
|
|
8
|
+
let policySetCounter = 0;
|
|
9
|
+
/**
|
|
10
|
+
* The in-process Cedar engine: the official `@cedar-policy/cedar-wasm`
|
|
11
|
+
* bindings behind the `CedarEngine` port.
|
|
12
|
+
*
|
|
13
|
+
* `load` parse-checks every file individually — so a syntax error names the
|
|
14
|
+
* file that contains it — then compiles the concatenated set once, at boot,
|
|
15
|
+
* into wasm memory under a per-load id. `isAuthorized` references that id per
|
|
16
|
+
* request and re-parses nothing; the call is synchronous, deterministic, and a
|
|
17
|
+
* few tens of microseconds, so the policy set answers as a plain `Rule`.
|
|
18
|
+
*
|
|
19
|
+
* What this engine costs is paid at import: the wasm module (about 12 MB on
|
|
20
|
+
* disk) is instantiated when the bindings load. That is why it lives in its
|
|
21
|
+
* own package — a deployment that evaluates out of process never carries it.
|
|
22
|
+
*/
|
|
23
|
+
export const cedarWasmEngine = {
|
|
24
|
+
name: CEDAR_WASM_ENGINE_NAME,
|
|
25
|
+
async: false,
|
|
26
|
+
load(source) {
|
|
27
|
+
for (const file of source.files) {
|
|
28
|
+
const answer = checkParsePolicySet({ staticPolicies: file.text });
|
|
29
|
+
if (answer.type === "failure") {
|
|
30
|
+
throw new CedarEngineError(`${file.source} failed to parse: ${details(answer.errors)}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const policySetId = `auth.policy-verifier.cedar-wasm:${policySetCounter++}`;
|
|
34
|
+
const compiled = preparsePolicySet(policySetId, { staticPolicies: source.text });
|
|
35
|
+
if (compiled.type === "failure") {
|
|
36
|
+
throw new CedarEngineError(`policy set from ${source.description} failed to compile: ${details(compiled.errors)}`);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
async: false,
|
|
40
|
+
isAuthorized(request) {
|
|
41
|
+
const answer = statefulIsAuthorized({ ...request, preparsedPolicySetId: policySetId });
|
|
42
|
+
if (answer.type !== "success") {
|
|
43
|
+
throw new CedarEngineError(`cedar-wasm could not evaluate the request: ${details(answer.errors)}`);
|
|
44
|
+
}
|
|
45
|
+
const { decision, diagnostics } = answer.response;
|
|
46
|
+
return {
|
|
47
|
+
decision,
|
|
48
|
+
reason: diagnostics.reason,
|
|
49
|
+
errors: diagnostics.errors.map((error) => `${error.policyId}: ${error.error.message}`),
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
function details(errors) {
|
|
56
|
+
return errors.map((error) => error.message).join("; ");
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@o3co/auth.policy-verifier.cedar-wasm",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@cedar-policy/cedar-wasm": "4.12.0",
|
|
29
|
-
"@o3co/auth.policy-verifier.cedar": "0.
|
|
29
|
+
"@o3co/auth.policy-verifier.cedar": "0.11.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "^26.5.1",
|
|
33
33
|
"@vitest/coverage-v8": "^5.0.0",
|
|
34
34
|
"vitest": "^5.0.0",
|
|
35
|
-
"@o3co/auth.policy-verifier.core": "0.
|
|
35
|
+
"@o3co/auth.policy-verifier.core": "0.11.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"prebuild": "rimraf dist",
|