@jacebenson/jsn 4.0.1 → 4.0.2

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
  "name": "@jacebenson/jsn",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "A command-line interface for ServiceNow that follows the Unix philosophy: simple, composable, and scriptable.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -307,6 +307,11 @@ async function formatFlowStructure(inspection, ctx) {
307
307
  if (!ctx.catalogVarNames) ctx.catalogVarNames = new Map();
308
308
  for (const [k, v] of names) ctx.catalogVarNames.set(k, v);
309
309
  }
310
+ const labelCache = buildLabelCache(inspection.payload);
311
+ if (labelCache.size > 0) {
312
+ if (!ctx.labelCache) ctx.labelCache = new Map();
313
+ for (const [k, v] of labelCache) ctx.labelCache.set(k, v);
314
+ }
310
315
  const payload = inspection.payload;
311
316
  if (Object.keys(payload).length > 0) {
312
317
  return formatFlowStructureFromPayload(payload, ctx);
@@ -314,6 +319,48 @@ async function formatFlowStructure(inspection, ctx) {
314
319
  return formatFlowStructureFallback(inspection);
315
320
  }
316
321
 
322
+ /**
323
+ * The ProcessFlow payload carries a label cache (also serialized as
324
+ * labelCacheAsJsonString) mapping data-pill names like "<step-uid>.<var>"
325
+ * to the human labels the Flow Designer UI shows, e.g.
326
+ * "1 - Get Catalog Variables➛session_title". Build a Map so guid-prefixed
327
+ * pills can be rendered readably.
328
+ */
329
+ function buildLabelCache(payload) {
330
+ const cache = new Map();
331
+ if (!payload || typeof payload !== 'object') return cache;
332
+ let entries = payload.label_cache;
333
+ if (!Array.isArray(entries)) {
334
+ try {
335
+ entries = JSON.parse(payload.labelCacheAsJsonString || '[]');
336
+ } catch {
337
+ entries = [];
338
+ }
339
+ }
340
+ for (const e of entries) {
341
+ if (!e || typeof e !== 'object') continue;
342
+ const name = getStringField(e, 'name');
343
+ const label = getStringField(e, 'label');
344
+ if (name && label) cache.set(name, label);
345
+ }
346
+ return cache;
347
+ }
348
+
349
+ const GUID_PILL_RE = /\{\{([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.([^}]+)\}\}/g;
350
+
351
+ /**
352
+ * Replace opaque guid-prefixed pills ({{<32-hex-guid>.<var>}}) with their
353
+ * human label from the payload's label cache. Readable step refs like
354
+ * {{Created_1.table_name}} are NOT matched and stay raw.
355
+ */
356
+ function resolveGuidPills(value, labelCache) {
357
+ if (!labelCache || labelCache.size === 0 || !value) return value;
358
+ return String(value).replace(GUID_PILL_RE, (m, guid, name) => {
359
+ const label = labelCache.get(`${guid}.${name}`);
360
+ return label ? `{{${label}}}` : m;
361
+ });
362
+ }
363
+
317
364
  /**
318
365
  * ServiceNow serializes catalog variable selections in action inputs as
319
366
  * comma-separated "sys_id:table" pairs (e.g. Get Catalog Variables / Create
@@ -657,6 +704,10 @@ export function formatActionStep(stepNum, pad, action, ctx) {
657
704
  const resolvedCatalog = resolveCatalogVarValue(inputValue, ctx?.catalogVarNames);
658
705
  if (resolvedCatalog) inputValue = resolvedCatalog;
659
706
 
707
+ // Opaque guid-prefixed pills ({{<32-hex>.<var>}}) get their human
708
+ // label from the payload's label cache. Readable step refs stay raw.
709
+ inputValue = resolveGuidPills(inputValue, ctx?.labelCache);
710
+
660
711
  let label = inputName;
661
712
  if (raw.parameter && typeof raw.parameter === 'object') {
662
713
  label = firstNonEmpty(getStringField(raw.parameter, 'label'), label);