@sfxcode/mongocamp-server-core 2.8.0 → 2.9.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/dist/index.d.mts CHANGED
@@ -353,8 +353,10 @@ declare class MongoAuthHolder implements AuthHolder {
353
353
  /**
354
354
  * Unique index for the api-key lookup, partial on string values (users without a key store `null`). A database in which two users share
355
355
  * a key (possible with the Scala server, which had no index) gets a non-unique index instead, so the start never fails on old data.
356
+ * 2.9.0: an empty key means no key — stored `""` (Scala server, admin UIs that sent `""` for "none") becomes `null` first, otherwise
357
+ * every such user shares the key `""` and the index can never be unique.
356
358
  */
357
- createApiKeyIndex(warn?: (message: string) => void): Promise<void>;
359
+ createApiKeyIndex(warn?: (message: string) => void, log?: (message: string) => void): Promise<void>;
358
360
  allUsers(filter: string | undefined, paging: Paging): Promise<{
359
361
  items: UserInformation[];
360
362
  info: PaginationInfo;
@@ -2577,7 +2579,7 @@ declare function createMongocampServer(options?: MongocampServerOptions): Promis
2577
2579
 
2578
2580
  declare const CoreVersion: {
2579
2581
  readonly name: "@sfxcode/mongocamp-server-core";
2580
- readonly version: "2.8.0";
2582
+ readonly version: "2.9.0";
2581
2583
  };
2582
2584
 
2583
2585
  /** Error codes of the API (`mongocamp-library/.../exception/ErrorCodes.scala`), sent in `ErrorDescription.code` and `x-error-code`. */
package/dist/index.mjs CHANGED
@@ -133,7 +133,8 @@ function toUserInformation(document) {
133
133
  return {
134
134
  userId: String(document.userId ?? ""),
135
135
  password: String(document.password ?? ""),
136
- apiKey: typeof document.apiKey === "string" ? document.apiKey : null,
136
+ // an empty key is no key (2.9.0)
137
+ apiKey: typeof document.apiKey === "string" && document.apiKey !== "" ? document.apiKey : null,
137
138
  roles: Array.isArray(document.roles) ? document.roles.map(String) : []
138
139
  };
139
140
  }
@@ -1275,13 +1276,19 @@ class MongoAuthHolder {
1275
1276
  }
1276
1277
  await this.users.createIndex({ userId: 1 }, { unique: true });
1277
1278
  await this.rolesCollection.createIndex({ name: 1 }, { unique: true });
1278
- await this.createApiKeyIndex(warn);
1279
+ await this.createApiKeyIndex(warn, log);
1279
1280
  }
1280
1281
  /**
1281
1282
  * Unique index for the api-key lookup, partial on string values (users without a key store `null`). A database in which two users share
1282
1283
  * a key (possible with the Scala server, which had no index) gets a non-unique index instead, so the start never fails on old data.
1284
+ * 2.9.0: an empty key means no key — stored `""` (Scala server, admin UIs that sent `""` for "none") becomes `null` first, otherwise
1285
+ * every such user shares the key `""` and the index can never be unique.
1283
1286
  */
1284
- async createApiKeyIndex(warn = console.warn) {
1287
+ async createApiKeyIndex(warn = console.warn, log = console.info) {
1288
+ const cleared = await this.users.updateMany({ apiKey: "" }, { $set: { apiKey: null } });
1289
+ if (cleared.modifiedCount > 0) {
1290
+ log(`${cleared.modifiedCount} users had an empty apiKey, stored as no key (null)`);
1291
+ }
1285
1292
  try {
1286
1293
  await this.users.createIndex(ApiKeyIndex.key, { name: ApiKeyIndex.uniqueName, unique: true, partialFilterExpression: ApiKeyIndex.partialFilter });
1287
1294
  } catch (error) {
@@ -7286,7 +7293,8 @@ function readUserInformation(body) {
7286
7293
  return {
7287
7294
  userId: requiredString(object, "userId"),
7288
7295
  password: requiredString(object, "password"),
7289
- apiKey: optionalString(object, "apiKey") ?? null,
7296
+ // 2.9.0: an empty key means no key (admin UIs send `""` for none); `""` would be one key shared by all such users
7297
+ apiKey: optionalString(object, "apiKey") || null,
7290
7298
  roles: object.roles === void 0 || object.roles === null ? [] : stringList$1(object.roles, "roles")
7291
7299
  };
7292
7300
  }
@@ -19162,7 +19170,7 @@ function metrics() {
19162
19170
  };
19163
19171
  }
19164
19172
 
19165
- const CoreVersion = { name: "@sfxcode/mongocamp-server-core", version: "2.8.0" };
19173
+ const CoreVersion = { name: "@sfxcode/mongocamp-server-core", version: "2.9.0" };
19166
19174
 
19167
19175
  function registerInformationRoutes(app, context) {
19168
19176
  app.get("/version", () => jsonResponse({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sfxcode/mongocamp-server-core",
3
- "version": "2.8.0",
3
+ "version": "2.9.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {