snow-flow-test 10.0.1-test.205 → 10.0.1-test.206

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "10.0.1-test.205",
3
+ "version": "10.0.1-test.206",
4
4
  "name": "snow-flow-test",
5
5
  "description": "Snow-Flow Test - ServiceNow Multi-Agent Development Framework",
6
6
  "license": "Elastic-2.0",
@@ -1614,7 +1614,8 @@ async function buildConditionLabelCache(
1614
1614
  table: string,
1615
1615
  tableLabel: string,
1616
1616
  logicUiId: string,
1617
- explicitFields?: string[]
1617
+ explicitFields?: string[],
1618
+ inputName?: string
1618
1619
  ): Promise<any[]> {
1619
1620
  if (!dataPillBase) return [];
1620
1621
 
@@ -1680,7 +1681,7 @@ async function buildConditionLabelCache(
1680
1681
  base_type: meta.type,
1681
1682
  parent_table_name: table,
1682
1683
  column_name: f,
1683
- usedInstances: [{ uiUniqueIdentifier: logicUiId, inputName: 'condition' }],
1684
+ usedInstances: [{ uiUniqueIdentifier: logicUiId, inputName: inputName || 'condition' }],
1684
1685
  choices: {}
1685
1686
  });
1686
1687
  }
@@ -2163,6 +2164,60 @@ async function addFlowLogicViaGraphQL(
2163
2164
  steps.condition_not_encoded_query = true;
2164
2165
  }
2165
2166
 
2167
+ // ── Rewrite shorthand pills in non-condition inputs (e.g. FOR_EACH "items") ────
2168
+ // These inputs may contain {{trigger.current}} or {{current.field}} that need rewriting
2169
+ // to the full dataPillBase (e.g. {{Created or Updated_1.current}}) + labelCache for rendering.
2170
+ var nonConditionPillInputs: { name: string; fields: string[]; isRecordLevel: boolean }[] = [];
2171
+ for (var nci = 0; nci < inputResult.inputs.length; nci++) {
2172
+ var ncInput = inputResult.inputs[nci];
2173
+ if (ncInput.name === 'condition' || ncInput.name === 'condition_name') continue;
2174
+ var ncVal = ncInput.value?.value || '';
2175
+ if (!ncVal.includes('{{')) continue;
2176
+
2177
+ var ncHasShorthand = PILL_SHORTHANDS.some(function (sh) {
2178
+ return ncVal.includes('{{' + sh + '.') || ncVal.includes('{{' + sh + '}}');
2179
+ });
2180
+ if (!ncHasShorthand) continue;
2181
+
2182
+ // Get trigger info if not already fetched
2183
+ if (!conditionTriggerInfo) {
2184
+ conditionTriggerInfo = await getFlowTriggerInfo(client, flowId);
2185
+ steps.trigger_info = {
2186
+ dataPillBase: conditionTriggerInfo.dataPillBase, triggerName: conditionTriggerInfo.triggerName,
2187
+ table: conditionTriggerInfo.table, tableLabel: conditionTriggerInfo.tableLabel, error: conditionTriggerInfo.error,
2188
+ debug: conditionTriggerInfo.debug
2189
+ };
2190
+ }
2191
+ if (!conditionTriggerInfo.dataPillBase) continue;
2192
+
2193
+ var ncPillBase = conditionTriggerInfo.dataPillBase;
2194
+ var ncOrigVal = ncVal;
2195
+ for (var si2 = 0; si2 < PILL_SHORTHANDS.length; si2++) {
2196
+ var sh2 = PILL_SHORTHANDS[si2];
2197
+ ncVal = ncVal.split('{{' + sh2 + '.').join('{{' + ncPillBase + '.');
2198
+ ncVal = ncVal.split('{{' + sh2 + '}}').join('{{' + ncPillBase + '}}');
2199
+ }
2200
+ ncInput.value.value = ncVal;
2201
+
2202
+ // Extract field names from pills for labelCache
2203
+ var ncPillFields: string[] = [];
2204
+ var ncIsRecordLevel = false;
2205
+ var ncPillRx = /\{\{([^}]+)\}\}/g;
2206
+ var ncm: RegExpExecArray | null;
2207
+ while ((ncm = ncPillRx.exec(ncVal)) !== null) {
2208
+ var ncParts = ncm[1].split('.');
2209
+ if (ncParts.length > 2) {
2210
+ ncPillFields.push(ncParts[ncParts.length - 1]);
2211
+ } else {
2212
+ // Record-level pill like {{Created or Updated_1.current}}
2213
+ ncIsRecordLevel = true;
2214
+ }
2215
+ }
2216
+
2217
+ nonConditionPillInputs.push({ name: ncInput.name, fields: ncPillFields, isRecordLevel: ncIsRecordLevel });
2218
+ steps['pill_rewrite_' + ncInput.name] = { original: ncOrigVal, rewritten: ncVal };
2219
+ }
2220
+
2166
2221
  // Calculate insertion order
2167
2222
  const resolvedOrder = await calculateInsertOrder(client, flowId, parentUiId, order);
2168
2223
  steps.insert_order = resolvedOrder;
@@ -2282,6 +2337,65 @@ async function addFlowLogicViaGraphQL(
2282
2337
  }
2283
2338
  }
2284
2339
 
2340
+ // Step 3: UPDATE labelCache for non-condition inputs with data pills (e.g. FOR_EACH "items")
2341
+ if (nonConditionPillInputs.length > 0 && conditionTriggerInfo?.dataPillBase) {
2342
+ try {
2343
+ var ncLabelInserts: any[] = [];
2344
+ var dPillBase = conditionTriggerInfo.dataPillBase;
2345
+ var dTriggerName = conditionTriggerInfo.triggerName;
2346
+ var dTable = conditionTriggerInfo.tableRef;
2347
+ var dTableLabel = conditionTriggerInfo.tableLabel;
2348
+
2349
+ for (var nli = 0; nli < nonConditionPillInputs.length; nli++) {
2350
+ var ncpi = nonConditionPillInputs[nli];
2351
+
2352
+ // Field-level pills: reuse buildConditionLabelCache with the correct inputName
2353
+ if (ncpi.fields.length > 0) {
2354
+ var ncFieldEntries = await buildConditionLabelCache(
2355
+ client, '', dPillBase, dTriggerName, dTable, dTableLabel, returnedUuid, ncpi.fields, ncpi.name
2356
+ );
2357
+ ncLabelInserts = ncLabelInserts.concat(ncFieldEntries);
2358
+ }
2359
+
2360
+ // Record-level pill (e.g. {{Created or Updated_1.current}}) — add record-level labelCache entry
2361
+ if (ncpi.isRecordLevel) {
2362
+ ncLabelInserts.push({
2363
+ name: dPillBase,
2364
+ label: 'Trigger - Record ' + dTriggerName + '\u279b' + dTableLabel + ' Record\u279b' + dTableLabel,
2365
+ reference: dTable,
2366
+ reference_display: dTableLabel,
2367
+ type: 'reference',
2368
+ base_type: 'reference',
2369
+ parent_table_name: dTable,
2370
+ column_name: '',
2371
+ attributes: '',
2372
+ choices: {},
2373
+ usedInstances: [{ uiUniqueIdentifier: returnedUuid, inputName: ncpi.name }]
2374
+ });
2375
+ }
2376
+ }
2377
+
2378
+ if (ncLabelInserts.length > 0) {
2379
+ var ncUpdatePatch: any = {
2380
+ flowId: flowId,
2381
+ flowLogics: {
2382
+ update: [{
2383
+ uiUniqueIdentifier: returnedUuid,
2384
+ type: 'flowlogic',
2385
+ }]
2386
+ },
2387
+ labelCache: { insert: ncLabelInserts }
2388
+ };
2389
+ steps.nc_pill_label_cache_mutation = jsToGraphQL(ncUpdatePatch);
2390
+ await executeFlowPatchMutation(client, ncUpdatePatch, logicResponseFields);
2391
+ steps.nc_pill_label_cache_update = { success: true, count: ncLabelInserts.length };
2392
+ }
2393
+ } catch (nce: any) {
2394
+ steps.nc_pill_label_cache_update = { success: false, error: nce.message };
2395
+ // Non-fatal: element was created, just label rendering may be affected
2396
+ }
2397
+ }
2398
+
2285
2399
  return { success: true, logicId, uiUniqueIdentifier: returnedUuid, steps };
2286
2400
  } catch (e: any) {
2287
2401
  steps.insert = { success: false, error: e.message };