@janssenproject/cedarling_wasm 0.0.307 → 0.0.308

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/README.md CHANGED
@@ -70,6 +70,25 @@ Before using any function from library you need initialize WASM runtime by calli
70
70
  */
71
71
  export function init(config: any): Promise<Cedarling>;
72
72
 
73
+ /**
74
+ * Create a new instance of the Cedarling application from archive bytes.
75
+ *
76
+ * This function allows loading a policy store from a Cedar Archive (.cjar)
77
+ * that was fetched with custom logic (e.g., with authentication headers).
78
+ *
79
+ * # Arguments
80
+ * * `config` - Bootstrap configuration (Map or Object). Policy store config is ignored.
81
+ * * `archive_bytes` - The .cjar archive bytes (Uint8Array)
82
+ *
83
+ * # Example
84
+ * ```javascript
85
+ * const response = await fetch(url, { headers: { Authorization: 'Bearer ...' } });
86
+ * const bytes = new Uint8Array(await response.arrayBuffer());
87
+ * const cedarling = await init_from_archive_bytes(config, bytes);
88
+ * ```
89
+ */
90
+ export function init_from_archive_bytes(config: any, archive_bytes: Uint8Array): Promise<Cedarling>;
91
+
73
92
  /**
74
93
  * The instance of the Cedarling application.
75
94
  */
@@ -248,6 +267,50 @@ export class PolicyEvaluationError {
248
267
 
249
268
  ## Configuration
250
269
 
270
+ ### Policy Store Sources
271
+
272
+ Cedarling supports multiple ways to load policy stores. **In WASM environments, only URL-based loading is available** (no filesystem access).
273
+
274
+ #### WASM-Supported Options
275
+
276
+ ```javascript
277
+ // Option 1: Fetch policy store from URL (simple)
278
+ const BOOTSTRAP_CONFIG = {
279
+ CEDARLING_POLICY_STORE_URI: "https://example.com/policy-store.cjar",
280
+ // ... other config
281
+ };
282
+ const cedarling = await init(BOOTSTRAP_CONFIG);
283
+
284
+ // Option 2: Inline JSON string (for embedded policy stores)
285
+ // policyStoreJson is the policy store JSON as a string
286
+ // See: https://docs.jans.io/stable/cedarling/reference/cedarling-policy-store/
287
+ const policyStoreJson = '{"cedar_version":"4.0","policy_stores":{...}}';
288
+ const BOOTSTRAP_CONFIG = {
289
+ CEDARLING_POLICY_STORE_LOCAL: policyStoreJson,
290
+ // ... other config
291
+ };
292
+ const cedarling = await init(BOOTSTRAP_CONFIG);
293
+
294
+ // Option 3: Custom fetch with auth headers (use init_from_archive_bytes)
295
+ const response = await fetch("https://example.com/policy-store.cjar", {
296
+ headers: { Authorization: `Bearer ${token}` },
297
+ });
298
+ const bytes = new Uint8Array(await response.arrayBuffer());
299
+ const cedarling = await init_from_archive_bytes(BOOTSTRAP_CONFIG, bytes);
300
+ ```
301
+
302
+ > **Note:** Directory-based loading and file-based loading are **NOT supported in WASM** (no filesystem access). Use URL-based loading or `init_from_archive_bytes` for custom fetch scenarios.
303
+
304
+ #### Cedar Archive (.cjar) Format
305
+
306
+ For the new directory-based format in WASM, package the directory structure as a `.cjar` file (ZIP archive):
307
+
308
+ ```bash
309
+ cd policy-store && zip -r ../policy-store.cjar .
310
+ ```
311
+
312
+ See [Policy Store Formats](../../../docs/cedarling/reference/cedarling-policy-store.md#policy-store-formats) for details on the directory structure and metadata.json format.
313
+
251
314
  ### ID Token Trust Mode
252
315
 
253
316
  The `CEDARLING_ID_TOKEN_TRUST_MODE` property controls how ID tokens are validated:
@@ -271,8 +334,4 @@ const BOOTSTRAP_CONFIG = {
271
334
  };
272
335
  ```
273
336
 
274
- For complete configuration documentation, see [cedarling-properties.md](../../../docs/cedarling/cedarling-properties.md) or on [our page](https://docs.jans.io/stable/cedarling/cedarling-properties/) .
275
-
276
- ```
277
-
278
- ```
337
+ For complete configuration documentation, see [cedarling-properties.md](../../../docs/cedarling/cedarling-properties.md) or on [our page](https://docs.jans.io/stable/cedarling/cedarling-properties/).