@janssenproject/cedarling_wasm 1.15.0-nodejs → 2.0.0-nodejs

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.
@@ -1,186 +1,503 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+ /**
4
+ * The `ReadableStreamType` enum.
5
+ *
6
+ * *This API requires the following crate features to be activated: `ReadableStreamType`*
7
+ */
3
8
 
9
+ type ReadableStreamType = "bytes";
10
+
11
+ /**
12
+ * A WASM wrapper for the Rust `cedarling::AuthorizeResult` struct.
13
+ * Represents the result of an authorization request.
14
+ */
4
15
  export class AuthorizeResult {
5
- private constructor();
6
- free(): void;
7
- [Symbol.dispose](): void;
8
- /**
9
- * Convert `AuthorizeResult` to json string value
10
- */
11
- json_string(): string;
12
- principal(principal: string): AuthorizeResultResponse | undefined;
13
- /**
14
- * Result of authorization where principal is `Jans::Workload`
15
- */
16
- get workload(): AuthorizeResultResponse | undefined;
17
- /**
18
- * Result of authorization where principal is `Jans::Workload`
19
- */
20
- set workload(value: AuthorizeResultResponse | null | undefined);
21
- /**
22
- * Result of authorization where principal is `Jans::User`
23
- */
24
- get person(): AuthorizeResultResponse | undefined;
25
- /**
26
- * Result of authorization where principal is `Jans::User`
27
- */
28
- set person(value: AuthorizeResultResponse | null | undefined);
29
- /**
30
- * Result of authorization
31
- * true means `ALLOW`
32
- * false means `Deny`
33
- *
34
- * this field is [`bool`] type to be compatible with [authzen Access Evaluation Decision](https://openid.github.io/authzen/#section-6.2.1).
35
- */
36
- decision: boolean;
37
- /**
38
- * Request ID of the authorization request
39
- */
40
- request_id: string;
16
+ private constructor();
17
+ free(): void;
18
+ [Symbol.dispose](): void;
19
+ /**
20
+ * Convert `AuthorizeResult` to json string value
21
+ */
22
+ json_string(): string;
23
+ /**
24
+ * Result of authorization
25
+ * true means `ALLOW`
26
+ * false means `Deny`
27
+ *
28
+ * this field is [`bool`] type to be compatible with [authzen Access Evaluation Decision](https://openid.github.io/authzen/#section-6.2.1).
29
+ */
30
+ decision: boolean;
31
+ /**
32
+ * Request ID of the authorization request
33
+ */
34
+ request_id: string;
35
+ /**
36
+ * Cedar authorization response for the request.
37
+ */
38
+ response: AuthorizeResultResponse;
41
39
  }
42
40
 
41
+ /**
42
+ * A WASM wrapper for the Rust `cedar_policy::Response` struct.
43
+ * Represents the result of an authorization request.
44
+ */
43
45
  export class AuthorizeResultResponse {
44
- private constructor();
45
- free(): void;
46
- [Symbol.dispose](): void;
47
- /**
48
- * Authorization decision
49
- */
50
- readonly decision: boolean;
51
- /**
52
- * Diagnostics providing more information on how this decision was reached
53
- */
54
- readonly diagnostics: Diagnostics;
46
+ private constructor();
47
+ free(): void;
48
+ [Symbol.dispose](): void;
49
+ /**
50
+ * Authorization decision
51
+ */
52
+ readonly decision: boolean;
53
+ /**
54
+ * Diagnostics providing more information on how this decision was reached
55
+ */
56
+ readonly diagnostics: Diagnostics;
55
57
  }
56
58
 
59
+ /**
60
+ * The instance of the Cedarling application.
61
+ */
57
62
  export class Cedarling {
58
- private constructor();
59
- free(): void;
60
- [Symbol.dispose](): void;
61
- /**
62
- * Create a new instance of the Cedarling application.
63
- * Assume that config is `Object`
64
- */
65
- static new(config: object): Promise<Cedarling>;
66
- /**
67
- * Create a new instance of the Cedarling application.
68
- * Assume that config is `Map`
69
- */
70
- static new_from_map(config: Map<any, any>): Promise<Cedarling>;
71
- /**
72
- * Authorize request
73
- * makes authorization decision based on the [`Request`]
74
- */
75
- authorize(request: any): Promise<AuthorizeResult>;
76
- /**
77
- * Authorize request for unsigned principals.
78
- * makes authorization decision based on the [`RequestUnsigned`]
79
- */
80
- authorize_unsigned(request: any): Promise<AuthorizeResult>;
81
- /**
82
- * Authorize multi-issuer request.
83
- * Makes authorization decision based on multiple JWT tokens from different issuers
84
- */
85
- authorize_multi_issuer(request: any): Promise<MultiIssuerAuthorizeResult>;
86
- /**
87
- * Get logs and remove them from the storage.
88
- * Returns `Array` of `Map`
89
- */
90
- pop_logs(): Array<any>;
91
- /**
92
- * Get specific log entry.
93
- * Returns `Map` with values or `null`.
94
- */
95
- get_log_by_id(id: string): any;
96
- /**
97
- * Returns a list of all log ids.
98
- * Returns `Array` of `String`
99
- */
100
- get_log_ids(): Array<any>;
101
- /**
102
- * Get logs by tag, like `log_kind` or `log level`.
103
- * Tag can be `log_kind`, `log_level`.
104
- */
105
- get_logs_by_tag(tag: string): any[];
106
- /**
107
- * Get logs by request_id.
108
- * Return log entries that match the given request_id.
109
- */
110
- get_logs_by_request_id(request_id: string): any[];
111
- /**
112
- * Get log by request_id and tag, like composite key `request_id` + `log_kind`.
113
- * Tag can be `log_kind`, `log_level`.
114
- * Return log entries that match the given request_id and tag.
115
- */
116
- get_logs_by_request_id_and_tag(request_id: string, tag: string): any[];
117
- /**
118
- * Closes the connections to the Lock Server and pushes all available logs.
119
- */
120
- shut_down(): Promise<void>;
63
+ private constructor();
64
+ free(): void;
65
+ [Symbol.dispose](): void;
66
+ /**
67
+ * Authorize multi-issuer request.
68
+ * Makes authorization decision based on multiple JWT tokens from different issuers
69
+ */
70
+ authorize_multi_issuer(request: any): Promise<MultiIssuerAuthorizeResult>;
71
+ /**
72
+ * Authorize an unsigned request carrying an optional single principal.
73
+ * Makes an authorization decision based on the [`RequestUnsigned`].
74
+ *
75
+ * When `principal` is omitted / `null` on the JS side the core uses Cedar
76
+ * partial evaluation; residual-dependent requests fail closed with
77
+ * `Decision::Deny` and surface residual policy ids in
78
+ * `response.diagnostics.reason`.
79
+ */
80
+ authorize_unsigned(request: any): Promise<AuthorizeResult>;
81
+ /**
82
+ * Clear all entries from the data store.
83
+ *
84
+ * # Example
85
+ *
86
+ * ```javascript
87
+ * cedarling.clear_data_ctx();
88
+ * console.log("All data entries cleared");
89
+ * ```
90
+ */
91
+ clear_data_ctx(): void;
92
+ /**
93
+ * Get trusted issuer identifiers that failed to load.
94
+ *
95
+ * # Example
96
+ *
97
+ * ```javascript
98
+ * const ids = cedarling.failed_trusted_issuer_ids();
99
+ * ```
100
+ */
101
+ failed_trusted_issuer_ids(): Array<any>;
102
+ /**
103
+ * Get a value from the data store by key.
104
+ * Returns null if the key doesn't exist or the entry has expired.
105
+ *
106
+ * # Arguments
107
+ *
108
+ * * `key` - A string key for the data entry to retrieve
109
+ *
110
+ * # Example
111
+ *
112
+ * ```javascript
113
+ * const value = cedarling.get_data_ctx("user:123");
114
+ * if (value !== null) {
115
+ * console.log(value.name); // "John"
116
+ * }
117
+ * ```
118
+ */
119
+ get_data_ctx(key: string): any;
120
+ /**
121
+ * Get a data entry with full metadata by key.
122
+ * Returns null if the key doesn't exist or the entry has expired.
123
+ *
124
+ * # Arguments
125
+ *
126
+ * * `key` - A string key for the data entry to retrieve
127
+ *
128
+ * # Example
129
+ *
130
+ * ```javascript
131
+ * const entry = cedarling.get_data_entry_ctx("user:123");
132
+ * if (entry !== null) {
133
+ * console.log(entry.key); // "user:123"
134
+ * console.log(entry.value); // { name: "John", age: 30 }
135
+ * console.log(entry.data_type); // "Record"
136
+ * console.log(entry.created_at); // "2024-01-01T12:00:00Z"
137
+ * console.log(entry.access_count); // 5
138
+ * }
139
+ * ```
140
+ */
141
+ get_data_entry_ctx(key: string): DataEntry | undefined;
142
+ /**
143
+ * Get specific log entry.
144
+ * Returns `Map` with values or `null`.
145
+ */
146
+ get_log_by_id(id: string): any;
147
+ /**
148
+ * Returns a list of all log ids.
149
+ * Returns `Array` of `String`
150
+ */
151
+ get_log_ids(): Array<any>;
152
+ /**
153
+ * Get logs by request_id.
154
+ * Return log entries that match the given request_id.
155
+ */
156
+ get_logs_by_request_id(request_id: string): any[];
157
+ /**
158
+ * Get log by request_id and tag, like composite key `request_id` + `log_kind`.
159
+ * Tag can be `log_kind`, `log_level`.
160
+ * Return log entries that match the given request_id and tag.
161
+ */
162
+ get_logs_by_request_id_and_tag(request_id: string, tag: string): any[];
163
+ /**
164
+ * Get logs by tag, like `log_kind` or `log level`.
165
+ * Tag can be `log_kind`, `log_level`.
166
+ */
167
+ get_logs_by_tag(tag: string): any[];
168
+ /**
169
+ * Get statistics about the data store.
170
+ *
171
+ * # Example
172
+ *
173
+ * ```javascript
174
+ * const stats = cedarling.get_stats_ctx();
175
+ * console.log(`Entries: ${stats.entry_count}/${stats.max_entries || 'unlimited'}`);
176
+ * console.log(`Capacity: ${stats.capacity_usage_percent.toFixed(2)}%`);
177
+ * console.log(`Total size: ${stats.total_size_bytes} bytes`);
178
+ * ```
179
+ */
180
+ get_stats_ctx(): DataStoreStats;
181
+ /**
182
+ * Check whether a trusted issuer was loaded by `iss` claim.
183
+ *
184
+ * # Arguments
185
+ *
186
+ * * `iss_claim` - Issuer `iss` claim value to check.
187
+ *
188
+ * # Example
189
+ *
190
+ * ```javascript
191
+ * const ok = cedarling.is_trusted_issuer_loaded_by_iss("https://issuer.example.org");
192
+ * ```
193
+ */
194
+ is_trusted_issuer_loaded_by_iss(iss_claim: string): boolean;
195
+ /**
196
+ * Check whether a trusted issuer was loaded by issuer identifier.
197
+ *
198
+ * # Arguments
199
+ *
200
+ * * `issuer_id` - Trusted issuer identifier to check.
201
+ *
202
+ * # Example
203
+ *
204
+ * ```javascript
205
+ * const ok = cedarling.is_trusted_issuer_loaded_by_name("issuer_id");
206
+ * ```
207
+ */
208
+ is_trusted_issuer_loaded_by_name(issuer_id: string): boolean;
209
+ /**
210
+ * List all entries with their metadata.
211
+ * Returns an array of DataEntry objects.
212
+ *
213
+ * # Example
214
+ *
215
+ * ```javascript
216
+ * const entries = cedarling.list_data_ctx();
217
+ * entries.forEach(entry => {
218
+ * console.log(`${entry.key}: ${entry.data_type} (accessed ${entry.access_count} times)`);
219
+ * });
220
+ * ```
221
+ */
222
+ list_data_ctx(): Array<any>;
223
+ /**
224
+ * Get trusted issuer identifiers loaded successfully.
225
+ *
226
+ * # Example
227
+ *
228
+ * ```javascript
229
+ * const ids = cedarling.loaded_trusted_issuer_ids();
230
+ * ```
231
+ */
232
+ loaded_trusted_issuer_ids(): Array<any>;
233
+ /**
234
+ * Get the number of trusted issuers loaded successfully.
235
+ *
236
+ * # Example
237
+ *
238
+ * ```javascript
239
+ * const loadedCount = cedarling.loaded_trusted_issuers_count();
240
+ * ```
241
+ */
242
+ loaded_trusted_issuers_count(): number;
243
+ /**
244
+ * Create a new instance of the Cedarling application.
245
+ * Assume that config is `Object`
246
+ */
247
+ static new(config: object): Promise<Cedarling>;
248
+ /**
249
+ * Create a new instance of the Cedarling application.
250
+ * Assume that config is `Map`
251
+ */
252
+ static new_from_map(config: Map<any, any>): Promise<Cedarling>;
253
+ /**
254
+ * Get logs and remove them from the storage.
255
+ * Returns `Array` of `Map`
256
+ */
257
+ pop_logs(): Array<any>;
258
+ /**
259
+ * Push a value into the data store with an optional TTL.
260
+ * If the key already exists, the value will be replaced.
261
+ * If TTL is not provided, the default TTL from configuration is used.
262
+ *
263
+ * # Arguments
264
+ *
265
+ * * `key` - A string key for the data entry (must not be empty)
266
+ * * `value` - The value to store (any JSON-serializable JavaScript value: object, array, string, number, boolean)
267
+ * * `ttl_secs` - Optional TTL in seconds (undefined/null uses default from config)
268
+ *
269
+ * # Example
270
+ *
271
+ * ```javascript
272
+ * cedarling.push_data_ctx("user:123", { name: "John", age: 30 }, 3600);
273
+ * cedarling.push_data_ctx("config", { setting: "value" }); // Uses default TTL
274
+ * ```
275
+ */
276
+ push_data_ctx(key: string, value: any, ttl_secs?: bigint | null): void;
277
+ /**
278
+ * Remove a value from the data store by key.
279
+ * Returns true if the key existed and was removed, false otherwise.
280
+ *
281
+ * # Arguments
282
+ *
283
+ * * `key` - A string key for the data entry to remove
284
+ *
285
+ * # Example
286
+ *
287
+ * ```javascript
288
+ * const removed = cedarling.remove_data_ctx("user:123");
289
+ * if (removed) {
290
+ * console.log("Entry was successfully removed");
291
+ * }
292
+ * ```
293
+ */
294
+ remove_data_ctx(key: string): boolean;
295
+ /**
296
+ * Closes the connections to the Lock Server and pushes all available logs.
297
+ */
298
+ shut_down(): Promise<void>;
299
+ /**
300
+ * Get the total number of trusted issuer entries discovered.
301
+ *
302
+ * # Example
303
+ *
304
+ * ```javascript
305
+ * const total = cedarling.total_issuers();
306
+ * ```
307
+ */
308
+ total_issuers(): number;
309
+ }
310
+
311
+ /**
312
+ * A WASM wrapper for the Rust `cedarling::DataEntry` struct.
313
+ * Represents a data entry in the DataStore with value and metadata.
314
+ */
315
+ export class DataEntry {
316
+ private constructor();
317
+ free(): void;
318
+ [Symbol.dispose](): void;
319
+ /**
320
+ * Convert `DataEntry` to json string value
321
+ */
322
+ json_string(): string;
323
+ /**
324
+ * Get the value stored in this entry as a JavaScript object
325
+ */
326
+ value(): any;
327
+ /**
328
+ * Number of times this entry has been accessed
329
+ */
330
+ access_count: bigint;
331
+ /**
332
+ * Timestamp when this entry was created (RFC 3339 format)
333
+ */
334
+ created_at: string;
335
+ /**
336
+ * The inferred Cedar type of the value
337
+ */
338
+ data_type: string;
339
+ /**
340
+ * Timestamp when this entry expires (RFC 3339 format), or null if no TTL
341
+ */
342
+ get expires_at(): string | undefined;
343
+ /**
344
+ * Timestamp when this entry expires (RFC 3339 format), or null if no TTL
345
+ */
346
+ set expires_at(value: string | null | undefined);
347
+ /**
348
+ * The key for this entry
349
+ */
350
+ key: string;
351
+ }
352
+
353
+ /**
354
+ * A WASM wrapper for the Rust `cedarling::DataStoreStats` struct.
355
+ * Statistics about the DataStore.
356
+ */
357
+ export class DataStoreStats {
358
+ private constructor();
359
+ free(): void;
360
+ [Symbol.dispose](): void;
361
+ /**
362
+ * Convert `DataStoreStats` to json string value
363
+ */
364
+ json_string(): string;
365
+ /**
366
+ * Average size per entry in bytes (0 if no entries)
367
+ */
368
+ avg_entry_size_bytes: number;
369
+ /**
370
+ * Percentage of capacity used (0.0-100.0, based on entry count)
371
+ */
372
+ capacity_usage_percent: number;
373
+ /**
374
+ * Number of entries currently stored
375
+ */
376
+ entry_count: number;
377
+ /**
378
+ * Maximum number of entries allowed (0 = unlimited)
379
+ */
380
+ max_entries: number;
381
+ /**
382
+ * Maximum size per entry in bytes (0 = unlimited)
383
+ */
384
+ max_entry_size: number;
385
+ /**
386
+ * Memory usage threshold percentage (from config)
387
+ */
388
+ memory_alert_threshold: number;
389
+ /**
390
+ * Whether memory usage exceeds the alert threshold
391
+ */
392
+ memory_alert_triggered: boolean;
393
+ /**
394
+ * Whether metrics tracking is enabled
395
+ */
396
+ metrics_enabled: boolean;
397
+ /**
398
+ * Total size of all entries in bytes (approximate, based on JSON serialization)
399
+ */
400
+ total_size_bytes: number;
121
401
  }
122
402
 
403
+ /**
404
+ * Diagnostics
405
+ * ===========
406
+ *
407
+ * Provides detailed information about how a policy decision was made, including policies that contributed to the decision and any errors encountered during evaluation.
408
+ */
123
409
  export class Diagnostics {
124
- private constructor();
125
- free(): void;
126
- [Symbol.dispose](): void;
127
- /**
128
- * `PolicyId`s of the policies that contributed to the decision.
129
- * If no policies applied to the request, this set will be empty.
130
- *
131
- * The ids should be treated as unordered,
132
- */
133
- readonly reason: string[];
134
- /**
135
- * Errors that occurred during authorization. The errors should be
136
- * treated as unordered, since policies may be evaluated in any order.
137
- */
138
- readonly errors: PolicyEvaluationError[];
410
+ private constructor();
411
+ free(): void;
412
+ [Symbol.dispose](): void;
413
+ /**
414
+ * Errors that occurred during authorization. The errors should be
415
+ * treated as unordered, since policies may be evaluated in any order.
416
+ */
417
+ readonly errors: PolicyEvaluationError[];
418
+ /**
419
+ * `PolicyId`s of the policies that contributed to the decision.
420
+ * If no policies applied to the request, this set will be empty.
421
+ *
422
+ * The ids should be treated as unordered,
423
+ */
424
+ readonly reason: string[];
425
+ }
426
+
427
+ export class IntoUnderlyingByteSource {
428
+ private constructor();
429
+ free(): void;
430
+ [Symbol.dispose](): void;
431
+ cancel(): void;
432
+ pull(controller: ReadableByteStreamController): Promise<any>;
433
+ start(controller: ReadableByteStreamController): void;
434
+ readonly autoAllocateChunkSize: number;
435
+ readonly type: ReadableStreamType;
436
+ }
437
+
438
+ export class IntoUnderlyingSink {
439
+ private constructor();
440
+ free(): void;
441
+ [Symbol.dispose](): void;
442
+ abort(reason: any): Promise<any>;
443
+ close(): Promise<any>;
444
+ write(chunk: any): Promise<any>;
139
445
  }
140
446
 
141
- export class JsJsonLogic {
142
- free(): void;
143
- [Symbol.dispose](): void;
144
- constructor();
145
- apply(logic: any, data: any): any;
447
+ export class IntoUnderlyingSource {
448
+ private constructor();
449
+ free(): void;
450
+ [Symbol.dispose](): void;
451
+ cancel(): void;
452
+ pull(controller: ReadableStreamDefaultController): Promise<any>;
146
453
  }
147
454
 
455
+ /**
456
+ * A WASM wrapper for the Rust `cedarling::MultiIssuerAuthorizeResult` struct.
457
+ * Represents the result of a multi-issuer authorization request.
458
+ */
148
459
  export class MultiIssuerAuthorizeResult {
149
- private constructor();
150
- free(): void;
151
- [Symbol.dispose](): void;
152
- /**
153
- * Convert `MultiIssuerAuthorizeResult` to json string value
154
- */
155
- json_string(): string;
156
- /**
157
- * Result of Cedar policy authorization
158
- */
159
- response: AuthorizeResultResponse;
160
- /**
161
- * Result of authorization
162
- * true means `ALLOW`
163
- * false means `Deny`
164
- */
165
- decision: boolean;
166
- /**
167
- * Request ID of the authorization request
168
- */
169
- request_id: string;
460
+ private constructor();
461
+ free(): void;
462
+ [Symbol.dispose](): void;
463
+ /**
464
+ * Convert `MultiIssuerAuthorizeResult` to json string value
465
+ */
466
+ json_string(): string;
467
+ /**
468
+ * Result of authorization
469
+ * true means `ALLOW`
470
+ * false means `Deny`
471
+ */
472
+ decision: boolean;
473
+ /**
474
+ * Request ID of the authorization request
475
+ */
476
+ request_id: string;
477
+ /**
478
+ * Result of Cedar policy authorization
479
+ */
480
+ response: AuthorizeResultResponse;
170
481
  }
171
482
 
483
+ /**
484
+ * PolicyEvaluationError
485
+ * =====================
486
+ *
487
+ * Represents an error that occurred when evaluating a Cedar policy.
488
+ */
172
489
  export class PolicyEvaluationError {
173
- private constructor();
174
- free(): void;
175
- [Symbol.dispose](): void;
176
- /**
177
- * Id of the policy with an error
178
- */
179
- readonly id: string;
180
- /**
181
- * Underlying evaluation error string representation
182
- */
183
- readonly error: string;
490
+ private constructor();
491
+ free(): void;
492
+ [Symbol.dispose](): void;
493
+ /**
494
+ * Underlying evaluation error string representation
495
+ */
496
+ readonly error: string;
497
+ /**
498
+ * Id of the policy with an error
499
+ */
500
+ readonly id: string;
184
501
  }
185
502
 
186
503
  /**
@@ -188,3 +505,22 @@ export class PolicyEvaluationError {
188
505
  * This function can take as config parameter the eather `Map` other `Object`
189
506
  */
190
507
  export function init(config: any): Promise<Cedarling>;
508
+
509
+ /**
510
+ * Create a new instance of the Cedarling application from archive bytes.
511
+ *
512
+ * This function allows loading a policy store from a Cedar Archive (.cjar)
513
+ * that was fetched with custom logic (e.g., with authentication headers).
514
+ *
515
+ * # Arguments
516
+ * * `config` - Bootstrap configuration (Map or Object). Policy store config is ignored.
517
+ * * `archive_bytes` - The .cjar archive bytes (Uint8Array)
518
+ *
519
+ * # Example
520
+ * ```javascript
521
+ * const response = await fetch(url, { headers: { Authorization: 'Bearer ...' } });
522
+ * const bytes = new Uint8Array(await response.arrayBuffer());
523
+ * const cedarling = await init_from_archive_bytes(config, bytes);
524
+ * ```
525
+ */
526
+ export function init_from_archive_bytes(config: any, archive_bytes: Uint8Array): Promise<Cedarling>;