kuzzle 2.61.0-beta.1 → 2.61.0-beta.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.
@@ -38,7 +38,7 @@ const wrapped = (0, kerror_1.wrap)("core", "configuration");
38
38
  function loadConfig() {
39
39
  let raw;
40
40
  try {
41
- raw = (0, rc_1.default)("kuzzle", withoutTokenDefaults(default_config_1.default));
41
+ raw = (0, rc_1.default)("kuzzle", withoutUnsetDefaults(default_config_1.default));
42
42
  }
43
43
  catch (e) {
44
44
  throw wrapped.get("cannot_parse", e instanceof Error ? e.message : (0, node_util_1.inspect)(e));
@@ -46,9 +46,11 @@ function loadConfig() {
46
46
  // In place: what `unstringify` answers is the object it was given.
47
47
  unstringify(raw);
48
48
  const { authToken, deprecatedSettings, jwt } = resolveTokenSettings(raw.security);
49
+ const { ignoredSettings, storageEngine } = resolveStorageEngine(raw.services.storageEngine);
49
50
  const loaded = {
50
51
  ...raw,
51
52
  security: { ...raw.security, authToken, jwt },
53
+ services: { ...raw.services, storageEngine },
52
54
  };
53
55
  checkLimitsConfig(loaded);
54
56
  checkHttpOptions(loaded);
@@ -64,6 +66,7 @@ function loadConfig() {
64
66
  seed: Buffer.from("^m&mOISKBvb1xpl1mRsrylaQXpjb&IJX"),
65
67
  },
66
68
  deprecatedSettings,
69
+ ignoredSettings,
67
70
  notifiableProtocols: [],
68
71
  },
69
72
  version: package_json_1.default.version,
@@ -75,19 +78,51 @@ function loadConfig() {
75
78
  return config;
76
79
  }
77
80
  /**
78
- * The packaged defaults, minus the values of `security.authToken` and of its
79
- * deprecated spelling `security.jwt`: both sections ship the same non-null
80
- * defaults, so once `rc` has merged them nothing tells a user's
81
- * `jwt.expiresIn` from the packaged one. Left empty here, they hold only what
82
- * the user set, and {@link resolveTokenSettings} applies the defaults after.
81
+ * The packaged defaults, minus the ones Kuzzle must tell apart from a value
82
+ * the user set, applied after `rc` has merged the configuration:
83
+ *
84
+ * - the values of `security.authToken` and of its deprecated spelling
85
+ * `security.jwt`: both sections ship the same non-null defaults, so once
86
+ * merged nothing tells a user's `jwt.expiresIn` from the packaged one. Left
87
+ * empty here, they hold only what the user set, and
88
+ * {@link resolveTokenSettings} applies the defaults after;
89
+ * - `services.storageEngine.majorVersion`, ignored when a storage driver is
90
+ * set: {@link resolveStorageEngine} reports it then, and applies the default.
83
91
  *
84
92
  * A shallow copy: the other sections stay the packaged objects `rc` merges
85
93
  * into, as before.
86
94
  */
87
- function withoutTokenDefaults(defaults) {
95
+ function withoutUnsetDefaults(defaults) {
88
96
  const authToken = {};
89
97
  const jwt = {};
90
- return { ...defaults, security: { ...defaults.security, authToken, jwt } };
98
+ const storageEngine = {
99
+ ...defaults.services.storageEngine,
100
+ };
101
+ delete storageEngine.majorVersion;
102
+ return {
103
+ ...defaults,
104
+ security: { ...defaults.security, authToken, jwt },
105
+ services: { ...defaults.services, storageEngine },
106
+ };
107
+ }
108
+ /**
109
+ * Applies the default `majorVersion`. `ignoredSettings` lists it when the
110
+ * user set it along with a storage `driver`, which `majorVersion` does not
111
+ * select: logged as a warning when the storage engine starts.
112
+ */
113
+ function resolveStorageEngine(storageEngine) {
114
+ const ignoredSettings = storageEngine.driver !== undefined &&
115
+ storageEngine.majorVersion !== undefined
116
+ ? ["services.storageEngine.majorVersion"]
117
+ : [];
118
+ return {
119
+ ignoredSettings,
120
+ storageEngine: {
121
+ ...storageEngine,
122
+ majorVersion: storageEngine.majorVersion ??
123
+ default_config_1.default.services.storageEngine.majorVersion,
124
+ },
125
+ };
91
126
  }
92
127
  /**
93
128
  * Resolves the authentication token settings: for each one, the value set
@@ -39,6 +39,10 @@ class StorageEngine {
39
39
  this.logger.info(identity === null
40
40
  ? `[ℹ] Elasticsearch configuration is set to major version : ${global.kuzzle.config.services.storageEngine.majorVersion}`
41
41
  : `[ℹ] Storage driver: ${description}`);
42
+ const ignored = global.kuzzle.config.internal?.ignoredSettings;
43
+ if (ignored?.length) {
44
+ this.logger.warn(`[⚠] Ignored, since "services.storageEngine.driver" selects the storage driver: ${ignored.join(", ")}. Remove it from your configuration.`);
45
+ }
42
46
  }
43
47
  /**
44
48
  * Initialize storage clients and perform integrity checks
@@ -357,7 +357,7 @@
357
357
  "code": 6,
358
358
  "errors": {
359
359
  "not_found": {
360
- "description": "The package named by services.storageEngine.driver cannot be found. Kuzzle does not start.",
360
+ "description": "The storage driver package cannot be found: the one named by services.storageEngine.driver, or the built-in kuzzle-storage-es-7 / kuzzle-storage-es-8 package of the configured majorVersion. Kuzzle does not start.",
361
361
  "code": 1,
362
362
  "message": "Cannot find the storage driver \"%s\": %s.",
363
363
  "class": "InternalError"
@@ -1,17 +1,11 @@
1
- import { Client as ClientES7 } from "sdk-es7";
2
- import { Client as ClientES8 } from "sdk-es8";
3
- import { ES7 } from "./7/elasticsearch";
4
- import { ES8 } from "./8/elasticsearch";
5
- import type { JSONObject } from "../../types/JSONObject";
1
+ import type { Client as ClientES7 } from "sdk-es7";
2
+ import type { Client as ClientES8 } from "sdk-es8";
6
3
  import type { StorageEngineElasticsearch } from "../../types/config/storageEngine/StorageEngineElasticsearchConfiguration";
7
- import type { StorageDriver, StorageDriverClass } from "../../types/storage/StorageDriver";
8
- export declare class ES7Driver extends ES7 implements StorageDriver {
9
- static createNativeClient(clientConfig: JSONObject): ClientES7;
10
- init(): Promise<void>;
11
- }
12
- export declare class ES8Driver extends ES8 implements StorageDriver {
13
- static createNativeClient(clientConfig: JSONObject): ClientES8;
14
- init(): Promise<void>;
15
- }
16
- /** The built-in driver of an Elasticsearch major version */
4
+ import type { StorageDriverClass } from "../../types/storage/StorageDriver";
5
+ /**
6
+ * The built-in driver of an Elasticsearch major version
7
+ *
8
+ * @throws {services.storage_driver.not_found} if its package is not
9
+ * installed: Kuzzle does not start
10
+ */
17
11
  export declare function builtInStorageDriver(majorVersion: StorageEngineElasticsearch["majorVersion"]): StorageDriverClass<ClientES7 | ClientES8, StorageEngineElasticsearch>;
@@ -19,43 +19,99 @@
19
19
  * See the License for the specific language governing permissions and
20
20
  * limitations under the License.
21
21
  */
22
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
23
+ if (k2 === undefined) k2 = k;
24
+ var desc = Object.getOwnPropertyDescriptor(m, k);
25
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
26
+ desc = { enumerable: true, get: function() { return m[k]; } };
27
+ }
28
+ Object.defineProperty(o, k2, desc);
29
+ }) : (function(o, m, k, k2) {
30
+ if (k2 === undefined) k2 = k;
31
+ o[k2] = m[k];
32
+ }));
33
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
34
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
35
+ }) : function(o, v) {
36
+ o["default"] = v;
37
+ });
38
+ var __importStar = (this && this.__importStar) || (function () {
39
+ var ownKeys = function(o) {
40
+ ownKeys = Object.getOwnPropertyNames || function (o) {
41
+ var ar = [];
42
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
43
+ return ar;
44
+ };
45
+ return ownKeys(o);
46
+ };
47
+ return function (mod) {
48
+ if (mod && mod.__esModule) return mod;
49
+ var result = {};
50
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
51
+ __setModuleDefault(result, mod);
52
+ return result;
53
+ };
54
+ })();
22
55
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.ES8Driver = exports.ES7Driver = void 0;
24
56
  exports.builtInStorageDriver = builtInStorageDriver;
25
- // The built-in Elasticsearch 7 and 8 drivers (ADR-0003 step 02): today's
26
- // classes as they are, plus the two members of the `StorageDriver` contract
27
- // they lack. Extracted to their own packages at the next major.
28
- const sdk_es7_1 = require("sdk-es7");
29
- const sdk_es8_1 = require("sdk-es8");
30
- const elasticsearch_1 = require("./7/elasticsearch");
31
- const elasticsearch_2 = require("./8/elasticsearch");
32
- class ES7Driver extends elasticsearch_1.ES7 {
33
- static createNativeClient(clientConfig) {
34
- return new sdk_es7_1.Client(clientConfig);
57
+ // The built-in Elasticsearch 7 and 8 drivers (ADR-0003 step 06): the
58
+ // packages `kuzzle-storage-es-7` and `kuzzle-storage-es-8`, dependencies of
59
+ // Kuzzle at pinned versions. Dropped from Kuzzle's dependencies at the next
60
+ // major.
61
+ const path = __importStar(require("node:path"));
62
+ const kerror = __importStar(require("../../kerror"));
63
+ const driverError = kerror.wrap("services", "storage_driver");
64
+ const PACKAGES = {
65
+ "7": "kuzzle-storage-es-7",
66
+ "8": "kuzzle-storage-es-8",
67
+ };
68
+ /**
69
+ * The built-in driver of an Elasticsearch major version
70
+ *
71
+ * @throws {services.storage_driver.not_found} if its package is not
72
+ * installed: Kuzzle does not start
73
+ */
74
+ function builtInStorageDriver(majorVersion) {
75
+ const packageName = PACKAGES[majorVersion];
76
+ if (!packageName) {
77
+ throw new Error("Invalid Elasticsearch version.");
35
78
  }
36
- init() {
37
- return this._initSequence();
79
+ let entry;
80
+ try {
81
+ entry = require.resolve(packageName);
38
82
  }
83
+ catch (error) {
84
+ throw driverError.get("not_found", packageName, error instanceof Error ? error.message : String(error));
85
+ }
86
+ provideRunningKuzzle(entry);
87
+ // Loaded here, not at module load: the package requires `kuzzle`, which
88
+ // has to be loaded first.
89
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
90
+ return require(entry).default;
39
91
  }
40
- exports.ES7Driver = ES7Driver;
41
- class ES8Driver extends elasticsearch_2.ES8 {
42
- static createNativeClient(clientConfig) {
43
- return new sdk_es8_1.Client(clientConfig);
92
+ /**
93
+ * A driver package requires `kuzzle`, a peer dependency. In an application,
94
+ * that is the running Kuzzle. When Kuzzle is itself the application (its
95
+ * repository, its Docker image), npm installs another copy of `kuzzle` for
96
+ * that peer dependency, whose error classes the running Kuzzle does not
97
+ * recognize: the running Kuzzle is put in that copy's place.
98
+ */
99
+ function provideRunningKuzzle(driverEntry) {
100
+ // `index.js` once built, `index.ts` when run from the sources
101
+ const entry = path.join(__dirname, "../../../index");
102
+ const running = require.cache[`${entry}.js`] ?? require.cache[`${entry}.ts`];
103
+ let peer;
104
+ try {
105
+ peer = require.resolve("kuzzle", {
106
+ paths: [path.dirname(driverEntry)],
107
+ });
44
108
  }
45
- init() {
46
- return this._initSequence();
109
+ catch {
110
+ return;
47
111
  }
48
- }
49
- exports.ES8Driver = ES8Driver;
50
- /** The built-in driver of an Elasticsearch major version */
51
- function builtInStorageDriver(majorVersion) {
52
- switch (majorVersion) {
53
- case "7":
54
- return ES7Driver;
55
- case "8":
56
- return ES8Driver;
57
- default:
58
- throw new Error("Invalid Elasticsearch version.");
112
+ // Under vitest, Kuzzle is not in Node's module cache: nothing to provide
113
+ if (running && require.cache[peer] === undefined) {
114
+ require.cache[peer] = running;
59
115
  }
60
116
  }
61
117
  //# sourceMappingURL=builtInDrivers.js.map
@@ -170,6 +170,14 @@ export interface IKuzzleConfiguration {
170
170
  * Optional here for the reason given on {@link IKuzzleConfiguration.version}.
171
171
  */
172
172
  deprecatedSettings?: string[];
173
+ /**
174
+ * Derived at startup: the configuration keys the user set that Kuzzle
175
+ * ignores (today, "services.storageEngine.majorVersion" set along with a
176
+ * storage driver), logged as a warning.
177
+ *
178
+ * Optional here for the reason given on {@link IKuzzleConfiguration.version}.
179
+ */
180
+ ignoredSettings?: string[];
173
181
  };
174
182
  /**
175
183
  * Collection specifications to apply at startup, by index then collection.
@@ -1,13 +1,18 @@
1
1
  export type StorageEngineElasticsearch = {
2
2
  /**
3
3
  * The npm package of the storage driver to run on (e.g.
4
- * `"@kuzzleio/storage-es-9"`), installed next to `kuzzle`. Not set: the
4
+ * `"kuzzle-storage-es-9"`), installed next to `kuzzle`. Not set: the
5
5
  * built-in Elasticsearch driver of `majorVersion`.
6
6
  */
7
7
  driver?: string;
8
8
  /**
9
9
  * Elasticsearch major version, which selects the built-in driver when
10
- * `driver` is not set
10
+ * `driver` is not set; ignored otherwise (Kuzzle warns at startup if both
11
+ * are set).
12
+ *
13
+ * Deprecated in the documentation only: Kuzzle 3 selects the storage engine
14
+ * with `driver` alone, but an ES7 / ES8 stack has nothing else to use in
15
+ * Kuzzle 2, hence no `@deprecated` tag (see docs/v3-breaking-changes.md).
11
16
  * @default "7"
12
17
  */
13
18
  majorVersion: "7" | "8";
package/dist/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kuzzle",
3
3
  "author": "The Kuzzle Team <support@kuzzle.io>",
4
- "version": "2.61.0-beta.1",
4
+ "version": "2.61.0-beta.3",
5
5
  "description": "Kuzzle is an open-source solution that handles all the data management through a secured API, with a large choice of protocols.",
6
6
  "scripts": {
7
7
  "build": "rm -Rf ./dist && tsc && node -r ts-node/register/transpile-only ./bin/copy-binaries.ts",
@@ -52,6 +52,8 @@
52
52
  "kuzzle-logger": "1.7.0",
53
53
  "kuzzle-plugin-auth-passport-local": "6.4.1",
54
54
  "kuzzle-sdk": ">=7.17.1 <8.0.0",
55
+ "kuzzle-storage-es-7": "1.0.0",
56
+ "kuzzle-storage-es-8": "1.0.0",
55
57
  "kuzzle-types": "^1.0.0",
56
58
  "kuzzle-vault": "2.2.0",
57
59
  "lodash": "4.17.21",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kuzzle",
3
3
  "author": "The Kuzzle Team <support@kuzzle.io>",
4
- "version": "2.61.0-beta.1",
4
+ "version": "2.61.0-beta.3",
5
5
  "description": "Kuzzle is an open-source solution that handles all the data management through a secured API, with a large choice of protocols.",
6
6
  "scripts": {
7
7
  "build": "rm -Rf ./dist && tsc && node -r ts-node/register/transpile-only ./bin/copy-binaries.ts",
@@ -52,6 +52,8 @@
52
52
  "kuzzle-logger": "1.7.0",
53
53
  "kuzzle-plugin-auth-passport-local": "6.4.1",
54
54
  "kuzzle-sdk": ">=7.17.1 <8.0.0",
55
+ "kuzzle-storage-es-7": "1.0.0",
56
+ "kuzzle-storage-es-8": "1.0.0",
55
57
  "kuzzle-types": "^1.0.0",
56
58
  "kuzzle-vault": "2.2.0",
57
59
  "lodash": "4.17.21",