@servicenow/sdk-build-plugins 4.5.0 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/column-plugin.js +3 -7
- package/dist/column-plugin.js.map +1 -1
- package/dist/flow/flow-logic/flow-logic-diagnostics.js +5 -5
- package/dist/flow/flow-logic/flow-logic-diagnostics.js.map +1 -1
- package/dist/flow/plugins/flow-action-definition-plugin.js +1229 -54
- package/dist/flow/plugins/flow-action-definition-plugin.js.map +1 -1
- package/dist/flow/plugins/flow-data-pill-plugin.js +5 -2
- package/dist/flow/plugins/flow-data-pill-plugin.js.map +1 -1
- package/dist/flow/plugins/flow-definition-plugin.js +16 -42
- package/dist/flow/plugins/flow-definition-plugin.js.map +1 -1
- package/dist/flow/plugins/flow-diagnostics-plugin.d.ts +2 -2
- package/dist/flow/plugins/flow-diagnostics-plugin.js +2 -2
- package/dist/flow/plugins/flow-instance-plugin.js +68 -22
- package/dist/flow/plugins/flow-instance-plugin.js.map +1 -1
- package/dist/flow/plugins/step-definition-plugin.js +2 -1
- package/dist/flow/plugins/step-definition-plugin.js.map +1 -1
- package/dist/flow/plugins/step-instance-plugin.d.ts +9 -1
- package/dist/flow/plugins/step-instance-plugin.js +649 -136
- package/dist/flow/plugins/step-instance-plugin.js.map +1 -1
- package/dist/flow/plugins/wfa-datapill-plugin.js +20 -5
- package/dist/flow/plugins/wfa-datapill-plugin.js.map +1 -1
- package/dist/flow/post-install.js +1 -0
- package/dist/flow/post-install.js.map +1 -1
- package/dist/flow/utils/complex-object-resolver.js +4 -1
- package/dist/flow/utils/complex-object-resolver.js.map +1 -1
- package/dist/flow/utils/complex-objects.js +1 -1
- package/dist/flow/utils/complex-objects.js.map +1 -1
- package/dist/flow/utils/flow-constants.d.ts +66 -2
- package/dist/flow/utils/flow-constants.js +402 -6
- package/dist/flow/utils/flow-constants.js.map +1 -1
- package/dist/flow/utils/flow-io-to-record.d.ts +1 -1
- package/dist/flow/utils/flow-io-to-record.js +37 -16
- package/dist/flow/utils/flow-io-to-record.js.map +1 -1
- package/dist/flow/utils/flow-shapes.js +4 -0
- package/dist/flow/utils/flow-shapes.js.map +1 -1
- package/dist/flow/utils/label-cache-parser.d.ts +9 -2
- package/dist/flow/utils/label-cache-parser.js +32 -4
- package/dist/flow/utils/label-cache-parser.js.map +1 -1
- package/dist/flow/utils/pill-shape-helpers.d.ts +15 -0
- package/dist/flow/utils/pill-shape-helpers.js +35 -0
- package/dist/flow/utils/pill-shape-helpers.js.map +1 -0
- package/dist/flow/utils/pill-string-parser.js +1 -0
- package/dist/flow/utils/pill-string-parser.js.map +1 -1
- package/dist/flow/utils/schema-to-flow-object.d.ts +6 -1
- package/dist/flow/utils/schema-to-flow-object.js +131 -15
- package/dist/flow/utils/schema-to-flow-object.js.map +1 -1
- package/dist/flow/utils/utils.d.ts +1 -0
- package/dist/flow/utils/utils.js +6 -1
- package/dist/flow/utils/utils.js.map +1 -1
- package/dist/form-plugin.js +7 -9
- package/dist/form-plugin.js.map +1 -1
- package/dist/inbound-email-action-plugin.d.ts +10 -0
- package/dist/inbound-email-action-plugin.js +128 -0
- package/dist/inbound-email-action-plugin.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/instance-scan-plugin.js +0 -5
- package/dist/instance-scan-plugin.js.map +1 -1
- package/dist/property-plugin.js +1 -1
- package/dist/property-plugin.js.map +1 -1
- package/dist/record-plugin.d.ts +7 -0
- package/dist/record-plugin.js +10 -2
- package/dist/record-plugin.js.map +1 -1
- package/dist/rest-api-plugin.js +8 -1
- package/dist/rest-api-plugin.js.map +1 -1
- package/dist/schedule-script/scheduled-script-plugin.js +8 -3
- package/dist/schedule-script/scheduled-script-plugin.js.map +1 -1
- package/dist/service-catalog/service-catalog-base.d.ts +18 -18
- package/dist/service-catalog/service-catalog-base.js +22 -22
- package/dist/service-catalog/service-catalog-base.js.map +1 -1
- package/dist/service-portal/header-footer-plugin.d.ts +2 -0
- package/dist/service-portal/header-footer-plugin.js +50 -0
- package/dist/service-portal/header-footer-plugin.js.map +1 -0
- package/dist/service-portal/menu-plugin.js +3 -22
- package/dist/service-portal/menu-plugin.js.map +1 -1
- package/dist/service-portal/page-plugin.js +3 -24
- package/dist/service-portal/page-plugin.js.map +1 -1
- package/dist/service-portal/page-route-map-plugin.d.ts +2 -0
- package/dist/service-portal/page-route-map-plugin.js +114 -0
- package/dist/service-portal/page-route-map-plugin.js.map +1 -0
- package/dist/service-portal/portal-plugin.js +21 -8
- package/dist/service-portal/portal-plugin.js.map +1 -1
- package/dist/service-portal/utils.d.ts +40 -2
- package/dist/service-portal/utils.js +283 -2
- package/dist/service-portal/utils.js.map +1 -1
- package/dist/service-portal/widget-plugin.js +9 -218
- package/dist/service-portal/widget-plugin.js.map +1 -1
- package/dist/static-content-plugin.js +4 -0
- package/dist/static-content-plugin.js.map +1 -1
- package/dist/table-plugin.js +190 -26
- package/dist/table-plugin.js.map +1 -1
- package/dist/ui-action-plugin.js +1 -4
- package/dist/ui-action-plugin.js.map +1 -1
- package/dist/ui-page-plugin.js +68 -13
- package/dist/ui-page-plugin.js.map +1 -1
- package/dist/view-plugin.js +8 -3
- package/dist/view-plugin.js.map +1 -1
- package/dist/workspace-plugin.js +39 -36
- package/dist/workspace-plugin.js.map +1 -1
- package/package.json +5 -4
- package/src/column-plugin.ts +3 -8
- package/src/flow/flow-logic/flow-logic-diagnostics.ts +5 -6
- package/src/flow/plugins/flow-action-definition-plugin.ts +1581 -61
- package/src/flow/plugins/flow-data-pill-plugin.ts +5 -2
- package/src/flow/plugins/flow-definition-plugin.ts +12 -47
- package/src/flow/plugins/flow-diagnostics-plugin.ts +2 -2
- package/src/flow/plugins/flow-instance-plugin.ts +98 -22
- package/src/flow/plugins/step-definition-plugin.ts +2 -1
- package/src/flow/plugins/step-instance-plugin.ts +772 -156
- package/src/flow/plugins/wfa-datapill-plugin.ts +25 -5
- package/src/flow/post-install.ts +1 -0
- package/src/flow/utils/complex-object-resolver.ts +4 -1
- package/src/flow/utils/complex-objects.ts +1 -1
- package/src/flow/utils/flow-constants.ts +421 -5
- package/src/flow/utils/flow-io-to-record.ts +43 -17
- package/src/flow/utils/flow-shapes.ts +4 -0
- package/src/flow/utils/label-cache-parser.ts +33 -4
- package/src/flow/utils/pill-shape-helpers.ts +42 -0
- package/src/flow/utils/pill-string-parser.ts +1 -0
- package/src/flow/utils/schema-to-flow-object.ts +183 -15
- package/src/flow/utils/utils.ts +12 -1
- package/src/form-plugin.ts +1 -3
- package/src/inbound-email-action-plugin.ts +145 -0
- package/src/index.ts +4 -0
- package/src/instance-scan-plugin.ts +0 -5
- package/src/property-plugin.ts +4 -1
- package/src/record-plugin.ts +14 -4
- package/src/rest-api-plugin.ts +7 -1
- package/src/schedule-script/scheduled-script-plugin.ts +14 -3
- package/src/service-catalog/service-catalog-base.ts +22 -22
- package/src/service-portal/header-footer-plugin.ts +57 -0
- package/src/service-portal/menu-plugin.ts +1 -23
- package/src/service-portal/page-plugin.ts +3 -28
- package/src/service-portal/page-route-map-plugin.ts +124 -0
- package/src/service-portal/portal-plugin.ts +33 -10
- package/src/service-portal/utils.ts +404 -3
- package/src/service-portal/widget-plugin.ts +14 -290
- package/src/static-content-plugin.ts +3 -0
- package/src/table-plugin.ts +226 -36
- package/src/ui-action-plugin.ts +1 -8
- package/src/ui-page-plugin.ts +76 -13
- package/src/view-plugin.ts +10 -4
- package/src/workspace-plugin.ts +43 -43
|
@@ -2,14 +2,148 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StepInstancePlugin = exports.StepInstanceShape = void 0;
|
|
4
4
|
const sdk_build_core_1 = require("@servicenow/sdk-build-core");
|
|
5
|
+
const now_id_plugin_1 = require("../../now-id-plugin");
|
|
5
6
|
const utils_1 = require("../utils/utils");
|
|
6
7
|
const column_helper_1 = require("../../column/column-helper");
|
|
7
8
|
const flow_constants_1 = require("../utils/flow-constants");
|
|
9
|
+
const flow_instance_plugin_1 = require("./flow-instance-plugin");
|
|
10
|
+
const flow_shapes_1 = require("../utils/flow-shapes");
|
|
11
|
+
const utils_2 = require("../../utils");
|
|
12
|
+
const complex_objects_1 = require("../utils/complex-objects");
|
|
13
|
+
const data_pill_shapes_1 = require("../utils/data-pill-shapes");
|
|
14
|
+
const utils_3 = require("../utils/utils");
|
|
8
15
|
// Error handling type mapping: string to number
|
|
9
16
|
const ERROR_HANDLING_TYPE_MAP = {
|
|
10
17
|
stop_the_action: 1,
|
|
11
18
|
dont_stop_the_action: 2,
|
|
12
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Resolves a TemplateValue field shape to a datapill string (e.g., "{{action.desc|string}}").
|
|
22
|
+
* Handles two cases:
|
|
23
|
+
* 1. Already resolved PillShape — call getValue() directly
|
|
24
|
+
* 2. Unresolved wfa.dataPill() CallExpressionShape — extract pill info from arguments
|
|
25
|
+
* @param cidMap - Optional map of step variable name → CID for direct lookup (avoids AST walking)
|
|
26
|
+
* Returns undefined if the field is not a datapill.
|
|
27
|
+
*/
|
|
28
|
+
function resolveFieldToPillString(fieldShape, cidMap) {
|
|
29
|
+
// Case 1: Already a PillShape (e.g., processed by the datapill plugin)
|
|
30
|
+
if (fieldShape instanceof data_pill_shapes_1.PillShape) {
|
|
31
|
+
return fieldShape.getValue();
|
|
32
|
+
}
|
|
33
|
+
// Case 2: Unresolved wfa.dataPill(expression, type) CallExpressionShape
|
|
34
|
+
if (fieldShape instanceof sdk_build_core_1.CallExpressionShape) {
|
|
35
|
+
const callee = fieldShape.getCallee();
|
|
36
|
+
if (callee !== 'wfa.dataPill') {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const typeArg = fieldShape.getArgument(1);
|
|
40
|
+
// Extract property path — try Shape API first, then AST node directly
|
|
41
|
+
const propertyNames = [];
|
|
42
|
+
const expressionArg = fieldShape.getArgument(0, false); // 0, false
|
|
43
|
+
if (expressionArg instanceof sdk_build_core_1.PropertyAccessShape) {
|
|
44
|
+
expressionArg.getElements().forEach((el) => {
|
|
45
|
+
if (el instanceof sdk_build_core_1.IdentifierShape) {
|
|
46
|
+
propertyNames.push(el.getName());
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (propertyNames.length < 2) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
let prefix = 'action';
|
|
54
|
+
let pathParts;
|
|
55
|
+
if (propertyNames[1] === 'inputs') {
|
|
56
|
+
// params.inputs.xxx → action pill
|
|
57
|
+
const originalNode = fieldShape.getOriginalNode?.();
|
|
58
|
+
if (originalNode) {
|
|
59
|
+
const actionAncestor = (0, utils_3.findAncestorByCalleeName)(originalNode, 'Action');
|
|
60
|
+
prefix = actionAncestor ? 'action' : 'subflow';
|
|
61
|
+
}
|
|
62
|
+
pathParts = propertyNames.slice(2);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// Could be a step variable reference: create_record_step.record.short_description
|
|
66
|
+
// Resolve CID via cidMap lookup (O(1))
|
|
67
|
+
const varName = propertyNames[0];
|
|
68
|
+
const stepCid = varName ? cidMap?.get(varName) : undefined;
|
|
69
|
+
if (stepCid) {
|
|
70
|
+
prefix = `step[${stepCid}]`;
|
|
71
|
+
pathParts = propertyNames.slice(1);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
// Cannot resolve step CID — return undefined so the caller can handle the failure
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const dataType = typeArg?.ifString()?.getValue();
|
|
79
|
+
const typeSuffix = dataType ? `|${dataType}` : '';
|
|
80
|
+
return `{{${prefix}.${pathParts.join('.')}${typeSuffix}}}`;
|
|
81
|
+
}
|
|
82
|
+
// Case 3: Already a resolved pill string
|
|
83
|
+
const val = fieldShape.getValue();
|
|
84
|
+
if (typeof val === 'string' && val.startsWith('{{') && val.endsWith('}}')) {
|
|
85
|
+
return val;
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Extracts pill type annotations from a pill string and stores them in the pillTypeMap.
|
|
91
|
+
* Captures types from both step pills ({{step[CID].path|type}}) and action pills
|
|
92
|
+
* ({{action.path|type}}). The "|type" portion is captured before it gets stripped
|
|
93
|
+
* for the element_mapping value. The collected types are used later when building the label_cache.
|
|
94
|
+
*/
|
|
95
|
+
const STEP_PILL_TYPE_REGEX = /\{\{step\[([^\]]+)\]\.([^|}]+)(?:\|([^}]+))?\}\}/g;
|
|
96
|
+
const ACTION_PILL_TYPE_REGEX = /\{\{action\.([^|}]+)(?:\|([^}]+))?\}\}/g;
|
|
97
|
+
function collectPillTypes(pillString, pillTypeMap) {
|
|
98
|
+
if (!pillTypeMap) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
for (const match of pillString.matchAll(STEP_PILL_TYPE_REGEX)) {
|
|
102
|
+
const [, cid, pillPath, dataType] = match;
|
|
103
|
+
if (cid && pillPath && dataType) {
|
|
104
|
+
pillTypeMap.set(`${cid}::${pillPath}`, dataType);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
for (const match of pillString.matchAll(ACTION_PILL_TYPE_REGEX)) {
|
|
108
|
+
const [, path, dataType] = match;
|
|
109
|
+
if (path && dataType) {
|
|
110
|
+
pillTypeMap.set(`action::${path}`, dataType);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Strips the |type suffix from a pill string.
|
|
116
|
+
* e.g., "{{action.desc|string}}" → "{{action.desc}}"
|
|
117
|
+
*
|
|
118
|
+
* Note: This is called on individual pill strings (from resolveFieldToPillString),
|
|
119
|
+
* never on concatenated multi-pill strings — so no `g` flag is needed.
|
|
120
|
+
*/
|
|
121
|
+
function stripPillType(pill) {
|
|
122
|
+
return pill.replace(/\|[^}]+/, '');
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Resolves a TemplateExpressionShape into a concatenated string, replacing
|
|
126
|
+
* datapill spans with their pill strings (type-stripped) and collecting pill types.
|
|
127
|
+
* Returns the resolved string and whether any pills were found.
|
|
128
|
+
*/
|
|
129
|
+
function resolveTemplateExpression(templateShape, cidMap, pillTypeMap) {
|
|
130
|
+
let result = templateShape.getLiteralText();
|
|
131
|
+
let hasPills = false;
|
|
132
|
+
for (const span of templateShape.getSpans()) {
|
|
133
|
+
const expr = span.getExpression();
|
|
134
|
+
const pillStr = resolveFieldToPillString(expr, cidMap);
|
|
135
|
+
if (pillStr) {
|
|
136
|
+
collectPillTypes(pillStr, pillTypeMap);
|
|
137
|
+
result += stripPillType(pillStr);
|
|
138
|
+
hasPills = true;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
result += String(expr.getValue?.() ?? '');
|
|
142
|
+
}
|
|
143
|
+
result += span.getLiteralText();
|
|
144
|
+
}
|
|
145
|
+
return { result, hasPills };
|
|
146
|
+
}
|
|
13
147
|
/**
|
|
14
148
|
* StepInstanceShape represents a step instance within a custom action's body
|
|
15
149
|
* This class handles the shape transformation for step instances
|
|
@@ -21,9 +155,13 @@ class StepInstanceShape extends sdk_build_core_1.CallExpressionShape {
|
|
|
21
155
|
stepLabel;
|
|
22
156
|
inputs;
|
|
23
157
|
inputDefinitions;
|
|
158
|
+
/** Map of step variable name → CID, set by ActionDefinitionPlugin for step pill resolution in Action() bodies */
|
|
159
|
+
_cidMap;
|
|
160
|
+
/** Map of "CID::pillPath" → dataType, populated during toRecord for label_cache type propagation */
|
|
161
|
+
_pillTypeMap;
|
|
24
162
|
constructor(args) {
|
|
25
163
|
const { source, sysId, config, stepDefinitionSysId, stepLabel, inputs, inputDefinitions } = args;
|
|
26
|
-
super({ source, callee: '
|
|
164
|
+
super({ source, callee: 'wfa.actionStep', args: [sysId, config, stepDefinitionSysId] });
|
|
27
165
|
this.config = config;
|
|
28
166
|
this.sysId = sysId;
|
|
29
167
|
this.stepDefinitionSysId = stepDefinitionSysId;
|
|
@@ -49,11 +187,23 @@ class StepInstanceShape extends sdk_build_core_1.CallExpressionShape {
|
|
|
49
187
|
getInputDefinitions() {
|
|
50
188
|
return this.inputDefinitions;
|
|
51
189
|
}
|
|
190
|
+
setCidMap(cidMap) {
|
|
191
|
+
this._cidMap = cidMap;
|
|
192
|
+
}
|
|
193
|
+
getCidMap() {
|
|
194
|
+
return this._cidMap;
|
|
195
|
+
}
|
|
196
|
+
setPillTypeMap(pillTypeMap) {
|
|
197
|
+
this._pillTypeMap = pillTypeMap;
|
|
198
|
+
}
|
|
199
|
+
getPillTypeMap() {
|
|
200
|
+
return this._pillTypeMap;
|
|
201
|
+
}
|
|
52
202
|
}
|
|
53
203
|
exports.StepInstanceShape = StepInstanceShape;
|
|
54
204
|
exports.StepInstancePlugin = sdk_build_core_1.Plugin.create({
|
|
55
205
|
name: 'StepInstancePlugin',
|
|
56
|
-
docs: [],
|
|
206
|
+
docs: [(0, utils_2.createSdkDocEntry)('wfa.actionStep', ['sys_hub_step_instance'])],
|
|
57
207
|
shapes: [
|
|
58
208
|
{
|
|
59
209
|
shape: sdk_build_core_1.CallExpressionShape,
|
|
@@ -69,10 +219,8 @@ exports.StepInstancePlugin = sdk_build_core_1.Plugin.create({
|
|
|
69
219
|
return { success: false };
|
|
70
220
|
}
|
|
71
221
|
const [stepDefinition, stepInstanceConfig, inputs] = args;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
stepDefinition.getCallee() !== 'ActionStepDefinition') {
|
|
75
|
-
diagnostics.error(callExpression, 'Expected first argument to be a ActionStepDefinition');
|
|
222
|
+
if (!stepDefinition) {
|
|
223
|
+
diagnostics.error(callExpression, 'Missing step definition argument');
|
|
76
224
|
return { success: false };
|
|
77
225
|
}
|
|
78
226
|
// Validate second argument is a valid ID
|
|
@@ -85,15 +233,55 @@ exports.StepInstancePlugin = sdk_build_core_1.Plugin.create({
|
|
|
85
233
|
diagnostics.error(callExpression, 'Expected third argument to be an object');
|
|
86
234
|
return { success: false };
|
|
87
235
|
}
|
|
88
|
-
|
|
236
|
+
let stepDefinitionSysId;
|
|
237
|
+
let stepLabel;
|
|
238
|
+
let inputDefinitions;
|
|
239
|
+
// First argument can be a string (built-in step name), IdentifierShape (actionStep.xxx),
|
|
240
|
+
// or ActionStepDefinition() call
|
|
241
|
+
const stepNameValue = stepDefinition.ifString()?.getValue();
|
|
242
|
+
if (stepNameValue) {
|
|
243
|
+
// Built-in step referenced by name string
|
|
244
|
+
stepDefinitionSysId = flow_constants_1.BUILT_IN_STEP_NAME_TO_SYSID[stepNameValue] ?? '';
|
|
245
|
+
stepLabel = stepNameValue;
|
|
246
|
+
if (!stepDefinitionSysId) {
|
|
247
|
+
diagnostics.error(callExpression, `Unknown built-in step type '${stepNameValue}'`);
|
|
248
|
+
return { success: false };
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
else if (stepDefinition instanceof sdk_build_core_1.IdentifierShape) {
|
|
252
|
+
// Built-in step referenced via actionStep.xxx identifier
|
|
253
|
+
const identifierName = stepDefinition.getName();
|
|
254
|
+
const prefix = `${flow_constants_1.BUILT_IN_STEP_PREFIX}.`;
|
|
255
|
+
const resolvedName = identifierName.startsWith(prefix)
|
|
256
|
+
? identifierName.slice(prefix.length)
|
|
257
|
+
: identifierName;
|
|
258
|
+
stepDefinitionSysId = flow_constants_1.BUILT_IN_STEP_NAME_TO_SYSID[resolvedName] ?? '';
|
|
259
|
+
stepLabel = resolvedName;
|
|
260
|
+
if (!stepDefinitionSysId) {
|
|
261
|
+
diagnostics.error(callExpression, `Unknown built-in step type '${identifierName}'`);
|
|
262
|
+
return { success: false };
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
else if (stepDefinition instanceof sdk_build_core_1.CallExpressionShape &&
|
|
266
|
+
stepDefinition.getCallee() === 'ActionStepDefinition') {
|
|
267
|
+
// Custom step definition
|
|
268
|
+
const stepConfig = stepDefinition.getArgument(0).asObject();
|
|
269
|
+
stepDefinitionSysId = stepConfig.get('$id')?.getValue();
|
|
270
|
+
stepLabel = stepConfig.get('name')?.getValue();
|
|
271
|
+
inputDefinitions = stepConfig.get('inputs')?.ifObject()?.asObject();
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
diagnostics.error(callExpression, 'Expected first argument to be a step type name string, actionStep.xxx identifier, or ActionStepDefinition');
|
|
275
|
+
return { success: false };
|
|
276
|
+
}
|
|
89
277
|
const shapeArgs = {
|
|
90
278
|
source: callExpression,
|
|
91
279
|
sysId: stepInstanceConfig.get('$id')?.getValue(),
|
|
92
280
|
config: stepInstanceConfig,
|
|
93
|
-
stepDefinitionSysId
|
|
94
|
-
stepLabel
|
|
95
|
-
inputDefinitions: stepConfig.get('inputs')?.asObject(),
|
|
281
|
+
stepDefinitionSysId,
|
|
282
|
+
stepLabel,
|
|
96
283
|
inputs: inputs,
|
|
284
|
+
...(inputDefinitions ? { inputDefinitions } : {}),
|
|
97
285
|
};
|
|
98
286
|
return {
|
|
99
287
|
success: true,
|
|
@@ -104,10 +292,11 @@ exports.StepInstancePlugin = sdk_build_core_1.Plugin.create({
|
|
|
104
292
|
{
|
|
105
293
|
shape: StepInstanceShape,
|
|
106
294
|
fileTypes: ['fluent'],
|
|
107
|
-
async toRecord(callExpression, { factory }) {
|
|
295
|
+
async toRecord(callExpression, { factory, diagnostics }) {
|
|
108
296
|
const stepInstanceRecord = await buildStepInstanceRecord({
|
|
109
297
|
callExpression,
|
|
110
298
|
factory,
|
|
299
|
+
diagnostics,
|
|
111
300
|
values: callExpression.getInputs(),
|
|
112
301
|
sysId: callExpression.getSysId(),
|
|
113
302
|
stepDefinitionSysId: callExpression.getStepDefinitionSysId(),
|
|
@@ -125,6 +314,12 @@ exports.StepInstancePlugin = sdk_build_core_1.Plugin.create({
|
|
|
125
314
|
sys_hub_step_ext_output: {
|
|
126
315
|
coalesce: ['model', 'element'],
|
|
127
316
|
},
|
|
317
|
+
sys_complex_object: {
|
|
318
|
+
coalesce: ['name'],
|
|
319
|
+
},
|
|
320
|
+
sys_element_mapping: {
|
|
321
|
+
coalesce: ['field', 'id'],
|
|
322
|
+
},
|
|
128
323
|
sys_hub_step_instance: {
|
|
129
324
|
relationships: {
|
|
130
325
|
sys_variable_value: {
|
|
@@ -148,81 +343,128 @@ exports.StepInstancePlugin = sdk_build_core_1.Plugin.create({
|
|
|
148
343
|
descendant: true,
|
|
149
344
|
},
|
|
150
345
|
},
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
346
|
+
toShape(record, { descendants, logger }) {
|
|
347
|
+
// Skip step instances that belong to an action definition —
|
|
348
|
+
// those are handled by ActionDefinitionPlugin's toShape for Action() definitions
|
|
349
|
+
const actionRef = record.get('action')?.asString()?.getValue();
|
|
350
|
+
if (actionRef) {
|
|
351
|
+
return { success: false };
|
|
352
|
+
}
|
|
353
|
+
const stepDefinitionRecords = descendants.query('sys_flow_step_definition');
|
|
354
|
+
const variableValues = descendants.query('sys_variable_value');
|
|
355
|
+
const configObj = {};
|
|
356
|
+
let stepDefinitionShape;
|
|
357
|
+
let stepName;
|
|
358
|
+
if (stepDefinitionRecords.length > 0) {
|
|
359
|
+
// Custom step definition found in descendants
|
|
360
|
+
const stepDefinition = stepDefinitionRecords[0];
|
|
361
|
+
if (!stepDefinition) {
|
|
362
|
+
logger.warn('Step definition is undefined');
|
|
363
|
+
return { success: false };
|
|
364
|
+
}
|
|
365
|
+
stepName = stepDefinition.get('name')?.asString()?.getValue();
|
|
366
|
+
// Resolve variable values using input definition records from descendants
|
|
367
|
+
for (const varValue of variableValues) {
|
|
368
|
+
const variableSysId = varValue.get('variable')?.asString()?.getValue();
|
|
369
|
+
const value = varValue.get('value')?.asString()?.getValue();
|
|
370
|
+
const inputRecords = descendants.query('sys_flow_step_definition_input', {
|
|
371
|
+
sysId: variableSysId,
|
|
372
|
+
});
|
|
373
|
+
if (inputRecords.length > 0) {
|
|
374
|
+
const elementName = inputRecords[0]?.get('element')?.asString()?.getValue();
|
|
375
|
+
if (elementName) {
|
|
376
|
+
try {
|
|
377
|
+
configObj[elementName] = JSON.parse(value || '');
|
|
378
|
+
}
|
|
379
|
+
catch {
|
|
380
|
+
configObj[elementName] = value;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
stepDefinitionShape = new sdk_build_core_1.CallExpressionShape({
|
|
386
|
+
source: stepDefinition,
|
|
387
|
+
callee: 'ActionStepDefinition',
|
|
388
|
+
args: [
|
|
389
|
+
stepDefinition.transform(({ $ }) => ({
|
|
390
|
+
$id: $.val(now_id_plugin_1.NowIdShape.from(stepDefinition)),
|
|
391
|
+
name: $,
|
|
392
|
+
})),
|
|
393
|
+
],
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
// OOB/built-in step definition — not in XML export
|
|
398
|
+
const stepTypeSysId = record.get('step_type')?.asString()?.getValue();
|
|
399
|
+
if (!stepTypeSysId) {
|
|
400
|
+
logger.warn(`Step instance ${record.getId().getValue()} has no step_type reference`);
|
|
401
|
+
return { success: false };
|
|
402
|
+
}
|
|
403
|
+
const builtInDef = flow_constants_1.BUILT_IN_STEP_DEFINITIONS[stepTypeSysId];
|
|
404
|
+
if (!builtInDef) {
|
|
405
|
+
logger.warn(`Unknown OOB step definition ${stepTypeSysId} for step instance ${record.getId().getValue()}`);
|
|
406
|
+
return { success: false };
|
|
407
|
+
}
|
|
408
|
+
stepName = builtInDef.name;
|
|
409
|
+
// Resolve variable values using the built-in definition's input/output mappings
|
|
410
|
+
for (const varValue of variableValues) {
|
|
411
|
+
const variableSysId = varValue.get('variable')?.asString()?.getValue();
|
|
412
|
+
const value = varValue.get('value')?.asString()?.getValue();
|
|
413
|
+
if (variableSysId) {
|
|
414
|
+
const entry = builtInDef.inputs[variableSysId] ?? builtInDef.outputs[variableSysId];
|
|
415
|
+
const elementName = entry ? (0, flow_constants_1.getVarEntryName)(entry) : undefined;
|
|
416
|
+
const uiType = entry ? (0, flow_constants_1.getVarEntryType)(entry) : undefined;
|
|
417
|
+
if (elementName && value != null) {
|
|
418
|
+
configObj[elementName] = uiType ? (0, flow_instance_plugin_1.normalizeInputValue)(value, uiType, record) : value;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
// Built-in/OOB step: emit actionStep.xxx reference
|
|
423
|
+
const stepIdentifier = (0, utils_1.getBuiltInStepIdentifier)(stepTypeSysId);
|
|
424
|
+
stepDefinitionShape = stepIdentifier
|
|
425
|
+
? new sdk_build_core_1.IdentifierShape({ source: record, name: stepIdentifier })
|
|
426
|
+
: builtInDef.name;
|
|
427
|
+
}
|
|
428
|
+
// Build step instance config (2nd arg): $id, label, error_handling_type
|
|
429
|
+
const configProperties = {
|
|
430
|
+
$id: now_id_plugin_1.NowIdShape.from(record),
|
|
431
|
+
};
|
|
432
|
+
const errorHandlingRaw = record.get('error_handling_type');
|
|
433
|
+
const errorHandlingType = errorHandlingRaw?.ifNumber()?.getValue() ?? Number(errorHandlingRaw?.ifString()?.getValue());
|
|
434
|
+
if (errorHandlingType && errorHandlingType !== 1 && !Number.isNaN(errorHandlingType)) {
|
|
435
|
+
configProperties['error_handling_type'] = errorHandlingType;
|
|
436
|
+
}
|
|
437
|
+
const label = record.get('label')?.asString()?.getValue();
|
|
438
|
+
if (label && label !== stepName) {
|
|
439
|
+
configProperties['label'] = label;
|
|
440
|
+
}
|
|
441
|
+
const stepInstanceConfig = new sdk_build_core_1.ObjectShape({
|
|
442
|
+
source: record,
|
|
443
|
+
properties: configProperties,
|
|
444
|
+
});
|
|
445
|
+
// Build inputs (3rd arg): resolved variable values only
|
|
446
|
+
const inputsShape = new sdk_build_core_1.ObjectShape({
|
|
447
|
+
source: record,
|
|
448
|
+
properties: { ...configObj },
|
|
449
|
+
});
|
|
450
|
+
return {
|
|
451
|
+
success: true,
|
|
452
|
+
value: new sdk_build_core_1.CallExpressionShape({
|
|
453
|
+
source: record,
|
|
454
|
+
callee: 'wfa.actionStep',
|
|
455
|
+
args: [stepDefinitionShape, stepInstanceConfig, inputsShape],
|
|
456
|
+
}),
|
|
457
|
+
};
|
|
458
|
+
},
|
|
222
459
|
},
|
|
223
460
|
},
|
|
224
461
|
});
|
|
225
|
-
async function buildStepInstanceRecord({ callExpression, factory, values, sysId, stepDefinitionSysId, stepLabel, inputs, }) {
|
|
462
|
+
async function buildStepInstanceRecord({ callExpression, factory, diagnostics, values, sysId, stepDefinitionSysId, stepLabel, inputs, }) {
|
|
463
|
+
// resolve: false — keep PillShapes and other ResolvableShapes intact (same reason as createVariableRecords).
|
|
464
|
+
// Using .getValue() on the parent ObjectShape would deeply resolve nested PillShapes into symbols.
|
|
465
|
+
const valuesArray = values.properties({ resolve: false });
|
|
466
|
+
const cidMap = callExpression.getCidMap();
|
|
467
|
+
const pillTypeMap = callExpression.getPillTypeMap();
|
|
226
468
|
// Create step instance record
|
|
227
469
|
const stepInstanceRecord = await factory.createRecord({
|
|
228
470
|
source: callExpression,
|
|
@@ -232,7 +474,7 @@ async function buildStepInstanceRecord({ callExpression, factory, values, sysId,
|
|
|
232
474
|
step_type: stepDefinitionSysId,
|
|
233
475
|
order: 1,
|
|
234
476
|
active: true,
|
|
235
|
-
error_handling_type: ERROR_HANDLING_TYPE_MAP[
|
|
477
|
+
error_handling_type: ERROR_HANDLING_TYPE_MAP[valuesArray['errorHandlingType']?.ifString()?.getValue() ?? ''] ?? 1,
|
|
236
478
|
label: stepLabel,
|
|
237
479
|
},
|
|
238
480
|
});
|
|
@@ -241,19 +483,21 @@ async function buildStepInstanceRecord({ callExpression, factory, values, sysId,
|
|
|
241
483
|
});
|
|
242
484
|
const stepInstanceSysId = updatedStepInstanceRecord.getId().getValue();
|
|
243
485
|
// Create sys_variable_value records for each input value
|
|
244
|
-
const
|
|
486
|
+
const stepDataRecords = await createVariableRecords(valuesArray, inputs, factory, callExpression, stepInstanceSysId, stepDefinitionSysId, cidMap);
|
|
245
487
|
const extendedInputRecords = [];
|
|
246
488
|
const extendedOutputRecords = [];
|
|
247
489
|
const extendedVariableValueRecords = [];
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
const
|
|
256
|
-
const
|
|
490
|
+
const inputVariablesShape = valuesArray['inputVariables'];
|
|
491
|
+
if (inputVariablesShape) {
|
|
492
|
+
const inputVarObj = inputVariablesShape.asObject();
|
|
493
|
+
const inputVarProps = inputVarObj.properties({ resolve: false });
|
|
494
|
+
const extInputTableName = `var__m_sys_hub_step_ext_input_${stepInstanceSysId}`;
|
|
495
|
+
for (const [name, configShapeRaw] of Object.entries(inputVarProps)) {
|
|
496
|
+
const configObj = configShapeRaw.asObject();
|
|
497
|
+
const configProps = configObj.properties({ resolve: false });
|
|
498
|
+
const label = (configProps['label']?.ifString?.()?.getValue() ?? name);
|
|
499
|
+
const defaultValue = (configProps['defaultValue']?.ifString?.()?.getValue() ?? '');
|
|
500
|
+
const valueShape = configProps['value'];
|
|
257
501
|
const extInputRecord = await factory.createRecord({
|
|
258
502
|
source: callExpression,
|
|
259
503
|
table: 'sys_hub_step_ext_input',
|
|
@@ -262,69 +506,336 @@ async function buildStepInstanceRecord({ callExpression, factory, values, sysId,
|
|
|
262
506
|
model: stepInstanceSysId,
|
|
263
507
|
model_id: stepInstanceSysId,
|
|
264
508
|
model_table: 'sys_hub_step_instance',
|
|
265
|
-
name:
|
|
509
|
+
name: extInputTableName,
|
|
266
510
|
element: name,
|
|
267
511
|
label: label,
|
|
268
|
-
mandatory: mandatory,
|
|
269
512
|
default_value: defaultValue,
|
|
513
|
+
attributes: (0, flow_constants_1.buildExtVarAttributes)('string'),
|
|
514
|
+
internal_type: 'string',
|
|
270
515
|
},
|
|
271
516
|
});
|
|
272
517
|
extendedInputRecords.push(extInputRecord);
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
518
|
+
if (!valueShape) {
|
|
519
|
+
// No value provided — still create a sys_variable_value record with empty value
|
|
520
|
+
// so the platform recognizes the ext input variable exists
|
|
521
|
+
extendedVariableValueRecords.push(await factory.createRecord({
|
|
522
|
+
source: callExpression,
|
|
523
|
+
table: 'sys_variable_value',
|
|
524
|
+
properties: {
|
|
525
|
+
document: 'sys_hub_step_instance',
|
|
526
|
+
document_key: stepInstanceSysId,
|
|
527
|
+
order: 100,
|
|
528
|
+
value: '',
|
|
529
|
+
variable: extInputRecord.getId().getValue(),
|
|
530
|
+
},
|
|
531
|
+
}));
|
|
532
|
+
}
|
|
533
|
+
else {
|
|
534
|
+
// Check if value is a datapill — if so, create sys_element_mapping instead of sys_variable_value
|
|
535
|
+
const pillString = resolveFieldToPillString(valueShape, cidMap);
|
|
536
|
+
if (pillString) {
|
|
537
|
+
collectPillTypes(pillString, pillTypeMap);
|
|
538
|
+
extendedVariableValueRecords.push(await factory.createRecord({
|
|
539
|
+
source: callExpression,
|
|
540
|
+
table: 'sys_element_mapping',
|
|
541
|
+
properties: {
|
|
542
|
+
field: name,
|
|
543
|
+
id: stepInstanceSysId,
|
|
544
|
+
table: extInputTableName,
|
|
545
|
+
value: stripPillType(pillString),
|
|
546
|
+
},
|
|
547
|
+
}));
|
|
548
|
+
}
|
|
549
|
+
else if (valueShape.is(sdk_build_core_1.TemplateExpressionShape)) {
|
|
550
|
+
const { result, hasPills } = resolveTemplateExpression(valueShape, cidMap, pillTypeMap);
|
|
551
|
+
if (hasPills) {
|
|
552
|
+
extendedVariableValueRecords.push(await factory.createRecord({
|
|
553
|
+
source: callExpression,
|
|
554
|
+
table: 'sys_element_mapping',
|
|
555
|
+
properties: {
|
|
556
|
+
field: name,
|
|
557
|
+
id: stepInstanceSysId,
|
|
558
|
+
table: extInputTableName,
|
|
559
|
+
value: result,
|
|
560
|
+
},
|
|
561
|
+
}));
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
extendedVariableValueRecords.push(await factory.createRecord({
|
|
565
|
+
source: callExpression,
|
|
566
|
+
table: 'sys_variable_value',
|
|
567
|
+
properties: {
|
|
568
|
+
document: 'sys_hub_step_instance',
|
|
569
|
+
document_key: stepInstanceSysId,
|
|
570
|
+
order: 100,
|
|
571
|
+
value: result,
|
|
572
|
+
variable: extInputRecord.getId().getValue(),
|
|
573
|
+
},
|
|
574
|
+
}));
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
// Simple value → store in sys_variable_value
|
|
579
|
+
const rawVal = valueShape.ifString()?.getValue() ?? valueShape.getValue?.();
|
|
580
|
+
const resolvedValue = typeof rawVal === 'symbol' ? '' : (rawVal ?? '');
|
|
581
|
+
extendedVariableValueRecords.push(await factory.createRecord({
|
|
582
|
+
source: callExpression,
|
|
583
|
+
table: 'sys_variable_value',
|
|
584
|
+
properties: {
|
|
585
|
+
document: 'sys_hub_step_instance',
|
|
586
|
+
document_key: stepInstanceSysId,
|
|
587
|
+
order: 100,
|
|
588
|
+
value: resolvedValue,
|
|
589
|
+
variable: extInputRecord.getId().getValue(),
|
|
590
|
+
},
|
|
591
|
+
}));
|
|
592
|
+
}
|
|
593
|
+
}
|
|
284
594
|
}
|
|
285
595
|
}
|
|
286
596
|
const outputVariables = valuesArray['outputVariables'];
|
|
597
|
+
const complexObjectRecords = [];
|
|
287
598
|
if (outputVariables) {
|
|
288
599
|
const outputItemShape = outputVariables.asObject();
|
|
289
|
-
const outputProperties = outputItemShape.properties();
|
|
600
|
+
const outputProperties = outputItemShape.properties({ resolve: false });
|
|
290
601
|
for (const [columnName, columnCallExpr] of Object.entries(outputProperties)) {
|
|
291
602
|
const callExpr = columnCallExpr.as(sdk_build_core_1.CallExpressionShape);
|
|
292
|
-
const columnType = callExpr.getCallee(); // e.g., 'StringColumn', 'IntegerColumn'
|
|
603
|
+
const columnType = callExpr.getCallee(); // e.g., 'StringColumn', 'IntegerColumn', 'FlowObject', 'FlowArray'
|
|
293
604
|
const columnConfig = callExpr.getArgument(0)?.asObject();
|
|
294
605
|
const columnLabel = columnConfig?.get('label')?.getValue();
|
|
295
606
|
const mandatory = columnConfig?.get('mandatory')?.getValue();
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
607
|
+
// Handle FlowObject and FlowArray complex objects
|
|
608
|
+
if (columnType === flow_constants_1.FLOW_OBJECT_API_NAME || columnType === flow_constants_1.FLOW_ARRAY_API_NAME) {
|
|
609
|
+
const coTypeName = columnConfig?.get('co_type_name')?.ifString()?.getValue();
|
|
610
|
+
const varSysId = `${stepInstanceSysId}_${columnName}`;
|
|
611
|
+
const complexObjectId = coTypeName || `FD${varSysId}`;
|
|
612
|
+
const isArray = columnType === flow_constants_1.FLOW_ARRAY_API_NAME;
|
|
613
|
+
// Generate schema for complex object
|
|
614
|
+
const schemaObj = (0, complex_objects_1.generateSchemaFromObject)(columnConfig, complexObjectId, columnName, stepInstanceSysId, 0, isArray, diagnostics, false);
|
|
615
|
+
// Create sys_complex_object record
|
|
616
|
+
const explicitId = columnConfig?.get('$id')?.ifString()?.getValue();
|
|
617
|
+
const complexRecord = await factory.createRecord({
|
|
618
|
+
source: callExpression,
|
|
619
|
+
table: 'sys_complex_object',
|
|
620
|
+
properties: {
|
|
621
|
+
name: complexObjectId,
|
|
622
|
+
namespace: 'FlowDesigner',
|
|
623
|
+
type: isArray ? 'complex_object_collection' : 'complex_object_schema',
|
|
624
|
+
serialized_content: JSON.stringify(schemaObj),
|
|
625
|
+
...(explicitId ? { sys_id: explicitId } : {}),
|
|
626
|
+
},
|
|
627
|
+
});
|
|
628
|
+
complexObjectRecords.push(complexRecord);
|
|
629
|
+
// Get complex object attributes
|
|
630
|
+
const systemAttributes = (0, complex_objects_1.getComplexObjectAttributes)(schemaObj, complexObjectId, isArray);
|
|
631
|
+
const attributesStr = (0, complex_objects_1.formatComplexObjectAttributes)(systemAttributes);
|
|
632
|
+
// Create ext_output record with complex object type
|
|
633
|
+
const extOutputRecord = await factory.createRecord({
|
|
634
|
+
source: callExpression,
|
|
635
|
+
table: 'sys_hub_step_ext_output',
|
|
636
|
+
properties: {
|
|
637
|
+
active: true,
|
|
638
|
+
model: stepInstanceSysId,
|
|
639
|
+
model_id: stepInstanceSysId,
|
|
640
|
+
model_table: 'sys_hub_step_instance',
|
|
641
|
+
name: `var__m_sys_hub_step_ext_output_${stepInstanceSysId}`,
|
|
642
|
+
element: columnName,
|
|
643
|
+
label: columnLabel || columnName,
|
|
644
|
+
internal_type: 'string',
|
|
645
|
+
max_length: 65000,
|
|
646
|
+
mandatory: mandatory,
|
|
647
|
+
attributes: attributesStr,
|
|
648
|
+
},
|
|
649
|
+
});
|
|
650
|
+
extendedOutputRecords.push(extOutputRecord);
|
|
651
|
+
}
|
|
652
|
+
else {
|
|
653
|
+
// Handle regular column types (StringColumn, IntegerColumn, etc.)
|
|
654
|
+
const internalType = column_helper_1.COLUMN_API_TO_TYPE[columnType] || 'string';
|
|
655
|
+
const maxLength = columnConfig?.get('maxLength')?.ifNumber()?.getValue();
|
|
656
|
+
const hint = columnConfig?.get('hint')?.ifString()?.getValue();
|
|
657
|
+
const defaultValue = columnConfig?.get('default')?.ifString()?.getValue();
|
|
658
|
+
const extOutputRecord = await factory.createRecord({
|
|
659
|
+
source: callExpression,
|
|
660
|
+
table: 'sys_hub_step_ext_output',
|
|
661
|
+
properties: {
|
|
662
|
+
active: true,
|
|
663
|
+
model: stepInstanceSysId,
|
|
664
|
+
model_id: stepInstanceSysId,
|
|
665
|
+
model_table: 'sys_hub_step_instance',
|
|
666
|
+
name: `var__m_sys_hub_step_ext_output_${stepInstanceSysId}`,
|
|
667
|
+
element: columnName,
|
|
668
|
+
label: columnLabel || columnName,
|
|
669
|
+
internal_type: internalType,
|
|
670
|
+
mandatory: mandatory,
|
|
671
|
+
...(maxLength != null ? { max_length: maxLength } : {}),
|
|
672
|
+
...(hint ? { hint } : {}),
|
|
673
|
+
...(defaultValue ? { default_value: defaultValue } : {}),
|
|
674
|
+
attributes: (0, flow_constants_1.buildExtVarAttributes)(internalType),
|
|
675
|
+
},
|
|
676
|
+
});
|
|
677
|
+
extendedOutputRecords.push(extOutputRecord);
|
|
678
|
+
}
|
|
313
679
|
}
|
|
314
680
|
}
|
|
315
|
-
return updatedStepInstanceRecord.with(...
|
|
681
|
+
return updatedStepInstanceRecord.with(...stepDataRecords, ...extendedInputRecords, ...extendedVariableValueRecords, ...extendedOutputRecords, ...complexObjectRecords);
|
|
316
682
|
}
|
|
317
|
-
async function createVariableRecords(
|
|
318
|
-
const properties = values.properties();
|
|
683
|
+
async function createVariableRecords(valuesProperties, inputs, factory, callExpression, stepInstanceSysId, stepDefinitionSysId, cidMap) {
|
|
319
684
|
// Filter out inputVariables, outputVariables and errorHandlingType as they are handled separately
|
|
320
|
-
const filteredEntries = Object.entries(
|
|
321
|
-
|
|
685
|
+
const filteredEntries = Object.entries(valuesProperties).filter(([key]) => key !== 'inputVariables' && key !== 'outputVariables' && key !== 'errorHandlingType');
|
|
686
|
+
// Build reverse lookup (elementName → varSysId) from BUILT_IN_STEP_DEFINITIONS
|
|
687
|
+
const builtInDef = flow_constants_1.BUILT_IN_STEP_DEFINITIONS[stepDefinitionSysId];
|
|
688
|
+
const elementToVarSysId = {};
|
|
689
|
+
if (builtInDef) {
|
|
690
|
+
for (const [varSysId, entry] of Object.entries(builtInDef.inputs)) {
|
|
691
|
+
elementToVarSysId[(0, flow_constants_1.getVarEntryName)(entry)] = varSysId;
|
|
692
|
+
}
|
|
693
|
+
for (const [varSysId, entry] of Object.entries(builtInDef.outputs)) {
|
|
694
|
+
elementToVarSysId[(0, flow_constants_1.getVarEntryName)(entry)] = varSysId;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
const pillTypeMap = callExpression.getPillTypeMap();
|
|
698
|
+
const allRecords = [];
|
|
699
|
+
await Promise.all(filteredEntries.map(async ([key, valueShape]) => {
|
|
700
|
+
// Try resolving from inputDefinitions shape first, then fall back to built-in map
|
|
701
|
+
let variableSysId = '';
|
|
322
702
|
const input = inputs?.get(key);
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
703
|
+
if (input instanceof sdk_build_core_1.CallExpressionShape) {
|
|
704
|
+
variableSysId = input.getArgument(0).asObject().get('sysId')?.getValue() ?? '';
|
|
705
|
+
}
|
|
706
|
+
if (!variableSysId) {
|
|
707
|
+
variableSysId = elementToVarSysId[key] ?? '';
|
|
708
|
+
}
|
|
709
|
+
// ApprovalDueDateShape: store JSON in sys_element_mapping.value (ServiceNow reads from there)
|
|
710
|
+
// and create sys_variable_value with empty value
|
|
711
|
+
if (valueShape.is(flow_shapes_1.ApprovalDueDateShape)) {
|
|
712
|
+
const jsonValue = valueShape.toString().getValue();
|
|
713
|
+
const [elementMappingRecord, variableValueRecord] = await Promise.all([
|
|
714
|
+
factory.createRecord({
|
|
715
|
+
source: callExpression,
|
|
716
|
+
table: 'sys_element_mapping',
|
|
717
|
+
properties: {
|
|
718
|
+
field: key,
|
|
719
|
+
id: stepInstanceSysId,
|
|
720
|
+
table: `var__m_sys_flow_step_definition_input_${stepDefinitionSysId}`,
|
|
721
|
+
value: jsonValue,
|
|
722
|
+
},
|
|
723
|
+
}),
|
|
724
|
+
factory.createRecord({
|
|
725
|
+
source: callExpression,
|
|
726
|
+
table: 'sys_variable_value',
|
|
727
|
+
properties: {
|
|
728
|
+
document: 'sys_hub_step_instance',
|
|
729
|
+
document_key: stepInstanceSysId,
|
|
730
|
+
order: 100,
|
|
731
|
+
// value intentionally empty: ServiceNow reads due_date JSON from sys_element_mapping, not here
|
|
732
|
+
value: '',
|
|
733
|
+
variable: variableSysId,
|
|
734
|
+
},
|
|
735
|
+
}),
|
|
736
|
+
]);
|
|
737
|
+
allRecords.push(elementMappingRecord, variableValueRecord);
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
// Handle TemplateValueShape specially - serialize to ServiceNow format.
|
|
741
|
+
// When TemplateValue contains datapills, the platform stores the entire encoded string
|
|
742
|
+
// (with pills inline) in a single sys_element_mapping record with field=<parent input name>.
|
|
743
|
+
let actualValue;
|
|
744
|
+
if (valueShape.is(sdk_build_core_1.TemplateValueShape)) {
|
|
745
|
+
const templateObj = valueShape.getTemplateValue();
|
|
746
|
+
const entries = [];
|
|
747
|
+
let hasPills = false;
|
|
748
|
+
for (const [field, fieldShape] of templateObj.entries({ resolve: false })) {
|
|
749
|
+
const pillString = resolveFieldToPillString(fieldShape, cidMap);
|
|
750
|
+
if (pillString) {
|
|
751
|
+
collectPillTypes(pillString, pillTypeMap);
|
|
752
|
+
entries.push(`${field}=${stripPillType(pillString)}`);
|
|
753
|
+
hasPills = true;
|
|
754
|
+
}
|
|
755
|
+
else if (fieldShape.is(sdk_build_core_1.TemplateExpressionShape)) {
|
|
756
|
+
const resolved = resolveTemplateExpression(fieldShape, cidMap, pillTypeMap);
|
|
757
|
+
if (resolved.hasPills) {
|
|
758
|
+
hasPills = true;
|
|
759
|
+
}
|
|
760
|
+
const escapedValue = resolved.result.replace(/\^/g, '^^');
|
|
761
|
+
entries.push(`${field}=${escapedValue}`);
|
|
762
|
+
}
|
|
763
|
+
else {
|
|
764
|
+
const resolved = fieldShape.getValue();
|
|
765
|
+
const escapedValue = String(resolved).replace(/\^/g, '^^');
|
|
766
|
+
entries.push(`${field}=${escapedValue}`);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
const encodedValue = entries.join('^');
|
|
770
|
+
if (hasPills) {
|
|
771
|
+
// TemplateValue with datapills → single sys_element_mapping record
|
|
772
|
+
// No sys_variable_value for this field — platform reads from element_mapping only
|
|
773
|
+
allRecords.push(await factory.createRecord({
|
|
774
|
+
source: callExpression,
|
|
775
|
+
table: 'sys_element_mapping',
|
|
776
|
+
properties: {
|
|
777
|
+
field: key,
|
|
778
|
+
id: stepInstanceSysId,
|
|
779
|
+
table: `var__m_sys_flow_step_definition_input_${stepDefinitionSysId}`,
|
|
780
|
+
value: encodedValue,
|
|
781
|
+
},
|
|
782
|
+
}));
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
// No datapills — standard encoded string in sys_variable_value
|
|
786
|
+
actualValue = encodedValue ? `${encodedValue}^EQ` : '';
|
|
787
|
+
}
|
|
788
|
+
else if (valueShape.is(sdk_build_core_1.DurationShape)) {
|
|
789
|
+
// DurationShape.getValue() returns a symbol, so use toString() instead
|
|
790
|
+
actualValue = valueShape.toString().getValue();
|
|
791
|
+
}
|
|
792
|
+
else if (valueShape.is(flow_shapes_1.ApprovalRulesShape)) {
|
|
793
|
+
// ApprovalRulesShape.getValue() returns a JSON object, not a string.
|
|
794
|
+
// Previously fell through to the generic getValue() path which stored a raw [object Object].
|
|
795
|
+
// toString() correctly serializes it to the JSON string ServiceNow expects.
|
|
796
|
+
actualValue = valueShape.toString().getValue();
|
|
797
|
+
}
|
|
798
|
+
else if (valueShape.is(sdk_build_core_1.TemplateExpressionShape)) {
|
|
799
|
+
const { result, hasPills } = resolveTemplateExpression(valueShape, cidMap, pillTypeMap);
|
|
800
|
+
if (hasPills) {
|
|
801
|
+
allRecords.push(await factory.createRecord({
|
|
802
|
+
source: callExpression,
|
|
803
|
+
table: 'sys_element_mapping',
|
|
804
|
+
properties: {
|
|
805
|
+
field: key,
|
|
806
|
+
id: stepInstanceSysId,
|
|
807
|
+
table: `var__m_sys_flow_step_definition_input_${stepDefinitionSysId}`,
|
|
808
|
+
value: result,
|
|
809
|
+
},
|
|
810
|
+
}));
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
actualValue = result;
|
|
814
|
+
}
|
|
815
|
+
else {
|
|
816
|
+
// Check if it's a wfa.dataPill() CallExpressionShape (step output reference)
|
|
817
|
+
// that needs to be resolved to a pill string for sys_element_mapping
|
|
818
|
+
const pillString = resolveFieldToPillString(valueShape, cidMap);
|
|
819
|
+
if (pillString) {
|
|
820
|
+
collectPillTypes(pillString, pillTypeMap);
|
|
821
|
+
allRecords.push(await factory.createRecord({
|
|
822
|
+
source: callExpression,
|
|
823
|
+
table: 'sys_element_mapping',
|
|
824
|
+
properties: {
|
|
825
|
+
field: key,
|
|
826
|
+
id: stepInstanceSysId,
|
|
827
|
+
table: `var__m_sys_flow_step_definition_input_${stepDefinitionSysId}`,
|
|
828
|
+
value: stripPillType(pillString),
|
|
829
|
+
},
|
|
830
|
+
}));
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
const rawValue = valueShape.getValue?.();
|
|
834
|
+
// Guard against symbol values (e.g., DurationShape, unresolved shapes with { resolve: false })
|
|
835
|
+
// since factory.createRecord cannot serialize symbols. Fall back to empty string.
|
|
836
|
+
actualValue = typeof rawValue === 'symbol' ? '' : (rawValue ?? '');
|
|
837
|
+
}
|
|
838
|
+
const record = await factory.createRecord({
|
|
328
839
|
source: callExpression,
|
|
329
840
|
table: 'sys_variable_value',
|
|
330
841
|
properties: {
|
|
@@ -335,6 +846,8 @@ async function createVariableRecords(values, inputs, factory, callExpression, st
|
|
|
335
846
|
variable: variableSysId,
|
|
336
847
|
},
|
|
337
848
|
});
|
|
849
|
+
allRecords.push(record);
|
|
338
850
|
}));
|
|
851
|
+
return allRecords;
|
|
339
852
|
}
|
|
340
853
|
//# sourceMappingURL=step-instance-plugin.js.map
|