@burdenoff/ui-engine 2026.1203.1 → 2026.1204.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,743 +0,0 @@
1
- import {
2
- sha256Hex2,
3
- targetFingerprint2
4
- } from "./index-dcs2pe49.js";
5
- import {
6
- UI_SCRIPT_VERSION2,
7
- MAX_SCRIPT_STEPS2,
8
- MAX_SCRIPT_BYTES2,
9
- MAX_FLOW_DEPTH2,
10
- MAX_EXPRESSION_DEPTH2,
11
- MAX_EXPRESSION_ITEMS2,
12
- MAX_OPERATOR_ARGS2,
13
- MAX_SCRIPT_INPUTS2,
14
- MAX_SCRIPT_OUTPUTS2,
15
- MAX_SCRIPT_VARIABLES2,
16
- MAX_SCRIPT_ELEMENTS2,
17
- MAX_TARGET_METHODS2,
18
- MAX_FRAME_DEPTH2,
19
- MAX_EXTRACT_FIELDS2,
20
- MAX_LIST_ITEMS2,
21
- MAX_LIST_PAGES2,
22
- MAX_LOOP_ITERATIONS2,
23
- MAX_RETRY_ATTEMPTS2,
24
- MAX_STEP_TIMEOUT_MS2,
25
- MAX_DELAY_MS2,
26
- MAX_KEYS2,
27
- MAX_SELECT_VALUES2,
28
- MAX_SELECTOR_LENGTH2,
29
- MAX_URL_LENGTH2,
30
- MAX_LABEL_LENGTH2,
31
- MAX_TEXT_LENGTH2,
32
- MAX_INTENT_LENGTH2,
33
- MAX_NAME_LENGTH2,
34
- jsonByteLength2
35
- } from "./index-20bbwwc9.js";
36
- import {
37
- UI_EXPRESSION_OPS2,
38
- UI_ANCHOR_RELATIONS2,
39
- UI_VALUE_TYPES2,
40
- walkSteps2,
41
- stepTargets2,
42
- stepExpressions2,
43
- visitExpression2
44
- } from "./index-g7724awk.js";
45
- import {
46
- containsCredential,
47
- containsCredentialInUrl
48
- } from "./index-mgztm37r.js";
49
-
50
- // src/script/schema.ts
51
- import { z } from "zod";
52
- var uiScriptRegistry2 = z.registry();
53
- var NAME_PATTERN2 = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;
54
- var STEP_ID_PATTERN2 = /^[A-Za-z0-9_-]{1,64}$/;
55
- var ELEMENT_KEY_PATTERN2 = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;
56
- var STORAGE_KEY_PATTERN = /^[A-Za-z0-9][A-Za-z0-9:/._-]{0,511}$/;
57
- var SECRET_REF_PATTERN = /^[A-Za-z0-9][A-Za-z0-9:/._#-]{0,254}$/;
58
- var ATTRIBUTE_PATTERN = /^[A-Za-z_:][A-Za-z0-9_.:-]{0,63}$/;
59
- var name = z.string().regex(NAME_PATTERN2);
60
- var label = z.string().min(1).max(MAX_LABEL_LENGTH2);
61
- var selector = z.string().min(1).max(MAX_SELECTOR_LENGTH2);
62
- var ms = z.int().min(0).max(MAX_STEP_TIMEOUT_MS2);
63
- var delay = z.int().min(0).max(MAX_DELAY_MS2);
64
- var valueType = z.enum(UI_VALUE_TYPES2);
65
- var valuePath = z.array(z.union([z.string().min(1).max(MAX_NAME_LENGTH2), z.int().min(0)])).min(1).max(MAX_EXPRESSION_DEPTH2);
66
- var uiExpressionSchema2 = z.lazy(() => z.union([
67
- z.string().max(MAX_TEXT_LENGTH2),
68
- z.number(),
69
- z.boolean(),
70
- z.null(),
71
- z.strictObject({ input: name, path: valuePath.optional() }),
72
- z.strictObject({ var: name, path: valuePath.optional() }),
73
- z.strictObject({ list: z.array(uiExpressionSchema2).max(MAX_EXPRESSION_ITEMS2) }),
74
- z.strictObject({ object: z.record(name, uiExpressionSchema2) }),
75
- z.strictObject({ op: z.enum(UI_EXPRESSION_OPS2), args: z.array(uiExpressionSchema2).max(MAX_OPERATOR_ARGS2) })
76
- ])).register(uiScriptRegistry2, { id: "UiExpression" });
77
- var enabled = { enabled: z.boolean().optional() };
78
- var anchorSchema = z.discriminatedUnion("kind", [
79
- z.strictObject({ kind: z.literal("text"), text: label }),
80
- z.strictObject({ kind: z.literal("role"), role: label, name: label })
81
- ]);
82
- var uiTargetMethodSchema2 = z.discriminatedUnion("kind", [
83
- z.strictObject({
84
- kind: z.literal("role"),
85
- role: label,
86
- name: label,
87
- nth: z.int().min(0).max(50).optional(),
88
- app: label.optional(),
89
- window: label.optional(),
90
- ...enabled
91
- }),
92
- z.strictObject({ kind: z.literal("css"), selector, ...enabled }),
93
- z.strictObject({
94
- kind: z.literal("testId"),
95
- value: label,
96
- attribute: z.string().regex(ATTRIBUTE_PATTERN).optional(),
97
- ...enabled
98
- }),
99
- z.strictObject({ kind: z.literal("xpath"), xpath: selector, ...enabled }),
100
- z.strictObject({
101
- kind: z.literal("fuzzy"),
102
- role: label.optional(),
103
- name: label,
104
- threshold: z.number().min(0.5).max(1).optional(),
105
- ...enabled
106
- }),
107
- z.strictObject({
108
- kind: z.literal("anchor"),
109
- anchor: anchorSchema,
110
- relation: z.enum(UI_ANCHOR_RELATIONS2),
111
- role: label.optional(),
112
- ...enabled
113
- }),
114
- z.strictObject({
115
- kind: z.literal("text"),
116
- text: label,
117
- exact: z.boolean().optional(),
118
- nth: z.int().min(0).max(50).optional(),
119
- ...enabled
120
- })
121
- ]).register(uiScriptRegistry2, { id: "UiTargetMethod" });
122
- var uiTargetSchema2 = z.strictObject({
123
- methods: z.array(uiTargetMethodSchema2).min(1).max(MAX_TARGET_METHODS2),
124
- frame: z.array(selector).min(1).max(MAX_FRAME_DEPTH2).optional()
125
- }).register(uiScriptRegistry2, { id: "UiTarget" });
126
- var uiTargetRefSchema2 = z.union([uiTargetSchema2, z.strictObject({ element: z.string().regex(ELEMENT_KEY_PATTERN2) })]).register(uiScriptRegistry2, { id: "UiTargetRef" });
127
- var verifyTimeout = { timeoutMs: ms.optional() };
128
- var verifySchema = z.discriminatedUnion("kind", [
129
- z.strictObject({ kind: z.literal("elementVisible"), target: uiTargetRefSchema2, ...verifyTimeout }),
130
- z.strictObject({ kind: z.literal("elementGone"), target: uiTargetRefSchema2, ...verifyTimeout }),
131
- z.strictObject({ kind: z.literal("urlContains"), value: uiExpressionSchema2, ...verifyTimeout }),
132
- z.strictObject({ kind: z.literal("textPresent"), text: uiExpressionSchema2, ...verifyTimeout }),
133
- z.strictObject({
134
- kind: z.literal("valueEquals"),
135
- target: uiTargetRefSchema2,
136
- value: uiExpressionSchema2,
137
- ...verifyTimeout
138
- })
139
- ]);
140
- var base = {
141
- id: z.string().regex(STEP_ID_PATTERN2),
142
- intent: z.string().min(1).max(MAX_INTENT_LENGTH2).optional(),
143
- note: z.string().min(1).max(MAX_INTENT_LENGTH2).optional(),
144
- saveAs: name.optional(),
145
- disabled: z.boolean().optional(),
146
- breakpoint: z.boolean().optional(),
147
- timeoutMs: ms.optional(),
148
- retry: z.strictObject({ attempts: z.int().min(1).max(MAX_RETRY_ATTEMPTS2), delayMs: delay.optional() }).optional(),
149
- onError: z.enum(["fail", "continue"]).optional(),
150
- verify: verifySchema.optional(),
151
- screenshot: z.enum(["never", "onFailure", "always"]).optional(),
152
- inputMethod: z.enum(["auto", "direct", "hardware"]).optional(),
153
- safeToRepeat: z.boolean().optional(),
154
- screenshotRef: z.string().regex(STORAGE_KEY_PATTERN).optional(),
155
- fingerprint: z.string().regex(/^[0-9a-f]{64}$/).optional()
156
- };
157
- var target = uiTargetRefSchema2;
158
- var steps = () => z.array(uiStepSchema2).min(1).max(MAX_SCRIPT_STEPS2);
159
- var fieldSchema = z.strictObject({
160
- name,
161
- target,
162
- attribute: z.string().regex(ATTRIBUTE_PATTERN).optional(),
163
- all: z.boolean().optional()
164
- });
165
- var fields = z.array(fieldSchema).min(1).max(MAX_EXTRACT_FIELDS2);
166
- var condition = { condition: uiExpressionSchema2.optional(), elementExists: target.optional() };
167
- var uiStepSchema2 = z.lazy(() => z.discriminatedUnion("action", [
168
- z.strictObject({
169
- ...base,
170
- action: z.literal("navigate"),
171
- url: uiExpressionSchema2,
172
- waitUntil: z.enum(["load", "domcontentloaded", "networkidle", "commit"]).optional()
173
- }),
174
- z.strictObject({ ...base, action: z.literal("goBack") }),
175
- z.strictObject({ ...base, action: z.literal("reload") }),
176
- z.strictObject({ ...base, action: z.literal("closeTab") }),
177
- z.strictObject({ ...base, action: z.literal("click"), target, button: z.enum(["left", "right"]).optional() }),
178
- z.strictObject({
179
- ...base,
180
- action: z.literal("doubleClick"),
181
- target,
182
- button: z.enum(["left", "right"]).optional()
183
- }),
184
- z.strictObject({ ...base, action: z.literal("hover"), target }),
185
- z.strictObject({
186
- ...base,
187
- action: z.literal("type"),
188
- target: target.optional(),
189
- text: uiExpressionSchema2.optional(),
190
- masked: z.boolean().optional(),
191
- clear: z.boolean().optional(),
192
- pressEnter: z.boolean().optional(),
193
- delayMs: delay.optional()
194
- }),
195
- z.strictObject({
196
- ...base,
197
- action: z.literal("typeSecret"),
198
- target,
199
- secretRef: z.string().regex(SECRET_REF_PATTERN),
200
- expectedOrigin: z.url({ protocol: /^https?$/ }).max(MAX_URL_LENGTH2).optional()
201
- }),
202
- z.strictObject({ ...base, action: z.literal("clear"), target }),
203
- z.strictObject({
204
- ...base,
205
- action: z.literal("select"),
206
- target,
207
- values: z.array(uiExpressionSchema2).min(1).max(MAX_SELECT_VALUES2)
208
- }),
209
- z.strictObject({ ...base, action: z.literal("check"), target, checked: z.boolean().optional() }),
210
- z.strictObject({
211
- ...base,
212
- action: z.literal("pressKey"),
213
- keys: z.array(z.string().min(1).max(32)).min(1).max(MAX_KEYS2),
214
- target: target.optional()
215
- }),
216
- z.strictObject({
217
- ...base,
218
- action: z.literal("scroll"),
219
- target: target.optional(),
220
- dx: z.int().min(-1e4).max(1e4).optional(),
221
- dy: z.int().min(-1e4).max(1e4).optional(),
222
- to: z.enum(["top", "bottom"]).optional()
223
- }),
224
- z.strictObject({
225
- ...base,
226
- action: z.literal("waitFor"),
227
- target: target.optional(),
228
- text: uiExpressionSchema2.optional(),
229
- urlContains: uiExpressionSchema2.optional(),
230
- milliseconds: z.int().min(1).max(MAX_STEP_TIMEOUT_MS2).optional(),
231
- state: z.enum(["visible", "hidden", "attached", "detached"]).optional()
232
- }),
233
- z.strictObject({ ...base, action: z.literal("extract"), fields }),
234
- z.strictObject({
235
- ...base,
236
- action: z.literal("extractList"),
237
- item: target,
238
- fields,
239
- maxItems: z.int().min(1).max(MAX_LIST_ITEMS2).optional(),
240
- next: target.optional(),
241
- maxPages: z.int().min(1).max(MAX_LIST_PAGES2).optional()
242
- }),
243
- z.strictObject({ ...base, action: z.literal("getText"), target }),
244
- z.strictObject({ ...base, action: z.literal("getValue"), target }),
245
- z.strictObject({
246
- ...base,
247
- action: z.literal("getAttribute"),
248
- target,
249
- attribute: z.string().regex(ATTRIBUTE_PATTERN)
250
- }),
251
- z.strictObject({ ...base, action: z.literal("elementExists"), target }),
252
- z.strictObject({ ...base, action: z.literal("getPageText") }),
253
- z.strictObject({ ...base, action: z.literal("getPageHtml") }),
254
- z.strictObject({
255
- ...base,
256
- action: z.literal("screenshot"),
257
- target: target.optional(),
258
- fullPage: z.boolean().optional()
259
- }),
260
- z.strictObject({
261
- ...base,
262
- action: z.literal("login"),
263
- username: target.optional(),
264
- password: target.optional(),
265
- submit: target.optional(),
266
- success: target.optional()
267
- }),
268
- z.strictObject({ ...base, action: z.literal("focusWindow"), app: label, title: label.optional() }),
269
- z.strictObject({ ...base, action: z.literal("if"), ...condition, then: steps(), else: steps().optional() }),
270
- z.strictObject({
271
- ...base,
272
- action: z.literal("forEach"),
273
- in: uiExpressionSchema2.optional(),
274
- elements: target.optional(),
275
- as: name,
276
- index: name.optional(),
277
- max: z.int().min(1).max(MAX_LOOP_ITERATIONS2).optional(),
278
- steps: steps()
279
- }),
280
- z.strictObject({
281
- ...base,
282
- action: z.literal("while"),
283
- ...condition,
284
- maxIterations: z.int().min(1).max(MAX_LOOP_ITERATIONS2),
285
- steps: steps()
286
- }),
287
- z.strictObject({
288
- ...base,
289
- action: z.literal("retryScope"),
290
- attempts: z.int().min(1).max(MAX_RETRY_ATTEMPTS2),
291
- delayMs: delay.optional(),
292
- steps: steps()
293
- }),
294
- z.strictObject({ ...base, action: z.literal("set"), name, value: uiExpressionSchema2 }),
295
- z.strictObject({
296
- ...base,
297
- action: z.literal("log"),
298
- level: z.enum(["debug", "info", "warn", "error"]).optional(),
299
- message: uiExpressionSchema2
300
- }),
301
- z.strictObject({
302
- ...base,
303
- action: z.literal("call"),
304
- sequenceId: z.string().min(1).max(MAX_NAME_LENGTH2),
305
- version: z.int().min(1),
306
- args: z.record(name, uiExpressionSchema2).optional()
307
- })
308
- ])).register(uiScriptRegistry2, { id: "UiStep" });
309
- var description = z.string().min(1).max(MAX_INTENT_LENGTH2).optional();
310
- var uiScriptSchema2 = z.strictObject({
311
- scriptVersion: z.literal(UI_SCRIPT_VERSION2),
312
- name: label.optional(),
313
- application: z.strictObject({ name: label.optional(), urlPattern: z.string().min(1).max(MAX_URL_LENGTH2).optional() }).optional(),
314
- settings: z.strictObject({
315
- firstWaitMs: ms.optional(),
316
- waitMs: ms.optional(),
317
- screenshots: z.enum(["never", "onFailure", "everyStep"]).optional(),
318
- inputMethod: z.enum(["auto", "direct", "hardware"]).optional()
319
- }).optional(),
320
- inputs: z.array(z.strictObject({
321
- name,
322
- type: valueType.optional(),
323
- required: z.boolean().optional(),
324
- default: uiExpressionSchema2.optional(),
325
- description
326
- })).max(MAX_SCRIPT_INPUTS2).optional(),
327
- outputs: z.array(z.strictObject({ name, type: valueType.optional(), value: uiExpressionSchema2, description })).max(MAX_SCRIPT_OUTPUTS2).optional(),
328
- variables: z.array(z.strictObject({ name, type: valueType.optional(), initial: uiExpressionSchema2.optional() })).max(MAX_SCRIPT_VARIABLES2).optional(),
329
- elements: z.record(z.string().regex(ELEMENT_KEY_PATTERN2), z.strictObject({
330
- elementId: z.string().min(1).max(MAX_NAME_LENGTH2),
331
- version: z.int().min(1),
332
- name: label.optional(),
333
- target: uiTargetSchema2.optional()
334
- })).optional(),
335
- steps: steps(),
336
- cleanup: steps().optional()
337
- });
338
-
339
- // src/script/canonical.ts
340
- function canonicalJson2(value) {
341
- return JSON.stringify(canonicalValue(value)) ?? "null";
342
- }
343
- function canonicalValue(value) {
344
- if (Array.isArray(value))
345
- return value.map(canonicalValue);
346
- if (value !== null && typeof value === "object") {
347
- const out = {};
348
- for (const key of Object.keys(value).sort()) {
349
- const item = Reflect.get(value, key);
350
- if (item !== undefined)
351
- out[key] = canonicalValue(item);
352
- }
353
- return out;
354
- }
355
- return value;
356
- }
357
-
358
- // src/script/fingerprint.ts
359
- var RECORDING_ACTION_OF2 = {
360
- click: "click",
361
- doubleClick: "click",
362
- type: "type",
363
- typeSecret: "secret_fill",
364
- pressKey: "key",
365
- scroll: "scroll",
366
- navigate: "navigate",
367
- focusWindow: "focus_window"
368
- };
369
- function soleRoleMethod(ref) {
370
- if (!ref || "element" in ref || ref.frame || ref.methods.length !== 1)
371
- return;
372
- const [method] = ref.methods;
373
- return method?.kind === "role" && method.enabled !== false ? method : undefined;
374
- }
375
- function stepTarget(step) {
376
- return "target" in step ? step.target : undefined;
377
- }
378
- function uiStepFingerprint2(step) {
379
- const target = stepTarget(step);
380
- const recordingAction = RECORDING_ACTION_OF2[step.action];
381
- const url = step.action === "navigate" ? step.url : undefined;
382
- const app = step.action === "focusWindow" ? step.app : undefined;
383
- const title = step.action === "focusWindow" ? step.title : undefined;
384
- const role = soleRoleMethod(target);
385
- const targets = stepTargets2(step);
386
- const onlyOwnTarget = targets.every(([field]) => field === "target");
387
- if (recordingAction && onlyOwnTarget && (target === undefined || role) && (url === undefined || typeof url === "string")) {
388
- return targetFingerprint2({
389
- action: recordingAction,
390
- ...role ? {
391
- target: {
392
- role: role.role,
393
- name: role.name,
394
- nth: role.nth ?? 0,
395
- ...role.app === undefined ? {} : { app: role.app },
396
- ...role.window === undefined ? {} : { window: role.window }
397
- }
398
- } : {},
399
- ...url === undefined ? {} : { url },
400
- ...app === undefined ? {} : { app },
401
- ...title === undefined ? {} : { title }
402
- });
403
- }
404
- return sha256Hex2(canonicalJson2(["ui-script/1", step.action, targets, url ?? null, app ?? null, title ?? null]));
405
- }
406
- function withFingerprint2(step) {
407
- return { ...step, fingerprint: uiStepFingerprint2(step) };
408
- }
409
-
410
- // src/script/parse.ts
411
- class UiScriptError2 extends Error {
412
- code;
413
- path;
414
- constructor(code, message, path) {
415
- super(message);
416
- this.code = code;
417
- this.path = path;
418
- this.name = "UiScriptError";
419
- }
420
- }
421
- var UI_EXPRESSION_ARITY2 = {
422
- eq: [2, 2],
423
- ne: [2, 2],
424
- lt: [2, 2],
425
- le: [2, 2],
426
- gt: [2, 2],
427
- ge: [2, 2],
428
- and: [2, 16],
429
- or: [2, 16],
430
- not: [1, 1],
431
- add: [2, 16],
432
- sub: [2, 2],
433
- mul: [2, 16],
434
- div: [2, 2],
435
- mod: [2, 2],
436
- neg: [1, 1],
437
- abs: [1, 1],
438
- round: [1, 2],
439
- min: [1, 16],
440
- max: [1, 16],
441
- concat: [1, 16],
442
- contains: [2, 2],
443
- startsWith: [2, 2],
444
- endsWith: [2, 2],
445
- lower: [1, 1],
446
- upper: [1, 1],
447
- trim: [1, 1],
448
- replace: [3, 3],
449
- split: [2, 2],
450
- join: [1, 2],
451
- length: [1, 1],
452
- toNumber: [1, 1],
453
- toText: [1, 1],
454
- toBoolean: [1, 1],
455
- isEmpty: [1, 1],
456
- coalesce: [1, 16],
457
- if: [3, 3],
458
- get: [2, 2],
459
- now: [0, 0],
460
- formatDate: [1, 2],
461
- addDays: [2, 2]
462
- };
463
- function parseUiScript2(value, options = {}) {
464
- const raw = readJson(value);
465
- const parsed = uiScriptSchema2.safeParse(raw);
466
- if (!parsed.success) {
467
- const issue = parsed.error.issues[0];
468
- const where = issue?.path.map(String).join(".") ?? "";
469
- throw new UiScriptError2("INVALID_SCRIPT", `The UI script is not valid at ${where || "the top"}: ${issue?.message ?? "unknown problem"}`, where || undefined);
470
- }
471
- checkScript(parsed.data, options);
472
- return parsed.data;
473
- }
474
- function safeParseUiScript2(value, options = {}) {
475
- try {
476
- return { success: true, script: parseUiScript2(value, options) };
477
- } catch (error) {
478
- if (error instanceof UiScriptError2)
479
- return { success: false, error };
480
- throw error;
481
- }
482
- }
483
- function readJson(value) {
484
- let raw = value;
485
- if (typeof value === "string") {
486
- if (new TextEncoder().encode(value).length > MAX_SCRIPT_BYTES2)
487
- tooLarge();
488
- try {
489
- raw = JSON.parse(value);
490
- } catch {
491
- throw new UiScriptError2("INVALID_SCRIPT", "The UI script is not valid JSON");
492
- }
493
- } else if (jsonByteLength2(value) > MAX_SCRIPT_BYTES2) {
494
- tooLarge();
495
- }
496
- if (jsonDepth(raw) > MAX_JSON_DEPTH) {
497
- throw new UiScriptError2("INVALID_SCRIPT", `The UI script is nested deeper than ${MAX_JSON_DEPTH} levels`);
498
- }
499
- return raw;
500
- }
501
- var MAX_JSON_DEPTH = 256;
502
- function jsonDepth(value) {
503
- let deepest = 0;
504
- const stack = [[value, 1]];
505
- while (stack.length > 0) {
506
- const [item, depth] = stack.pop() ?? [null, 0];
507
- if (item === null || typeof item !== "object")
508
- continue;
509
- deepest = Math.max(deepest, depth);
510
- if (deepest > MAX_JSON_DEPTH)
511
- return deepest;
512
- for (const child of Object.values(item))
513
- stack.push([child, depth + 1]);
514
- }
515
- return deepest;
516
- }
517
- function tooLarge() {
518
- throw new UiScriptError2("SCRIPT_TOO_LARGE", `The UI script is larger than ${MAX_SCRIPT_BYTES2} bytes`);
519
- }
520
- function checkScript(script, options) {
521
- const elements = script.elements ?? {};
522
- if (Object.keys(elements).length > MAX_SCRIPT_ELEMENTS2) {
523
- throw new UiScriptError2("INVALID_SCRIPT", `A UI script pins at most ${MAX_SCRIPT_ELEMENTS2} elements`, "elements");
524
- }
525
- const inputs = uniqueNames(script.inputs, "inputs");
526
- uniqueNames(script.outputs, "outputs");
527
- uniqueNames(script.variables, "variables");
528
- const checkExpression = (expression, where) => {
529
- visitExpression2(expression, (node, depth) => {
530
- if (depth > MAX_EXPRESSION_DEPTH2) {
531
- throw new UiScriptError2("INVALID_SCRIPT", `An expression is nested deeper than ${MAX_EXPRESSION_DEPTH2}`, where);
532
- }
533
- if (typeof node === "string" && containsCredential(node)) {
534
- throw new UiScriptError2("CREDENTIAL_IN_SCRIPT", "The UI script holds a credential in a value", where);
535
- }
536
- if (node === null || typeof node !== "object")
537
- return;
538
- if ("input" in node && !inputs.has(node.input)) {
539
- throw new UiScriptError2("UNKNOWN_INPUT", `The input "${node.input}" is not declared`, where);
540
- }
541
- if ("op" in node) {
542
- const [fewest, most] = UI_EXPRESSION_ARITY2[node.op];
543
- if (node.args.length < fewest || node.args.length > most) {
544
- throw new UiScriptError2("INVALID_SCRIPT", `The operator "${node.op}" takes ${fewest === most ? fewest : `${fewest} to ${most}`} arguments`, where);
545
- }
546
- }
547
- });
548
- };
549
- script.inputs?.forEach((input, index) => {
550
- if (input.default !== undefined)
551
- checkExpression(input.default, `inputs.${index}.default`);
552
- });
553
- script.outputs?.forEach((output, index) => checkExpression(output.value, `outputs.${index}.value`));
554
- script.variables?.forEach((variable, index) => {
555
- if (variable.initial !== undefined)
556
- checkExpression(variable.initial, `variables.${index}.initial`);
557
- });
558
- checkScriptText(script);
559
- if (options.resolved) {
560
- for (const [key, element] of Object.entries(elements)) {
561
- if (!element.target) {
562
- throw new UiScriptError2("UNRESOLVED", `The element "${key}" has no target`, `elements.${key}`);
563
- }
564
- }
565
- }
566
- const ids = new Set;
567
- let count = 0;
568
- for (const { step, path, depth } of walkSteps2(script)) {
569
- count += 1;
570
- if (count > MAX_SCRIPT_STEPS2) {
571
- throw new UiScriptError2("TOO_MANY_STEPS", `A UI script has at most ${MAX_SCRIPT_STEPS2} steps`, path);
572
- }
573
- if (depth > MAX_FLOW_DEPTH2) {
574
- throw new UiScriptError2("INVALID_SCRIPT", `Flow blocks nest at most ${MAX_FLOW_DEPTH2} deep`, path);
575
- }
576
- if (ids.has(step.id)) {
577
- throw new UiScriptError2("DUPLICATE_STEP_ID", `Step id ${step.id} is used twice`, path);
578
- }
579
- ids.add(step.id);
580
- if (options.resolved && step.action === "call") {
581
- throw new UiScriptError2("UNRESOLVED", `Step ${step.id} calls a shared sequence that was not inlined`, path);
582
- }
583
- checkStepShape(step, path);
584
- for (const [field, ref] of stepTargets2(step)) {
585
- if ("element" in ref && !Object.hasOwn(elements, ref.element)) {
586
- throw new UiScriptError2("UNKNOWN_ELEMENT", `Step ${step.id} uses the element "${ref.element}", which the script does not pin`, `${path}.${field}`);
587
- }
588
- if (!("element" in ref))
589
- refuseCredentialText(targetText(ref), `${path}.${field}`);
590
- }
591
- for (const [field, expression] of stepExpressions2(step))
592
- checkExpression(expression, `${path}.${field}`);
593
- checkStepText(step, path);
594
- if (step.fingerprint !== undefined && step.fingerprint !== uiStepFingerprint2(step)) {
595
- throw new UiScriptError2("FINGERPRINT_MISMATCH", `Step ${step.id} was changed after it was recorded`, path);
596
- }
597
- }
598
- }
599
- function uniqueNames(list, where) {
600
- const names = new Set;
601
- list?.forEach(({ name }, index) => {
602
- if (names.has(name)) {
603
- throw new UiScriptError2("INVALID_SCRIPT", `The name "${name}" is declared twice`, `${where}.${index}`);
604
- }
605
- names.add(name);
606
- });
607
- return names;
608
- }
609
- function exactlyOne(step, path, fields) {
610
- const given = Object.entries(fields).filter(([, value]) => value !== undefined);
611
- if (given.length !== 1) {
612
- throw new UiScriptError2("INVALID_SCRIPT", `Step ${step.id} (${step.action}) needs exactly one of ${Object.keys(fields).join(", ")}`, path);
613
- }
614
- }
615
- function checkStepShape(step, path) {
616
- const refuse = (message) => {
617
- throw new UiScriptError2("INVALID_SCRIPT", `Step ${step.id} (${step.action}): ${message}`, path);
618
- };
619
- switch (step.action) {
620
- case "navigate":
621
- if (typeof step.url === "string" && !isHttpUrl(step.url))
622
- refuse("the URL must be an absolute http(s) URL");
623
- break;
624
- case "waitFor":
625
- exactlyOne(step, path, {
626
- target: step.target,
627
- text: step.text,
628
- urlContains: step.urlContains,
629
- milliseconds: step.milliseconds
630
- });
631
- if (step.state !== undefined && step.target === undefined)
632
- refuse("state needs a target");
633
- break;
634
- case "if":
635
- case "while":
636
- exactlyOne(step, path, { condition: step.condition, elementExists: step.elementExists });
637
- break;
638
- case "forEach":
639
- exactlyOne(step, path, { in: step.in, elements: step.elements });
640
- if (step.index !== undefined && step.index === step.as)
641
- refuse("the item and the index need different names");
642
- break;
643
- case "type":
644
- if (step.masked === true && step.text !== undefined)
645
- refuse("a masked step carries no text");
646
- break;
647
- case "scroll":
648
- if (step.to !== undefined && (step.target !== undefined || step.dx !== undefined || step.dy !== undefined)) {
649
- refuse("to scrolls the page and cannot be combined with a target or an offset");
650
- }
651
- break;
652
- default:
653
- break;
654
- }
655
- }
656
- function isHttpUrl(text) {
657
- if (text.length > MAX_URL_LENGTH2)
658
- return false;
659
- try {
660
- const url = new URL(text);
661
- return url.protocol === "http:" || url.protocol === "https:";
662
- } catch {
663
- return false;
664
- }
665
- }
666
- function targetText(target) {
667
- const texts = [...target.frame ?? []];
668
- for (const method of target.methods) {
669
- switch (method.kind) {
670
- case "role":
671
- texts.push(method.role, method.name, method.app, method.window);
672
- break;
673
- case "css":
674
- texts.push(method.selector);
675
- break;
676
- case "testId":
677
- texts.push(method.value, method.attribute);
678
- break;
679
- case "xpath":
680
- texts.push(method.xpath);
681
- break;
682
- case "fuzzy":
683
- texts.push(method.role, method.name);
684
- break;
685
- case "anchor":
686
- texts.push(method.role, method.anchor.kind === "text" ? method.anchor.text : method.anchor.name);
687
- if (method.anchor.kind === "role")
688
- texts.push(method.anchor.role);
689
- break;
690
- default:
691
- texts.push(method.text);
692
- break;
693
- }
694
- }
695
- return texts.filter((text) => text !== undefined);
696
- }
697
- function refuseCredentialText(texts, where) {
698
- if (texts.some((text) => containsCredential(text))) {
699
- throw new UiScriptError2("CREDENTIAL_IN_SCRIPT", "The UI script holds a credential in a stored text", where);
700
- }
701
- }
702
- function checkScriptText(script) {
703
- refuseCredentialText([script.name, script.application?.name, script.application?.urlPattern].filter((text) => text !== undefined), "name");
704
- for (const [list, where] of [
705
- [script.inputs, "inputs"],
706
- [script.outputs, "outputs"]
707
- ]) {
708
- list?.forEach((item, index) => {
709
- if (item.description !== undefined)
710
- refuseCredentialText([item.description], `${where}.${index}.description`);
711
- });
712
- }
713
- for (const [key, element] of Object.entries(script.elements ?? {})) {
714
- refuseCredentialText([element.name, ...element.target ? targetText(element.target) : []].filter((text) => text !== undefined), `elements.${key}`);
715
- }
716
- }
717
- function checkStepText(step, path) {
718
- if (step.action === "focusWindow") {
719
- refuseCredentialText(step.title === undefined ? [step.app] : [step.app, step.title], path);
720
- }
721
- for (const [field, text] of [
722
- ["intent", step.intent],
723
- ["note", step.note]
724
- ]) {
725
- if (text !== undefined && containsCredential(text)) {
726
- throw new UiScriptError2("CREDENTIAL_IN_SCRIPT", `Step ${step.id} holds a credential in its ${field}`, path);
727
- }
728
- }
729
- if (step.action === "navigate" && typeof step.url === "string") {
730
- let userInfo = false;
731
- try {
732
- const url = new URL(step.url);
733
- userInfo = Boolean(url.username || url.password);
734
- } catch {
735
- userInfo = false;
736
- }
737
- if (userInfo || containsCredentialInUrl(step.url)) {
738
- throw new UiScriptError2("CREDENTIAL_IN_SCRIPT", `Step ${step.id} holds a credential in its URL`, `${path}.url`);
739
- }
740
- }
741
- }
742
-
743
- export { uiScriptRegistry2, NAME_PATTERN2, STEP_ID_PATTERN2, ELEMENT_KEY_PATTERN2, uiExpressionSchema2, uiTargetMethodSchema2, uiTargetSchema2, uiTargetRefSchema2, uiStepSchema2, uiScriptSchema2, canonicalJson2, RECORDING_ACTION_OF2, soleRoleMethod, uiStepFingerprint2, withFingerprint2, UiScriptError2, UI_EXPRESSION_ARITY2, parseUiScript2, safeParseUiScript2 };