@cedar-policy/cedar-wasm 3.2.2 → 3.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,6 +6,33 @@ An implementation of various cedar functions to enable developers to write types
6
6
 
7
7
  Installing is simple, just run `npm i @cedar-policy/cedar-wasm --save` or install with whatever your favorite package manager is.
8
8
 
9
+ Loading is much more complicated. It depends on your environment. We offer three subpackages:
10
+
11
+ * es modules (default). It loads wasm in a way that will be bundled into a single file if you use dynamic imports, or embedded into your main bundle if you use regular imports.
12
+ * commonjs (for node). It loads wasm using node's `fs` module, synchronously. Not really designed for bundling or shipping to the browser.
13
+ * web: more customizable. This one is for when you need to load the wasm in some totally custom way. More details in the "alternate loading strategies" section.
14
+
15
+ These sub-packages are named `@cedar-policy/cedar-wasm`, `@cedar-policy/cedar-wasm/nodejs`, and `@cedar-policy/cedar-wasm/web`, respectively.
16
+
17
+ ## Loading in bare nodeJs without a bundler
18
+
19
+ Node uses CommonJs so you have to import with require, or with dynamic `import()`.
20
+
21
+ Importing the CJS export:
22
+
23
+ ```
24
+ const cedar = require('@cedar-policy/cedar-wasm/nodejs');
25
+ console.log(cedar.getCedarVersion());
26
+ ```
27
+
28
+ Importing the esm version using esm async import:
29
+
30
+ ```
31
+ import('@cedar-policy/cedar-wasm')
32
+ .then(cedar => console.log(cedar.getCedarVersion()));
33
+ ```
34
+
35
+
9
36
  ## Loading in webpack 5:
10
37
 
11
38
  Minimal package.json for webpack including dev server:
@@ -32,7 +59,8 @@ Minimal package.json for webpack including dev server:
32
59
  "typescript": "^5.4.5",
33
60
  "webpack": "^5.91.0",
34
61
  "webpack-cli": "^5.1.4",
35
- "webpack-dev-server": "^5.0.4"
62
+ "webpack-dev-server": "^5.0.4",
63
+ "html-webpack-plugin": "^5.6.0"
36
64
  }
37
65
  }
38
66
  ```
@@ -57,6 +85,7 @@ Configure webpack.config.js:
57
85
 
58
86
  ```
59
87
  const path = require('path');
88
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
60
89
 
61
90
  module.exports = {
62
91
  mode: 'development', // change this to suit you
@@ -79,7 +108,8 @@ module.exports = {
79
108
  },
80
109
  experiments: {
81
110
  asyncWebAssembly: true, // enables wasm support in webpack
82
- },
111
+ },
112
+ plugins: [new HtmlWebpackPlugin()],
83
113
  devServer: {
84
114
  static: {
85
115
  directory: path.join(__dirname, 'dist'),
package/esm/README.md CHANGED
@@ -6,6 +6,33 @@ An implementation of various cedar functions to enable developers to write types
6
6
 
7
7
  Installing is simple, just run `npm i @cedar-policy/cedar-wasm --save` or install with whatever your favorite package manager is.
8
8
 
9
+ Loading is much more complicated. It depends on your environment. We offer three subpackages:
10
+
11
+ * es modules (default). It loads wasm in a way that will be bundled into a single file if you use dynamic imports, or embedded into your main bundle if you use regular imports.
12
+ * commonjs (for node). It loads wasm using node's `fs` module, synchronously. Not really designed for bundling or shipping to the browser.
13
+ * web: more customizable. This one is for when you need to load the wasm in some totally custom way. More details in the "alternate loading strategies" section.
14
+
15
+ These sub-packages are named `@cedar-policy/cedar-wasm`, `@cedar-policy/cedar-wasm/nodejs`, and `@cedar-policy/cedar-wasm/web`, respectively.
16
+
17
+ ## Loading in bare nodeJs without a bundler
18
+
19
+ Node uses CommonJs so you have to import with require, or with dynamic `import()`.
20
+
21
+ Importing the CJS export:
22
+
23
+ ```
24
+ const cedar = require('@cedar-policy/cedar-wasm/nodejs');
25
+ console.log(cedar.getCedarVersion());
26
+ ```
27
+
28
+ Importing the esm version using esm async import:
29
+
30
+ ```
31
+ import('@cedar-policy/cedar-wasm')
32
+ .then(cedar => console.log(cedar.getCedarVersion()));
33
+ ```
34
+
35
+
9
36
  ## Loading in webpack 5:
10
37
 
11
38
  Minimal package.json for webpack including dev server:
@@ -32,7 +59,8 @@ Minimal package.json for webpack including dev server:
32
59
  "typescript": "^5.4.5",
33
60
  "webpack": "^5.91.0",
34
61
  "webpack-cli": "^5.1.4",
35
- "webpack-dev-server": "^5.0.4"
62
+ "webpack-dev-server": "^5.0.4",
63
+ "html-webpack-plugin": "^5.6.0"
36
64
  }
37
65
  }
38
66
  ```
@@ -57,6 +85,7 @@ Configure webpack.config.js:
57
85
 
58
86
  ```
59
87
  const path = require('path');
88
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
60
89
 
61
90
  module.exports = {
62
91
  mode: 'development', // change this to suit you
@@ -79,7 +108,8 @@ module.exports = {
79
108
  },
80
109
  experiments: {
81
110
  asyncWebAssembly: true, // enables wasm support in webpack
82
- },
111
+ },
112
+ plugins: [new HtmlWebpackPlugin()],
83
113
  devServer: {
84
114
  static: {
85
115
  directory: path.join(__dirname, 'dist'),
@@ -21,6 +21,13 @@ export function checkParsePolicySet(input_policies_str: string): CheckParsePolic
21
21
  */
22
22
  export function checkParseTemplate(template_str: string): CheckParseTemplateResult;
23
23
  /**
24
+ * @param {string} policies_str
25
+ * @param {number} line_width
26
+ * @param {number} indent_width
27
+ * @returns {FormattingResult}
28
+ */
29
+ export function formatPolicies(policies_str: string, line_width: number, indent_width: number): FormattingResult;
30
+ /**
24
31
  * @param {string} input_schema
25
32
  * @returns {CheckParseResult}
26
33
  */
@@ -39,17 +46,6 @@ export function checkParseEntities(entities_str: string, schema_str: string): Ch
39
46
  */
40
47
  export function checkParseContext(context_str: string, action_str: string, schema_str: string): CheckParseResult;
41
48
  /**
42
- * @param {string} policies_str
43
- * @param {number} line_width
44
- * @param {number} indent_width
45
- * @returns {FormattingResult}
46
- */
47
- export function formatPolicies(policies_str: string, line_width: number, indent_width: number): FormattingResult;
48
- /**
49
- * @returns {string}
50
- */
51
- export function getCedarVersion(): string;
52
- /**
53
49
  * @param {AuthorizationCall} call
54
50
  * @returns {AuthorizationAnswer}
55
51
  */
@@ -59,6 +55,10 @@ export function isAuthorized(call: AuthorizationCall): AuthorizationAnswer;
59
55
  * @returns {ValidationAnswer}
60
56
  */
61
57
  export function validate(call: ValidationCall): ValidationAnswer;
58
+ /**
59
+ * @returns {string}
60
+ */
61
+ export function getCedarVersion(): string;
62
62
  export type JsonToPolicyResult = { type: "success"; policyText: string } | { type: "error"; errors: string[] };
63
63
 
64
64
  export type PolicyToJsonResult = { type: "success"; policy: Policy } | { type: "error"; errors: string[] };
@@ -67,10 +67,10 @@ export type CheckParsePolicySetResult = { type: "success"; policies: number; tem
67
67
 
68
68
  export type CheckParseTemplateResult = { type: "success"; slots: string[] } | { type: "error"; errors: string[] };
69
69
 
70
- export type CheckParseResult = { type: "success" } | { type: "error"; errors: string[] };
71
-
72
70
  export type FormattingResult = { type: "success"; formatted_policy: string } | { type: "error"; errors: string[] };
73
71
 
72
+ export type CheckParseResult = { type: "success" } | { type: "error"; errors: string[] };
73
+
74
74
  export type Schema = { human: string } | { json: SchemaJson };
75
75
 
76
76
  export type PolicySet = string | Record<string, string>;
@@ -203,23 +203,28 @@ export interface NamespaceDefinition {
203
203
 
204
204
  export type SchemaJson = Record<string, NamespaceDefinition>;
205
205
 
206
- export type EntityUidJson = { __expr: string } | { __entity: TypeAndId } | TypeAndId;
206
+ export type ActionInConstraint = { entity: EntityUidJson } | { entities: EntityUidJson[] };
207
207
 
208
- export interface FnAndArg {
209
- fn: string;
210
- arg: CedarValueJson;
208
+ export interface PrincipalOrResourceIsConstraint {
209
+ entity_type: string;
210
+ in?: PrincipalOrResourceInConstraint;
211
211
  }
212
212
 
213
- export interface TypeAndId {
214
- type: string;
215
- id: string;
216
- }
213
+ export type PrincipalOrResourceInConstraint = { entity: EntityUidJson } | { slot: string };
217
214
 
218
- export type CedarValueJson = { __expr: string } | { __entity: TypeAndId } | { __extn: FnAndArg } | boolean | number | string | CedarValueJson[] | { [key: string]: CedarValueJson } | null;
215
+ export type EqConstraint = { entity: EntityUidJson } | { slot: string };
219
216
 
220
- export type Var = "principal" | "action" | "resource" | "context";
217
+ export type ResourceConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
221
218
 
222
- export type Effect = "permit" | "forbid";
219
+ export type ActionConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & ActionInConstraint);
220
+
221
+ export type PrincipalConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
222
+
223
+ export interface EntityJson {
224
+ uid: EntityUidJson;
225
+ attrs: Record<string, CedarValueJson>;
226
+ parents: EntityUidJson[];
227
+ }
223
228
 
224
229
  export type Clause = { kind: "when"; body: Expr } | { kind: "unless"; body: Expr };
225
230
 
@@ -232,36 +237,31 @@ export interface Policy {
232
237
  annotations?: Record<string, string>;
233
238
  }
234
239
 
235
- export interface EntityJson {
236
- uid: EntityUidJson;
237
- attrs: Record<string, CedarValueJson>;
238
- parents: EntityUidJson[];
239
- }
240
-
241
- export type Decision = "Allow" | "Deny";
242
-
243
- export type ActionInConstraint = { entity: EntityUidJson } | { entities: EntityUidJson[] };
240
+ export type Effect = "permit" | "forbid";
244
241
 
245
- export interface PrincipalOrResourceIsConstraint {
246
- entity_type: string;
247
- in?: PrincipalOrResourceInConstraint;
248
- }
242
+ export type ExtFuncCall = {} & Record<string, Array<Expr>>;
249
243
 
250
- export type PrincipalOrResourceInConstraint = { entity: EntityUidJson } | { slot: string };
244
+ export type ExprNoExt = { Value: CedarValueJson } | { Var: Var } | { Slot: string } | { Unknown: { name: string } } | { "!": { arg: Expr } } | { neg: { arg: Expr } } | { "==": { left: Expr; right: Expr } } | { "!=": { left: Expr; right: Expr } } | { in: { left: Expr; right: Expr } } | { "<": { left: Expr; right: Expr } } | { "<=": { left: Expr; right: Expr } } | { ">": { left: Expr; right: Expr } } | { ">=": { left: Expr; right: Expr } } | { "&&": { left: Expr; right: Expr } } | { "||": { left: Expr; right: Expr } } | { "+": { left: Expr; right: Expr } } | { "-": { left: Expr; right: Expr } } | { "*": { left: Expr; right: Expr } } | { contains: { left: Expr; right: Expr } } | { containsAll: { left: Expr; right: Expr } } | { containsAny: { left: Expr; right: Expr } } | { ".": { left: Expr; attr: SmolStr } } | { has: { left: Expr; attr: SmolStr } } | { like: { left: Expr; pattern: SmolStr } } | { is: { left: Expr; entity_type: SmolStr; in?: Expr } } | { "if-then-else": { if: Expr; then: Expr; else: Expr } } | { Set: Expr[] } | { Record: Record<string, Expr> };
251
245
 
252
- export type EqConstraint = { entity: EntityUidJson } | { slot: string };
246
+ export type Expr = ExprNoExt | ExtFuncCall;
253
247
 
254
- export type ResourceConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
248
+ export type EntityUidJson = { __expr: string } | { __entity: TypeAndId } | TypeAndId;
255
249
 
256
- export type ActionConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & ActionInConstraint);
250
+ export interface FnAndArg {
251
+ fn: string;
252
+ arg: CedarValueJson;
253
+ }
257
254
 
258
- export type PrincipalConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
255
+ export interface TypeAndId {
256
+ type: string;
257
+ id: string;
258
+ }
259
259
 
260
- export type ExtFuncCall = {} & Record<string, Array<Expr>>;
260
+ export type CedarValueJson = { __expr: string } | { __entity: TypeAndId } | { __extn: FnAndArg } | boolean | number | string | CedarValueJson[] | { [key: string]: CedarValueJson } | null;
261
261
 
262
- export type ExprNoExt = { Value: CedarValueJson } | { Var: Var } | { Slot: string } | { Unknown: { name: string } } | { "!": { arg: Expr } } | { neg: { arg: Expr } } | { "==": { left: Expr; right: Expr } } | { "!=": { left: Expr; right: Expr } } | { in: { left: Expr; right: Expr } } | { "<": { left: Expr; right: Expr } } | { "<=": { left: Expr; right: Expr } } | { ">": { left: Expr; right: Expr } } | { ">=": { left: Expr; right: Expr } } | { "&&": { left: Expr; right: Expr } } | { "||": { left: Expr; right: Expr } } | { "+": { left: Expr; right: Expr } } | { "-": { left: Expr; right: Expr } } | { "*": { left: Expr; right: Expr } } | { contains: { left: Expr; right: Expr } } | { containsAll: { left: Expr; right: Expr } } | { containsAny: { left: Expr; right: Expr } } | { ".": { left: Expr; attr: SmolStr } } | { has: { left: Expr; attr: SmolStr } } | { like: { left: Expr; pattern: SmolStr } } | { is: { left: Expr; entity_type: SmolStr; in?: Expr } } | { "if-then-else": { if: Expr; then: Expr; else: Expr } } | { Set: Expr[] } | { Record: Record<string, Expr> };
262
+ export type Decision = "Allow" | "Deny";
263
263
 
264
- export type Expr = ExprNoExt | ExtFuncCall;
264
+ export type Var = "principal" | "action" | "resource" | "context";
265
265
 
266
266
  type SmolStr = string;
267
267
  type Name = string;
@@ -167,6 +167,19 @@ export function checkParseTemplate(template_str) {
167
167
  return takeObject(ret);
168
168
  }
169
169
 
170
+ /**
171
+ * @param {string} policies_str
172
+ * @param {number} line_width
173
+ * @param {number} indent_width
174
+ * @returns {FormattingResult}
175
+ */
176
+ export function formatPolicies(policies_str, line_width, indent_width) {
177
+ const ptr0 = passStringToWasm0(policies_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
178
+ const len0 = WASM_VECTOR_LEN;
179
+ const ret = wasm.formatPolicies(ptr0, len0, line_width, indent_width);
180
+ return takeObject(ret);
181
+ }
182
+
170
183
  /**
171
184
  * @param {string} input_schema
172
185
  * @returns {CheckParseResult}
@@ -210,15 +223,20 @@ export function checkParseContext(context_str, action_str, schema_str) {
210
223
  }
211
224
 
212
225
  /**
213
- * @param {string} policies_str
214
- * @param {number} line_width
215
- * @param {number} indent_width
216
- * @returns {FormattingResult}
226
+ * @param {AuthorizationCall} call
227
+ * @returns {AuthorizationAnswer}
217
228
  */
218
- export function formatPolicies(policies_str, line_width, indent_width) {
219
- const ptr0 = passStringToWasm0(policies_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
220
- const len0 = WASM_VECTOR_LEN;
221
- const ret = wasm.formatPolicies(ptr0, len0, line_width, indent_width);
229
+ export function isAuthorized(call) {
230
+ const ret = wasm.isAuthorized(addHeapObject(call));
231
+ return takeObject(ret);
232
+ }
233
+
234
+ /**
235
+ * @param {ValidationCall} call
236
+ * @returns {ValidationAnswer}
237
+ */
238
+ export function validate(call) {
239
+ const ret = wasm.validate(addHeapObject(call));
222
240
  return takeObject(ret);
223
241
  }
224
242
 
@@ -242,24 +260,6 @@ export function getCedarVersion() {
242
260
  }
243
261
  }
244
262
 
245
- /**
246
- * @param {AuthorizationCall} call
247
- * @returns {AuthorizationAnswer}
248
- */
249
- export function isAuthorized(call) {
250
- const ret = wasm.isAuthorized(addHeapObject(call));
251
- return takeObject(ret);
252
- }
253
-
254
- /**
255
- * @param {ValidationCall} call
256
- * @returns {ValidationAnswer}
257
- */
258
- export function validate(call) {
259
- const ret = wasm.validate(addHeapObject(call));
260
- return takeObject(ret);
261
- }
262
-
263
263
  function handleError(f, args) {
264
264
  try {
265
265
  return f.apply(this, args);
Binary file
@@ -5,13 +5,13 @@ export function policyTextFromJson(a: number, b: number): number;
5
5
  export function policyTextToJson(a: number, b: number): number;
6
6
  export function checkParsePolicySet(a: number, b: number): number;
7
7
  export function checkParseTemplate(a: number, b: number): number;
8
+ export function formatPolicies(a: number, b: number, c: number, d: number): number;
8
9
  export function checkParseSchema(a: number, b: number): number;
9
10
  export function checkParseEntities(a: number, b: number, c: number, d: number): number;
10
11
  export function checkParseContext(a: number, b: number, c: number, d: number, e: number, f: number): number;
11
- export function formatPolicies(a: number, b: number, c: number, d: number): number;
12
- export function getCedarVersion(a: number): void;
13
12
  export function isAuthorized(a: number): number;
14
13
  export function validate(a: number): number;
14
+ export function getCedarVersion(a: number): void;
15
15
  export function __wbindgen_malloc(a: number, b: number): number;
16
16
  export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number;
17
17
  export function __wbindgen_add_to_stack_pointer(a: number): number;
package/esm/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@cedar-policy/cedar-wasm",
3
3
  "description": "Wasm bindings and typescript types for Cedar lib",
4
- "version": "3.2.2",
4
+ "version": "3.2.4",
5
5
  "license": "Apache-2.0",
6
6
  "files": [
7
7
  "cedar_wasm_bg.wasm",
8
- "cedar_wasm_bg.wasm.d.ts",
9
8
  "cedar_wasm.js",
10
9
  "cedar_wasm_bg.js",
11
10
  "cedar_wasm.d.ts"
package/nodejs/README.md CHANGED
@@ -6,6 +6,33 @@ An implementation of various cedar functions to enable developers to write types
6
6
 
7
7
  Installing is simple, just run `npm i @cedar-policy/cedar-wasm --save` or install with whatever your favorite package manager is.
8
8
 
9
+ Loading is much more complicated. It depends on your environment. We offer three subpackages:
10
+
11
+ * es modules (default). It loads wasm in a way that will be bundled into a single file if you use dynamic imports, or embedded into your main bundle if you use regular imports.
12
+ * commonjs (for node). It loads wasm using node's `fs` module, synchronously. Not really designed for bundling or shipping to the browser.
13
+ * web: more customizable. This one is for when you need to load the wasm in some totally custom way. More details in the "alternate loading strategies" section.
14
+
15
+ These sub-packages are named `@cedar-policy/cedar-wasm`, `@cedar-policy/cedar-wasm/nodejs`, and `@cedar-policy/cedar-wasm/web`, respectively.
16
+
17
+ ## Loading in bare nodeJs without a bundler
18
+
19
+ Node uses CommonJs so you have to import with require, or with dynamic `import()`.
20
+
21
+ Importing the CJS export:
22
+
23
+ ```
24
+ const cedar = require('@cedar-policy/cedar-wasm/nodejs');
25
+ console.log(cedar.getCedarVersion());
26
+ ```
27
+
28
+ Importing the esm version using esm async import:
29
+
30
+ ```
31
+ import('@cedar-policy/cedar-wasm')
32
+ .then(cedar => console.log(cedar.getCedarVersion()));
33
+ ```
34
+
35
+
9
36
  ## Loading in webpack 5:
10
37
 
11
38
  Minimal package.json for webpack including dev server:
@@ -32,7 +59,8 @@ Minimal package.json for webpack including dev server:
32
59
  "typescript": "^5.4.5",
33
60
  "webpack": "^5.91.0",
34
61
  "webpack-cli": "^5.1.4",
35
- "webpack-dev-server": "^5.0.4"
62
+ "webpack-dev-server": "^5.0.4",
63
+ "html-webpack-plugin": "^5.6.0"
36
64
  }
37
65
  }
38
66
  ```
@@ -57,6 +85,7 @@ Configure webpack.config.js:
57
85
 
58
86
  ```
59
87
  const path = require('path');
88
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
60
89
 
61
90
  module.exports = {
62
91
  mode: 'development', // change this to suit you
@@ -79,7 +108,8 @@ module.exports = {
79
108
  },
80
109
  experiments: {
81
110
  asyncWebAssembly: true, // enables wasm support in webpack
82
- },
111
+ },
112
+ plugins: [new HtmlWebpackPlugin()],
83
113
  devServer: {
84
114
  static: {
85
115
  directory: path.join(__dirname, 'dist'),
@@ -21,6 +21,13 @@ export function checkParsePolicySet(input_policies_str: string): CheckParsePolic
21
21
  */
22
22
  export function checkParseTemplate(template_str: string): CheckParseTemplateResult;
23
23
  /**
24
+ * @param {string} policies_str
25
+ * @param {number} line_width
26
+ * @param {number} indent_width
27
+ * @returns {FormattingResult}
28
+ */
29
+ export function formatPolicies(policies_str: string, line_width: number, indent_width: number): FormattingResult;
30
+ /**
24
31
  * @param {string} input_schema
25
32
  * @returns {CheckParseResult}
26
33
  */
@@ -39,17 +46,6 @@ export function checkParseEntities(entities_str: string, schema_str: string): Ch
39
46
  */
40
47
  export function checkParseContext(context_str: string, action_str: string, schema_str: string): CheckParseResult;
41
48
  /**
42
- * @param {string} policies_str
43
- * @param {number} line_width
44
- * @param {number} indent_width
45
- * @returns {FormattingResult}
46
- */
47
- export function formatPolicies(policies_str: string, line_width: number, indent_width: number): FormattingResult;
48
- /**
49
- * @returns {string}
50
- */
51
- export function getCedarVersion(): string;
52
- /**
53
49
  * @param {AuthorizationCall} call
54
50
  * @returns {AuthorizationAnswer}
55
51
  */
@@ -59,6 +55,10 @@ export function isAuthorized(call: AuthorizationCall): AuthorizationAnswer;
59
55
  * @returns {ValidationAnswer}
60
56
  */
61
57
  export function validate(call: ValidationCall): ValidationAnswer;
58
+ /**
59
+ * @returns {string}
60
+ */
61
+ export function getCedarVersion(): string;
62
62
  export type JsonToPolicyResult = { type: "success"; policyText: string } | { type: "error"; errors: string[] };
63
63
 
64
64
  export type PolicyToJsonResult = { type: "success"; policy: Policy } | { type: "error"; errors: string[] };
@@ -67,10 +67,10 @@ export type CheckParsePolicySetResult = { type: "success"; policies: number; tem
67
67
 
68
68
  export type CheckParseTemplateResult = { type: "success"; slots: string[] } | { type: "error"; errors: string[] };
69
69
 
70
- export type CheckParseResult = { type: "success" } | { type: "error"; errors: string[] };
71
-
72
70
  export type FormattingResult = { type: "success"; formatted_policy: string } | { type: "error"; errors: string[] };
73
71
 
72
+ export type CheckParseResult = { type: "success" } | { type: "error"; errors: string[] };
73
+
74
74
  export type Schema = { human: string } | { json: SchemaJson };
75
75
 
76
76
  export type PolicySet = string | Record<string, string>;
@@ -203,23 +203,28 @@ export interface NamespaceDefinition {
203
203
 
204
204
  export type SchemaJson = Record<string, NamespaceDefinition>;
205
205
 
206
- export type EntityUidJson = { __expr: string } | { __entity: TypeAndId } | TypeAndId;
206
+ export type ActionInConstraint = { entity: EntityUidJson } | { entities: EntityUidJson[] };
207
207
 
208
- export interface FnAndArg {
209
- fn: string;
210
- arg: CedarValueJson;
208
+ export interface PrincipalOrResourceIsConstraint {
209
+ entity_type: string;
210
+ in?: PrincipalOrResourceInConstraint;
211
211
  }
212
212
 
213
- export interface TypeAndId {
214
- type: string;
215
- id: string;
216
- }
213
+ export type PrincipalOrResourceInConstraint = { entity: EntityUidJson } | { slot: string };
217
214
 
218
- export type CedarValueJson = { __expr: string } | { __entity: TypeAndId } | { __extn: FnAndArg } | boolean | number | string | CedarValueJson[] | { [key: string]: CedarValueJson } | null;
215
+ export type EqConstraint = { entity: EntityUidJson } | { slot: string };
219
216
 
220
- export type Var = "principal" | "action" | "resource" | "context";
217
+ export type ResourceConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
221
218
 
222
- export type Effect = "permit" | "forbid";
219
+ export type ActionConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & ActionInConstraint);
220
+
221
+ export type PrincipalConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
222
+
223
+ export interface EntityJson {
224
+ uid: EntityUidJson;
225
+ attrs: Record<string, CedarValueJson>;
226
+ parents: EntityUidJson[];
227
+ }
223
228
 
224
229
  export type Clause = { kind: "when"; body: Expr } | { kind: "unless"; body: Expr };
225
230
 
@@ -232,36 +237,31 @@ export interface Policy {
232
237
  annotations?: Record<string, string>;
233
238
  }
234
239
 
235
- export interface EntityJson {
236
- uid: EntityUidJson;
237
- attrs: Record<string, CedarValueJson>;
238
- parents: EntityUidJson[];
239
- }
240
-
241
- export type Decision = "Allow" | "Deny";
242
-
243
- export type ActionInConstraint = { entity: EntityUidJson } | { entities: EntityUidJson[] };
240
+ export type Effect = "permit" | "forbid";
244
241
 
245
- export interface PrincipalOrResourceIsConstraint {
246
- entity_type: string;
247
- in?: PrincipalOrResourceInConstraint;
248
- }
242
+ export type ExtFuncCall = {} & Record<string, Array<Expr>>;
249
243
 
250
- export type PrincipalOrResourceInConstraint = { entity: EntityUidJson } | { slot: string };
244
+ export type ExprNoExt = { Value: CedarValueJson } | { Var: Var } | { Slot: string } | { Unknown: { name: string } } | { "!": { arg: Expr } } | { neg: { arg: Expr } } | { "==": { left: Expr; right: Expr } } | { "!=": { left: Expr; right: Expr } } | { in: { left: Expr; right: Expr } } | { "<": { left: Expr; right: Expr } } | { "<=": { left: Expr; right: Expr } } | { ">": { left: Expr; right: Expr } } | { ">=": { left: Expr; right: Expr } } | { "&&": { left: Expr; right: Expr } } | { "||": { left: Expr; right: Expr } } | { "+": { left: Expr; right: Expr } } | { "-": { left: Expr; right: Expr } } | { "*": { left: Expr; right: Expr } } | { contains: { left: Expr; right: Expr } } | { containsAll: { left: Expr; right: Expr } } | { containsAny: { left: Expr; right: Expr } } | { ".": { left: Expr; attr: SmolStr } } | { has: { left: Expr; attr: SmolStr } } | { like: { left: Expr; pattern: SmolStr } } | { is: { left: Expr; entity_type: SmolStr; in?: Expr } } | { "if-then-else": { if: Expr; then: Expr; else: Expr } } | { Set: Expr[] } | { Record: Record<string, Expr> };
251
245
 
252
- export type EqConstraint = { entity: EntityUidJson } | { slot: string };
246
+ export type Expr = ExprNoExt | ExtFuncCall;
253
247
 
254
- export type ResourceConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
248
+ export type EntityUidJson = { __expr: string } | { __entity: TypeAndId } | TypeAndId;
255
249
 
256
- export type ActionConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & ActionInConstraint);
250
+ export interface FnAndArg {
251
+ fn: string;
252
+ arg: CedarValueJson;
253
+ }
257
254
 
258
- export type PrincipalConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
255
+ export interface TypeAndId {
256
+ type: string;
257
+ id: string;
258
+ }
259
259
 
260
- export type ExtFuncCall = {} & Record<string, Array<Expr>>;
260
+ export type CedarValueJson = { __expr: string } | { __entity: TypeAndId } | { __extn: FnAndArg } | boolean | number | string | CedarValueJson[] | { [key: string]: CedarValueJson } | null;
261
261
 
262
- export type ExprNoExt = { Value: CedarValueJson } | { Var: Var } | { Slot: string } | { Unknown: { name: string } } | { "!": { arg: Expr } } | { neg: { arg: Expr } } | { "==": { left: Expr; right: Expr } } | { "!=": { left: Expr; right: Expr } } | { in: { left: Expr; right: Expr } } | { "<": { left: Expr; right: Expr } } | { "<=": { left: Expr; right: Expr } } | { ">": { left: Expr; right: Expr } } | { ">=": { left: Expr; right: Expr } } | { "&&": { left: Expr; right: Expr } } | { "||": { left: Expr; right: Expr } } | { "+": { left: Expr; right: Expr } } | { "-": { left: Expr; right: Expr } } | { "*": { left: Expr; right: Expr } } | { contains: { left: Expr; right: Expr } } | { containsAll: { left: Expr; right: Expr } } | { containsAny: { left: Expr; right: Expr } } | { ".": { left: Expr; attr: SmolStr } } | { has: { left: Expr; attr: SmolStr } } | { like: { left: Expr; pattern: SmolStr } } | { is: { left: Expr; entity_type: SmolStr; in?: Expr } } | { "if-then-else": { if: Expr; then: Expr; else: Expr } } | { Set: Expr[] } | { Record: Record<string, Expr> };
262
+ export type Decision = "Allow" | "Deny";
263
263
 
264
- export type Expr = ExprNoExt | ExtFuncCall;
264
+ export type Var = "principal" | "action" | "resource" | "context";
265
265
 
266
266
  type SmolStr = string;
267
267
  type Name = string;
@@ -162,6 +162,19 @@ module.exports.checkParseTemplate = function(template_str) {
162
162
  return takeObject(ret);
163
163
  };
164
164
 
165
+ /**
166
+ * @param {string} policies_str
167
+ * @param {number} line_width
168
+ * @param {number} indent_width
169
+ * @returns {FormattingResult}
170
+ */
171
+ module.exports.formatPolicies = function(policies_str, line_width, indent_width) {
172
+ const ptr0 = passStringToWasm0(policies_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
173
+ const len0 = WASM_VECTOR_LEN;
174
+ const ret = wasm.formatPolicies(ptr0, len0, line_width, indent_width);
175
+ return takeObject(ret);
176
+ };
177
+
165
178
  /**
166
179
  * @param {string} input_schema
167
180
  * @returns {CheckParseResult}
@@ -205,15 +218,20 @@ module.exports.checkParseContext = function(context_str, action_str, schema_str)
205
218
  };
206
219
 
207
220
  /**
208
- * @param {string} policies_str
209
- * @param {number} line_width
210
- * @param {number} indent_width
211
- * @returns {FormattingResult}
221
+ * @param {AuthorizationCall} call
222
+ * @returns {AuthorizationAnswer}
212
223
  */
213
- module.exports.formatPolicies = function(policies_str, line_width, indent_width) {
214
- const ptr0 = passStringToWasm0(policies_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
215
- const len0 = WASM_VECTOR_LEN;
216
- const ret = wasm.formatPolicies(ptr0, len0, line_width, indent_width);
224
+ module.exports.isAuthorized = function(call) {
225
+ const ret = wasm.isAuthorized(addHeapObject(call));
226
+ return takeObject(ret);
227
+ };
228
+
229
+ /**
230
+ * @param {ValidationCall} call
231
+ * @returns {ValidationAnswer}
232
+ */
233
+ module.exports.validate = function(call) {
234
+ const ret = wasm.validate(addHeapObject(call));
217
235
  return takeObject(ret);
218
236
  };
219
237
 
@@ -237,24 +255,6 @@ module.exports.getCedarVersion = function() {
237
255
  }
238
256
  };
239
257
 
240
- /**
241
- * @param {AuthorizationCall} call
242
- * @returns {AuthorizationAnswer}
243
- */
244
- module.exports.isAuthorized = function(call) {
245
- const ret = wasm.isAuthorized(addHeapObject(call));
246
- return takeObject(ret);
247
- };
248
-
249
- /**
250
- * @param {ValidationCall} call
251
- * @returns {ValidationAnswer}
252
- */
253
- module.exports.validate = function(call) {
254
- const ret = wasm.validate(addHeapObject(call));
255
- return takeObject(ret);
256
- };
257
-
258
258
  function handleError(f, args) {
259
259
  try {
260
260
  return f.apply(this, args);
Binary file
@@ -5,13 +5,13 @@ export function policyTextFromJson(a: number, b: number): number;
5
5
  export function policyTextToJson(a: number, b: number): number;
6
6
  export function checkParsePolicySet(a: number, b: number): number;
7
7
  export function checkParseTemplate(a: number, b: number): number;
8
+ export function formatPolicies(a: number, b: number, c: number, d: number): number;
8
9
  export function checkParseSchema(a: number, b: number): number;
9
10
  export function checkParseEntities(a: number, b: number, c: number, d: number): number;
10
11
  export function checkParseContext(a: number, b: number, c: number, d: number, e: number, f: number): number;
11
- export function formatPolicies(a: number, b: number, c: number, d: number): number;
12
- export function getCedarVersion(a: number): void;
13
12
  export function isAuthorized(a: number): number;
14
13
  export function validate(a: number): number;
14
+ export function getCedarVersion(a: number): void;
15
15
  export function __wbindgen_malloc(a: number, b: number): number;
16
16
  export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number;
17
17
  export function __wbindgen_add_to_stack_pointer(a: number): number;
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@cedar-policy/cedar-wasm",
3
3
  "description": "Wasm bindings and typescript types for Cedar lib",
4
- "version": "3.2.2",
4
+ "version": "3.2.4",
5
5
  "license": "Apache-2.0",
6
6
  "files": [
7
7
  "cedar_wasm_bg.wasm",
8
- "cedar_wasm_bg.wasm.d.ts",
9
8
  "cedar_wasm.js",
10
9
  "cedar_wasm.d.ts"
11
10
  ],
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cedar-policy/cedar-wasm",
3
3
  "description": "Wasm bindings and typescript types for Cedar lib",
4
- "version": "3.2.2",
4
+ "version": "3.2.4",
5
5
  "license": "Apache-2.0",
6
6
  "files": [
7
7
  "esm/package.json",
@@ -31,16 +31,16 @@
31
31
  ],
32
32
  "exports": {
33
33
  ".": {
34
- "import": "esm/cedar_wasm.js",
35
- "types": "esm/cedar_wasm.d.ts"
34
+ "import": "./esm/cedar_wasm.js",
35
+ "types": "./esm/cedar_wasm.d.ts"
36
36
  },
37
37
  "./nodejs": {
38
- "import": "nodejs/cedar_wasm.js",
39
- "types": "nodejs/cedar_wasm.d.ts"
38
+ "require": "./nodejs/cedar_wasm.js",
39
+ "types": "./nodejs/cedar_wasm.d.ts"
40
40
  },
41
41
  "./web": {
42
- "import": "web/cedar_wasm.js",
43
- "types": "web/cedar_wasm.d.ts"
42
+ "import": "./web/cedar_wasm.js",
43
+ "types": "./web/cedar_wasm.d.ts"
44
44
  }
45
45
  }
46
46
  }
package/web/README.md CHANGED
@@ -6,6 +6,33 @@ An implementation of various cedar functions to enable developers to write types
6
6
 
7
7
  Installing is simple, just run `npm i @cedar-policy/cedar-wasm --save` or install with whatever your favorite package manager is.
8
8
 
9
+ Loading is much more complicated. It depends on your environment. We offer three subpackages:
10
+
11
+ * es modules (default). It loads wasm in a way that will be bundled into a single file if you use dynamic imports, or embedded into your main bundle if you use regular imports.
12
+ * commonjs (for node). It loads wasm using node's `fs` module, synchronously. Not really designed for bundling or shipping to the browser.
13
+ * web: more customizable. This one is for when you need to load the wasm in some totally custom way. More details in the "alternate loading strategies" section.
14
+
15
+ These sub-packages are named `@cedar-policy/cedar-wasm`, `@cedar-policy/cedar-wasm/nodejs`, and `@cedar-policy/cedar-wasm/web`, respectively.
16
+
17
+ ## Loading in bare nodeJs without a bundler
18
+
19
+ Node uses CommonJs so you have to import with require, or with dynamic `import()`.
20
+
21
+ Importing the CJS export:
22
+
23
+ ```
24
+ const cedar = require('@cedar-policy/cedar-wasm/nodejs');
25
+ console.log(cedar.getCedarVersion());
26
+ ```
27
+
28
+ Importing the esm version using esm async import:
29
+
30
+ ```
31
+ import('@cedar-policy/cedar-wasm')
32
+ .then(cedar => console.log(cedar.getCedarVersion()));
33
+ ```
34
+
35
+
9
36
  ## Loading in webpack 5:
10
37
 
11
38
  Minimal package.json for webpack including dev server:
@@ -32,7 +59,8 @@ Minimal package.json for webpack including dev server:
32
59
  "typescript": "^5.4.5",
33
60
  "webpack": "^5.91.0",
34
61
  "webpack-cli": "^5.1.4",
35
- "webpack-dev-server": "^5.0.4"
62
+ "webpack-dev-server": "^5.0.4",
63
+ "html-webpack-plugin": "^5.6.0"
36
64
  }
37
65
  }
38
66
  ```
@@ -57,6 +85,7 @@ Configure webpack.config.js:
57
85
 
58
86
  ```
59
87
  const path = require('path');
88
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
60
89
 
61
90
  module.exports = {
62
91
  mode: 'development', // change this to suit you
@@ -79,7 +108,8 @@ module.exports = {
79
108
  },
80
109
  experiments: {
81
110
  asyncWebAssembly: true, // enables wasm support in webpack
82
- },
111
+ },
112
+ plugins: [new HtmlWebpackPlugin()],
83
113
  devServer: {
84
114
  static: {
85
115
  directory: path.join(__dirname, 'dist'),
@@ -21,6 +21,13 @@ export function checkParsePolicySet(input_policies_str: string): CheckParsePolic
21
21
  */
22
22
  export function checkParseTemplate(template_str: string): CheckParseTemplateResult;
23
23
  /**
24
+ * @param {string} policies_str
25
+ * @param {number} line_width
26
+ * @param {number} indent_width
27
+ * @returns {FormattingResult}
28
+ */
29
+ export function formatPolicies(policies_str: string, line_width: number, indent_width: number): FormattingResult;
30
+ /**
24
31
  * @param {string} input_schema
25
32
  * @returns {CheckParseResult}
26
33
  */
@@ -39,17 +46,6 @@ export function checkParseEntities(entities_str: string, schema_str: string): Ch
39
46
  */
40
47
  export function checkParseContext(context_str: string, action_str: string, schema_str: string): CheckParseResult;
41
48
  /**
42
- * @param {string} policies_str
43
- * @param {number} line_width
44
- * @param {number} indent_width
45
- * @returns {FormattingResult}
46
- */
47
- export function formatPolicies(policies_str: string, line_width: number, indent_width: number): FormattingResult;
48
- /**
49
- * @returns {string}
50
- */
51
- export function getCedarVersion(): string;
52
- /**
53
49
  * @param {AuthorizationCall} call
54
50
  * @returns {AuthorizationAnswer}
55
51
  */
@@ -59,6 +55,10 @@ export function isAuthorized(call: AuthorizationCall): AuthorizationAnswer;
59
55
  * @returns {ValidationAnswer}
60
56
  */
61
57
  export function validate(call: ValidationCall): ValidationAnswer;
58
+ /**
59
+ * @returns {string}
60
+ */
61
+ export function getCedarVersion(): string;
62
62
  export type JsonToPolicyResult = { type: "success"; policyText: string } | { type: "error"; errors: string[] };
63
63
 
64
64
  export type PolicyToJsonResult = { type: "success"; policy: Policy } | { type: "error"; errors: string[] };
@@ -67,10 +67,10 @@ export type CheckParsePolicySetResult = { type: "success"; policies: number; tem
67
67
 
68
68
  export type CheckParseTemplateResult = { type: "success"; slots: string[] } | { type: "error"; errors: string[] };
69
69
 
70
- export type CheckParseResult = { type: "success" } | { type: "error"; errors: string[] };
71
-
72
70
  export type FormattingResult = { type: "success"; formatted_policy: string } | { type: "error"; errors: string[] };
73
71
 
72
+ export type CheckParseResult = { type: "success" } | { type: "error"; errors: string[] };
73
+
74
74
  export type Schema = { human: string } | { json: SchemaJson };
75
75
 
76
76
  export type PolicySet = string | Record<string, string>;
@@ -203,23 +203,28 @@ export interface NamespaceDefinition {
203
203
 
204
204
  export type SchemaJson = Record<string, NamespaceDefinition>;
205
205
 
206
- export type EntityUidJson = { __expr: string } | { __entity: TypeAndId } | TypeAndId;
206
+ export type ActionInConstraint = { entity: EntityUidJson } | { entities: EntityUidJson[] };
207
207
 
208
- export interface FnAndArg {
209
- fn: string;
210
- arg: CedarValueJson;
208
+ export interface PrincipalOrResourceIsConstraint {
209
+ entity_type: string;
210
+ in?: PrincipalOrResourceInConstraint;
211
211
  }
212
212
 
213
- export interface TypeAndId {
214
- type: string;
215
- id: string;
216
- }
213
+ export type PrincipalOrResourceInConstraint = { entity: EntityUidJson } | { slot: string };
217
214
 
218
- export type CedarValueJson = { __expr: string } | { __entity: TypeAndId } | { __extn: FnAndArg } | boolean | number | string | CedarValueJson[] | { [key: string]: CedarValueJson } | null;
215
+ export type EqConstraint = { entity: EntityUidJson } | { slot: string };
219
216
 
220
- export type Var = "principal" | "action" | "resource" | "context";
217
+ export type ResourceConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
221
218
 
222
- export type Effect = "permit" | "forbid";
219
+ export type ActionConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & ActionInConstraint);
220
+
221
+ export type PrincipalConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
222
+
223
+ export interface EntityJson {
224
+ uid: EntityUidJson;
225
+ attrs: Record<string, CedarValueJson>;
226
+ parents: EntityUidJson[];
227
+ }
223
228
 
224
229
  export type Clause = { kind: "when"; body: Expr } | { kind: "unless"; body: Expr };
225
230
 
@@ -232,36 +237,31 @@ export interface Policy {
232
237
  annotations?: Record<string, string>;
233
238
  }
234
239
 
235
- export interface EntityJson {
236
- uid: EntityUidJson;
237
- attrs: Record<string, CedarValueJson>;
238
- parents: EntityUidJson[];
239
- }
240
-
241
- export type Decision = "Allow" | "Deny";
242
-
243
- export type ActionInConstraint = { entity: EntityUidJson } | { entities: EntityUidJson[] };
240
+ export type Effect = "permit" | "forbid";
244
241
 
245
- export interface PrincipalOrResourceIsConstraint {
246
- entity_type: string;
247
- in?: PrincipalOrResourceInConstraint;
248
- }
242
+ export type ExtFuncCall = {} & Record<string, Array<Expr>>;
249
243
 
250
- export type PrincipalOrResourceInConstraint = { entity: EntityUidJson } | { slot: string };
244
+ export type ExprNoExt = { Value: CedarValueJson } | { Var: Var } | { Slot: string } | { Unknown: { name: string } } | { "!": { arg: Expr } } | { neg: { arg: Expr } } | { "==": { left: Expr; right: Expr } } | { "!=": { left: Expr; right: Expr } } | { in: { left: Expr; right: Expr } } | { "<": { left: Expr; right: Expr } } | { "<=": { left: Expr; right: Expr } } | { ">": { left: Expr; right: Expr } } | { ">=": { left: Expr; right: Expr } } | { "&&": { left: Expr; right: Expr } } | { "||": { left: Expr; right: Expr } } | { "+": { left: Expr; right: Expr } } | { "-": { left: Expr; right: Expr } } | { "*": { left: Expr; right: Expr } } | { contains: { left: Expr; right: Expr } } | { containsAll: { left: Expr; right: Expr } } | { containsAny: { left: Expr; right: Expr } } | { ".": { left: Expr; attr: SmolStr } } | { has: { left: Expr; attr: SmolStr } } | { like: { left: Expr; pattern: SmolStr } } | { is: { left: Expr; entity_type: SmolStr; in?: Expr } } | { "if-then-else": { if: Expr; then: Expr; else: Expr } } | { Set: Expr[] } | { Record: Record<string, Expr> };
251
245
 
252
- export type EqConstraint = { entity: EntityUidJson } | { slot: string };
246
+ export type Expr = ExprNoExt | ExtFuncCall;
253
247
 
254
- export type ResourceConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
248
+ export type EntityUidJson = { __expr: string } | { __entity: TypeAndId } | TypeAndId;
255
249
 
256
- export type ActionConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & ActionInConstraint);
250
+ export interface FnAndArg {
251
+ fn: string;
252
+ arg: CedarValueJson;
253
+ }
257
254
 
258
- export type PrincipalConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
255
+ export interface TypeAndId {
256
+ type: string;
257
+ id: string;
258
+ }
259
259
 
260
- export type ExtFuncCall = {} & Record<string, Array<Expr>>;
260
+ export type CedarValueJson = { __expr: string } | { __entity: TypeAndId } | { __extn: FnAndArg } | boolean | number | string | CedarValueJson[] | { [key: string]: CedarValueJson } | null;
261
261
 
262
- export type ExprNoExt = { Value: CedarValueJson } | { Var: Var } | { Slot: string } | { Unknown: { name: string } } | { "!": { arg: Expr } } | { neg: { arg: Expr } } | { "==": { left: Expr; right: Expr } } | { "!=": { left: Expr; right: Expr } } | { in: { left: Expr; right: Expr } } | { "<": { left: Expr; right: Expr } } | { "<=": { left: Expr; right: Expr } } | { ">": { left: Expr; right: Expr } } | { ">=": { left: Expr; right: Expr } } | { "&&": { left: Expr; right: Expr } } | { "||": { left: Expr; right: Expr } } | { "+": { left: Expr; right: Expr } } | { "-": { left: Expr; right: Expr } } | { "*": { left: Expr; right: Expr } } | { contains: { left: Expr; right: Expr } } | { containsAll: { left: Expr; right: Expr } } | { containsAny: { left: Expr; right: Expr } } | { ".": { left: Expr; attr: SmolStr } } | { has: { left: Expr; attr: SmolStr } } | { like: { left: Expr; pattern: SmolStr } } | { is: { left: Expr; entity_type: SmolStr; in?: Expr } } | { "if-then-else": { if: Expr; then: Expr; else: Expr } } | { Set: Expr[] } | { Record: Record<string, Expr> };
262
+ export type Decision = "Allow" | "Deny";
263
263
 
264
- export type Expr = ExprNoExt | ExtFuncCall;
264
+ export type Var = "principal" | "action" | "resource" | "context";
265
265
 
266
266
 
267
267
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
@@ -272,13 +272,13 @@ export interface InitOutput {
272
272
  readonly policyTextToJson: (a: number, b: number) => number;
273
273
  readonly checkParsePolicySet: (a: number, b: number) => number;
274
274
  readonly checkParseTemplate: (a: number, b: number) => number;
275
+ readonly formatPolicies: (a: number, b: number, c: number, d: number) => number;
275
276
  readonly checkParseSchema: (a: number, b: number) => number;
276
277
  readonly checkParseEntities: (a: number, b: number, c: number, d: number) => number;
277
278
  readonly checkParseContext: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
278
- readonly formatPolicies: (a: number, b: number, c: number, d: number) => number;
279
- readonly getCedarVersion: (a: number) => void;
280
279
  readonly isAuthorized: (a: number) => number;
281
280
  readonly validate: (a: number) => number;
281
+ readonly getCedarVersion: (a: number) => void;
282
282
  readonly __wbindgen_malloc: (a: number, b: number) => number;
283
283
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
284
284
  readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
package/web/cedar_wasm.js CHANGED
@@ -159,6 +159,19 @@ export function checkParseTemplate(template_str) {
159
159
  return takeObject(ret);
160
160
  }
161
161
 
162
+ /**
163
+ * @param {string} policies_str
164
+ * @param {number} line_width
165
+ * @param {number} indent_width
166
+ * @returns {FormattingResult}
167
+ */
168
+ export function formatPolicies(policies_str, line_width, indent_width) {
169
+ const ptr0 = passStringToWasm0(policies_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
170
+ const len0 = WASM_VECTOR_LEN;
171
+ const ret = wasm.formatPolicies(ptr0, len0, line_width, indent_width);
172
+ return takeObject(ret);
173
+ }
174
+
162
175
  /**
163
176
  * @param {string} input_schema
164
177
  * @returns {CheckParseResult}
@@ -202,15 +215,20 @@ export function checkParseContext(context_str, action_str, schema_str) {
202
215
  }
203
216
 
204
217
  /**
205
- * @param {string} policies_str
206
- * @param {number} line_width
207
- * @param {number} indent_width
208
- * @returns {FormattingResult}
218
+ * @param {AuthorizationCall} call
219
+ * @returns {AuthorizationAnswer}
209
220
  */
210
- export function formatPolicies(policies_str, line_width, indent_width) {
211
- const ptr0 = passStringToWasm0(policies_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
212
- const len0 = WASM_VECTOR_LEN;
213
- const ret = wasm.formatPolicies(ptr0, len0, line_width, indent_width);
221
+ export function isAuthorized(call) {
222
+ const ret = wasm.isAuthorized(addHeapObject(call));
223
+ return takeObject(ret);
224
+ }
225
+
226
+ /**
227
+ * @param {ValidationCall} call
228
+ * @returns {ValidationAnswer}
229
+ */
230
+ export function validate(call) {
231
+ const ret = wasm.validate(addHeapObject(call));
214
232
  return takeObject(ret);
215
233
  }
216
234
 
@@ -234,24 +252,6 @@ export function getCedarVersion() {
234
252
  }
235
253
  }
236
254
 
237
- /**
238
- * @param {AuthorizationCall} call
239
- * @returns {AuthorizationAnswer}
240
- */
241
- export function isAuthorized(call) {
242
- const ret = wasm.isAuthorized(addHeapObject(call));
243
- return takeObject(ret);
244
- }
245
-
246
- /**
247
- * @param {ValidationCall} call
248
- * @returns {ValidationAnswer}
249
- */
250
- export function validate(call) {
251
- const ret = wasm.validate(addHeapObject(call));
252
- return takeObject(ret);
253
- }
254
-
255
255
  function handleError(f, args) {
256
256
  try {
257
257
  return f.apply(this, args);
Binary file
@@ -5,13 +5,13 @@ export function policyTextFromJson(a: number, b: number): number;
5
5
  export function policyTextToJson(a: number, b: number): number;
6
6
  export function checkParsePolicySet(a: number, b: number): number;
7
7
  export function checkParseTemplate(a: number, b: number): number;
8
+ export function formatPolicies(a: number, b: number, c: number, d: number): number;
8
9
  export function checkParseSchema(a: number, b: number): number;
9
10
  export function checkParseEntities(a: number, b: number, c: number, d: number): number;
10
11
  export function checkParseContext(a: number, b: number, c: number, d: number, e: number, f: number): number;
11
- export function formatPolicies(a: number, b: number, c: number, d: number): number;
12
- export function getCedarVersion(a: number): void;
13
12
  export function isAuthorized(a: number): number;
14
13
  export function validate(a: number): number;
14
+ export function getCedarVersion(a: number): void;
15
15
  export function __wbindgen_malloc(a: number, b: number): number;
16
16
  export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number;
17
17
  export function __wbindgen_add_to_stack_pointer(a: number): number;
package/web/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@cedar-policy/cedar-wasm",
3
3
  "description": "Wasm bindings and typescript types for Cedar lib",
4
- "version": "3.2.2",
4
+ "version": "3.2.4",
5
5
  "license": "Apache-2.0",
6
6
  "files": [
7
7
  "cedar_wasm_bg.wasm",
8
- "cedar_wasm_bg.wasm.d.ts",
9
8
  "cedar_wasm.js",
10
9
  "cedar_wasm.d.ts"
11
10
  ],