@janssenproject/cedarling_wasm 0.0.415 → 0.0.416

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.
@@ -63,6 +63,67 @@ export class Cedarling {
63
63
  private constructor();
64
64
  free(): void;
65
65
  [Symbol.dispose](): void;
66
+ /**
67
+ * Collect every value of the annotation `key` across the given policies,
68
+ * preserving duplicates. Unknown policy IDs are silently skipped.
69
+ *
70
+ * # Arguments
71
+ *
72
+ * * `policy_ids` - List of policy IDs to search. Typically
73
+ * `result.response.diagnostics.reason` from an authorization result.
74
+ * * `key` - The annotation key to collect values for (e.g. `"redirect"`).
75
+ *
76
+ * # Example
77
+ *
78
+ * ```javascript
79
+ * const redirects = cedarling.annotation_values(result.response.diagnostics.reason, "redirect");
80
+ * // ["/upgrade"]
81
+ * ```
82
+ */
83
+ annotation_values(policy_ids: string[], key: string): string[];
84
+ /**
85
+ * Return the annotations of each given policy, grouped by policy ID
86
+ * the loss-free companion to `annotations_map`. Unknown policy IDs are
87
+ * silently skipped.
88
+ *
89
+ * # Arguments
90
+ *
91
+ * * `policy_ids` - List of policy IDs whose annotations should be returned
92
+ * grouped by policy ID. Typically `result.response.diagnostics.reason` from
93
+ * an authorization result.
94
+ *
95
+ * # Example
96
+ *
97
+ * ```javascript
98
+ * const byPolicy = cedarling.annotations_by_policy(result.response.diagnostics.reason);
99
+ * // { "5": { redirect: "/upgrade", tier: "premium" } }
100
+ * ```
101
+ */
102
+ annotations_by_policy(policy_ids: string[]): any;
103
+ /**
104
+ * Merge the annotations (`@key("value")`) of the given policies into a single object.
105
+ *
106
+ * Intended for resolving the determining policies of an authorization decision:
107
+ * pass `result.response.diagnostics.reason`.
108
+ *
109
+ * Lossy: if the same annotation key appears on several policies, one value wins
110
+ * arbitrarily. Use `annotation_values` / `annotations_by_policy` when duplicates
111
+ * matter. Unknown policy IDs are silently skipped.
112
+ *
113
+ * # Arguments
114
+ *
115
+ * * `policy_ids` - List of policy IDs whose annotations should be merged into
116
+ * a single object. Typically `result.response.diagnostics.reason` from an
117
+ * authorization result.
118
+ *
119
+ * # Example
120
+ *
121
+ * ```javascript
122
+ * const annotations = cedarling.annotations_map(result.response.diagnostics.reason);
123
+ * // { redirect: "/upgrade", tier: "premium" }
124
+ * ```
125
+ */
126
+ annotations_map(policy_ids: string[]): any;
66
127
  /**
67
128
  * Authorize multi-issuer request.
68
129
  * Makes authorization decision based on multiple JWT tokens from different issuers.
@@ -593,6 +654,9 @@ export interface InitOutput {
593
654
  readonly authorizeresult_json_string: (a: number, b: number) => void;
594
655
  readonly authorizeresultresponse_decision: (a: number) => number;
595
656
  readonly authorizeresultresponse_diagnostics: (a: number) => number;
657
+ readonly cedarling_annotation_values: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
658
+ readonly cedarling_annotations_by_policy: (a: number, b: number, c: number, d: number) => void;
659
+ readonly cedarling_annotations_map: (a: number, b: number, c: number, d: number) => void;
596
660
  readonly cedarling_authorize_multi_issuer: (a: number, b: number, c: number) => number;
597
661
  readonly cedarling_authorize_unsigned: (a: number, b: number, c: number) => number;
598
662
  readonly cedarling_clear_data_ctx: (a: number, b: number) => void;
@@ -655,10 +719,10 @@ export interface InitOutput {
655
719
  readonly __wbg_get_multiissuerauthorizeresult_request_id: (a: number, b: number) => void;
656
720
  readonly __wbg_multiissuerauthorizeresult_free: (a: number, b: number) => void;
657
721
  readonly cedarling_get_logs_by_tag: (a: number, b: number, c: number, d: number) => void;
658
- readonly __wasm_bindgen_func_elem_8668: (a: number, b: number, c: number, d: number) => void;
659
- readonly __wasm_bindgen_func_elem_8722: (a: number, b: number, c: number, d: number) => void;
660
- readonly __wasm_bindgen_func_elem_12144: (a: number, b: number, c: number) => void;
661
- readonly __wasm_bindgen_func_elem_8503: (a: number, b: number) => void;
722
+ readonly __wasm_bindgen_func_elem_8693: (a: number, b: number, c: number, d: number) => void;
723
+ readonly __wasm_bindgen_func_elem_8748: (a: number, b: number, c: number, d: number) => void;
724
+ readonly __wasm_bindgen_func_elem_12170: (a: number, b: number, c: number) => void;
725
+ readonly __wasm_bindgen_func_elem_8528: (a: number, b: number) => void;
662
726
  readonly __wbindgen_export: (a: number, b: number) => number;
663
727
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
664
728
  readonly __wbindgen_export3: (a: number) => void;
package/cedarling_wasm.js CHANGED
@@ -173,6 +173,122 @@ export class Cedarling {
173
173
  const ptr = this.__destroy_into_raw();
174
174
  wasm.__wbg_cedarling_free(ptr, 0);
175
175
  }
176
+ /**
177
+ * Collect every value of the annotation `key` across the given policies,
178
+ * preserving duplicates. Unknown policy IDs are silently skipped.
179
+ *
180
+ * # Arguments
181
+ *
182
+ * * `policy_ids` - List of policy IDs to search. Typically
183
+ * `result.response.diagnostics.reason` from an authorization result.
184
+ * * `key` - The annotation key to collect values for (e.g. `"redirect"`).
185
+ *
186
+ * # Example
187
+ *
188
+ * ```javascript
189
+ * const redirects = cedarling.annotation_values(result.response.diagnostics.reason, "redirect");
190
+ * // ["/upgrade"]
191
+ * ```
192
+ * @param {string[]} policy_ids
193
+ * @param {string} key
194
+ * @returns {string[]}
195
+ */
196
+ annotation_values(policy_ids, key) {
197
+ try {
198
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
199
+ const ptr0 = passArrayJsValueToWasm0(policy_ids, wasm.__wbindgen_export);
200
+ const len0 = WASM_VECTOR_LEN;
201
+ const ptr1 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
202
+ const len1 = WASM_VECTOR_LEN;
203
+ wasm.cedarling_annotation_values(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
204
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
205
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
206
+ var v3 = getArrayJsValueFromWasm0(r0, r1).slice();
207
+ wasm.__wbindgen_export5(r0, r1 * 4, 4);
208
+ return v3;
209
+ } finally {
210
+ wasm.__wbindgen_add_to_stack_pointer(16);
211
+ }
212
+ }
213
+ /**
214
+ * Return the annotations of each given policy, grouped by policy ID
215
+ * the loss-free companion to `annotations_map`. Unknown policy IDs are
216
+ * silently skipped.
217
+ *
218
+ * # Arguments
219
+ *
220
+ * * `policy_ids` - List of policy IDs whose annotations should be returned
221
+ * grouped by policy ID. Typically `result.response.diagnostics.reason` from
222
+ * an authorization result.
223
+ *
224
+ * # Example
225
+ *
226
+ * ```javascript
227
+ * const byPolicy = cedarling.annotations_by_policy(result.response.diagnostics.reason);
228
+ * // { "5": { redirect: "/upgrade", tier: "premium" } }
229
+ * ```
230
+ * @param {string[]} policy_ids
231
+ * @returns {any}
232
+ */
233
+ annotations_by_policy(policy_ids) {
234
+ try {
235
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
236
+ const ptr0 = passArrayJsValueToWasm0(policy_ids, wasm.__wbindgen_export);
237
+ const len0 = WASM_VECTOR_LEN;
238
+ wasm.cedarling_annotations_by_policy(retptr, this.__wbg_ptr, ptr0, len0);
239
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
240
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
241
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
242
+ if (r2) {
243
+ throw takeObject(r1);
244
+ }
245
+ return takeObject(r0);
246
+ } finally {
247
+ wasm.__wbindgen_add_to_stack_pointer(16);
248
+ }
249
+ }
250
+ /**
251
+ * Merge the annotations (`@key("value")`) of the given policies into a single object.
252
+ *
253
+ * Intended for resolving the determining policies of an authorization decision:
254
+ * pass `result.response.diagnostics.reason`.
255
+ *
256
+ * Lossy: if the same annotation key appears on several policies, one value wins
257
+ * arbitrarily. Use `annotation_values` / `annotations_by_policy` when duplicates
258
+ * matter. Unknown policy IDs are silently skipped.
259
+ *
260
+ * # Arguments
261
+ *
262
+ * * `policy_ids` - List of policy IDs whose annotations should be merged into
263
+ * a single object. Typically `result.response.diagnostics.reason` from an
264
+ * authorization result.
265
+ *
266
+ * # Example
267
+ *
268
+ * ```javascript
269
+ * const annotations = cedarling.annotations_map(result.response.diagnostics.reason);
270
+ * // { redirect: "/upgrade", tier: "premium" }
271
+ * ```
272
+ * @param {string[]} policy_ids
273
+ * @returns {any}
274
+ */
275
+ annotations_map(policy_ids) {
276
+ try {
277
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
278
+ const ptr0 = passArrayJsValueToWasm0(policy_ids, wasm.__wbindgen_export);
279
+ const len0 = WASM_VECTOR_LEN;
280
+ wasm.cedarling_annotations_map(retptr, this.__wbg_ptr, ptr0, len0);
281
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
282
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
283
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
284
+ if (r2) {
285
+ throw takeObject(r1);
286
+ }
287
+ return takeObject(r0);
288
+ } finally {
289
+ wasm.__wbindgen_add_to_stack_pointer(16);
290
+ }
291
+ }
176
292
  /**
177
293
  * Authorize multi-issuer request.
178
294
  * Makes authorization decision based on multiple JWT tokens from different issuers.
@@ -1870,7 +1986,7 @@ function __wbg_get_imports() {
1870
1986
  const a = state0.a;
1871
1987
  state0.a = 0;
1872
1988
  try {
1873
- return __wasm_bindgen_func_elem_8722(a, state0.b, arg0, arg1);
1989
+ return __wasm_bindgen_func_elem_8748(a, state0.b, arg0, arg1);
1874
1990
  } finally {
1875
1991
  state0.a = a;
1876
1992
  }
@@ -2080,17 +2196,17 @@ function __wbg_get_imports() {
2080
2196
  },
2081
2197
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
2082
2198
  // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1196, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2083
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_12144);
2199
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_12170);
2084
2200
  return addHeapObject(ret);
2085
2201
  },
2086
2202
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
2087
2203
  // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 995, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
2088
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_8668);
2204
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_8693);
2089
2205
  return addHeapObject(ret);
2090
2206
  },
2091
2207
  __wbindgen_cast_0000000000000003: function(arg0, arg1) {
2092
2208
  // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 883, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2093
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_8503);
2209
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_8528);
2094
2210
  return addHeapObject(ret);
2095
2211
  },
2096
2212
  __wbindgen_cast_0000000000000004: function(arg0) {
@@ -2132,18 +2248,18 @@ function __wbg_get_imports() {
2132
2248
  };
2133
2249
  }
2134
2250
 
2135
- function __wasm_bindgen_func_elem_8503(arg0, arg1) {
2136
- wasm.__wasm_bindgen_func_elem_8503(arg0, arg1);
2251
+ function __wasm_bindgen_func_elem_8528(arg0, arg1) {
2252
+ wasm.__wasm_bindgen_func_elem_8528(arg0, arg1);
2137
2253
  }
2138
2254
 
2139
- function __wasm_bindgen_func_elem_12144(arg0, arg1, arg2) {
2140
- wasm.__wasm_bindgen_func_elem_12144(arg0, arg1, addHeapObject(arg2));
2255
+ function __wasm_bindgen_func_elem_12170(arg0, arg1, arg2) {
2256
+ wasm.__wasm_bindgen_func_elem_12170(arg0, arg1, addHeapObject(arg2));
2141
2257
  }
2142
2258
 
2143
- function __wasm_bindgen_func_elem_8668(arg0, arg1, arg2) {
2259
+ function __wasm_bindgen_func_elem_8693(arg0, arg1, arg2) {
2144
2260
  try {
2145
2261
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2146
- wasm.__wasm_bindgen_func_elem_8668(retptr, arg0, arg1, addHeapObject(arg2));
2262
+ wasm.__wasm_bindgen_func_elem_8693(retptr, arg0, arg1, addHeapObject(arg2));
2147
2263
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2148
2264
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2149
2265
  if (r1) {
@@ -2154,8 +2270,8 @@ function __wasm_bindgen_func_elem_8668(arg0, arg1, arg2) {
2154
2270
  }
2155
2271
  }
2156
2272
 
2157
- function __wasm_bindgen_func_elem_8722(arg0, arg1, arg2, arg3) {
2158
- wasm.__wasm_bindgen_func_elem_8722(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
2273
+ function __wasm_bindgen_func_elem_8748(arg0, arg1, arg2, arg3) {
2274
+ wasm.__wasm_bindgen_func_elem_8748(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
2159
2275
  }
2160
2276
 
2161
2277
 
@@ -2381,6 +2497,16 @@ function makeMutClosure(arg0, arg1, f) {
2381
2497
  return real;
2382
2498
  }
2383
2499
 
2500
+ function passArrayJsValueToWasm0(array, malloc) {
2501
+ const ptr = malloc(array.length * 4, 4) >>> 0;
2502
+ const mem = getDataViewMemory0();
2503
+ for (let i = 0; i < array.length; i++) {
2504
+ mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
2505
+ }
2506
+ WASM_VECTOR_LEN = array.length;
2507
+ return ptr;
2508
+ }
2509
+
2384
2510
  function passStringToWasm0(arg, malloc, realloc) {
2385
2511
  if (realloc === undefined) {
2386
2512
  const buf = cachedTextEncoder.encode(arg);
Binary file
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@janssenproject/cedarling_wasm",
3
3
  "type": "module",
4
4
  "description": "The Cedarling is a performant local authorization service that runs the Rust Cedar Engine",
5
- "version": "0.0.415",
5
+ "version": "0.0.416",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",