@agiledigital/pingone-aic-script-tester 0.1.0

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.
Files changed (169) hide show
  1. package/LICENSE-APACHE +201 -0
  2. package/LICENSE-MIT +21 -0
  3. package/README.md +274 -0
  4. package/dist/bin/fetch-jar.d.ts +2 -0
  5. package/dist/bin/fetch-jar.js +13 -0
  6. package/dist/bin/pull-profile.d.ts +2 -0
  7. package/dist/bin/pull-profile.js +40 -0
  8. package/dist/bin/show-log.d.ts +2 -0
  9. package/dist/bin/show-log.js +31 -0
  10. package/dist/classes/.complete +12 -0
  11. package/dist/classes/AmClassShutter.class +0 -0
  12. package/dist/classes/AmContextFactory$ObservedContext.class +0 -0
  13. package/dist/classes/AmContextFactory.class +0 -0
  14. package/dist/classes/AmScopes.class +0 -0
  15. package/dist/classes/HostOps.class +0 -0
  16. package/dist/classes/JsValues.class +0 -0
  17. package/dist/classes/Json$Parser.class +0 -0
  18. package/dist/classes/Json.class +0 -0
  19. package/dist/classes/LanguageVersions.class +0 -0
  20. package/dist/classes/Runner.class +0 -0
  21. package/dist/classes/ScriptContextScope.class +0 -0
  22. package/dist/src/aic/callbacks.d.ts +35 -0
  23. package/dist/src/aic/callbacks.js +130 -0
  24. package/dist/src/aic/conform.d.ts +90 -0
  25. package/dist/src/aic/conform.js +193 -0
  26. package/dist/src/aic/constants.d.ts +13 -0
  27. package/dist/src/aic/constants.js +13 -0
  28. package/dist/src/aic/diff.d.ts +25 -0
  29. package/dist/src/aic/diff.js +201 -0
  30. package/dist/src/aic/emit-journey.d.ts +64 -0
  31. package/dist/src/aic/emit-journey.js +254 -0
  32. package/dist/src/aic/emit-result.d.ts +10 -0
  33. package/dist/src/aic/emit-result.js +39 -0
  34. package/dist/src/aic/emit-session.d.ts +26 -0
  35. package/dist/src/aic/emit-session.js +132 -0
  36. package/dist/src/aic/emit-subject.d.ts +40 -0
  37. package/dist/src/aic/emit-subject.js +210 -0
  38. package/dist/src/aic/file-lease.d.ts +35 -0
  39. package/dist/src/aic/file-lease.js +543 -0
  40. package/dist/src/aic/http.d.ts +21 -0
  41. package/dist/src/aic/http.js +127 -0
  42. package/dist/src/aic/idm.d.ts +10 -0
  43. package/dist/src/aic/idm.js +112 -0
  44. package/dist/src/aic/index.d.ts +35 -0
  45. package/dist/src/aic/index.js +21 -0
  46. package/dist/src/aic/js.d.ts +8 -0
  47. package/dist/src/aic/js.js +11 -0
  48. package/dist/src/aic/lease-identity.d.ts +38 -0
  49. package/dist/src/aic/lease-identity.js +72 -0
  50. package/dist/src/aic/lease-lock.d.ts +45 -0
  51. package/dist/src/aic/lease-lock.js +173 -0
  52. package/dist/src/aic/managed.d.ts +28 -0
  53. package/dist/src/aic/managed.js +199 -0
  54. package/dist/src/aic/provider.d.ts +156 -0
  55. package/dist/src/aic/provider.js +416 -0
  56. package/dist/src/aic/record.d.ts +28 -0
  57. package/dist/src/aic/record.js +183 -0
  58. package/dist/src/aic/resource-snapshot.d.ts +12 -0
  59. package/dist/src/aic/resource-snapshot.js +116 -0
  60. package/dist/src/aic/run.d.ts +102 -0
  61. package/dist/src/aic/run.js +450 -0
  62. package/dist/src/aic/tenant.d.ts +107 -0
  63. package/dist/src/aic/tenant.js +307 -0
  64. package/dist/src/aic/trace.d.ts +25 -0
  65. package/dist/src/aic/trace.js +56 -0
  66. package/dist/src/aic/txid.d.ts +11 -0
  67. package/dist/src/aic/txid.js +25 -0
  68. package/dist/src/aic/unsupported.d.ts +15 -0
  69. package/dist/src/aic/unsupported.js +60 -0
  70. package/dist/src/bindings/allowlist.d.ts +42 -0
  71. package/dist/src/bindings/allowlist.js +62 -0
  72. package/dist/src/bindings/harvest.d.ts +7 -0
  73. package/dist/src/bindings/harvest.js +137 -0
  74. package/dist/src/bindings/index.d.ts +4 -0
  75. package/dist/src/bindings/index.js +3 -0
  76. package/dist/src/bindings/preamble.d.ts +23 -0
  77. package/dist/src/bindings/preamble.js +36 -0
  78. package/dist/src/bindings/run.d.ts +33 -0
  79. package/dist/src/bindings/run.js +55 -0
  80. package/dist/src/case/equal.d.ts +2 -0
  81. package/dist/src/case/equal.js +40 -0
  82. package/dist/src/case/index.d.ts +5 -0
  83. package/dist/src/case/index.js +4 -0
  84. package/dist/src/case/portable.d.ts +10 -0
  85. package/dist/src/case/portable.js +28 -0
  86. package/dist/src/case/session.d.ts +34 -0
  87. package/dist/src/case/session.js +66 -0
  88. package/dist/src/case/state.d.ts +4 -0
  89. package/dist/src/case/state.js +47 -0
  90. package/dist/src/case/types.d.ts +266 -0
  91. package/dist/src/case/types.js +106 -0
  92. package/dist/src/case/util.d.ts +7 -0
  93. package/dist/src/case/util.js +115 -0
  94. package/dist/src/case/validate.d.ts +8 -0
  95. package/dist/src/case/validate.js +463 -0
  96. package/dist/src/case/verdict.d.ts +6 -0
  97. package/dist/src/case/verdict.js +810 -0
  98. package/dist/src/diagnostics.d.ts +7 -0
  99. package/dist/src/diagnostics.js +5 -0
  100. package/dist/src/emit-dts.d.ts +2 -0
  101. package/dist/src/emit-dts.js +82 -0
  102. package/dist/src/emit-js.d.ts +3 -0
  103. package/dist/src/emit-js.js +149 -0
  104. package/dist/src/harness/failures.d.ts +26 -0
  105. package/dist/src/harness/failures.js +113 -0
  106. package/dist/src/harness/idm.d.ts +12 -0
  107. package/dist/src/harness/idm.js +44 -0
  108. package/dist/src/harness/index.d.ts +11 -0
  109. package/dist/src/harness/index.js +6 -0
  110. package/dist/src/harness/lease.d.ts +136 -0
  111. package/dist/src/harness/lease.js +286 -0
  112. package/dist/src/harness/residue.d.ts +23 -0
  113. package/dist/src/harness/residue.js +73 -0
  114. package/dist/src/harness/show-log.d.ts +43 -0
  115. package/dist/src/harness/show-log.js +253 -0
  116. package/dist/src/harness/spec.d.ts +67 -0
  117. package/dist/src/harness/spec.js +189 -0
  118. package/dist/src/harness/step.d.ts +80 -0
  119. package/dist/src/harness/step.js +97 -0
  120. package/dist/src/harness/types.d.ts +100 -0
  121. package/dist/src/harness/types.js +1 -0
  122. package/dist/src/harness/vitest.d.ts +52 -0
  123. package/dist/src/harness/vitest.js +155 -0
  124. package/dist/src/idents.d.ts +4 -0
  125. package/dist/src/idents.js +42 -0
  126. package/dist/src/jvm.d.ts +124 -0
  127. package/dist/src/jvm.js +432 -0
  128. package/dist/src/load.d.ts +2 -0
  129. package/dist/src/load.js +104 -0
  130. package/dist/src/paths.d.ts +36 -0
  131. package/dist/src/paths.js +50 -0
  132. package/dist/src/profile/index.d.ts +5 -0
  133. package/dist/src/profile/index.js +3 -0
  134. package/dist/src/profile/normalise.d.ts +16 -0
  135. package/dist/src/profile/normalise.js +106 -0
  136. package/dist/src/profile/pull.d.ts +22 -0
  137. package/dist/src/profile/pull.js +36 -0
  138. package/dist/src/profile/seed.d.ts +11 -0
  139. package/dist/src/profile/seed.js +28 -0
  140. package/dist/src/profile/store.d.ts +13 -0
  141. package/dist/src/profile/store.js +60 -0
  142. package/dist/src/profile/types.d.ts +45 -0
  143. package/dist/src/profile/types.js +1 -0
  144. package/dist/src/profile/validate.d.ts +38 -0
  145. package/dist/src/profile/validate.js +129 -0
  146. package/dist/src/project.d.ts +37 -0
  147. package/dist/src/project.js +93 -0
  148. package/dist/src/protocol.d.ts +62 -0
  149. package/dist/src/protocol.js +68 -0
  150. package/dist/src/provider-module.d.ts +11 -0
  151. package/dist/src/provider-module.js +46 -0
  152. package/dist/src/runner.d.ts +39 -0
  153. package/dist/src/runner.js +337 -0
  154. package/dist/src/schema.d.ts +48 -0
  155. package/dist/src/schema.js +93 -0
  156. package/generated/scripted-decision-mocks.cjs +722 -0
  157. package/generated/scripted-decision-mocks.d.ts +626 -0
  158. package/generated/scripted-decision-next.json +3640 -0
  159. package/java/AmClassShutter.java +98 -0
  160. package/java/AmContextFactory.java +69 -0
  161. package/java/AmScopes.java +49 -0
  162. package/java/HostOps.java +180 -0
  163. package/java/JsValues.java +39 -0
  164. package/java/Json.java +441 -0
  165. package/java/LanguageVersions.java +55 -0
  166. package/java/Runner.java +289 -0
  167. package/java/ScriptContextScope.java +147 -0
  168. package/package.json +88 -0
  169. package/src/bindings/rhino/runtime.cjs +3021 -0
@@ -0,0 +1,3021 @@
1
+ // Handwritten overlay on generated/scripted-decision-mocks.cjs.
2
+ // Evaluated inside AM's Rhino 1.7.14 (VERSION_DEFAULT): no let, no top-level
3
+ // const, no for...of, no object shorthand, no destructuring, no default
4
+ // parameters, and none of Map / Set / Symbol / Promise / WeakMap / WeakSet.
5
+ //
6
+ // Methods this file does not replace keep throwing
7
+ // `rhino-local: not mocked: <binding>.<method> …`.
8
+
9
+ var __rhinoLocal = {
10
+ shared: {},
11
+ transient: {},
12
+ secure: {},
13
+ initialShared: {},
14
+ initialTransient: {},
15
+ initialSecure: {},
16
+ managed: {},
17
+ esv: {},
18
+ esvProvided: false,
19
+ secrets: {},
20
+ secretsProvided: false,
21
+ bindings: {},
22
+ submittedCallbacks: null,
23
+ httpStubs: [],
24
+ generatedId: 0,
25
+ outcome: null,
26
+ callbacks: [],
27
+ openidm: [],
28
+ http: [],
29
+ logs: [],
30
+ libraries: {},
31
+ requireCache: {},
32
+ };
33
+
34
+ var sharedState;
35
+ var transientState;
36
+ var systemEnv;
37
+ var require;
38
+
39
+ function __rhinoLocalClone(value) {
40
+ return JSON.parse(JSON.stringify(value));
41
+ }
42
+
43
+ function __rhinoLocalHide(object, name, fn) {
44
+ if (typeof Object.defineProperty === "function") {
45
+ Object.defineProperty(object, name, {
46
+ enumerable: false,
47
+ configurable: true,
48
+ writable: true,
49
+ value: fn,
50
+ });
51
+ return;
52
+ }
53
+ object[name] = fn;
54
+ }
55
+
56
+ function __rhinoLocalExpectArity(path, args, expected) {
57
+ if (args.length !== expected) {
58
+ throw new Error(
59
+ "rhino-local: " +
60
+ path +
61
+ " arity=" +
62
+ args.length +
63
+ " (expected " +
64
+ expected +
65
+ ")"
66
+ );
67
+ }
68
+ }
69
+
70
+ function __rhinoLocalHas(object, key) {
71
+ return Object.prototype.hasOwnProperty.call(object, key);
72
+ }
73
+
74
+ function __rhinoLocalIsPlainObject(value) {
75
+ return (
76
+ value !== null &&
77
+ typeof value === "object" &&
78
+ !Array.isArray(value)
79
+ );
80
+ }
81
+
82
+ function __rhinoLocalAssignPlain(target, source) {
83
+ if (!__rhinoLocalIsPlainObject(source)) {
84
+ return;
85
+ }
86
+ var keys = Object.keys(source);
87
+ var i;
88
+ for (i = 0; i < keys.length; i += 1) {
89
+ target[keys[i]] = source[keys[i]];
90
+ }
91
+ }
92
+
93
+ function __rhinoLocalMergeBucket(bucketName, object) {
94
+ if (!__rhinoLocalIsPlainObject(object)) {
95
+ throw new Error(
96
+ "rhino-local: nodeState.merge" +
97
+ (bucketName === "shared" ? "Shared" : "Transient") +
98
+ ": expected an object"
99
+ );
100
+ }
101
+ var bucket = __rhinoLocal[bucketName];
102
+ var keys = Object.keys(object);
103
+ var i;
104
+ var key;
105
+ var incoming;
106
+ var existing;
107
+ var merged;
108
+ // Both merges refuse a nested plain object (measured), except inside
109
+ // objectAttributes (measured for mergeShared). Arrays were not measured.
110
+ for (i = 0; i < keys.length; i += 1) {
111
+ if (
112
+ keys[i] !== "objectAttributes" &&
113
+ __rhinoLocalIsPlainObject(object[keys[i]])
114
+ ) {
115
+ throw new InternalError(
116
+ "State must not contain nested objects unless they are inside registered state containers: objectAttributes"
117
+ );
118
+ }
119
+ }
120
+ for (i = 0; i < keys.length; i += 1) {
121
+ key = keys[i];
122
+ incoming = object[key];
123
+ existing = bucket[key];
124
+ if (__rhinoLocalIsPlainObject(existing) && __rhinoLocalIsPlainObject(incoming)) {
125
+ merged = {};
126
+ __rhinoLocalAssignPlain(merged, existing);
127
+ __rhinoLocalAssignPlain(merged, incoming);
128
+ bucket[key] = __rhinoLocalAsJavaMap(merged);
129
+ } else if (__rhinoLocalIsPlainObject(incoming)) {
130
+ // A merged object is stored as a Java map (measured); putShared's is not.
131
+ merged = {};
132
+ __rhinoLocalAssignPlain(merged, incoming);
133
+ bucket[key] = __rhinoLocalAsJavaMap(merged);
134
+ } else {
135
+ bucket[key] = incoming;
136
+ }
137
+ }
138
+ }
139
+
140
+ function __rhinoLocalJavaList(items) {
141
+ var list = [];
142
+ var i;
143
+ for (i = 0; i < items.length; i += 1) {
144
+ list.push(items[i]);
145
+ }
146
+ __rhinoLocalHide(list, "size", function () {
147
+ return this.length;
148
+ });
149
+ __rhinoLocalHide(list, "get", function (index) {
150
+ return this[index];
151
+ });
152
+ __rhinoLocalHide(list, "isEmpty", function () {
153
+ return this.length === 0;
154
+ });
155
+ __rhinoLocalHide(list, "contains", function (value) {
156
+ return this.indexOf(value) !== -1;
157
+ });
158
+ return list;
159
+ }
160
+
161
+ function __rhinoLocalRequestMap(values, options) {
162
+ var caseInsensitive = Boolean(options && options.caseInsensitive);
163
+ var asList = !(options && options.asList === false);
164
+ var map = {};
165
+ var store = {};
166
+ var keyCount = 0;
167
+ var names = values ? Object.keys(values) : [];
168
+ var i;
169
+ var raw;
170
+ var stored;
171
+ var value;
172
+ for (i = 0; i < names.length; i += 1) {
173
+ raw = names[i];
174
+ stored = caseInsensitive ? String(raw).toLowerCase() : String(raw);
175
+ value = values[raw];
176
+ if (asList) {
177
+ if (typeof value === "string") {
178
+ store[stored] = __rhinoLocalJavaList([value]);
179
+ } else {
180
+ store[stored] = __rhinoLocalJavaList(value);
181
+ }
182
+ } else {
183
+ store[stored] = value;
184
+ }
185
+ map[stored] = store[stored];
186
+ keyCount += 1;
187
+ }
188
+ __rhinoLocalHide(map, "get", function (name) {
189
+ __rhinoLocalExpectArity("map.get", arguments, 1);
190
+ var key = caseInsensitive ? String(name).toLowerCase() : String(name);
191
+ if (!__rhinoLocalHas(store, key)) {
192
+ return null;
193
+ }
194
+ return store[key];
195
+ });
196
+ __rhinoLocalHide(map, "containsKey", function (name) {
197
+ __rhinoLocalExpectArity("map.containsKey", arguments, 1);
198
+ var key = caseInsensitive ? String(name).toLowerCase() : String(name);
199
+ return __rhinoLocalHas(store, key);
200
+ });
201
+ __rhinoLocalHide(map, "size", function () {
202
+ return keyCount;
203
+ });
204
+ __rhinoLocalHide(map, "isEmpty", function () {
205
+ return keyCount === 0;
206
+ });
207
+ __rhinoLocalHide(map, "keySet", function () {
208
+ throw new Error(
209
+ "rhino-local: keySet is blocked by AM's class shutter; iterate with for...in"
210
+ );
211
+ });
212
+ return map;
213
+ }
214
+
215
+ /**
216
+ * `existingSession`: a String->String map of AM's own session properties plus
217
+ * anything a prior journey stored with `putSessionProperty`. Present only when
218
+ * the request carries a session cookie. Measured 2026-09-14 against a live
219
+ * tenant on both evaluators (docs/api/12-script-bindings-matrix.md).
220
+ *
221
+ * Deliberately NOT a plain object; each difference is one a plain object would
222
+ * get wrong in the false-pass direction:
223
+ * - `hasOwnProperty` is not reachable on AM's wrapper, so a script that calls
224
+ * it passes here and throws there. Hence the null prototype.
225
+ * - `keySet()` exists and is a trap: the returned java.util.HashMap$KeySet is
226
+ * refused by AM's class shutter. Iterate with for...in, as the request maps
227
+ * above already require.
228
+ * - `String(session)` renders per evaluator: next-gen wraps the map in
229
+ * MapScriptWrapper, whose toString is JSON-ish; legacy hands over the raw
230
+ * Java map, so it is AbstractMap.toString. Key ORDER is AM's hash order and
231
+ * is not reproduced -- seeding order is used instead.
232
+ */
233
+ function __rhinoLocalSessionMap(values, engine) {
234
+ var map = typeof Object.create === "function" ? Object.create(null) : {};
235
+ var names = values ? Object.keys(values) : [];
236
+ var legacy = engine === "legacy";
237
+ var i;
238
+ for (i = 0; i < names.length; i += 1) {
239
+ map[String(names[i])] = String(values[names[i]]);
240
+ }
241
+ __rhinoLocalHide(map, "get", function (key) {
242
+ __rhinoLocalExpectArity("existingSession.get", arguments, 1);
243
+ var k = String(key);
244
+ if (!__rhinoLocalHas(map, k)) {
245
+ return null;
246
+ }
247
+ return map[k];
248
+ });
249
+ __rhinoLocalHide(map, "put", function (key, value) {
250
+ __rhinoLocalExpectArity("existingSession.put", arguments, 2);
251
+ map[String(key)] = String(value);
252
+ });
253
+ __rhinoLocalHide(map, "containsKey", function (key) {
254
+ __rhinoLocalExpectArity("existingSession.containsKey", arguments, 1);
255
+ return __rhinoLocalHas(map, String(key));
256
+ });
257
+ __rhinoLocalHide(map, "size", function () {
258
+ return __rhinoLocalSessionKeys(map).length;
259
+ });
260
+ __rhinoLocalHide(map, "isEmpty", function () {
261
+ return __rhinoLocalSessionKeys(map).length === 0;
262
+ });
263
+ __rhinoLocalHide(map, "keySet", function () {
264
+ throw new Error(
265
+ "rhino-local: existingSession.keySet is blocked by AM's class shutter " +
266
+ '(Access to Java class "java.util.HashMap$KeySet" is prohibited); ' +
267
+ "iterate with for...in"
268
+ );
269
+ });
270
+ __rhinoLocalHide(map, "toString", function () {
271
+ var keys = __rhinoLocalSessionKeys(map);
272
+ var parts = [];
273
+ var j;
274
+ for (j = 0; j < keys.length; j += 1) {
275
+ if (legacy) {
276
+ parts.push(keys[j] + "=" + map[keys[j]]);
277
+ } else {
278
+ parts.push(
279
+ JSON.stringify(keys[j]) + ": " + JSON.stringify(map[keys[j]])
280
+ );
281
+ }
282
+ }
283
+ return legacy
284
+ ? "{" + parts.join(", ") + "}"
285
+ : "{ " + parts.join(", ") + " }";
286
+ });
287
+ return map;
288
+ }
289
+
290
+ function __rhinoLocalSessionKeys(map) {
291
+ var out = [];
292
+ var k;
293
+ for (k in map) {
294
+ if (__rhinoLocalHas(map, k)) {
295
+ out.push(k);
296
+ }
297
+ }
298
+ return out;
299
+ }
300
+
301
+ function __rhinoLocalStateMap(bucketName) {
302
+ var map = {};
303
+ __rhinoLocalHide(map, "get", function (key) {
304
+ __rhinoLocalExpectArity(bucketName + ".get", arguments, 1);
305
+ var k = String(key);
306
+ if (!__rhinoLocalHas(__rhinoLocal[bucketName], k)) {
307
+ return null;
308
+ }
309
+ return __rhinoLocal[bucketName][k];
310
+ });
311
+ __rhinoLocalHide(map, "put", function (key, value) {
312
+ __rhinoLocalExpectArity(bucketName + ".put", arguments, 2);
313
+ if (value === undefined) {
314
+ throw new Error("rhino-local: " + bucketName + ".put: value is undefined");
315
+ }
316
+ __rhinoLocal[bucketName][String(key)] = value;
317
+ });
318
+ return map;
319
+ }
320
+
321
+ function __rhinoLocalLookupState(key) {
322
+ if (__rhinoLocalHas(__rhinoLocal.transient, key)) {
323
+ return __rhinoLocal.transient[key];
324
+ }
325
+ if (__rhinoLocalHas(__rhinoLocal.secure, key)) {
326
+ return __rhinoLocal.secure[key];
327
+ }
328
+ if (__rhinoLocalHas(__rhinoLocal.shared, key)) {
329
+ return __rhinoLocal.shared[key];
330
+ }
331
+ return null;
332
+ }
333
+
334
+ function __rhinoLocalIsDefined(key) {
335
+ return (
336
+ __rhinoLocalHas(__rhinoLocal.transient, key) ||
337
+ __rhinoLocalHas(__rhinoLocal.secure, key) ||
338
+ __rhinoLocalHas(__rhinoLocal.shared, key)
339
+ );
340
+ }
341
+
342
+ nodeState.get = function (key) {
343
+ __rhinoLocalExpectArity("nodeState.get", arguments, 1);
344
+ return __rhinoLocalLookupState(String(key));
345
+ };
346
+
347
+ nodeState.isDefined = function (key) {
348
+ __rhinoLocalExpectArity("nodeState.isDefined", arguments, 1);
349
+ return __rhinoLocalIsDefined(String(key));
350
+ };
351
+
352
+ nodeState.putShared = function (key, value) {
353
+ __rhinoLocalExpectArity("nodeState.putShared", arguments, 2);
354
+ if (value === undefined) {
355
+ throw new Error("rhino-local: nodeState.putShared: value is undefined");
356
+ }
357
+ __rhinoLocal.shared[String(key)] = value;
358
+ return nodeState;
359
+ };
360
+
361
+ nodeState.putTransient = function (key, value) {
362
+ __rhinoLocalExpectArity("nodeState.putTransient", arguments, 2);
363
+ if (value === undefined) {
364
+ throw new Error("rhino-local: nodeState.putTransient: value is undefined");
365
+ }
366
+ __rhinoLocal.transient[String(key)] = value;
367
+ return nodeState;
368
+ };
369
+
370
+ nodeState.remove = function (key) {
371
+ __rhinoLocalExpectArity("nodeState.remove", arguments, 1);
372
+ var k = String(key);
373
+ delete __rhinoLocal.shared[k];
374
+ delete __rhinoLocal.transient[k];
375
+ delete __rhinoLocal.secure[k];
376
+ };
377
+
378
+ nodeState.keys = function () {
379
+ __rhinoLocalExpectArity("nodeState.keys", arguments, 0);
380
+ var seen = {};
381
+ var names = [];
382
+ function take(bucket) {
383
+ var keys = Object.keys(bucket);
384
+ var i;
385
+ var key;
386
+ for (i = 0; i < keys.length; i += 1) {
387
+ key = keys[i];
388
+ if (!__rhinoLocalHas(seen, key)) {
389
+ seen[key] = true;
390
+ names.push(key);
391
+ }
392
+ }
393
+ }
394
+ take(__rhinoLocal.transient);
395
+ take(__rhinoLocal.secure);
396
+ take(__rhinoLocal.shared);
397
+ var list = __rhinoLocalJavaList(names);
398
+ __rhinoLocalHide(list, "iterator", function () {
399
+ var index = 0;
400
+ return {
401
+ hasNext: function () {
402
+ return index < list.length;
403
+ },
404
+ next: function () {
405
+ return list[index++];
406
+ },
407
+ };
408
+ });
409
+ return list;
410
+ };
411
+
412
+ // How a Java map/list from nodeState.getObject prints (measured).
413
+ function __rhinoLocalJavaMapString(value) {
414
+ if (value === null) {
415
+ return "null";
416
+ }
417
+ if (Array.isArray(value)) {
418
+ var items = [];
419
+ var i;
420
+ for (i = 0; i < value.length; i += 1) {
421
+ items.push(__rhinoLocalJavaMapString(value[i]));
422
+ }
423
+ return "[ " + items.join(", ") + " ]";
424
+ }
425
+ if (__rhinoLocalIsPlainObject(value)) {
426
+ var keys = Object.keys(value);
427
+ var pairs = [];
428
+ var j;
429
+ for (j = 0; j < keys.length; j += 1) {
430
+ pairs.push(JSON.stringify(keys[j]) + ": " + __rhinoLocalJavaMapString(value[keys[j]]));
431
+ }
432
+ return "{ " + pairs.join(", ") + " }";
433
+ }
434
+ if (typeof value === "string") {
435
+ return JSON.stringify(value);
436
+ }
437
+ if (typeof value === "number" && Math.floor(value) === value) {
438
+ return String(value) + ".0";
439
+ }
440
+ return String(value);
441
+ }
442
+
443
+ // A plain object dressed as the Java map AIC hands back: it prints as one,
444
+ // and containsKey, size and keySet are functions (measured).
445
+ function __rhinoLocalAsJavaMap(map) {
446
+ var names = Object.keys(map);
447
+ __rhinoLocalHide(map, "toString", function () {
448
+ return __rhinoLocalJavaMapString(map);
449
+ });
450
+ __rhinoLocalHide(map, "containsKey", function (name) {
451
+ return names.indexOf(String(name)) !== -1;
452
+ });
453
+ __rhinoLocalHide(map, "size", function () {
454
+ return names.length;
455
+ });
456
+ __rhinoLocalHide(map, "keySet", function () {
457
+ return __rhinoLocalJavaList(names.slice());
458
+ });
459
+ return map;
460
+ }
461
+
462
+ nodeState.getObject = function (key) {
463
+ __rhinoLocalExpectArity("nodeState.getObject", arguments, 1);
464
+ var k = String(key);
465
+ var sharedVal = __rhinoLocalHas(__rhinoLocal.shared, k)
466
+ ? __rhinoLocal.shared[k]
467
+ : undefined;
468
+ var secureVal = __rhinoLocalHas(__rhinoLocal.secure, k)
469
+ ? __rhinoLocal.secure[k]
470
+ : undefined;
471
+ var transientVal = __rhinoLocalHas(__rhinoLocal.transient, k)
472
+ ? __rhinoLocal.transient[k]
473
+ : undefined;
474
+ if (
475
+ __rhinoLocalIsPlainObject(sharedVal) ||
476
+ __rhinoLocalIsPlainObject(secureVal) ||
477
+ __rhinoLocalIsPlainObject(transientVal)
478
+ ) {
479
+ var merged = {};
480
+ __rhinoLocalAssignPlain(merged, sharedVal);
481
+ __rhinoLocalAssignPlain(merged, secureVal);
482
+ __rhinoLocalAssignPlain(merged, transientVal);
483
+ return __rhinoLocalAsJavaMap(merged);
484
+ }
485
+ return __rhinoLocalLookupState(k);
486
+ };
487
+
488
+ nodeState.mergeShared = function (object) {
489
+ __rhinoLocalExpectArity("nodeState.mergeShared", arguments, 1);
490
+ __rhinoLocalMergeBucket("shared", object);
491
+ return nodeState;
492
+ };
493
+
494
+ nodeState.mergeTransient = function (object) {
495
+ __rhinoLocalExpectArity("nodeState.mergeTransient", arguments, 1);
496
+ __rhinoLocalMergeBucket("transient", object);
497
+ return nodeState;
498
+ };
499
+
500
+ // AIC's action is a Java wrapper; String(action) names its class (measured).
501
+ action.toString = function () {
502
+ return "org.forgerock.openam.auth.nodes.script.ActionWrapper@1b6d3586";
503
+ };
504
+
505
+ action.goTo = function (name) {
506
+ __rhinoLocalExpectArity("action.goTo", arguments, 1);
507
+ __rhinoLocal.outcome = String(name);
508
+ outcome = __rhinoLocal.outcome;
509
+ return action;
510
+ };
511
+
512
+ action.withErrorMessage = function (message) {
513
+ __rhinoLocalExpectArity("action.withErrorMessage", arguments, 1);
514
+ return action;
515
+ };
516
+
517
+ action.withHeader = function (header) {
518
+ __rhinoLocalExpectArity("action.withHeader", arguments, 1);
519
+ return action;
520
+ };
521
+
522
+ action.withIdentifiedUser = function (username) {
523
+ __rhinoLocalExpectArity("action.withIdentifiedUser", arguments, 1);
524
+ return action;
525
+ };
526
+
527
+ action.withIdentifiedAgent = function (agentName) {
528
+ __rhinoLocalExpectArity("action.withIdentifiedAgent", arguments, 1);
529
+ return action;
530
+ };
531
+
532
+ action.withStage = function (stage) {
533
+ __rhinoLocalExpectArity("action.withStage", arguments, 1);
534
+ return action;
535
+ };
536
+
537
+ action.withDescription = function (description) {
538
+ __rhinoLocalExpectArity("action.withDescription", arguments, 1);
539
+ return action;
540
+ };
541
+
542
+ action.withLockoutMessage = function (lockoutMessage) {
543
+ __rhinoLocalExpectArity("action.withLockoutMessage", arguments, 1);
544
+ return action;
545
+ };
546
+
547
+ action.putSessionProperty = function (key, value) {
548
+ __rhinoLocalExpectArity("action.putSessionProperty", arguments, 2);
549
+ return action;
550
+ };
551
+
552
+ action.removeSessionProperty = function (key) {
553
+ __rhinoLocalExpectArity("action.removeSessionProperty", arguments, 1);
554
+ return action;
555
+ };
556
+
557
+ // AIC's Integer parameter (measured): "120" and 1.5 convert, "x" does not,
558
+ // and null matches no overload.
559
+ function __rhinoLocalActionInteger(method, value) {
560
+ if (value === null) {
561
+ throw new InternalError(
562
+ "Can't find method org.forgerock.openam.auth.nodes.script.ActionWrapper." +
563
+ method +
564
+ "(null)."
565
+ );
566
+ }
567
+ if (isNaN(Number(value))) {
568
+ throw new InternalError("Cannot convert " + value + " to java.lang.Integer");
569
+ }
570
+ }
571
+
572
+ action.withMaxSessionTime = function (maxSessionTime) {
573
+ __rhinoLocalExpectArity("action.withMaxSessionTime", arguments, 1);
574
+ __rhinoLocalActionInteger("withMaxSessionTime", maxSessionTime);
575
+ return action;
576
+ };
577
+
578
+ action.withMaxIdleTime = function (maxIdleTime) {
579
+ __rhinoLocalExpectArity("action.withMaxIdleTime", arguments, 1);
580
+ __rhinoLocalActionInteger("withMaxIdleTime", maxIdleTime);
581
+ return action;
582
+ };
583
+
584
+ action.suspend = function (callbackTextFormat, additionalLogic) {
585
+ if (arguments.length < 1 || arguments.length > 3) {
586
+ throw new Error(
587
+ "rhino-local: action.suspend arity=" +
588
+ arguments.length +
589
+ " (expected 1..3)"
590
+ );
591
+ }
592
+ var message = String(callbackTextFormat);
593
+ var resumeUri = "https://rhino-local.invalid/resume";
594
+ if (arguments.length >= 2) {
595
+ if (typeof additionalLogic !== "function") {
596
+ throw new Error(
597
+ "rhino-local: action.suspend additionalLogic is not a function"
598
+ );
599
+ }
600
+ message = message.split("{0}").join(resumeUri);
601
+ additionalLogic(resumeUri);
602
+ }
603
+ __rhinoLocalCallback("SuspendedTextOutputCallback", { message: message });
604
+ return action;
605
+ };
606
+
607
+ function __rhinoLocalIsThrowable(value) {
608
+ return (
609
+ value !== null &&
610
+ typeof value === "object" &&
611
+ typeof value.getMessage === "function" &&
612
+ typeof value.getStackTrace === "function"
613
+ );
614
+ }
615
+
616
+ function __rhinoLocalFormat(pattern, bound) {
617
+ var out = "";
618
+ var i = 0;
619
+ var argIndex = 0;
620
+ var slashes;
621
+ var pairs;
622
+ var odd;
623
+ while (i < pattern.length) {
624
+ if (
625
+ pattern.charAt(i) === "{" &&
626
+ i + 1 < pattern.length &&
627
+ pattern.charAt(i + 1) === "}"
628
+ ) {
629
+ slashes = 0;
630
+ while (out.length - slashes > 0 && out.charAt(out.length - 1 - slashes) === "\\") {
631
+ slashes += 1;
632
+ }
633
+ pairs = Math.floor(slashes / 2);
634
+ odd = slashes % 2 === 1;
635
+ out = out.substring(0, out.length - slashes);
636
+ var p;
637
+ for (p = 0; p < pairs; p += 1) {
638
+ out += "\\";
639
+ }
640
+ if (odd) {
641
+ out += "{}";
642
+ } else if (argIndex < bound.length) {
643
+ out += String(bound[argIndex]);
644
+ argIndex += 1;
645
+ } else {
646
+ out += "{}";
647
+ }
648
+ i += 2;
649
+ } else {
650
+ out += pattern.charAt(i);
651
+ i += 1;
652
+ }
653
+ }
654
+ return out;
655
+ }
656
+
657
+ function __rhinoLocalLog(level, args) {
658
+ if (args.length < 1) {
659
+ throw new Error(
660
+ "rhino-local: logger." + level + " arity=" + args.length + " (expected >= 1)"
661
+ );
662
+ }
663
+ var format = String(args[0]);
664
+ var bound = [];
665
+ var i;
666
+ if (args.length === 2 && Array.isArray(args[1])) {
667
+ bound = args[1];
668
+ } else {
669
+ for (i = 1; i < args.length; i += 1) {
670
+ bound.push(args[i]);
671
+ }
672
+ }
673
+ if (bound.length > 0 && __rhinoLocalIsThrowable(bound[bound.length - 1])) {
674
+ bound = bound.slice(0, bound.length - 1);
675
+ }
676
+ __rhinoLocal.logs.push({
677
+ level: level,
678
+ message: __rhinoLocalFormat(format, bound),
679
+ });
680
+ }
681
+
682
+ logger.getName = function () {
683
+ return scriptName;
684
+ };
685
+
686
+ logger.trace = function () {
687
+ __rhinoLocalLog("trace", arguments);
688
+ };
689
+
690
+ logger.debug = function () {
691
+ __rhinoLocalLog("debug", arguments);
692
+ };
693
+
694
+ logger.info = function () {
695
+ __rhinoLocalLog("info", arguments);
696
+ };
697
+
698
+ logger.warn = function () {
699
+ __rhinoLocalLog("warn", arguments);
700
+ };
701
+
702
+ logger.error = function () {
703
+ __rhinoLocalLog("error", arguments);
704
+ };
705
+
706
+ logger.isTraceEnabled = function () {
707
+ return false;
708
+ };
709
+
710
+ logger.isDebugEnabled = function () {
711
+ return true;
712
+ };
713
+
714
+ logger.isInfoEnabled = function () {
715
+ return true;
716
+ };
717
+
718
+ logger.isWarnEnabled = function () {
719
+ return true;
720
+ };
721
+
722
+ logger.isErrorEnabled = function () {
723
+ return true;
724
+ };
725
+
726
+ function __rhinoLocalCallback(type, fields) {
727
+ var cb = { type: type };
728
+ var keys = Object.keys(fields);
729
+ var i;
730
+ var key;
731
+ for (i = 0; i < keys.length; i += 1) {
732
+ key = keys[i];
733
+ if (fields[key] !== undefined) {
734
+ cb[key] = fields[key];
735
+ }
736
+ }
737
+ __rhinoLocal.callbacks.push(cb);
738
+ }
739
+
740
+ callbacksBuilder.nameCallback = function (prompt, defaultName) {
741
+ if (arguments.length !== 1 && arguments.length !== 2) {
742
+ throw new Error(
743
+ "rhino-local: callbacksBuilder.nameCallback arity=" +
744
+ arguments.length +
745
+ " (expected 1 or 2)"
746
+ );
747
+ }
748
+ __rhinoLocalCallback("NameCallback", { prompt: String(prompt) });
749
+ };
750
+
751
+ callbacksBuilder.passwordCallback = function (prompt, echoOn) {
752
+ __rhinoLocalExpectArity("callbacksBuilder.passwordCallback", arguments, 2);
753
+ __rhinoLocalCallback("PasswordCallback", { prompt: String(prompt) });
754
+ };
755
+
756
+ callbacksBuilder.textOutputCallback = function (messageType, message) {
757
+ __rhinoLocalExpectArity("callbacksBuilder.textOutputCallback", arguments, 2);
758
+ __rhinoLocalCallback("TextOutputCallback", {
759
+ messageType: String(messageType),
760
+ message: String(message),
761
+ });
762
+ };
763
+
764
+ callbacksBuilder.hiddenValueCallback = function (id, value) {
765
+ __rhinoLocalExpectArity("callbacksBuilder.hiddenValueCallback", arguments, 2);
766
+ __rhinoLocalCallback("HiddenValueCallback", {
767
+ id: String(id),
768
+ value: String(value),
769
+ });
770
+ };
771
+
772
+ callbacksBuilder.confirmationCallback = function () {
773
+ var a = arguments;
774
+ var fields = {};
775
+ if (a.length === 3 && typeof a[0] === "number" && Array.isArray(a[1])) {
776
+ fields.prompt = "";
777
+ fields.messageType = a[0];
778
+ fields.options = a[1];
779
+ fields.optionType = -1;
780
+ fields.defaultOption = a[2];
781
+ } else if (a.length === 3 && typeof a[0] === "number") {
782
+ fields.prompt = "";
783
+ fields.messageType = a[0];
784
+ fields.options = [];
785
+ fields.optionType = a[1];
786
+ fields.defaultOption = a[2];
787
+ } else if (a.length === 4 && Array.isArray(a[2])) {
788
+ fields.prompt = String(a[0]);
789
+ fields.messageType = a[1];
790
+ fields.options = a[2];
791
+ fields.optionType = -1;
792
+ fields.defaultOption = a[3];
793
+ } else if (a.length === 4) {
794
+ fields.prompt = String(a[0]);
795
+ fields.messageType = a[1];
796
+ fields.options = [];
797
+ fields.optionType = a[2];
798
+ fields.defaultOption = a[3];
799
+ } else {
800
+ throw new Error(
801
+ "rhino-local: callbacksBuilder.confirmationCallback arity=" + a.length
802
+ );
803
+ }
804
+ __rhinoLocalCallback("ConfirmationCallback", fields);
805
+ };
806
+
807
+ callbacksBuilder.choiceCallback = function (
808
+ prompt,
809
+ choices,
810
+ defaultChoice,
811
+ multipleSelectionsAllowed
812
+ ) {
813
+ __rhinoLocalExpectArity("callbacksBuilder.choiceCallback", arguments, 4);
814
+ __rhinoLocalCallback("ChoiceCallback", {
815
+ prompt: String(prompt),
816
+ choices: choices,
817
+ defaultChoice: defaultChoice,
818
+ });
819
+ };
820
+
821
+ callbacksBuilder.radioChoiceCallback = function (prompt, choices, defaultChoice) {
822
+ __rhinoLocalExpectArity("callbacksBuilder.radioChoiceCallback", arguments, 3);
823
+ __rhinoLocalCallback("ChoiceCallback", {
824
+ prompt: String(prompt),
825
+ choices: choices,
826
+ defaultChoice: defaultChoice,
827
+ radio: true,
828
+ });
829
+ };
830
+
831
+ callbacksBuilder.suspendedTextOutputCallback = function (messageType, message) {
832
+ __rhinoLocalExpectArity(
833
+ "callbacksBuilder.suspendedTextOutputCallback",
834
+ arguments,
835
+ 2
836
+ );
837
+ __rhinoLocalCallback("SuspendedTextOutputCallback", {
838
+ messageType: String(messageType),
839
+ message: String(message),
840
+ });
841
+ };
842
+
843
+ callbacksBuilder.textInputCallback = function (prompt, defaultText) {
844
+ if (arguments.length !== 1 && arguments.length !== 2) {
845
+ throw new Error(
846
+ "rhino-local: callbacksBuilder.textInputCallback arity=" +
847
+ arguments.length +
848
+ " (expected 1 or 2)"
849
+ );
850
+ }
851
+ var textFields = { prompt: String(prompt) };
852
+ textFields.defaultText = arguments.length > 1 ? String(defaultText) : "";
853
+ __rhinoLocalCallback("TextInputCallback", textFields);
854
+ };
855
+
856
+ callbacksBuilder.scriptTextOutputCallback = function (message) {
857
+ __rhinoLocalExpectArity(
858
+ "callbacksBuilder.scriptTextOutputCallback",
859
+ arguments,
860
+ 1
861
+ );
862
+ __rhinoLocalCallback("TextOutputCallback", {
863
+ message: String(message),
864
+ messageType: "4",
865
+ });
866
+ };
867
+
868
+ callbacksBuilder.languageCallback = function (language, country) {
869
+ __rhinoLocalExpectArity("callbacksBuilder.languageCallback", arguments, 2);
870
+ __rhinoLocalCallback("LanguageCallback", {});
871
+ };
872
+
873
+ callbacksBuilder.idPCallback = function (
874
+ provider,
875
+ clientId,
876
+ redirectUri,
877
+ scope,
878
+ nonce,
879
+ request,
880
+ requestUri,
881
+ acrValues,
882
+ requestNativeAppForUserInfo,
883
+ token,
884
+ tokenType
885
+ ) {
886
+ if (arguments.length !== 9 && arguments.length !== 11) {
887
+ throw new Error(
888
+ "rhino-local: callbacksBuilder.idPCallback arity=" +
889
+ arguments.length +
890
+ " (expected 9 or 11)"
891
+ );
892
+ }
893
+ var idpFields = {
894
+ provider: String(provider),
895
+ clientId: String(clientId),
896
+ redirectUri: String(redirectUri),
897
+ scopes: scope,
898
+ nonce: String(nonce),
899
+ request: String(request),
900
+ requestUri: String(requestUri),
901
+ acrValues: acrValues,
902
+ acceptsJSON: Boolean(requestNativeAppForUserInfo),
903
+ };
904
+ __rhinoLocalCallback("IdPCallback", idpFields);
905
+ };
906
+
907
+ callbacksBuilder.httpCallback = function () {
908
+ var a = arguments;
909
+ if (a.length === 4) {
910
+ __rhinoLocalCallback("HttpCallback", {
911
+ authRHeader: String(a[0]),
912
+ negoName: String(a[1]),
913
+ negoValue: String(a[2]),
914
+ errorCode: a[3],
915
+ });
916
+ return;
917
+ }
918
+ if (a.length === 3) {
919
+ __rhinoLocalCallback("HttpCallback", {
920
+ authorizationHeader: String(a[0]),
921
+ negotiationHeader: String(a[1]),
922
+ errorCode: a[2],
923
+ });
924
+ return;
925
+ }
926
+ throw new Error(
927
+ "rhino-local: callbacksBuilder.httpCallback arity=" + a.length
928
+ );
929
+ };
930
+
931
+ callbacksBuilder.x509CertificateCallback = function (
932
+ prompt,
933
+ certificate,
934
+ requestSignature
935
+ ) {
936
+ if (arguments.length < 1 || arguments.length > 3) {
937
+ throw new Error(
938
+ "rhino-local: callbacksBuilder.x509CertificateCallback arity=" +
939
+ arguments.length +
940
+ " (expected 1..3)"
941
+ );
942
+ }
943
+ var x509 = { prompt: String(prompt) };
944
+ if (arguments.length > 1) {
945
+ x509.certificate = certificate;
946
+ }
947
+ if (arguments.length > 2) {
948
+ x509.requestSignature = Boolean(requestSignature);
949
+ }
950
+ __rhinoLocalCallback("X509CertificateCallback", x509);
951
+ };
952
+
953
+ callbacksBuilder.consentMappingCallback = function () {
954
+ var a = arguments;
955
+ if (a.length === 7) {
956
+ __rhinoLocalCallback("ConsentMappingCallback", {
957
+ name: String(a[0]),
958
+ displayName: String(a[1]),
959
+ icon: String(a[2]),
960
+ accessLevel: String(a[3]),
961
+ fields: a[4],
962
+ message: String(a[5]),
963
+ isRequired: Boolean(a[6]),
964
+ });
965
+ return;
966
+ }
967
+ if (a.length === 3) {
968
+ var config = a[0];
969
+ var emptyFields = [];
970
+ var i;
971
+ // AIC streams config.fields and fails without it (measured).
972
+ if (!config || !Array.isArray(config.fields)) {
973
+ throw new Error(
974
+ "rhino-local: consentMappingCallback config needs a fields list; AIC refuses one without"
975
+ );
976
+ }
977
+ for (i = 0; i < config.fields.length; i += 1) {
978
+ emptyFields.push(null);
979
+ }
980
+ __rhinoLocalCallback("ConsentMappingCallback", {
981
+ name: String(config.name),
982
+ displayName: String(config.displayName),
983
+ icon: String(config.icon),
984
+ accessLevel: String(config.accessLevel),
985
+ fields: emptyFields,
986
+ message: String(a[1]),
987
+ isRequired: Boolean(a[2]),
988
+ });
989
+ return;
990
+ }
991
+ throw new Error(
992
+ "rhino-local: callbacksBuilder.consentMappingCallback arity=" + a.length
993
+ );
994
+ };
995
+
996
+ callbacksBuilder.deviceProfileCallback = function (metadata, location, message) {
997
+ __rhinoLocalExpectArity("callbacksBuilder.deviceProfileCallback", arguments, 3);
998
+ __rhinoLocalCallback("DeviceProfileCallback", {
999
+ metadata: Boolean(metadata),
1000
+ location: Boolean(location),
1001
+ message: String(message),
1002
+ });
1003
+ };
1004
+
1005
+ callbacksBuilder.kbaCreateCallback = function (
1006
+ prompt,
1007
+ predefinedQuestions,
1008
+ allowUserDefinedQuestions
1009
+ ) {
1010
+ __rhinoLocalExpectArity("callbacksBuilder.kbaCreateCallback", arguments, 3);
1011
+ __rhinoLocalCallback("KbaCreateCallback", {
1012
+ prompt: String(prompt),
1013
+ predefinedQuestions: predefinedQuestions,
1014
+ allowUserDefinedQuestions: Boolean(allowUserDefinedQuestions),
1015
+ });
1016
+ };
1017
+
1018
+ callbacksBuilder.selectIdPCallback = function (providers) {
1019
+ __rhinoLocalExpectArity("callbacksBuilder.selectIdPCallback", arguments, 1);
1020
+ __rhinoLocalCallback("SelectIdPCallback", { providers: providers, value: "" });
1021
+ };
1022
+
1023
+ callbacksBuilder.termsAndConditionsCallback = function (version, terms, createDate) {
1024
+ __rhinoLocalExpectArity(
1025
+ "callbacksBuilder.termsAndConditionsCallback",
1026
+ arguments,
1027
+ 3
1028
+ );
1029
+ __rhinoLocalCallback("TermsAndConditionsCallback", {
1030
+ version: String(version),
1031
+ terms: String(terms),
1032
+ createDate: String(createDate),
1033
+ });
1034
+ };
1035
+
1036
+ callbacksBuilder.metadataCallback = function (outputValue) {
1037
+ __rhinoLocalExpectArity("callbacksBuilder.metadataCallback", arguments, 1);
1038
+ __rhinoLocalCallback("MetadataCallback", { data: outputValue });
1039
+ };
1040
+
1041
+ callbacksBuilder.pollingWaitCallback = function (waitTime, message) {
1042
+ __rhinoLocalExpectArity("callbacksBuilder.pollingWaitCallback", arguments, 2);
1043
+ __rhinoLocalCallback("PollingWaitCallback", {
1044
+ waitTime: String(waitTime),
1045
+ message: String(message),
1046
+ });
1047
+ };
1048
+
1049
+ callbacksBuilder.redirectCallback = function (
1050
+ redirectUrl,
1051
+ redirectData,
1052
+ method,
1053
+ fourth,
1054
+ fifth,
1055
+ sixth
1056
+ ) {
1057
+ var a = arguments;
1058
+ var redirectFields = {
1059
+ redirectUrl: String(redirectUrl),
1060
+ redirectData: redirectData,
1061
+ redirectMethod: String(method),
1062
+ // Follows the argument; the status parameter and redirect-back cookie are
1063
+ // not rendered (both measured).
1064
+ trackingCookie:
1065
+ a.length === 4 ? Boolean(fourth) : a.length === 6 ? Boolean(sixth) : false,
1066
+ };
1067
+ if (a.length >= 3 && a.length <= 6) {
1068
+ __rhinoLocalCallback("RedirectCallback", redirectFields);
1069
+ return;
1070
+ }
1071
+ throw new Error(
1072
+ "rhino-local: callbacksBuilder.redirectCallback arity=" + a.length
1073
+ );
1074
+ };
1075
+
1076
+ function __rhinoLocalAttributeCallback(type, args) {
1077
+ var fields = {
1078
+ name: String(args[0]),
1079
+ prompt: String(args[1]),
1080
+ value: args[2],
1081
+ required: Boolean(args[3]),
1082
+ policies: [],
1083
+ failedPolicies: [],
1084
+ validateOnly: false,
1085
+ };
1086
+ if (args.length === 4) {
1087
+ __rhinoLocalCallback(type, fields);
1088
+ return;
1089
+ }
1090
+ if (args.length === 5) {
1091
+ fields.failedPolicies = args[4];
1092
+ __rhinoLocalCallback(type, fields);
1093
+ return;
1094
+ }
1095
+ if (args.length === 6) {
1096
+ fields.policies = args[4];
1097
+ fields.validateOnly = Boolean(args[5]);
1098
+ __rhinoLocalCallback(type, fields);
1099
+ return;
1100
+ }
1101
+ if (args.length === 7) {
1102
+ fields.policies = args[4];
1103
+ fields.validateOnly = Boolean(args[5]);
1104
+ fields.failedPolicies = args[6];
1105
+ __rhinoLocalCallback(type, fields);
1106
+ return;
1107
+ }
1108
+ throw new Error(
1109
+ "rhino-local: callbacksBuilder." +
1110
+ type.charAt(0).toLowerCase() +
1111
+ type.substring(1) +
1112
+ " arity=" +
1113
+ args.length
1114
+ );
1115
+ }
1116
+
1117
+ callbacksBuilder.stringAttributeInputCallback = function () {
1118
+ __rhinoLocalAttributeCallback("StringAttributeInputCallback", arguments);
1119
+ };
1120
+
1121
+ callbacksBuilder.numberAttributeInputCallback = function () {
1122
+ __rhinoLocalAttributeCallback("NumberAttributeInputCallback", arguments);
1123
+ };
1124
+
1125
+ callbacksBuilder.booleanAttributeInputCallback = function () {
1126
+ __rhinoLocalAttributeCallback("BooleanAttributeInputCallback", arguments);
1127
+ };
1128
+
1129
+ callbacksBuilder.validatedUsernameCallback = function (
1130
+ prompt,
1131
+ policies,
1132
+ validateOnly,
1133
+ failedPolicies
1134
+ ) {
1135
+ if (arguments.length !== 3 && arguments.length !== 4) {
1136
+ throw new Error(
1137
+ "rhino-local: callbacksBuilder.validatedUsernameCallback arity=" +
1138
+ arguments.length +
1139
+ " (expected 3 or 4)"
1140
+ );
1141
+ }
1142
+ var userFields = {
1143
+ prompt: String(prompt),
1144
+ policies: policies,
1145
+ validateOnly: Boolean(validateOnly),
1146
+ failedPolicies: [],
1147
+ };
1148
+ if (arguments.length === 4) {
1149
+ userFields.failedPolicies = failedPolicies;
1150
+ }
1151
+ __rhinoLocalCallback("ValidatedCreateUsernameCallback", userFields);
1152
+ };
1153
+
1154
+ callbacksBuilder.validatedPasswordCallback = function (
1155
+ prompt,
1156
+ echoOn,
1157
+ policies,
1158
+ validateOnly,
1159
+ failedPolicies
1160
+ ) {
1161
+ if (arguments.length !== 4 && arguments.length !== 5) {
1162
+ throw new Error(
1163
+ "rhino-local: callbacksBuilder.validatedPasswordCallback arity=" +
1164
+ arguments.length +
1165
+ " (expected 4 or 5)"
1166
+ );
1167
+ }
1168
+ var pwFields = {
1169
+ prompt: String(prompt),
1170
+ echoOn: Boolean(echoOn),
1171
+ policies: policies,
1172
+ validateOnly: Boolean(validateOnly),
1173
+ failedPolicies: [],
1174
+ };
1175
+ if (arguments.length === 5) {
1176
+ pwFields.failedPolicies = failedPolicies;
1177
+ }
1178
+ __rhinoLocalCallback("ValidatedCreatePasswordCallback", pwFields);
1179
+ };
1180
+
1181
+ function __rhinoLocalRequireSubmitted() {
1182
+ if (__rhinoLocal.submittedCallbacks === null) {
1183
+ throw new Error("rhino-local: callbacks: no given.callbacks");
1184
+ }
1185
+ return __rhinoLocal.submittedCallbacks;
1186
+ }
1187
+
1188
+ // A Java List as AIC's getters return it: indexable, size/get/isEmpty/contains, and
1189
+ // printed "[a, b]" with each element formatted by format().
1190
+ function __rhinoLocalCallbackList(items, format) {
1191
+ var list = {};
1192
+ var i;
1193
+ for (i = 0; i < items.length; i += 1) {
1194
+ list[i] = items[i];
1195
+ }
1196
+ Object.defineProperty(list, "length", {
1197
+ enumerable: false,
1198
+ configurable: true,
1199
+ writable: true,
1200
+ value: items.length
1201
+ });
1202
+ __rhinoLocalHide(list, "size", function () {
1203
+ return items.length;
1204
+ });
1205
+ __rhinoLocalHide(list, "get", function (index) {
1206
+ return items[index] === undefined ? null : items[index];
1207
+ });
1208
+ __rhinoLocalHide(list, "isEmpty", function () {
1209
+ return items.length === 0;
1210
+ });
1211
+ __rhinoLocalHide(list, "contains", function (value) {
1212
+ return items.indexOf(value) !== -1;
1213
+ });
1214
+ __rhinoLocalHide(list, "toString", function () {
1215
+ var values = [];
1216
+ var j;
1217
+ for (j = 0; j < items.length; j += 1) {
1218
+ values.push(format(items[j]));
1219
+ }
1220
+ return "[" + values.join(", ") + "]";
1221
+ });
1222
+ return list;
1223
+ }
1224
+
1225
+ function __rhinoLocalCallbackValueString(value) {
1226
+ if (Array.isArray(value)) {
1227
+ return "[" + value.map(__rhinoLocalCallbackValueString).join(", ") + "]";
1228
+ }
1229
+ if (value === null || value === undefined) {
1230
+ return "null";
1231
+ }
1232
+ return String(value);
1233
+ }
1234
+
1235
+ function __rhinoLocalCallbackMap(values) {
1236
+ var map = {};
1237
+ var keys = Object.keys(values);
1238
+ var i;
1239
+ for (i = 0; i < keys.length; i += 1) {
1240
+ map[keys[i]] = values[keys[i]];
1241
+ }
1242
+ __rhinoLocalHide(map, "size", function () {
1243
+ return keys.length;
1244
+ });
1245
+ __rhinoLocalHide(map, "get", function (key) {
1246
+ return __rhinoLocalHas(map, String(key)) ? map[String(key)] : null;
1247
+ });
1248
+ __rhinoLocalHide(map, "toString", function () {
1249
+ return __rhinoLocalJavaMapString(map);
1250
+ });
1251
+ __rhinoLocalHide(map, "__javaString", function () {
1252
+ var pairs = [];
1253
+ var j;
1254
+ for (j = 0; j < keys.length; j += 1) {
1255
+ pairs.push(keys[j] + "=" + __rhinoLocalCallbackValueString(map[keys[j]]));
1256
+ }
1257
+ return "{" + pairs.join(", ") + "}";
1258
+ });
1259
+ return map;
1260
+ }
1261
+
1262
+ // A List of Java maps prints each as "{k=v, …}" (Map.toString).
1263
+ function __rhinoLocalCallbackMapList(maps) {
1264
+ return __rhinoLocalCallbackList(maps, function (m) {
1265
+ return m.__javaString();
1266
+ });
1267
+ }
1268
+
1269
+ function __rhinoLocalSubmittedValues(type) {
1270
+ var submitted = __rhinoLocalRequireSubmitted();
1271
+ var out = [];
1272
+ var i;
1273
+ var cb;
1274
+ for (i = 0; i < submitted.length; i += 1) {
1275
+ cb = submitted[i];
1276
+ if (cb.type === type) {
1277
+ if (cb.value === undefined) {
1278
+ throw new Error(
1279
+ "rhino-local: given.callbacks[" +
1280
+ i +
1281
+ "] (" +
1282
+ type +
1283
+ ") has no value"
1284
+ );
1285
+ }
1286
+ out.push(cb.value);
1287
+ }
1288
+ }
1289
+ // Number values are Doubles on AIC: [7.0].
1290
+ var decimal = type === "NumberAttributeInputCallback";
1291
+ return __rhinoLocalCallbackList(out, function (value) {
1292
+ return decimal && typeof value === "number" && Math.floor(value) === value
1293
+ ? String(value) + ".0"
1294
+ : String(value);
1295
+ });
1296
+ }
1297
+
1298
+ callbacks.isEmpty = function () {
1299
+ __rhinoLocalExpectArity("callbacks.isEmpty", arguments, 0);
1300
+ return __rhinoLocalRequireSubmitted().length === 0;
1301
+ };
1302
+
1303
+ callbacks.getNameCallbacks = function () {
1304
+ __rhinoLocalExpectArity("callbacks.getNameCallbacks", arguments, 0);
1305
+ return __rhinoLocalSubmittedValues("NameCallback");
1306
+ };
1307
+
1308
+ callbacks.getPasswordCallbacks = function () {
1309
+ __rhinoLocalExpectArity("callbacks.getPasswordCallbacks", arguments, 0);
1310
+ return __rhinoLocalSubmittedValues("PasswordCallback");
1311
+ };
1312
+
1313
+ callbacks.getHiddenValueCallbacks = function () {
1314
+ __rhinoLocalExpectArity("callbacks.getHiddenValueCallbacks", arguments, 0);
1315
+ var submitted = __rhinoLocalRequireSubmitted();
1316
+ var values = {};
1317
+ var i;
1318
+ for (i = 0; i < submitted.length; i += 1) {
1319
+ if (submitted[i].type === "HiddenValueCallback") {
1320
+ values[String(submitted[i].id)] = submitted[i].value;
1321
+ }
1322
+ }
1323
+ return __rhinoLocalCallbackMap(values);
1324
+ };
1325
+
1326
+ callbacks.getDeviceProfileCallbacks = function () {
1327
+ __rhinoLocalExpectArity("callbacks.getDeviceProfileCallbacks", arguments, 0);
1328
+ return __rhinoLocalSubmittedValues("DeviceProfileCallback");
1329
+ };
1330
+
1331
+ callbacks.getKbaCreateCallbacks = function () {
1332
+ __rhinoLocalExpectArity("callbacks.getKbaCreateCallbacks", arguments, 0);
1333
+ var submitted = __rhinoLocalRequireSubmitted();
1334
+ var maps = [];
1335
+ var i;
1336
+ for (i = 0; i < submitted.length; i += 1) {
1337
+ if (submitted[i].type === "KbaCreateCallback") {
1338
+ maps.push(__rhinoLocalCallbackMap({
1339
+ selectedAnswer: submitted[i].selectedAnswer,
1340
+ selectedQuestion: submitted[i].selectedQuestion,
1341
+ }));
1342
+ }
1343
+ }
1344
+ return __rhinoLocalCallbackMapList(maps);
1345
+ };
1346
+
1347
+ callbacks.getSelectIdPCallbacks = function () {
1348
+ __rhinoLocalExpectArity("callbacks.getSelectIdPCallbacks", arguments, 0);
1349
+ return __rhinoLocalSubmittedValues("SelectIdPCallback");
1350
+ };
1351
+
1352
+ callbacks.getTermsAndConditionsCallbacks = function () {
1353
+ __rhinoLocalExpectArity(
1354
+ "callbacks.getTermsAndConditionsCallbacks",
1355
+ arguments,
1356
+ 0
1357
+ );
1358
+ return __rhinoLocalSubmittedValues("TermsAndConditionsCallback");
1359
+ };
1360
+
1361
+ callbacks.getTextInputCallbacks = function () {
1362
+ __rhinoLocalExpectArity("callbacks.getTextInputCallbacks", arguments, 0);
1363
+ return __rhinoLocalSubmittedValues("TextInputCallback");
1364
+ };
1365
+
1366
+ callbacks.getStringAttributeInputCallbacks = function () {
1367
+ __rhinoLocalExpectArity(
1368
+ "callbacks.getStringAttributeInputCallbacks",
1369
+ arguments,
1370
+ 0
1371
+ );
1372
+ return __rhinoLocalSubmittedValues("StringAttributeInputCallback");
1373
+ };
1374
+
1375
+ callbacks.getNumberAttributeInputCallbacks = function () {
1376
+ __rhinoLocalExpectArity(
1377
+ "callbacks.getNumberAttributeInputCallbacks",
1378
+ arguments,
1379
+ 0
1380
+ );
1381
+ return __rhinoLocalSubmittedValues("NumberAttributeInputCallback");
1382
+ };
1383
+
1384
+ callbacks.getBooleanAttributeInputCallbacks = function () {
1385
+ __rhinoLocalExpectArity(
1386
+ "callbacks.getBooleanAttributeInputCallbacks",
1387
+ arguments,
1388
+ 0
1389
+ );
1390
+ return __rhinoLocalSubmittedValues("BooleanAttributeInputCallback");
1391
+ };
1392
+
1393
+ callbacks.getConfirmationCallbacks = function () {
1394
+ __rhinoLocalExpectArity("callbacks.getConfirmationCallbacks", arguments, 0);
1395
+ return __rhinoLocalSubmittedValues("ConfirmationCallback");
1396
+ };
1397
+
1398
+ callbacks.getLanguageCallbacks = function () {
1399
+ __rhinoLocalExpectArity("callbacks.getLanguageCallbacks", arguments, 0);
1400
+ return __rhinoLocalSubmittedValues("LanguageCallback");
1401
+ };
1402
+
1403
+ callbacks.getIdpCallbacks = function () {
1404
+ __rhinoLocalExpectArity("callbacks.getIdpCallbacks", arguments, 0);
1405
+ var submitted = __rhinoLocalRequireSubmitted();
1406
+ var maps = [];
1407
+ var i;
1408
+ for (i = 0; i < submitted.length; i += 1) {
1409
+ if (submitted[i].type === "IdPCallback") {
1410
+ // nodeName, userInfo and requestNativeAppForUserInfo are not in the
1411
+ // rendered callback; these are the values AIC's map held (measured).
1412
+ maps.push(__rhinoLocalCallbackMap({
1413
+ nodeName: "IdPCallback",
1414
+ redirectUri: submitted[i].redirectUri,
1415
+ request: submitted[i].request,
1416
+ acrValues: submitted[i].acrValues,
1417
+ userInfo: null,
1418
+ clientId: submitted[i].clientId,
1419
+ requestNativeAppForUserInfo: false,
1420
+ requestUri: submitted[i].requestUri,
1421
+ nonce: submitted[i].nonce,
1422
+ token: submitted[i].token,
1423
+ provider: submitted[i].provider,
1424
+ scope: submitted[i].scopes,
1425
+ tokenType: submitted[i].tokenType,
1426
+ }));
1427
+ }
1428
+ }
1429
+ return __rhinoLocalCallbackMapList(maps);
1430
+ };
1431
+
1432
+ callbacks.getValidatedPasswordCallbacks = function () {
1433
+ __rhinoLocalExpectArity(
1434
+ "callbacks.getValidatedPasswordCallbacks",
1435
+ arguments,
1436
+ 0
1437
+ );
1438
+ return __rhinoLocalValidatedCallbacks("ValidatedCreatePasswordCallback");
1439
+ };
1440
+
1441
+ callbacks.getValidatedUsernameCallbacks = function () {
1442
+ __rhinoLocalExpectArity(
1443
+ "callbacks.getValidatedUsernameCallbacks",
1444
+ arguments,
1445
+ 0
1446
+ );
1447
+ return __rhinoLocalValidatedCallbacks("ValidatedCreateUsernameCallback");
1448
+ };
1449
+
1450
+ function __rhinoLocalValidatedCallbacks(type) {
1451
+ var submitted = __rhinoLocalRequireSubmitted();
1452
+ var maps = [];
1453
+ var i;
1454
+ for (i = 0; i < submitted.length; i += 1) {
1455
+ if (submitted[i].type === type) {
1456
+ maps.push(__rhinoLocalCallbackMap({
1457
+ validateOnly: submitted[i].validateOnly,
1458
+ value: submitted[i].value,
1459
+ }));
1460
+ }
1461
+ }
1462
+ return __rhinoLocalCallbackMapList(maps);
1463
+ }
1464
+
1465
+ callbacks.getHttpCallbacks = function () {
1466
+ __rhinoLocalExpectArity("callbacks.getHttpCallbacks", arguments, 0);
1467
+ return __rhinoLocalSubmittedValues("HttpCallback");
1468
+ };
1469
+
1470
+ callbacks.getX509CertificateCallbacks = function () {
1471
+ __rhinoLocalExpectArity("callbacks.getX509CertificateCallbacks", arguments, 0);
1472
+ return __rhinoLocalSubmittedValues("X509CertificateCallback");
1473
+ };
1474
+
1475
+ callbacks.getConsentMappingCallbacks = function () {
1476
+ __rhinoLocalExpectArity("callbacks.getConsentMappingCallbacks", arguments, 0);
1477
+ return __rhinoLocalSubmittedValues("ConsentMappingCallback");
1478
+ };
1479
+
1480
+ callbacks.getChoiceCallbacks = function () {
1481
+ __rhinoLocalExpectArity("callbacks.getChoiceCallbacks", arguments, 0);
1482
+ return __rhinoLocalSubmittedValues("ChoiceCallback");
1483
+ };
1484
+
1485
+ function __rhinoLocalSplitResource(id) {
1486
+ var s = String(id);
1487
+ var parts = s.split("/");
1488
+ if (parts.length >= 3) {
1489
+ return {
1490
+ collection: parts.slice(0, parts.length - 1).join("/"),
1491
+ recordId: parts[parts.length - 1],
1492
+ };
1493
+ }
1494
+ return { collection: s, recordId: null };
1495
+ }
1496
+
1497
+ function __rhinoLocalFindRecord(collection, recordId) {
1498
+ var rows = __rhinoLocal.managed[collection];
1499
+ if (!rows) {
1500
+ return { rows: null, index: -1, record: null };
1501
+ }
1502
+ var i;
1503
+ for (i = 0; i < rows.length; i += 1) {
1504
+ if (String(rows[i]._id) === String(recordId)) {
1505
+ return { rows: rows, index: i, record: rows[i] };
1506
+ }
1507
+ }
1508
+ return { rows: rows, index: -1, record: null };
1509
+ }
1510
+
1511
+ // Object types this environment declares, from a pulled harness profile.
1512
+ // `null` means no profile was supplied, which keeps the pre-profile behaviour:
1513
+ // an unseeded collection is always a missing fixture.
1514
+ function __rhinoLocalDeclaresType(collection) {
1515
+ if (!__rhinoLocal.knownTypes) {
1516
+ return false;
1517
+ }
1518
+ return __rhinoLocalHas(__rhinoLocal.knownTypes, collection);
1519
+ }
1520
+
1521
+ function __rhinoLocalRequireCollection(method, collection) {
1522
+ if (__rhinoLocalHas(__rhinoLocal.managed, collection)) {
1523
+ return __rhinoLocal.managed[collection];
1524
+ }
1525
+ // With a profile, a declared-but-unseeded type is an EMPTY collection, which
1526
+ // is what AIC presents: read returns null rather than failing. Without one we
1527
+ // cannot tell that from a typo, so the miss stays a missing-fixture throw.
1528
+ if (__rhinoLocalDeclaresType(collection)) {
1529
+ __rhinoLocal.managed[collection] = [];
1530
+ return __rhinoLocal.managed[collection];
1531
+ }
1532
+ if (__rhinoLocal.knownTypes) {
1533
+ throw new Error(
1534
+ "rhino-local: openidm." +
1535
+ method +
1536
+ ": " +
1537
+ JSON.stringify(collection) +
1538
+ " is not a managed object in environment " +
1539
+ JSON.stringify(__rhinoLocal.profileTenant) +
1540
+ " (pulled " +
1541
+ String(__rhinoLocal.profilePulledAt) +
1542
+ "). Check the name, or re-pull the profile if the tenant has changed."
1543
+ );
1544
+ }
1545
+ throw new Error(
1546
+ "rhino-local: openidm." +
1547
+ method +
1548
+ ": no given.managed entry for " +
1549
+ JSON.stringify(collection)
1550
+ );
1551
+ }
1552
+
1553
+ function __rhinoLocalRequireRecord(method, resource) {
1554
+ var split = __rhinoLocalSplitResource(resource);
1555
+ if (split.recordId === null) {
1556
+ throw new Error(
1557
+ "rhino-local: openidm." +
1558
+ method +
1559
+ ": " +
1560
+ JSON.stringify(resource) +
1561
+ " is a collection path, not a record"
1562
+ );
1563
+ }
1564
+ __rhinoLocalRequireCollection(method, split.collection);
1565
+ var found = __rhinoLocalFindRecord(split.collection, split.recordId);
1566
+ if (!found.record) {
1567
+ throw new Error(
1568
+ "rhino-local: openidm." + method + ": No Such Entry: " + resource
1569
+ );
1570
+ }
1571
+ return found;
1572
+ }
1573
+
1574
+ function __rhinoLocalProject(record, fields) {
1575
+ if (!fields || !Array.isArray(fields) || fields.length === 0) {
1576
+ return record;
1577
+ }
1578
+ var i;
1579
+ for (i = 0; i < fields.length; i += 1) {
1580
+ if (fields[i] === "*") {
1581
+ return record;
1582
+ }
1583
+ }
1584
+ var out = {};
1585
+ if (record._id !== undefined) {
1586
+ out._id = record._id;
1587
+ }
1588
+ if (record._rev !== undefined) {
1589
+ out._rev = record._rev;
1590
+ }
1591
+ var field;
1592
+ var parent;
1593
+ for (i = 0; i < fields.length; i += 1) {
1594
+ field = String(fields[i]);
1595
+ if (__rhinoLocalHas(record, field)) {
1596
+ out[field] = record[field];
1597
+ } else if (field.indexOf("/") !== -1) {
1598
+ parent = field.split("/")[0];
1599
+ if (__rhinoLocalHas(record, parent) && !__rhinoLocalHas(out, parent)) {
1600
+ out[parent] = record[parent];
1601
+ }
1602
+ }
1603
+ }
1604
+ return out;
1605
+ }
1606
+
1607
+ function __rhinoLocalPushOpenidm(method, resource, body, actionName) {
1608
+ var rec = { method: method, resource: resource };
1609
+ if (body !== undefined) {
1610
+ rec.body = __rhinoLocalClone(body);
1611
+ }
1612
+ if (actionName !== undefined) {
1613
+ rec.actionName = actionName;
1614
+ }
1615
+ __rhinoLocal.openidm.push(rec);
1616
+ }
1617
+
1618
+ function __rhinoLocalFilterError(filter) {
1619
+ throw new Error(
1620
+ "rhino-local: openidm.query: unmocked filter " + JSON.stringify(filter)
1621
+ );
1622
+ }
1623
+
1624
+ // update and patch with a stale non-null _rev (measured on both).
1625
+ function __rhinoLocalCheckRev(method, rev, record) {
1626
+ if (rev !== null && rev !== undefined && String(rev) !== String(record._rev)) {
1627
+ throw new Error(
1628
+ "rhino-local: openidm." +
1629
+ method +
1630
+ ": the expected version '" +
1631
+ String(rev) +
1632
+ "' does not match the current version '" +
1633
+ String(record._rev) +
1634
+ "'"
1635
+ );
1636
+ }
1637
+ }
1638
+
1639
+ function __rhinoLocalOpenidmRecord(value, id, rev) {
1640
+ var record = { _id: id, _rev: rev };
1641
+ var keys = Object.keys(value);
1642
+ var i;
1643
+ for (i = 0; i < keys.length; i += 1) {
1644
+ if (keys[i] !== "_id" && keys[i] !== "_rev") {
1645
+ record[keys[i]] = value[keys[i]];
1646
+ }
1647
+ }
1648
+ return record;
1649
+ }
1650
+
1651
+ function __rhinoLocalIsIdentChar(ch) {
1652
+ return (
1653
+ (ch >= "a" && ch <= "z") ||
1654
+ (ch >= "A" && ch <= "Z") ||
1655
+ (ch >= "0" && ch <= "9") ||
1656
+ ch === "_" ||
1657
+ ch === "-"
1658
+ );
1659
+ }
1660
+
1661
+ function __rhinoLocalReadField(record, pointer) {
1662
+ var path = String(pointer);
1663
+ if (path.charAt(0) === "/") {
1664
+ path = path.substring(1);
1665
+ }
1666
+ if (path === "") {
1667
+ return record;
1668
+ }
1669
+ var parts = path.split("/");
1670
+ var cur = record;
1671
+ var i;
1672
+ for (i = 0; i < parts.length; i += 1) {
1673
+ if (cur === null || cur === undefined || typeof cur !== "object") {
1674
+ return undefined;
1675
+ }
1676
+ if (!__rhinoLocalHas(cur, parts[i])) {
1677
+ return undefined;
1678
+ }
1679
+ cur = cur[parts[i]];
1680
+ }
1681
+ return cur;
1682
+ }
1683
+
1684
+ function __rhinoLocalCompareOne(actual, op, expected) {
1685
+ var left = actual === null || actual === undefined ? "" : String(actual);
1686
+ var right = expected === null || expected === undefined ? "" : String(expected);
1687
+ if (op === "eq") {
1688
+ return left === right;
1689
+ }
1690
+ if (op === "co") {
1691
+ return left.indexOf(right) !== -1;
1692
+ }
1693
+ if (op === "sw") {
1694
+ return left.indexOf(right) === 0;
1695
+ }
1696
+ return false;
1697
+ }
1698
+
1699
+ function __rhinoLocalCompareField(record, pointer, op, expected) {
1700
+ var actual = __rhinoLocalReadField(record, pointer);
1701
+ if (op === "pr") {
1702
+ return actual !== undefined && actual !== null;
1703
+ }
1704
+ if (actual === undefined || actual === null) {
1705
+ return false;
1706
+ }
1707
+ if (Array.isArray(actual)) {
1708
+ var i;
1709
+ for (i = 0; i < actual.length; i += 1) {
1710
+ if (__rhinoLocalCompareOne(actual[i], op, expected)) {
1711
+ return true;
1712
+ }
1713
+ }
1714
+ return false;
1715
+ }
1716
+ return __rhinoLocalCompareOne(actual, op, expected);
1717
+ }
1718
+
1719
+ function __rhinoLocalParseFilter(filter) {
1720
+ var src = String(filter);
1721
+ var i = 0;
1722
+
1723
+ function skipWs() {
1724
+ while (i < src.length) {
1725
+ var ch = src.charAt(i);
1726
+ if (ch !== " " && ch !== "\t" && ch !== "\n" && ch !== "\r") {
1727
+ break;
1728
+ }
1729
+ i += 1;
1730
+ }
1731
+ }
1732
+
1733
+ function peek() {
1734
+ skipWs();
1735
+ if (i >= src.length) {
1736
+ return "";
1737
+ }
1738
+ return src.charAt(i);
1739
+ }
1740
+
1741
+ function readIdent() {
1742
+ skipWs();
1743
+ var start = i;
1744
+ while (i < src.length && __rhinoLocalIsIdentChar(src.charAt(i))) {
1745
+ i += 1;
1746
+ }
1747
+ if (start === i) {
1748
+ return "";
1749
+ }
1750
+ return src.substring(start, i);
1751
+ }
1752
+
1753
+ function readField() {
1754
+ skipWs();
1755
+ var start = i;
1756
+ if (i < src.length && src.charAt(i) === "/") {
1757
+ i += 1;
1758
+ }
1759
+ if (!__rhinoLocalIsIdentChar(peekCharRaw())) {
1760
+ i = start;
1761
+ return null;
1762
+ }
1763
+ while (i < src.length) {
1764
+ var ch = src.charAt(i);
1765
+ if (__rhinoLocalIsIdentChar(ch) || ch === "/") {
1766
+ i += 1;
1767
+ } else {
1768
+ break;
1769
+ }
1770
+ }
1771
+ var field = src.substring(start, i);
1772
+ if (field === "" || field === "/") {
1773
+ i = start;
1774
+ return null;
1775
+ }
1776
+ return field;
1777
+ }
1778
+
1779
+ function peekCharRaw() {
1780
+ if (i >= src.length) {
1781
+ return "";
1782
+ }
1783
+ return src.charAt(i);
1784
+ }
1785
+
1786
+ function readString() {
1787
+ skipWs();
1788
+ if (src.charAt(i) !== '"') {
1789
+ return null;
1790
+ }
1791
+ i += 1;
1792
+ var out = "";
1793
+ while (i < src.length) {
1794
+ var ch = src.charAt(i);
1795
+ if (ch === "\\") {
1796
+ i += 1;
1797
+ if (i >= src.length) {
1798
+ __rhinoLocalFilterError(filter);
1799
+ }
1800
+ out += src.charAt(i);
1801
+ i += 1;
1802
+ } else if (ch === '"') {
1803
+ i += 1;
1804
+ return out;
1805
+ } else {
1806
+ out += ch;
1807
+ i += 1;
1808
+ }
1809
+ }
1810
+ __rhinoLocalFilterError(filter);
1811
+ return null;
1812
+ }
1813
+
1814
+ function readNumber() {
1815
+ skipWs();
1816
+ var start = i;
1817
+ if (src.charAt(i) === "-") {
1818
+ i += 1;
1819
+ }
1820
+ var digits = 0;
1821
+ while (i < src.length && src.charAt(i) >= "0" && src.charAt(i) <= "9") {
1822
+ digits += 1;
1823
+ i += 1;
1824
+ }
1825
+ if (src.charAt(i) === ".") {
1826
+ i += 1;
1827
+ while (i < src.length && src.charAt(i) >= "0" && src.charAt(i) <= "9") {
1828
+ digits += 1;
1829
+ i += 1;
1830
+ }
1831
+ }
1832
+ if (digits === 0) {
1833
+ i = start;
1834
+ return null;
1835
+ }
1836
+ return Number(src.substring(start, i));
1837
+ }
1838
+
1839
+ function parseValue() {
1840
+ skipWs();
1841
+ var str = readString();
1842
+ if (str !== null) {
1843
+ return str;
1844
+ }
1845
+ var ident = "";
1846
+ var saved = i;
1847
+ ident = readIdent();
1848
+ if (ident === "true") {
1849
+ return true;
1850
+ }
1851
+ if (ident === "false") {
1852
+ return false;
1853
+ }
1854
+ if (ident === "null") {
1855
+ return null;
1856
+ }
1857
+ i = saved;
1858
+ var num = readNumber();
1859
+ if (num !== null && !isNaN(num)) {
1860
+ return num;
1861
+ }
1862
+ __rhinoLocalFilterError(filter);
1863
+ return null;
1864
+ }
1865
+
1866
+ function parsePrimary() {
1867
+ skipWs();
1868
+ if (peek() === "(") {
1869
+ i += 1;
1870
+ var inner = parseOr();
1871
+ skipWs();
1872
+ if (peek() !== ")") {
1873
+ __rhinoLocalFilterError(filter);
1874
+ }
1875
+ i += 1;
1876
+ return inner;
1877
+ }
1878
+ var saved = i;
1879
+ var ident = readIdent();
1880
+ if (ident === "true") {
1881
+ return { kind: "true" };
1882
+ }
1883
+ if (ident === "false") {
1884
+ return { kind: "false" };
1885
+ }
1886
+ i = saved;
1887
+ var field = readField();
1888
+ if (field === null) {
1889
+ __rhinoLocalFilterError(filter);
1890
+ }
1891
+ skipWs();
1892
+ var op = readIdent();
1893
+ if (op === "pr") {
1894
+ return { kind: "pr", field: field };
1895
+ }
1896
+ if (op === "eq" || op === "co" || op === "sw") {
1897
+ return { kind: "cmp", field: field, op: op, value: parseValue() };
1898
+ }
1899
+ __rhinoLocalFilterError(filter);
1900
+ return null;
1901
+ }
1902
+
1903
+ function parseNot() {
1904
+ skipWs();
1905
+ if (peek() === "!") {
1906
+ i += 1;
1907
+ return { kind: "not", inner: parseNot() };
1908
+ }
1909
+ var saved = i;
1910
+ var ident = readIdent();
1911
+ if (ident === "not") {
1912
+ // AIC rejects the word form (docs/api/10, verified 2026-07-03).
1913
+ __rhinoLocalFilterError(filter);
1914
+ }
1915
+ i = saved;
1916
+ return parsePrimary();
1917
+ }
1918
+
1919
+ function parseAnd() {
1920
+ var left = parseNot();
1921
+ while (true) {
1922
+ var saved = i;
1923
+ var ident = readIdent();
1924
+ if (ident !== "and") {
1925
+ i = saved;
1926
+ break;
1927
+ }
1928
+ left = { kind: "and", left: left, right: parseNot() };
1929
+ }
1930
+ return left;
1931
+ }
1932
+
1933
+ function parseOr() {
1934
+ var left = parseAnd();
1935
+ while (true) {
1936
+ var saved = i;
1937
+ var ident = readIdent();
1938
+ if (ident !== "or") {
1939
+ i = saved;
1940
+ break;
1941
+ }
1942
+ left = { kind: "or", left: left, right: parseAnd() };
1943
+ }
1944
+ return left;
1945
+ }
1946
+
1947
+ var ast = parseOr();
1948
+ skipWs();
1949
+ if (i !== src.length) {
1950
+ __rhinoLocalFilterError(filter);
1951
+ }
1952
+ return ast;
1953
+ }
1954
+
1955
+ function __rhinoLocalEvalFilter(record, ast) {
1956
+ if (ast.kind === "true") {
1957
+ return true;
1958
+ }
1959
+ if (ast.kind === "false") {
1960
+ return false;
1961
+ }
1962
+ if (ast.kind === "not") {
1963
+ return !__rhinoLocalEvalFilter(record, ast.inner);
1964
+ }
1965
+ if (ast.kind === "and") {
1966
+ return (
1967
+ __rhinoLocalEvalFilter(record, ast.left) &&
1968
+ __rhinoLocalEvalFilter(record, ast.right)
1969
+ );
1970
+ }
1971
+ if (ast.kind === "or") {
1972
+ return (
1973
+ __rhinoLocalEvalFilter(record, ast.left) ||
1974
+ __rhinoLocalEvalFilter(record, ast.right)
1975
+ );
1976
+ }
1977
+ if (ast.kind === "pr") {
1978
+ return __rhinoLocalCompareField(record, ast.field, "pr", null);
1979
+ }
1980
+ if (ast.kind === "cmp") {
1981
+ return __rhinoLocalCompareField(record, ast.field, ast.op, ast.value);
1982
+ }
1983
+ return false;
1984
+ }
1985
+
1986
+ function __rhinoLocalMatchesFilter(record, filter) {
1987
+ if (!filter || filter === "true") {
1988
+ return true;
1989
+ }
1990
+ if (filter === "false") {
1991
+ return false;
1992
+ }
1993
+ return __rhinoLocalEvalFilter(record, __rhinoLocalParseFilter(filter));
1994
+ }
1995
+
1996
+ openidm.read = function (resourceName, _params, fields) {
1997
+ if (arguments.length < 1 || arguments.length > 3) {
1998
+ throw new Error(
1999
+ "rhino-local: openidm.read arity=" + arguments.length + " (expected 1..3)"
2000
+ );
2001
+ }
2002
+ var resource = String(resourceName);
2003
+ __rhinoLocalPushOpenidm("read", resource);
2004
+ var split = __rhinoLocalSplitResource(resource);
2005
+ if (split.recordId === null) {
2006
+ throw new Error(
2007
+ "rhino-local: openidm.read: " +
2008
+ JSON.stringify(resource) +
2009
+ " is a collection path, not a record"
2010
+ );
2011
+ }
2012
+ __rhinoLocalRequireCollection("read", split.collection);
2013
+ var found = __rhinoLocalFindRecord(split.collection, split.recordId);
2014
+ if (!found.record) {
2015
+ // AIC returns null for a missing record in a known collection
2016
+ // (docs/api/10, verified 2026-07-17). An unseeded collection still
2017
+ // throws above — that is a missing given.managed fixture.
2018
+ return null;
2019
+ }
2020
+ return __rhinoLocalProject(found.record, fields);
2021
+ };
2022
+
2023
+ openidm.query = function (resourceName, params, fields) {
2024
+ if (arguments.length < 2 || arguments.length > 3) {
2025
+ throw new Error(
2026
+ "rhino-local: openidm.query arity=" + arguments.length + " (expected 2 or 3)"
2027
+ );
2028
+ }
2029
+ var collection = String(resourceName);
2030
+ __rhinoLocalPushOpenidm("query", collection, params);
2031
+ var rows = __rhinoLocalRequireCollection("query", collection);
2032
+ var kinds = 0;
2033
+ var kindNames = ["_queryId", "_queryExpression", "_queryFilter"];
2034
+ var k;
2035
+ for (k = 0; k < kindNames.length; k += 1) {
2036
+ if (params && params[kindNames[k]] !== undefined) {
2037
+ kinds += 1;
2038
+ }
2039
+ }
2040
+ if (kinds !== 1) {
2041
+ throw new Error(
2042
+ "rhino-local: openidm.query: You must use exactly one of [_queryId, _queryExpression, _queryFilter]."
2043
+ );
2044
+ }
2045
+ if (params._queryExpression !== undefined) {
2046
+ throw new Error(
2047
+ "rhino-local: openidm.query: Query Expressions are not supported when using DS as the repo"
2048
+ );
2049
+ }
2050
+ // query-all-ids is the one _queryId measured: every record, _id/_rev only.
2051
+ if (params._queryId !== undefined && params._queryId !== "query-all-ids") {
2052
+ throw new Error(
2053
+ "rhino-local: not mocked: openidm.query _queryId " + String(params._queryId)
2054
+ );
2055
+ }
2056
+ var filter = params._queryId !== undefined ? "true" : params._queryFilter;
2057
+ if (params._queryId !== undefined) {
2058
+ fields = ["_id"];
2059
+ }
2060
+ var result = [];
2061
+ var i;
2062
+ for (i = 0; i < rows.length; i += 1) {
2063
+ if (__rhinoLocalMatchesFilter(rows[i], filter)) {
2064
+ result.push(__rhinoLocalProject(rows[i], fields));
2065
+ }
2066
+ }
2067
+ return {
2068
+ result: result,
2069
+ pagedResultsCookie: null,
2070
+ totalPagedResultsPolicy: "NONE",
2071
+ totalPagedResults: -1,
2072
+ resultCount: result.length,
2073
+ };
2074
+ };
2075
+
2076
+ openidm.create = function (resourceName, newResourceId, content) {
2077
+ if (arguments.length < 3 || arguments.length > 5) {
2078
+ throw new Error(
2079
+ "rhino-local: openidm.create arity=" + arguments.length + " (expected 3..5)"
2080
+ );
2081
+ }
2082
+ var collection = String(resourceName);
2083
+ var id = newResourceId;
2084
+ var recordedResource;
2085
+ if (id === null || id === undefined || id === "") {
2086
+ __rhinoLocal.generatedId += 1;
2087
+ id = "generated-" + __rhinoLocal.generatedId;
2088
+ recordedResource = collection;
2089
+ } else {
2090
+ id = String(id);
2091
+ recordedResource = collection + "/" + id;
2092
+ }
2093
+ __rhinoLocalPushOpenidm("create", recordedResource, content);
2094
+ if (!__rhinoLocalHas(__rhinoLocal.managed, collection)) {
2095
+ __rhinoLocal.managed[collection] = [];
2096
+ }
2097
+ var rows = __rhinoLocal.managed[collection];
2098
+ if (
2099
+ id !== undefined &&
2100
+ id !== null &&
2101
+ __rhinoLocalFindRecord(collection, id).record
2102
+ ) {
2103
+ throw new Error(
2104
+ "rhino-local: openidm.create: Entry Already Exists: " + recordedResource
2105
+ );
2106
+ }
2107
+ var stored = __rhinoLocalClone(content);
2108
+ stored = __rhinoLocalOpenidmRecord(
2109
+ stored,
2110
+ id,
2111
+ stored._rev === undefined ? "local-rev" : stored._rev
2112
+ );
2113
+ rows.push(stored);
2114
+ return __rhinoLocalProject(stored, arguments.length >= 5 ? arguments[4] : null);
2115
+ };
2116
+
2117
+ openidm.update = function (id, _rev, value) {
2118
+ if (arguments.length < 3 || arguments.length > 5) {
2119
+ throw new Error(
2120
+ "rhino-local: openidm.update arity=" + arguments.length + " (expected 3..5)"
2121
+ );
2122
+ }
2123
+ var resource = String(id);
2124
+ __rhinoLocalPushOpenidm("update", resource, value);
2125
+ var found = __rhinoLocalRequireRecord("update", resource);
2126
+ __rhinoLocalCheckRev("update", _rev, found.record);
2127
+ var next = __rhinoLocalClone(value);
2128
+ next = __rhinoLocalOpenidmRecord(next, found.record._id, found.record._rev);
2129
+ found.rows[found.index] = next;
2130
+ return __rhinoLocalProject(next, arguments.length >= 5 ? arguments[4] : null);
2131
+ };
2132
+
2133
+ openidm.patch = function (resourceName, _rev, patch) {
2134
+ if (arguments.length < 3 || arguments.length > 5) {
2135
+ throw new Error(
2136
+ "rhino-local: openidm.patch arity=" + arguments.length + " (expected 3..5)"
2137
+ );
2138
+ }
2139
+ var resource = String(resourceName);
2140
+ __rhinoLocalPushOpenidm("patch", resource, patch);
2141
+ var found = __rhinoLocalRequireRecord("patch", resource);
2142
+ __rhinoLocalCheckRev("patch", _rev, found.record);
2143
+ var i;
2144
+ var op;
2145
+ var field;
2146
+ for (i = 0; i < patch.length; i += 1) {
2147
+ op = patch[i];
2148
+ if (op.operation !== "add" && op.operation !== "remove" && op.operation !== "replace") {
2149
+ throw new Error(
2150
+ "rhino-local: openidm.patch: not a valid JSON patch (operation " +
2151
+ String(op.operation) +
2152
+ ")"
2153
+ );
2154
+ }
2155
+ }
2156
+ for (i = 0; i < patch.length; i += 1) {
2157
+ op = patch[i];
2158
+ field = String(op.field).replace(/^\//, "");
2159
+ if (op.operation === "remove") {
2160
+ delete found.record[field];
2161
+ } else {
2162
+ found.record[field] = op.value;
2163
+ }
2164
+ }
2165
+ return __rhinoLocalProject(found.record, arguments.length >= 5 ? arguments[4] : null);
2166
+ };
2167
+
2168
+ openidm.delete = function (resourceName, _rev) {
2169
+ if (arguments.length < 2 || arguments.length > 4) {
2170
+ throw new Error(
2171
+ "rhino-local: openidm.delete arity=" + arguments.length + " (expected 2..4)"
2172
+ );
2173
+ }
2174
+ var resource = String(resourceName);
2175
+ __rhinoLocalPushOpenidm("delete", resource);
2176
+ var found = __rhinoLocalRequireRecord("delete", resource);
2177
+ if (_rev !== null && _rev !== undefined && String(_rev) !== String(found.record._rev)) {
2178
+ throw new Error(
2179
+ "rhino-local: openidm.delete: Assertion Failed: the entry cannot be removed because the request contained an LDAP assertion control and the associated filter did not match the contents of the entry"
2180
+ );
2181
+ }
2182
+ var removed = found.record;
2183
+ found.rows.splice(found.index, 1);
2184
+ return __rhinoLocalProject(removed, arguments.length >= 4 ? arguments[3] : null);
2185
+ };
2186
+
2187
+ openidm.action = function (resource, actionName, content, params) {
2188
+ if (arguments.length < 2 || arguments.length > 5) {
2189
+ throw new Error(
2190
+ "rhino-local: openidm.action arity=" + arguments.length + " (expected 2..5)"
2191
+ );
2192
+ }
2193
+ var body = content;
2194
+ if (body === undefined || body === null) {
2195
+ body = params;
2196
+ }
2197
+ __rhinoLocalPushOpenidm("action", String(resource), body, String(actionName));
2198
+ // Measured on a managed collection only; other resources have other actions.
2199
+ if (
2200
+ /^managed\/[^/]+$/.test(String(resource)) &&
2201
+ actionName !== "patch" &&
2202
+ actionName !== "triggerSyncCheck" &&
2203
+ actionName !== "updateLastSync"
2204
+ ) {
2205
+ throw new Error(
2206
+ "rhino-local: openidm.action: Expecting String containing one of: patch triggerSyncCheck updateLastSync"
2207
+ );
2208
+ }
2209
+ return {};
2210
+ };
2211
+
2212
+ function __rhinoLocalAsPattern(value) {
2213
+ if (value && typeof value === "object" && typeof value.__regex === "string") {
2214
+ return new RegExp(value.__regex, value.__flags || "");
2215
+ }
2216
+ return value;
2217
+ }
2218
+
2219
+ function __rhinoLocalMatchUrl(pattern, url) {
2220
+ var p = __rhinoLocalAsPattern(pattern);
2221
+ if (typeof p === "string") {
2222
+ return p === url;
2223
+ }
2224
+ if (p && typeof p.test === "function") {
2225
+ return p.test(url);
2226
+ }
2227
+ throw new Error("rhino-local: given.http match.url is not a string or regexp");
2228
+ }
2229
+
2230
+ function __rhinoLocalMatchHttp(url, method) {
2231
+ var i;
2232
+ var stub;
2233
+ var wantMethod;
2234
+ for (i = 0; i < __rhinoLocal.httpStubs.length; i += 1) {
2235
+ stub = __rhinoLocal.httpStubs[i];
2236
+ if (!__rhinoLocalMatchUrl(stub.match.url, url)) {
2237
+ continue;
2238
+ }
2239
+ wantMethod = stub.match.method;
2240
+ if (wantMethod && String(wantMethod).toUpperCase() !== method) {
2241
+ continue;
2242
+ }
2243
+ return stub.reply;
2244
+ }
2245
+ return null;
2246
+ }
2247
+
2248
+ httpClient.send = function (uri, requestOptions) {
2249
+ if (arguments.length < 1 || arguments.length > 2) {
2250
+ throw new Error(
2251
+ "rhino-local: httpClient.send arity=" + arguments.length + " (expected 1 or 2)"
2252
+ );
2253
+ }
2254
+ var url = String(uri);
2255
+ var method = "GET";
2256
+ var body;
2257
+ if (requestOptions && requestOptions.method) {
2258
+ method = String(requestOptions.method).toUpperCase();
2259
+ }
2260
+ if (requestOptions && requestOptions.body !== undefined) {
2261
+ body = requestOptions.body;
2262
+ }
2263
+ var effect = { url: url, method: method };
2264
+ if (body !== undefined) {
2265
+ effect.body = body;
2266
+ }
2267
+ __rhinoLocal.http.push(effect);
2268
+ var reply = __rhinoLocalMatchHttp(url, method);
2269
+ if (!reply) {
2270
+ throw new Error(
2271
+ "rhino-local: httpClient.send: no given.http stub for " + method + " " + url
2272
+ );
2273
+ }
2274
+ var response = {
2275
+ status: reply.status,
2276
+ ok: reply.status >= 200 && reply.status < 300,
2277
+ statusText: String(reply.status),
2278
+ headers: reply.headers || {},
2279
+ json: function () {
2280
+ return reply.body;
2281
+ },
2282
+ text: function () {
2283
+ if (typeof reply.body === "string") {
2284
+ return reply.body;
2285
+ }
2286
+ if (reply.body === undefined) {
2287
+ return "";
2288
+ }
2289
+ return JSON.stringify(reply.body);
2290
+ },
2291
+ };
2292
+ return {
2293
+ get: function () {
2294
+ return response;
2295
+ },
2296
+ };
2297
+ };
2298
+
2299
+ idRepository.getIdentity = function (userName) {
2300
+ __rhinoLocalExpectArity("idRepository.getIdentity", arguments, 1);
2301
+ var wanted = String(userName);
2302
+ var collections = Object.keys(__rhinoLocal.managed);
2303
+ var c;
2304
+ var rows;
2305
+ var i;
2306
+ var record;
2307
+ var found = null;
2308
+ for (c = 0; c < collections.length; c += 1) {
2309
+ rows = __rhinoLocal.managed[collections[c]];
2310
+ for (i = 0; i < rows.length; i += 1) {
2311
+ record = rows[i];
2312
+ if (String(record._id) === wanted || String(record.userName) === wanted) {
2313
+ found = record;
2314
+ break;
2315
+ }
2316
+ }
2317
+ if (found) {
2318
+ break;
2319
+ }
2320
+ }
2321
+ if (!found) {
2322
+ throw new Error(
2323
+ "rhino-local: idRepository.getIdentity: no given.managed record for " +
2324
+ JSON.stringify(wanted)
2325
+ );
2326
+ }
2327
+ return {
2328
+ getName: function () {
2329
+ if (found.userName !== undefined) {
2330
+ return found.userName;
2331
+ }
2332
+ return found._id;
2333
+ },
2334
+ getUniversalId: function () {
2335
+ return found._id;
2336
+ },
2337
+ exists: function () {
2338
+ return true;
2339
+ },
2340
+ getAttributeValues: function (attributeName) {
2341
+ var value = found[attributeName];
2342
+ if (value === undefined || value === null) {
2343
+ return __rhinoLocalJavaList([]);
2344
+ }
2345
+ if (Array.isArray(value)) {
2346
+ return __rhinoLocalJavaList(value);
2347
+ }
2348
+ return __rhinoLocalJavaList([value]);
2349
+ },
2350
+ setAttribute: function () {
2351
+ __rhinoLocalNotMocked("idRepository.getIdentity()", "setAttribute", arguments, [
2352
+ {
2353
+ arity: 2,
2354
+ types: ["string", "array"],
2355
+ label: "setAttribute(attributeName: string, attributeValues: array)",
2356
+ },
2357
+ ]);
2358
+ },
2359
+ addAttribute: function () {
2360
+ __rhinoLocalNotMocked("idRepository.getIdentity()", "addAttribute", arguments, [
2361
+ {
2362
+ arity: 2,
2363
+ types: ["string", "string"],
2364
+ label: "addAttribute(attributeName: string, attributeValue: string)",
2365
+ },
2366
+ ]);
2367
+ },
2368
+ store: function () {
2369
+ __rhinoLocalNotMocked("idRepository.getIdentity()", "store", arguments, [
2370
+ { arity: 0, types: [], label: "store()" },
2371
+ ]);
2372
+ },
2373
+ };
2374
+ };
2375
+
2376
+ idRepository.createUser = function (userName, password, attributes) {
2377
+ if (arguments.length === 3 && __rhinoLocalIsPlainObject(attributes)) {
2378
+ var names = Object.keys(attributes);
2379
+ var i;
2380
+ for (i = 0; i < names.length; i += 1) {
2381
+ if (!Array.isArray(attributes[names[i]])) {
2382
+ throw new InternalError(
2383
+ "class java.lang.String cannot be cast to class java.util.Collection (java.lang.String and java.util.Collection are in module java.base of loader 'bootstrap')"
2384
+ );
2385
+ }
2386
+ }
2387
+ }
2388
+ throw new InternalError(
2389
+ "User creation through identity repository is not allowed in this environment"
2390
+ );
2391
+ };
2392
+
2393
+ systemEnv = {
2394
+ getProperty: function (key, defaultValue, returnType) {
2395
+ if (arguments.length < 1 || arguments.length > 3) {
2396
+ throw new Error("rhino-local: systemEnv.getProperty arity=" + arguments.length);
2397
+ }
2398
+ var k = String(key);
2399
+ if (!__rhinoLocal.esvProvided) {
2400
+ throw new Error(
2401
+ "rhino-local: systemEnv.getProperty: no given.esv entry for " +
2402
+ JSON.stringify(k)
2403
+ );
2404
+ }
2405
+ var value = __rhinoLocalHas(__rhinoLocal.esv, k)
2406
+ ? __rhinoLocal.esv[k]
2407
+ : arguments.length === 1
2408
+ ? null
2409
+ : defaultValue;
2410
+ if (arguments.length < 3 || value === null) {
2411
+ return value;
2412
+ }
2413
+ var type;
2414
+ if (typeof returnType === "string") {
2415
+ type = returnType.toLowerCase();
2416
+ } else {
2417
+ var classType = String(returnType).match(/^\[JavaClass java\.lang\.(Integer|String|Boolean|Double)\]$/);
2418
+ if (!classType) {
2419
+ throw new InternalError("Property resolution failed");
2420
+ }
2421
+ type = classType[1].toLowerCase();
2422
+ }
2423
+ if (type === "string") {
2424
+ return String(value);
2425
+ }
2426
+ if (type === "integer" || type === "number") {
2427
+ var number = Number(value);
2428
+ if (isNaN(number)) {
2429
+ throw new InternalError("Property resolution failed");
2430
+ }
2431
+ return number;
2432
+ }
2433
+ if (type === "double") {
2434
+ var doubleValue = Number(value);
2435
+ if (isNaN(doubleValue)) {
2436
+ throw new InternalError("Property resolution failed");
2437
+ }
2438
+ return doubleValue;
2439
+ }
2440
+ if (type === "boolean") {
2441
+ return String(value).toLowerCase() === "true";
2442
+ }
2443
+ if (type === "object" || type === "map") {
2444
+ try {
2445
+ var parsed = JSON.parse(String(value));
2446
+ if (!__rhinoLocalIsPlainObject(parsed)) {
2447
+ throw new Error("not a map");
2448
+ }
2449
+ __rhinoLocalHide(parsed, "toString", function () {
2450
+ return __rhinoLocalJavaMapString(parsed).replace(/([0-9]+)\.0\b/g, "$1");
2451
+ });
2452
+ __rhinoLocalHide(parsed, "size", function () {
2453
+ return Object.keys(parsed).filter(function (name) {
2454
+ return name !== "toString" && name !== "size";
2455
+ }).length;
2456
+ });
2457
+ return parsed;
2458
+ } catch (e) {
2459
+ throw new InternalError("Property resolution failed");
2460
+ }
2461
+ }
2462
+ if (type === "array" || type === "list") {
2463
+ var values;
2464
+ try {
2465
+ values = String(value).split(",");
2466
+ } catch (e) {
2467
+ throw new InternalError("Property resolution failed");
2468
+ }
2469
+ var list = new java.util.ArrayList();
2470
+ for (var j = 0; j < values.length; j += 1) {
2471
+ list.add(values[j]);
2472
+ }
2473
+ return list;
2474
+ }
2475
+ throw new InternalError("Unsupported return type: " + returnType);
2476
+ },
2477
+ };
2478
+
2479
+ function __rhinoLocalSecret(value) {
2480
+ return {
2481
+ getAsUtf8: function () {
2482
+ __rhinoLocalExpectArity("secret.getAsUtf8", arguments, 0);
2483
+ return value;
2484
+ },
2485
+ };
2486
+ }
2487
+
2488
+ function __rhinoLocalRequireSecret(method, secretId) {
2489
+ var id = String(secretId);
2490
+ if (!__rhinoLocalHas(__rhinoLocal.secrets, id)) {
2491
+ if (__rhinoLocal.secretsProvided) {
2492
+ throw new Error(
2493
+ "rhino-local: secrets." + method + ": Secret id " + id + " not accessible"
2494
+ );
2495
+ }
2496
+ throw new Error(
2497
+ "rhino-local: secrets." +
2498
+ method +
2499
+ ": no given.secrets entry for " +
2500
+ JSON.stringify(id)
2501
+ );
2502
+ }
2503
+ return __rhinoLocalSecret(__rhinoLocal.secrets[id]);
2504
+ }
2505
+
2506
+ secrets.getGenericSecret = function (secretId) {
2507
+ __rhinoLocalExpectArity("secrets.getGenericSecret", arguments, 1);
2508
+ return __rhinoLocalRequireSecret("getGenericSecret", secretId);
2509
+ };
2510
+
2511
+ secrets.getDecryptionKey = function (secretId) {
2512
+ __rhinoLocalExpectArity("secrets.getDecryptionKey", arguments, 1);
2513
+ return __rhinoLocalRequireSecret("getDecryptionKey", secretId);
2514
+ };
2515
+
2516
+ secrets.getEncryptionKey = function (secretId) {
2517
+ __rhinoLocalExpectArity("secrets.getEncryptionKey", arguments, 1);
2518
+ return __rhinoLocalRequireSecret("getEncryptionKey", secretId);
2519
+ };
2520
+
2521
+ secrets.getSigningKey = function (secretId) {
2522
+ __rhinoLocalExpectArity("secrets.getSigningKey", arguments, 1);
2523
+ return __rhinoLocalRequireSecret("getSigningKey", secretId);
2524
+ };
2525
+
2526
+ secrets.getVerificationKey = function (secretId) {
2527
+ __rhinoLocalExpectArity("secrets.getVerificationKey", arguments, 1);
2528
+ return __rhinoLocalRequireSecret("getVerificationKey", secretId);
2529
+ };
2530
+
2531
+ // given.bindings.cacheManager: {} is the measured state, no caches at all.
2532
+ function __rhinoLocalRequireCaches(method) {
2533
+ if (!__rhinoLocalHas(__rhinoLocal.bindings, "cacheManager")) {
2534
+ throw new Error(
2535
+ "rhino-local: cacheManager." + method + ": no given.bindings.cacheManager"
2536
+ );
2537
+ }
2538
+ }
2539
+
2540
+ cacheManager.exists = function (cacheName) {
2541
+ __rhinoLocalExpectArity("cacheManager.exists", arguments, 1);
2542
+ __rhinoLocalRequireCaches("exists");
2543
+ return false;
2544
+ };
2545
+
2546
+ cacheManager.named = function (cacheName) {
2547
+ __rhinoLocalExpectArity("cacheManager.named", arguments, 1);
2548
+ __rhinoLocalRequireCaches("named");
2549
+ return null;
2550
+ };
2551
+
2552
+ function __rhinoLocalJourneySeed(field) {
2553
+ var seed = __rhinoLocal.bindings.journey;
2554
+ if (!seed || seed[field] === undefined) {
2555
+ throw new Error(
2556
+ "rhino-local: journey." + field + ": no given.bindings.journey." + field
2557
+ );
2558
+ }
2559
+ return seed[field];
2560
+ }
2561
+
2562
+ journey.name = function () {
2563
+ __rhinoLocalExpectArity("journey.name", arguments, 0);
2564
+ return __rhinoLocalJourneySeed("name");
2565
+ };
2566
+
2567
+ journey.innerJourney = function () {
2568
+ __rhinoLocalExpectArity("journey.innerJourney", arguments, 0);
2569
+ return __rhinoLocalJourneySeed("innerJourney");
2570
+ };
2571
+
2572
+ journey.mustRun = function () {
2573
+ __rhinoLocalExpectArity("journey.mustRun", arguments, 0);
2574
+ return __rhinoLocalJourneySeed("mustRun");
2575
+ };
2576
+
2577
+ journey.identityResource = function () {
2578
+ __rhinoLocalExpectArity("journey.identityResource", arguments, 0);
2579
+ return __rhinoLocalJourneySeed("identityResource");
2580
+ };
2581
+
2582
+ // Capture the Rhino builtin before we shadow it. A function declaration
2583
+ // would hoist and capture the wrapper itself.
2584
+ var __rhinoLocalRealJavaImporter =
2585
+ typeof JavaImporter === "function" ? JavaImporter : null;
2586
+
2587
+ function __rhinoLocalHiddenValueCallback(id, value) {
2588
+ this.type = "HiddenValueCallback";
2589
+ this.id = String(id);
2590
+ this.value = value === undefined || value === null ? "" : String(value);
2591
+ }
2592
+
2593
+ function __rhinoLocalActionBuilder() {
2594
+ return {
2595
+ build: function () {
2596
+ if (__rhinoLocal.outcome === null) {
2597
+ __rhinoLocal.outcome = "ok";
2598
+ outcome = "ok";
2599
+ }
2600
+ return action;
2601
+ },
2602
+ };
2603
+ }
2604
+
2605
+ var __rhinoLocalActionClass = {
2606
+ send: function () {
2607
+ var i;
2608
+ var cb;
2609
+ var fields;
2610
+ var key;
2611
+ for (i = 0; i < arguments.length; i += 1) {
2612
+ cb = arguments[i];
2613
+ if (!cb) {
2614
+ continue;
2615
+ }
2616
+ fields = {};
2617
+ for (key in cb) {
2618
+ if (Object.prototype.hasOwnProperty.call(cb, key) && key !== "type") {
2619
+ fields[key] = cb[key];
2620
+ }
2621
+ }
2622
+ __rhinoLocalCallback(
2623
+ cb.type ? String(cb.type) : "HiddenValueCallback",
2624
+ fields
2625
+ );
2626
+ }
2627
+ if (__rhinoLocal.outcome === null) {
2628
+ __rhinoLocal.outcome = "ok";
2629
+ outcome = "ok";
2630
+ }
2631
+ return __rhinoLocalActionBuilder();
2632
+ },
2633
+ goTo: function (name) {
2634
+ __rhinoLocal.outcome = String(name);
2635
+ outcome = __rhinoLocal.outcome;
2636
+ return __rhinoLocalActionBuilder();
2637
+ },
2638
+ };
2639
+
2640
+ JavaImporter = function () {
2641
+ var real = null;
2642
+ if (typeof __rhinoLocalRealJavaImporter === "function") {
2643
+ real = __rhinoLocalRealJavaImporter.apply(null, arguments);
2644
+ }
2645
+ function Importer() {}
2646
+ if (real) {
2647
+ Importer.prototype = real;
2648
+ }
2649
+ var wrapper = new Importer();
2650
+ wrapper.Action = __rhinoLocalActionClass;
2651
+ wrapper.HiddenValueCallback = __rhinoLocalHiddenValueCallback;
2652
+ return wrapper;
2653
+ };
2654
+
2655
+ function __rhinoLocalLoadLibrary(name) {
2656
+ var id = String(name);
2657
+ if (__rhinoLocalHas(__rhinoLocal.requireCache, id)) {
2658
+ return __rhinoLocal.requireCache[id];
2659
+ }
2660
+ if (!__rhinoLocalHas(__rhinoLocal.libraries, id)) {
2661
+ throw new Error(
2662
+ "rhino-local: require: no given.libraries entry for " + JSON.stringify(id)
2663
+ );
2664
+ }
2665
+ var exports = {};
2666
+ var module = { exports: exports };
2667
+ __rhinoLocal.requireCache[id] = exports;
2668
+ var source = String(__rhinoLocal.libraries[id]);
2669
+ var loader = eval(
2670
+ "(function (require, exports, module) {\n" + source + "\n})"
2671
+ );
2672
+ loader(require, exports, module);
2673
+ __rhinoLocal.requireCache[id] = module.exports;
2674
+ return module.exports;
2675
+ }
2676
+
2677
+ // utils is backed by java/HostOps.java, a native function the runner defines
2678
+ // for the preamble and deletes before the script runs: java.util.Base64,
2679
+ // SecureRandom and javax.crypto are outside the AM allow-list, so neither the
2680
+ // mocks nor a script can reach them directly. Absent (the node vm path), utils
2681
+ // stays unmocked.
2682
+ if (typeof __rhinoLocalHostOp !== "undefined") {
2683
+ (function (hostOp) {
2684
+ // AIC's service errors carry no (script#line) suffix; a JS-thrown
2685
+ // InternalError has none either, where one reported from Java would.
2686
+ function fail(message) {
2687
+ throw new InternalError(message);
2688
+ }
2689
+ // A number or boolean takes AIC's String overload ("MTI=" for 12).
2690
+ function bytes(value) {
2691
+ var t = typeof value;
2692
+ return t === "string" || t === "number" || t === "boolean"
2693
+ ? hostOp("utf8", String(value))
2694
+ : value;
2695
+ }
2696
+ function encoded(value, url) {
2697
+ return hostOp("base64Encode", bytes(value), url);
2698
+ }
2699
+ function decoded(value, url, asBytes) {
2700
+ var result;
2701
+ try {
2702
+ result = hostOp("base64Decode", String(value), url);
2703
+ } catch (e) {
2704
+ if (url) {
2705
+ return null;
2706
+ }
2707
+ if (typeof e === "string") {
2708
+ fail(e);
2709
+ }
2710
+ throw e;
2711
+ }
2712
+ return asBytes ? result : hostOp("fromUtf8", result);
2713
+ }
2714
+ [utils.base64, utils.base64url].forEach(function (codec, index) {
2715
+ var url = index === 1;
2716
+ codec.encode = function (value) {
2717
+ return encoded(value, url);
2718
+ };
2719
+ codec.decode = function (value) {
2720
+ return decoded(value, url, false);
2721
+ };
2722
+ codec.decodeToBytes = function (value) {
2723
+ return decoded(value, url, true);
2724
+ };
2725
+ codec.btoa = codec.encode;
2726
+ codec.atob = codec.decode;
2727
+ });
2728
+ utils.types.stringToBytes = function (value) {
2729
+ return hostOp("utf8", String(value));
2730
+ };
2731
+ utils.types.bytesToString = function (value) {
2732
+ return hostOp("fromUtf8", value);
2733
+ };
2734
+ utils.crypto.randomUUID = function () {
2735
+ __rhinoLocalExpectArity("utils.crypto.randomUUID", arguments, 0);
2736
+ return hostOp("uuid");
2737
+ };
2738
+ utils.crypto.getRandomValues = function (array) {
2739
+ __rhinoLocalExpectArity("utils.crypto.getRandomValues", arguments, 1);
2740
+ // AIC takes an array only; an array-like object has no overload.
2741
+ if (!Array.isArray(array) && !(array instanceof java.lang.Object)) {
2742
+ fail(
2743
+ "Can't find method org.forgerock.openam.scripting.bindings.crypto.ScriptCryptoService.getRandomValues(object)."
2744
+ );
2745
+ }
2746
+ var i;
2747
+ for (i = 0; i < array.length; i += 1) {
2748
+ array[i] = hostOp("randomInt32");
2749
+ }
2750
+ return array;
2751
+ };
2752
+
2753
+ var subtle = utils.crypto.subtle;
2754
+ function algorithmName(value) {
2755
+ return typeof value === "string" ? value : value.name;
2756
+ }
2757
+ function hmacHash(algorithm) {
2758
+ var hash = typeof algorithm === "string" ? "SHA-256" : algorithm.hash;
2759
+ if (typeof hash !== "string") {
2760
+ fail("Unsupported hashing algorithm: [object Object]");
2761
+ }
2762
+ return hash;
2763
+ }
2764
+ // Only these names, and only as a string: { name } is refused (measured).
2765
+ var DIGESTS = ["SHA-256", "SHA-384", "SHA-1", "SHA-512"];
2766
+ subtle.digest = function (algorithm, data) {
2767
+ if (typeof algorithm !== "string" || DIGESTS.indexOf(algorithm) < 0) {
2768
+ fail("Algorithm must be one of [" + DIGESTS.join(", ") + "]");
2769
+ }
2770
+ return hostOp("digest", algorithm, data);
2771
+ };
2772
+ subtle.sign = function (algorithm, key, data) {
2773
+ var name = algorithmName(algorithm);
2774
+ if (name === "HMAC") {
2775
+ return hostOp("hmac", hmacHash(algorithm), key, data);
2776
+ }
2777
+ if (name === "ECDSA") {
2778
+ return hostOp("ecdsaSign", key, data);
2779
+ }
2780
+ fail("Algorithm must be one of [HMAC, ECDSA]");
2781
+ };
2782
+ subtle.verify = function (algorithm, key, data, signature) {
2783
+ var name = algorithmName(algorithm);
2784
+ if (name === "HMAC") {
2785
+ var expected = hostOp("hmac", hmacHash(algorithm), key, data);
2786
+ var i;
2787
+ if (expected.length !== signature.length) {
2788
+ return false;
2789
+ }
2790
+ for (i = 0; i < expected.length; i += 1) {
2791
+ if (expected[i] !== signature[i]) {
2792
+ return false;
2793
+ }
2794
+ }
2795
+ return true;
2796
+ }
2797
+ if (name === "ECDSA") {
2798
+ return hostOp("ecdsaVerify", key, data, signature);
2799
+ }
2800
+ fail("Algorithm must be one of [HMAC, ECDSA]");
2801
+ };
2802
+ function cipher(encrypt) {
2803
+ return function (algorithm, key, data) {
2804
+ var name = algorithmName(algorithm);
2805
+ if (name === "AES") {
2806
+ return hostOp("aes", encrypt, key, data);
2807
+ }
2808
+ if (name === "RSA") {
2809
+ return hostOp("rsa", encrypt, key, data);
2810
+ }
2811
+ fail("Algorithm must be one of [AES, RSA]");
2812
+ };
2813
+ }
2814
+ subtle.encrypt = cipher(true);
2815
+ subtle.decrypt = cipher(false);
2816
+ subtle.generateKey = function (algorithm) {
2817
+ var name = algorithmName(algorithm);
2818
+ if (name === "AES" || name === "HMAC") {
2819
+ return hostOp("generateSecret");
2820
+ }
2821
+ if (name === "RSA" || name === "ECDSA") {
2822
+ var pair = hostOp("generateKeyPair", name);
2823
+ // How AIC's key-pair map prints (measured).
2824
+ Object.defineProperty(pair, "toString", {
2825
+ enumerable: false,
2826
+ value: function () {
2827
+ return (
2828
+ '{ "privateKey": ' +
2829
+ this.privateKey +
2830
+ ', "publicKey": ' +
2831
+ this.publicKey +
2832
+ " }"
2833
+ );
2834
+ },
2835
+ });
2836
+ return pair;
2837
+ }
2838
+ fail("Algorithm must be one of [AES, ECDSA, RSA, HMAC]");
2839
+ };
2840
+ subtle.deriveKey = function (algorithm, baseKey, length) {
2841
+ if (typeof algorithm === "string") {
2842
+ fail("Salt must be provided for PBKDF2.");
2843
+ }
2844
+ if (algorithm.name !== "PBKDF2") {
2845
+ fail("Algorithm must be one of [PBKDF2]");
2846
+ }
2847
+ try {
2848
+ return hostOp(
2849
+ "pbkdf2",
2850
+ baseKey,
2851
+ algorithm.salt,
2852
+ algorithm.iterations,
2853
+ length,
2854
+ algorithm.hash
2855
+ );
2856
+ } catch (e) {
2857
+ if (typeof e === "string") {
2858
+ fail(e);
2859
+ }
2860
+ throw e;
2861
+ }
2862
+ };
2863
+ })(__rhinoLocalHostOp);
2864
+ }
2865
+
2866
+ function __rhinoLocalSeed(given) {
2867
+ given = given || {};
2868
+ __rhinoLocal.bindings = __rhinoLocalClone(given.bindings || {});
2869
+ var seeded = Object.keys(__rhinoLocal.bindings);
2870
+ var s;
2871
+ var journeyFields = ["name", "identityResource", "innerJourney", "mustRun"];
2872
+ for (s = 0; s < seeded.length; s += 1) {
2873
+ if (seeded[s] === "journey") {
2874
+ Object.keys(__rhinoLocal.bindings.journey || {}).forEach(function (f) {
2875
+ if (journeyFields.indexOf(f) === -1) {
2876
+ throw new Error(
2877
+ "rhino-local: given.bindings.journey." + f + " is not a journey seed"
2878
+ );
2879
+ }
2880
+ });
2881
+ } else if (seeded[s] === "cacheManager") {
2882
+ if (Object.keys(__rhinoLocal.bindings.cacheManager || {}).length > 0) {
2883
+ throw new Error(
2884
+ "rhino-local: given.bindings.cacheManager must be {}; seeding caches is not implemented"
2885
+ );
2886
+ }
2887
+ } else {
2888
+ throw new Error(
2889
+ "rhino-local: given.bindings." +
2890
+ seeded[s] +
2891
+ " seeding is not implemented; only journey and cacheManager are"
2892
+ );
2893
+ }
2894
+ }
2895
+ // Measured null in a journey: every call is "Cannot call method … of null".
2896
+ samlApplication = null;
2897
+ oauthApplication = null;
2898
+ __rhinoLocal.shared = __rhinoLocalClone(given.sharedState || {});
2899
+ __rhinoLocal.transient = __rhinoLocalClone(given.transientState || {});
2900
+ __rhinoLocal.secure = __rhinoLocalClone(given.secureState || {});
2901
+ __rhinoLocal.initialShared = __rhinoLocalClone(__rhinoLocal.shared);
2902
+ __rhinoLocal.initialTransient = __rhinoLocalClone(__rhinoLocal.transient);
2903
+ __rhinoLocal.initialSecure = __rhinoLocalClone(__rhinoLocal.secure);
2904
+ __rhinoLocal.managed = __rhinoLocalClone(given.managed || {});
2905
+ // Set of `managed/<name>` this environment declares. Membership only — every
2906
+ // schema RULE (properties, required, enum) is checked in the Node layer, so
2907
+ // there is exactly one implementation of each.
2908
+ __rhinoLocal.knownTypes = given.knownTypes
2909
+ ? __rhinoLocalClone(given.knownTypes)
2910
+ : null;
2911
+ __rhinoLocal.profileTenant = given.profileTenant || null;
2912
+ __rhinoLocal.profilePulledAt = given.profilePulledAt || null;
2913
+ __rhinoLocal.esv = __rhinoLocalClone(given.esv || {});
2914
+ __rhinoLocal.esvProvided = given.esv !== undefined;
2915
+ __rhinoLocal.secrets = __rhinoLocalClone(given.secrets || {});
2916
+ __rhinoLocal.secretsProvided = given.secrets !== undefined;
2917
+ __rhinoLocal.libraries = given.libraries
2918
+ ? __rhinoLocalClone(given.libraries)
2919
+ : {};
2920
+ __rhinoLocal.requireCache = {};
2921
+ if (given.engine === "legacy") {
2922
+ require = undefined;
2923
+ } else {
2924
+ require = function (name) {
2925
+ __rhinoLocalExpectArity("require", arguments, 1);
2926
+ return __rhinoLocalLoadLibrary(name);
2927
+ };
2928
+ }
2929
+ if (given.callbacks === undefined) {
2930
+ __rhinoLocal.submittedCallbacks = null;
2931
+ } else {
2932
+ __rhinoLocal.submittedCallbacks = __rhinoLocalClone(given.callbacks);
2933
+ }
2934
+ __rhinoLocal.httpStubs = given.http ? __rhinoLocalClone(given.http) : [];
2935
+ __rhinoLocal.generatedId = 0;
2936
+ __rhinoLocal.outcome = null;
2937
+ __rhinoLocal.callbacks = [];
2938
+ __rhinoLocal.openidm = [];
2939
+ __rhinoLocal.http = [];
2940
+ __rhinoLocal.logs = [];
2941
+
2942
+ requestHeaders = __rhinoLocalRequestMap(given.requestHeaders || {}, {
2943
+ caseInsensitive: true,
2944
+ asList: true,
2945
+ });
2946
+ requestParameters = __rhinoLocalRequestMap(given.requestParameters || {}, {
2947
+ caseInsensitive: false,
2948
+ asList: true,
2949
+ });
2950
+ requestCookies = __rhinoLocalRequestMap(given.requestCookies || {}, {
2951
+ caseInsensitive: false,
2952
+ asList: false,
2953
+ });
2954
+
2955
+ // Assigned either way: the runner's scope outlives one case, so leaving a
2956
+ // previous case's session installed would seed a binding nobody declared.
2957
+ existingSession =
2958
+ given.existingSession === undefined
2959
+ ? undefined
2960
+ : __rhinoLocalSessionMap(given.existingSession, given.engine);
2961
+
2962
+ if (given.realm !== undefined) {
2963
+ realm = given.realm;
2964
+ }
2965
+ if (given.scriptName !== undefined) {
2966
+ scriptName = given.scriptName;
2967
+ }
2968
+ if (given.cookieName !== undefined) {
2969
+ cookieName = given.cookieName;
2970
+ }
2971
+ if (given.resumedFromSuspend !== undefined) {
2972
+ resumedFromSuspend = given.resumedFromSuspend;
2973
+ }
2974
+ if (given.locales !== undefined) {
2975
+ locales = given.locales;
2976
+ }
2977
+
2978
+ if (given.engine === "legacy") {
2979
+ sharedState = __rhinoLocalStateMap("shared");
2980
+ transientState = __rhinoLocalStateMap("transient");
2981
+ // Next-gen-only bindings. Live legacy typeofs them as undefined
2982
+ // (docs/api/12); leaving them installed makes scripts take the
2983
+ // callbacksBuilder fallback and never hit Action.send.
2984
+ callbacksBuilder = undefined;
2985
+ action = undefined;
2986
+ openidm = undefined;
2987
+ utils = undefined;
2988
+ requestCookies = undefined;
2989
+ }
2990
+ }
2991
+
2992
+ function __rhinoLocalHarvest() {
2993
+ var recordedOutcome = __rhinoLocal.outcome;
2994
+ if (
2995
+ recordedOutcome === null &&
2996
+ typeof outcome !== "undefined" &&
2997
+ outcome !== null
2998
+ ) {
2999
+ recordedOutcome = String(outcome);
3000
+ }
3001
+ return JSON.stringify({
3002
+ outcome: recordedOutcome,
3003
+ sharedState: {
3004
+ initial: __rhinoLocal.initialShared,
3005
+ final: __rhinoLocalClone(__rhinoLocal.shared),
3006
+ },
3007
+ transientState: {
3008
+ initial: __rhinoLocal.initialTransient,
3009
+ final: __rhinoLocalClone(__rhinoLocal.transient),
3010
+ },
3011
+ secureState: {
3012
+ initial: __rhinoLocal.initialSecure,
3013
+ final: __rhinoLocalClone(__rhinoLocal.secure),
3014
+ },
3015
+ callbacks: __rhinoLocal.callbacks,
3016
+ openidm: __rhinoLocal.openidm,
3017
+ managedStore: __rhinoLocalClone(__rhinoLocal.managed),
3018
+ http: __rhinoLocal.http,
3019
+ logs: __rhinoLocal.logs,
3020
+ });
3021
+ }