@jacebenson/jsn 3.0.1 → 3.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": "3.0.1",
3
+ "version": "3.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": {
package/src/app.js CHANGED
@@ -7,6 +7,7 @@ import { getEffectiveInstance } from './config.js';
7
7
  import { extractProfileName } from './helpers.js';
8
8
  import { getCurrentUser, getCurrentApplication, getCurrentUpdateSet } from './context.js';
9
9
  import { errUsage, errAuth } from './errors.js';
10
+ import { isMutationCommand } from './mutations.js';
10
11
  import process from 'node:process';
11
12
 
12
13
 
@@ -57,7 +58,7 @@ export class App {
57
58
  return getEffectiveInstance(this.config);
58
59
  }
59
60
 
60
- async printContextHeader() {
61
+ async printContextHeader(argv = {}) {
61
62
  if (!this.getEffectiveInstance() || !this.sdk) return;
62
63
  if (process.env.JSN_NO_HEADER) return;
63
64
  if (this.output.getFormat() === FormatJSON || this.output.getFormat() === FormatQuiet) return;
@@ -127,8 +128,10 @@ export class App {
127
128
 
128
129
  process.stderr.write(`${profileStr} ${userStr} ${scopeStr} ${updateSetStr}\n\n`);
129
130
 
130
- // ⚠️ Warning if in the Default update set
131
- if (updateSet && updateSet.toLowerCase().includes('default')) {
131
+ // ⚠️ Warning if in the Default update set (mutation commands only)
132
+ const profile = this.context.profileName ? this.config.profiles[this.context.profileName] : null;
133
+ const isYolo = profile?.yolo === true;
134
+ if (!isYolo && isMutationCommand(argv) && updateSet && updateSet.toLowerCase().includes('default')) {
132
135
  const isGlobal = scope === 'global';
133
136
  if (isGlobal) {
134
137
  // 🔴 HARD WARNING — Global + Default
@@ -146,7 +149,7 @@ export class App {
146
149
  '┃ Or switch to a scoped scope first: ┃\n' +
147
150
  '┃ jsn dev scopes list ┃\n' +
148
151
  '┃ ┃\n' +
149
- '┃ (Run jsn updatesets yolo to silence this check) ┃\n' +
152
+ '┃ (Run jsn dev updatesets yolo to silence this check) ┃\n' +
150
153
  '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\x1b[0m\n'
151
154
  );
152
155
  } else {
@@ -157,7 +160,7 @@ export class App {
157
160
  ' ⚠ Default update set in scope [' + scope + ']\n' +
158
161
  ' Changes are contained to this scope, but a named\n' +
159
162
  ' update set is still recommended for tracking.\n' +
160
- ' (Run \x1b[1mjsn updatesets yolo\x1b[22m to silence this warning)\n' +
163
+ ' (Run \x1b[1mjsn dev updatesets yolo\x1b[22m to silence this warning)\n' +
161
164
  '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n' +
162
165
  '\x1b[0m' // reset
163
166
  );
package/src/cli.js CHANGED
@@ -156,7 +156,7 @@ export const cli = yargs(hideBin(process.argv))
156
156
 
157
157
  // Print context header for interactive terminals (at the TOP, before command output)
158
158
  if (!['help', 'version', 'completion', 'skill'].includes(cmd)) {
159
- await argv.app.printContextHeader();
159
+ await argv.app.printContextHeader(argv);
160
160
  }
161
161
  })
162
162
  .command(setupCmd(wrap))
@@ -185,6 +185,25 @@ export const cli = yargs(hideBin(process.argv))
185
185
  if (err) throw err;
186
186
  // No command given → show custom grouped help instead of yargs error
187
187
  if (msg === 'You must specify a command') {
188
+ // Check if --profile/-p was used without a value — show profile info instead
189
+ const raw = process.argv.slice(2);
190
+ const hasLoneProfile = raw.some((a, i, arr) => {
191
+ if (a !== '--profile' && a !== '-p') return false;
192
+ const next = arr[i + 1];
193
+ return !next || next.startsWith('-');
194
+ });
195
+ if (hasLoneProfile) {
196
+ const cfg = loadConfig();
197
+ const activeName = cfg.activeProfile || cfg.defaultProfile;
198
+ process.stdout.write('Profiles:\n');
199
+ for (const [name, p] of Object.entries(cfg.profiles || {})) {
200
+ const marker = name === activeName ? ' *' : ' ';
201
+ process.stdout.write(` ${marker} ${name.padEnd(20)} ${p.instance_url || ''}\n`);
202
+ }
203
+ process.stdout.write('\nUsage: jsn --profile <name> <command>\n');
204
+ process.stdout.write(' jsn profiles use <name>\n');
205
+ process.exit(0);
206
+ }
188
207
  process.stdout.write(renderHelp());
189
208
  process.exit(0);
190
209
  }
@@ -6,8 +6,8 @@ export function evalCmd(wrap) {
6
6
  describe: 'Execute background scripts on the instance',
7
7
  builder: (yargs) => {
8
8
  return yargs
9
- .option('script', { alias: 's', type: 'string', describe: 'JavaScript code to execute' })
10
- .option('file', { alias: 'f', type: 'string', describe: 'Read script from file' });
9
+ .option('script', { alias: 's', type: 'string', describe: "JavaScript code to execute (single-quote the script, double quotes inside: --script 'gs.log(\"Hello\")')" })
10
+ .option('file', { alias: 'f', type: 'string', describe: 'Read script from file (avoids shell quoting issues)' });
11
11
  },
12
12
  handler: wrap(async (argv, app) => {
13
13
  let script;
@@ -54,6 +54,10 @@ export function formsCmd(wrap) {
54
54
  aliases: ['ls'],
55
55
  describe: 'List form views for a table',
56
56
  builder: (y) => y
57
+ .positional('table', {
58
+ describe: 'Table name (e.g. incident, change_request)',
59
+ type: 'string',
60
+ })
57
61
  .option('limit', { alias: 'l', type: 'number', default: 50, describe: 'Max records' }),
58
62
  handler: wrap(async (argv, app) => {
59
63
  const table = argv.table;
@@ -45,6 +45,10 @@ export function listsCmd(wrap) {
45
45
  aliases: ['ls'],
46
46
  describe: 'List list views for a table',
47
47
  builder: (y) => y
48
+ .positional('table', {
49
+ describe: 'Table name (e.g. incident, change_request)',
50
+ type: 'string',
51
+ })
48
52
  .option('limit', { alias: 'l', type: 'number', default: 50, describe: 'Max records' }),
49
53
  handler: wrap(async (argv, app) => {
50
54
  const table = argv.table;
@@ -47,14 +47,24 @@ export function scopesCmd(wrap) {
47
47
  .command({
48
48
  command: 'show <scope>',
49
49
  aliases: ['get'],
50
- describe: 'Show a scope',
50
+ describe: 'Show a scope by scope value or name',
51
+ builder: (y) => y
52
+ .positional('scope', {
53
+ describe: 'Scope value (e.g. x_417611_daves_o_0) or display name',
54
+ type: 'string',
55
+ }),
51
56
  handler: wrap(async (argv, app) => {
52
- const params = new URLSearchParams();
53
- params.set('sysparm_query', `scope=${argv.scope}`);
54
- params.set('sysparm_limit', '1');
55
- params.set('sysparm_display_value', 'all');
56
- const records = await app.sdk.list('sys_scope', params);
57
- if (records.length === 0) {
57
+ let records;
58
+ // Try by scope value first, then by name
59
+ for (const queryField of ['scope', 'name']) {
60
+ const params = new URLSearchParams();
61
+ params.set('sysparm_query', `${queryField}=${argv.scope}`);
62
+ params.set('sysparm_limit', '1');
63
+ params.set('sysparm_display_value', 'all');
64
+ records = await app.sdk.list('sys_scope', params);
65
+ if (records.length > 0) break;
66
+ }
67
+ if (!records || records.length === 0) {
58
68
  throw new Error(`Scope not found: ${argv.scope}`);
59
69
  }
60
70
  app.ok(records[0], { summary: `Scope ${argv.scope}` });
@@ -162,6 +162,21 @@ export function updateSetsCmd(wrap) {
162
162
  });
163
163
  }),
164
164
  })
165
+ .command({
166
+ command: 'yolo',
167
+ aliases: ['silence'],
168
+ describe: 'Silence the "Default update set" warning for this profile',
169
+ handler: wrap(async (argv, app) => {
170
+ const name = app.context.profileName;
171
+ if (!name) {
172
+ throw new Error('No active profile to mark as yolo. Run jsn setup first.');
173
+ }
174
+ app.config.profiles[name].yolo = true;
175
+ const { saveConfig } = await import('../../config.js');
176
+ saveConfig(app.config);
177
+ app.ok({ profile: name, yolo: true }, { summary: 'Default update set warning silenced for this profile' });
178
+ }),
179
+ })
165
180
 
166
181
  },
167
182
  handler: (argv) => {
@@ -181,6 +181,9 @@ export function profilesCmd(wrap) {
181
181
  console.log(' use <name> Switch to a different profile');
182
182
  console.log(' remove <name> Remove a profile');
183
183
  console.log('\nRun "jsn profiles <command> --help" for more details.');
184
+ console.log('\nNote: You can also create a profile by authenticating:');
185
+ console.log(' jsn auth login --profile <name> <instance-url>');
186
+ console.log(' jsn auth login --profile staging --password https://dev12345.service-now.com');
184
187
  }
185
188
  },
186
189
  };
@@ -26,7 +26,7 @@ export function ticketsCmd(wrap) {
26
26
  if (fields) params.set('sysparm_fields', fields);
27
27
  const q = argv.query ? argv.query + '^ORDERBYDESCsys_updated_on' : 'ORDERBYDESCsys_updated_on';
28
28
  params.set('sysparm_query', q);
29
- const records = await app.sdk.list('ticket', params);
29
+ const records = await app.sdk.list('task', params);
30
30
  const displayRecords = fields ? records.map(r => formatRecordForDisplay(r, columns)) : records;
31
31
  const breadcrumbs = [
32
32
  { action: 'create', cmd: 'jsn tickets create --data \'{...}\'', description: 'Create a new ticket' },
@@ -46,7 +46,7 @@ export function ticketsCmd(wrap) {
46
46
  });
47
47
  }
48
48
  app.ok({
49
- table: 'ticket',
49
+ table: 'task',
50
50
  count: records.length,
51
51
  columns,
52
52
  records: displayRecords,
@@ -64,7 +64,7 @@ export function ticketsCmd(wrap) {
64
64
  params.set('sysparm_query', `number=${argv.number}`);
65
65
  params.set('sysparm_limit', '1');
66
66
  params.set('sysparm_display_value', 'all');
67
- const records = await app.sdk.list('ticket', params);
67
+ const records = await app.sdk.list('task', params);
68
68
  if (records.length === 0) {
69
69
  throw new Error(`Ticket not found: ${argv.number}`);
70
70
  }
@@ -77,7 +77,7 @@ export function ticketsCmd(wrap) {
77
77
  builder: (y) => y.option('data', { type: 'string', demandOption: true, describe: 'JSON fields (e.g. \'{"state":"2","priority":"1"}\')' }),
78
78
  handler: wrap(async (argv, app) => {
79
79
  const recordData = JSON.parse(argv.data);
80
- const record = await app.sdk.create('ticket', recordData);
80
+ const record = await app.sdk.create('task', recordData);
81
81
  app.ok(record, { summary: `Created ticket ${getStringField(record, 'number')}` });
82
82
  }),
83
83
  })
@@ -90,12 +90,12 @@ export function ticketsCmd(wrap) {
90
90
  const findParams = new URLSearchParams();
91
91
  findParams.set('sysparm_query', `number=${argv.number}`);
92
92
  findParams.set('sysparm_limit', '1');
93
- const records = await app.sdk.list('ticket', findParams);
93
+ const records = await app.sdk.list('task', findParams);
94
94
  if (records.length === 0) {
95
95
  throw new Error(`Ticket not found: ${argv.number}`);
96
96
  }
97
97
  const sysID = getStringField(records[0], 'sys_id');
98
- const updated = await app.sdk.update('ticket', sysID, recordData);
98
+ const updated = await app.sdk.update('task', sysID, recordData);
99
99
  app.ok(updated, { summary: `Updated ticket ${argv.number}` });
100
100
  }),
101
101
  })
@@ -106,12 +106,12 @@ export function ticketsCmd(wrap) {
106
106
  const findParams = new URLSearchParams();
107
107
  findParams.set('sysparm_query', `number=${argv.number}`);
108
108
  findParams.set('sysparm_limit', '1');
109
- const records = await app.sdk.list('ticket', findParams);
109
+ const records = await app.sdk.list('task', findParams);
110
110
  if (records.length === 0) {
111
111
  throw new Error(`Ticket not found: ${argv.number}`);
112
112
  }
113
113
  const sysID = getStringField(records[0], 'sys_id');
114
- await app.sdk.delete('ticket', sysID);
114
+ await app.sdk.delete('task', sysID);
115
115
  app.ok({ number: argv.number, message: 'Ticket deleted' }, { summary: `Deleted ticket ${argv.number}` });
116
116
  }),
117
117
  })
package/src/mutations.js CHANGED
@@ -23,11 +23,32 @@ export const MUTATION_COMMANDS = [
23
23
  ['tasks', 'create'],
24
24
  ['tasks', 'update'],
25
25
  ['tasks', 'delete'],
26
- // Dev
26
+ // Tickets
27
+ ['tickets', 'create'],
28
+ ['tickets', 'update'],
29
+ ['tickets', 'delete'],
30
+ // Users
31
+ ['users', 'create'],
32
+ ['users', 'update'],
33
+ ['users', 'delete'],
34
+ // Groups
35
+ ['groups', 'create'],
36
+ ['groups', 'update'],
37
+ ['groups', 'delete'],
38
+ // Catalog
39
+ ['catalog', 'create-item'],
40
+ // Dev flows
41
+ ['dev', 'flows', 'create'],
42
+ ['dev', 'flows', 'update'],
43
+ ['dev', 'flows', 'delete'],
44
+ // Dev scopes
45
+ ['dev', 'scopes', 'create'],
46
+ ['dev', 'scopes', 'set'],
47
+ // Dev eval
27
48
  ['dev', 'eval'],
49
+ // Dev updatesets
28
50
  ['dev', 'updatesets', 'set'],
29
51
  ['dev', 'updatesets', 'create'],
30
- ['dev', 'scopes', 'set'],
31
52
  ];
32
53
 
33
54
  /**