@uipath/maestro-builder-sdk 5.2.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/LICENSE +21 -0
- package/README.md +322 -0
- package/dist/bindings-v2.d.ts +37 -0
- package/dist/bindings-v2.js +155 -0
- package/dist/bindings.d.ts +6 -0
- package/dist/bindings.js +6 -0
- package/dist/bpmn/bpmn-expr-check.d.ts +41 -0
- package/dist/bpmn/bpmn-expr-check.js +218 -0
- package/dist/bpmn/bpmn-sdk.d.ts +2257 -0
- package/dist/bpmn/bpmn-sdk.js +1476 -0
- package/dist/bpmn/check-cli.d.ts +3 -0
- package/dist/bpmn/check-cli.js +32 -0
- package/dist/bpmn/check.d.ts +25 -0
- package/dist/bpmn/check.js +430 -0
- package/dist/bpmn/compile-cli.d.ts +3 -0
- package/dist/bpmn/compile-cli.js +60 -0
- package/dist/bpmn/connector.d.ts +56 -0
- package/dist/bpmn/connector.js +199 -0
- package/dist/bpmn/decompile-cli.d.ts +8 -0
- package/dist/bpmn/decompile-cli.js +54 -0
- package/dist/bpmn/decompile.d.ts +6 -0
- package/dist/bpmn/decompile.js +1108 -0
- package/dist/bpmn/format-profile.d.ts +27 -0
- package/dist/bpmn/format-profile.js +11 -0
- package/dist/bpmn/intsvc.d.ts +77 -0
- package/dist/bpmn/intsvc.js +155 -0
- package/dist/bpmn/load.d.ts +4 -0
- package/dist/bpmn/load.js +22 -0
- package/dist/bpmn/merge-cli.d.ts +3 -0
- package/dist/bpmn/merge-cli.js +45 -0
- package/dist/bpmn/merge.d.ts +19 -0
- package/dist/bpmn/merge.js +293 -0
- package/dist/bpmn/registry-types.json +1869 -0
- package/dist/bpmn/serialize.d.ts +28 -0
- package/dist/bpmn/serialize.js +757 -0
- package/dist/bpmn/tidy-cli.d.ts +2 -0
- package/dist/bpmn/tidy-cli.js +39 -0
- package/dist/bpmn/typed-node.d.ts +382 -0
- package/dist/bpmn/typed-node.js +551 -0
- package/dist/bpmn/uipath-moddle.v1.json +823 -0
- package/dist/bpmn/xml-ranges.d.ts +45 -0
- package/dist/bpmn/xml-ranges.js +151 -0
- package/dist/case/case-expr-check.d.ts +35 -0
- package/dist/case/case-expr-check.js +85 -0
- package/dist/case/case-sdk.d.ts +1282 -0
- package/dist/case/case-sdk.js +923 -0
- package/dist/case/check-cli.d.ts +3 -0
- package/dist/case/check-cli.js +31 -0
- package/dist/case/check.d.ts +18 -0
- package/dist/case/check.js +456 -0
- package/dist/case/compile-cli.d.ts +3 -0
- package/dist/case/compile-cli.js +291 -0
- package/dist/case/decompile-cli.d.ts +9 -0
- package/dist/case/decompile-cli.js +117 -0
- package/dist/case/decompile.d.ts +187 -0
- package/dist/case/decompile.js +1170 -0
- package/dist/case/entry-points.d.ts +79 -0
- package/dist/case/entry-points.js +118 -0
- package/dist/case/format-profile.d.ts +60 -0
- package/dist/case/format-profile.js +79 -0
- package/dist/case/ids.d.ts +24 -0
- package/dist/case/ids.js +76 -0
- package/dist/case/load.d.ts +12 -0
- package/dist/case/load.js +32 -0
- package/dist/case/preserve.d.ts +133 -0
- package/dist/case/preserve.js +105 -0
- package/dist/case/serialize.d.ts +10 -0
- package/dist/case/serialize.js +1414 -0
- package/dist/check-cli.d.ts +3 -0
- package/dist/check-cli.js +118 -0
- package/dist/check.d.ts +146 -0
- package/dist/check.js +4898 -0
- package/dist/cli/commands/bpmn.d.ts +2 -0
- package/dist/cli/commands/bpmn.js +73 -0
- package/dist/cli/commands/case.d.ts +2 -0
- package/dist/cli/commands/case.js +60 -0
- package/dist/cli/commands/flow.d.ts +2 -0
- package/dist/cli/commands/flow.js +99 -0
- package/dist/cli/commands/registry.d.ts +10 -0
- package/dist/cli/commands/registry.js +170 -0
- package/dist/cli/common.d.ts +30 -0
- package/dist/cli/common.js +92 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +18 -0
- package/dist/cli-run.d.ts +2 -0
- package/dist/cli-run.js +42 -0
- package/dist/compile-cli.d.ts +3 -0
- package/dist/compile-cli.js +160 -0
- package/dist/config.d.ts +47 -0
- package/dist/config.js +201 -0
- package/dist/core/actions.d.ts +3244 -0
- package/dist/core/actions.js +1062 -0
- package/dist/core/binding-messages.d.ts +1 -0
- package/dist/core/binding-messages.js +16 -0
- package/dist/core/bindings.d.ts +12 -0
- package/dist/core/bindings.js +67 -0
- package/dist/core/ceql.d.ts +73 -0
- package/dist/core/ceql.js +272 -0
- package/dist/core/cli-spelling.d.ts +39 -0
- package/dist/core/cli-spelling.js +62 -0
- package/dist/core/connector-raw-node.d.ts +21 -0
- package/dist/core/connector-raw-node.js +47 -0
- package/dist/core/connectors.d.ts +184 -0
- package/dist/core/connectors.js +128 -0
- package/dist/core/expr-check.d.ts +93 -0
- package/dist/core/expr-check.js +186 -0
- package/dist/core/expr.d.ts +323 -0
- package/dist/core/expr.js +400 -0
- package/dist/core/index.d.ts +10 -0
- package/dist/core/index.js +10 -0
- package/dist/core/library.d.ts +440 -0
- package/dist/core/library.js +1183 -0
- package/dist/core/list-envelope.d.ts +45 -0
- package/dist/core/list-envelope.js +97 -0
- package/dist/core/lookup-store.d.ts +22 -0
- package/dist/core/lookup-store.js +85 -0
- package/dist/core/lookups.d.ts +227 -0
- package/dist/core/lookups.js +231 -0
- package/dist/core/node-classes.d.ts +234 -0
- package/dist/core/node-classes.js +158 -0
- package/dist/core/script-return.d.ts +68 -0
- package/dist/core/script-return.js +197 -0
- package/dist/core/stable-id.d.ts +28 -0
- package/dist/core/stable-id.js +37 -0
- package/dist/core-definitions.json +16249 -0
- package/dist/decompile-cli.d.ts +3 -0
- package/dist/decompile-cli.js +131 -0
- package/dist/decompile.d.ts +138 -0
- package/dist/decompile.js +2482 -0
- package/dist/emit.d.ts +10 -0
- package/dist/emit.js +60 -0
- package/dist/event-filters.d.ts +130 -0
- package/dist/event-filters.js +137 -0
- package/dist/flow-expr-check.d.ts +17 -0
- package/dist/flow-expr-check.js +193 -0
- package/dist/flow-sdk.d.ts +1341 -0
- package/dist/flow-sdk.js +1164 -0
- package/dist/flow-variables.d.ts +13 -0
- package/dist/flow-variables.js +42 -0
- package/dist/format-profile.d.ts +72 -0
- package/dist/format-profile.js +97 -0
- package/dist/generators/_connections.py +287 -0
- package/dist/generators/_events.py +355 -0
- package/dist/generators/_lookups.py +114 -0
- package/dist/generators/_naming.py +185 -0
- package/dist/generators/_objects.py +299 -0
- package/dist/generators/_resolve.py +273 -0
- package/dist/generators/convert_library_to_md.py +1441 -0
- package/dist/generators/extract_library.py +125 -0
- package/dist/generators/generate_connectors_ts.py +936 -0
- package/dist/generators/generate_library_json.py +2527 -0
- package/dist/generators/generate_triggers_ts.py +110 -0
- package/dist/generators/materialize_registry.py +155 -0
- package/dist/generators/prepare_connector.py +1688 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +35 -0
- package/dist/ixp-definition.json +1982 -0
- package/dist/library.d.ts +6 -0
- package/dist/library.js +6 -0
- package/dist/load.d.ts +16 -0
- package/dist/load.js +95 -0
- package/dist/merge-cli.d.ts +3 -0
- package/dist/merge-cli.js +47 -0
- package/dist/merge.d.ts +125 -0
- package/dist/merge.js +0 -0
- package/dist/migrate.d.ts +15 -0
- package/dist/migrate.js +245 -0
- package/dist/node-runtime.d.ts +3 -0
- package/dist/node-runtime.js +22 -0
- package/dist/package-name.d.ts +17 -0
- package/dist/package-name.js +17 -0
- package/dist/ref-resolve.d.ts +77 -0
- package/dist/ref-resolve.js +170 -0
- package/dist/registry/cache.d.ts +55 -0
- package/dist/registry/cache.js +134 -0
- package/dist/registry/curated-overlay.d.ts +16 -0
- package/dist/registry/curated-overlay.js +62 -0
- package/dist/registry/extractor.d.ts +22 -0
- package/dist/registry/extractor.js +18 -0
- package/dist/registry/materialize-bin.d.ts +2 -0
- package/dist/registry/materialize-bin.js +7 -0
- package/dist/registry/materialize-cli.d.ts +1 -0
- package/dist/registry/materialize-cli.js +46 -0
- package/dist/registry/materializer.d.ts +23 -0
- package/dist/registry/materializer.js +34 -0
- package/dist/registry/path-cli.d.ts +1 -0
- package/dist/registry/path-cli.js +56 -0
- package/dist/registry/prepare-cli.d.ts +62 -0
- package/dist/registry/prepare-cli.js +185 -0
- package/dist/registry/pull-cli.d.ts +1 -0
- package/dist/registry/pull-cli.js +274 -0
- package/dist/registry/python.d.ts +26 -0
- package/dist/registry/python.js +46 -0
- package/dist/registry/search-cli.d.ts +52 -0
- package/dist/registry/search-cli.js +159 -0
- package/dist/schema-version.d.ts +165 -0
- package/dist/schema-version.js +148 -0
- package/dist/serialize.d.ts +64 -0
- package/dist/serialize.js +6398 -0
- package/lib/README.md +112 -0
- package/lib/library-json.samples/index.json +158 -0
- package/lib/library-json.samples/invariant-collections.json +83 -0
- package/lib/library-json.samples/list-envelopes.json +123 -0
- package/lib/library-json.samples/uipath-atlassian-jira/create-issue@1.0.0.json +131 -0
- package/lib/library-json.samples/uipath-atlassian-jira/create-issue@1.0.0.v1def.json +306 -0
- package/lib/library-json.samples/uipath-atlassian-jira/generic/create_issue/create@1.0.0.json +86 -0
- package/lib/library-json.samples/uipath-atlassian-jira/generic/create_issue/create@1.0.0.v1def.json +208 -0
- package/lib/library-json.samples/uipath-atlassian-jira/get-issue@1.0.0.json +2040 -0
- package/lib/library-json.samples/uipath-atlassian-jira/get-issue@1.0.0.v1def.json +195 -0
- package/lib/library-json.samples/uipath-google-vertex/execute-google-vertex-agent@1.0.0.json +169 -0
- package/lib/library-json.samples/uipath-google-vertex/execute-google-vertex-agent@1.0.0.v1def.json +209 -0
- package/lib/library-json.samples/uipath-http-webhook/event-http-webhook@1.0.0.json +63 -0
- package/lib/library-json.samples/uipath-http-webhook/event-http-webhook@1.0.0.v1def.json +262 -0
- package/lib/library-json.samples/uipath-http-webhook/trigger-http-webhook@1.0.0.json +63 -0
- package/lib/library-json.samples/uipath-http-webhook/trigger-http-webhook@1.0.0.v1def.json +213 -0
- package/lib/library-json.samples/uipath-microsoft-azureactivedirectory/list-groups@1.0.0.json +227 -0
- package/lib/library-json.samples/uipath-microsoft-azureactivedirectory/list-groups@1.0.0.v1def.json +373 -0
- package/lib/library-json.samples/uipath-microsoft-onedrive/event-file-created@1.0.0.json +116 -0
- package/lib/library-json.samples/uipath-microsoft-onedrive/event-file-created@1.0.0.v1def.json +369 -0
- package/lib/library-json.samples/uipath-microsoft-onedrive/event-list-item-added@1.0.0.json +56 -0
- package/lib/library-json.samples/uipath-microsoft-onedrive/event-list-item-added@1.0.0.v1def.json +256 -0
- package/lib/library-json.samples/uipath-microsoft-onedrive/trigger-file-created@1.0.0.json +116 -0
- package/lib/library-json.samples/uipath-microsoft-onedrive/trigger-file-created@1.0.0.v1def.json +320 -0
- package/lib/library-json.samples/uipath-microsoft-onedrive/trigger-list-item-added@1.0.0.json +56 -0
- package/lib/library-json.samples/uipath-microsoft-onedrive/trigger-list-item-added@1.0.0.v1def.json +207 -0
- package/lib/library-json.samples/uipath-microsoft-outlook365/event-email-received@1.0.0.json +107 -0
- package/lib/library-json.samples/uipath-microsoft-outlook365/event-email-received@1.0.0.v1def.json +264 -0
- package/lib/library-json.samples/uipath-microsoft-outlook365/send-email@1.0.0.json +142 -0
- package/lib/library-json.samples/uipath-microsoft-outlook365/send-email@1.0.0.v1def.json +306 -0
- package/lib/library-json.samples/uipath-microsoft-outlook365/trigger-email-received@1.0.0.json +107 -0
- package/lib/library-json.samples/uipath-microsoft-outlook365/trigger-email-received@1.0.0.v1def.json +217 -0
- package/lib/library-json.samples/uipath-microsoft-powerautomate/invoke-a-microsoft-power-automate-flow@1.0.0.json +85 -0
- package/lib/library-json.samples/uipath-microsoft-powerautomate/invoke-a-microsoft-power-automate-flow@1.0.0.v1def.json +209 -0
- package/lib/library-json.samples/uipath-salesforce-slack/send-message-to-user@1.0.0.json +755 -0
- package/lib/library-json.samples/uipath-salesforce-slack/send-message-to-user@1.0.0.v1def.json +513 -0
- package/lib/library-json.samples/uipath-uipath-dataservice/query-entity-records@1.0.0.json +122 -0
- package/lib/library-json.samples/uipath-uipath-dataservice/query-entity-records@1.0.0.v1def.json +227 -0
- package/package.json +85 -0
|
@@ -0,0 +1,923 @@
|
|
|
1
|
+
import { connector as makeConnector, subscriptionFrom, } from '../core/actions.js';
|
|
2
|
+
import { isTriggerDescriptor } from '../core/connectors.js';
|
|
3
|
+
import { checkCaseExpressions, CaseBuildError } from './case-expr-check.js';
|
|
4
|
+
import { CASE_FORMAT_PROFILE, CASE_SCHEMA_VERSIONS, recordAuthoredCaseVersion } from './format-profile.js';
|
|
5
|
+
import { schemaVersionRefusal } from '../schema-version.js';
|
|
6
|
+
export { preserveCaseJson } from './preserve.js';
|
|
7
|
+
export { CaseBuildError } from './case-expr-check.js';
|
|
8
|
+
/**
|
|
9
|
+
* Declare a condition rule. Pass one rule, an array for an AND-group, or an
|
|
10
|
+
* array of arrays for the complete OR-of-AND grid to
|
|
11
|
+
* `entryWhen`/`exitWhen`/etc.
|
|
12
|
+
*
|
|
13
|
+
* @param type - Which condition, e.g. `'case-entered'` or `'selected-tasks-completed'`.
|
|
14
|
+
* @param opts - What the rule needs, e.g. the `tasks` a task-completion rule waits on.
|
|
15
|
+
* @returns A rule to pass to `entryWhen` / `exitWhen` / `completeWhen`.
|
|
16
|
+
*/
|
|
17
|
+
export function rule(type, opts = {}) {
|
|
18
|
+
return { rule: type, ...opts };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Gate a condition slot only on case data without naming its default event.
|
|
22
|
+
*
|
|
23
|
+
* @param expression - A `=js:` expression over declared `vars.*` values.
|
|
24
|
+
* @returns A slot-agnostic marker resolved by `entryWhen`, `exitWhen`, or `completeWhen`.
|
|
25
|
+
*/
|
|
26
|
+
export function when(expression) {
|
|
27
|
+
return { kind: 'case-when-expression', expression };
|
|
28
|
+
}
|
|
29
|
+
const DEFAULT_RULE_BY_SLOT = {
|
|
30
|
+
'stage-entry': 'case-entered',
|
|
31
|
+
'stage-exit': 'selected-tasks-completed',
|
|
32
|
+
'task-entry': 'current-stage-entered',
|
|
33
|
+
'case-exit': 'required-stages-completed',
|
|
34
|
+
};
|
|
35
|
+
function resolveRule(input, slot) {
|
|
36
|
+
if (input.kind === 'case-when-expression')
|
|
37
|
+
return rule(DEFAULT_RULE_BY_SLOT[slot], { expression: input.expression });
|
|
38
|
+
return input;
|
|
39
|
+
}
|
|
40
|
+
/** Coerce a rule, AND-group, or complete OR-of-AND grid into the wire DNF. */
|
|
41
|
+
function ruleGroups(rules, slot) {
|
|
42
|
+
const groups = !Array.isArray(rules)
|
|
43
|
+
? [[rules]]
|
|
44
|
+
: rules.length > 0 && Array.isArray(rules[0])
|
|
45
|
+
? rules
|
|
46
|
+
: [rules];
|
|
47
|
+
return groups.map((group) => group.map((input) => resolveRule(input, slot)));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Declare an escalation. `notify` recipients come from {@link toUser}/{@link toGroup}.
|
|
51
|
+
*
|
|
52
|
+
* @param opts - When it fires (`after`) and who it notifies (`notify`).
|
|
53
|
+
* @returns An escalation to attach to an SLA.
|
|
54
|
+
*/
|
|
55
|
+
export function escalation(opts) {
|
|
56
|
+
return opts;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* An escalation recipient that is a single user.
|
|
60
|
+
*
|
|
61
|
+
* @param target - How the user is addressed, e.g. `'email'`.
|
|
62
|
+
* @param value - The address itself, when `target` names a lookup rather than a value.
|
|
63
|
+
* @returns A recipient for an escalation's `notify` list.
|
|
64
|
+
*/
|
|
65
|
+
export function toUser(target, value) {
|
|
66
|
+
return { scope: 'User', target, value };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* An escalation recipient that is a user group.
|
|
70
|
+
*
|
|
71
|
+
* @param target - How the group is addressed, e.g. `'name'`.
|
|
72
|
+
* @param value - The value itself, when `target` names a lookup rather than a value.
|
|
73
|
+
* @returns A recipient for an escalation's `notify` list.
|
|
74
|
+
*/
|
|
75
|
+
export function toGroup(target, value) {
|
|
76
|
+
return { scope: 'UserGroup', target, value };
|
|
77
|
+
}
|
|
78
|
+
function buildSla(opts) {
|
|
79
|
+
return {
|
|
80
|
+
count: opts.count,
|
|
81
|
+
unit: opts.unit,
|
|
82
|
+
displayName: opts.displayName,
|
|
83
|
+
// The default SLA (no `when`) carries the designer's always-true gate.
|
|
84
|
+
expression: opts.when ?? '=js:true',
|
|
85
|
+
escalations: opts.escalations ?? [],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A manual (user-initiated) case trigger.
|
|
90
|
+
*
|
|
91
|
+
* @param opts - Display name and other trigger metadata.
|
|
92
|
+
* @returns A trigger to pass to `.trigger(...)`.
|
|
93
|
+
*/
|
|
94
|
+
export function manualTrigger(opts = {}) {
|
|
95
|
+
return { kind: 'manual', name: opts.name, description: opts.description };
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* A timer (scheduled) case trigger. `every` is an ISO-8601 repeating interval.
|
|
99
|
+
*
|
|
100
|
+
* @param opts - The schedule — `every`, as an ISO-8601 repeating interval.
|
|
101
|
+
* @returns A trigger to pass to `.trigger(...)`.
|
|
102
|
+
*/
|
|
103
|
+
export function timerTrigger(opts) {
|
|
104
|
+
return { kind: 'timer', name: opts.name, description: opts.description, timeCycle: opts.every };
|
|
105
|
+
}
|
|
106
|
+
export function eventTrigger(descriptorOrOpts = {}, descriptorOpts = {}) {
|
|
107
|
+
const descriptor = isTriggerDescriptor(descriptorOrOpts) ? descriptorOrOpts : undefined;
|
|
108
|
+
const opts = descriptor ? descriptorOpts : descriptorOrOpts;
|
|
109
|
+
const eventOutputs = [];
|
|
110
|
+
for (const [name, v] of Object.entries(opts.outputs ?? {})) {
|
|
111
|
+
const source = typeof v === 'string' ? v : v.source;
|
|
112
|
+
const type = (typeof v === 'string' ? 'string' : (v.type ?? 'string'));
|
|
113
|
+
eventOutputs.push({ var: name, source, type });
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
kind: 'event',
|
|
117
|
+
name: opts.name,
|
|
118
|
+
description: opts.description,
|
|
119
|
+
eventOutputs: eventOutputs.length ? eventOutputs : undefined,
|
|
120
|
+
eventSubscription: descriptor
|
|
121
|
+
? subscriptionFrom(descriptor, descriptorOpts)
|
|
122
|
+
: opts.subscription,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Declare a structured (object/array) variable type. Pass the JSON schema — object
|
|
127
|
+
* vs array is `body.type`. Use in `.var()`/`.input()`/`.output()` where a
|
|
128
|
+
* {@link TypeDesc} is expected.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* **Declare an object variable and an array variable**
|
|
132
|
+
* ```ts
|
|
133
|
+
* .var('caseData', jsonSchema({ type: 'object', properties: { status: { type: 'string' } } }))
|
|
134
|
+
* .var('attachments', jsonSchema({ type: 'array', items: { type: 'string' } }))
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* @param body - The JSON schema. Its `type` decides object vs array.
|
|
138
|
+
* @returns A type descriptor for `.var()` / `.input()` / `.output()`.
|
|
139
|
+
*/
|
|
140
|
+
export function jsonSchema(body) {
|
|
141
|
+
return { type: 'jsonSchema', body };
|
|
142
|
+
}
|
|
143
|
+
/** Normalize a variable spec (a bare {@link TypeDesc}, a {@link JsonSchemaType}, or `{ type, default?, body? }`). */
|
|
144
|
+
function normVarSpec(spec) {
|
|
145
|
+
if (typeof spec === 'string')
|
|
146
|
+
return { type: spec };
|
|
147
|
+
return { type: spec.type, default: spec.default, body: spec.body };
|
|
148
|
+
}
|
|
149
|
+
class TaskBuilder {
|
|
150
|
+
_name;
|
|
151
|
+
_kind;
|
|
152
|
+
_ref;
|
|
153
|
+
_action;
|
|
154
|
+
_connector;
|
|
155
|
+
_external;
|
|
156
|
+
_timer;
|
|
157
|
+
_waitConnector;
|
|
158
|
+
_required;
|
|
159
|
+
_runOnce;
|
|
160
|
+
_description;
|
|
161
|
+
_skip;
|
|
162
|
+
_inputs;
|
|
163
|
+
_outputs;
|
|
164
|
+
_entry = [];
|
|
165
|
+
constructor(_name) {
|
|
166
|
+
this._name = _name;
|
|
167
|
+
}
|
|
168
|
+
setKind(kind) {
|
|
169
|
+
if (this._kind)
|
|
170
|
+
throw new Error(`task "${this._name}": kind already set to "${this._kind}", cannot also be "${kind}".`);
|
|
171
|
+
this._kind = kind;
|
|
172
|
+
}
|
|
173
|
+
reference(kind, name, opts = {}) {
|
|
174
|
+
this.setKind(kind);
|
|
175
|
+
this._ref = { name, folderPath: opts.folder ?? '' };
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Reference a published Maestro process.
|
|
180
|
+
*
|
|
181
|
+
* @param name - The published process's name.
|
|
182
|
+
* @param opts - `folder` — the Orchestrator folder it lives in.
|
|
183
|
+
* @returns This builder, so calls chain.
|
|
184
|
+
*/
|
|
185
|
+
process(name, opts) {
|
|
186
|
+
return this.reference('process', name, opts);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Preserve an explicitly unresolved published-resource task as a typed
|
|
190
|
+
* skeleton whose serialized `data` is `{}`.
|
|
191
|
+
*
|
|
192
|
+
* @remarks
|
|
193
|
+
* Use this only when the requested resource identity cannot be resolved.
|
|
194
|
+
* Do not invent a name or folder. An unresolved task cannot declare input or
|
|
195
|
+
* output bindings because there is no referenced contract to bind against.
|
|
196
|
+
*
|
|
197
|
+
* @param kind - The published-resource family to preserve.
|
|
198
|
+
* @returns This builder, so calls chain.
|
|
199
|
+
*/
|
|
200
|
+
unresolved(kind) {
|
|
201
|
+
this.setKind(kind);
|
|
202
|
+
return this;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Reference a published agent.
|
|
206
|
+
*
|
|
207
|
+
* @param name - The published agent's name.
|
|
208
|
+
* @param opts - `folder` — the Orchestrator folder it lives in.
|
|
209
|
+
* @returns This builder, so calls chain.
|
|
210
|
+
*/
|
|
211
|
+
agent(name, opts) {
|
|
212
|
+
return this.reference('agent', name, opts);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Reference a published RPA process.
|
|
216
|
+
*
|
|
217
|
+
* @param name - The published RPA process's name.
|
|
218
|
+
* @param opts - `folder` — the Orchestrator folder it lives in.
|
|
219
|
+
* @returns This builder, so calls chain.
|
|
220
|
+
*/
|
|
221
|
+
rpa(name, opts) {
|
|
222
|
+
return this.reference('rpa', name, opts);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Reference a published API workflow.
|
|
226
|
+
*
|
|
227
|
+
* @param name - The published API workflow's name.
|
|
228
|
+
* @param opts - `folder` — the Orchestrator folder it lives in.
|
|
229
|
+
* @returns This builder, so calls chain.
|
|
230
|
+
*/
|
|
231
|
+
apiWorkflow(name, opts) {
|
|
232
|
+
return this.reference('api-workflow', name, opts);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Reference another published case (a **sub-case**). Pass data into the child
|
|
236
|
+
* with `.inputs({...})` and read results back with `.outputs({...})` — the same
|
|
237
|
+
* io-binding as reference-mode tasks.
|
|
238
|
+
*
|
|
239
|
+
* @param name - The published child case's name.
|
|
240
|
+
* @param opts - `folder` — the Orchestrator folder it lives in.
|
|
241
|
+
* @returns This builder, so calls chain.
|
|
242
|
+
*/
|
|
243
|
+
caseManagement(name, opts) {
|
|
244
|
+
return this.reference('case-management', name, opts);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Reference a published Maestro Flow.
|
|
248
|
+
*
|
|
249
|
+
* @param name - The published Flow's name.
|
|
250
|
+
* @param opts - `folder` — the Orchestrator folder it lives in.
|
|
251
|
+
* @returns This builder, so calls chain.
|
|
252
|
+
*/
|
|
253
|
+
flowProcess(name, opts) {
|
|
254
|
+
return this.reference('flow-process', name, opts);
|
|
255
|
+
}
|
|
256
|
+
external(kind, descriptor, opts) {
|
|
257
|
+
this.setKind(kind);
|
|
258
|
+
this._external = {
|
|
259
|
+
mode: opts.mode,
|
|
260
|
+
connector: makeConnector(descriptor, opts.inputs, {
|
|
261
|
+
connection: opts.connection,
|
|
262
|
+
folder: opts.folder,
|
|
263
|
+
}),
|
|
264
|
+
};
|
|
265
|
+
return this;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Invoke an external agent through its generated Integration Service descriptor.
|
|
269
|
+
*
|
|
270
|
+
* @param descriptor - An `AgentExecution` operation from a generated connector module.
|
|
271
|
+
* @param opts - Required connection/folder bindings, sync/async mode, and descriptor-typed inputs.
|
|
272
|
+
* @returns This builder, so calls chain.
|
|
273
|
+
*/
|
|
274
|
+
externalAgent(descriptor, opts) {
|
|
275
|
+
return this.external('external-agent', descriptor, opts);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Invoke an external workflow through its generated Integration Service descriptor.
|
|
279
|
+
*
|
|
280
|
+
* @param descriptor - A `ProcessExecution` operation from a generated connector module.
|
|
281
|
+
* @param opts - Required connection/folder bindings, sync/async mode, and descriptor-typed inputs.
|
|
282
|
+
* @returns This builder, so calls chain.
|
|
283
|
+
*/
|
|
284
|
+
externalWorkflow(descriptor, opts) {
|
|
285
|
+
return this.external('external-workflow', descriptor, opts);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* An Action Center human task. `recipient` may be an email (→ Type 2) or
|
|
289
|
+
* `{ type, value }`. `inputs`/`outputs` declare the task's form fields — inputs
|
|
290
|
+
* are read-only context the assignee sees, outputs are what they fill in.
|
|
291
|
+
* `labels` and `actionCatalogName` tag the task and name its action app.
|
|
292
|
+
*
|
|
293
|
+
* @param spec - The human task: its `title`, `priority`, `recipient`, and the `inputs` / `outputs` its form shows and collects.
|
|
294
|
+
* @returns This builder, so calls chain.
|
|
295
|
+
*/
|
|
296
|
+
action(spec = {}) {
|
|
297
|
+
this.setKind('action');
|
|
298
|
+
const recipient = typeof spec.recipient === 'string' ? { type: 2, value: spec.recipient } : spec.recipient;
|
|
299
|
+
this._action = {
|
|
300
|
+
title: spec.title,
|
|
301
|
+
priority: spec.priority,
|
|
302
|
+
recipient,
|
|
303
|
+
labels: spec.labels,
|
|
304
|
+
actionCatalogName: spec.actionCatalogName,
|
|
305
|
+
inputs: spec.inputs,
|
|
306
|
+
outputs: spec.outputs,
|
|
307
|
+
};
|
|
308
|
+
return this;
|
|
309
|
+
}
|
|
310
|
+
connector(a, b, c, d) {
|
|
311
|
+
this.setKind('connector');
|
|
312
|
+
// Reuse the shared connector() so descriptor/nodeType splitting + version
|
|
313
|
+
// handling match the Flow surface exactly; store the connector ActionSpec.
|
|
314
|
+
this._connector = makeConnector(a, b, c, d);
|
|
315
|
+
return this;
|
|
316
|
+
}
|
|
317
|
+
waitForConnector(descriptorOrSpec = {}, opts) {
|
|
318
|
+
this.setKind('wait-for-connector');
|
|
319
|
+
this._waitConnector = isTriggerDescriptor(descriptorOrSpec)
|
|
320
|
+
? subscriptionFrom(descriptorOrSpec, opts)
|
|
321
|
+
: descriptorOrSpec;
|
|
322
|
+
return this;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* A wait-for-timer task (ISO-8601 `duration`, ISO `date`, or repeating `cycle`).
|
|
326
|
+
*
|
|
327
|
+
* @param spec - How long to wait: an ISO-8601 `duration`, a `date`, or a repeating `cycle`.
|
|
328
|
+
* @returns This builder, so calls chain.
|
|
329
|
+
*/
|
|
330
|
+
waitForTimer(spec) {
|
|
331
|
+
this.setKind('wait-for-timer');
|
|
332
|
+
this._timer = spec;
|
|
333
|
+
return this;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Mark this task required, so its stage cannot complete without it.
|
|
337
|
+
*
|
|
338
|
+
* @param value - Whether the task is required.
|
|
339
|
+
* @returns This builder, so calls chain.
|
|
340
|
+
*/
|
|
341
|
+
required(value = true) {
|
|
342
|
+
this._required = value;
|
|
343
|
+
return this;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Run this task at most once, even if its entry condition is met again.
|
|
347
|
+
*
|
|
348
|
+
* @param value - Whether the task runs only once.
|
|
349
|
+
* @returns This builder, so calls chain.
|
|
350
|
+
*/
|
|
351
|
+
runOnce(value = true) {
|
|
352
|
+
this._runOnce = value;
|
|
353
|
+
return this;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Run this task again whenever its entry condition is met after stage re-entry.
|
|
357
|
+
* This is the semantic inverse of {@link TaskBuilder.runOnce} and emits an explicit
|
|
358
|
+
* `shouldRunOnlyOnce: false`.
|
|
359
|
+
*
|
|
360
|
+
* @returns This builder, so calls chain.
|
|
361
|
+
*/
|
|
362
|
+
runOnReEntry() {
|
|
363
|
+
this._runOnce = false;
|
|
364
|
+
return this;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Describe this task.
|
|
368
|
+
*
|
|
369
|
+
* @param text - Prose the designer shows on the task.
|
|
370
|
+
* @returns This builder, so calls chain.
|
|
371
|
+
*/
|
|
372
|
+
description(text) {
|
|
373
|
+
this._description = text;
|
|
374
|
+
return this;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Skip this task when the `=js:` expression is truthy.
|
|
378
|
+
*
|
|
379
|
+
* @param expression - An `=js:` expression; the task is skipped when it is truthy.
|
|
380
|
+
* @returns This builder, so calls chain.
|
|
381
|
+
*/
|
|
382
|
+
skipWhen(expression) {
|
|
383
|
+
this._skip = expression;
|
|
384
|
+
return this;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Bind resource **input** parameters (reference-mode tasks). Each key is a
|
|
388
|
+
* declared input parameter name; each value is a literal, a case-variable read
|
|
389
|
+
* `=vars.<name>`, or a `=js:` expression. Pass `{ value, type }` to set a
|
|
390
|
+
* non-string type (default `string`).
|
|
391
|
+
*
|
|
392
|
+
* @param shape - Input parameter names to literals, case-variable references, or `{ value, type }`.
|
|
393
|
+
* @returns This builder, so calls chain.
|
|
394
|
+
*/
|
|
395
|
+
inputs(shape) {
|
|
396
|
+
this._inputs ??= [];
|
|
397
|
+
for (const [name, v] of Object.entries(shape)) {
|
|
398
|
+
const value = typeof v === 'string' ? v : v.value;
|
|
399
|
+
const type = (typeof v === 'string' ? 'string' : (v.type ?? 'string'));
|
|
400
|
+
this._inputs.push({ name, value, type });
|
|
401
|
+
}
|
|
402
|
+
return this;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Extract fields of the task's **result** into case variables (reference-mode
|
|
406
|
+
* tasks). Each key is the case-variable name a later task/condition reads as
|
|
407
|
+
* `=vars.<name>`; each value is the source field expression (e.g. `=response`,
|
|
408
|
+
* `=Error.Message`). Pass `{ source, type }` to set a non-string type. Emits a
|
|
409
|
+
* `data.outputs[]` row plus a root `inputOutputs` companion so the name resolves.
|
|
410
|
+
*
|
|
411
|
+
* @param shape - Case-variable names to the result field they take, or `{ source, type }`.
|
|
412
|
+
* @returns This builder, so calls chain.
|
|
413
|
+
*/
|
|
414
|
+
outputs(shape) {
|
|
415
|
+
this._outputs ??= [];
|
|
416
|
+
for (const [name, v] of Object.entries(shape)) {
|
|
417
|
+
const source = typeof v === 'string' ? v : v.source;
|
|
418
|
+
const type = (typeof v === 'string' ? 'string' : (v.type ?? 'string'));
|
|
419
|
+
this._outputs.push({ var: name, source, type });
|
|
420
|
+
}
|
|
421
|
+
return this;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Add a task-entry condition. Pass a nested array for the complete OR-of-AND grid.
|
|
425
|
+
*
|
|
426
|
+
* @param rules - One rule, an AND-group, or the complete OR-of-AND grid.
|
|
427
|
+
* @param opts - `displayName` for the condition.
|
|
428
|
+
* @returns This builder, so calls chain.
|
|
429
|
+
*/
|
|
430
|
+
entryWhen(rules, opts = {}) {
|
|
431
|
+
this._entry.push({ displayName: opts.displayName, rules: ruleGroups(rules, 'task-entry') });
|
|
432
|
+
return this;
|
|
433
|
+
}
|
|
434
|
+
/** @internal */
|
|
435
|
+
_build() {
|
|
436
|
+
if (!this._kind)
|
|
437
|
+
throw new Error(`task "${this._name}" has no kind — call .process()/.agent()/.rpa()/.action()/.connector()/.waitForTimer()/… once.`);
|
|
438
|
+
// Task I/O binding is reference-mode only — process/agent/rpa/api-workflow,
|
|
439
|
+
// case-management, and flow-process. Connector tasks derive their own
|
|
440
|
+
// inputs/outputs from the operation schema.
|
|
441
|
+
const REF_IO = new Set(['process', 'agent', 'rpa', 'api-workflow', 'case-management', 'flow-process']);
|
|
442
|
+
if ((this._inputs || this._outputs) && !REF_IO.has(this._kind))
|
|
443
|
+
throw new Error(`task "${this._name}": .inputs()/.outputs() are only supported on reference-mode tasks (process/agent/rpa/api-workflow/case-management/flow-process), not "${this._kind}".`);
|
|
444
|
+
if (!this._ref && (this._inputs || this._outputs))
|
|
445
|
+
throw new Error(`task "${this._name}": an unresolved reference task cannot declare inputs or outputs.`);
|
|
446
|
+
return {
|
|
447
|
+
name: this._name,
|
|
448
|
+
kind: this._kind,
|
|
449
|
+
ref: this._ref,
|
|
450
|
+
action: this._action,
|
|
451
|
+
connector: this._connector,
|
|
452
|
+
external: this._external,
|
|
453
|
+
timer: this._timer,
|
|
454
|
+
waitConnector: this._waitConnector,
|
|
455
|
+
required: this._required,
|
|
456
|
+
runOnce: this._runOnce,
|
|
457
|
+
description: this._description,
|
|
458
|
+
skip: this._skip,
|
|
459
|
+
inputs: this._inputs,
|
|
460
|
+
outputs: this._outputs,
|
|
461
|
+
entry: this._entry,
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
class StageBuilder {
|
|
466
|
+
_label;
|
|
467
|
+
_exception;
|
|
468
|
+
_description;
|
|
469
|
+
_required;
|
|
470
|
+
_lanes = [];
|
|
471
|
+
_entry = [];
|
|
472
|
+
_exit = [];
|
|
473
|
+
_sla = [];
|
|
474
|
+
constructor(_label, _exception) {
|
|
475
|
+
this._label = _label;
|
|
476
|
+
this._exception = _exception;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Describe this stage.
|
|
480
|
+
*
|
|
481
|
+
* @param text - Prose the designer shows on the stage.
|
|
482
|
+
* @returns This builder, so calls chain.
|
|
483
|
+
*/
|
|
484
|
+
description(text) {
|
|
485
|
+
this._description = text;
|
|
486
|
+
return this;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Mark this stage required, so the case cannot complete without it.
|
|
490
|
+
*
|
|
491
|
+
* @param value - Whether the stage is required.
|
|
492
|
+
* @returns This builder, so calls chain.
|
|
493
|
+
*/
|
|
494
|
+
required(value = true) {
|
|
495
|
+
this._required = value;
|
|
496
|
+
return this;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Add a task. `fn` receives a task sub-builder. `lane` is the index of the
|
|
500
|
+
* task's SET in `data.tasks[][]` (default 0) and orders SEQUENTIAL sets — a
|
|
501
|
+
* task whose entry conditions are all `runs-sequentially` waits for the
|
|
502
|
+
* previous set. It does NOT make tasks parallel: every other task runs when
|
|
503
|
+
* its own entry condition fires, whatever set it sits in.
|
|
504
|
+
*
|
|
505
|
+
* Two tasks on `current-stage-entered` therefore convert to byte-identical
|
|
506
|
+
* scheduler rules whether they share a set or not, and the designer writes
|
|
507
|
+
* one task per set even for a stage its own SDD calls parallel.
|
|
508
|
+
*
|
|
509
|
+
* @param displayName - The task's display name.
|
|
510
|
+
* @param fn - Receives a sub-builder for what the task does.
|
|
511
|
+
* @param opts - `lane` is the task's set index in `data.tasks[][]` (default 0);
|
|
512
|
+
* it orders `runs-sequentially` sets and is inert for every other task.
|
|
513
|
+
* @returns This builder, so calls chain.
|
|
514
|
+
*/
|
|
515
|
+
task(displayName, fn, opts = {}) {
|
|
516
|
+
const tb = new TaskBuilder(displayName);
|
|
517
|
+
fn(tb);
|
|
518
|
+
const lane = opts.lane ?? 0;
|
|
519
|
+
while (this._lanes.length <= lane)
|
|
520
|
+
this._lanes.push([]);
|
|
521
|
+
this._lanes[lane].push(tb._build());
|
|
522
|
+
return this;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Add a stage-entry condition. Pass a nested array for the complete OR-of-AND grid.
|
|
526
|
+
*
|
|
527
|
+
* @param rules - One rule, an AND-group, or the complete OR-of-AND grid.
|
|
528
|
+
* @param opts - `displayName`, and the entry behaviour flags.
|
|
529
|
+
* @returns This builder, so calls chain.
|
|
530
|
+
*/
|
|
531
|
+
entryWhen(rules, opts = {}) {
|
|
532
|
+
this._entry.push({ displayName: opts.displayName, isInterrupting: opts.isInterrupting, rules: ruleGroups(rules, 'stage-entry') });
|
|
533
|
+
return this;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Add a stage-exit condition. Pass a nested array for the complete OR-of-AND grid.
|
|
537
|
+
*
|
|
538
|
+
* @param rules - One rule, an AND-group, or the complete OR-of-AND grid.
|
|
539
|
+
* @param opts - `displayName`, and whether meeting it completes the stage.
|
|
540
|
+
* @returns This builder, so calls chain.
|
|
541
|
+
*/
|
|
542
|
+
exitWhen(rules, opts = {}) {
|
|
543
|
+
this._exit.push({
|
|
544
|
+
displayName: opts.displayName,
|
|
545
|
+
marksStageComplete: opts.marksStageComplete,
|
|
546
|
+
type: opts.type,
|
|
547
|
+
exitToStage: opts.exitToStage,
|
|
548
|
+
selectNextStage: opts.selectNextStage,
|
|
549
|
+
rules: ruleGroups(rules, 'stage-exit'),
|
|
550
|
+
});
|
|
551
|
+
return this;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Set an SLA (deadline + escalations) on this stage. Call more than once for
|
|
555
|
+
* conditional SLAs (each with a `when` gate); the default SLA (no `when`) must
|
|
556
|
+
* be last.
|
|
557
|
+
*
|
|
558
|
+
* @param opts - The deadline, its escalations, and an optional `when` gate.
|
|
559
|
+
* @returns This builder, so calls chain.
|
|
560
|
+
*/
|
|
561
|
+
sla(opts) {
|
|
562
|
+
this._sla.push(buildSla(opts));
|
|
563
|
+
return this;
|
|
564
|
+
}
|
|
565
|
+
/** @internal */
|
|
566
|
+
_build() {
|
|
567
|
+
return {
|
|
568
|
+
label: this._label,
|
|
569
|
+
exception: this._exception,
|
|
570
|
+
description: this._description,
|
|
571
|
+
required: this._required,
|
|
572
|
+
lanes: this._lanes.length ? this._lanes : [[]],
|
|
573
|
+
entry: this._entry,
|
|
574
|
+
exit: this._exit,
|
|
575
|
+
slaRules: this._sla,
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
class CaseBuilder {
|
|
580
|
+
_id;
|
|
581
|
+
_name;
|
|
582
|
+
_authoredVersion;
|
|
583
|
+
_schemaVersion;
|
|
584
|
+
_description;
|
|
585
|
+
_identifier;
|
|
586
|
+
_identifierType = 'constant';
|
|
587
|
+
_caseApp = false;
|
|
588
|
+
_caseAppConfig;
|
|
589
|
+
_allowAdhocTasks;
|
|
590
|
+
_layout;
|
|
591
|
+
_vars = [];
|
|
592
|
+
_stages = [];
|
|
593
|
+
_caseExit = [];
|
|
594
|
+
_sla = [];
|
|
595
|
+
_triggers = [];
|
|
596
|
+
constructor(_id) {
|
|
597
|
+
this._id = _id;
|
|
598
|
+
this._name = _id;
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Set the case plan's display name.
|
|
602
|
+
*
|
|
603
|
+
* @param n - The name the designer shows.
|
|
604
|
+
* @returns This builder, so calls chain.
|
|
605
|
+
*/
|
|
606
|
+
name(n) {
|
|
607
|
+
this._name = n;
|
|
608
|
+
return this;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Set the case plan's schema version during the compatibility window.
|
|
612
|
+
*
|
|
613
|
+
* @deprecated Use {@link CaseBuilder.schemaVersion}, which declares the same
|
|
614
|
+
* concept and accepts only versions this build can actually write. This call
|
|
615
|
+
* was never a switch: it recorded a requested version that `check()` then
|
|
616
|
+
* compared against the serializer's profile.
|
|
617
|
+
* @param v - The legacy requested schema version.
|
|
618
|
+
* @returns This builder, so calls chain.
|
|
619
|
+
*/
|
|
620
|
+
version(v) {
|
|
621
|
+
this._authoredVersion = v;
|
|
622
|
+
return this;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Declare the Case JSON SCHEMA version this plan targets.
|
|
626
|
+
*
|
|
627
|
+
* @remarks
|
|
628
|
+
* The top-level `version` of a `caseplan.json` is a claim that the whole
|
|
629
|
+
* document matches that grammar — `@uipath/case-schema` ships one closed
|
|
630
|
+
* schema per version — so this accepts only what the serializer can emit,
|
|
631
|
+
* currently `30.0.0` alone. Omit it and the plan declares the same thing;
|
|
632
|
+
* declaring it explicitly is what lets `case-decompile` PRESERVE the version
|
|
633
|
+
* it read rather than re-stamping the SDK's own default, so a later write-floor
|
|
634
|
+
* bump cannot silently upgrade a document a decompile already captured.
|
|
635
|
+
*
|
|
636
|
+
* Case has no `migrate` command: documents move forward on read, through the
|
|
637
|
+
* platform's feature-flag-gated chain. An older version is therefore refused
|
|
638
|
+
* with the reason rather than written onto V30 bytes.
|
|
639
|
+
*
|
|
640
|
+
* @example
|
|
641
|
+
* ```ts
|
|
642
|
+
* casePlan('claims').schemaVersion('30.0.0')
|
|
643
|
+
* ```
|
|
644
|
+
*
|
|
645
|
+
* @param version - A writable Case JSON schema version, e.g. `'30.0.0'`.
|
|
646
|
+
* @returns This builder, so calls chain.
|
|
647
|
+
* @throws Error when this SDK build cannot write `version`.
|
|
648
|
+
* @defaultValue `'30.0.0'` — `CASE_FORMAT_PROFILE.writeVersion`.
|
|
649
|
+
*/
|
|
650
|
+
schemaVersion(version) {
|
|
651
|
+
const refusal = schemaVersionRefusal(CASE_SCHEMA_VERSIONS, version);
|
|
652
|
+
if (refusal)
|
|
653
|
+
throw new Error(refusal);
|
|
654
|
+
this._schemaVersion = version;
|
|
655
|
+
return this;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Describe the case plan.
|
|
659
|
+
*
|
|
660
|
+
* @param text - Prose the designer shows alongside the plan.
|
|
661
|
+
* @returns This builder, so calls chain.
|
|
662
|
+
*/
|
|
663
|
+
description(text) {
|
|
664
|
+
this._description = text;
|
|
665
|
+
return this;
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Set the runtime case identifier (constant prefix, or an `=`-expression when type is `external`).
|
|
669
|
+
*
|
|
670
|
+
* @param id - The prefix, or an `=`-expression when `type` is `'external'`.
|
|
671
|
+
* @param type - `'constant'` for a fixed prefix, `'external'` to compute it.
|
|
672
|
+
* @returns This builder, so calls chain.
|
|
673
|
+
*/
|
|
674
|
+
identifier(id, type = 'constant') {
|
|
675
|
+
this._identifier = id;
|
|
676
|
+
this._identifierType = type;
|
|
677
|
+
return this;
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Turn the generated Case App on or off, or configure its summary and sections.
|
|
681
|
+
*
|
|
682
|
+
* Section `details` are authored as a map of at most six primitive values; the
|
|
683
|
+
* serializer JSON-encodes that map into the shipped wire string. Configuring a
|
|
684
|
+
* Case App enables it. The platform-owned Case App version markers are never
|
|
685
|
+
* inferred by this method.
|
|
686
|
+
*
|
|
687
|
+
* @example
|
|
688
|
+
* **Configure a summary and one detail section**
|
|
689
|
+
* ```ts
|
|
690
|
+
* .caseApp({
|
|
691
|
+
* summary: '=js:vars.summary',
|
|
692
|
+
* sections: [{ title: 'Amounts', details: { total: '=js:vars.total', urgent: true } }],
|
|
693
|
+
* })
|
|
694
|
+
* ```
|
|
695
|
+
*
|
|
696
|
+
* @param enabledOrConfig - A boolean toggle, or the typed Case App configuration.
|
|
697
|
+
* @returns This builder, so calls chain.
|
|
698
|
+
*/
|
|
699
|
+
caseApp(enabledOrConfig = true) {
|
|
700
|
+
if (typeof enabledOrConfig === 'boolean') {
|
|
701
|
+
this._caseApp = enabledOrConfig;
|
|
702
|
+
}
|
|
703
|
+
else {
|
|
704
|
+
this._caseApp = true;
|
|
705
|
+
this._caseAppConfig = enabledOrConfig;
|
|
706
|
+
}
|
|
707
|
+
return this;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Enable optional tasks whose entry rule is `adhoc`, allowing them to be
|
|
711
|
+
* started through the Case ad-hoc message contract.
|
|
712
|
+
*
|
|
713
|
+
* @param enabled - Whether ad-hoc optional-stage tasks are enabled.
|
|
714
|
+
* @returns This builder, so calls chain.
|
|
715
|
+
*/
|
|
716
|
+
allowAdhocTasks(enabled = true) {
|
|
717
|
+
this._allowAdhocTasks = enabled;
|
|
718
|
+
return this;
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Set optional designer layout for stages and triggers by their author-level
|
|
722
|
+
* names. This metadata does not affect Case behavior. Unknown or ambiguous
|
|
723
|
+
* names fail serialization rather than being silently dropped.
|
|
724
|
+
*
|
|
725
|
+
* When editing a decompiled foreign Case, an authored field wins only for the
|
|
726
|
+
* named node and field; all other preserved layout bytes remain untouched.
|
|
727
|
+
*
|
|
728
|
+
* @example
|
|
729
|
+
* **Move a stage and a named trigger**
|
|
730
|
+
* ```ts
|
|
731
|
+
* .layout({
|
|
732
|
+
* stages: { Intake: { position: { x: 160, y: 120 } } },
|
|
733
|
+
* triggers: { 'Order received': { position: { x: 40, y: 120 } } },
|
|
734
|
+
* })
|
|
735
|
+
* ```
|
|
736
|
+
*
|
|
737
|
+
* @param layout - Stage and trigger layout keyed by their exact display names.
|
|
738
|
+
* @returns This builder, so calls chain.
|
|
739
|
+
*/
|
|
740
|
+
layout(layout) {
|
|
741
|
+
this._layout = layout;
|
|
742
|
+
return this;
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Declare case In-args. Each value is a {@link TypeDesc}, or `{ type, default }`
|
|
746
|
+
* to set a default. Pass `{ from: <trigger> }` to bind the args to a trigger —
|
|
747
|
+
* their value arrives when it fires, readable as `=vars.<name>` — and they are
|
|
748
|
+
* projected into that trigger's `entry-points.json` input schema. A declared
|
|
749
|
+
* In-arg is readable as `=vars.<name>` (its `inputOutputs` companion resolves it).
|
|
750
|
+
*
|
|
751
|
+
* @example
|
|
752
|
+
* **Bind case In-args to a trigger's payload**
|
|
753
|
+
* ```ts
|
|
754
|
+
* const t = manualTrigger();
|
|
755
|
+
* casePlan('x').trigger(t)
|
|
756
|
+
* .input({ claimId: 'string', riskScore: { type: 'float', default: '1.5' } }, { from: t })
|
|
757
|
+
* ```
|
|
758
|
+
*
|
|
759
|
+
* @param shape - In-arg names to types, or `{ type, default }`.
|
|
760
|
+
* @param opts - `{ from: <trigger> }` binds the args to a trigger's payload.
|
|
761
|
+
* @returns This builder, so calls chain.
|
|
762
|
+
*/
|
|
763
|
+
input(shape, opts = {}) {
|
|
764
|
+
for (const [name, spec] of Object.entries(shape)) {
|
|
765
|
+
const { type, default: def, body } = normVarSpec(spec);
|
|
766
|
+
this._vars.push({ name, type, direction: 'in', default: def, body, sourceTrigger: opts.from });
|
|
767
|
+
}
|
|
768
|
+
return this;
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* Declare case Out-args. Each value is a {@link TypeDesc}, or `{ type, default }`
|
|
772
|
+
* to set a default. Out-args are readable as `=vars.<name>` and projected into
|
|
773
|
+
* every trigger's `entry-points.json` output schema (with their default).
|
|
774
|
+
*
|
|
775
|
+
* @param shape - Out-arg names to types, or `{ type, default }`.
|
|
776
|
+
* @returns This builder, so calls chain.
|
|
777
|
+
*/
|
|
778
|
+
output(shape) {
|
|
779
|
+
for (const [name, spec] of Object.entries(shape)) {
|
|
780
|
+
const { type, default: def, body } = normVarSpec(spec);
|
|
781
|
+
this._vars.push({ name, type, direction: 'out', default: def, body });
|
|
782
|
+
}
|
|
783
|
+
return this;
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Declare a read/write case variable.
|
|
787
|
+
*
|
|
788
|
+
* @remarks
|
|
789
|
+
* Readable from a `=js:vars.<name>` expression, like a trigger-bound In-arg.
|
|
790
|
+
*
|
|
791
|
+
* This comment used to say the opposite — that only `.input(shape, { from })`
|
|
792
|
+
* could be read, and that a bare `.var()` failed `uip maestro case validate`
|
|
793
|
+
* with "Variable 'vars.<name>' does not exist". That was true when written and
|
|
794
|
+
* stopped being true at #257, which made the serializer emit the `inputOutputs`
|
|
795
|
+
* companion (`id: <name>`, `elementId: "root"`) the platform resolves
|
|
796
|
+
* `vars.<name>` against. `check` carried a matching `VAR_NOT_REFERENCEABLE`
|
|
797
|
+
* error and dropped it for the same reason.
|
|
798
|
+
*
|
|
799
|
+
* Binding is about WHEN a value arrives, not whether it can be read. An
|
|
800
|
+
* UNDECLARED `vars.<x>` is still a hard error, thrown by `.build()`.
|
|
801
|
+
*
|
|
802
|
+
* @param name - The variable's name; read it as `=vars.<name>`.
|
|
803
|
+
* @param type - A `types.*` descriptor, or {@link jsonSchema} for a structured one.
|
|
804
|
+
* @param defaultValue - Its initial value. Non-string values are JSON-encoded
|
|
805
|
+
* before emission because the Case artifact contract stores every default as
|
|
806
|
+
* a string. Omit it to start unset.
|
|
807
|
+
* @returns This builder, so calls chain.
|
|
808
|
+
*/
|
|
809
|
+
var(name, type, defaultValue) {
|
|
810
|
+
const { type: t, body } = normVarSpec(type);
|
|
811
|
+
this._vars.push({ name, type: t, direction: 'inout', default: defaultValue, body });
|
|
812
|
+
return this;
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* Add a case trigger (what starts the case). Call more than once for
|
|
816
|
+
* multiple triggers; the first is the primary. Omit entirely for the default
|
|
817
|
+
* single manual trigger. Build specs with {@link manualTrigger}/{@link timerTrigger}.
|
|
818
|
+
*
|
|
819
|
+
* @param t - A trigger from `manualTrigger` / `timerTrigger` / `eventTrigger`.
|
|
820
|
+
* @returns This builder, so calls chain.
|
|
821
|
+
*/
|
|
822
|
+
trigger(t) {
|
|
823
|
+
this._triggers.push(t);
|
|
824
|
+
return this;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Add a primary stage. `fn` receives a stage sub-builder.
|
|
828
|
+
*
|
|
829
|
+
* @param label - The stage's display name.
|
|
830
|
+
* @param fn - Receives a sub-builder for the stage's tasks and conditions.
|
|
831
|
+
* @returns This builder, so calls chain.
|
|
832
|
+
*/
|
|
833
|
+
stage(label, fn) {
|
|
834
|
+
const sb = new StageBuilder(label, false);
|
|
835
|
+
fn(sb);
|
|
836
|
+
this._stages.push(sb._build());
|
|
837
|
+
return this;
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* Add a secondary/exception stage (`case-management:Stage` with `data.stageType: "secondary"`).
|
|
841
|
+
*
|
|
842
|
+
* @param label - The stage's display name.
|
|
843
|
+
* @param fn - Receives a sub-builder for the stage's tasks and conditions.
|
|
844
|
+
* @returns This builder, so calls chain.
|
|
845
|
+
*/
|
|
846
|
+
exceptionStage(label, fn) {
|
|
847
|
+
const sb = new StageBuilder(label, true);
|
|
848
|
+
fn(sb);
|
|
849
|
+
this._stages.push(sb._build());
|
|
850
|
+
return this;
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Add a case-completion rule (`metadata.caseExitRules`, `marksCaseComplete: true` by default).
|
|
854
|
+
*
|
|
855
|
+
* @param rules - One rule, an AND-group, or the complete OR-of-AND grid.
|
|
856
|
+
* @param opts - `displayName`, and whether meeting it completes the case.
|
|
857
|
+
* @returns This builder, so calls chain.
|
|
858
|
+
*/
|
|
859
|
+
completeWhen(rules, opts = {}) {
|
|
860
|
+
this._caseExit.push({
|
|
861
|
+
displayName: opts.displayName,
|
|
862
|
+
marksCaseComplete: opts.marksCaseComplete ?? true,
|
|
863
|
+
rules: ruleGroups(rules, 'case-exit'),
|
|
864
|
+
});
|
|
865
|
+
return this;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Set a case-level SLA (deadline + escalations for the whole case), emitted to
|
|
869
|
+
* `metadata.slaRules`. Call more than once for conditional SLAs; the default
|
|
870
|
+
* (no `when`) must be last.
|
|
871
|
+
*
|
|
872
|
+
* @param opts - The deadline, its escalations, and an optional `when` gate.
|
|
873
|
+
* @returns This builder, so calls chain.
|
|
874
|
+
*/
|
|
875
|
+
sla(opts) {
|
|
876
|
+
this._sla.push(buildSla(opts));
|
|
877
|
+
return this;
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Finish the plan and return the description the serializer writes.
|
|
881
|
+
*
|
|
882
|
+
* @returns The built case — its stages, tasks, triggers and variables.
|
|
883
|
+
*/
|
|
884
|
+
build() {
|
|
885
|
+
const built = {
|
|
886
|
+
id: this._id,
|
|
887
|
+
name: this._name,
|
|
888
|
+
version: this._schemaVersion ?? CASE_FORMAT_PROFILE.writeVersion,
|
|
889
|
+
description: this._description,
|
|
890
|
+
identifier: this._identifier ?? this._name,
|
|
891
|
+
identifierType: this._identifierType,
|
|
892
|
+
caseAppEnabled: this._caseApp,
|
|
893
|
+
...(this._caseAppConfig ? { caseAppConfig: this._caseAppConfig } : {}),
|
|
894
|
+
...(this._allowAdhocTasks !== undefined
|
|
895
|
+
? { allowAdhocOptionalStageTasks: this._allowAdhocTasks }
|
|
896
|
+
: {}),
|
|
897
|
+
vars: this._vars,
|
|
898
|
+
stages: this._stages,
|
|
899
|
+
caseExit: this._caseExit,
|
|
900
|
+
slaRules: this._sla,
|
|
901
|
+
triggers: this._triggers,
|
|
902
|
+
...(this._layout ? { layout: this._layout } : {}),
|
|
903
|
+
};
|
|
904
|
+
if (this._authoredVersion !== undefined)
|
|
905
|
+
recordAuthoredCaseVersion(built, this._authoredVersion);
|
|
906
|
+
// First-level validation, intrinsic to running the SDK: catch a reference to
|
|
907
|
+
// an undeclared `vars.<name>` HERE, before the caseplan is serialized, rather
|
|
908
|
+
// than three steps later at `uip maestro case validate`. See case-expr-check.
|
|
909
|
+
const errors = checkCaseExpressions(built).filter((d) => d.level === 'error');
|
|
910
|
+
if (errors.length)
|
|
911
|
+
throw new CaseBuildError(built, errors);
|
|
912
|
+
return built;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Start building a case plan with the given id. (`casePlan`, not `case` — reserved word.)
|
|
917
|
+
*
|
|
918
|
+
* @param id - The plan's stable identifier.
|
|
919
|
+
* @returns A {@link CaseBuilder} to declare stages and tasks on.
|
|
920
|
+
*/
|
|
921
|
+
export function casePlan(id) {
|
|
922
|
+
return new CaseBuilder(id);
|
|
923
|
+
}
|