@jacebenson/jsn 4.3.8-dev.49 → 4.3.8-dev.51

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.3.8-dev.49",
3
+ "version": "4.3.8-dev.51",
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": {
@@ -55,7 +55,7 @@ export const actionsCmd = wrap => {
55
55
  describe: 'Flow Designer actions: create, edit full definitions, and test with outputs',
56
56
  builder: y => base.builder(y)
57
57
  .command({
58
- command: 'create', describe: 'Create parent and executable Process Flow action; verify persistence',
58
+ command: 'create', describe: `Create parent and executable Process Flow action; verify persistence. --data/--data-file requires a full definition with inputs, outputs, and steps arrays. Variables have name and type; each step requires cid, step_type, and inputs, outputs, extended_inputs, extended_outputs arrays. Use step_types for valid step_type schema. Example (structure only):\n{"name":"Example action","inputs":[{"name":"record_id","type":"string"}],"outputs":[],"steps":[{"cid":"step-1","step_type":"<stepTypeFromSchema>","inputs":[],"outputs":[],"extended_inputs":[],"extended_outputs":[]}]}`,
59
59
  builder: yy => dataOptions(yy).option('scope', { type: 'string', describe: 'Exact target scope sys_id, or global' }),
60
60
  handler: run(async (argv, app) => {
61
61
  const guided = !hasDefinitionData(argv) ? await guidedActionCreate(argv, app) : undefined;
@@ -294,7 +294,7 @@ export function flowsCmd(wrap) {
294
294
  })
295
295
  .command({
296
296
  command: 'create',
297
- describe: 'Create a draft flow: pick a trigger category then trigger in a terminal, or use a JSON manifest in scripts',
297
+ describe: `Create a draft flow. JSON manifest fields: name (required), scope (required), optional description, trigger { type (required), optional table, condition, inputs }, actions (required array of { type, optional inputs }). Trigger type must be supported; trigger inputs and action inputs are objects. Flow Logic, subflows, variables, and errorHandling are unsupported. Example:\n{"name":"Approval flow","scope":"global","trigger":{"type":"record_create_or_update","table":"incident"},"actions":[{"type":"<actionTypeSysId>","inputs":{"message":"Created"}}]}`,
298
298
  builder: (y) => y
299
299
  .option('data', { type: 'string', describe: 'Flow manifest as inline JSON' })
300
300
  .option('data-file', { type: 'string', describe: 'Read the flow manifest from a JSON file' })
@@ -322,7 +322,7 @@ export function flowsCmd(wrap) {
322
322
  .command({
323
323
  command: 'update [identifier]',
324
324
  aliases: ['edit'],
325
- describe: 'Safely update supported fields of an existing inactive Draft flow',
325
+ describe: `Safely update an inactive Draft flow. JSON may contain scope, trigger { optional type: "record_create_or_update", table and/or condition }, and/or actions [{ order (positive integer), type, inputs (non-empty object of changed values) }]. Only existing trigger and action inputs are updated; omitted values are preserved. Example:\n{"trigger":{"table":"incident","condition":"active=true"},"actions":[{"order":1,"type":"<existingActionTypeSysId>","inputs":{"message":"Updated"}}]}`,
326
326
  builder: (y) => y
327
327
  .option('data', { type: 'string', describe: 'Update manifest as inline JSON' })
328
328
  .option('data-file', { type: 'string', describe: 'Read the update manifest from a JSON file' })
@@ -80,9 +80,21 @@ export async function publishFlows(sdk, flowIDs = [], actionIDs = []) {
80
80
  /** Publish one flow through the ProcessFlow snapshot/version lifecycle. */
81
81
  export async function publishFlowLifecycle(sdk, instance, flowId) {
82
82
  const flowRecord = sdk.get ? await sdk.get('sys_hub_flow', flowId) : null;
83
- const scope = str(flowRecord, 'scope');
84
- if (!scope) throw new Error(`Flow ${flowId} has no transaction scope; refusing to publish`);
85
- const definitionResponse = await sdk.request(`${instance}${PROCESSFLOW_PATH}/${encodeURIComponent(flowId)}?sysparm_transaction_scope=${encodeURIComponent(scope)}`, { method: 'GET' });
83
+ const flowPath = `${instance}${PROCESSFLOW_PATH}/${encodeURIComponent(flowId)}`;
84
+ // sys_hub_flow.scope is often omitted by the Table API for newly created
85
+ // flows. The ProcessFlow definition carries the application scope needed by
86
+ // its snapshot and version endpoints, so read it before constructing either.
87
+ let scope = str(flowRecord, 'scope');
88
+ let definitionResponse;
89
+ if (!scope) {
90
+ definitionResponse = await sdk.request(flowPath, { method: 'GET' });
91
+ const initialDefinition = definitionResponse?.result?.data ?? definitionResponse?.data?.result?.data ?? definitionResponse?.data ?? definitionResponse?.result ?? definitionResponse;
92
+ scope = str(initialDefinition, 'scope');
93
+ if (!scope) throw new Error(`Flow ${flowId} has no transaction scope; refusing to publish`);
94
+ }
95
+ if (!definitionResponse) {
96
+ definitionResponse = await sdk.request(`${flowPath}?sysparm_transaction_scope=${encodeURIComponent(scope)}`, { method: 'GET' });
97
+ }
86
98
  const definition = definitionResponse?.result?.data ?? definitionResponse?.data?.result?.data ?? definitionResponse?.data ?? definitionResponse?.result ?? definitionResponse;
87
99
  if (!definition || typeof definition !== 'object') throw new Error(`Flow definition could not be read for ${flowId}`);
88
100
  const definitionScope = str(definition, 'scope');