@uipath/maestro-builder-sdk 6.86.18 → 6.86.20

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.
@@ -49,6 +49,19 @@ export interface RuleOpts {
49
49
  * "Reject") must be qualified at the source, e.g. `'Withdraw Request (Counsel)'`.
50
50
  */
51
51
  tasks?: string[];
52
+ /**
53
+ * For a `case-entered` rule: the triggers whose start of the case fires it,
54
+ * as the trigger objects passed to {@link CaseBuilder.trigger}. Omit it and
55
+ * the rule fires whichever trigger starts the case. Emitted as the rule's
56
+ * `selectedTriggerIds`; the platform lowers each listed trigger to its own
57
+ * `CaseEntered` condition naming that trigger.
58
+ *
59
+ * @example
60
+ * const web = manualTrigger({ name: 'Web form' });
61
+ * casePlan('intake').trigger(web)
62
+ * .stage('Triage', (s) => s.entryWhen(rule('case-entered', { triggers: [web] })))
63
+ */
64
+ triggers?: BuiltTrigger[];
52
65
  /**
53
66
  * For a `wait-for-connector` rule — the connector event to suspend on. Omit for
54
67
  * a placeholder (both fields default to `"placeholder"`). Emits the rule's
@@ -42,6 +42,7 @@ interface Rule {
42
42
  selectedStageId?: string;
43
43
  selectedStageIds?: string[];
44
44
  selectedTasksIds?: string[];
45
+ selectedTriggerIds?: unknown;
45
46
  conditionExpression?: string;
46
47
  uipath?: SubscriptionBag;
47
48
  slaId?: string;
@@ -118,6 +118,7 @@ function buildRefs(plan, library, diagnostics) {
118
118
  const refs = {
119
119
  stageLabelById: new Map(),
120
120
  taskNameById: new Map(),
121
+ triggerVarById: new Map(),
121
122
  slaNameById: new Map(),
122
123
  escalationNameById: new Map(),
123
124
  bindingById: new Map(),
@@ -143,6 +144,9 @@ function buildRefs(plan, library, diagnostics) {
143
144
  }
144
145
  }
145
146
  addSlaRefs(plan.metadata?.slaRules, refs, seenSlaIds);
147
+ for (const { trigger, name } of triggerConsts(plan))
148
+ if (trigger.id)
149
+ refs.triggerVarById.set(trigger.id, name);
146
150
  return refs;
147
151
  }
148
152
  /**
@@ -183,6 +187,14 @@ function variableKeys(plan) {
183
187
  }
184
188
  return keys;
185
189
  }
190
+ /**
191
+ * Each trigger node with the name of the const its decompile declares. The one
192
+ * place that names them: the declarations, `.trigger(...)` and a `case-entered`
193
+ * rule's `triggers` all read it, so they cannot drift apart.
194
+ */
195
+ function triggerConsts(plan) {
196
+ return (plan.nodes ?? []).filter(isTrigger).map((trigger, index) => ({ trigger, name: `trigger${index + 1}` }));
197
+ }
186
198
  function diagnose(refs, diagnostic) {
187
199
  if (!refs.diagnostics)
188
200
  throw new Error(diagnostic.message);
@@ -568,6 +580,21 @@ function emitRule(rule, refs) {
568
580
  });
569
581
  entries.push(['tasks', `[${names.join(', ')}]`]);
570
582
  }
583
+ if (rule.selectedTriggerIds !== undefined) {
584
+ // Only `case-entered` reads it: on any other rule it has no authored spelling.
585
+ if (rule.rule !== 'case-entered')
586
+ throw new Error(`rule "${rule.rule}" has selectedTriggerIds, which only a case-entered rule takes; remove the field.`);
587
+ const ids = rule.selectedTriggerIds;
588
+ if (!Array.isArray(ids) || !ids.every((id) => typeof id === 'string'))
589
+ throw new Error(`rule "${rule.rule}" has selectedTriggerIds that is not a list of trigger id strings.`);
590
+ const names = ids.map((id) => {
591
+ const name = refs.triggerVarById.get(id);
592
+ if (name === undefined)
593
+ throw new Error(`rule "${rule.rule}" selects unknown trigger id "${id}"; the case has no trigger with that id.`);
594
+ return name;
595
+ });
596
+ entries.push(['triggers', `[${names.join(', ')}]`]);
597
+ }
571
598
  if (rule.rule === 'wait-for-connector') {
572
599
  const connector = waitConnectorSpec(rule.uipath, `rule "${rule.rule}"`, refs);
573
600
  if (connector && connector !== '{}')
@@ -2739,6 +2766,13 @@ export function collectPreservation(plan) {
2739
2766
  fields.default = row.default;
2740
2767
  if (lane === 'outputs' && row.var !== undefined)
2741
2768
  fields.var = row.var;
2769
+ // `body` is typed only on a structured (`jsonSchema`) variable. On any
2770
+ // other row it is the schema the Designer generated for the type (for a
2771
+ // `file`, the job attachment's `{ ID, FullName, MimeType, Metadata }`),
2772
+ // which compile does not write, so it is carried verbatim, with the type
2773
+ // it describes (`bodyType`): compile drops it once the type changes.
2774
+ if (row.type !== 'jsonSchema' && row.body !== undefined)
2775
+ Object.assign(fields, { body: row.body, bodyType: row.type });
2742
2776
  if (Object.keys(fields).length)
2743
2777
  byName[row.name] = fields;
2744
2778
  if (row.default !== undefined && typeof row.default !== 'string')
@@ -2786,14 +2820,11 @@ export function decompileWithDiagnostics(plan, options = {}) {
2786
2820
  const refs = buildRefs(plan, options.library, options.bestEffort ? diagnostics : undefined);
2787
2821
  const selectNextStage = selectNextStageByExit(plan, refs);
2788
2822
  const metadata = plan.metadata ?? {};
2789
- const triggers = (plan.nodes ?? []).filter(isTrigger);
2790
- const triggerNameById = new Map();
2823
+ const consts = triggerConsts(plan);
2824
+ const triggers = consts.map(({ trigger }) => trigger);
2791
2825
  const out = new Emit();
2792
- triggers.forEach((trigger, index) => {
2793
- const variableName = `trigger${index + 1}`;
2794
- if (trigger.id)
2795
- triggerNameById.set(trigger.id, variableName);
2796
- out.line(0, `const ${variableName} = ${triggerSource(trigger, index, plan, refs)};`);
2826
+ consts.forEach(({ trigger, name }, index) => {
2827
+ out.line(0, `const ${name} = ${triggerSource(trigger, index, plan, refs)};`);
2797
2828
  });
2798
2829
  if (triggers.length)
2799
2830
  out.line(0, '');
@@ -2834,8 +2865,9 @@ export function decompileWithDiagnostics(plan, options = {}) {
2834
2865
  throw new Error('allowAdhocOptionalStageTasks must be boolean.');
2835
2866
  chain.line(depth, metadata.allowAdhocOptionalStageTasks ? '.allowAdhocTasks()' : '.allowAdhocTasks(false)');
2836
2867
  }
2837
- emitVariables(chain, depth, plan, triggerNameById, triggers.map(isTimerTrigger));
2838
- triggers.forEach((_trigger, index) => chain.line(depth, `.trigger(trigger${index + 1})`));
2868
+ emitVariables(chain, depth, plan, refs.triggerVarById, triggers.map(isTimerTrigger));
2869
+ for (const { name } of consts)
2870
+ chain.line(depth, `.trigger(${name})`);
2839
2871
  (metadata.slaRules ?? []).forEach((sla, index) => chain.line(depth, `.sla(${slaSource(sla, index)})`));
2840
2872
  for (const event of metadata.businessEvents ?? [])
2841
2873
  chain.line(depth, businessEventSource(event));
@@ -276,17 +276,23 @@ export function caseJsonPreservationErrors(payload) {
276
276
  errors.push(`variable lane "${lane}" is not recognized`);
277
277
  continue;
278
278
  }
279
+ // A carried `body` names the non-structured type it was saved for.
280
+ for (const [name, fields] of Object.entries(rows ?? {}))
281
+ if (fields.body !== undefined && (typeof fields.bodyType !== 'string' || fields.bodyType === 'jsonSchema'))
282
+ errors.push(`variable "${name}" carried body needs the non-jsonSchema type it was saved for (bodyType)`);
279
283
  for (const [name, fields] of Object.entries(rows ?? {}))
280
284
  for (const field of Object.keys(fields))
281
285
  if (lane === 'inputOutputs' && field === 'value')
282
286
  errors.push(`variable "${name}" field "value" on inputOutputs is behavior (a process mapping's var) and cannot be preserved`);
283
287
  else if (!PRESERVED_VARIABLE_KEYS.has(field)
284
288
  && !(lane === 'inputOutputs' && (field === 'default' || field === 'custom'))
285
- && !(lane === 'outputs' && field === 'var'))
289
+ && !(lane === 'outputs' && field === 'var')
290
+ && field !== 'body' && field !== 'bodyType')
286
291
  errors.push(`variable "${name}" field "${field}" is not an allowed preserved designer field`);
287
292
  else if (VARIABLE_KEYS.has(field)
288
293
  && !(lane === 'inputOutputs' && field === 'default')
289
- && !(lane === 'outputs' && field === 'var'))
294
+ && !(lane === 'outputs' && field === 'var')
295
+ && field !== 'body')
290
296
  errors.push(`variable "${name}" field "${field}" is owned by the typed Case serializer`);
291
297
  }
292
298
  for (const lane of payload.variableLanes ?? [])
@@ -9,7 +9,7 @@ export const ANY_ESCALATION_ID = 'any';
9
9
  /** `expression` is a gate any rule can carry. */
10
10
  const COMMON = ['expression'];
11
11
  const RULE_OPTIONS = {
12
- 'case-entered': [],
12
+ 'case-entered': ['triggers'],
13
13
  'required-tasks-completed': [],
14
14
  'required-stages-completed': [],
15
15
  'selected-stage-completed': ['stage', 'stages'],
@@ -228,6 +228,7 @@ function serializeCase(built, opts) {
228
228
  escalationId: new Map(),
229
229
  escalationIdByName: new Map(),
230
230
  businessEvents: new Set((built.businessEvents ?? []).map((event) => event.name)),
231
+ triggerIdByRef: new Map(),
231
232
  conditionName: conditionNamer(built),
232
233
  elementSeededIds: [],
233
234
  subscriptions: [],
@@ -293,6 +294,7 @@ function serializeCase(built, opts) {
293
294
  // trigger-bound In-arg can resolve `{ from }` to the node it wires onto.
294
295
  const triggerNodeByRef = new Map();
295
296
  built.triggers.forEach((t, i) => triggerNodeByRef.set(t, triggerNodes[i]));
297
+ built.triggers.forEach((t, i) => resolver.triggerIdByRef.set(t, triggerNodes[i].id));
296
298
  built.stages.forEach((stage, si) => {
297
299
  nodes.push(emitStage(stage, stageLanes[si], si, stageIds[si], taskIds[si], ids, resolver));
298
300
  });
@@ -629,8 +631,16 @@ export function applyPreservation(result, preservation, options = {}) {
629
631
  if (!row)
630
632
  throw new CompileRefusal('PRESERVATION_TARGET_MISSING', `preserved variable "${name}" was not regenerated in variables.${lane}.`);
631
633
  for (const [field, value] of Object.entries(fields)) {
634
+ // `bodyType` is the type a carried `body` was saved for, not a field.
635
+ if (field === 'bodyType')
636
+ continue;
632
637
  if (row[field] === value)
633
638
  continue;
639
+ // A carried `body` describes the type it was saved with. A variable the
640
+ // edit gave another type (a `string`, or a `jsonSchema` with the schema
641
+ // the author typed) does not get it.
642
+ if (field === 'body' && row.type !== fields.bodyType)
643
+ continue;
634
644
  if (!options.overwrite && Object.prototype.hasOwnProperty.call(row, field))
635
645
  throw new CompileRefusal('PRESERVATION_FIELD_COLLISION', `preserved variable "${name}" field "${field}" collides with serializer-owned output.`);
636
646
  row[field] = value;
@@ -1605,7 +1615,7 @@ function applyPreservedIdentities(result, preservation) {
1605
1615
  // then renamed to its designer id, and the exit points at nothing. Silently:
1606
1616
  // `case check` says OK and `uip maestro case validate` reports nothing about it.
1607
1617
  const referenceFields = new Set([
1608
- 'elementId', 'exitToStageId', 'selectedStageId', 'selectedStageIds', 'selectedTasksIds',
1618
+ 'elementId', 'exitToStageId', 'selectedStageId', 'selectedStageIds', 'selectedTasksIds', 'selectedTriggerIds',
1609
1619
  'slaId', 'escalationId', 'originalVar', 'var', 'source', 'target',
1610
1620
  ]);
1611
1621
  const preservedOutputSources = [];
@@ -3418,6 +3428,15 @@ function emitRule(r, seed, ownerId, ids, resolver, site) {
3418
3428
  return tid;
3419
3429
  });
3420
3430
  }
3431
+ if (r.rule === 'case-entered' && r.triggers !== undefined) {
3432
+ // Absent means any trigger; a list narrows the rule to those triggers.
3433
+ out.selectedTriggerIds = r.triggers.map((t, i) => {
3434
+ const id = resolver.triggerIdByRef.get(t);
3435
+ if (!id)
3436
+ throw new CompileRefusal('UNKNOWN_TRIGGER_REF', `rule "case-entered" in ${site} lists trigger #${i + 1}${t && typeof t === 'object' && t.name ? ` ("${t.name}")` : ''}, which the case does not declare — pass the object you gave .trigger(...).`);
3437
+ return id;
3438
+ });
3439
+ }
3421
3440
  if (r.rule === 'wait-for-connector') {
3422
3441
  // A rule always carries the subscription under `uipath` (placeholder-safe).
3423
3442
  out[CASE_FORMAT_PROFILE.waitConnectorRuleBagField] = waitConnectorBag(r.connector, { alwaysContext: true }, resolver, `${ownerId}-${ruleId}`, `wait-for-connector rule in ${site}`);
@@ -757,6 +757,7 @@ export declare const REFUSALS: {
757
757
  readonly UNKNOWN_SLA_REF: "lowering";
758
758
  readonly UNKNOWN_STAGE_REF: "lowering";
759
759
  readonly UNKNOWN_TASK_REF: "lowering";
760
+ readonly UNKNOWN_TRIGGER_REF: "lowering";
760
761
  readonly UPDATES_NOT_SUPPORTED: "lowering";
761
762
  readonly UPDATE_INPUT_READONLY: "lint";
762
763
  readonly UPDATE_UNKNOWN_VAR: "lint";
@@ -830,6 +830,7 @@ export const REFUSALS = {
830
830
  UNKNOWN_SLA_REF: 'lowering',
831
831
  UNKNOWN_STAGE_REF: 'lowering',
832
832
  UNKNOWN_TASK_REF: 'lowering',
833
+ UNKNOWN_TRIGGER_REF: 'lowering',
833
834
  UPDATES_NOT_SUPPORTED: 'lowering',
834
835
  UPDATE_INPUT_READONLY: 'lint',
835
836
  UPDATE_UNKNOWN_VAR: 'lint',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.86.18",
3
+ "version": "6.86.20",
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",
@@ -103,5 +103,5 @@
103
103
  "@types/node": "^22.7.0",
104
104
  "esbuild": "^0.28.1"
105
105
  },
106
- "gitref": "084694cb55926a5d346d171315535674674b19fa"
106
+ "gitref": "e802da118b3c4f36c932a0e15950c80cf88b7c14"
107
107
  }