@uipath/maestro-builder-sdk 6.79.1 → 6.81.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.
@@ -38,6 +38,8 @@ import { CompileRefusal } from '../core/compile-refusal.js';
38
38
  import { implicitInArgBuiltTrigger, unboundInArgMessage } from './in-arg-binding.js';
39
39
  import { jsonClone } from '../core/json-clone.js';
40
40
  import { taskShapeProblems } from './task-shape.js';
41
+ import { SCRIPT_INPUTS, scriptOutputMappings, scriptOutputs, storedScript } from './script.js';
42
+ import { HTTP_REQUEST_CONNECTION_NAME, HTTP_REQUEST_IMPLICIT_BINDING_ID, HTTP_REQUEST_IMPLICIT_CONNECTION, HTTP_REQUEST_SERVICE_TYPE, httpRequestBody, httpRequestContext, httpRequestInputs, httpRequestOutputMappings, httpRequestOutputs, httpRequestRefusal, writeHttpRequestMetadata, } from './http-request.js';
41
43
  import { connectorPlaceholderData, isConnectorPlaceholder } from './connector-placeholder.js';
42
44
  import { lowerTaskOutputRefs, planTaskOutputs, resolveInPlan, unresolvedTaskOutputRef } from './task-output-ref.js';
43
45
  /** The ids a serialize pass hashed from element ids, by the document it returned. */
@@ -215,6 +217,7 @@ function serializeCase(built, opts) {
215
217
  ownNameRows: new Map(),
216
218
  outputIds: new Set(),
217
219
  ownOutputVars: ownOutputVars(built),
220
+ caseVarNames: new Set([...built.vars.map((v) => v.name), ...mappedFixedOutputVars(built)]),
218
221
  slaId: new Map(),
219
222
  slaIdByName: new Map(),
220
223
  escalationId: new Map(),
@@ -709,6 +712,16 @@ export function applyPreservation(result, preservation, options = {}) {
709
712
  if (written === 'different' && !options.overwrite)
710
713
  throw new CompileRefusal('PRESERVATION_FIELD_COLLISION', `preserved connector configuration of task "${entry.stage}/${entry.task}" collides with serializer-owned output.`);
711
714
  }
715
+ for (const entry of preservation.httpRequestMetadata ?? []) {
716
+ const stage = stageNodes.find((candidate) => candidate.data?.label === entry.stage);
717
+ const task = stageTask(stage, entry.task);
718
+ // A deleted task, or one the edit made another kind, gets nothing: the
719
+ // saved metadata describes the HTTP request activity only. The vendored
720
+ // copy compile wrote is not authored, so replacing it is no collision.
721
+ if (!task || task.type !== 'http-request')
722
+ continue;
723
+ writeHttpRequestMetadata(task.data, entry.metadata);
724
+ }
712
725
  for (const entry of preservation.actionDataFields ?? []) {
713
726
  const stage = stageNodes.find((candidate) => candidate.data?.label === entry.stage);
714
727
  const task = stageTask(stage, entry.task);
@@ -1098,6 +1111,7 @@ export function followRenames(result, preservation) {
1098
1111
  },
1099
1112
  ...(preservation.taskFields ? { taskFields: preservation.taskFields.map(ref) } : {}),
1100
1113
  ...(preservation.connectorConfigurations ? { connectorConfigurations: preservation.connectorConfigurations.map(ref) } : {}),
1114
+ ...(preservation.httpRequestMetadata ? { httpRequestMetadata: preservation.httpRequestMetadata.map(ref) } : {}),
1101
1115
  ...(preservation.actionDataFields ? { actionDataFields: preservation.actionDataFields.map(ref) } : {}),
1102
1116
  ...(preservation.omitTaskElementIds ? { omitTaskElementIds: preservation.omitTaskElementIds.map(ref) } : {}),
1103
1117
  ...(preservation.omitStagePositions ? { omitStagePositions: preservation.omitStagePositions.map(stageName) } : {}),
@@ -2051,6 +2065,12 @@ function taskData(task, resolver, taskId, stageId, ids) {
2051
2065
  : {};
2052
2066
  return withCustomOutputs(data, task, resolver);
2053
2067
  }
2068
+ case 'script':
2069
+ // Only `{ assign }` rows are written beside the two: a mapped row is one of them.
2070
+ return withCustomOutputs(scriptTaskData(task, resolver, `${stageId}-${taskId}`), { ...task, outputs: task.outputs?.filter((o) => o.custom) }, resolver);
2071
+ case 'http-request':
2072
+ // Only `{ assign }` rows are written beside the four: a mapped row is one of them.
2073
+ return withCustomOutputs(httpRequestTaskData(task, resolver, `${stageId}-${taskId}`), { ...task, outputs: task.outputs?.filter((o) => o.custom) }, resolver);
2054
2074
  case 'wait-for-connector':
2055
2075
  // A placeholder returned `{}` above; naming the connector/operation emits
2056
2076
  // the `context` subscription, and a resolved one the full bag.
@@ -2717,6 +2737,108 @@ function externalTaskData(kind, spec, resolver, elementId, where) {
2717
2737
  context.push(io('activityConfigurationVersion', 'string', { value: 'v2' }));
2718
2738
  return { ...data, serviceType: externalServiceType(kind, mode) };
2719
2739
  }
2740
+ /**
2741
+ * A script task (`case/script.ts`): the body behind the Designer's leading `=`,
2742
+ * its two inputs, and its two outputs, each claimed like any task output's and
2743
+ * kept off the case's own variable names (an output's `var` is its id).
2744
+ */
2745
+ function scriptTaskData(task, resolver, elementId) {
2746
+ const where = `Script task "${task.name}"`;
2747
+ const spec = task.script;
2748
+ if (!spec)
2749
+ throw new Error(`internal SDK error: ${where} has no body.`);
2750
+ const mappings = scriptOutputMappings(where, task.outputs);
2751
+ if (!(mappings instanceof Map))
2752
+ throw new CompileRefusal(mappings.code, mappings.message, mappings.suggestion);
2753
+ const claim = (base) => {
2754
+ let id = claimOutputId(resolver, base);
2755
+ while (resolver.caseVarNames.has(id))
2756
+ id = claimOutputId(resolver, base);
2757
+ return id;
2758
+ };
2759
+ registerMappedCompanions(resolver, mappings);
2760
+ return {
2761
+ script: storedScript(spec.body),
2762
+ inputs: SCRIPT_INPUTS.map((row) => ({ ...row })),
2763
+ outputs: scriptOutputs(elementId, claim, mappings, spec),
2764
+ };
2765
+ }
2766
+ /**
2767
+ * A mapped output writes a case variable the source may not declare. Its row
2768
+ * is reassigned (`var` is not its id), so like a connector extract's it needs a
2769
+ * root entry for `=vars.<name>` to read; a declared `.var()` wins the name.
2770
+ */
2771
+ function registerMappedCompanions(resolver, mappings) {
2772
+ for (const variable of mappings.values())
2773
+ if (!resolver.varCompanions.has(variable))
2774
+ resolver.varCompanions.set(variable, { id: variable, name: variable, type: 'object', elementId: 'root', custom: true });
2775
+ }
2776
+ /**
2777
+ * An HTTP request task (`case/http-request.ts`): the generic HTTP connector's
2778
+ * activity, with the request in the `body` input. A manual request names the
2779
+ * plan's one `ImplicitConnection` binding; a connector request binds the
2780
+ * connection and its folder the way a connector task does (`bindingRef`,
2781
+ * `folderBindingRef`), and carries those two rows on the task too, as the
2782
+ * Designer saves it.
2783
+ */
2784
+ function httpRequestTaskData(task, resolver, elementId) {
2785
+ const where = `HTTP request task "${task.name}"`;
2786
+ const spec = task.http;
2787
+ if (!spec)
2788
+ throw new Error(`internal SDK error: ${where} has no request.`);
2789
+ const refused = httpRequestRefusal(where, spec);
2790
+ if (refused)
2791
+ throw new CompileRefusal(refused.code, refused.message, refused.suggestion);
2792
+ const mappings = httpRequestOutputMappings(where, task.outputs);
2793
+ if (!(mappings instanceof Map))
2794
+ throw new CompileRefusal(mappings.code, mappings.message, mappings.suggestion);
2795
+ registerMappedCompanions(resolver, mappings);
2796
+ let connection;
2797
+ let resourceKey = null;
2798
+ let folderKey = null;
2799
+ const bindings = [];
2800
+ if (spec.connector) {
2801
+ const target = { key: spec.connector.key };
2802
+ refuseBindingLabels(resolver, spec.connector, { where, target });
2803
+ const connRef = bindingRef(resolver, spec.connector.connection, 'Connection', 'ConnectionId', HTTP_REQUEST_CONNECTION_NAME, { attribute: 'connection', where, target });
2804
+ const folderRef = folderBindingRef(resolver, spec.connector.folder, connRef, { attribute: 'folder', where, target });
2805
+ if (!connRef || !folderRef)
2806
+ throw new Error(`internal SDK error: ${where} bound no connection or folder.`);
2807
+ connection = `=bindings.${connRef.id}`;
2808
+ resourceKey = connRef.resourceKey;
2809
+ folderKey = `=bindings.${folderRef.id}`;
2810
+ for (const id of [connRef.id, folderRef.id])
2811
+ bindings.push(jsonClone(resolver.bindingSink.get(id)));
2812
+ }
2813
+ else {
2814
+ if (!resolver.bindingSink.has(HTTP_REQUEST_IMPLICIT_BINDING_ID))
2815
+ resolver.bindingSink.set(HTTP_REQUEST_IMPLICIT_BINDING_ID, {
2816
+ id: HTTP_REQUEST_IMPLICIT_BINDING_ID,
2817
+ name: HTTP_REQUEST_CONNECTION_NAME,
2818
+ type: 'string',
2819
+ resource: 'Connection',
2820
+ resourceKey: HTTP_REQUEST_IMPLICIT_CONNECTION,
2821
+ default: HTTP_REQUEST_IMPLICIT_CONNECTION,
2822
+ propertyAttribute: 'ConnectionId',
2823
+ });
2824
+ connection = `=bindings.${HTTP_REQUEST_IMPLICIT_BINDING_ID}`;
2825
+ }
2826
+ return {
2827
+ serviceType: HTTP_REQUEST_SERVICE_TYPE,
2828
+ // The container ids follow `ioSlot`, every connector task's.
2829
+ inputs: httpRequestInputs(elementId, (name) => `v${name}`, httpRequestBody(spec)),
2830
+ // An output's `var` is its id, so an id a case variable has would point the
2831
+ // response at that variable: `code`, `code2`, … skip them, as convert does.
2832
+ outputs: httpRequestOutputs(elementId, (base) => {
2833
+ let id = claimOutputId(resolver, base);
2834
+ while (resolver.caseVarNames.has(id))
2835
+ id = claimOutputId(resolver, base);
2836
+ return id;
2837
+ }, mappings),
2838
+ context: httpRequestContext(connection, resourceKey, folderKey),
2839
+ bindings,
2840
+ };
2841
+ }
2720
2842
  /** A context/output name/value entry (the caseplan `InputOutput` shape). */
2721
2843
  function io(name, type, extra) {
2722
2844
  return { name, type, ...extra };
@@ -3023,6 +3145,30 @@ function isOwnNameOutput(o) {
3023
3145
  const field = o.source.replace(/^=/, '').split('.').pop() ?? '';
3024
3146
  return keepsOwnName(o.var, field);
3025
3147
  }
3148
+ /**
3149
+ * The task kinds whose output rows are fixed (the task writes its own rows and
3150
+ * a `.outputs()` mapping reassigns one to a case variable), so a mapped
3151
+ * variable must be reserved before any row id is claimed.
3152
+ */
3153
+ const FIXED_OUTPUT_KINDS = new Set(['http-request', 'script']);
3154
+ /**
3155
+ * The case variables a fixed-output task's `.outputs()` maps, declared or not.
3156
+ * Collected before any task is emitted, so no task's own output row takes one
3157
+ * of them as its id, whatever the task order: an undeclared one gets a root
3158
+ * companion, and a row id equal to it would make two writers of one variable,
3159
+ * or read back as unmapped.
3160
+ */
3161
+ function mappedFixedOutputVars(built) {
3162
+ const vars = new Set();
3163
+ for (const stage of built.stages)
3164
+ for (const lane of stage.lanes)
3165
+ for (const task of lane)
3166
+ if (FIXED_OUTPUT_KINDS.has(task.kind))
3167
+ for (const o of task.outputs ?? [])
3168
+ if (!o.custom)
3169
+ vars.add(o.var);
3170
+ return vars;
3171
+ }
3026
3172
  /**
3027
3173
  * Every variable a task in the plan writes under its own name: own-name task
3028
3174
  * outputs and action form outputs (whose row id is the variable). Collected
@@ -160,6 +160,18 @@ export declare const REFUSALS: {
160
160
  readonly CASE_IN_ARG_UNBOUND: "lowering";
161
161
  readonly CASE_LAYOUT_NODE_MATCH: "lowering";
162
162
  readonly CASE_LAYOUT_UNKNOWN_FIELD: "lowering";
163
+ readonly SCRIPT_BODY_SYNTAX: "lint";
164
+ readonly SCRIPT_OUTPUT: "lowering";
165
+ readonly HTTP_REQUEST_CONNECTOR: "lowering";
166
+ readonly HTTP_REQUEST_TARGET: "lowering";
167
+ readonly HTTP_REQUEST_FIELD: "lowering";
168
+ readonly HTTP_REQUEST_OUTPUT: "lowering";
169
+ readonly HTTP_REQUEST_BODY_FORM: "lowering";
170
+ readonly HTTP_REQUEST_BODY_EXPRESSION: "lowering";
171
+ readonly HTTP_REQUEST_METHOD: "lint";
172
+ readonly HTTP_REQUEST_NO_URL: "lint";
173
+ readonly HTTP_REQUEST_CREDENTIAL_HEADER: "lint";
174
+ readonly HTTP_REQUEST_BODY_METHOD: "lint";
163
175
  readonly RULE_SELECTS_ADHOC_TASK: "lint";
164
176
  readonly SELECTED_STAGE_EXITED_NO_EXIT: "lint";
165
177
  readonly SLA_RESPONSE_REENTERS_STAGE: "lint";
@@ -209,6 +209,24 @@ export const REFUSALS = {
209
209
  CASE_IN_ARG_UNBOUND: 'lowering',
210
210
  CASE_LAYOUT_NODE_MATCH: 'lowering',
211
211
  CASE_LAYOUT_UNKNOWN_FIELD: 'lowering',
212
+ // Case script task (case/script.ts). A string body that does not parse is
213
+ // written as authored (`lint`); an output other than the two has no row to
214
+ // write it to (`lowering`).
215
+ SCRIPT_BODY_SYNTAX: 'lint',
216
+ SCRIPT_OUTPUT: 'lowering',
217
+ // Case http-request task (case/http-request.ts). `lowering`: compile would
218
+ // drop or rewrite what the source says. `lint`: compile writes it as
219
+ // authored, and only `check` reports it.
220
+ HTTP_REQUEST_CONNECTOR: 'lowering',
221
+ HTTP_REQUEST_TARGET: 'lowering',
222
+ HTTP_REQUEST_FIELD: 'lowering',
223
+ HTTP_REQUEST_OUTPUT: 'lowering',
224
+ HTTP_REQUEST_BODY_FORM: 'lowering',
225
+ HTTP_REQUEST_BODY_EXPRESSION: 'lowering',
226
+ HTTP_REQUEST_METHOD: 'lint',
227
+ HTTP_REQUEST_NO_URL: 'lint',
228
+ HTTP_REQUEST_CREDENTIAL_HEADER: 'lint',
229
+ HTTP_REQUEST_BODY_METHOD: 'lint',
212
230
  // Case check: what a condition's references mean (case/check-rule-semantics.ts).
213
231
  RULE_SELECTS_ADHOC_TASK: 'lint',
214
232
  SELECTED_STAGE_EXITED_NO_EXIT: 'lint',
@@ -0,0 +1,34 @@
1
+ /**
2
+ * core/script-engine — what the engine gives a script body, whichever family
3
+ * wrote the task: a Flow script node and a Case script task both run on
4
+ * UiPath/PO.BpmnEngine's script service, Jint 4.4.0
5
+ * (`ScriptTaskService.InvokeScriptAsync`,
6
+ * `src/BpmnEngine/UiPath.PO.Worker/Services/ElementExecution/Script/ScriptTaskService.cs`).
7
+ * Each family's `ScriptRuntime` (`core/script-function.ts`) names its own scope
8
+ * globals and takes these facts from here, so the two lists cannot drift.
9
+ * Moved from `nodes/script/flow/runtime.ts`, where the measurements are
10
+ * described; change them when the engine does.
11
+ */
12
+ /**
13
+ * The names the engine's preludes declare with `const` before the script runs
14
+ * (`ScriptTaskService.cs`, `WithBuiltInFunctions` and `WithConsole`). At the
15
+ * body's top level, a `const`, `let`, `var`, `function` or `class` of one fails
16
+ * with "Identifier '…' has already been declared", and an assignment to one with
17
+ * "Assignment to constant variable." (both measured on Jint 4.4.0). Inside a
18
+ * nested block or function the name is the author's own and is fine.
19
+ */
20
+ export declare const SCRIPT_ENGINE_CONST_GLOBALS: ReadonlySet<string>;
21
+ /**
22
+ * The members the engine's own objects have; any other member reads
23
+ * `undefined`, so calling it throws "Property '…' of object is not a function"
24
+ * (measured on Jint 4.4.0). `crypto` holds only `randomUUID`
25
+ * (`JavaScriptEvaluator.cs`), and `console` only the five no-ops `WithConsole`
26
+ * declares (`ScriptTaskService.cs`).
27
+ */
28
+ export declare const SCRIPT_ENGINE_GLOBAL_MEMBERS: ReadonlyMap<string, ReadonlySet<string>>;
29
+ /**
30
+ * Every global a script body can read besides its family's scope globals: the
31
+ * language's ES2020 built-ins, the globals the engine registers (`btoa`,
32
+ * `atob`, `randomUUID`, `crypto`), and `console`.
33
+ */
34
+ export declare const SCRIPT_ENGINE_GLOBALS: ReadonlySet<string>;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * core/script-engine — what the engine gives a script body, whichever family
3
+ * wrote the task: a Flow script node and a Case script task both run on
4
+ * UiPath/PO.BpmnEngine's script service, Jint 4.4.0
5
+ * (`ScriptTaskService.InvokeScriptAsync`,
6
+ * `src/BpmnEngine/UiPath.PO.Worker/Services/ElementExecution/Script/ScriptTaskService.cs`).
7
+ * Each family's `ScriptRuntime` (`core/script-function.ts`) names its own scope
8
+ * globals and takes these facts from here, so the two lists cannot drift.
9
+ * Moved from `nodes/script/flow/runtime.ts`, where the measurements are
10
+ * described; change them when the engine does.
11
+ */
12
+ /**
13
+ * The names the engine's preludes declare with `const` before the script runs
14
+ * (`ScriptTaskService.cs`, `WithBuiltInFunctions` and `WithConsole`). At the
15
+ * body's top level, a `const`, `let`, `var`, `function` or `class` of one fails
16
+ * with "Identifier '…' has already been declared", and an assignment to one with
17
+ * "Assignment to constant variable." (both measured on Jint 4.4.0). Inside a
18
+ * nested block or function the name is the author's own and is fine.
19
+ */
20
+ export const SCRIPT_ENGINE_CONST_GLOBALS = new Set(['console', 'uipath', 'aggregate', '_aggregate', '_pipe']);
21
+ /**
22
+ * The members the engine's own objects have; any other member reads
23
+ * `undefined`, so calling it throws "Property '…' of object is not a function"
24
+ * (measured on Jint 4.4.0). `crypto` holds only `randomUUID`
25
+ * (`JavaScriptEvaluator.cs`), and `console` only the five no-ops `WithConsole`
26
+ * declares (`ScriptTaskService.cs`).
27
+ */
28
+ export const SCRIPT_ENGINE_GLOBAL_MEMBERS = new Map([
29
+ ['crypto', new Set(['randomUUID'])],
30
+ ['console', new Set(['debug', 'error', 'info', 'log', 'warn'])],
31
+ ]);
32
+ /**
33
+ * Every global a script body can read besides its family's scope globals: the
34
+ * language's ES2020 built-ins, the globals the engine registers (`btoa`,
35
+ * `atob`, `randomUUID`, `crypto`), and `console`.
36
+ */
37
+ export const SCRIPT_ENGINE_GLOBALS = new Set([
38
+ 'undefined', 'NaN', 'Infinity', 'globalThis', 'console',
39
+ 'btoa', 'atob', 'randomUUID', 'crypto',
40
+ 'Object', 'Function', 'Array', 'Number', 'Boolean', 'String', 'Symbol', 'BigInt', 'Date', 'RegExp', 'Math', 'JSON',
41
+ 'Promise', 'Proxy', 'Reflect', 'Map', 'Set', 'WeakMap', 'WeakSet',
42
+ 'Error', 'EvalError', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError',
43
+ 'ArrayBuffer', 'SharedArrayBuffer', 'DataView', 'Atomics',
44
+ 'Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array', 'Int32Array', 'Uint32Array',
45
+ 'Float32Array', 'Float64Array', 'BigInt64Array', 'BigUint64Array',
46
+ 'parseInt', 'parseFloat', 'isNaN', 'isFinite',
47
+ 'encodeURI', 'encodeURIComponent', 'decodeURI', 'decodeURIComponent', 'eval',
48
+ ]);
@@ -20,7 +20,7 @@ import type { ScriptRuntime } from '../../../core/script-function.js';
20
20
  * the body goes to `Engine.Evaluate` as a script, after `btoa`/`atob` (UTF-8),
21
21
  * `randomUUID` and `crypto` (holding only `randomUUID`) are set
22
22
  * (`src/BpmnEngine/UiPath.PO.BpmnEngine/Expressions/JavaScriptEvaluator.cs`) and
23
- * two preludes declare {@link FLOW_SCRIPT_CONST_GLOBALS} with `const`. `Intl`,
23
+ * two preludes declare {@link SCRIPT_ENGINE_CONST_GLOBALS} with `const`. `Intl`,
24
24
  * `URL`, `TextEncoder`, `Buffer`, `fetch`, `require` and `structuredClone` read
25
25
  * `undefined` there, so they are absent here. Change this when the engine does.
26
26
  *
@@ -1,23 +1,4 @@
1
- /**
2
- * The names the engine's preludes declare with `const` before the script runs
3
- * (`ScriptTaskService.cs`, `WithBuiltInFunctions` and `WithConsole`). At the
4
- * body's top level, a `const`, `let`, `var`, `function` or `class` of one fails
5
- * with "Identifier '…' has already been declared", and an assignment to one with
6
- * "Assignment to constant variable." (both measured on Jint 4.4.0). Inside a
7
- * nested block or function the name is the author's own and is fine.
8
- */
9
- const FLOW_SCRIPT_CONST_GLOBALS = new Set(['console', 'uipath', 'aggregate', '_aggregate', '_pipe']);
10
- /**
11
- * The members the engine's own objects have; any other member reads
12
- * `undefined`, so calling it throws "Property '…' of object is not a function"
13
- * (measured on Jint 4.4.0). `crypto` holds only `randomUUID`
14
- * (`JavaScriptEvaluator.cs`), and `console` only the five no-ops `WithConsole`
15
- * declares (`ScriptTaskService.cs`).
16
- */
17
- const FLOW_SCRIPT_GLOBAL_MEMBERS = new Map([
18
- ['crypto', new Set(['randomUUID'])],
19
- ['console', new Set(['debug', 'error', 'info', 'log', 'warn'])],
20
- ]);
1
+ import { SCRIPT_ENGINE_CONST_GLOBALS, SCRIPT_ENGINE_GLOBAL_MEMBERS, SCRIPT_ENGINE_GLOBALS } from '../../../core/script-engine.js';
21
2
  /**
22
3
  * What a Flow script body can read: the language's ES2020 built-ins, the
23
4
  * globals the engine registers, `console`, and the runtime's `$vars` and
@@ -35,7 +16,7 @@ const FLOW_SCRIPT_GLOBAL_MEMBERS = new Map([
35
16
  * the body goes to `Engine.Evaluate` as a script, after `btoa`/`atob` (UTF-8),
36
17
  * `randomUUID` and `crypto` (holding only `randomUUID`) are set
37
18
  * (`src/BpmnEngine/UiPath.PO.BpmnEngine/Expressions/JavaScriptEvaluator.cs`) and
38
- * two preludes declare {@link FLOW_SCRIPT_CONST_GLOBALS} with `const`. `Intl`,
19
+ * two preludes declare {@link SCRIPT_ENGINE_CONST_GLOBALS} with `const`. `Intl`,
39
20
  * `URL`, `TextEncoder`, `Buffer`, `fetch`, `require` and `structuredClone` read
40
21
  * `undefined` there, so they are absent here. Change this when the engine does.
41
22
  *
@@ -63,18 +44,7 @@ export const FLOW_SCRIPT_RUNTIME = {
63
44
  },
64
45
  ],
65
46
  name: 'the Flow script runtime',
66
- constGlobals: FLOW_SCRIPT_CONST_GLOBALS,
67
- globalMembers: FLOW_SCRIPT_GLOBAL_MEMBERS,
68
- globals: new Set([
69
- 'undefined', 'NaN', 'Infinity', 'globalThis', 'console',
70
- 'btoa', 'atob', 'randomUUID', 'crypto',
71
- 'Object', 'Function', 'Array', 'Number', 'Boolean', 'String', 'Symbol', 'BigInt', 'Date', 'RegExp', 'Math', 'JSON',
72
- 'Promise', 'Proxy', 'Reflect', 'Map', 'Set', 'WeakMap', 'WeakSet',
73
- 'Error', 'EvalError', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError',
74
- 'ArrayBuffer', 'SharedArrayBuffer', 'DataView', 'Atomics',
75
- 'Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array', 'Int32Array', 'Uint32Array',
76
- 'Float32Array', 'Float64Array', 'BigInt64Array', 'BigUint64Array',
77
- 'parseInt', 'parseFloat', 'isNaN', 'isFinite',
78
- 'encodeURI', 'encodeURIComponent', 'decodeURI', 'decodeURIComponent', 'eval',
79
- ]),
47
+ constGlobals: SCRIPT_ENGINE_CONST_GLOBALS,
48
+ globalMembers: SCRIPT_ENGINE_GLOBAL_MEMBERS,
49
+ globals: SCRIPT_ENGINE_GLOBALS,
80
50
  };
@@ -1,5 +1,7 @@
1
1
  import { relative } from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
2
3
  import { typescript } from './core/typescript-module.js';
4
+ import { isSdkSpecifier } from './sdk-resolve-hook.js';
3
5
  import { isReference } from './core/script-function.js';
4
6
  /**
5
7
  * Every name a `script(fn)` function in `file` (or a file it imports) reads from
@@ -18,7 +20,7 @@ export function scriptFunctionScope(file) {
18
20
  noLib: true, types: [], noEmit: true, skipLibCheck: true, allowImportingTsExtensions: true,
19
21
  target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.NodeNext, moduleResolution: ts.ModuleResolutionKind.NodeNext,
20
22
  };
21
- const program = ts.createProgram([file], options);
23
+ const program = ts.createProgram([file], options, sdkResolvingHost(ts, options));
22
24
  const checker = program.getTypeChecker();
23
25
  const cwd = process.cwd();
24
26
  const where = (n) => {
@@ -61,6 +63,25 @@ export function scriptFunctionScope(file) {
61
63
  }
62
64
  return { captures: out, unfollowed, untyped, followed: seen.size, followedTexts };
63
65
  }
66
+ /**
67
+ * A compiler host that resolves the SDK's own specifiers (the package name and
68
+ * its subpaths) from inside this package, as `sdk-resolve-hook.ts` does at run
69
+ * time. The author's folder may have no `node_modules` (a global install): a
70
+ * plain NodeNext program then cannot find the SDK's declarations, a Case
71
+ * task's `t` is `any`, and `.script(fn)` is not recognised. Package
72
+ * self-reference maps the name to the declarations beside this file. Any other
73
+ * specifier resolves as before.
74
+ */
75
+ function sdkResolvingHost(ts, options) {
76
+ const host = ts.createCompilerHost(options);
77
+ const self = fileURLToPath(import.meta.url);
78
+ host.resolveModuleNameLiterals = (literals, containingFile, redirected, opts, containing) => literals.map((literal) => {
79
+ const from = isSdkSpecifier(literal.text) ? self : containingFile;
80
+ const mode = ts.getModeForUsageLocation(containing, literal, opts);
81
+ return ts.resolveModuleName(literal.text, from, opts, host, undefined, redirected, mode);
82
+ });
83
+ return host;
84
+ }
64
85
  /** A whitespace-free key for comparing function texts. */
65
86
  export function functionTextKey(text) {
66
87
  return text.replace(/\s+/g, '');
@@ -136,8 +157,11 @@ export function scriptFunctionCaptureMessage(captures) {
136
157
  + 'Move the helper\'s code inside the function, or give it a name the runtime does not have.';
137
158
  }
138
159
  /**
139
- * Whether a call is `script(…)` from an import: the callee is an identifier
140
- * imported under the name `script`, or `<namespace import>.script`.
160
+ * Whether a call is a script call: Flow's `script(…)` from an import (the
161
+ * callee is an identifier imported under the name `script`, or
162
+ * `<namespace import>.script`), or a Case task's `.script(…)`, a method the
163
+ * checker resolves to the SDK's own `TaskBuilder.script` (`case/case-sdk.ts`),
164
+ * so another library's `script` method is not one.
141
165
  */
142
166
  function isScriptCall(ts, checker, call) {
143
167
  const callee = call.expression;
@@ -145,12 +169,26 @@ function isScriptCall(ts, checker, call) {
145
169
  const decl = checker.getSymbolAtLocation(callee)?.declarations?.[0];
146
170
  return decl !== undefined && ts.isImportSpecifier(decl) && (decl.propertyName ?? decl.name).text === 'script';
147
171
  }
148
- if (ts.isPropertyAccessExpression(callee) && callee.name.text === 'script' && ts.isIdentifier(callee.expression)) {
149
- const decl = checker.getSymbolAtLocation(callee.expression)?.declarations?.[0];
150
- return decl !== undefined && ts.isNamespaceImport(decl);
172
+ if (ts.isPropertyAccessExpression(callee) && callee.name.text === 'script') {
173
+ if (ts.isIdentifier(callee.expression)) {
174
+ const decl = checker.getSymbolAtLocation(callee.expression)?.declarations?.[0];
175
+ if (decl !== undefined && ts.isNamespaceImport(decl))
176
+ return true;
177
+ }
178
+ return isCaseTaskScript(ts, checker, callee);
151
179
  }
152
180
  return false;
153
181
  }
182
+ /** Whether `callee` is the Case `TaskBuilder.script` method, declared in the SDK's `case-sdk` module. */
183
+ function isCaseTaskScript(ts, checker, callee) {
184
+ const decl = checker.getSymbolAtLocation(callee.name)?.declarations?.[0];
185
+ if (!decl || !ts.isMethodDeclaration(decl))
186
+ return false;
187
+ const owner = decl.parent;
188
+ if (!ts.isClassDeclaration(owner) || owner.name?.text !== 'TaskBuilder')
189
+ return false;
190
+ return /(?:^|[\\/])case-sdk\.(?:d\.)?ts$/.test(decl.getSourceFile().fileName);
191
+ }
154
192
  /** The function an argument is, or names: inline, a declaration, or a `const` bound to one, through imports. */
155
193
  function functionOf(ts, checker, arg) {
156
194
  const fnLike = (n) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.79.1",
3
+ "version": "6.81.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",
@@ -103,5 +103,5 @@
103
103
  "@types/node": "^22.7.0",
104
104
  "esbuild": "^0.28.1"
105
105
  },
106
- "gitref": "5336a78ca0e7e6bdb6502ce791d71ccb49bbbf01"
106
+ "gitref": "f1f3a61ac051ab0738028776a78b2e564a15987f"
107
107
  }