para-cli 1.19.1 → 1.20.1

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/README.md CHANGED
@@ -52,6 +52,7 @@ para-cli ping
52
52
  new-key Generates a new secret key and saves it to config.json
53
53
  new-jwt Generates a new JWT super token to be used for app authentication
54
54
  new-app <name> --name --shared Creates a new Para app. Only works if you have the keys for the "root" app
55
+ delete-app <id> Deletes an existing Para app. Only works for child apps, not the "root" app
55
56
  export Exports all data from the app's table
56
57
  import <file> Imports data from a previously exported ZIP archive
57
58
  ping Tests the connection to the Para server
package/index.js CHANGED
@@ -61,7 +61,7 @@ export function setup(config) {
61
61
  var secret = (secretKey || config.get('secretKey')).trim();
62
62
  var endpoint = (endpoint || config.get('endpoint')).trim();
63
63
  newJWT(access, secret, endpoint, config);
64
- var pc = new ParaClient(access, secret, { endpoint: endpoint || defaultConfig.endpoint });
64
+ var pc = new ParaClient(access, secret, parseEndpoint(endpoint || defaultConfig.endpoint));
65
65
  ping(pc, config);
66
66
  if (access === 'app:para') {
67
67
  listApps(config, {}, access, function () {
@@ -303,6 +303,36 @@ export function newApp(pc, input, flags) {
303
303
  });
304
304
  }
305
305
 
306
+ export function deleteApp(pc, input, flags) {
307
+ if (!input[1]) {
308
+ fail('App id not specified.');
309
+ return;
310
+ }
311
+ var appid = input[1];
312
+ if (appid.indexOf('app:') < 0) {
313
+ appid = 'app:' + appid;
314
+ }
315
+ var rl = createInterface({
316
+ input: process.stdin,
317
+ output: process.stdout
318
+ });
319
+ rl.question(red.bold('Are you sure you want to delete ' + appid +
320
+ '? ALL DATA FOR THAT APP WILL BE LOST! ') + 'yes/No ', function (confirm) {
321
+ if (confirm === "yes") {
322
+ pc.invokeDelete('apps/' + appid, {}).then(function (resp) {
323
+ if (resp && resp.ok) {
324
+ console.log(green('✔'), 'App ' + red.bold(appid) + ' was deleted!');
325
+ } else {
326
+ console.log(green('✔'), yellow('App "' + appid + '" could not be deleted.'));
327
+ }
328
+ }).catch(function (err) {
329
+ fail('Failed to delete app:', err);
330
+ });
331
+ }
332
+ rl.close();
333
+ });
334
+ }
335
+
306
336
  export function ping(pc, config) {
307
337
  pc.me().then(function (mee) {
308
338
  pc.getServerVersion().then(function (ver) {
@@ -432,7 +462,7 @@ export function listApps(config, flags, parentAccessKey, failureCallback) {
432
462
  var accessKey = selectedEndpoint.accessKey;
433
463
  var secretKey = selectedEndpoint.secretKey;
434
464
  var endpoint = selectedEndpoint.endpoint;
435
- var pc = new ParaClient(accessKey, secretKey, {endpoint: endpoint});
465
+ var pc = new ParaClient(accessKey, secretKey, parseEndpoint(endpoint));
436
466
  var p = new Pager();
437
467
  var results = [];
438
468
  p.sortby = '_docid';
@@ -473,7 +503,7 @@ export function selectApp(input, config, flags) {
473
503
  appid: accessKey,
474
504
  getCredentials: selectedApp
475
505
  }), secretKey, { algorithm: 'HS256' });
476
- var paraClient = new ParaClient(accessKey, secretKey, { endpoint: endpoint });
506
+ var paraClient = new ParaClient(accessKey, secretKey, parseEndpoint(endpoint));
477
507
  paraClient.setAccessToken(jwt);
478
508
  paraClient.me(jwt).then(function (data) {
479
509
  if (data && data.credentials) {
@@ -523,7 +553,7 @@ export function addEndpoint(config) {
523
553
  return;
524
554
  }
525
555
  rl.question(cyan.bold('Para Secret Key (for root app app:para): '), function (secretKey) {
526
- var pc = new ParaClient("app:para", secretKey, {endpoint: endpoint});
556
+ var pc = new ParaClient("app:para", secretKey, parseEndpoint(endpoint));
527
557
  var endpoints = config.get('endpoints') || [];
528
558
  var existing = false;
529
559
  for (var i = 0; i < endpoints.length; i++) {
@@ -592,6 +622,19 @@ export function selectEndpoint(config, flags) {
592
622
  });
593
623
  }
594
624
 
625
+ export function parseEndpoint(endpoint) {
626
+ try {
627
+ var url = new URL(endpoint);
628
+ if (url.pathname !== '/') {
629
+ var x = { endpoint: url.protocol + '//' + url.host, apiPath: url.pathname.replace(/\/*$/, '') + '/v1/' };
630
+ return x;
631
+ }
632
+ } catch (e) {
633
+ fail('Invalid Para endpoint:', endpoint);
634
+ }
635
+ return { endpoint: endpoint };
636
+ }
637
+
595
638
  function getSelectedEndpoint(config, flags) {
596
639
  var accessKey = flags.accessKey || process.env.PARA_ACCESS_KEY || config.get('accessKey');
597
640
  var secretKey = flags.secretKey || process.env.PARA_SECRET_KEY || config.get('secretKey');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "para-cli",
3
- "version": "1.19.1",
3
+ "version": "1.20.1",
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.28.0"
27
+ "eslint": "^8.29.0"
28
28
  },
29
29
  "repository": "Erudika/para-cli",
30
30
  "dependencies": {
package/para-cli.js CHANGED
@@ -28,8 +28,8 @@ import figlet from 'figlet';
28
28
  import chalk from 'chalk';
29
29
  import meow from 'meow';
30
30
  import {
31
- defaultConfig, setup, listApps, selectEndpoint, addEndpoint, removeEndpoint, selectApp, createAll, readAll,
32
- updateAll, deleteAll, search, newKeys, newJWT, newApp, ping, me, appSettings, rebuildIndex, exportData, importData
31
+ defaultConfig, setup, listApps, parseEndpoint, selectEndpoint, addEndpoint, removeEndpoint, selectApp, createAll, readAll,
32
+ updateAll, deleteAll, search, newKeys, newJWT, newApp, deleteApp, ping, me, appSettings, rebuildIndex, exportData, importData
33
33
  } from './index.js';
34
34
 
35
35
  const { red, green, blue } = chalk;
@@ -54,6 +54,7 @@ var cli = meow(`
54
54
  new-key Generates a new secret key and saves it to config.json
55
55
  new-jwt Generates a new JWT super token to be used for app authentication
56
56
  new-app <name> --name --shared Creates a new Para app. Only works if you have the keys for the "root" app
57
+ delete-app <id> Deletes an existing Para app. Only works for child apps, not the "root" app
57
58
  export Exports all data from the app's table
58
59
  import <file> Imports data from a previously exported ZIP archive
59
60
  ping Tests the connection to the Para server
@@ -128,7 +129,7 @@ if (!input[0]) {
128
129
  process.exitCode = 1;
129
130
  setup(config);
130
131
  } else {
131
- var pc = new ParaClient(accessKey, secretKey, { endpoint: endpoint });
132
+ var pc = new ParaClient(accessKey, secretKey, parseEndpoint(endpoint));
132
133
 
133
134
  if (input[0] === 'setup') {
134
135
  setup(config);
@@ -184,6 +185,10 @@ if (!input[0]) {
184
185
  newApp(pc, input, flags);
185
186
  }
186
187
 
188
+ if (input[0] === 'delete-app') {
189
+ deleteApp(pc, input, flags);
190
+ }
191
+
187
192
  if (input[0] === 'ping') {
188
193
  ping(pc, config);
189
194
  }