kuzzle 2.15.2 → 2.16.3

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 (49) hide show
  1. package/lib/api/controllers/serverController.js +24 -4
  2. package/lib/api/funnel.js +19 -0
  3. package/lib/{config → api}/httpRoutes.js +29 -14
  4. package/lib/api/openApiGenerator.d.ts +6 -0
  5. package/lib/api/openApiGenerator.js +167 -126
  6. package/lib/api/openapi/document/count.yaml +47 -0
  7. package/lib/api/openapi/document/create.yaml +46 -0
  8. package/lib/api/openapi/document/createOrReplace.yaml +61 -0
  9. package/lib/api/openapi/document/delete.yaml +67 -0
  10. package/lib/api/openapi/document/deleteByQuery.yaml +90 -0
  11. package/lib/api/openapi/document/exists.yaml +35 -0
  12. package/lib/api/openapi/document/get.yaml +68 -0
  13. package/lib/api/openapi/document/index.d.ts +20 -0
  14. package/lib/api/openapi/document/index.js +55 -0
  15. package/lib/api/openapi/document/replace.yaml +66 -0
  16. package/lib/api/openapi/document/scroll.yaml +49 -0
  17. package/lib/api/openapi/document/update.yaml +78 -0
  18. package/lib/api/openapi/index.d.ts +2 -0
  19. package/lib/api/openapi/index.js +18 -0
  20. package/lib/api/openapi/payloads.yaml +32 -0
  21. package/lib/api/request/kuzzleRequest.d.ts +32 -0
  22. package/lib/api/request/kuzzleRequest.js +34 -0
  23. package/lib/api/request/requestInput.d.ts +2 -0
  24. package/lib/api/request/requestInput.js +2 -0
  25. package/lib/config/default.config.js +1 -1
  26. package/lib/core/network/router.js +33 -0
  27. package/lib/core/realtime/hotelClerk.d.ts +7 -0
  28. package/lib/core/realtime/hotelClerk.js +14 -0
  29. package/lib/util/readYamlFile.d.ts +2 -0
  30. package/lib/util/readYamlFile.js +10 -0
  31. package/package-lock.json +160 -175
  32. package/package.json +11 -25
  33. package/.kuzzlerc.sample +0 -988
  34. package/CONTRIBUTING.md +0 -116
  35. package/bin/.lib/colorOutput.js +0 -71
  36. package/bin/.upgrades/connectors/es.js +0 -90
  37. package/bin/.upgrades/connectors/redis.js +0 -112
  38. package/bin/.upgrades/lib/connectorContext.js +0 -38
  39. package/bin/.upgrades/lib/context.js +0 -142
  40. package/bin/.upgrades/lib/formatters.js +0 -103
  41. package/bin/.upgrades/lib/inquirerExtended.js +0 -46
  42. package/bin/.upgrades/lib/logger.js +0 -99
  43. package/bin/.upgrades/lib/progressBar.js +0 -70
  44. package/bin/.upgrades/versions/v1/checkConfiguration.js +0 -85
  45. package/bin/.upgrades/versions/v1/index.js +0 -35
  46. package/bin/.upgrades/versions/v1/upgradeCache.js +0 -149
  47. package/bin/.upgrades/versions/v1/upgradeStorage.js +0 -450
  48. package/protocols/available/.gitignore +0 -4
  49. package/protocols/enabled/.gitignore +0 -4
@@ -1,46 +0,0 @@
1
- /*
2
- * Kuzzle, a backend software, self-hostable and ready to use
3
- * to power modern apps
4
- *
5
- * Copyright 2015-2020 Kuzzle
6
- * mailto: support AT kuzzle.io
7
- * website: http://kuzzle.io
8
- *
9
- * Licensed under the Apache License, Version 2.0 (the "License");
10
- * you may not use this file except in compliance with the License.
11
- * You may obtain a copy of the License at
12
- *
13
- * https://www.apache.org/licenses/LICENSE-2.0
14
- *
15
- * Unless required by applicable law or agreed to in writing, software
16
- * distributed under the License is distributed on an "AS IS" BASIS,
17
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- * See the License for the specific language governing permissions and
19
- * limitations under the License.
20
- */
21
-
22
- 'use strict';
23
-
24
- // Returns an instance of "inquirer" extended with a "direct" function that
25
- // returns the answer directly, instead of a key-value map of answers.
26
- // Useful only because we often prompt questions one by one, with tasks in the
27
- // middle, and this "direct" function helps reducing the clutter.
28
-
29
- const
30
- assert = require('assert').strict,
31
- inquirer = require('inquirer'),
32
- _ = require('lodash');
33
-
34
- inquirer.direct = async function direct (prompt) {
35
- assert(_.isPlainObject(prompt), 'Invalid argument: expected a non-empty object');
36
- assert(typeof prompt.name === 'undefined', 'Unexpected "name" argument: if you need to set a name, use inquirer.prompt');
37
-
38
- const p = _.cloneDeep(prompt);
39
- p.name = 'foo';
40
-
41
- const { foo } = await inquirer.prompt(p);
42
-
43
- return foo;
44
- };
45
-
46
- module.exports = inquirer;
@@ -1,99 +0,0 @@
1
- /*
2
- * Kuzzle, a backend software, self-hostable and ready to use
3
- * to power modern apps
4
- *
5
- * Copyright 2015-2020 Kuzzle
6
- * mailto: support AT kuzzle.io
7
- * website: http://kuzzle.io
8
- *
9
- * Licensed under the Apache License, Version 2.0 (the "License");
10
- * you may not use this file except in compliance with the License.
11
- * You may obtain a copy of the License at
12
- *
13
- * https://www.apache.org/licenses/LICENSE-2.0
14
- *
15
- * Unless required by applicable law or agreed to in writing, software
16
- * distributed under the License is distributed on an "AS IS" BASIS,
17
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- * See the License for the specific language governing permissions and
19
- * limitations under the License.
20
- */
21
-
22
- 'use strict';
23
-
24
- const
25
- fs = require('fs'),
26
- {
27
- ColoredFormatter,
28
- PrefixedFormatter,
29
- FileFormatter
30
- } = require('./formatters');
31
-
32
- class ColorOutput {
33
- constructor (opts) {
34
- this.terminalFormatter = opts.C
35
- ? new PrefixedFormatter()
36
- : new ColoredFormatter();
37
-
38
- this.fileFormatter = new FileFormatter();
39
-
40
- this.fileReport = null;
41
-
42
- if (!opts.R) {
43
- this.notice(`Upgrade report file: ${opts.output}`);
44
- this.fileReport = fs.openSync(opts.output, 'w', 0o600);
45
- }
46
- }
47
-
48
- /* eslint-disable no-console */
49
- error (str) {
50
- console.error(this.terminalFormatter.error(str));
51
-
52
- if (this.fileReport) {
53
- fs.writeSync(this.fileReport, this.fileFormatter.error(str));
54
- }
55
- }
56
-
57
- warn (str) {
58
- console.warn(this.terminalFormatter.warn(str));
59
-
60
- if (this.fileReport) {
61
- fs.writeSync(this.fileReport, this.fileFormatter.warn(str));
62
- }
63
- }
64
-
65
- notice (str) {
66
- console.log(this.terminalFormatter.notice(str));
67
-
68
- if (this.fileReport) {
69
- fs.writeSync(this.fileReport, this.fileFormatter.notice(str));
70
- }
71
- }
72
-
73
- question (str) {
74
- console.log(this.terminalFormatter.question(str));
75
-
76
- if (this.fileReport) {
77
- fs.writeSync(this.fileReport, this.fileFormatter.question(str));
78
- }
79
- }
80
-
81
- ok (str) {
82
- console.log(this.terminalFormatter.ok(str));
83
-
84
- if (this.fileReport) {
85
- fs.writeSync(this.fileReport, this.fileFormatter.ok(str));
86
- }
87
- }
88
-
89
- print (str) {
90
- console.log(this.terminalFormatter.raw(str));
91
-
92
- if (this.fileReport) {
93
- fs.writeSync(this.fileReport, this.fileFormatter.raw(str));
94
- }
95
- }
96
- /* eslint-enable no-console */
97
- }
98
-
99
- module.exports = ColorOutput;
@@ -1,70 +0,0 @@
1
- /*
2
- * Kuzzle, a backend software, self-hostable and ready to use
3
- * to power modern apps
4
- *
5
- * Copyright 2015-2020 Kuzzle
6
- * mailto: support AT kuzzle.io
7
- * website: http://kuzzle.io
8
- *
9
- * Licensed under the Apache License, Version 2.0 (the "License");
10
- * you may not use this file except in compliance with the License.
11
- * You may obtain a copy of the License at
12
- *
13
- * https://www.apache.org/licenses/LICENSE-2.0
14
- *
15
- * Unless required by applicable law or agreed to in writing, software
16
- * distributed under the License is distributed on an "AS IS" BASIS,
17
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- * See the License for the specific language governing permissions and
19
- * limitations under the License.
20
- */
21
-
22
- 'use strict';
23
-
24
- const moment = require('moment');
25
-
26
- // Simple progress bar making the wait for long tasks more bearable
27
- class ProgressBar {
28
- constructor (context, text, total, barSize = 20) {
29
- this.text = text;
30
- this.total = total;
31
- this.barSize = barSize;
32
- this.bar = new context.inquire.ui.BottomBar();
33
- this.update(0);
34
- this.start = Date.now();
35
- }
36
-
37
- destroy () {
38
- this.bar.updateBottomBar('');
39
- this.bar.close();
40
- }
41
-
42
- update (count) {
43
- const
44
- remaining = this._getRemainingTime(count),
45
- str = `${this.text}
46
- ${this._getBar(count)}(remaining: ${remaining}) ${count} / ${this.total}`;
47
-
48
- this.bar.updateBottomBar(str);
49
- }
50
-
51
- _getRemainingTime (count) {
52
- const
53
- elapsed = Date.now() - this.start,
54
- remaining = count > 0
55
- ? Math.round(this.total * elapsed / count) - elapsed
56
- : 0;
57
-
58
- return moment(remaining).format('mm:ss');
59
- }
60
-
61
- _getBar (count) {
62
- const
63
- percent = count * 100 / this.total,
64
- progress = Math.round(percent * this.barSize / 100);
65
-
66
- return '[' + '#'.repeat(progress) + '-'.repeat(this.barSize - progress) + ']';
67
- }
68
- }
69
-
70
- module.exports = ProgressBar;
@@ -1,85 +0,0 @@
1
- /*
2
- * Kuzzle, a backend software, self-hostable and ready to use
3
- * to power modern apps
4
- *
5
- * Copyright 2015-2020 Kuzzle
6
- * mailto: support AT kuzzle.io
7
- * website: http://kuzzle.io
8
- *
9
- * Licensed under the Apache License, Version 2.0 (the "License");
10
- * you may not use this file except in compliance with the License.
11
- * You may obtain a copy of the License at
12
- *
13
- * https://www.apache.org/licenses/LICENSE-2.0
14
- *
15
- * Unless required by applicable law or agreed to in writing, software
16
- * distributed under the License is distributed on an "AS IS" BASIS,
17
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- * See the License for the specific language governing permissions and
19
- * limitations under the License.
20
- */
21
-
22
- 'use strict';
23
-
24
- const _ = require('lodash');
25
-
26
- module.exports = async function check (context) {
27
- let action = false;
28
- const warn = msg => context.log.warn(`[CONFIG. FILES] ${msg}`);
29
- const renamed = {
30
- 'services.db': 'services.storageEngine',
31
- 'services.internalEngine': 'services.internalIndex',
32
- 'services.storageEngine.commonMapping._kuzzle_info': 'services.storageEngine.commonMapping.properties._kuzzle_info',
33
- 'services.storageEngine.dynamic': 'services.storageEngine.commonMapping.dynamic'
34
- };
35
- const deprecated = [
36
- 'server.entryPoints',
37
- 'server.protocols.socketio',
38
- 'server.proxy',
39
- 'services.garbageCollector',
40
- 'services.storageEngine.client.apiVersion',
41
- 'services.storageEngine.commonMapping.properties._kuzzle_info.deletedAt',
42
- 'services.storageEngine.commonMapping.properties._kuzzle_info.active'
43
- ];
44
-
45
-
46
- for (const [oldName, newName] of Object.entries(renamed)) {
47
- if (_.get(context.config, oldName)) {
48
- action = true;
49
- warn(`The configuration key "${oldName}" is now named "${newName}"`);
50
- }
51
- }
52
-
53
- for (const name of deprecated) {
54
- if (_.get(context.config, name)) {
55
- action = true;
56
- warn(`The configuration key "${name}" is obsolete and should be removed`);
57
- }
58
- }
59
-
60
- if (action) {
61
- const
62
- choices = [
63
- 'Check again',
64
- 'Abort',
65
- 'Ignore (not recommended)'
66
- ],
67
- proceed = await context.inquire.direct({
68
- choices,
69
- default: choices[0],
70
- message: 'Configuration files need to be updated:',
71
- type: 'list'
72
- });
73
-
74
- if (proceed === choices[0]) {
75
- await context.loadConfiguration();
76
- return check(context);
77
- }
78
-
79
- if (proceed === choices[1]) {
80
- process.exit(1);
81
- }
82
- }
83
-
84
- context.log.ok('Configuration files checked: OK');
85
- };
@@ -1,35 +0,0 @@
1
- /*
2
- * Kuzzle, a backend software, self-hostable and ready to use
3
- * to power modern apps
4
- *
5
- * Copyright 2015-2020 Kuzzle
6
- * mailto: support AT kuzzle.io
7
- * website: http://kuzzle.io
8
- *
9
- * Licensed under the Apache License, Version 2.0 (the "License");
10
- * you may not use this file except in compliance with the License.
11
- * You may obtain a copy of the License at
12
- *
13
- * https://www.apache.org/licenses/LICENSE-2.0
14
- *
15
- * Unless required by applicable law or agreed to in writing, software
16
- * distributed under the License is distributed on an "AS IS" BASIS,
17
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- * See the License for the specific language governing permissions and
19
- * limitations under the License.
20
- */
21
-
22
- 'use strict';
23
-
24
- const checkConfiguration = require('./checkConfiguration');
25
- const upgradeStorage = require('./upgradeStorage');
26
- const upgradeCache = require('./upgradeCache');
27
-
28
- module.exports = async function upgrade (context) {
29
- context.log.notice('\n\n=== CONFIGURATION FILES ===');
30
- await checkConfiguration(context);
31
- context.log.notice('\n\n=== STORAGE ===');
32
- await upgradeStorage(context);
33
- context.log.notice('\n\n=== CACHE ===');
34
- await upgradeCache(context);
35
- };
@@ -1,149 +0,0 @@
1
- /*
2
- * Kuzzle, a backend software, self-hostable and ready to use
3
- * to power modern apps
4
- *
5
- * Copyright 2015-2020 Kuzzle
6
- * mailto: support AT kuzzle.io
7
- * website: http://kuzzle.io
8
- *
9
- * Licensed under the Apache License, Version 2.0 (the "License");
10
- * you may not use this file except in compliance with the License.
11
- * You may obtain a copy of the License at
12
- *
13
- * https://www.apache.org/licenses/LICENSE-2.0
14
- *
15
- * Unless required by applicable law or agreed to in writing, software
16
- * distributed under the License is distributed on an "AS IS" BASIS,
17
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- * See the License for the specific language governing permissions and
19
- * limitations under the License.
20
- */
21
-
22
- 'use strict';
23
-
24
- const getRedisConnector = require('../../connectors/redis');
25
-
26
- async function copyKey (context, key) {
27
- const
28
- dump = await context.source.dumpBuffer(key),
29
- ttl = Math.max(0, await context.source.pttl(key));
30
-
31
- // Breaking change from v1 to v2, due to how indexes are handled:
32
- // token keys are prefixed "repos/%kuzzle/token" in v1, and
33
- // "repos/kuzzle/token" in v2
34
- const newKey = key.replace('repos/%kuzzle/token', 'repos/kuzzle/token');
35
-
36
- await context.target.restore(newKey, ttl, dump, 'REPLACE');
37
- }
38
-
39
- async function getSourceKeys (context, pattern) {
40
- if (!context.source.nodes) {
41
- return await context.source.keys(pattern);
42
- }
43
-
44
- const keys = [];
45
-
46
- for (const node of context.source.nodes('master')) {
47
- keys.push(...await node.source.keys(pattern));
48
- }
49
-
50
- return keys;
51
- }
52
-
53
- async function copyDatabase (context, db) {
54
- await context.source.select(db);
55
- await context.target.select(db);
56
-
57
- await context.target.flushdb();
58
-
59
- const keys = await getSourceKeys(context, '*');
60
-
61
- for (const key of keys) {
62
- await copyKey(context, key);
63
- }
64
-
65
- context.log.ok(`Imported cache keys from database ${db}`);
66
- }
67
-
68
- async function inPlaceMigration (context) {
69
- context.log.notice(`
70
- In-place migration detected: this script will make the changes necessary to
71
- make the cache data compatible with Kuzzle v2.`);
72
-
73
- const
74
- choices = {
75
- abort: 'Abort',
76
- copy: 'Copy to new keys (obsolete keys will be delete once expired)',
77
- move: 'Move keys (cannot be undone, cache won\'t work with Kuzzle v1 anymore)'
78
- },
79
- action = await context.inquire.direct({
80
- choices: Object.values(choices),
81
- default: choices.copy,
82
- message: 'Select how the database should be migrated:',
83
- type: 'list'
84
- });
85
-
86
- if (action === choices.abort) {
87
- context.log.error('Aborted by user.');
88
- process.exit(0);
89
- }
90
-
91
- const db = context.config.services.internalCache.database || 0;
92
-
93
- await context.source.select(db);
94
-
95
- const keys = await getSourceKeys(context, 'repos/*');
96
-
97
- for (const key of keys) {
98
- await copyKey(context, key);
99
-
100
- if (action === choices.move) {
101
- await context.source.del(key);
102
- }
103
- }
104
- }
105
-
106
- async function upgradeToTarget (context) {
107
- context.log.notice(`
108
- This script will WIPE TARGET DATABASES from the target cache instance.
109
- Then, it will COPY all data from the source cache instance, without altering it
110
- in any way.`);
111
-
112
- const confirm = await context.inquire.direct({
113
- default: true,
114
- message: 'Continue?',
115
- type: 'confirm'
116
- });
117
-
118
- if (!confirm) {
119
- context.log.error('Aborted by user.');
120
- process.exit(0);
121
- }
122
-
123
- for (const cachedb of ['internalCache', 'memoryStorage']) {
124
- const config = context.config.services[cachedb];
125
-
126
- await copyDatabase(context, config.database || 0);
127
- }
128
- }
129
-
130
- module.exports = async function upgradeCache (context) {
131
- const cacheContext = await getRedisConnector(context);
132
-
133
- try {
134
- if (cacheContext.inPlace) {
135
- await inPlaceMigration(cacheContext);
136
- }
137
- else {
138
- await upgradeToTarget(cacheContext);
139
- }
140
-
141
- cacheContext.log.ok('Cache import complete.');
142
- }
143
- catch (e) {
144
- cacheContext.log.error(`Cache import failure: ${e.message}`);
145
- cacheContext.log.print(e.stack);
146
- cacheContext.log.error('Aborted.');
147
- process.exit(1);
148
- }
149
- };