snow-flow 1.3.16 → 1.3.18

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.
@@ -55,14 +55,22 @@ const path = __importStar(require("path"));
55
55
  const zlib = __importStar(require("zlib"));
56
56
  // VERIFIED action type sys_ids from working Flow Designer examples
57
57
  exports.VERIFIED_ACTION_TYPES = {
58
- 'notification': '87b067a4db01030077c9a4d3ca961916',
59
- 'approval': 'c39067a4db01030077c9a4d3ca96191a',
58
+ // From analyzed XML examples
59
+ 'check_change_approval': 'ffd74e4e731310108ef62d2b04f6a769',
60
+ 'wait_for_condition': '89ce8a4187120010663ca1bb36cb0be3',
61
+ 'evaluate_change_model': '83a1f363735310108ef62d2b04f6a74c',
62
+ 'update_record': 'f9d01dd2c31332002841b63b12d3aea1',
63
+ 'apply_approval_policy': 'cd04ac7573011010791f94596bf6a716',
64
+ 'send_email': 'c1806bf4a70323008299b39f087901cb',
65
+ 'disregard_approvals': '280065eb734310108ef62d2b04f6a751',
66
+ // Common action types (estimated based on pattern)
67
+ 'notification': 'c1806bf4a70323008299b39f087901cb', // Same as send_email
68
+ 'approval': 'cd04ac7573011010791f94596bf6a716', // Same as apply_approval_policy
60
69
  'script': '4bb067a4db01030077c9a4d3ca9619e1',
61
70
  'create_record': 'e39067a4db01030077c9a4d3ca961915',
62
- 'update_record': '179067a4db01030077c9a4d3ca96191b',
63
71
  'rest_step': '4f9067a4db01030077c9a4d3ca9619e3',
64
72
  'condition': '539067a4db01030077c9a4d3ca9619e5',
65
- 'assign_subflow': '8bb067a4db01030077c9a4d3ca961918'
73
+ 'assign_subflow': '63cf7e4c87122010c84e4561d5cb0b36' // From Step based request fulfillment
66
74
  };
67
75
  // VERIFIED trigger type sys_ids from working examples
68
76
  exports.VERIFIED_TRIGGER_TYPES = {
@@ -122,6 +130,18 @@ class ImprovedFlowXMLGenerator {
122
130
  return JSON.stringify(value);
123
131
  }
124
132
  }
133
+ /**
134
+ * Encode action parameters for v2 format
135
+ * Converts inputs object to parameter array structure
136
+ */
137
+ encodeActionParameters(inputs) {
138
+ const parameters = Object.entries(inputs).map(([name, value]) => ({
139
+ name,
140
+ value: typeof value === 'string' ? value : JSON.stringify(value),
141
+ valueType: typeof value === 'string' && value.startsWith('{{') ? 'fd_data' : 'static'
142
+ }));
143
+ return this.encodeFlowValue(parameters);
144
+ }
125
145
  /**
126
146
  * Generate complex label_cache structure (critical for working flows)
127
147
  */
@@ -279,7 +299,7 @@ class ImprovedFlowXMLGenerator {
279
299
  </sys_update_xml>
280
300
 
281
301
  ${this.generateActionInstancesV2XML(flowDef.activities, activitySysIds, updateSetSysId)}
282
- ${this.generateFlowLogicXML(triggerSysId, activitySysIds, updateSetSysId)}
302
+ ${this.generateFlowLogicV2XML(triggerSysId, activitySysIds, updateSetSysId)}
283
303
  </unload>`;
284
304
  return xml;
285
305
  }
@@ -395,9 +415,11 @@ class ImprovedFlowXMLGenerator {
395
415
  generateActionInstancesV2XML(activities, sysIds, updateSetSysId) {
396
416
  return activities.map((activity, index) => {
397
417
  const actionSysId = sysIds[index];
398
- // Use Base64+gzip encoding for inputs and outputs (as seen in working flows)
399
- const encodedInputs = this.encodeFlowValue(activity.inputs);
400
- const encodedOutputs = this.encodeFlowValue(activity.outputs || {});
418
+ const uiId = (0, uuid_1.v4)(); // Generate ui_id for visual designer
419
+ // Convert inputs to v2 parameter array format and encode
420
+ const encodedValues = this.encodeActionParameters(activity.inputs);
421
+ // Use arrow notation for order (e.g., "2➛3")
422
+ const orderValue = index === 0 ? '1' : `${index}➛${index + 1}`;
401
423
  return `
402
424
  <!-- sys_hub_action_instance_v2: ${this.escapeXml(activity.name)} -->
403
425
  <sys_update_xml action="INSERT_OR_UPDATE">
@@ -405,7 +427,7 @@ class ImprovedFlowXMLGenerator {
405
427
  <action>INSERT_OR_UPDATE</action>
406
428
  <application display_value="Global">global</application>
407
429
  <name>sys_hub_action_instance_v2_${actionSysId}</name>
408
- <payload><![CDATA[<?xml version="1.0" encoding="UTF-8"?><record_update table="sys_hub_action_instance_v2"><sys_hub_action_instance_v2 action="INSERT_OR_UPDATE"><action_type display_value="">${this.getActionTypeId(activity.type)}</action_type><active>true</active><comment_text/><condition>${this.escapeXml(activity.condition || '')}</condition><flow display_value="${this.escapeXml(activity.name)}">${this.flowSysId}</flow><inputs>${encodedInputs}</inputs><name>${this.escapeXml(activity.name)}</name><order>${activity.order || ((index + 1) * 100)}</order><outputs>${encodedOutputs}</outputs><sys_class_name>sys_hub_action_instance_v2</sys_class_name><sys_created_by>admin</sys_created_by><sys_created_on>${this.timestamp}</sys_created_on><sys_domain>global</sys_domain><sys_domain_path>/</sys_domain_path><sys_id>${actionSysId}</sys_id><sys_mod_count>0</sys_mod_count><sys_updated_by>admin</sys_updated_by><sys_updated_on>${this.timestamp}</sys_updated_on></sys_hub_action_instance_v2></record_update>]]></payload>
430
+ <payload><![CDATA[<?xml version="1.0" encoding="UTF-8"?><record_update table="sys_hub_action_instance_v2"><sys_hub_action_instance_v2 action="INSERT_OR_UPDATE"><action_type display_value="${this.getActionDisplayName(activity.type)}">${this.getActionTypeId(activity.type)}</action_type><action_type_parent/><attributes/><comment>${this.escapeXml(activity.description || '')}</comment><compiled_snapshot>${this.getActionTypeId(activity.type)}</compiled_snapshot><display_text/><flow display_value="${this.escapeXml(activity.name)}">${this.flowSysId}</flow><generation_source/><order>${orderValue}</order><parent_ui_id/><sys_class_name>sys_hub_action_instance_v2</sys_class_name><sys_created_by>admin</sys_created_by><sys_created_on>${this.timestamp}</sys_created_on><sys_id>${actionSysId}</sys_id><sys_mod_count>0</sys_mod_count><sys_scope display_value="Global">global</sys_scope><sys_updated_by>admin</sys_updated_by><sys_updated_on>${this.timestamp}</sys_updated_on><ui_id>${uiId}</ui_id><updation_source/><values>${encodedValues}</values></sys_hub_action_instance_v2></record_update>]]></payload>
409
431
  <remote_update_set display_value="${this.escapeXml(this.updateSetName)}">${updateSetSysId}</remote_update_set>
410
432
  <source_table>sys_hub_action_instance_v2</source_table>
411
433
  <type>Flow Designer Action</type>
@@ -413,7 +435,43 @@ class ImprovedFlowXMLGenerator {
413
435
  }).join('\n');
414
436
  }
415
437
  /**
416
- * Generate sys_hub_flow_logic XML for connections
438
+ * Generate sys_hub_flow_logic_instance_v2 XML for connections
439
+ */
440
+ generateFlowLogicV2XML(triggerSysId, activitySysIds, updateSetSysId) {
441
+ const connections = [];
442
+ const endSysId = this.generateSysId();
443
+ // Trigger -> First Activity
444
+ if (activitySysIds.length > 0) {
445
+ connections.push(`
446
+ <!-- Flow Logic V2: Trigger -> First Activity -->
447
+ <sys_update_xml action="INSERT_OR_UPDATE">
448
+ <sys_id>${this.generateSysId()}</sys_id>
449
+ <action>INSERT_OR_UPDATE</action>
450
+ <application display_value="Global">global</application>
451
+ <name>sys_hub_flow_logic_instance_v2_${this.generateSysId()}</name>
452
+ <payload><![CDATA[<?xml version="1.0" encoding="UTF-8"?><record_update table="sys_hub_flow_logic_instance_v2"><sys_hub_flow_logic_instance_v2 action="INSERT_OR_UPDATE"><attributes/><block display_value="">${this.generateSysId()}</block><comment/><connected_to/><decision_table/><display_text/><flow display_value="">${this.flowSysId}</flow><flow_variables_assigned/><generation_source/><logic_definition/><order>0</order><outputs_assigned/><parent_ui_id/><sys_class_name>sys_hub_flow_logic_instance_v2</sys_class_name><sys_created_by>admin</sys_created_by><sys_created_on>${this.timestamp}</sys_created_on><sys_id>${this.generateSysId()}</sys_id><sys_mod_count>0</sys_mod_count><sys_scope/><sys_updated_by>admin</sys_updated_by><sys_updated_on>${this.timestamp}</sys_updated_on><ui_id>${(0, uuid_1.v4)()}</ui_id><updation_source/><values>H4sIAAAAAAAA/6tWyi8tKSgtKQ7JdywuzkzPU7KKjtVRyswDiUHYZYlFmYlJOalQbkpqcmZxZn5eCEjME0ldSmVeYm5mMrJQeX5RdlpOfjlCrBYAD1ouqHEAAAA=</values><workflow_reference/></sys_hub_flow_logic_instance_v2></record_update>]]></payload>
453
+ <remote_update_set display_value="${this.escapeXml(this.updateSetName)}">${updateSetSysId}</remote_update_set>
454
+ <source_table>sys_hub_flow_logic_instance_v2</source_table>
455
+ <type>Flow Designer Logic</type>
456
+ </sys_update_xml>`);
457
+ }
458
+ // Add End logic node
459
+ connections.push(`
460
+ <!-- Flow Logic V2: End -->
461
+ <sys_update_xml action="INSERT_OR_UPDATE">
462
+ <sys_id>${this.generateSysId()}</sys_id>
463
+ <action>INSERT_OR_UPDATE</action>
464
+ <application display_value="Global">global</application>
465
+ <name>sys_hub_flow_logic_instance_v2_${endSysId}</name>
466
+ <payload><![CDATA[<?xml version="1.0" encoding="UTF-8"?><record_update table="sys_hub_flow_logic_instance_v2"><sys_hub_flow_logic_instance_v2 action="INSERT_OR_UPDATE"><attributes/><block display_value="">${this.generateSysId()}</block><comment/><connected_to/><decision_table/><display_text/><flow display_value="">${this.flowSysId}</flow><flow_variables_assigned/><generation_source/><logic_definition display_value="End">d176605ea76103004f27b0d2187901c7</logic_definition><order>${(activitySysIds.length + 1) * 100}</order><outputs_assigned/><parent_ui_id/><sys_class_name>sys_hub_flow_logic_instance_v2</sys_class_name><sys_created_by>admin</sys_created_by><sys_created_on>${this.timestamp}</sys_created_on><sys_id>${endSysId}</sys_id><sys_mod_count>0</sys_mod_count><sys_scope/><sys_updated_by>admin</sys_updated_by><sys_updated_on>${this.timestamp}</sys_updated_on><ui_id>${(0, uuid_1.v4)()}</ui_id><updation_source/><values>H4sIAAAAAAAA/6tWyi8tKSgtKQ7JdywuzkzPU7KKjtVRyswDiUHYZYlFmYlJOalQbkpqcmZxZn5eCEjME0ldSmVeYm5mMrJQeX5RdlpOfjlCrBYAD1ouqHEAAAA=</values><workflow_reference/></sys_hub_flow_logic_instance_v2></record_update>]]></payload>
467
+ <remote_update_set display_value="${this.escapeXml(this.updateSetName)}">${updateSetSysId}</remote_update_set>
468
+ <source_table>sys_hub_flow_logic_instance_v2</source_table>
469
+ <type>Flow Designer Logic</type>
470
+ </sys_update_xml>`);
471
+ return connections.join('\n');
472
+ }
473
+ /**
474
+ * Generate sys_hub_flow_logic XML for connections (deprecated, kept for compatibility)
417
475
  */
418
476
  generateFlowLogicXML(triggerSysId, activitySysIds, updateSetSysId) {
419
477
  const connections = [];
@@ -425,47 +425,38 @@ class XMLFirstFlowGenerator {
425
425
  }
426
426
  exports.XMLFirstFlowGenerator = XMLFirstFlowGenerator;
427
427
  /**
428
- * Generate PRODUCTION-READY flow XML (NO placeholders!)
428
+ * Generate PRODUCTION-READY flow XML with BOTH formats
429
429
  */
430
430
  function generateProductionFlowXML(flowDef) {
431
431
  const generator = new XMLFirstFlowGenerator(flowDef.name.replace(/[^a-zA-Z0-9]+/g, '_') + '_Import');
432
+ // Generate Update Set XML (better for automatic deployment)
432
433
  const xml = generator.generateFlowUpdateSetXML(flowDef);
433
434
  const filePath = generator.saveToFile(xml, flowDef.name.toLowerCase().replace(/[^a-z0-9]+/g, '_') + '_flow.xml');
434
435
  const instructions = `
435
- === ServiceNow Flow Import Instructions ===
436
+ === ServiceNow Flow Deployment Options ===
436
437
 
437
- 1. Log into your ServiceNow instance as an admin user
438
+ 🚀 OPTION 1: Automatic Deployment (RECOMMENDED)
439
+ Use the snow-flow deploy-xml command for complete automation:
440
+
441
+ snow-flow deploy-xml ${filePath}
442
+
443
+ This automatically:
444
+ ✅ Imports the Update Set
445
+ ✅ Previews for conflicts
446
+ ✅ Commits if clean
447
+ ✅ Reports any issues
438
448
 
439
- 2. Navigate to:
440
- System Update Sets > Retrieved Update Sets
449
+ 🔧 OPTION 2: Manual Import (if automatic fails)
450
+
451
+ 1. Log into ServiceNow as admin
452
+ 2. Navigate to: System Update Sets > Local Update Sets
453
+ 3. Click "Import Update Set from XML"
454
+ 4. Choose file: ${filePath}
455
+ 5. Click "Upload" and follow prompts
456
+ 6. Preview and commit the Update Set
457
+ 7. Find your flow in Flow Designer
441
458
 
442
- 3. Click the "Import Update Set from XML" link at the bottom of the list
443
- (NOT the "Import from XML" in the context menu!)
444
-
445
- 4. Choose file: ${filePath}
446
-
447
- 5. Click "Upload"
448
-
449
- 6. Find your imported Update Set in the list
450
-
451
- 7. Click on the Update Set name to open it
452
-
453
- 8. Click "Preview Update Set"
454
- - Review any errors or warnings
455
- - Resolve any missing dependencies
456
-
457
- 9. Once preview is clean, click "Commit Update Set"
458
-
459
- 10. Navigate to Flow Designer:
460
- - All > Flow Designer > Designer
461
- - Your flow "${flowDef.name}" should appear in the list
462
-
463
- 11. Open the flow to verify all components are present
464
-
465
- TROUBLESHOOTING:
466
- - If flow appears empty: Check that all sys_update_xml records were imported
467
- - If import fails: Verify you're using "Import Update Set from XML" link
468
- - For dependency errors: Import required plugins/applications first
459
+ The flow "${flowDef.name}" will appear in Flow Designer > Designer
469
460
  `.trim();
470
461
  return { xml, filePath, instructions };
471
462
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "snow-flow",
3
- "version": "1.3.16",
3
+ "version": "1.3.18",
4
4
  "description": "ServiceNow Queen Agent - Hive-Mind Intelligence for ServiceNow Development inspired by claude-flow. Transform complex workflows into elegant one-command orchestration.",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",