@cedar-policy/cedar-wasm 4.5.1 → 4.7.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/web/cedar_wasm.js CHANGED
@@ -1,9 +1,5 @@
1
1
  let wasm;
2
2
 
3
- const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
4
-
5
- if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
6
-
7
3
  let cachedUint8ArrayMemory0 = null;
8
4
 
9
5
  function getUint8ArrayMemory0() {
@@ -13,9 +9,25 @@ function getUint8ArrayMemory0() {
13
9
  return cachedUint8ArrayMemory0;
14
10
  }
15
11
 
12
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
13
+
14
+ cachedTextDecoder.decode();
15
+
16
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
17
+ let numBytesDecoded = 0;
18
+ function decodeText(ptr, len) {
19
+ numBytesDecoded += len;
20
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
21
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
22
+ cachedTextDecoder.decode();
23
+ numBytesDecoded = len;
24
+ }
25
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
26
+ }
27
+
16
28
  function getStringFromWasm0(ptr, len) {
17
29
  ptr = ptr >>> 0;
18
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
30
+ return decodeText(ptr, len);
19
31
  }
20
32
 
21
33
  function addToExternrefTable0(obj) {
@@ -35,20 +47,18 @@ function handleError(f, args) {
35
47
 
36
48
  let WASM_VECTOR_LEN = 0;
37
49
 
38
- const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
50
+ const cachedTextEncoder = new TextEncoder();
39
51
 
40
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
41
- ? function (arg, view) {
42
- return cachedTextEncoder.encodeInto(arg, view);
52
+ if (!('encodeInto' in cachedTextEncoder)) {
53
+ cachedTextEncoder.encodeInto = function (arg, view) {
54
+ const buf = cachedTextEncoder.encode(arg);
55
+ view.set(buf);
56
+ return {
57
+ read: arg.length,
58
+ written: buf.length
59
+ };
60
+ }
43
61
  }
44
- : function (arg, view) {
45
- const buf = cachedTextEncoder.encode(arg);
46
- view.set(buf);
47
- return {
48
- read: arg.length,
49
- written: buf.length
50
- };
51
- });
52
62
 
53
63
  function passStringToWasm0(arg, malloc, realloc) {
54
64
 
@@ -79,7 +89,7 @@ function passStringToWasm0(arg, malloc, realloc) {
79
89
  }
80
90
  ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
81
91
  const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
82
- const ret = encodeString(arg, view);
92
+ const ret = cachedTextEncoder.encodeInto(arg, view);
83
93
 
84
94
  offset += ret.written;
85
95
  ptr = realloc(ptr, len, offset, 1) >>> 0;
@@ -104,11 +114,11 @@ function getDataViewMemory0() {
104
114
  /**
105
115
  * @returns {string}
106
116
  */
107
- export function getCedarVersion() {
117
+ export function getCedarSDKVersion() {
108
118
  let deferred1_0;
109
119
  let deferred1_1;
110
120
  try {
111
- const ret = wasm.getCedarVersion();
121
+ const ret = wasm.getCedarSDKVersion();
112
122
  deferred1_0 = ret[0];
113
123
  deferred1_1 = ret[1];
114
124
  return getStringFromWasm0(ret[0], ret[1]);
@@ -120,11 +130,11 @@ export function getCedarVersion() {
120
130
  /**
121
131
  * @returns {string}
122
132
  */
123
- export function getCedarSDKVersion() {
133
+ export function getCedarVersion() {
124
134
  let deferred1_0;
125
135
  let deferred1_1;
126
136
  try {
127
- const ret = wasm.getCedarSDKVersion();
137
+ const ret = wasm.getCedarVersion();
128
138
  deferred1_0 = ret[0];
129
139
  deferred1_1 = ret[1];
130
140
  return getStringFromWasm0(ret[0], ret[1]);
@@ -135,43 +145,80 @@ export function getCedarSDKVersion() {
135
145
 
136
146
  /**
137
147
  * Get valid request environment
138
- * @param {Template} t
148
+ * @param {Policy} t
139
149
  * @param {Schema} s
140
150
  * @returns {GetValidRequestEnvsResult}
141
151
  */
142
- export function getValidRequestEnvsTemplate(t, s) {
143
- const ret = wasm.getValidRequestEnvsTemplate(t, s);
152
+ export function getValidRequestEnvsPolicy(t, s) {
153
+ const ret = wasm.getValidRequestEnvsPolicy(t, s);
144
154
  return ret;
145
155
  }
146
156
 
147
157
  /**
148
158
  * Get valid request environment
149
- * @param {Policy} t
159
+ * @param {Template} t
150
160
  * @param {Schema} s
151
161
  * @returns {GetValidRequestEnvsResult}
152
162
  */
153
- export function getValidRequestEnvsPolicy(t, s) {
154
- const ret = wasm.getValidRequestEnvsPolicy(t, s);
163
+ export function getValidRequestEnvsTemplate(t, s) {
164
+ const ret = wasm.getValidRequestEnvsTemplate(t, s);
155
165
  return ret;
156
166
  }
157
167
 
158
168
  /**
159
- * Check whether a set of entities successfully parses.
160
- * @param {EntitiesParsingCall} call
169
+ * Stateful authorization using preparsed schemas and policy sets.
170
+ *
171
+ * This function works like [`is_authorized`] but retrieves schemas and policy sets
172
+ * from thread-local cache instead of parsing them on each call.
173
+ * @param {StatefulAuthorizationCall} call
174
+ * @returns {AuthorizationAnswer}
175
+ */
176
+ export function statefulIsAuthorized(call) {
177
+ const ret = wasm.statefulIsAuthorized(call);
178
+ return ret;
179
+ }
180
+
181
+ /**
182
+ * Basic interface, using [`AuthorizationCall`] and [`AuthorizationAnswer`] types
183
+ * @param {AuthorizationCall} call
184
+ * @returns {AuthorizationAnswer}
185
+ */
186
+ export function isAuthorized(call) {
187
+ const ret = wasm.isAuthorized(call);
188
+ return ret;
189
+ }
190
+
191
+ /**
192
+ * Preparse and cache a policy set in thread-local storage
193
+ *
194
+ * # Errors
195
+ *
196
+ * Will return `Err` if the input cannot be parsed. Side-effect free on error.
197
+ * @param {string} pset_id
198
+ * @param {PolicySet} policies
161
199
  * @returns {CheckParseAnswer}
162
200
  */
163
- export function checkParseEntities(call) {
164
- const ret = wasm.checkParseEntities(call);
201
+ export function preparsePolicySet(pset_id, policies) {
202
+ const ptr0 = passStringToWasm0(pset_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
203
+ const len0 = WASM_VECTOR_LEN;
204
+ const ret = wasm.preparsePolicySet(ptr0, len0, policies);
165
205
  return ret;
166
206
  }
167
207
 
168
208
  /**
169
- * Check whether a schema successfully parses.
209
+ * Preparse and cache a schema in thread-local storage
210
+ *
211
+ * # Errors
212
+ *
213
+ * Will return `Err` if the input cannot be parsed. Side-effect free on error.
214
+ * @param {string} schema_name
170
215
  * @param {Schema} schema
171
216
  * @returns {CheckParseAnswer}
172
217
  */
173
- export function checkParseSchema(schema) {
174
- const ret = wasm.checkParseSchema(schema);
218
+ export function preparseSchema(schema_name, schema) {
219
+ const ptr0 = passStringToWasm0(schema_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
220
+ const len0 = WASM_VECTOR_LEN;
221
+ const ret = wasm.preparseSchema(ptr0, len0, schema);
175
222
  return ret;
176
223
  }
177
224
 
@@ -196,32 +243,22 @@ export function checkParseContext(call) {
196
243
  }
197
244
 
198
245
  /**
199
- * Apply the Cedar policy formatter to a policy set in the Cedar policy format
200
- * @param {FormattingCall} call
201
- * @returns {FormattingAnswer}
202
- */
203
- export function formatPolicies(call) {
204
- const ret = wasm.formatPolicies(call);
205
- return ret;
206
- }
207
-
208
- /**
209
- * Return the Cedar (textual) representation of a template.
210
- * @param {Template} template
211
- * @returns {PolicyToTextAnswer}
246
+ * Check whether a schema successfully parses.
247
+ * @param {Schema} schema
248
+ * @returns {CheckParseAnswer}
212
249
  */
213
- export function templateToText(template) {
214
- const ret = wasm.templateToText(template);
250
+ export function checkParseSchema(schema) {
251
+ const ret = wasm.checkParseSchema(schema);
215
252
  return ret;
216
253
  }
217
254
 
218
255
  /**
219
- * Return the JSON representation of a policy.
220
- * @param {Policy} policy
221
- * @returns {PolicyToJsonAnswer}
256
+ * Check whether a set of entities successfully parses.
257
+ * @param {EntitiesParsingCall} call
258
+ * @returns {CheckParseAnswer}
222
259
  */
223
- export function policyToJson(policy) {
224
- const ret = wasm.policyToJson(policy);
260
+ export function checkParseEntities(call) {
261
+ const ret = wasm.checkParseEntities(call);
225
262
  return ret;
226
263
  }
227
264
 
@@ -239,22 +276,12 @@ export function policySetTextToParts(policyset_str) {
239
276
  }
240
277
 
241
278
  /**
242
- * Return the JSON representation of a schema.
243
- * @param {Schema} schema
244
- * @returns {SchemaToJsonAnswer}
245
- */
246
- export function schemaToJson(schema) {
247
- const ret = wasm.schemaToJson(schema);
248
- return ret;
249
- }
250
-
251
- /**
252
- * Return the Cedar (textual) representation of a schema.
253
- * @param {Schema} schema
254
- * @returns {SchemaToTextAnswer}
279
+ * Return the JSON representation of a template.
280
+ * @param {Template} template
281
+ * @returns {PolicyToJsonAnswer}
255
282
  */
256
- export function schemaToText(schema) {
257
- const ret = wasm.schemaToText(schema);
283
+ export function templateToJson(template) {
284
+ const ret = wasm.templateToJson(template);
258
285
  return ret;
259
286
  }
260
287
 
@@ -269,35 +296,42 @@ export function policyToText(policy) {
269
296
  }
270
297
 
271
298
  /**
272
- * Return the JSON representation of a template.
299
+ * Return the JSON representation of a schema.
300
+ * @param {Schema} schema
301
+ * @returns {SchemaToJsonAnswer}
302
+ */
303
+ export function schemaToJson(schema) {
304
+ const ret = wasm.schemaToJson(schema);
305
+ return ret;
306
+ }
307
+
308
+ /**
309
+ * Return the Cedar (textual) representation of a template.
273
310
  * @param {Template} template
274
- * @returns {PolicyToJsonAnswer}
311
+ * @returns {PolicyToTextAnswer}
275
312
  */
276
- export function templateToJson(template) {
277
- const ret = wasm.templateToJson(template);
313
+ export function templateToText(template) {
314
+ const ret = wasm.templateToText(template);
278
315
  return ret;
279
316
  }
280
317
 
281
318
  /**
282
- * Parse a policy set and optionally validate it against a provided schema
283
- *
284
- * This is the basic validator interface, using [`ValidationCall`] and
285
- * [`ValidationAnswer`] types
286
- * @param {ValidationCall} call
287
- * @returns {ValidationAnswer}
319
+ * Return the JSON representation of a policy.
320
+ * @param {Policy} policy
321
+ * @returns {PolicyToJsonAnswer}
288
322
  */
289
- export function validate(call) {
290
- const ret = wasm.validate(call);
323
+ export function policyToJson(policy) {
324
+ const ret = wasm.policyToJson(policy);
291
325
  return ret;
292
326
  }
293
327
 
294
328
  /**
295
- * Basic interface, using [`AuthorizationCall`] and [`AuthorizationAnswer`] types
296
- * @param {AuthorizationCall} call
297
- * @returns {AuthorizationAnswer}
329
+ * Return the Cedar (textual) representation of a schema.
330
+ * @param {Schema} schema
331
+ * @returns {SchemaToTextAnswer}
298
332
  */
299
- export function isAuthorized(call) {
300
- const ret = wasm.isAuthorized(call);
333
+ export function schemaToText(schema) {
334
+ const ret = wasm.schemaToText(schema);
301
335
  return ret;
302
336
  }
303
337
 
@@ -318,6 +352,31 @@ export function getCedarLangVersion() {
318
352
  }
319
353
  }
320
354
 
355
+ /**
356
+ * Apply the Cedar policy formatter to a policy set in the Cedar policy format
357
+ * @param {FormattingCall} call
358
+ * @returns {FormattingAnswer}
359
+ */
360
+ export function formatPolicies(call) {
361
+ const ret = wasm.formatPolicies(call);
362
+ return ret;
363
+ }
364
+
365
+ /**
366
+ * Parse a policy set and optionally validate it against a provided schema
367
+ *
368
+ * This is the basic validator interface, using [`ValidationCall`] and
369
+ * [`ValidationAnswer`] types
370
+ * @param {ValidationCall} call
371
+ * @returns {ValidationAnswer}
372
+ */
373
+ export function validate(call) {
374
+ const ret = wasm.validate(call);
375
+ return ret;
376
+ }
377
+
378
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
379
+
321
380
  async function __wbg_load(module, imports) {
322
381
  if (typeof Response === 'function' && module instanceof Response) {
323
382
  if (typeof WebAssembly.instantiateStreaming === 'function') {
@@ -325,7 +384,9 @@ async function __wbg_load(module, imports) {
325
384
  return await WebAssembly.instantiateStreaming(module, imports);
326
385
 
327
386
  } catch (e) {
328
- if (module.headers.get('Content-Type') != 'application/wasm') {
387
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
388
+
389
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
329
390
  console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
330
391
 
331
392
  } else {
@@ -352,29 +413,19 @@ async function __wbg_load(module, imports) {
352
413
  function __wbg_get_imports() {
353
414
  const imports = {};
354
415
  imports.wbg = {};
355
- imports.wbg.__wbg_parse_def2e24ef1252aff = function() { return handleError(function (arg0, arg1) {
416
+ imports.wbg.__wbg_parse_442f5ba02e5eaf8b = function() { return handleError(function (arg0, arg1) {
356
417
  const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
357
418
  return ret;
358
419
  }, arguments) };
359
- imports.wbg.__wbg_stringify_f7ed6987935b4a24 = function() { return handleError(function (arg0) {
420
+ imports.wbg.__wbg_stringify_b98c93d0a190446a = function() { return handleError(function (arg0) {
360
421
  const ret = JSON.stringify(arg0);
361
422
  return ret;
362
423
  }, arguments) };
363
- imports.wbg.__wbindgen_init_externref_table = function() {
364
- const table = wasm.__wbindgen_export_2;
365
- const offset = table.grow(4);
366
- table.set(0, undefined);
367
- table.set(offset + 0, undefined);
368
- table.set(offset + 1, null);
369
- table.set(offset + 2, true);
370
- table.set(offset + 3, false);
371
- ;
372
- };
373
- imports.wbg.__wbindgen_is_undefined = function(arg0) {
424
+ imports.wbg.__wbg_wbindgenisundefined_c4b71d073b92f3c5 = function(arg0) {
374
425
  const ret = arg0 === undefined;
375
426
  return ret;
376
427
  };
377
- imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
428
+ imports.wbg.__wbg_wbindgenstringget_0f16a6ddddef376f = function(arg0, arg1) {
378
429
  const obj = arg1;
379
430
  const ret = typeof(obj) === 'string' ? obj : undefined;
380
431
  var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -382,9 +433,19 @@ function __wbg_get_imports() {
382
433
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
383
434
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
384
435
  };
385
- imports.wbg.__wbindgen_throw = function(arg0, arg1) {
436
+ imports.wbg.__wbg_wbindgenthrow_451ec1a8469d7eb6 = function(arg0, arg1) {
386
437
  throw new Error(getStringFromWasm0(arg0, arg1));
387
438
  };
439
+ imports.wbg.__wbindgen_init_externref_table = function() {
440
+ const table = wasm.__wbindgen_export_2;
441
+ const offset = table.grow(4);
442
+ table.set(0, undefined);
443
+ table.set(offset + 0, undefined);
444
+ table.set(offset + 1, null);
445
+ table.set(offset + 2, true);
446
+ table.set(offset + 3, false);
447
+ ;
448
+ };
388
449
 
389
450
  return imports;
390
451
  }
Binary file
@@ -5,11 +5,15 @@ export const getCedarSDKVersion: () => [number, number];
5
5
  export const getValidRequestEnvsPolicy: (a: any, b: any) => any;
6
6
  export const getValidRequestEnvsTemplate: (a: any, b: any) => any;
7
7
  export const getCedarVersion: () => [number, number];
8
+ export const isAuthorized: (a: any) => any;
9
+ export const preparsePolicySet: (a: number, b: number, c: any) => any;
10
+ export const preparseSchema: (a: number, b: number, c: any) => any;
11
+ export const statefulIsAuthorized: (a: any) => any;
8
12
  export const checkParseContext: (a: any) => any;
9
13
  export const checkParseEntities: (a: any) => any;
10
14
  export const checkParsePolicySet: (a: any) => any;
11
15
  export const checkParseSchema: (a: any) => any;
12
- export const formatPolicies: (a: any) => any;
16
+ export const getCedarLangVersion: () => [number, number];
13
17
  export const policySetTextToParts: (a: number, b: number) => any;
14
18
  export const policyToJson: (a: any) => any;
15
19
  export const policyToText: (a: any) => any;
@@ -17,9 +21,8 @@ export const schemaToJson: (a: any) => any;
17
21
  export const schemaToText: (a: any) => any;
18
22
  export const templateToJson: (a: any) => any;
19
23
  export const templateToText: (a: any) => any;
24
+ export const formatPolicies: (a: any) => any;
20
25
  export const validate: (a: any) => any;
21
- export const isAuthorized: (a: any) => any;
22
- export const getCedarLangVersion: () => [number, number];
23
26
  export const __wbindgen_exn_store: (a: number) => void;
24
27
  export const __externref_table_alloc: () => number;
25
28
  export const __wbindgen_export_2: WebAssembly.Table;
package/web/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@cedar-policy/cedar-wasm",
3
3
  "type": "module",
4
4
  "description": "Wasm bindings and typescript types for Cedar lib",
5
- "version": "4.5.1",
5
+ "version": "4.7.0",
6
6
  "license": "Apache-2.0",
7
7
  "files": [
8
8
  "cedar_wasm_bg.wasm",