@uipath/maestro-builder-sdk 6.116.0 → 6.117.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.
package/dist/check.js CHANGED
@@ -6,7 +6,7 @@ import { FlowNode } from './core/node-classes.js';
6
6
  import { definitionHasErrorPort } from './core/error-port.js';
7
7
  import { bundledDefinition, resolveContributionDefinition, serialize } from './serialize.js';
8
8
  import { checkEventResolution, checkEventSubscription, eventParamsFor, } from './core/event-checks.js';
9
- import { checkCookedEscapes, checkFlowExpressions, literalExprShape, literalLooksLikeExpr } from './flow-expr-check.js';
9
+ import { checkCookedEscapes, checkFlowExpressions, checkVarsOnlyInQuotes, literalExprShape, literalLooksLikeExpr } from './flow-expr-check.js';
10
10
  import { FLOW_EXPR_DIALECT, checkBindingLabels, checkConnectorLookups as coreCheckConnectorLookups, checkConnectorResources as coreCheckConnectorResources, checkConnectorSchema as coreCheckConnectorSchema, } from './core/connector-checks.js';
11
11
  import { nearestName } from './core/edit-distance.js';
12
12
  import { escapeRegExp } from './core/escape-regexp.js';
@@ -49,7 +49,7 @@ export function checkCompiled(built, opts = {}) {
49
49
  const diags = checkFlow(built, [], opts);
50
50
  // Once, from the top: the walk reaches child flows itself, so running it per
51
51
  // `checkFlow` would report a child's escape twice.
52
- for (const d of checkCookedEscapes(built)) {
52
+ for (const d of [...checkCookedEscapes(built), ...checkVarsOnlyInQuotes(built)]) {
53
53
  diags.push({
54
54
  level: d.level, code: d.code, message: `In ${d.where}: ${d.message}`,
55
55
  ...(d.step !== undefined ? { step: d.step } : {}),
@@ -114,6 +114,42 @@ export interface ExprScope {
114
114
  * `namespace` defaults to `$vars` (Flow); Case passes `case`.
115
115
  */
116
116
  export declare function extractRefs(expr: string, namespace?: string): ExprRef[];
117
+ /** A quoted mention of the namespace inside an expression that reads none (`quotedOnlyMentions`). */
118
+ export interface QuotedMention {
119
+ /** The string literal as written, quotes included: `'$vars.start.output.topic'`. */
120
+ literal: string;
121
+ /** The text inside the quotes. */
122
+ text: string;
123
+ /**
124
+ * Where `literal` sits in the expression (`expr.slice(start, end) === literal`), for a
125
+ * whole string: a quoted string or a template with no parts. Absent for a piece of a
126
+ * template with parts (head, middle, tail): its token carries the `` ` ``/`${`/`}`
127
+ * delimiters, so there is no quoted reference to unquote in place.
128
+ */
129
+ start?: number;
130
+ end?: number;
131
+ }
132
+ /**
133
+ * The string literals that mention `<namespace>.` (or `<namespace>[`) in an
134
+ * expression that reads no variable, or `undefined` when the expression reads
135
+ * one, mentions the namespace in no string, or does not parse (that is
136
+ * EXPR_SYNTAX's). A read is the namespace itself or any other `$`-prefixed root
137
+ * (`$metadata.instanceId`): an expression that reads `$metadata` is not a
138
+ * constant, whatever its quoted text says.
139
+ *
140
+ * For instance `'"' + '$vars.start.output.topic' + '"'` reads no variable: the
141
+ * reference sits inside quotes, so the expression is the string constant
142
+ * `"$vars.start.output.topic"` on every run. `$vars.a.output + ' ($vars.b)'`
143
+ * reads `$vars.a`, so it is not reported: a mention in text beside a real read
144
+ * may well be deliberate.
145
+ *
146
+ * Parsed, not pattern-matched: a read is an identifier token in code (a member
147
+ * chain, `Object.keys($vars)`, a `${...}` part of a template), and a mention is
148
+ * a string or template text piece that contains the namespace. So an escaped
149
+ * quote, a comment, a regular expression and a string inside a template part
150
+ * are each read for what they are.
151
+ */
152
+ export declare function quotedOnlyMentions(expr: string, namespace?: string): QuotedMention[] | undefined;
117
153
  /**
118
154
  * First-level check of ONE expression: every reference's root must resolve (or, for a
119
155
  * root declared with a dot in its name, its leading segments; see `unresolvedDottedName`).
@@ -225,6 +225,54 @@ export function extractRefs(expr, namespace = DEFAULT_NAMESPACE) {
225
225
  }
226
226
  return refs;
227
227
  }
228
+ /**
229
+ * The string literals that mention `<namespace>.` (or `<namespace>[`) in an
230
+ * expression that reads no variable, or `undefined` when the expression reads
231
+ * one, mentions the namespace in no string, or does not parse (that is
232
+ * EXPR_SYNTAX's). A read is the namespace itself or any other `$`-prefixed root
233
+ * (`$metadata.instanceId`): an expression that reads `$metadata` is not a
234
+ * constant, whatever its quoted text says.
235
+ *
236
+ * For instance `'"' + '$vars.start.output.topic' + '"'` reads no variable: the
237
+ * reference sits inside quotes, so the expression is the string constant
238
+ * `"$vars.start.output.topic"` on every run. `$vars.a.output + ' ($vars.b)'`
239
+ * reads `$vars.a`, so it is not reported: a mention in text beside a real read
240
+ * may well be deliberate.
241
+ *
242
+ * Parsed, not pattern-matched: a read is an identifier token in code (a member
243
+ * chain, `Object.keys($vars)`, a `${...}` part of a template), and a mention is
244
+ * a string or template text piece that contains the namespace. So an escaped
245
+ * quote, a comment, a regular expression and a string inside a template part
246
+ * are each read for what they are.
247
+ */
248
+ export function quotedOnlyMentions(expr, namespace = DEFAULT_NAMESPACE) {
249
+ if (!expr.includes(namespace))
250
+ return undefined;
251
+ const ts = typescript();
252
+ const { source, problems } = parseExpression(expr);
253
+ if (problems.length)
254
+ return undefined;
255
+ const mention = new RegExp(`${escapeRegExp(namespace)}\\s*[.[]`);
256
+ let reads = 0;
257
+ const found = [];
258
+ const visit = (node) => {
259
+ if (ts.isIdentifier(node) && (node.text === namespace || node.text.startsWith('$')))
260
+ reads++;
261
+ else if (node.kind >= ts.SyntaxKind.FirstLiteralToken && node.kind <= ts.SyntaxKind.LastTemplateToken
262
+ && node.kind !== ts.SyntaxKind.RegularExpressionLiteral) {
263
+ const text = node.text;
264
+ // The source is `(${expr}\n)`: one character before the expression starts.
265
+ const start = node.getStart(source) - 1;
266
+ const whole = node.kind === ts.SyntaxKind.StringLiteral || node.kind === ts.SyntaxKind.NoSubstitutionTemplateLiteral;
267
+ const literal = expr.slice(start, node.end - 1);
268
+ if (mention.test(text))
269
+ found.push(whole ? { literal, text, start, end: node.end - 1 } : { literal, text });
270
+ }
271
+ ts.forEachChild(node, visit);
272
+ };
273
+ visit(source);
274
+ return reads === 0 && found.length ? found : undefined;
275
+ }
228
276
  /** True when `a` and `b` are equal or one edit (insert/delete/substitute) apart. */
229
277
  function editDistanceLE1(a, b) {
230
278
  if (a === b)
@@ -351,6 +351,7 @@ export declare const REFUSALS: {
351
351
  readonly EXPR_BARE_VAR_REF: "lint";
352
352
  readonly EXPR_SYNTAX: "lowering";
353
353
  readonly EXPR_UNDECLARED_REF: "lint";
354
+ readonly EXPR_VARS_ONLY_IN_QUOTES: "lint";
354
355
  readonly EXTERNAL_TASK_CONNECTION: "lowering";
355
356
  readonly EXTERNAL_TASK_DESCRIPTOR: "lint";
356
357
  readonly EXTERNAL_TASK_DESCRIPTOR_CONTRACT: "lowering";
@@ -425,6 +425,7 @@ export const REFUSALS = {
425
425
  EXPR_BARE_VAR_REF: 'lint',
426
426
  EXPR_SYNTAX: 'lowering',
427
427
  EXPR_UNDECLARED_REF: 'lint',
428
+ EXPR_VARS_ONLY_IN_QUOTES: 'lint',
428
429
  EXTERNAL_TASK_CONNECTION: 'lowering',
429
430
  EXTERNAL_TASK_DESCRIPTOR: 'lint',
430
431
  EXTERNAL_TASK_DESCRIPTOR_CONTRACT: 'lowering',
@@ -23,19 +23,33 @@ export declare function checkFlowExpressions(built: BuiltFlow): LocatedDiagnosti
23
23
  * Every `js` template escape that changed what its expression means
24
24
  * (JS_ESCAPE_COOKED), each stamped with where it sits.
25
25
  *
26
- * WHY A GENERIC WALK. The two per-site walks (`walk` above and `check.ts`'s
27
- * expression collection) each enumerate the positions an expression can sit in,
28
- * and neither covers all of them — HTTP branch conditions, trigger filters and
29
- * error-handler bodies each live in only one, or none. This warning is about the
30
- * `Expr` itself, not about the field it fills, so it visits every `Expr` reachable
31
- * from the built flow, child flows included: a new position cannot be missed.
32
- *
33
26
  * Only `meaning` effects are reported here. An escape that breaks the parse is
34
27
  * named by EXPR_SYNTAX, which the serializer refuses.
35
28
  */
36
29
  export declare function checkCookedEscapes(built: BuiltFlow): (LocatedDiagnostic & {
37
30
  step?: string;
38
31
  })[];
32
+ /**
33
+ * EXPR_VARS_ONLY_IN_QUOTES (warning, #1971): an expression whose every `$vars`
34
+ * mention sits inside a string literal, so it reads no variable and evaluates
35
+ * to the same constant on every run. For instance
36
+ * js`'"' + '$vars.start.output.topic' + '"'` is the text
37
+ * `"$vars.start.output.topic"`, not the topic: the reference was quoted.
38
+ *
39
+ * Only an expression that reads NO variable is reported (`quotedOnlyMentions`):
40
+ * `$vars.a.output + ' ($vars.b)'` and `$metadata.instanceId + ' $vars.b'` each
41
+ * read one, and a mention beside a real read may be deliberate text. A `lit(...)` is not an
42
+ * expression, and a script body (`code`) or a prompt is a plain string, so
43
+ * none of them is read here.
44
+ *
45
+ * The suggestion is the expression with each quoted whole reference unquoted
46
+ * (`'$vars.start.output.topic'` → `$vars.start.output.topic`), when every
47
+ * mention is one; a mention inside longer text (`'Hi $vars.x'`) has no
48
+ * mechanical fix, so the message points at `tmpl`.
49
+ */
50
+ export declare function checkVarsOnlyInQuotes(built: BuiltFlow): (LocatedDiagnostic & {
51
+ step?: string;
52
+ })[];
39
53
  /**
40
54
  * How a plain string looks like an expression: `text` = sent as written,
41
55
  * `template` = interpolated through `{{ … }}`, `wire` = evaluated because it
@@ -32,7 +32,7 @@
32
32
  * script body's `$vars.*` reads are `check.ts`'s UNKNOWN_REF.
33
33
  */
34
34
  import { Expr, cookedEscapesOf } from './core/expr.js';
35
- import { checkExpression, cookedEscapeDiagnostics, extractRefs } from './core/expr-check.js';
35
+ import { checkExpression, cookedEscapeDiagnostics, extractRefs, quotedOnlyMentions } from './core/expr-check.js';
36
36
  import { refusalClass } from './core/refusals.js';
37
37
  import { stepDeclaredVariables } from './flow-step-variables.js';
38
38
  import { CompileRefusal } from './core/compile-refusal.js';
@@ -222,34 +222,31 @@ export function checkFlowExpressions(built) {
222
222
  return out;
223
223
  }
224
224
  /**
225
- * Every `js` template escape that changed what its expression means
226
- * (JS_ESCAPE_COOKED), each stamped with where it sits.
225
+ * Visit every `Expr` reachable from the built flow, child flows included, with
226
+ * where it sits.
227
227
  *
228
228
  * WHY A GENERIC WALK. The two per-site walks (`walk` above and `check.ts`'s
229
229
  * expression collection) each enumerate the positions an expression can sit in,
230
230
  * and neither covers all of them — HTTP branch conditions, trigger filters and
231
- * error-handler bodies each live in only one, or none. This warning is about the
232
- * `Expr` itself, not about the field it fills, so it visits every `Expr` reachable
233
- * from the built flow, child flows included: a new position cannot be missed.
231
+ * error-handler bodies each live in only one, or none. A rule about the `Expr`
232
+ * itself, not about the field it fills (JS_ESCAPE_COOKED,
233
+ * EXPR_VARS_ONLY_IN_QUOTES), visits every `Expr` this way: a new position
234
+ * cannot be missed. Run it once, from the top: it reaches child flows itself.
234
235
  *
235
- * Only `meaning` effects are reported here. An escape that breaks the parse is
236
- * named by EXPR_SYNTAX, which the serializer refuses.
236
+ * `onExpr` gets an `Expr`, or a value of another SDK copy that carries cooked
237
+ * escapes (`cookedEscapesOf`); the walk does not descend into either.
237
238
  */
238
- export function checkCookedEscapes(built) {
239
- const out = [];
239
+ function visitExprs(built, onExpr) {
240
240
  const seen = new WeakSet();
241
241
  const root = built;
242
242
  const visit = (val, at) => {
243
243
  if (val === null || typeof val !== 'object')
244
244
  return;
245
- const escapes = cookedEscapesOf(val);
246
- if (escapes.length) {
247
- for (const d of cookedEscapeDiagnostics(val.js, escapes)) {
248
- out.push({ ...d, where: at.where, ...(at.step !== undefined ? { step: at.step } : {}) });
249
- }
245
+ if (val instanceof Expr || cookedEscapesOf(val).length) {
246
+ onExpr(val, at);
250
247
  return;
251
248
  }
252
- if (val instanceof Expr || seen.has(val))
249
+ if (seen.has(val))
253
250
  return;
254
251
  seen.add(val);
255
252
  if (Array.isArray(val)) {
@@ -278,6 +275,77 @@ export function checkCookedEscapes(built) {
278
275
  visit(v, at);
279
276
  };
280
277
  visit(built, { where: 'flow', prefix: '' });
278
+ }
279
+ /** A finding stamped with where its `Expr` sits (`visitExprs`). */
280
+ function located(d, at) {
281
+ return { ...d, where: at.where, ...(at.step !== undefined ? { step: at.step } : {}) };
282
+ }
283
+ /**
284
+ * Every `js` template escape that changed what its expression means
285
+ * (JS_ESCAPE_COOKED), each stamped with where it sits.
286
+ *
287
+ * Only `meaning` effects are reported here. An escape that breaks the parse is
288
+ * named by EXPR_SYNTAX, which the serializer refuses.
289
+ */
290
+ export function checkCookedEscapes(built) {
291
+ const out = [];
292
+ visitExprs(built, (val, at) => {
293
+ const escapes = cookedEscapesOf(val);
294
+ if (!escapes.length)
295
+ return;
296
+ for (const d of cookedEscapeDiagnostics(val.js, escapes))
297
+ out.push(located(d, at));
298
+ });
299
+ return out;
300
+ }
301
+ /**
302
+ * EXPR_VARS_ONLY_IN_QUOTES (warning, #1971): an expression whose every `$vars`
303
+ * mention sits inside a string literal, so it reads no variable and evaluates
304
+ * to the same constant on every run. For instance
305
+ * js`'"' + '$vars.start.output.topic' + '"'` is the text
306
+ * `"$vars.start.output.topic"`, not the topic: the reference was quoted.
307
+ *
308
+ * Only an expression that reads NO variable is reported (`quotedOnlyMentions`):
309
+ * `$vars.a.output + ' ($vars.b)'` and `$metadata.instanceId + ' $vars.b'` each
310
+ * read one, and a mention beside a real read may be deliberate text. A `lit(...)` is not an
311
+ * expression, and a script body (`code`) or a prompt is a plain string, so
312
+ * none of them is read here.
313
+ *
314
+ * The suggestion is the expression with each quoted whole reference unquoted
315
+ * (`'$vars.start.output.topic'` → `$vars.start.output.topic`), when every
316
+ * mention is one; a mention inside longer text (`'Hi $vars.x'`) has no
317
+ * mechanical fix, so the message points at `tmpl`.
318
+ */
319
+ export function checkVarsOnlyInQuotes(built) {
320
+ const out = [];
321
+ visitExprs(built, (val, at) => {
322
+ if (!(val instanceof Expr) || val.literal)
323
+ return;
324
+ const mentions = quotedOnlyMentions(val.js);
325
+ if (!mentions)
326
+ return;
327
+ const wholeRef = /^\$vars(?:\.[A-Za-z_$][\w$]*|\[\d+\])+$/;
328
+ // Spliced by offset, last mention first, so an earlier splice never moves a later one
329
+ // and a mention's text is never matched elsewhere in the expression.
330
+ let fixed = val.js;
331
+ for (const m of [...mentions].sort((a, b) => (b.start ?? -1) - (a.start ?? -1))) {
332
+ // A template piece has no offsets (`QuotedMention.start`): nothing to unquote in place.
333
+ if (m.start === undefined || m.end === undefined || !wholeRef.test(m.text)) {
334
+ fixed = undefined;
335
+ break;
336
+ }
337
+ fixed = fixed.slice(0, m.start) + m.text + fixed.slice(m.end);
338
+ }
339
+ const quoted = mentions.map((m) => m.literal).join(', ');
340
+ out.push(located({
341
+ level: 'warning',
342
+ code: 'EXPR_VARS_ONLY_IN_QUOTES',
343
+ message: `the expression \`${val.js.length > 120 ? `${val.js.slice(0, 117)}...` : val.js}\` mentions $vars only inside quotes (${quoted}), `
344
+ + 'so it reads no variable: the quoted text is a string constant, and the expression has the same value on every run. '
345
+ + 'Take the reference out of the quotes: js`\'"\' + ${input(\'topic\')} + \'"\'`, or tmpl`"${input(\'topic\')}"` for text around it.',
346
+ ...(fixed !== undefined ? { suggestion: fixed } : {}),
347
+ }, at));
348
+ });
281
349
  return out;
282
350
  }
283
351
  // ─── LITERAL_LOOKS_LIKE_EXPR (#1970) ────────────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.116.0",
3
+ "version": "6.117.0",
4
4
  "description": "Build UiPath Flow, Case, and BPMN artifacts by writing TypeScript.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://docs.uipath.com/maestro",
@@ -124,5 +124,5 @@
124
124
  "@types/node": "^22.7.0",
125
125
  "esbuild": "^0.28.1"
126
126
  },
127
- "gitref": "af42df6616e52079ecf678c69fdb763518cc61bf"
127
+ "gitref": "1b64d4c5c62d489c3bb736aa9a47860615d43fa0"
128
128
  }