kourou 0.21.0 → 0.21.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.
Files changed (118) hide show
  1. package/README.md +1 -1
  2. package/lib/commands/api-key/check.d.ts +24 -0
  3. package/lib/commands/api-key/check.js +25 -0
  4. package/lib/commands/api-key/create.d.ts +26 -0
  5. package/lib/commands/api-key/create.js +30 -0
  6. package/lib/commands/api-key/delete.d.ts +24 -0
  7. package/lib/commands/api-key/delete.js +21 -0
  8. package/lib/commands/api-key/search.d.ts +24 -0
  9. package/lib/commands/api-key/search.js +39 -0
  10. package/lib/commands/app/scaffold.d.ts +17 -0
  11. package/lib/commands/app/scaffold.js +41 -0
  12. package/lib/commands/app/start-services.d.ts +11 -0
  13. package/lib/commands/app/start-services.js +110 -0
  14. package/lib/commands/collection/create.d.ts +27 -0
  15. package/lib/commands/collection/create.js +25 -0
  16. package/lib/commands/collection/export.d.ts +31 -0
  17. package/lib/commands/collection/export.js +75 -0
  18. package/lib/commands/collection/import.d.ts +27 -0
  19. package/lib/commands/collection/import.js +40 -0
  20. package/lib/commands/config/diff.d.ts +17 -0
  21. package/lib/commands/config/diff.js +80 -0
  22. package/lib/commands/document/search.d.ts +33 -0
  23. package/lib/commands/document/search.js +60 -0
  24. package/lib/commands/es/indices/cat.d.ts +12 -0
  25. package/lib/commands/es/indices/cat.js +37 -0
  26. package/lib/commands/es/indices/get.d.ts +16 -0
  27. package/lib/commands/es/indices/get.js +31 -0
  28. package/lib/commands/es/indices/insert.d.ts +18 -0
  29. package/lib/commands/es/indices/insert.js +38 -0
  30. package/lib/commands/es/migrate.d.ts +20 -0
  31. package/lib/commands/es/migrate.js +116 -0
  32. package/lib/commands/es/snapshot/create-repository.d.ts +17 -0
  33. package/lib/commands/es/snapshot/create-repository.js +42 -0
  34. package/lib/commands/es/snapshot/create.d.ts +16 -0
  35. package/lib/commands/es/snapshot/create.js +32 -0
  36. package/lib/commands/es/snapshot/list.d.ts +16 -0
  37. package/lib/commands/es/snapshot/list.js +44 -0
  38. package/lib/commands/file/decrypt.d.ts +18 -0
  39. package/lib/commands/file/decrypt.js +64 -0
  40. package/lib/commands/file/encrypt.d.ts +18 -0
  41. package/lib/commands/file/encrypt.js +64 -0
  42. package/lib/commands/file/test.d.ts +16 -0
  43. package/lib/commands/file/test.js +52 -0
  44. package/lib/commands/import.d.ts +27 -0
  45. package/lib/commands/import.js +133 -0
  46. package/lib/commands/index/export.d.ts +28 -0
  47. package/lib/commands/index/export.js +59 -0
  48. package/lib/commands/index/import.d.ts +27 -0
  49. package/lib/commands/index/import.js +55 -0
  50. package/lib/commands/instance/kill.d.ts +13 -0
  51. package/lib/commands/instance/kill.js +101 -0
  52. package/lib/commands/instance/list.d.ts +7 -0
  53. package/lib/commands/instance/list.js +73 -0
  54. package/lib/commands/instance/logs.d.ts +13 -0
  55. package/lib/commands/instance/logs.js +69 -0
  56. package/lib/commands/instance/spawn.d.ts +16 -0
  57. package/lib/commands/instance/spawn.js +233 -0
  58. package/lib/commands/paas/init.d.ts +14 -0
  59. package/lib/commands/paas/init.js +41 -0
  60. package/lib/commands/paas/login.d.ts +14 -0
  61. package/lib/commands/paas/login.js +42 -0
  62. package/lib/commands/paas/publish.d.ts +18 -0
  63. package/lib/commands/paas/publish.js +62 -0
  64. package/lib/commands/profile/export.d.ts +19 -0
  65. package/lib/commands/profile/export.js +46 -0
  66. package/lib/commands/profile/import.d.ts +22 -0
  67. package/lib/commands/profile/import.js +25 -0
  68. package/lib/commands/realtime/subscribe.d.ts +34 -0
  69. package/lib/commands/realtime/subscribe.js +68 -0
  70. package/lib/commands/redis/list-keys.d.ts +27 -0
  71. package/lib/commands/redis/list-keys.js +61 -0
  72. package/lib/commands/role/export.d.ts +19 -0
  73. package/lib/commands/role/export.js +45 -0
  74. package/lib/commands/role/import.d.ts +23 -0
  75. package/lib/commands/role/import.js +28 -0
  76. package/lib/commands/sdk/execute.d.ts +31 -0
  77. package/lib/commands/sdk/execute.js +122 -0
  78. package/lib/commands/sdk/query.d.ts +32 -0
  79. package/lib/commands/sdk/query.js +123 -0
  80. package/lib/commands/user/export-mappings.d.ts +18 -0
  81. package/lib/commands/user/export-mappings.js +31 -0
  82. package/lib/commands/user/export.d.ts +25 -0
  83. package/lib/commands/user/export.js +111 -0
  84. package/lib/commands/user/import-mappings.d.ts +22 -0
  85. package/lib/commands/user/import-mappings.js +23 -0
  86. package/lib/commands/user/import.d.ts +22 -0
  87. package/lib/commands/user/import.js +25 -0
  88. package/lib/commands/vault/add.d.ts +16 -0
  89. package/lib/commands/vault/add.js +59 -0
  90. package/lib/commands/vault/decrypt.d.ts +18 -0
  91. package/lib/commands/vault/decrypt.js +71 -0
  92. package/lib/commands/vault/encrypt.d.ts +18 -0
  93. package/lib/commands/vault/encrypt.js +83 -0
  94. package/lib/commands/vault/show.d.ts +20 -0
  95. package/lib/commands/vault/show.js +71 -0
  96. package/lib/commands/vault/test.d.ts +16 -0
  97. package/lib/commands/vault/test.js +45 -0
  98. package/lib/common.d.ts +53 -0
  99. package/lib/common.js +193 -0
  100. package/lib/hooks/command_not_found/api-action.d.ts +28 -0
  101. package/lib/hooks/command_not_found/api-action.js +97 -0
  102. package/lib/index.d.ts +1 -0
  103. package/lib/index.js +5 -0
  104. package/lib/support/PaasKommand.d.ts +22 -0
  105. package/lib/support/PaasKommand.js +52 -0
  106. package/lib/support/dump-collection.d.ts +2 -0
  107. package/lib/support/dump-collection.js +244 -0
  108. package/lib/support/editor.d.ts +12 -0
  109. package/lib/support/editor.js +47 -0
  110. package/lib/support/execute.d.ts +23 -0
  111. package/lib/support/execute.js +49 -0
  112. package/lib/support/kuzzle.d.ts +50 -0
  113. package/lib/support/kuzzle.js +172 -0
  114. package/lib/support/restore-collection.d.ts +29 -0
  115. package/lib/support/restore-collection.js +147 -0
  116. package/lib/support/restore-securities.d.ts +3 -0
  117. package/lib/support/restore-securities.js +53 -0
  118. package/package.json +2 -1
package/README.md CHANGED
@@ -26,7 +26,7 @@ $ npm install -g kourou
26
26
  $ kourou COMMAND
27
27
  running command...
28
28
  $ kourou (-v|--version|version)
29
- kourou/0.21.0 linux-x64 node-v16.13.2
29
+ kourou/0.21.1 linux-x64 node-v16.13.2
30
30
  $ kourou --help [COMMAND]
31
31
  USAGE
32
32
  $ kourou COMMAND
@@ -0,0 +1,24 @@
1
+ import { flags } from '@oclif/command';
2
+ import { Kommand } from '../../common';
3
+ declare class ApiKeyCheck extends Kommand {
4
+ static description: string;
5
+ static flags: {
6
+ host: flags.IOptionFlag<string>;
7
+ port: flags.IOptionFlag<string>;
8
+ ssl: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
9
+ username: flags.IOptionFlag<string>;
10
+ password: flags.IOptionFlag<string | undefined>;
11
+ protocol: flags.IOptionFlag<string>;
12
+ as: flags.IOptionFlag<string | undefined>;
13
+ 'api-key': flags.IOptionFlag<string | undefined>;
14
+ help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
15
+ };
16
+ static args: {
17
+ name: string;
18
+ description: string;
19
+ required: boolean;
20
+ }[];
21
+ static examples: string[];
22
+ runSafe(): Promise<void>;
23
+ }
24
+ export default ApiKeyCheck;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const command_1 = require("@oclif/command");
4
+ const common_1 = require("../../common");
5
+ const kuzzle_1 = require("../../support/kuzzle");
6
+ class ApiKeyCheck extends common_1.Kommand {
7
+ async runSafe() {
8
+ const { valid } = await this.sdk.auth.checkToken(this.args.token);
9
+ if (valid) {
10
+ this.logOk('API key is still valid');
11
+ }
12
+ else {
13
+ this.logKo('API key is not valid');
14
+ }
15
+ }
16
+ }
17
+ ApiKeyCheck.description = 'Checks an API key validity';
18
+ ApiKeyCheck.flags = Object.assign({ help: command_1.flags.help() }, kuzzle_1.kuzzleFlags);
19
+ ApiKeyCheck.args = [
20
+ { name: 'token', description: 'API key token', required: true },
21
+ ];
22
+ ApiKeyCheck.examples = [
23
+ 'kourou api-key:check eyJhbG...QxfQrc'
24
+ ];
25
+ exports.default = ApiKeyCheck;
@@ -0,0 +1,26 @@
1
+ import { flags } from '@oclif/command';
2
+ import { Kommand } from '../../common';
3
+ declare class ApiKeyCreate extends Kommand {
4
+ static description: string;
5
+ static flags: {
6
+ host: flags.IOptionFlag<string>;
7
+ port: flags.IOptionFlag<string>;
8
+ ssl: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
9
+ username: flags.IOptionFlag<string>;
10
+ password: flags.IOptionFlag<string | undefined>;
11
+ protocol: flags.IOptionFlag<string>;
12
+ as: flags.IOptionFlag<string | undefined>;
13
+ 'api-key': flags.IOptionFlag<string | undefined>;
14
+ help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
15
+ description: flags.IOptionFlag<string>;
16
+ id: flags.IOptionFlag<string | undefined>;
17
+ expire: flags.IOptionFlag<string>;
18
+ };
19
+ static args: {
20
+ name: string;
21
+ description: string;
22
+ required: boolean;
23
+ }[];
24
+ runSafe(): Promise<void>;
25
+ }
26
+ export default ApiKeyCreate;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const command_1 = require("@oclif/command");
4
+ const common_1 = require("../../common");
5
+ const kuzzle_1 = require("../../support/kuzzle");
6
+ class ApiKeyCreate extends common_1.Kommand {
7
+ async runSafe() {
8
+ const apiKey = await this.sdk.security.createApiKey(this.args.user, this.flags.description, {
9
+ _id: this.flags.id,
10
+ expiresIn: this.flags.expire
11
+ });
12
+ this.logOk(`Successfully created API Key "${apiKey._id}" for user "${this.args.user}"`);
13
+ this.log(apiKey._source.token);
14
+ }
15
+ }
16
+ ApiKeyCreate.description = 'Creates a new API Key for a user';
17
+ ApiKeyCreate.flags = Object.assign({ help: command_1.flags.help(), description: command_1.flags.string({
18
+ char: 'd',
19
+ description: 'API Key description',
20
+ required: true,
21
+ }), id: command_1.flags.string({
22
+ description: 'API Key unique ID',
23
+ }), expire: command_1.flags.string({
24
+ description: 'API Key validity',
25
+ default: '-1',
26
+ }) }, kuzzle_1.kuzzleFlags);
27
+ ApiKeyCreate.args = [
28
+ { name: 'user', description: 'User kuid', required: true },
29
+ ];
30
+ exports.default = ApiKeyCreate;
@@ -0,0 +1,24 @@
1
+ import { flags } from '@oclif/command';
2
+ import { Kommand } from '../../common';
3
+ declare class ApiKeyDelete extends Kommand {
4
+ static description: string;
5
+ static flags: {
6
+ host: flags.IOptionFlag<string>;
7
+ port: flags.IOptionFlag<string>;
8
+ ssl: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
9
+ username: flags.IOptionFlag<string>;
10
+ password: flags.IOptionFlag<string | undefined>;
11
+ protocol: flags.IOptionFlag<string>;
12
+ as: flags.IOptionFlag<string | undefined>;
13
+ 'api-key': flags.IOptionFlag<string | undefined>;
14
+ help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
15
+ };
16
+ static args: {
17
+ name: string;
18
+ description: string;
19
+ required: boolean;
20
+ }[];
21
+ static examples: string[];
22
+ runSafe(): Promise<void>;
23
+ }
24
+ export default ApiKeyDelete;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const command_1 = require("@oclif/command");
4
+ const common_1 = require("../../common");
5
+ const kuzzle_1 = require("../../support/kuzzle");
6
+ class ApiKeyDelete extends common_1.Kommand {
7
+ async runSafe() {
8
+ await this.sdk.security.deleteApiKey(this.args.user, this.args.id);
9
+ this.logOk(`Successfully deleted API Key "${this.args.id}" of user "${this.args.user}"`);
10
+ }
11
+ }
12
+ ApiKeyDelete.description = 'Deletes an API key.';
13
+ ApiKeyDelete.flags = Object.assign({ help: command_1.flags.help() }, kuzzle_1.kuzzleFlags);
14
+ ApiKeyDelete.args = [
15
+ { name: 'user', description: 'User kuid', required: true },
16
+ { name: 'id', description: 'API Key unique ID', required: true },
17
+ ];
18
+ ApiKeyDelete.examples = [
19
+ 'kourou vault:delete sigfox-gateway 1k-BF3EBjsXdvA2PR8x'
20
+ ];
21
+ exports.default = ApiKeyDelete;
@@ -0,0 +1,24 @@
1
+ import { flags } from '@oclif/command';
2
+ import { Kommand } from '../../common';
3
+ declare class ApiKeySearch extends Kommand {
4
+ static description: string;
5
+ static flags: {
6
+ host: flags.IOptionFlag<string>;
7
+ port: flags.IOptionFlag<string>;
8
+ ssl: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
9
+ username: flags.IOptionFlag<string>;
10
+ password: flags.IOptionFlag<string | undefined>;
11
+ protocol: flags.IOptionFlag<string>;
12
+ as: flags.IOptionFlag<string | undefined>;
13
+ 'api-key': flags.IOptionFlag<string | undefined>;
14
+ help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
15
+ filter: flags.IOptionFlag<string | undefined>;
16
+ };
17
+ static args: {
18
+ name: string;
19
+ description: string;
20
+ required: boolean;
21
+ }[];
22
+ runSafe(): Promise<void>;
23
+ }
24
+ export default ApiKeySearch;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const command_1 = require("@oclif/command");
4
+ const common_1 = require("../../common");
5
+ const kuzzle_1 = require("../../support/kuzzle");
6
+ class ApiKeySearch extends common_1.Kommand {
7
+ async runSafe() {
8
+ let query = {};
9
+ if (this.flags.filter) {
10
+ query = {
11
+ match: {
12
+ description: this.flags.filter,
13
+ },
14
+ };
15
+ }
16
+ const result = await this.sdk.security.searchApiKeys(this.args.user, query, {
17
+ from: 0,
18
+ size: 100
19
+ });
20
+ this.logOk(`${result.total} API Keys found for user ${this.args.user}`);
21
+ if (result.total !== 0) {
22
+ this.log('');
23
+ for (const { _id, _source } of result.hits) {
24
+ this.log(` - Key "${_id}"`);
25
+ this.log(` Description: ${_source.description}`);
26
+ this.log(` Fingerprint: ${_source.fingerprint}`);
27
+ this.log(` Expires at: ${_source.expiresAt}`);
28
+ }
29
+ }
30
+ }
31
+ }
32
+ ApiKeySearch.description = 'Lists a user\'s API Keys.';
33
+ ApiKeySearch.flags = Object.assign({ help: command_1.flags.help(), filter: command_1.flags.string({
34
+ description: 'Filter to match the API Key descriptions',
35
+ }) }, kuzzle_1.kuzzleFlags);
36
+ ApiKeySearch.args = [
37
+ { name: 'user', description: 'User kuid', required: true },
38
+ ];
39
+ exports.default = ApiKeySearch;
@@ -0,0 +1,17 @@
1
+ import { flags } from '@oclif/command';
2
+ import { Kommand } from '../../common';
3
+ export default class AppScaffold extends Kommand {
4
+ static initSdk: boolean;
5
+ static description: string;
6
+ static flags: {
7
+ help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
8
+ flavor: flags.IOptionFlag<string>;
9
+ };
10
+ static args: {
11
+ name: string;
12
+ description: string;
13
+ required: boolean;
14
+ }[];
15
+ runSafe(): Promise<void>;
16
+ cloneTemplate(flavor: string, destination: string): Promise<void>;
17
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const command_1 = require("@oclif/command");
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
+ const listr_1 = tslib_1.__importDefault(require("listr"));
7
+ const common_1 = require("../../common");
8
+ const execute_1 = require("../../support/execute");
9
+ class AppScaffold extends common_1.Kommand {
10
+ async runSafe() {
11
+ const destination = this.args.destination;
12
+ const flavor = this.flags.flavor;
13
+ const tasks = new listr_1.default([
14
+ {
15
+ title: 'Creating and rendering application files',
16
+ task: async () => this.cloneTemplate(flavor, destination)
17
+ },
18
+ ]);
19
+ await tasks.run();
20
+ this.log('');
21
+ this.logOk(`Scaffolding complete! Use ${chalk_1.default.grey(`cd ${destination} && npm run docker npm install`)} install dependencies and then ${chalk_1.default.grey(`npm run docker:dev`)} to run your application!`);
22
+ }
23
+ async cloneTemplate(flavor, destination) {
24
+ await (0, execute_1.execute)('git', 'clone', '--depth=1', 'https://github.com/kuzzleio/project-templates', '--branch', flavor, '--single-branch');
25
+ await (0, execute_1.execute)('mv', `project-templates/${flavor}`, `${destination}/`);
26
+ await (0, execute_1.execute)('rm', '-rf', 'project-templates/');
27
+ }
28
+ }
29
+ exports.default = AppScaffold;
30
+ AppScaffold.initSdk = false;
31
+ AppScaffold.description = 'Scaffolds a new Kuzzle application';
32
+ AppScaffold.flags = {
33
+ help: command_1.flags.help(),
34
+ flavor: command_1.flags.string({
35
+ default: 'generic',
36
+ description: 'Template flavor ("generic", "iot-platform")'
37
+ })
38
+ };
39
+ AppScaffold.args = [
40
+ { name: 'destination', description: 'Directory to scaffold the app', required: true },
41
+ ];
@@ -0,0 +1,11 @@
1
+ import { Kommand } from '../../common';
2
+ export default class AppStartServices extends Kommand {
3
+ static initSdk: boolean;
4
+ static description: string;
5
+ static flags: {
6
+ help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
7
+ check: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
8
+ };
9
+ runSafe(): Promise<void>;
10
+ checkPrerequisites(): Promise<boolean>;
11
+ }
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const fs_1 = require("fs");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const command_1 = require("@oclif/command");
7
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
8
+ const listr_1 = tslib_1.__importDefault(require("listr"));
9
+ const node_emoji_1 = tslib_1.__importDefault(require("node-emoji"));
10
+ const common_1 = require("../../common");
11
+ const execute_1 = require("../../support/execute");
12
+ const MIN_DOCO_VERSION = '1.12.0';
13
+ const kuzzleServicesFile = `
14
+ version: '3'
15
+
16
+ services:
17
+ redis:
18
+ image: redis:5
19
+ ports:
20
+ - "6379:6379"
21
+
22
+ elasticsearch:
23
+ image: kuzzleio/elasticsearch:7
24
+ ports:
25
+ - "9200:9200"
26
+ ulimits:
27
+ nofile: 65536
28
+ `;
29
+ class AppStartServices extends common_1.Kommand {
30
+ async runSafe() {
31
+ this.createKourouDir();
32
+ const docoFilename = path_1.default.join(this.kourouDir, 'kuzzle-services.yml');
33
+ const successfullCheck = this.flags.check ?
34
+ await this.checkPrerequisites() :
35
+ true;
36
+ if (this.flags.check && successfullCheck) {
37
+ this.log(`\n${node_emoji_1.default.get('ok_hand')} Prerequisites are ${chalk_1.default.green.bold('OK')}!`);
38
+ }
39
+ else if (this.flags.check && !successfullCheck) {
40
+ throw new Error(`${node_emoji_1.default.get('shrug')} Your system doesn't satisfy all the prerequisites. Cannot run Kuzzle services.`);
41
+ }
42
+ this.log(chalk_1.default.grey(`\nWriting docker-compose file to ${docoFilename}...\n`));
43
+ (0, fs_1.writeFileSync)(docoFilename, kuzzleServicesFile);
44
+ // clean up
45
+ await (0, execute_1.execute)('docker-compose', '-f', docoFilename, 'down');
46
+ try {
47
+ await (0, execute_1.execute)('docker-compose', '-f', docoFilename, 'up', '-d');
48
+ this.logOk('Elasticsearch and Redis are booting in the background right now.');
49
+ this.log(chalk_1.default.grey('\nTo watch the logs, run'));
50
+ this.log(chalk_1.default.grey(` docker-compose -f ${docoFilename} logs -f\n`));
51
+ this.log(' Elasticsearch port: 9200');
52
+ this.log(' Redis port: 6379');
53
+ }
54
+ catch (error) {
55
+ this.logKo(` Something went wrong: ${error.message}`);
56
+ this.log(chalk_1.default.grey('If you want to investigate the problem, try running'));
57
+ this.log(chalk_1.default.grey(` docker-compose -f ${docoFilename} up\n`));
58
+ }
59
+ }
60
+ async checkPrerequisites() {
61
+ this.log(chalk_1.default.grey('Checking prerequisites...'));
62
+ const checks = new listr_1.default([
63
+ {
64
+ title: `docker-compose exists and the version is at least ${MIN_DOCO_VERSION}`,
65
+ task: async () => {
66
+ try {
67
+ const docov = await (0, execute_1.execute)('docker-compose', '-v');
68
+ const matches = docov.stdout.match(/[^0-9.]*([0-9.]*).*/);
69
+ if (matches === null) {
70
+ throw new Error('Unable to read docker-compose verson. This is weird.');
71
+ }
72
+ const docoVersion = matches.length > 0 ? matches[1] : null;
73
+ if (docoVersion === null) {
74
+ throw new Error('Unable to read docker-compose version. This is weird.');
75
+ }
76
+ try {
77
+ if (docoVersion < MIN_DOCO_VERSION) {
78
+ throw new Error(`The detected version of docker-compose (${docoVersion}) is not recent enough (${MIN_DOCO_VERSION})`);
79
+ }
80
+ }
81
+ catch (error) {
82
+ throw new Error(error);
83
+ }
84
+ }
85
+ catch (error) {
86
+ throw new Error('No docker-compose found. Are you sure docker-compose is installed?');
87
+ }
88
+ },
89
+ }
90
+ ]);
91
+ try {
92
+ await checks.run();
93
+ return true;
94
+ }
95
+ catch (error) {
96
+ this.logKo(error.message);
97
+ return false;
98
+ }
99
+ }
100
+ }
101
+ exports.default = AppStartServices;
102
+ AppStartServices.initSdk = false;
103
+ AppStartServices.description = 'Starts Kuzzle services (Elasticsearch and Redis)';
104
+ AppStartServices.flags = {
105
+ help: command_1.flags.help(),
106
+ check: command_1.flags.boolean({
107
+ description: 'Check prerequisite before running services',
108
+ default: false,
109
+ }),
110
+ };
@@ -0,0 +1,27 @@
1
+ import { flags } from '@oclif/command';
2
+ import { Kommand } from '../../common';
3
+ export default class CollectionCreate extends Kommand {
4
+ static description: string;
5
+ static flags: {
6
+ host: flags.IOptionFlag<string>;
7
+ port: flags.IOptionFlag<string>;
8
+ ssl: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
9
+ username: flags.IOptionFlag<string>;
10
+ password: flags.IOptionFlag<string | undefined>;
11
+ protocol: flags.IOptionFlag<string>;
12
+ as: flags.IOptionFlag<string | undefined>;
13
+ 'api-key': flags.IOptionFlag<string | undefined>;
14
+ help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
15
+ };
16
+ static args: ({
17
+ name: string;
18
+ description: string;
19
+ required: boolean;
20
+ } | {
21
+ name: string;
22
+ description: string;
23
+ required?: undefined;
24
+ })[];
25
+ static readStdin: boolean;
26
+ runSafe(): Promise<void>;
27
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const command_1 = require("@oclif/command");
4
+ const common_1 = require("../../common");
5
+ const kuzzle_1 = require("../../support/kuzzle");
6
+ class CollectionCreate extends common_1.Kommand {
7
+ async runSafe() {
8
+ const body = this.stdin ? this.stdin : this.args.body || '{}';
9
+ if (!await this.sdk.index.exists(this.args.index)) {
10
+ await this.sdk.index.create(this.args.index);
11
+ this.logInfo(`Index "${this.args.index}" created`);
12
+ }
13
+ await this.sdk.collection.create(this.args.index, this.args.collection, this.parseJs(body));
14
+ this.logOk(`Collection "${this.args.index}":"${this.args.collection}" created`);
15
+ }
16
+ }
17
+ exports.default = CollectionCreate;
18
+ CollectionCreate.description = 'Creates a collection';
19
+ CollectionCreate.flags = Object.assign({ help: command_1.flags.help() }, kuzzle_1.kuzzleFlags);
20
+ CollectionCreate.args = [
21
+ { name: 'index', description: 'Index name', required: true },
22
+ { name: 'collection', description: 'Collection name', required: true },
23
+ { name: 'body', description: 'Collection mappings and settings in JS or JSON format. Will be read from STDIN if available' },
24
+ ];
25
+ CollectionCreate.readStdin = true;
@@ -0,0 +1,31 @@
1
+ import { flags } from '@oclif/command';
2
+ import { Kommand } from '../../common';
3
+ export default class CollectionExport extends Kommand {
4
+ static keepAuth: boolean;
5
+ static description: string;
6
+ static flags: {
7
+ protocol: flags.IOptionFlag<string>;
8
+ host: flags.IOptionFlag<string>;
9
+ port: flags.IOptionFlag<string>;
10
+ ssl: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
11
+ username: flags.IOptionFlag<string>;
12
+ password: flags.IOptionFlag<string | undefined>;
13
+ as: flags.IOptionFlag<string | undefined>;
14
+ 'api-key': flags.IOptionFlag<string | undefined>;
15
+ help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
16
+ path: flags.IOptionFlag<string | undefined>;
17
+ 'batch-size': flags.IOptionFlag<string>;
18
+ query: flags.IOptionFlag<string>;
19
+ editor: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
20
+ format: flags.IOptionFlag<string>;
21
+ fields: flags.IOptionFlag<string | undefined>;
22
+ scrollTTL: flags.IOptionFlag<string | undefined>;
23
+ };
24
+ static args: {
25
+ name: string;
26
+ description: string;
27
+ required: boolean;
28
+ }[];
29
+ static examples: string[];
30
+ runSafe(): Promise<void>;
31
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const command_1 = require("@oclif/command");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ const common_1 = require("../../common");
8
+ const kuzzle_1 = require("../../support/kuzzle");
9
+ const dump_collection_1 = require("../../support/dump-collection");
10
+ class CollectionExport extends common_1.Kommand {
11
+ async runSafe() {
12
+ const exportPath = this.flags.path
13
+ ? path_1.default.join(this.flags.path, this.args.index)
14
+ : this.args.index;
15
+ const fields = this.flags.fields
16
+ ? this.flags.fields.split(',')
17
+ : [];
18
+ if (this.flags.format === 'csv' && fields.length === 0) {
19
+ this.logInfo('It looks like you are exporting to CSV but you did not select any field. All exportable fields in the mapping will be exported.');
20
+ }
21
+ let query = this.parseJs(this.flags.query);
22
+ if (this.flags.editor) {
23
+ query = this.fromEditor(query, { json: true });
24
+ }
25
+ const countAll = await this.sdk.document.count(this.args.index, this.args.collection);
26
+ const count = await this.sdk.document.count(this.args.index, this.args.collection, { query });
27
+ this.logInfo(`Dumping ${count} of ${countAll} documents from collection "${this.args.index}:${this.args.collection}" in ${exportPath} ...`);
28
+ fs_1.default.mkdirSync(exportPath, { recursive: true });
29
+ await (0, dump_collection_1.dumpCollectionMappings)(this.sdk, this.args.index, this.args.collection, exportPath, this.flags.format);
30
+ await (0, dump_collection_1.dumpCollectionData)(this.sdk, this.args.index, this.args.collection, Number(this.flags['batch-size']), exportPath, query, this.flags.format, fields, this.flags.scrollTTL);
31
+ this.logOk(`Collection ${this.args.index}:${this.args.collection} dumped`);
32
+ }
33
+ }
34
+ exports.default = CollectionExport;
35
+ CollectionExport.keepAuth = true;
36
+ CollectionExport.description = 'Exports a collection (JSONL format)';
37
+ CollectionExport.flags = Object.assign(Object.assign({ help: command_1.flags.help({}), path: command_1.flags.string({
38
+ description: 'Dump root directory',
39
+ }), 'batch-size': command_1.flags.string({
40
+ description: 'Maximum batch size (see limits.documentsFetchCount config)',
41
+ default: '2000'
42
+ }), query: command_1.flags.string({
43
+ description: 'Only dump documents matching the query (JS or JSON format)',
44
+ default: '{}'
45
+ }), editor: command_1.flags.boolean({
46
+ description: 'Open an editor (EDITOR env variable) to edit the query before sending'
47
+ }), format: command_1.flags.string({
48
+ description: `"kuzzle" will export in Kuzzle format usable for internal fixtures,
49
+ "jsonl" allows to import that data back with kourou,
50
+ "csv" allows to import data into Excel (please, specify the fields to export using the --fields option).`,
51
+ options: ['jsonl', 'kuzzle', 'csv'],
52
+ default: 'jsonl'
53
+ }), fields: command_1.flags.string({
54
+ description: `[CSV format only] The list of fields to be included in the CSV export in dot-path format.
55
+
56
+ Example:
57
+ --fields oneField,anotherField,yetAnotherOne.nested.moarNested
58
+
59
+ Note that the '_id' field is always included in the CSV export. Leaving this option empty implies that all
60
+ exportable fields in the mapping will be exported.`
61
+ }), scrollTTL: command_1.flags.string({
62
+ description: `The scroll TTL option to pass to the dump operation (which performs a document.search under the hood),
63
+ expressed in ms format, e.g. '2s', '1m', '3h'.`
64
+ }) }, kuzzle_1.kuzzleFlags), { protocol: command_1.flags.string({
65
+ description: 'Kuzzle protocol (http or websocket)',
66
+ default: 'ws',
67
+ }) });
68
+ CollectionExport.args = [
69
+ { name: 'index', description: 'Index name', required: true },
70
+ { name: 'collection', description: 'Collection name', required: true },
71
+ ];
72
+ CollectionExport.examples = [
73
+ 'kourou collection:export nyc-open-data yellow-taxi',
74
+ 'kourou collection:export nyc-open-data yellow-taxi --query \'{ term: { city: "Saigon" } }\'',
75
+ ];
@@ -0,0 +1,27 @@
1
+ import { flags } from '@oclif/command';
2
+ import { Kommand } from '../../common';
3
+ export default class CollectionImport extends Kommand {
4
+ static keepAuth: boolean;
5
+ static description: string;
6
+ static flags: {
7
+ protocol: flags.IOptionFlag<string>;
8
+ host: flags.IOptionFlag<string>;
9
+ port: flags.IOptionFlag<string>;
10
+ ssl: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
11
+ username: flags.IOptionFlag<string>;
12
+ password: flags.IOptionFlag<string | undefined>;
13
+ as: flags.IOptionFlag<string | undefined>;
14
+ 'api-key': flags.IOptionFlag<string | undefined>;
15
+ help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
16
+ 'batch-size': flags.IOptionFlag<string>;
17
+ index: flags.IOptionFlag<string | undefined>;
18
+ collection: flags.IOptionFlag<string | undefined>;
19
+ 'no-mappings': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
20
+ };
21
+ static args: {
22
+ name: string;
23
+ description: string;
24
+ required: boolean;
25
+ }[];
26
+ runSafe(): Promise<void>;
27
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const path_1 = tslib_1.__importDefault(require("path"));
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const command_1 = require("@oclif/command");
7
+ const common_1 = require("../../common");
8
+ const kuzzle_1 = require("../../support/kuzzle");
9
+ const restore_collection_1 = require("../../support/restore-collection");
10
+ class CollectionImport extends common_1.Kommand {
11
+ async runSafe() {
12
+ this.logInfo(`Start importing dump from ${this.args.path}`);
13
+ if (!this.flags['no-mappings']) {
14
+ const mappingsPath = path_1.default.join(this.args.path, 'mappings.json');
15
+ const dump = JSON.parse(fs_1.default.readFileSync(mappingsPath, 'utf8'));
16
+ await (0, restore_collection_1.restoreCollectionMappings)(this.sdk, dump, this.flags.index, this.flags.collection);
17
+ }
18
+ const { index, collection, total } = await (0, restore_collection_1.restoreCollectionData)(this.sdk, this.log.bind(this), Number(this.flags['batch-size']), path_1.default.join(this.args.path, 'documents.jsonl'), this.flags.index, this.flags.collection);
19
+ this.logOk(`Successfully imported ${total} documents from "${this.args.path}" in "${index}:${collection}"`);
20
+ }
21
+ }
22
+ exports.default = CollectionImport;
23
+ CollectionImport.keepAuth = true;
24
+ CollectionImport.description = 'Imports a collection';
25
+ CollectionImport.flags = Object.assign(Object.assign({ help: command_1.flags.help({}), 'batch-size': command_1.flags.string({
26
+ description: 'Maximum batch size (see limits.documentsWriteCount config)',
27
+ default: '200'
28
+ }), index: command_1.flags.string({
29
+ description: 'If set, override the index destination name',
30
+ }), collection: command_1.flags.string({
31
+ description: 'If set, override the collection destination name',
32
+ }), 'no-mappings': command_1.flags.boolean({
33
+ description: 'Skip collection mappings'
34
+ }) }, kuzzle_1.kuzzleFlags), { protocol: command_1.flags.string({
35
+ description: 'Kuzzle protocol (http or websocket)',
36
+ default: 'ws',
37
+ }) });
38
+ CollectionImport.args = [
39
+ { name: 'path', description: 'Dump directory path', required: true },
40
+ ];