@cedar-policy/cedar-wasm 3.2.1 → 3.2.3

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.
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "@cedar-policy/cedar-wasm",
3
+ "description": "Wasm bindings and typescript types for Cedar lib",
4
+ "version": "3.2.3",
5
+ "license": "Apache-2.0",
6
+ "files": [
7
+ "cedar_wasm_bg.wasm",
8
+ "cedar_wasm.js",
9
+ "cedar_wasm.d.ts"
10
+ ],
11
+ "main": "cedar_wasm.js",
12
+ "types": "cedar_wasm.d.ts",
13
+ "type": "commonjs"
14
+ }
package/package.json CHANGED
@@ -1,12 +1,28 @@
1
1
  {
2
2
  "name": "@cedar-policy/cedar-wasm",
3
- "description": "WASM bindings and typescript types for Cedar lib",
4
- "version": "3.2.1",
3
+ "description": "Wasm bindings and typescript types for Cedar lib",
4
+ "version": "3.2.3",
5
5
  "license": "Apache-2.0",
6
6
  "files": [
7
- "esm/*",
8
- "nodejs/*",
9
- "web/*"
7
+ "esm/package.json",
8
+ "esm/README.md",
9
+ "esm/cedar_wasm_bg.wasm",
10
+ "esm/cedar_wasm_bg.wasm.d.ts",
11
+ "esm/cedar_wasm.js",
12
+ "esm/cedar_wasm_bg.js",
13
+ "esm/cedar_wasm.d.ts",
14
+ "nodejs/package.json",
15
+ "nodejs/README.md",
16
+ "nodejs/cedar_wasm_bg.wasm",
17
+ "nodejs/cedar_wasm_bg.wasm.d.ts",
18
+ "nodejs/cedar_wasm.js",
19
+ "nodejs/cedar_wasm.d.ts",
20
+ "web/package.json",
21
+ "web/README.md",
22
+ "web/cedar_wasm_bg.wasm",
23
+ "web/cedar_wasm_bg.wasm.d.ts",
24
+ "web/cedar_wasm.js",
25
+ "web/cedar_wasm.d.ts"
10
26
  ],
11
27
  "module": "esm/cedar_wasm.js",
12
28
  "types": "esm/cedar_wasm.d.ts",
@@ -15,16 +31,16 @@
15
31
  ],
16
32
  "exports": {
17
33
  ".": {
18
- "import": "esm/cedar_wasm.js",
19
- "types": "esm/cedar_wasm.d.ts"
34
+ "import": "./esm/cedar_wasm.js",
35
+ "types": "./esm/cedar_wasm.d.ts"
20
36
  },
21
37
  "./nodejs": {
22
- "import": "nodejs/cedar_wasm.js",
23
- "types": "nodejs/cedar_wasm.d.ts"
38
+ "require": "./nodejs/cedar_wasm.js",
39
+ "types": "./nodejs/cedar_wasm.d.ts"
24
40
  },
25
41
  "./web": {
26
- "import": "web/cedar_wasm.js",
27
- "types": "web/cedar_wasm.d.ts"
42
+ "import": "./web/cedar_wasm.js",
43
+ "types": "./web/cedar_wasm.d.ts"
28
44
  }
29
45
  }
30
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'),
@@ -0,0 +1,313 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * @param {string} json_str
5
+ * @returns {JsonToPolicyResult}
6
+ */
7
+ export function policyTextFromJson(json_str: string): JsonToPolicyResult;
8
+ /**
9
+ * @param {string} cedar_str
10
+ * @returns {PolicyToJsonResult}
11
+ */
12
+ export function policyTextToJson(cedar_str: string): PolicyToJsonResult;
13
+ /**
14
+ * @param {string} input_policies_str
15
+ * @returns {CheckParsePolicySetResult}
16
+ */
17
+ export function checkParsePolicySet(input_policies_str: string): CheckParsePolicySetResult;
18
+ /**
19
+ * @param {string} template_str
20
+ * @returns {CheckParseTemplateResult}
21
+ */
22
+ export function checkParseTemplate(template_str: string): CheckParseTemplateResult;
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
+ /**
31
+ * @param {string} input_schema
32
+ * @returns {CheckParseResult}
33
+ */
34
+ export function checkParseSchema(input_schema: string): CheckParseResult;
35
+ /**
36
+ * @param {string} entities_str
37
+ * @param {string} schema_str
38
+ * @returns {CheckParseResult}
39
+ */
40
+ export function checkParseEntities(entities_str: string, schema_str: string): CheckParseResult;
41
+ /**
42
+ * @param {string} context_str
43
+ * @param {string} action_str
44
+ * @param {string} schema_str
45
+ * @returns {CheckParseResult}
46
+ */
47
+ export function checkParseContext(context_str: string, action_str: string, schema_str: string): CheckParseResult;
48
+ /**
49
+ * @param {AuthorizationCall} call
50
+ * @returns {AuthorizationAnswer}
51
+ */
52
+ export function isAuthorized(call: AuthorizationCall): AuthorizationAnswer;
53
+ /**
54
+ * @param {ValidationCall} call
55
+ * @returns {ValidationAnswer}
56
+ */
57
+ export function validate(call: ValidationCall): ValidationAnswer;
58
+ /**
59
+ * @returns {string}
60
+ */
61
+ export function getCedarVersion(): string;
62
+ export type JsonToPolicyResult = { type: "success"; policyText: string } | { type: "error"; errors: string[] };
63
+
64
+ export type PolicyToJsonResult = { type: "success"; policy: Policy } | { type: "error"; errors: string[] };
65
+
66
+ export type CheckParsePolicySetResult = { type: "success"; policies: number; templates: number } | { type: "error"; errors: string[] };
67
+
68
+ export type CheckParseTemplateResult = { type: "success"; slots: string[] } | { type: "error"; errors: string[] };
69
+
70
+ export type FormattingResult = { type: "success"; formatted_policy: string } | { type: "error"; errors: string[] };
71
+
72
+ export type CheckParseResult = { type: "success" } | { type: "error"; errors: string[] };
73
+
74
+ export type ValidationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; validationErrors: ValidationError[]; validationWarnings: ValidationError[]; otherWarnings: DetailedError[] };
75
+
76
+ export interface ValidationError {
77
+ policyId: SmolStr;
78
+ error: DetailedError;
79
+ }
80
+
81
+ export type ValidationEnabled = "on" | "off";
82
+
83
+ export interface ValidationSettings {
84
+ enabled: ValidationEnabled;
85
+ }
86
+
87
+ export interface ValidationCall {
88
+ validationSettings?: ValidationSettings;
89
+ schema: Schema;
90
+ policySet: PolicySet;
91
+ }
92
+
93
+ export interface RecvdSlice {
94
+ policies: PolicySet;
95
+ entities: Array<EntityJson>;
96
+ templates?: Record<string, string> | null;
97
+ templateInstantiations: TemplateLink[] | null;
98
+ }
99
+
100
+ export type Links = Link[];
101
+
102
+ export interface TemplateLink {
103
+ templateId: string;
104
+ resultPolicyId: string;
105
+ instantiations: Links;
106
+ }
107
+
108
+ export interface Link {
109
+ slot: string;
110
+ value: EntityUIDStrings;
111
+ }
112
+
113
+ export interface EntityUIDStrings {
114
+ ty: string;
115
+ eid: string;
116
+ }
117
+
118
+ export interface AuthorizationCall {
119
+ principal: {type: string, id: string};
120
+ action: {type: string, id: string};
121
+ resource: {type: string, id: string};
122
+ context: Record<string, CedarValueJson>;
123
+ schema?: Schema;
124
+ enableRequestValidation?: boolean;
125
+ slice: RecvdSlice;
126
+ }
127
+
128
+ export type AuthorizationAnswer = { type: "failure"; errors: DetailedError[]; warnings: DetailedError[] } | { type: "success"; response: Response; warnings: DetailedError[] };
129
+
130
+ export interface AuthorizationError {
131
+ policyId: SmolStr;
132
+ error: DetailedError;
133
+ }
134
+
135
+ export interface Diagnostics {
136
+ reason: Set<String>;
137
+ errors: AuthorizationError[];
138
+ }
139
+
140
+ export interface Response {
141
+ decision: Decision;
142
+ diagnostics: Diagnostics;
143
+ }
144
+
145
+ export type Schema = { human: string } | { json: SchemaJson };
146
+
147
+ export type PolicySet = string | Record<string, string>;
148
+
149
+ export interface SourceLocation {
150
+ start: number;
151
+ end: number;
152
+ }
153
+
154
+ export interface SourceLabel extends SourceLocation {
155
+ label: string | null;
156
+ }
157
+
158
+ export type Severity = "advice" | "warning" | "error";
159
+
160
+ export interface DetailedError {
161
+ message: string;
162
+ help: string | null;
163
+ code: string | null;
164
+ url: string | null;
165
+ severity: Severity | null;
166
+ sourceLocations?: SourceLabel[];
167
+ related?: DetailedError[];
168
+ }
169
+
170
+ export type SchemaTypeVariant = { type: "String" } | { type: "Long" } | { type: "Boolean" } | { type: "Set"; element: SchemaType } | { type: "Record"; attributes: Record<SmolStr, TypeOfAttribute>; additionalAttributes: boolean } | { type: "Entity"; name: Name } | { type: "Extension"; name: Id };
171
+
172
+ export type SchemaType = SchemaTypeVariant | { type: Name };
173
+
174
+ export interface ActionEntityUID {
175
+ id: SmolStr;
176
+ type?: Name;
177
+ }
178
+
179
+ export interface ApplySpec {
180
+ resourceTypes?: Name[];
181
+ principalTypes?: Name[];
182
+ context?: AttributesOrContext;
183
+ }
184
+
185
+ export interface ActionType {
186
+ attributes?: Record<SmolStr, CedarValueJson>;
187
+ appliesTo?: ApplySpec;
188
+ memberOf?: ActionEntityUID[];
189
+ }
190
+
191
+ export type AttributesOrContext = SchemaType;
192
+
193
+ export interface EntityType {
194
+ memberOfTypes?: Name[];
195
+ shape?: AttributesOrContext;
196
+ }
197
+
198
+ export interface NamespaceDefinition {
199
+ commonTypes?: Record<Id, SchemaType>;
200
+ entityTypes: Record<Id, EntityType>;
201
+ actions: Record<SmolStr, ActionType>;
202
+ }
203
+
204
+ export type SchemaJson = Record<string, NamespaceDefinition>;
205
+
206
+ export type ActionInConstraint = { entity: EntityUidJson } | { entities: EntityUidJson[] };
207
+
208
+ export interface PrincipalOrResourceIsConstraint {
209
+ entity_type: string;
210
+ in?: PrincipalOrResourceInConstraint;
211
+ }
212
+
213
+ export type PrincipalOrResourceInConstraint = { entity: EntityUidJson } | { slot: string };
214
+
215
+ export type EqConstraint = { entity: EntityUidJson } | { slot: string };
216
+
217
+ export type ResourceConstraint = { op: "All" } | ({ op: "==" } & EqConstraint) | ({ op: "in" } & PrincipalOrResourceInConstraint) | ({ op: "is" } & PrincipalOrResourceIsConstraint);
218
+
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
+ }
228
+
229
+ export type Clause = { kind: "when"; body: Expr } | { kind: "unless"; body: Expr };
230
+
231
+ export interface Policy {
232
+ effect: Effect;
233
+ principal: PrincipalConstraint;
234
+ action: ActionConstraint;
235
+ resource: ResourceConstraint;
236
+ conditions: Clause[];
237
+ annotations?: Record<string, string>;
238
+ }
239
+
240
+ export type Effect = "permit" | "forbid";
241
+
242
+ export type EntityUidJson = { __expr: string } | { __entity: TypeAndId } | TypeAndId;
243
+
244
+ export interface FnAndArg {
245
+ fn: string;
246
+ arg: CedarValueJson;
247
+ }
248
+
249
+ export interface TypeAndId {
250
+ type: string;
251
+ id: string;
252
+ }
253
+
254
+ export type CedarValueJson = { __expr: string } | { __entity: TypeAndId } | { __extn: FnAndArg } | boolean | number | string | CedarValueJson[] | { [key: string]: CedarValueJson } | null;
255
+
256
+ export type Decision = "Allow" | "Deny";
257
+
258
+ export type ExtFuncCall = {} & Record<string, Array<Expr>>;
259
+
260
+ 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> };
261
+
262
+ export type Expr = ExprNoExt | ExtFuncCall;
263
+
264
+ export type Var = "principal" | "action" | "resource" | "context";
265
+
266
+
267
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
268
+
269
+ export interface InitOutput {
270
+ readonly memory: WebAssembly.Memory;
271
+ readonly policyTextFromJson: (a: number, b: number) => number;
272
+ readonly policyTextToJson: (a: number, b: number) => number;
273
+ readonly checkParsePolicySet: (a: number, b: number) => number;
274
+ readonly checkParseTemplate: (a: number, b: number) => number;
275
+ readonly formatPolicies: (a: number, b: number, c: number, d: number) => number;
276
+ readonly checkParseSchema: (a: number, b: number) => number;
277
+ readonly checkParseEntities: (a: number, b: number, c: number, d: number) => number;
278
+ readonly checkParseContext: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
279
+ readonly isAuthorized: (a: number) => number;
280
+ readonly validate: (a: number) => number;
281
+ readonly getCedarVersion: (a: number) => void;
282
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
283
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
284
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
285
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
286
+ readonly __wbindgen_exn_store: (a: number) => void;
287
+ }
288
+
289
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
290
+ /**
291
+ * Instantiates the given `module`, which can either be bytes or
292
+ * a precompiled `WebAssembly.Module`.
293
+ *
294
+ * @param {SyncInitInput} module
295
+ *
296
+ * @returns {InitOutput}
297
+ */
298
+ export function initSync(module: SyncInitInput): InitOutput;
299
+
300
+ /**
301
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
302
+ * for everything else, calls `WebAssembly.instantiate` directly.
303
+ *
304
+ * @param {InitInput | Promise<InitInput>} module_or_path
305
+ *
306
+ * @returns {Promise<InitOutput>}
307
+ */
308
+ export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
309
+ type SmolStr = string;
310
+ type Name = string;
311
+ type Id = string;
312
+ export type TypeOfAttribute = SchemaType & { required?: boolean };
313
+ export type Context = Record<string, CedarValueJson>;