para-cli 1.19.0 → 1.20.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/README.md CHANGED
@@ -17,9 +17,9 @@ This is the command-line tool for interacting with a Para server.
17
17
  ## Installation
18
18
 
19
19
  ```sh
20
- $ npm install -g para-cli
21
- $ para-cli setup
22
- $ para-cli ping
20
+ npm install -g para-cli
21
+ para-cli setup
22
+ para-cli ping
23
23
  ```
24
24
 
25
25
  ## Usage
@@ -41,6 +41,7 @@ $ para-cli ping
41
41
  setup Initial setup, prompts you to enter your Para API keys and endpoint
42
42
  apps Returns a list of all Para apps
43
43
  select <appid> Selects a Para app as a target for all subsequent read/write requests.
44
+ endpoints [add|remove] List and select Para server endpoints, add new or remove an exiting one.
44
45
  create <file|glob> [--id] [--type] Persists files as Para objects and makes them searchable
45
46
  read --id 123 [--id 345 ...] Fetches objects with the given ids
46
47
  update <file.json|glob> ... Updates Para objects with the data from a JSON file (must contain id field)
@@ -51,6 +52,7 @@ $ para-cli ping
51
52
  new-key Generates a new secret key and saves it to config.json
52
53
  new-jwt Generates a new JWT super token to be used for app authentication
53
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
54
56
  export Exports all data from the app's table
55
57
  import <file> Imports data from a previously exported ZIP archive
56
58
  ping Tests the connection to the Para server
@@ -83,6 +85,9 @@ $ para-cli ping
83
85
  $ para-cli search "*" --type article --page all
84
86
  $ para-cli new-key
85
87
  $ para-cli new-app "mynewapp" --name "Full app name"
88
+ $ para-cli apps
89
+ $ para-cli select scoold
90
+ $ para-cli endpoints
86
91
 
87
92
  ```
88
93
 
@@ -95,7 +100,7 @@ The plan is to add more functionality in the near future.
95
100
 
96
101
  **Quick start:**
97
102
  ```
98
- $ para-cli setup
103
+ para-cli setup
99
104
  ```
100
105
 
101
106
  The configuration file is located in `~/.config/para-cli-nodejs/config.json` and contains the keys used to authenticate
@@ -115,12 +120,32 @@ Here's an example `config.json` file:
115
120
  Once configured you can test your connection to the server:
116
121
 
117
122
  ```
118
- $ para-cli ping
123
+ para-cli ping
119
124
  ```
120
125
 
121
126
  To get the currently authenticated app/user object run:
122
127
  ```
123
- $ para-cli me
128
+ para-cli me
129
+ ```
130
+
131
+ ## Switching between apps and endpoints
132
+
133
+ Para CLI can be configured to work with multiple Para servers and apps. Here's how to add additional Para server endpoints:
134
+ ```
135
+ para-cli endpoints add
136
+ ```
137
+ To select a specific endpoint run:
138
+ ```
139
+ para-cli endpoints
140
+ ```
141
+
142
+ After selecting the Para server you wish to connect to, you can list and select apps within it:
143
+ ```
144
+ para-cli apps
145
+ ```
146
+ Select the 'scoold' app, for example:
147
+ ```
148
+ para-cli select scoold
124
149
  ```
125
150
 
126
151
  ## Para Docs
package/index.js CHANGED
@@ -38,6 +38,7 @@ import { globbySync } from 'globby';
38
38
  import chalk from 'chalk';
39
39
  import { Promise } from 'rsvp';
40
40
  import apiClient from 'superagent';
41
+ import { URL } from 'url';
41
42
  import { ParaClient, ParaObject, Pager } from 'para-client-js';
42
43
 
43
44
  const { cyan, red, yellow, green } = chalk;
@@ -302,6 +303,36 @@ export function newApp(pc, input, flags) {
302
303
  });
303
304
  }
304
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
+
305
336
  export function ping(pc, config) {
306
337
  pc.me().then(function (mee) {
307
338
  pc.getServerVersion().then(function (ver) {
@@ -516,6 +547,11 @@ export function addEndpoint(config) {
516
547
  output: process.stdout
517
548
  });
518
549
  rl.question(cyan.bold('Para Endpoint: '), function (endpoint) {
550
+ if (!isValidUrl(endpoint)) {
551
+ fail('Endpoint must be a valid URL.');
552
+ rl.close();
553
+ return;
554
+ }
519
555
  rl.question(cyan.bold('Para Secret Key (for root app app:para): '), function (secretKey) {
520
556
  var pc = new ParaClient("app:para", secretKey, {endpoint: endpoint});
521
557
  var endpoints = config.get('endpoints') || [];
@@ -716,6 +752,15 @@ function parseHTML(file) {
716
752
  };
717
753
  }
718
754
 
755
+ function isValidUrl(url) {
756
+ try {
757
+ new URL(url);
758
+ return true;
759
+ } catch (err) {
760
+ return false;
761
+ }
762
+ }
763
+
719
764
  function readFile(filePath) {
720
765
  return readFileSync(filePath, { encoding: 'utf8' });
721
766
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "para-cli",
3
- "version": "1.19.0",
3
+ "version": "1.20.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.28.0"
27
+ "eslint": "^8.29.0"
28
28
  },
29
29
  "repository": "Erudika/para-cli",
30
30
  "dependencies": {
@@ -39,7 +39,7 @@
39
39
  "jsonwebtoken": "^8.5.1",
40
40
  "meow": "^11.0.0",
41
41
  "mime-types": "^2.1.35",
42
- "para-client-js": "^1.37.14",
42
+ "para-client-js": "^1.38.0",
43
43
  "resolve": "^1.22.1",
44
44
  "striptags": "^3.2.0",
45
45
  "update-notifier": "^6.0.2",
package/para-cli.js CHANGED
@@ -29,7 +29,7 @@ import chalk from 'chalk';
29
29
  import meow from 'meow';
30
30
  import {
31
31
  defaultConfig, setup, listApps, selectEndpoint, addEndpoint, removeEndpoint, selectApp, createAll, readAll,
32
- updateAll, deleteAll, search, newKeys, newJWT, newApp, ping, me, appSettings, rebuildIndex, exportData, importData
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
@@ -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
  }