para-cli 1.15.2 → 1.17.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.
Files changed (4) hide show
  1. package/README.md +46 -44
  2. package/index.js +51 -7
  3. package/package.json +9 -31
  4. package/para-cli.js +11 -3
package/README.md CHANGED
@@ -34,50 +34,52 @@ $ para-cli setup
34
34
  Command-line tool for Para backend servers
35
35
 
36
36
  Usage:
37
- $ para-cli [command] [file]
38
-
39
- Commands:
40
- setup Initial setup, prompts you to enter your Para API keys and endpoint
41
- create <file|glob> [--id] [--type] Persists files as Para objects and makes them searchable
42
- read --id 123 [--id 345 ...] Fetches objects with the given ids
43
- update <file.json|glob> ... Updates Para objects with the data from a JSON file (must contain id field)
44
- delete [glob] --id 123 ... Deletes one or more objects from Para
45
- search "query" [--limit --page --sort] Searches the Para index for objects given a query string
46
- rebuild-index Rebuilds the entire search index
47
- app-settings Returns all settings for the authenticated app
48
- new-key Generates a new secret key and saves it to config.json
49
- new-jwt Generates a new JWT super token to be used for app authentication
50
- new-app <name> --name --shared Creates a new Para app. Only works if you have the keys for the "root" app
51
- ping Tests the connection to the Para server
52
- me Returns the JSON for the currently authenticated user or app
53
-
54
- Options:
55
- --type Sets the "type" field of an object
56
- --id Sets the "id" field of an object
57
- --sanitize Strips all symbols from input files
58
- --accessKey Sets the Para access key
59
- --secretKey Sets the Para secret key
60
- --endpoint Sets the URL of the Para server
61
- --sort Sets the field on which to sort search results
62
- --desc Descending sort for search results (default: true)
63
- --page Page number for search results, "all" will auto-paginate through all results
64
- --limit Limits the number of search results
65
- --lastKey Sets the last id for search-after pagination
66
- --cwd Sets the current directory - used for resolving file paths
67
- --encodeId By default all ids are Base64 encoded, unless this is 'false'
68
- --help Prints the list of commands
69
- --version Prints the version of the program
70
-
71
- Examples:
72
- $ para-cli setup
73
- $ para-cli create my-blog-post.md
74
- $ para-cli read --id my-blog-post.md
75
- $ para-cli create index.html --type webpage --id "My new article" --sanitize
76
- $ para-cli delete --id 123 --id "my-blog-post.md"
77
- $ para-cli search "type:article AND title:*" --sort timestamp --desc false --limit 10
78
- $ para-cli search "*" --type article --page all
79
- $ para-cli new-key
80
- $ para-cli new-app "mynewapp" --name "Full app name"
37
+ $ para-cli [command] [file]
38
+
39
+ Commands:
40
+ setup Initial setup, prompts you to enter your Para API keys and endpoint
41
+ create <file|glob> [--id] [--type] Persists files as Para objects and makes them searchable
42
+ read --id 123 [--id 345 ...] Fetches objects with the given ids
43
+ update <file.json|glob> ... Updates Para objects with the data from a JSON file (must contain id field)
44
+ delete [glob] --id 123 ... Deletes one or more objects from Para
45
+ search "query" [--limit --page --sort] Searches the Para index for objects given a query string
46
+ rebuild-index Rebuilds the entire search index
47
+ app-settings Returns all settings for the authenticated app
48
+ new-key Generates a new secret key and saves it to config.json
49
+ new-jwt Generates a new JWT super token to be used for app authentication
50
+ new-app <name> --name --shared Creates a new Para app. Only works if you have the keys for the "root" app
51
+ export Exports all data from the app's table
52
+ import <file> Imports data from a previously exported ZIP archive
53
+ ping Tests the connection to the Para server
54
+ me Returns the JSON for the currently authenticated user or app
55
+
56
+ Options:
57
+ --type Sets the "type" field of an object
58
+ --id Sets the "id" field of an object
59
+ --sanitize Strips all symbols from input files
60
+ --accessKey Sets the Para access key
61
+ --secretKey Sets the Para secret key
62
+ --endpoint Sets the URL of the Para server
63
+ --sort Sets the field on which to sort search results
64
+ --desc Descending sort for search results (default: true)
65
+ --page Page number for search results, "all" will auto-paginate through all results
66
+ --limit Limits the number of search results
67
+ --lastKey Sets the last id for search-after pagination
68
+ --cwd Sets the current directory - used for resolving file paths
69
+ --encodeId By default all ids are Base64 encoded, unless this is 'false'
70
+ --help Prints the list of commands
71
+ --version Prints the version of the program
72
+
73
+ Examples:
74
+ $ para-cli setup
75
+ $ para-cli create my-blog-post.md
76
+ $ para-cli read --id my-blog-post.md
77
+ $ para-cli create index.html --type webpage --id "My new article" --sanitize
78
+ $ para-cli delete --id 123 --id "my-blog-post.md"
79
+ $ para-cli search "type:article AND title:*" --sort timestamp --desc false --limit 10
80
+ $ para-cli search "*" --type article --page all
81
+ $ para-cli new-key
82
+ $ para-cli new-app "mynewapp" --name "Full app name"
81
83
 
82
84
  ```
83
85
 
package/index.js CHANGED
@@ -25,9 +25,8 @@
25
25
  /* eslint indent: ["error", "tab"] */
26
26
  /* eslint object-curly-spacing: ["error", "always"] */
27
27
 
28
- 'use strict';
29
- import { statSync, readFileSync } from 'fs';
30
- import { relative, basename } from 'path';
28
+ import { statSync, readFileSync, writeFileSync } from 'fs';
29
+ import { relative, basename, resolve } from 'path';
31
30
  import { TextEncoder } from 'util';
32
31
  var encoder = new TextEncoder('utf-8');
33
32
  import striptags from 'striptags';
@@ -35,9 +34,10 @@ import { Parser } from 'htmlparser2';
35
34
  import { createInterface } from 'readline';
36
35
  import jsonwebtoken from 'jsonwebtoken';
37
36
  import { lookup } from 'mime-types';
38
- import { sync } from 'globby';
37
+ import { globbySync } from 'globby';
39
38
  import chalk from 'chalk';
40
39
  import { Promise } from 'rsvp';
40
+ import apiClient from 'superagent';
41
41
  import { ParaClient, ParaObject, Pager } from 'para-client-js';
42
42
 
43
43
  const { cyan, red, yellow, green } = chalk;
@@ -70,9 +70,10 @@ export function setup(config) {
70
70
  export function createAll(pc, input, flags) {
71
71
  if (!input[1]) {
72
72
  fail('No files specified.');
73
+ return;
73
74
  }
74
75
 
75
- var files = sync(input[1], { realpath: true });
76
+ var files = globbySync(input[1], { realpath: true });
76
77
  var totalSize = 0;
77
78
  var totalObjects = 0;
78
79
  var batches = [[]];
@@ -180,9 +181,10 @@ export function readAll(pc, flags) {
180
181
  export function updateAll(pc, input, flags) {
181
182
  if (!input[1]) {
182
183
  fail('No files specified.');
184
+ return;
183
185
  }
184
186
 
185
- var files = sync(input[1], { realpath: true });
187
+ var files = globbySync(input[1], { realpath: true });
186
188
  var updateList = [];
187
189
 
188
190
  for (var i = 0; i < files.length; i++) {
@@ -216,7 +218,7 @@ export function updateAll(pc, input, flags) {
216
218
 
217
219
  export function deleteAll(pc, input, flags) {
218
220
  if (flags.id || input[1]) {
219
- var deleteIds = sync(input[1] || ' ', { realpath: true });
221
+ var deleteIds = globbySync(input[1] || ' ', { realpath: true });
220
222
  if (deleteIds.length === 0) {
221
223
  deleteIds = flags.id instanceof Array ? flags.id : [String(flags.id)];
222
224
  }
@@ -247,6 +249,7 @@ export function newKeys(pc, config) {
247
249
  export function newJWT(accessKey, secretKey, endpoint, config) {
248
250
  if (!accessKey || accessKey.length < 3 || !secretKey || secretKey.length < 6) {
249
251
  fail('Invalid credentials.');
252
+ return;
250
253
  }
251
254
 
252
255
  var now = Math.round(new Date().getTime() / 1000);
@@ -266,6 +269,7 @@ export function newJWT(accessKey, secretKey, endpoint, config) {
266
269
  export function newApp(pc, input, flags) {
267
270
  if (!input[1]) {
268
271
  fail('App name not specified.');
272
+ return;
269
273
  }
270
274
 
271
275
  var appid = input[1];
@@ -304,6 +308,46 @@ export function me(pc, config) {
304
308
  });
305
309
  }
306
310
 
311
+ export function exportData(pc, config) {
312
+ pc.invokeGet('/_export').then(function (data) {
313
+ try {
314
+ var filename = (data.headers['content-disposition'] || 'export.zip');
315
+ var filesize = Math.round(((data.headers['content-length'] || 0) / 1000000) * 100) / 100;
316
+ filename = filename.substring(filename.lastIndexOf('=') + 1);
317
+ writeFileSync(filename, data.body);
318
+ console.log(green('✔'), yellow('Exported ' + filesize + 'MB of data to file ' + filename));
319
+ } catch (e) {
320
+ console.error(e);
321
+ }
322
+ }).catch(function () {
323
+ fail('Connection failed. Server might be down. Check the configuration file', yellow(config.path));
324
+ });
325
+ }
326
+
327
+ export function importData(pc, input, config) {
328
+ if (!input[1]) {
329
+ fail('No file to import.');
330
+ return;
331
+ }
332
+ if (!config.get('jwt')) {
333
+ newJWT(config.get('accessKey'), config.get('secretKey'), config.get('endpoint'), config);
334
+ }
335
+ var headers = {
336
+ 'User-Agent': 'Para CLI tool',
337
+ 'Content-Type': 'application/zip',
338
+ 'Authorization': 'Bearer ' + config.get('jwt')
339
+ };
340
+ try {
341
+ apiClient.put(pc.endpoint + '/v1/_import').set(headers).send(readFileSync(resolve(input[1]))).then(function(res) {
342
+ console.log(green('✔'), yellow('Imported ' + res.body.count + ' object into app "' + res.body.appid) + '"');
343
+ }).catch(function (e) {
344
+ fail('Import request failed. ' + e);
345
+ });
346
+ } catch (e) {
347
+ fail('Import request failed: ' + e);
348
+ }
349
+ }
350
+
307
351
  function promiseWhile(results, fn) {
308
352
  return new Promise(function (resolve, _reject) {
309
353
  function loop() {
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "para-cli",
3
- "version": "1.15.2",
3
+ "version": "1.17.2",
4
+ "license": "Apache-2.0",
4
5
  "description": "Command-line tool for Para backend servers",
5
6
  "homepage": "https://paraio.org",
6
7
  "type": "module",
8
+ "exports": "./index.js",
7
9
  "author": {
8
10
  "name": "Alex Bogdanovski",
9
11
  "email": "alex@erudika.com",
@@ -22,47 +24,23 @@
22
24
  "api"
23
25
  ],
24
26
  "devDependencies": {
25
- "eslint": "^7.28.0",
26
- "eslint-config-xo-space": "^0.28.0",
27
- "gulp": "^4.0.2",
28
- "gulp-eslint": "^6.0.0",
29
- "gulp-exclude-gitignore": "^1.2.0",
30
- "gulp-istanbul": "^1.1.3",
31
- "gulp-line-ending-corrector": "^1.0.3",
32
- "gulp-mocha": "^8.0.0",
33
- "gulp-plumber": "^1.2.1",
34
- "gulp-xo": "^0.25.0",
35
- "handlebars": "^4.7.6",
36
- "lodash": "^4.17.21",
37
- "mem": "^8.1.1",
38
- "minimist": ">=1.2.3",
39
- "yargs-parser": ">=20.2.7"
40
- },
41
- "eslintConfig": {
42
- "extends": "xo-space",
43
- "env": {
44
- "mocha": true
45
- }
27
+ "eslint": "^8.7.0"
46
28
  },
47
29
  "repository": "Erudika/para-cli",
48
- "scripts": {
49
- "test": "gulp"
50
- },
51
- "license": "Apache-2.0",
52
30
  "dependencies": {
53
31
  "brace-expansion": "^2.0.1",
54
- "chalk": "^4.1.1",
32
+ "chalk": "^5.0.0",
55
33
  "conf": "^10.0.1",
56
34
  "exit": "^0.1.2",
57
35
  "figlet": "^1.5.0",
58
36
  "get-stdin": "^9.0.0",
59
- "globby": "^11.0.4",
60
- "htmlparser2": "^6.1.0",
37
+ "globby": "^13.1.0",
38
+ "htmlparser2": "^7.2.0",
61
39
  "jsonwebtoken": "^8.5.1",
62
40
  "meow": "^10.0.1",
63
41
  "mime-types": "^2.1.31",
64
- "para-client-js": "^1.37.6",
65
- "resolve": "^1.20.0",
42
+ "para-client-js": "^1.37.9",
43
+ "resolve": "^1.22.0",
66
44
  "striptags": "^3.1.1",
67
45
  "update-notifier": "^5.1.0",
68
46
  "yargs-parser": ">=20.2.7"
package/para-cli.js CHANGED
@@ -21,15 +21,13 @@
21
21
  /* eslint indent: ["error", "tab"] */
22
22
  /* eslint object-curly-spacing: ["error", "always"] */
23
23
 
24
- 'use strict';
25
-
26
24
  import updateNotifier from 'update-notifier';
27
25
  import ParaClient from 'para-client-js';
28
26
  import Conf from 'conf';
29
27
  import figlet from 'figlet';
30
28
  import chalk from 'chalk';
31
29
  import meow from 'meow';
32
- import { defaultConfig, setup, createAll, readAll, updateAll, deleteAll, search, newKeys, newJWT, newApp, ping, me, appSettings, rebuildIndex } from './index.js';
30
+ import { defaultConfig, setup, createAll, readAll, updateAll, deleteAll, search, newKeys, newJWT, newApp, ping, me, appSettings, rebuildIndex, exportData, importData } from './index.js';
33
31
 
34
32
  const { blue } = chalk;
35
33
  const { textSync } = figlet;
@@ -50,6 +48,8 @@ var cli = meow(`
50
48
  new-key Generates a new secret key and saves it to config.json
51
49
  new-jwt Generates a new JWT super token to be used for app authentication
52
50
  new-app <name> --name --shared Creates a new Para app. Only works if you have the keys for the "root" app
51
+ export Exports all data from the app's table
52
+ import <file> Imports data from a previously exported ZIP archive
53
53
  ping Tests the connection to the Para server
54
54
  me Returns the JSON for the currently authenticated user or app
55
55
 
@@ -161,3 +161,11 @@ if (input[0] === 'app-settings') {
161
161
  if (input[0] === 'rebuild-index') {
162
162
  rebuildIndex(pc, config, flags);
163
163
  }
164
+
165
+ if (input[0] === 'export') {
166
+ exportData(pc, config, flags);
167
+ }
168
+
169
+ if (input[0] === 'import') {
170
+ importData(pc, input, config);
171
+ }