@janssenproject/cedarling_wasm 0.0.313-nodejs → 0.0.314

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.
@@ -227,3 +227,96 @@ export function init(config: any): Promise<Cedarling>;
227
227
  * ```
228
228
  */
229
229
  export function init_from_archive_bytes(config: any, archive_bytes: Uint8Array): Promise<Cedarling>;
230
+
231
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
232
+
233
+ export interface InitOutput {
234
+ readonly memory: WebAssembly.Memory;
235
+ readonly __wbg_cedarling_free: (a: number, b: number) => void;
236
+ readonly __wbg_multiissuerauthorizeresult_free: (a: number, b: number) => void;
237
+ readonly __wbg_get_multiissuerauthorizeresult_response: (a: number) => number;
238
+ readonly __wbg_set_multiissuerauthorizeresult_response: (a: number, b: number) => void;
239
+ readonly __wbg_get_multiissuerauthorizeresult_decision: (a: number) => number;
240
+ readonly __wbg_set_multiissuerauthorizeresult_decision: (a: number, b: number) => void;
241
+ readonly __wbg_get_multiissuerauthorizeresult_request_id: (a: number) => [number, number];
242
+ readonly __wbg_set_multiissuerauthorizeresult_request_id: (a: number, b: number, c: number) => void;
243
+ readonly multiissuerauthorizeresult_json_string: (a: number) => [number, number];
244
+ readonly init: (a: any) => any;
245
+ readonly init_from_archive_bytes: (a: any, b: any) => any;
246
+ readonly cedarling_new: (a: any) => any;
247
+ readonly cedarling_new_from_map: (a: any) => any;
248
+ readonly cedarling_authorize: (a: number, b: any) => any;
249
+ readonly cedarling_authorize_unsigned: (a: number, b: any) => any;
250
+ readonly cedarling_authorize_multi_issuer: (a: number, b: any) => any;
251
+ readonly cedarling_pop_logs: (a: number) => [number, number, number];
252
+ readonly cedarling_get_log_by_id: (a: number, b: number, c: number) => [number, number, number];
253
+ readonly cedarling_get_log_ids: (a: number) => any;
254
+ readonly cedarling_get_logs_by_tag: (a: number, b: number, c: number) => [number, number, number, number];
255
+ readonly cedarling_get_logs_by_request_id: (a: number, b: number, c: number) => [number, number, number, number];
256
+ readonly cedarling_get_logs_by_request_id_and_tag: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
257
+ readonly cedarling_shut_down: (a: number) => any;
258
+ readonly __wbg_authorizeresult_free: (a: number, b: number) => void;
259
+ readonly __wbg_get_authorizeresult_workload: (a: number) => number;
260
+ readonly __wbg_set_authorizeresult_workload: (a: number, b: number) => void;
261
+ readonly __wbg_get_authorizeresult_person: (a: number) => number;
262
+ readonly __wbg_set_authorizeresult_person: (a: number, b: number) => void;
263
+ readonly __wbg_get_authorizeresult_decision: (a: number) => number;
264
+ readonly __wbg_set_authorizeresult_decision: (a: number, b: number) => void;
265
+ readonly __wbg_get_authorizeresult_request_id: (a: number) => [number, number];
266
+ readonly __wbg_set_authorizeresult_request_id: (a: number, b: number, c: number) => void;
267
+ readonly authorizeresult_json_string: (a: number) => [number, number];
268
+ readonly authorizeresult_principal: (a: number, b: number, c: number) => number;
269
+ readonly __wbg_authorizeresultresponse_free: (a: number, b: number) => void;
270
+ readonly authorizeresultresponse_decision: (a: number) => number;
271
+ readonly authorizeresultresponse_diagnostics: (a: number) => number;
272
+ readonly __wbg_diagnostics_free: (a: number, b: number) => void;
273
+ readonly diagnostics_reason: (a: number) => [number, number];
274
+ readonly diagnostics_errors: (a: number) => [number, number];
275
+ readonly __wbg_policyevaluationerror_free: (a: number, b: number) => void;
276
+ readonly policyevaluationerror_id: (a: number) => [number, number];
277
+ readonly policyevaluationerror_error: (a: number) => [number, number];
278
+ readonly rust_zstd_wasm_shim_qsort: (a: number, b: number, c: number, d: number) => void;
279
+ readonly rust_zstd_wasm_shim_malloc: (a: number) => number;
280
+ readonly rust_zstd_wasm_shim_memcmp: (a: number, b: number, c: number) => number;
281
+ readonly rust_zstd_wasm_shim_calloc: (a: number, b: number) => number;
282
+ readonly rust_zstd_wasm_shim_free: (a: number) => void;
283
+ readonly rust_zstd_wasm_shim_memcpy: (a: number, b: number, c: number) => number;
284
+ readonly rust_zstd_wasm_shim_memmove: (a: number, b: number, c: number) => number;
285
+ readonly rust_zstd_wasm_shim_memset: (a: number, b: number, c: number) => number;
286
+ readonly wasm_bindgen__closure__destroy__hd529f22c34389d0f: (a: number, b: number) => void;
287
+ readonly wasm_bindgen__closure__destroy__h0bd98a3a1d60a5b1: (a: number, b: number) => void;
288
+ readonly wasm_bindgen__convert__closures_____invoke__h826419d66d164abb: (a: number, b: number, c: any) => [number, number];
289
+ readonly wasm_bindgen__convert__closures_____invoke__h494d783032f4344f: (a: number, b: number, c: any, d: any) => void;
290
+ readonly wasm_bindgen__convert__closures_____invoke__hbf3e188fe995424e: (a: number, b: number) => void;
291
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
292
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
293
+ readonly __wbindgen_exn_store: (a: number) => void;
294
+ readonly __externref_table_alloc: () => number;
295
+ readonly __wbindgen_externrefs: WebAssembly.Table;
296
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
297
+ readonly __externref_table_dealloc: (a: number) => void;
298
+ readonly __externref_drop_slice: (a: number, b: number) => void;
299
+ readonly __wbindgen_start: () => void;
300
+ }
301
+
302
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
303
+
304
+ /**
305
+ * Instantiates the given `module`, which can either be bytes or
306
+ * a precompiled `WebAssembly.Module`.
307
+ *
308
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
309
+ *
310
+ * @returns {InitOutput}
311
+ */
312
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
313
+
314
+ /**
315
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
316
+ * for everything else, calls `WebAssembly.instantiate` directly.
317
+ *
318
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
319
+ *
320
+ * @returns {Promise<InitOutput>}
321
+ */
322
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/cedarling_wasm.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * A WASM wrapper for the Rust `cedarling::AuthorizeResult` struct.
5
5
  * Represents the result of an authorization request.
6
6
  */
7
- class AuthorizeResult {
7
+ export class AuthorizeResult {
8
8
  static __wrap(ptr) {
9
9
  ptr = ptr >>> 0;
10
10
  const obj = Object.create(AuthorizeResult.prototype);
@@ -138,13 +138,12 @@ class AuthorizeResult {
138
138
  }
139
139
  }
140
140
  if (Symbol.dispose) AuthorizeResult.prototype[Symbol.dispose] = AuthorizeResult.prototype.free;
141
- exports.AuthorizeResult = AuthorizeResult;
142
141
 
143
142
  /**
144
143
  * A WASM wrapper for the Rust `cedar_policy::Response` struct.
145
144
  * Represents the result of an authorization request.
146
145
  */
147
- class AuthorizeResultResponse {
146
+ export class AuthorizeResultResponse {
148
147
  static __wrap(ptr) {
149
148
  ptr = ptr >>> 0;
150
149
  const obj = Object.create(AuthorizeResultResponse.prototype);
@@ -180,12 +179,11 @@ class AuthorizeResultResponse {
180
179
  }
181
180
  }
182
181
  if (Symbol.dispose) AuthorizeResultResponse.prototype[Symbol.dispose] = AuthorizeResultResponse.prototype.free;
183
- exports.AuthorizeResultResponse = AuthorizeResultResponse;
184
182
 
185
183
  /**
186
184
  * The instance of the Cedarling application.
187
185
  */
188
- class Cedarling {
186
+ export class Cedarling {
189
187
  static __wrap(ptr) {
190
188
  ptr = ptr >>> 0;
191
189
  const obj = Object.create(Cedarling.prototype);
@@ -354,7 +352,6 @@ class Cedarling {
354
352
  }
355
353
  }
356
354
  if (Symbol.dispose) Cedarling.prototype[Symbol.dispose] = Cedarling.prototype.free;
357
- exports.Cedarling = Cedarling;
358
355
 
359
356
  /**
360
357
  * Diagnostics
@@ -362,7 +359,7 @@ exports.Cedarling = Cedarling;
362
359
  *
363
360
  * Provides detailed information about how a policy decision was made, including policies that contributed to the decision and any errors encountered during evaluation.
364
361
  */
365
- class Diagnostics {
362
+ export class Diagnostics {
366
363
  static __wrap(ptr) {
367
364
  ptr = ptr >>> 0;
368
365
  const obj = Object.create(Diagnostics.prototype);
@@ -406,13 +403,12 @@ class Diagnostics {
406
403
  }
407
404
  }
408
405
  if (Symbol.dispose) Diagnostics.prototype[Symbol.dispose] = Diagnostics.prototype.free;
409
- exports.Diagnostics = Diagnostics;
410
406
 
411
407
  /**
412
408
  * A WASM wrapper for the Rust `cedarling::MultiIssuerAuthorizeResult` struct.
413
409
  * Represents the result of a multi-issuer authorization request.
414
410
  */
415
- class MultiIssuerAuthorizeResult {
411
+ export class MultiIssuerAuthorizeResult {
416
412
  static __wrap(ptr) {
417
413
  ptr = ptr >>> 0;
418
414
  const obj = Object.create(MultiIssuerAuthorizeResult.prototype);
@@ -509,7 +505,6 @@ class MultiIssuerAuthorizeResult {
509
505
  }
510
506
  }
511
507
  if (Symbol.dispose) MultiIssuerAuthorizeResult.prototype[Symbol.dispose] = MultiIssuerAuthorizeResult.prototype.free;
512
- exports.MultiIssuerAuthorizeResult = MultiIssuerAuthorizeResult;
513
508
 
514
509
  /**
515
510
  * PolicyEvaluationError
@@ -517,7 +512,7 @@ exports.MultiIssuerAuthorizeResult = MultiIssuerAuthorizeResult;
517
512
  *
518
513
  * Represents an error that occurred when evaluating a Cedar policy.
519
514
  */
520
- class PolicyEvaluationError {
515
+ export class PolicyEvaluationError {
521
516
  static __wrap(ptr) {
522
517
  ptr = ptr >>> 0;
523
518
  const obj = Object.create(PolicyEvaluationError.prototype);
@@ -569,7 +564,6 @@ class PolicyEvaluationError {
569
564
  }
570
565
  }
571
566
  if (Symbol.dispose) PolicyEvaluationError.prototype[Symbol.dispose] = PolicyEvaluationError.prototype.free;
572
- exports.PolicyEvaluationError = PolicyEvaluationError;
573
567
 
574
568
  /**
575
569
  * Create a new instance of the Cedarling application.
@@ -577,11 +571,10 @@ exports.PolicyEvaluationError = PolicyEvaluationError;
577
571
  * @param {any} config
578
572
  * @returns {Promise<Cedarling>}
579
573
  */
580
- function init(config) {
574
+ export function init(config) {
581
575
  const ret = wasm.init(config);
582
576
  return ret;
583
577
  }
584
- exports.init = init;
585
578
 
586
579
  /**
587
580
  * Create a new instance of the Cedarling application from archive bytes.
@@ -603,11 +596,10 @@ exports.init = init;
603
596
  * @param {Uint8Array} archive_bytes
604
597
  * @returns {Promise<Cedarling>}
605
598
  */
606
- function init_from_archive_bytes(config, archive_bytes) {
599
+ export function init_from_archive_bytes(config, archive_bytes) {
607
600
  const ret = wasm.init_from_archive_bytes(config, archive_bytes);
608
601
  return ret;
609
602
  }
610
- exports.init_from_archive_bytes = init_from_archive_bytes;
611
603
 
612
604
  function __wbg_get_imports() {
613
605
  const import0 = {
@@ -1396,7 +1388,15 @@ function takeFromExternrefTable0(idx) {
1396
1388
 
1397
1389
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1398
1390
  cachedTextDecoder.decode();
1391
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
1392
+ let numBytesDecoded = 0;
1399
1393
  function decodeText(ptr, len) {
1394
+ numBytesDecoded += len;
1395
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
1396
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1397
+ cachedTextDecoder.decode();
1398
+ numBytesDecoded = len;
1399
+ }
1400
1400
  return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
1401
1401
  }
1402
1402
 
@@ -1415,8 +1415,95 @@ if (!('encodeInto' in cachedTextEncoder)) {
1415
1415
 
1416
1416
  let WASM_VECTOR_LEN = 0;
1417
1417
 
1418
- const wasmPath = `${__dirname}/cedarling_wasm_bg.wasm`;
1419
- const wasmBytes = require('fs').readFileSync(wasmPath);
1420
- const wasmModule = new WebAssembly.Module(wasmBytes);
1421
- let wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
1422
- wasm.__wbindgen_start();
1418
+ let wasmModule, wasm;
1419
+ function __wbg_finalize_init(instance, module) {
1420
+ wasm = instance.exports;
1421
+ wasmModule = module;
1422
+ cachedDataViewMemory0 = null;
1423
+ cachedUint8ArrayMemory0 = null;
1424
+ wasm.__wbindgen_start();
1425
+ return wasm;
1426
+ }
1427
+
1428
+ async function __wbg_load(module, imports) {
1429
+ if (typeof Response === 'function' && module instanceof Response) {
1430
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
1431
+ try {
1432
+ return await WebAssembly.instantiateStreaming(module, imports);
1433
+ } catch (e) {
1434
+ const validResponse = module.ok && expectedResponseType(module.type);
1435
+
1436
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
1437
+ 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);
1438
+
1439
+ } else { throw e; }
1440
+ }
1441
+ }
1442
+
1443
+ const bytes = await module.arrayBuffer();
1444
+ return await WebAssembly.instantiate(bytes, imports);
1445
+ } else {
1446
+ const instance = await WebAssembly.instantiate(module, imports);
1447
+
1448
+ if (instance instanceof WebAssembly.Instance) {
1449
+ return { instance, module };
1450
+ } else {
1451
+ return instance;
1452
+ }
1453
+ }
1454
+
1455
+ function expectedResponseType(type) {
1456
+ switch (type) {
1457
+ case 'basic': case 'cors': case 'default': return true;
1458
+ }
1459
+ return false;
1460
+ }
1461
+ }
1462
+
1463
+ function initSync(module) {
1464
+ if (wasm !== undefined) return wasm;
1465
+
1466
+
1467
+ if (module !== undefined) {
1468
+ if (Object.getPrototypeOf(module) === Object.prototype) {
1469
+ ({module} = module)
1470
+ } else {
1471
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
1472
+ }
1473
+ }
1474
+
1475
+ const imports = __wbg_get_imports();
1476
+ if (!(module instanceof WebAssembly.Module)) {
1477
+ module = new WebAssembly.Module(module);
1478
+ }
1479
+ const instance = new WebAssembly.Instance(module, imports);
1480
+ return __wbg_finalize_init(instance, module);
1481
+ }
1482
+
1483
+ async function __wbg_init(module_or_path) {
1484
+ if (wasm !== undefined) return wasm;
1485
+
1486
+
1487
+ if (module_or_path !== undefined) {
1488
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1489
+ ({module_or_path} = module_or_path)
1490
+ } else {
1491
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
1492
+ }
1493
+ }
1494
+
1495
+ if (module_or_path === undefined) {
1496
+ module_or_path = new URL('cedarling_wasm_bg.wasm', import.meta.url);
1497
+ }
1498
+ const imports = __wbg_get_imports();
1499
+
1500
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
1501
+ module_or_path = fetch(module_or_path);
1502
+ }
1503
+
1504
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
1505
+
1506
+ return __wbg_finalize_init(instance, module);
1507
+ }
1508
+
1509
+ export { initSync, __wbg_init as default };
Binary file
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@janssenproject/cedarling_wasm",
3
+ "type": "module",
3
4
  "description": "The Cedarling is a performant local authorization service that runs the Rust Cedar Engine",
4
- "version": "0.0.313-nodejs",
5
+ "version": "0.0.314",
5
6
  "license": "Apache-2.0",
6
7
  "repository": {
7
8
  "type": "git",
@@ -13,5 +14,8 @@
13
14
  "cedarling_wasm.d.ts"
14
15
  ],
15
16
  "main": "cedarling_wasm.js",
16
- "types": "cedarling_wasm.d.ts"
17
+ "types": "cedarling_wasm.d.ts",
18
+ "sideEffects": [
19
+ "./snippets/*"
20
+ ]
17
21
  }