snow-flow 10.0.1-dev.439 → 10.0.1-dev.441
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/package.json
CHANGED
|
@@ -74,12 +74,15 @@ async function addTriggerViaGraphQL(
|
|
|
74
74
|
else if (triggerType.endsWith('e')) variations.push(triggerType + 'd');
|
|
75
75
|
else variations.push(triggerType + 'ed', triggerType + 'd');
|
|
76
76
|
|
|
77
|
+
// Resolve reference fields that may be objects {display_value, link} or plain strings
|
|
78
|
+
const str = (val: any) => typeof val === 'object' && val !== null ? (val.display_value || val.value || '') : (val || '');
|
|
79
|
+
|
|
77
80
|
const assignFound = (found: any, matched: string) => {
|
|
78
81
|
trigDefId = found.sys_id;
|
|
79
|
-
trigName = found.name || triggerType;
|
|
80
|
-
trigType = found.type || triggerType;
|
|
81
|
-
trigCategory = found.category
|
|
82
|
-
steps.def_lookup = { id: found.sys_id, type: found.type, name: found.name, category: found.category, matched };
|
|
82
|
+
trigName = str(found.name) || triggerType;
|
|
83
|
+
trigType = str(found.type) || triggerType;
|
|
84
|
+
trigCategory = str(found.category);
|
|
85
|
+
steps.def_lookup = { id: found.sys_id, type: str(found.type), name: str(found.name), category: str(found.category), matched };
|
|
83
86
|
};
|
|
84
87
|
|
|
85
88
|
// Try exact match on type and name for each variation
|
|
@@ -219,6 +222,48 @@ async function addActionViaGraphQL(
|
|
|
219
222
|
}
|
|
220
223
|
if (!actionDefId) return { success: false, error: 'Action definition not found for: ' + actionType, steps };
|
|
221
224
|
|
|
225
|
+
// Look up available input fields from sys_hub_action_input
|
|
226
|
+
let actionParams: { element: string; label: string; mandatory: boolean; default_value: string; internal_type: string }[] = [];
|
|
227
|
+
try {
|
|
228
|
+
const resp = await client.get('/api/now/table/sys_hub_action_input', {
|
|
229
|
+
params: {
|
|
230
|
+
sysparm_query: 'model=' + actionDefId,
|
|
231
|
+
sysparm_fields: 'sys_id,element,label,mandatory,default_value,internal_type',
|
|
232
|
+
sysparm_display_value: 'false',
|
|
233
|
+
sysparm_limit: 50
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
actionParams = (resp.data.result || []).map((r: any) => ({
|
|
237
|
+
element: r.element,
|
|
238
|
+
label: r.label,
|
|
239
|
+
mandatory: r.mandatory === 'true' || r.mandatory === true,
|
|
240
|
+
default_value: r.default_value || '',
|
|
241
|
+
internal_type: r.internal_type || ''
|
|
242
|
+
}));
|
|
243
|
+
steps.available_inputs = actionParams;
|
|
244
|
+
} catch (_) {}
|
|
245
|
+
|
|
246
|
+
// Match provided inputs to actual field names (fuzzy: "message" → "log_message", "level" → "log_level")
|
|
247
|
+
const resolvedInputs: Record<string, string> = {};
|
|
248
|
+
if (inputs) {
|
|
249
|
+
const paramElements = actionParams.map(p => p.element);
|
|
250
|
+
for (const [key, value] of Object.entries(inputs)) {
|
|
251
|
+
// Exact match first
|
|
252
|
+
if (paramElements.includes(key)) {
|
|
253
|
+
resolvedInputs[key] = value;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
// Try to find a param whose element ends with the key or contains it
|
|
257
|
+
const match = actionParams.find(p => p.element.endsWith('_' + key) || p.element === key || p.label.toLowerCase() === key.toLowerCase());
|
|
258
|
+
if (match) {
|
|
259
|
+
resolvedInputs[match.element] = value;
|
|
260
|
+
} else {
|
|
261
|
+
resolvedInputs[key] = value;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
steps.resolved_inputs = resolvedInputs;
|
|
265
|
+
}
|
|
266
|
+
|
|
222
267
|
const uuid = generateUUID();
|
|
223
268
|
const actionResponseFields = 'actions { inserts { sysId uiUniqueIdentifier __typename } updates deletes __typename }';
|
|
224
269
|
try {
|
|
@@ -243,8 +288,8 @@ async function addActionViaGraphQL(
|
|
|
243
288
|
const actionId = result?.actions?.inserts?.[0]?.sysId;
|
|
244
289
|
steps.insert = { success: !!actionId, actionId, uuid };
|
|
245
290
|
|
|
246
|
-
if (actionId &&
|
|
247
|
-
const updateInputs = Object.entries(
|
|
291
|
+
if (actionId && Object.keys(resolvedInputs).length > 0) {
|
|
292
|
+
const updateInputs = Object.entries(resolvedInputs).map(([name, value]) => ({
|
|
248
293
|
name,
|
|
249
294
|
value: { schemaless: false, schemalessValue: '', value: String(value) }
|
|
250
295
|
}));
|
|
@@ -253,7 +298,7 @@ async function addActionViaGraphQL(
|
|
|
253
298
|
flowId: flowId,
|
|
254
299
|
actions: { update: [{ uiUniqueIdentifier: uuid, type: 'action', inputs: updateInputs }] }
|
|
255
300
|
}, actionResponseFields);
|
|
256
|
-
steps.value_update = { success: true };
|
|
301
|
+
steps.value_update = { success: true, inputs: updateInputs.map(i => i.name) };
|
|
257
302
|
} catch (e: any) {
|
|
258
303
|
steps.value_update = { success: false, error: e.message };
|
|
259
304
|
}
|