@jacebenson/jsn 0.0.7 → 0.0.9

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": "0.0.7",
3
+ "version": "0.0.9",
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": {
@@ -17,8 +17,8 @@ export function buildTicketCommands(table, displayName, alias, defaultColumns, s
17
17
  aliases: ['ls'],
18
18
  describe: `List ${table}`,
19
19
  builder: (y) => y
20
- .option('query', { type: 'string', describe: 'Encoded query string' })
21
- .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns' })
20
+ .option('query', { type: 'string', describe: 'Encoded query (e.g. "nameLIKEincident" or "active=true")' })
21
+ .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns (e.g. "number,short_description")' })
22
22
  .option('limit', { alias: 'l', type: 'number', default: 20, describe: 'Max records' })
23
23
  .option('offset', { alias: 'o', type: 'number', default: 0, describe: 'Offset for pagination' }),
24
24
  handler: wrap(async (argv, app) => {
@@ -61,8 +61,8 @@ export function buildDevCmd(name, table, aliases, defaultColumns, wrap, opts = {
61
61
  aliases: ['ls'],
62
62
  describe: `List ${name}`,
63
63
  builder: (y) => y
64
- .option('query', { type: 'string', describe: 'Encoded query string' })
65
- .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns' })
64
+ .option('query', { type: 'string', describe: 'Encoded query (e.g. "nameLIKEincident" or "active=true^priority=1")' })
65
+ .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns (e.g. "name,label,super_class")' })
66
66
  .option('limit', { alias: 'l', type: 'number', default: 20, describe: 'Max records' }),
67
67
  handler: wrap(async (argv, app) => {
68
68
  const columns = argv.columns ? argv.columns.split(',') : defaultColumns;
@@ -123,7 +123,7 @@ export function buildDevCmd(name, table, aliases, defaultColumns, wrap, opts = {
123
123
  .command({
124
124
  command: 'create',
125
125
  describe: `Create a new ${singular}`,
126
- builder: (y) => y.option('data', { type: 'string', demandOption: true, describe: 'JSON data' }),
126
+ builder: (y) => y.option('data', { type: 'string', demandOption: true, describe: 'JSON fields (e.g. \'{"state":"2"}\')' }),
127
127
  handler: wrap(async (argv, app) => {
128
128
  const recordData = JSON.parse(argv.data);
129
129
  const record = await app.sdk.create(table, recordData);
@@ -138,7 +138,7 @@ export function buildDevCmd(name, table, aliases, defaultColumns, wrap, opts = {
138
138
  .command({
139
139
  command: 'update <identifier>',
140
140
  describe: `Update ${vowelArticle(singular)} ${singular}`,
141
- builder: (y) => y.option('data', { type: 'string', demandOption: true, describe: 'JSON data' }),
141
+ builder: (y) => y.option('data', { type: 'string', demandOption: true, describe: 'JSON fields (e.g. \'{"state":"2"}\')' }),
142
142
  handler: wrap(async (argv, app) => {
143
143
  const id = argv.identifier;
144
144
  const queryField = isHexString(id) && id.length === 32 ? 'sys_id' : 'name';
@@ -12,8 +12,8 @@ export function flowsCmd(wrap) {
12
12
  aliases: ['ls'],
13
13
  describe: 'List flows',
14
14
  builder: (y) => y
15
- .option('query', { type: 'string', describe: 'Encoded query string' })
16
- .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns' })
15
+ .option('query', { type: 'string', describe: 'Encoded query (e.g. "nameLIKEincident" or "active=true")' })
16
+ .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns (e.g. "number,short_description")' })
17
17
  .option('limit', { alias: 'l', type: 'number', default: 20, describe: 'Max records' }),
18
18
  handler: wrap(async (argv, app) => {
19
19
  const columns = argv.columns ? argv.columns.split(',') : ['name', 'active', 'description', 'sys_created_by', 'sys_updated_on'];
@@ -12,8 +12,8 @@ export function logsCmd(wrap) {
12
12
  aliases: ['ls'],
13
13
  describe: 'List system logs',
14
14
  builder: (y) => y
15
- .option('query', { type: 'string', describe: 'Encoded query string' })
16
- .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns' })
15
+ .option('query', { type: 'string', describe: 'Encoded query (e.g. "nameLIKEincident" or "active=true")' })
16
+ .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns (e.g. "number,short_description")' })
17
17
  .option('limit', { alias: 'l', type: 'number', default: 50, describe: 'Max records' }),
18
18
  handler: wrap(async (argv, app) => {
19
19
  const columns = argv.columns ? argv.columns.split(',') : ['level', 'message', 'source', 'created'];
@@ -12,8 +12,8 @@ export function scopesCmd(wrap) {
12
12
  aliases: ['ls'],
13
13
  describe: 'List application scopes',
14
14
  builder: (y) => y
15
- .option('query', { type: 'string', describe: 'Encoded query string' })
16
- .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns' })
15
+ .option('query', { type: 'string', describe: 'Encoded query (e.g. "nameLIKEincident" or "active=true")' })
16
+ .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns (e.g. "number,short_description")' })
17
17
  .option('limit', { alias: 'l', type: 'number', default: 20, describe: 'Max records' }),
18
18
  handler: wrap(async (argv, app) => {
19
19
  const columns = argv.columns ? argv.columns.split(',') : ['name', 'scope', 'short_description', 'active'];
@@ -12,8 +12,8 @@ export function updateSetsCmd(wrap) {
12
12
  aliases: ['ls'],
13
13
  describe: 'List update sets',
14
14
  builder: (y) => y
15
- .option('query', { type: 'string', describe: 'Encoded query string' })
16
- .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns' })
15
+ .option('query', { type: 'string', describe: 'Encoded query (e.g. "nameLIKEincident" or "active=true")' })
16
+ .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns (e.g. "number,short_description")' })
17
17
  .option('limit', { alias: 'l', type: 'number', default: 20, describe: 'Max records' }),
18
18
  handler: wrap(async (argv, app) => {
19
19
  const columns = argv.columns ? argv.columns.split(',') : ['name', 'state', 'application'];
@@ -12,8 +12,8 @@ export function groupMembersCmd(wrap) {
12
12
  aliases: ['ls'],
13
13
  describe: 'List group members',
14
14
  builder: (y) => y
15
- .option('query', { type: 'string', describe: 'Encoded query string' })
16
- .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns' })
15
+ .option('query', { type: 'string', describe: 'Encoded query (e.g. "nameLIKEincident" or "active=true")' })
16
+ .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns (e.g. "number,short_description")' })
17
17
  .option('limit', { alias: 'l', type: 'number', default: 20, describe: 'Max records' }),
18
18
  handler: wrap(async (argv, app) => {
19
19
  const columns = argv.columns ? argv.columns.split(',') : ['user.name', 'group.name'];
@@ -12,8 +12,8 @@ export function groupRolesCmd(wrap) {
12
12
  aliases: ['ls'],
13
13
  describe: 'List group roles',
14
14
  builder: (y) => y
15
- .option('query', { type: 'string', describe: 'Encoded query string' })
16
- .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns' })
15
+ .option('query', { type: 'string', describe: 'Encoded query (e.g. "nameLIKEincident" or "active=true")' })
16
+ .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns (e.g. "number,short_description")' })
17
17
  .option('limit', { alias: 'l', type: 'number', default: 20, describe: 'Max records' }),
18
18
  handler: wrap(async (argv, app) => {
19
19
  const columns = argv.columns ? argv.columns.split(',') : ['group.name', 'role.name'];
@@ -12,8 +12,8 @@ export function groupsCmd(wrap) {
12
12
  aliases: ['ls'],
13
13
  describe: 'List groups',
14
14
  builder: (y) => y
15
- .option('query', { type: 'string', describe: 'Encoded query string' })
16
- .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns' })
15
+ .option('query', { type: 'string', describe: 'Encoded query (e.g. "nameLIKEincident" or "active=true")' })
16
+ .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns (e.g. "number,short_description")' })
17
17
  .option('limit', { alias: 'l', type: 'number', default: 20, describe: 'Max records' }),
18
18
  handler: wrap(async (argv, app) => {
19
19
  const columns = argv.columns ? argv.columns.split(',') : ['name', 'manager', 'email'];
@@ -30,8 +30,8 @@ export function recordsCmd(wrap) {
30
30
  describe: 'List records from a table',
31
31
  builder: (y) => y
32
32
  .option('table', { type: 'string', demandOption: true, describe: 'Table name' })
33
- .option('query', { type: 'string', describe: 'Encoded query string' })
34
- .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns' })
33
+ .option('query', { type: 'string', describe: 'Encoded query (e.g. "nameLIKEincident" or "active=true")' })
34
+ .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns (e.g. "number,short_description")' })
35
35
  .option('limit', { type: 'number', default: 20, describe: 'Max records' })
36
36
  .option('offset', { type: 'number', default: 0, describe: 'Offset' }),
37
37
  handler: wrap(async (argv, app) => {
@@ -80,7 +80,7 @@ export function recordsCmd(wrap) {
80
80
  builder: (y) => y
81
81
  .option('table', { type: 'string', demandOption: true, describe: 'Table name' })
82
82
  .option('sys-id', { type: 'string', demandOption: true, describe: 'Record sys_id' })
83
- .option('columns', { type: 'string', describe: 'Comma-separated columns' }),
83
+ .option('columns', { type: 'string', describe: 'Comma-separated columns (e.g. "number,short_description")' }),
84
84
  handler: wrap(async (argv, app) => {
85
85
  const params = new URLSearchParams();
86
86
  params.set('sysparm_query', `sys_id=${argv['sys-id']}`);
@@ -99,7 +99,7 @@ export function recordsCmd(wrap) {
99
99
  describe: 'Create a new record',
100
100
  builder: (y) => y
101
101
  .option('table', { type: 'string', demandOption: true, describe: 'Table name' })
102
- .option('data', { type: 'string', demandOption: true, describe: 'JSON data' }),
102
+ .option('data', { type: 'string', demandOption: true, describe: 'JSON fields (e.g. \'{"state":"2"}\')' }),
103
103
  handler: wrap(async (argv, app) => {
104
104
  const recordData = JSON.parse(argv.data);
105
105
  const record = await app.sdk.create(argv.table, recordData);
@@ -112,7 +112,7 @@ export function recordsCmd(wrap) {
112
112
  builder: (y) => y
113
113
  .option('table', { type: 'string', demandOption: true, describe: 'Table name' })
114
114
  .option('sys-id', { type: 'string', demandOption: true, describe: 'Record sys_id' })
115
- .option('data', { type: 'string', demandOption: true, describe: 'JSON data' }),
115
+ .option('data', { type: 'string', demandOption: true, describe: 'JSON fields (e.g. \'{"state":"2"}\')' }),
116
116
  handler: wrap(async (argv, app) => {
117
117
  const recordData = JSON.parse(argv.data);
118
118
  const record = await app.sdk.update(argv.table, argv['sys-id'], recordData);
@@ -12,8 +12,8 @@ export function ticketsCmd(wrap) {
12
12
  aliases: ['ls'],
13
13
  describe: 'List tickets',
14
14
  builder: (y) => y
15
- .option('query', { type: 'string', describe: 'Encoded query string' })
16
- .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns' })
15
+ .option('query', { type: 'string', describe: 'Encoded query (e.g. "active=true^priority=1")' })
16
+ .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns (e.g. "number,short_description,priority")' })
17
17
  .option('limit', { alias: 'l', type: 'number', default: 20, describe: 'Max records' })
18
18
  .option('offset', { alias: 'o', type: 'number', default: 0, describe: 'Offset' }),
19
19
  handler: wrap(async (argv, app) => {
@@ -73,7 +73,7 @@ export function ticketsCmd(wrap) {
73
73
  .command({
74
74
  command: 'create',
75
75
  describe: 'Create a new ticket',
76
- builder: (y) => y.option('data', { type: 'string', demandOption: true, describe: 'JSON data' }),
76
+ builder: (y) => y.option('data', { type: 'string', demandOption: true, describe: 'JSON fields (e.g. \'{"state":"2","priority":"1"}\')' }),
77
77
  handler: wrap(async (argv, app) => {
78
78
  const recordData = JSON.parse(argv.data);
79
79
  const record = await app.sdk.create('ticket', recordData);
@@ -83,7 +83,7 @@ export function ticketsCmd(wrap) {
83
83
  .command({
84
84
  command: 'update <number>',
85
85
  describe: 'Update a ticket',
86
- builder: (y) => y.option('data', { type: 'string', demandOption: true, describe: 'JSON data' }),
86
+ builder: (y) => y.option('data', { type: 'string', demandOption: true, describe: 'JSON fields (e.g. \'{"state":"2","priority":"1"}\')' }),
87
87
  handler: wrap(async (argv, app) => {
88
88
  const recordData = JSON.parse(argv.data);
89
89
  const findParams = new URLSearchParams();
@@ -12,8 +12,8 @@ export function usersCmd(wrap) {
12
12
  aliases: ['ls'],
13
13
  describe: 'List users',
14
14
  builder: (y) => y
15
- .option('query', { type: 'string', describe: 'Encoded query string' })
16
- .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns' })
15
+ .option('query', { type: 'string', describe: 'Encoded query (e.g. "nameLIKEincident" or "active=true")' })
16
+ .option('columns', { alias: 'c', type: 'string', describe: 'Comma-separated columns (e.g. "number,short_description")' })
17
17
  .option('limit', { alias: 'l', type: 'number', default: 20, describe: 'Max records' }),
18
18
  handler: wrap(async (argv, app) => {
19
19
  const columns = argv.columns ? argv.columns.split(',') : ['user_name', 'name', 'email', 'active'];
package/src/config.js CHANGED
@@ -50,6 +50,7 @@ function loadFromFile(cfg, filePath, source) {
50
50
  }
51
51
  if (fileCfg.default_profile) {
52
52
  cfg.defaultProfile = fileCfg.default_profile;
53
+ cfg.activeProfile = fileCfg.default_profile;
53
54
  cfg.sources.default_profile = source;
54
55
  }
55
56
  if (fileCfg.profiles && typeof fileCfg.profiles === 'object') {
@@ -134,8 +135,9 @@ export function saveLocalConfig(cfg) {
134
135
  }
135
136
 
136
137
  export function getEffectiveInstance(cfg) {
137
- if (cfg.activeProfile && cfg.profiles[cfg.activeProfile] && cfg.profiles[cfg.activeProfile].instance_url) {
138
- return cfg.profiles[cfg.activeProfile].instance_url;
138
+ const name = cfg.activeProfile || cfg.defaultProfile;
139
+ if (name && cfg.profiles[name] && cfg.profiles[name].instance_url) {
140
+ return cfg.profiles[name].instance_url;
139
141
  }
140
142
  return cfg.instanceURL || '';
141
143
  }