@cedar-policy/cedar-wasm 4.5.1 → 4.6.1

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;
@@ -135,23 +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);
165
+ return ret;
166
+ }
167
+
168
+ /**
169
+ * Preparse and cache a policy set in thread-local storage
170
+ *
171
+ * # Errors
172
+ *
173
+ * Will return `Err` if the input cannot be parsed. Side-effect free on error.
174
+ * @param {string} pset_id
175
+ * @param {PolicySet} policies
176
+ * @returns {CheckParseAnswer}
177
+ */
178
+ export function preparsePolicySet(pset_id, policies) {
179
+ const ptr0 = passStringToWasm0(pset_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
180
+ const len0 = WASM_VECTOR_LEN;
181
+ const ret = wasm.preparsePolicySet(ptr0, len0, policies);
182
+ return ret;
183
+ }
184
+
185
+ /**
186
+ * Basic interface, using [`AuthorizationCall`] and [`AuthorizationAnswer`] types
187
+ * @param {AuthorizationCall} call
188
+ * @returns {AuthorizationAnswer}
189
+ */
190
+ export function isAuthorized(call) {
191
+ const ret = wasm.isAuthorized(call);
192
+ return ret;
193
+ }
194
+
195
+ /**
196
+ * Stateful authorization using preparsed schemas and policy sets.
197
+ *
198
+ * This function works like [`is_authorized`] but retrieves schemas and policy sets
199
+ * from thread-local cache instead of parsing them on each call.
200
+ * @param {StatefulAuthorizationCall} call
201
+ * @returns {AuthorizationAnswer}
202
+ */
203
+ export function statefulIsAuthorized(call) {
204
+ const ret = wasm.statefulIsAuthorized(call);
205
+ return ret;
206
+ }
207
+
208
+ /**
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
215
+ * @param {Schema} schema
216
+ * @returns {CheckParseAnswer}
217
+ */
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);
155
222
  return ret;
156
223
  }
157
224
 
@@ -196,32 +263,32 @@ export function checkParseContext(call) {
196
263
  }
197
264
 
198
265
  /**
199
- * Apply the Cedar policy formatter to a policy set in the Cedar policy format
200
- * @param {FormattingCall} call
201
- * @returns {FormattingAnswer}
266
+ * Return the Cedar (textual) representation of a policy.
267
+ * @param {Policy} policy
268
+ * @returns {PolicyToTextAnswer}
202
269
  */
203
- export function formatPolicies(call) {
204
- const ret = wasm.formatPolicies(call);
270
+ export function policyToText(policy) {
271
+ const ret = wasm.policyToText(policy);
205
272
  return ret;
206
273
  }
207
274
 
208
275
  /**
209
- * Return the Cedar (textual) representation of a template.
210
- * @param {Template} template
211
- * @returns {PolicyToTextAnswer}
276
+ * Return the Cedar (textual) representation of a schema.
277
+ * @param {Schema} schema
278
+ * @returns {SchemaToTextAnswer}
212
279
  */
213
- export function templateToText(template) {
214
- const ret = wasm.templateToText(template);
280
+ export function schemaToText(schema) {
281
+ const ret = wasm.schemaToText(schema);
215
282
  return ret;
216
283
  }
217
284
 
218
285
  /**
219
- * Return the JSON representation of a policy.
220
- * @param {Policy} policy
286
+ * Return the JSON representation of a template.
287
+ * @param {Template} template
221
288
  * @returns {PolicyToJsonAnswer}
222
289
  */
223
- export function policyToJson(policy) {
224
- const ret = wasm.policyToJson(policy);
290
+ export function templateToJson(template) {
291
+ const ret = wasm.templateToJson(template);
225
292
  return ret;
226
293
  }
227
294
 
@@ -249,32 +316,49 @@ export function schemaToJson(schema) {
249
316
  }
250
317
 
251
318
  /**
252
- * Return the Cedar (textual) representation of a schema.
253
- * @param {Schema} schema
254
- * @returns {SchemaToTextAnswer}
319
+ * Return the JSON representation of a policy.
320
+ * @param {Policy} policy
321
+ * @returns {PolicyToJsonAnswer}
255
322
  */
256
- export function schemaToText(schema) {
257
- const ret = wasm.schemaToText(schema);
323
+ export function policyToJson(policy) {
324
+ const ret = wasm.policyToJson(policy);
258
325
  return ret;
259
326
  }
260
327
 
261
328
  /**
262
- * Return the Cedar (textual) representation of a policy.
263
- * @param {Policy} policy
329
+ * Return the Cedar (textual) representation of a template.
330
+ * @param {Template} template
264
331
  * @returns {PolicyToTextAnswer}
265
332
  */
266
- export function policyToText(policy) {
267
- const ret = wasm.policyToText(policy);
333
+ export function templateToText(template) {
334
+ const ret = wasm.templateToText(template);
268
335
  return ret;
269
336
  }
270
337
 
271
338
  /**
272
- * Return the JSON representation of a template.
273
- * @param {Template} template
274
- * @returns {PolicyToJsonAnswer}
339
+ * Get language version of Cedar
340
+ * @returns {string}
275
341
  */
276
- export function templateToJson(template) {
277
- const ret = wasm.templateToJson(template);
342
+ export function getCedarLangVersion() {
343
+ let deferred1_0;
344
+ let deferred1_1;
345
+ try {
346
+ const ret = wasm.getCedarLangVersion();
347
+ deferred1_0 = ret[0];
348
+ deferred1_1 = ret[1];
349
+ return getStringFromWasm0(ret[0], ret[1]);
350
+ } finally {
351
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
352
+ }
353
+ }
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);
278
362
  return ret;
279
363
  }
280
364
 
@@ -291,32 +375,7 @@ export function validate(call) {
291
375
  return ret;
292
376
  }
293
377
 
294
- /**
295
- * Basic interface, using [`AuthorizationCall`] and [`AuthorizationAnswer`] types
296
- * @param {AuthorizationCall} call
297
- * @returns {AuthorizationAnswer}
298
- */
299
- export function isAuthorized(call) {
300
- const ret = wasm.isAuthorized(call);
301
- return ret;
302
- }
303
-
304
- /**
305
- * Get language version of Cedar
306
- * @returns {string}
307
- */
308
- export function getCedarLangVersion() {
309
- let deferred1_0;
310
- let deferred1_1;
311
- try {
312
- const ret = wasm.getCedarLangVersion();
313
- deferred1_0 = ret[0];
314
- deferred1_1 = ret[1];
315
- return getStringFromWasm0(ret[0], ret[1]);
316
- } finally {
317
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
318
- }
319
- }
378
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
320
379
 
321
380
  async function __wbg_load(module, imports) {
322
381
  if (typeof Response === 'function' && module instanceof Response) {
@@ -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.6.1",
6
6
  "license": "Apache-2.0",
7
7
  "files": [
8
8
  "cedar_wasm_bg.wasm",