para-cli 1.17.2 → 1.18.0
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/LICENSE +1 -1
- package/README.md +3 -0
- package/index.js +86 -5
- package/package.json +3 -3
- package/para-cli.js +71 -49
package/LICENSE
CHANGED
|
@@ -187,7 +187,7 @@
|
|
|
187
187
|
same "printed page" as the copyright notice for easier
|
|
188
188
|
identification within third-party archives.
|
|
189
189
|
|
|
190
|
-
Copyright
|
|
190
|
+
Copyright 2022 Erudika LTD, https://erudika.com
|
|
191
191
|
|
|
192
192
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
193
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ This is the command-line tool for interacting with a Para server.
|
|
|
19
19
|
```sh
|
|
20
20
|
$ npm install -g para-cli
|
|
21
21
|
$ para-cli setup
|
|
22
|
+
$ para-cli ping
|
|
22
23
|
```
|
|
23
24
|
|
|
24
25
|
## Usage
|
|
@@ -38,6 +39,8 @@ $ para-cli setup
|
|
|
38
39
|
|
|
39
40
|
Commands:
|
|
40
41
|
setup Initial setup, prompts you to enter your Para API keys and endpoint
|
|
42
|
+
apps Returns a list of all Para apps
|
|
43
|
+
select <appid> Selects a Para app as a target for all subsequent read/write requests.
|
|
41
44
|
create <file|glob> [--id] [--type] Persists files as Para objects and makes them searchable
|
|
42
45
|
read --id 123 [--id 345 ...] Fetches objects with the given ids
|
|
43
46
|
update <file.json|glob> ... Updates Para objects with the data from a JSON file (must contain id field)
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright 2013-
|
|
2
|
+
* Copyright 2013-2022 Erudika. https://erudika.com
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -56,12 +56,28 @@ export function setup(config) {
|
|
|
56
56
|
rl.question(cyan.bold('Para Access Key: '), function (accessKey) {
|
|
57
57
|
rl.question(cyan.bold('Para Secret Key: '), function (secretKey) {
|
|
58
58
|
rl.question(cyan.bold('Para Endpoint: '), function (endpoint) {
|
|
59
|
-
var access = accessKey || config.get('accessKey');
|
|
60
|
-
var secret = secretKey || config.get('secretKey');
|
|
59
|
+
var access = (accessKey || config.get('accessKey')).trim();
|
|
60
|
+
var secret = (secretKey || config.get('secretKey')).trim();
|
|
61
|
+
var endpoint = (endpoint || config.get('endpoint')).trim();
|
|
61
62
|
newJWT(access, secret, endpoint, config);
|
|
62
63
|
var pc = new ParaClient(access, secret, { endpoint: endpoint || defaultConfig.endpoint });
|
|
63
64
|
ping(pc, config);
|
|
64
|
-
|
|
65
|
+
if (access === 'app:para') {
|
|
66
|
+
listApps(pc, function () {
|
|
67
|
+
// if none, ask to create one
|
|
68
|
+
rl.question(cyan.bold('Would you like to create a new Para app? [Y/n] '), function (Yn) {
|
|
69
|
+
Yn = Yn.trim();
|
|
70
|
+
if ('' === Yn || 'y' === Yn || 'Y' === Yn) {
|
|
71
|
+
rl.question(cyan.bold('App name: '), function (appname) {
|
|
72
|
+
newApp(pc, ['', appname], {});
|
|
73
|
+
rl.close();
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
rl.close();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
65
81
|
});
|
|
66
82
|
});
|
|
67
83
|
});
|
|
@@ -294,9 +310,11 @@ export function ping(pc, config) {
|
|
|
294
310
|
cyan(mee.type + ' ' + mee.name + ' (' + mee.id + ')'));
|
|
295
311
|
}).catch(function () {
|
|
296
312
|
fail('Connection failed. Run "para-cli setup" or check the configuration file', yellow(config.path));
|
|
313
|
+
process.exit(1);
|
|
297
314
|
});
|
|
298
315
|
}).catch(function () {
|
|
299
316
|
fail('Connection failed. Run "para-cli setup" or check the configuration file', yellow(config.path));
|
|
317
|
+
process.exit(1);
|
|
300
318
|
});
|
|
301
319
|
}
|
|
302
320
|
|
|
@@ -353,7 +371,9 @@ function promiseWhile(results, fn) {
|
|
|
353
371
|
function loop() {
|
|
354
372
|
return Promise.resolve(fn()).then(function (result) {
|
|
355
373
|
if (result && result.length > 0) {
|
|
356
|
-
|
|
374
|
+
result.forEach(function (res) {
|
|
375
|
+
results.push(res);
|
|
376
|
+
});
|
|
357
377
|
return loop();
|
|
358
378
|
}
|
|
359
379
|
resolve();
|
|
@@ -406,6 +426,67 @@ export function rebuildIndex(pc, config, flags) {
|
|
|
406
426
|
});
|
|
407
427
|
}
|
|
408
428
|
|
|
429
|
+
export function listApps(config, flags, parentAccessKey, failureCallback) {
|
|
430
|
+
var accessKey = flags.accessKey || process.env.PARA_ACCESS_KEY || config.get('accessKey');
|
|
431
|
+
var secretKey = flags.secretKey || process.env.PARA_SECRET_KEY || config.get('secretKey');
|
|
432
|
+
var endpoint = flags.endpoint || process.env.PARA_ENDPOINT || config.get('endpoint');
|
|
433
|
+
var pc = new ParaClient(accessKey, secretKey, {endpoint: endpoint});
|
|
434
|
+
var p = new Pager();
|
|
435
|
+
var results = [];
|
|
436
|
+
p.sortby = '_docid';
|
|
437
|
+
p.page = 1;
|
|
438
|
+
promiseWhile(results, function () {
|
|
439
|
+
return pc.findQuery('app', '*', p);
|
|
440
|
+
}).then(function () {
|
|
441
|
+
var apps = results.map(function (app) {return app.appIdentifier.trim();});
|
|
442
|
+
if (apps.length) {
|
|
443
|
+
console.log('Found', p.count, 'apps:', yellow('[') + green(apps.join(yellow('] ['))) + yellow(']'));
|
|
444
|
+
console.log('Typing', cyan('para-cli select'), green(apps[0]), 'will switch to that app. Current app:',
|
|
445
|
+
green(parentAccessKey));
|
|
446
|
+
process.exit(0);
|
|
447
|
+
} else {
|
|
448
|
+
failureCallback();
|
|
449
|
+
}
|
|
450
|
+
}).catch(function (err) {
|
|
451
|
+
failureCallback();
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
export function selectApp(pc, input, config, flags) {
|
|
456
|
+
var accessKey = flags.accessKey || process.env.PARA_ACCESS_KEY || config.get('accessKey');
|
|
457
|
+
var secretKey = flags.secretKey || process.env.PARA_SECRET_KEY || config.get('secretKey');
|
|
458
|
+
if (accessKey === 'app:para' && secretKey) {
|
|
459
|
+
var selectedApp = 'app:' + (input[1] || 'para').trim();
|
|
460
|
+
if (selectedApp === 'app:para') {
|
|
461
|
+
config.delete('selectedApp');
|
|
462
|
+
console.log(green('✔'), 'Selected', green(selectedApp), 'as the current app.');
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
var now = Math.round(new Date().getTime() / 1000);
|
|
466
|
+
var jwt = sign(JSON.stringify({
|
|
467
|
+
iat: now,
|
|
468
|
+
exp: now + 60,
|
|
469
|
+
appid: accessKey,
|
|
470
|
+
getCredentials: selectedApp
|
|
471
|
+
}), secretKey, { algorithm: 'HS256' });
|
|
472
|
+
pc.setAccessToken(jwt);
|
|
473
|
+
pc.me(jwt).then(function (data) {
|
|
474
|
+
if (data && data.credentials) {
|
|
475
|
+
config.set('selectedApp', data.credentials);
|
|
476
|
+
console.log(green('✔'), 'Selected', green(selectedApp), 'as the current app.');
|
|
477
|
+
} else {
|
|
478
|
+
fail('That did not work -' + red(input[1]) + ' try updating Para to the latest version.');
|
|
479
|
+
}
|
|
480
|
+
pc.clearAccessToken();
|
|
481
|
+
}).catch(function (err) {
|
|
482
|
+
fail('App ' + red(input[1]) + ' not found!');
|
|
483
|
+
pc.clearAccessToken();
|
|
484
|
+
});
|
|
485
|
+
} else {
|
|
486
|
+
fail('This command only works when Para CLI is configured to use the keys for the root app.');
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
409
490
|
function sendFileChunk(chunkId, textEncoded, json, id, flags, start, end, pc, decoder) {
|
|
410
491
|
if (start > 0 && textEncoded[start] !== 32) {
|
|
411
492
|
for (var i = 0; i < 100 && start - i >= 0; i++) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "para-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Command-line tool for Para backend servers",
|
|
6
6
|
"homepage": "https://paraio.org",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"api"
|
|
25
25
|
],
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"eslint": "^8.
|
|
27
|
+
"eslint": "^8.8.0"
|
|
28
28
|
},
|
|
29
29
|
"repository": "Erudika/para-cli",
|
|
30
30
|
"dependencies": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"exit": "^0.1.2",
|
|
35
35
|
"figlet": "^1.5.0",
|
|
36
36
|
"get-stdin": "^9.0.0",
|
|
37
|
-
"globby": "^13.1.
|
|
37
|
+
"globby": "^13.1.1",
|
|
38
38
|
"htmlparser2": "^7.2.0",
|
|
39
39
|
"jsonwebtoken": "^8.5.1",
|
|
40
40
|
"meow": "^10.0.1",
|
package/para-cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
|
-
* Copyright 2013-
|
|
4
|
+
* Copyright 2013-2022 Erudika. https://erudika.com
|
|
5
5
|
*
|
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
7
|
* you may not use this file except in compliance with the License.
|
|
@@ -27,9 +27,9 @@ import Conf from 'conf';
|
|
|
27
27
|
import figlet from 'figlet';
|
|
28
28
|
import chalk from 'chalk';
|
|
29
29
|
import meow from 'meow';
|
|
30
|
-
import { defaultConfig, setup, createAll, readAll, updateAll, deleteAll, search, newKeys, newJWT, newApp, ping, me, appSettings, rebuildIndex, exportData, importData } from './index.js';
|
|
30
|
+
import { defaultConfig, setup, listApps, selectApp, createAll, readAll, updateAll, deleteAll, search, newKeys, newJWT, newApp, ping, me, appSettings, rebuildIndex, exportData, importData } from './index.js';
|
|
31
31
|
|
|
32
|
-
const { blue } = chalk;
|
|
32
|
+
const { red, green, blue } = chalk;
|
|
33
33
|
const { textSync } = figlet;
|
|
34
34
|
|
|
35
35
|
var cli = meow(`
|
|
@@ -38,6 +38,8 @@ var cli = meow(`
|
|
|
38
38
|
|
|
39
39
|
Commands:
|
|
40
40
|
setup Initial setup, prompts you to enter your Para API keys and endpoint
|
|
41
|
+
apps Returns a list of all Para apps
|
|
42
|
+
select <appid> Selects a Para app as a target for all subsequent read/write requests.
|
|
41
43
|
create <file|glob> [--id] [--type] Persists files as Para objects and makes them searchable
|
|
42
44
|
read --id 123 [--id 345 ...] Fetches objects with the given ids
|
|
43
45
|
update <file.json|glob> ... Updates Para objects with the data from a JSON file (must contain id field)
|
|
@@ -104,68 +106,88 @@ var flags = cli.flags;
|
|
|
104
106
|
var accessKey = flags.accessKey || process.env.PARA_ACCESS_KEY || config.get('accessKey');
|
|
105
107
|
var secretKey = flags.secretKey || process.env.PARA_SECRET_KEY || config.get('secretKey');
|
|
106
108
|
var endpoint = flags.endpoint || process.env.PARA_ENDPOINT || config.get('endpoint');
|
|
107
|
-
var
|
|
109
|
+
var selectedApp = config.get('selectedApp');
|
|
108
110
|
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
+
if (selectedApp && selectedApp.accessKey && selectedApp.accessKey.indexOf("app:") === 0) {
|
|
112
|
+
accessKey = selectedApp.accessKey;
|
|
113
|
+
secretKey = selectedApp.secretKey;
|
|
111
114
|
}
|
|
112
115
|
|
|
113
|
-
if (input[0]
|
|
116
|
+
if (!input[0]) {
|
|
117
|
+
console.log(help);
|
|
118
|
+
} else if (!accessKey || !secretKey) {
|
|
119
|
+
console.error(red('Command ' + input[0] + ' failed! Blank credentials, running setup first...'));
|
|
120
|
+
process.exitCode = 1;
|
|
114
121
|
setup(config);
|
|
115
|
-
}
|
|
122
|
+
} else {
|
|
123
|
+
var pc = new ParaClient(accessKey, secretKey, { endpoint: endpoint });
|
|
116
124
|
|
|
117
|
-
if (input[0] === '
|
|
118
|
-
|
|
119
|
-
}
|
|
125
|
+
if (input[0] === 'setup') {
|
|
126
|
+
setup(config);
|
|
127
|
+
}
|
|
120
128
|
|
|
121
|
-
if (input[0] === '
|
|
122
|
-
|
|
123
|
-
}
|
|
129
|
+
if (input[0] === 'apps') {
|
|
130
|
+
listApps(config, flags, accessKey, function () {console.log('No apps found within', green(accessKey));});
|
|
131
|
+
}
|
|
124
132
|
|
|
125
|
-
if (input[0] === '
|
|
126
|
-
|
|
127
|
-
}
|
|
133
|
+
if (input[0] === 'select') {
|
|
134
|
+
selectApp(pc, input, config, flags);
|
|
135
|
+
}
|
|
128
136
|
|
|
129
|
-
if (input[0] === '
|
|
130
|
-
|
|
131
|
-
}
|
|
137
|
+
if (input[0] === 'create') {
|
|
138
|
+
createAll(pc, input, flags);
|
|
139
|
+
}
|
|
132
140
|
|
|
133
|
-
if (input[0] === '
|
|
134
|
-
|
|
135
|
-
}
|
|
141
|
+
if (input[0] === 'read') {
|
|
142
|
+
readAll(pc, flags);
|
|
143
|
+
}
|
|
136
144
|
|
|
137
|
-
if (input[0] === '
|
|
138
|
-
|
|
139
|
-
}
|
|
145
|
+
if (input[0] === 'update') {
|
|
146
|
+
updateAll(pc, input, flags);
|
|
147
|
+
}
|
|
140
148
|
|
|
141
|
-
if (input[0] === '
|
|
142
|
-
|
|
143
|
-
}
|
|
149
|
+
if (input[0] === 'delete') {
|
|
150
|
+
deleteAll(pc, input, flags);
|
|
151
|
+
}
|
|
144
152
|
|
|
145
|
-
if (input[0] === '
|
|
146
|
-
|
|
147
|
-
}
|
|
153
|
+
if (input[0] === 'search') {
|
|
154
|
+
search(pc, input, flags);
|
|
155
|
+
}
|
|
148
156
|
|
|
149
|
-
if (input[0] === '
|
|
150
|
-
|
|
151
|
-
}
|
|
157
|
+
if (input[0] === 'new-key') {
|
|
158
|
+
newKeys(pc, config);
|
|
159
|
+
}
|
|
152
160
|
|
|
153
|
-
if (input[0] === '
|
|
154
|
-
|
|
155
|
-
}
|
|
161
|
+
if (input[0] === 'new-jwt') {
|
|
162
|
+
newJWT(accessKey, secretKey, endpoint, config);
|
|
163
|
+
}
|
|
156
164
|
|
|
157
|
-
if (input[0] === 'app
|
|
158
|
-
|
|
159
|
-
}
|
|
165
|
+
if (input[0] === 'new-app') {
|
|
166
|
+
newApp(pc, input, flags);
|
|
167
|
+
}
|
|
160
168
|
|
|
161
|
-
if (input[0] === '
|
|
162
|
-
|
|
163
|
-
}
|
|
169
|
+
if (input[0] === 'ping') {
|
|
170
|
+
ping(pc, config);
|
|
171
|
+
}
|
|
164
172
|
|
|
165
|
-
if (input[0] === '
|
|
166
|
-
|
|
167
|
-
}
|
|
173
|
+
if (input[0] === 'me') {
|
|
174
|
+
me(pc, config);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (input[0] === 'app-settings') {
|
|
178
|
+
appSettings(pc, config);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (input[0] === 'rebuild-index') {
|
|
182
|
+
rebuildIndex(pc, config, flags);
|
|
183
|
+
}
|
|
168
184
|
|
|
169
|
-
if (input[0] === '
|
|
170
|
-
|
|
185
|
+
if (input[0] === 'export') {
|
|
186
|
+
exportData(pc, config, flags);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (input[0] === 'import') {
|
|
190
|
+
importData(pc, input, config);
|
|
191
|
+
}
|
|
171
192
|
}
|
|
193
|
+
|