@sfxcode/mongocamp-server-core 1.10.0 → 2.0.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.
Files changed (3) hide show
  1. package/dist/index.d.mts +77 -20
  2. package/dist/index.mjs +3024 -2340
  3. package/package.json +3 -1
package/dist/index.d.mts CHANGED
@@ -35,6 +35,8 @@ declare const ConfigKeys: {
35
35
  readonly AuthRefreshGraceDuration: "AUTH_REFRESH_GRACE_DURATION";
36
36
  readonly AuthGrantDeniedStatus: "AUTH_GRANT_DENIED_STATUS";
37
37
  readonly ImportMaxBytes: "IMPORT_MAX_BYTES";
38
+ readonly FilterTimeZone: "FILTER_TIME_ZONE";
39
+ readonly MigrationDropScalaLeftovers: "MIGRATION_DROP_SCALA_LEFTOVERS";
38
40
  readonly AuthPrefix: "AUTH_PREFIX";
39
41
  readonly AuthBearer: "AUTH_BEARER";
40
42
  readonly AuthBasic: "AUTH_BASIC";
@@ -158,16 +160,24 @@ declare const PaginationHeaders: {
158
160
  readonly currentPage: "x-pagination-current-page";
159
161
  readonly countRows: "x-pagination-count-rows";
160
162
  readonly countPages: "x-pagination-count-pages";
163
+ readonly next: "x-pagination-next";
161
164
  };
165
+ /** `after` switches to cursor paging (`http/cursor.ts`): the token of the previous page, or empty for the first page. */
162
166
  interface Paging {
163
167
  rowsPerPage?: number;
164
168
  page?: number;
169
+ after?: string;
165
170
  }
171
+ /**
172
+ * `allCount` and `pagesCount` are missing when the count was skipped (`count=none`), `page` with cursor paging; `next` is the cursor of the
173
+ * next page, missing when the page is the last one.
174
+ */
166
175
  interface PaginationInfo {
167
- allCount: number;
176
+ allCount?: number;
168
177
  perPage: number;
169
- page: number;
170
- pagesCount: number;
178
+ page?: number;
179
+ pagesCount?: number;
180
+ next?: string;
171
181
  }
172
182
 
173
183
  interface Grant {
@@ -184,7 +194,7 @@ interface Role {
184
194
  }
185
195
  interface UserInformation {
186
196
  userId: string;
187
- /** SHA-256 hex of the password. */
197
+ /** The stored hash of the password (`auth/password.ts`: `scrypt$...`, or the SHA-256 hex of the Scala server). */
188
198
  password: string;
189
199
  apiKey: string | null;
190
200
  roles: string[];
@@ -241,8 +251,8 @@ interface AuthHolder {
241
251
  info: PaginationInfo;
242
252
  }>;
243
253
  findUserOption: (userId: string) => Promise<UserInformation | undefined>;
244
- /** The user with the given password hash; 401 "user or password does not exists" otherwise. */
245
- findUserWithPassword: (userId: string, passwordHash: string) => Promise<UserInformation>;
254
+ /** Replaces a password hash of the old format after a login (only while the stored hash is still `oldHash`). */
255
+ upgradePassword: (userId: string, oldHash: string, newHash: string) => Promise<void>;
246
256
  findUserByApiKeyOption: (apiKey: string) => Promise<UserInformation | undefined>;
247
257
  findRoles: (names: string[]) => Promise<Role[]>;
248
258
  }
@@ -256,6 +266,11 @@ declare class MongoAuthHolder implements AuthHolder {
256
266
  get rolesCollection(): Collection;
257
267
  /** Creates the indexes and, for an empty user collection, the user `admin` with a random password that is printed once. */
258
268
  createIndicesAndInitData(log?: (message: string) => void): Promise<void>;
269
+ /**
270
+ * Unique index for the api-key lookup, partial on string values (users without a key store `null`). A database in which two users share
271
+ * 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.
272
+ */
273
+ createApiKeyIndex(warn?: (message: string) => void): Promise<void>;
259
274
  allUsers(filter: string | undefined, paging: Paging): Promise<{
260
275
  items: UserInformation[];
261
276
  info: PaginationInfo;
@@ -265,7 +280,7 @@ declare class MongoAuthHolder implements AuthHolder {
265
280
  info: PaginationInfo;
266
281
  }>;
267
282
  findUserOption(userId: string): Promise<UserInformation | undefined>;
268
- findUserWithPassword(userId: string, passwordHash: string): Promise<UserInformation>;
283
+ upgradePassword(userId: string, oldHash: string, newHash: string): Promise<void>;
269
284
  findUserByApiKeyOption(apiKey: string): Promise<UserInformation | undefined>;
270
285
  findRoles(names: string[]): Promise<Role[]>;
271
286
  addUser(user: UserInformation): Promise<UserInformation>;
@@ -339,6 +354,8 @@ declare class AuthService {
339
354
  private readonly version;
340
355
  readonly holder: AuthHolder;
341
356
  readonly tokens: TokenCache;
357
+ /** Key: SHA-256 of user and password; value: the stored hash that was verified, valid while the user still has it. */
358
+ private readonly basicCache;
342
359
  constructor(database: MongocampDatabase, config: ConfigStore, version: VersionInfo);
343
360
  initialize(): Promise<void>;
344
361
  /** The users and roles in the database, for the routes that change them (only with `AUTH_HANDLER=mongo`). */
@@ -360,6 +377,12 @@ declare class AuthService {
360
377
  /** A new token for the user (`AuthHolder.generateLoginResult`), valid for `AUTH_EXPIRING_DURATION`. */
361
378
  generateLoginResult(user: UserInformation): Promise<LoginResult>;
362
379
  login(userId: string, password: string): Promise<LoginResult>;
380
+ /**
381
+ * The user with this password; 401 "user or password does not exists" otherwise. A correct password with a hash of the old format
382
+ * (SHA-256 of the Scala server) is stored again with a salted hash (2.0.0). With `cache` (Basic auth) a verified password is remembered
383
+ * for `BasicAuthCacheMillis` as long as the stored hash does not change (a new password or a deleted user count at once).
384
+ */
385
+ verifyCredentials(userId: string, password: string, cache: boolean): Promise<UserInformation>;
363
386
  /** A new token; the bearer token of the call stays valid for `AUTH_REFRESH_GRACE_DURATION` and is invalid afterwards. */
364
387
  refresh(user: UserInformation, bearer: string | undefined): Promise<LoginResult>;
365
388
  }
@@ -400,8 +423,20 @@ interface components {
400
423
  /** ClusterMemberInformation */
401
424
  ClusterMemberInformation: {
402
425
  name: string;
426
+ /**
427
+ * @deprecated
428
+ * @description Deprecated: JGroups cluster of the Scala server, always false
429
+ */
403
430
  siteMaster: boolean;
431
+ /**
432
+ * @deprecated
433
+ * @description Deprecated: JGroups cluster of the Scala server, always false
434
+ */
404
435
  siteAddress: boolean;
436
+ /**
437
+ * @deprecated
438
+ * @description Deprecated: JGroups cluster of the Scala server, always false
439
+ */
405
440
  multicast: boolean;
406
441
  coordinator: boolean;
407
442
  };
@@ -617,6 +652,10 @@ interface components {
617
652
  /** IndexOptionsRequest */
618
653
  IndexOptionsRequest: {
619
654
  name?: string;
655
+ /**
656
+ * @deprecated
657
+ * @description Deprecated: ignored by MongoDB since 4.2
658
+ */
620
659
  background?: boolean;
621
660
  defaultLanguage?: string;
622
661
  /** Format: int32 */
@@ -860,7 +899,15 @@ interface components {
860
899
  /** SettingsResponse */
861
900
  SettingsResponse: {
862
901
  routesPlugins?: string[];
902
+ /**
903
+ * @deprecated
904
+ * @description Deprecated: plugin system of the Scala server, always [GridFsFileAdapter]
905
+ */
863
906
  filePlugins?: string[];
907
+ /**
908
+ * @deprecated
909
+ * @description Deprecated: plugin system of the Scala server, the value of PLUGINS_IGNORED
910
+ */
864
911
  ignoredPlugins?: string[];
865
912
  configurations: components["schemas"]["Map_Any"];
866
913
  };
@@ -1155,7 +1202,7 @@ declare class ConfigPersistence {
1155
1202
  * year optional), steps as `* /5` without the space, `L`, `W`, `#`, nicknames like `@daily`; 0 is Sunday.
1156
1203
  *
1157
1204
  * Differences to the Scala server (Quartz, clustered JDBC job store in `mc_jobs_*`): the Quartz tables are not read, Quartz expressions
1158
- * like `0 0/5 * ? * * *` are not accepted, and every instance with an active scheduler runs the jobs (the handlers must allow that, the
1205
+ * like `0 0/5 * ? * * *` are not accepted (`MIGRATION_DROP_SCALA_LEFTOVERS` rewrites the one of the token cleanup), and every instance with an active scheduler runs the jobs (the handlers must allow that, the
1159
1206
  * token cleanup does). Changes of another instance are read with the refresh.
1160
1207
  */
1161
1208
  type JobConfig = Schemas['JobConfig'];
@@ -1397,16 +1444,18 @@ declare function convertIdValue(id: unknown): unknown;
1397
1444
  declare function pathIdFilter(id: string): PlainObject;
1398
1445
 
1399
1446
  /**
1400
- * How documents are written in responses.
1447
+ * How documents are written in responses (query parameter `extendedJson`).
1401
1448
  *
1402
- * Without the query parameter `extendedJson` the documents are written as the Scala server did (`BsonConverter.asMap` + circe):
1403
- * ObjectIds as hex strings, dates as ISO-8601 instants, every number as JSON number (64 bit integers and decimals with all digits),
1404
- * regular expressions as their pattern. With `extendedJson=relaxed|canonical` they are MongoDB Extended JSON (`ExtendedJsonWriter.scala`).
1449
+ * - `relaxed` (the default since 2.0.0) and `canonical`: MongoDB Extended JSON (`ExtendedJsonWriter.scala`), the types of ids, dates,
1450
+ * decimals, binary data and regular expressions stay visible (`{"$oid": ...}`, `{"$date": ...}`); canonical also wraps every number.
1451
+ * A text that looks like a date is written as `{"$string": ...}`, so a request body gives it back as text.
1452
+ * - `plain` (the default of 1.x, the format of the Scala server, `BsonConverter.asMap` + circe): ObjectIds as hex strings, dates as
1453
+ * ISO-8601 instants, every number as JSON number (64 bit integers and decimals with all digits), regular expressions as their pattern.
1405
1454
  */
1406
- type ExtendedJsonMode = 'relaxed' | 'canonical';
1407
- /** The mode of the query parameter `extendedJson`; `undefined` without it. Another value is a bad request. */
1455
+ type ExtendedJsonMode = 'relaxed' | 'canonical' | 'plain';
1456
+ /** The mode of the query parameter `extendedJson`; `undefined` without it (the caller picks the default). Another value is a bad request. */
1408
1457
  declare function parseExtendedJsonMode(value: string | null | undefined): ExtendedJsonMode | undefined;
1409
- /** A document for a response: the default format, or Extended JSON for the query parameter `extendedJson`. */
1458
+ /** A document for a response in the mode of the query parameter `extendedJson`, relaxed Extended JSON by default. */
1410
1459
  declare function documentToJson(document: Record<string, unknown>, mode?: ExtendedJsonMode): Record<string, unknown>;
1411
1460
 
1412
1461
  /**
@@ -1456,11 +1505,15 @@ declare class LuceneQueryError extends Error {
1456
1505
  }
1457
1506
 
1458
1507
  /**
1459
- * A Lucene query as MongoDB filter, ported from `LuceneQueryConverter.scala` of the Scala driver with its results (also where they
1460
- * are surprising, e.g. a negated AND group becomes `$nor` of the terms; the server pins these results in its tests).
1508
+ * A Lucene query as MongoDB filter (from `LuceneQueryConverter.scala` of the Scala driver, with Lucene's boolean rules since 2.0.0).
1461
1509
  *
1510
+ * - a group matches its required clauses (MUST) and none of its prohibited ones (MUST_NOT); its optional clauses (SHOULD) only count
1511
+ * without a required clause, then one of them has to match, as in Lucene
1512
+ * - a group of prohibited clauses only matches every document except them (like Elasticsearch and Solr, Lucene itself matches nothing)
1513
+ * - a prohibited group is negated as a whole: `-(a AND b)` is "not both", `$nor` of the group
1462
1514
  * - terms are `$eq` / `$ne` with the converted value (number, boolean, date or text)
1463
- * - wildcards and prefixes are anchored, case-insensitive regular expressions that match line breaks (`$options: "is"`)
1515
+ * - wildcards and prefixes are anchored, case-sensitive regular expressions that match line breaks (`$options: "s"`), so an index on the
1516
+ * field serves a prefix (`abc*`); `caseInsensitive` adds the option `i` (the behaviour before 2.0.0, which cannot use index bounds)
1464
1517
  * - ranges are `$gte`/`$gt`/`$lte`/`$lt`, `[* TO *]`, `field:*` and `_exists_:field` are `$exists`
1465
1518
  *
1466
1519
  * With `searchWithValueAndString` a value that converts (e.g. the number `123`) is also searched as the text (`"123"`).
@@ -1468,6 +1521,10 @@ declare class LuceneQueryError extends Error {
1468
1521
  type Filter = Record<string, unknown>;
1469
1522
  interface ConvertOptions {
1470
1523
  searchWithValueAndString?: boolean;
1524
+ /** Wildcards and prefixes ignore the case (query parameter `filterCaseInsensitive`). */
1525
+ caseInsensitive?: boolean;
1526
+ /** The time zone of dates without offset (`FILTER_TIME_ZONE`), UTC by default. */
1527
+ timeZone?: string;
1471
1528
  }
1472
1529
  declare function luceneQueryToFilter(query: LuceneQuery, options?: ConvertOptions): Filter;
1473
1530
 
@@ -1480,10 +1537,10 @@ declare const FilterDefaultField = "";
1480
1537
  declare function luceneToFilter(input: string, defaultField: string, options?: ConvertOptions): Record<string, unknown>;
1481
1538
  /**
1482
1539
  * The `filter` query parameter of the server (`LuceneQueryTools.parseFilter` + `toFilterMap`): the MongoDB filter of the query, an
1483
- * empty filter without one. A filter that cannot be parsed or converted is a decode failure of the parameter (400, code 4001) with
1540
+ * empty filter without one or for a blank one. A filter that cannot be parsed or converted is a decode failure of the parameter (400, code 4001) with
1484
1541
  * the first line of the reason as additional info. The `_id` and wrapper conversion (`convertFields`) is applied by the routes.
1485
1542
  */
1486
- declare function filterParameter(input: string | null | undefined, parameter?: string): Record<string, unknown>;
1543
+ declare function filterParameter(input: string | null | undefined, options?: ConvertOptions, parameter?: string): Record<string, unknown>;
1487
1544
 
1488
1545
  export { CleanUpTokenJob, CleanUpTokenJobClass, ConfigKeys, ConfigStore, ConfigurationError, DefaultRowsPerPage, ErrorCodes, EventBus, FilterDefaultField, JobScheduler, LuceneQueryError, MongocampError, PaginationHeaders, TextMarker, configDefinitions, convertFields, convertIdValue, createMongocampServer, decodeAny, documentToJson, filterParameter, luceneQueryToFilter, luceneToFilter, parseExtendedJsonMode, parseJson, parseLuceneQuery, pathIdFilter, stringifyJson };
1489
1546
  export type { ConfigDefinition, ConfigKey, ConfigType, ConvertOptions, ErrorDescription, EventListener, EventName, ExtendedJsonMode, JobConfig, JobHandler, JobInformation, JobRun, LuceneQuery, MongocampContext, MongocampEvent, MongocampEvents, MongocampServer, MongocampServerOptions, PaginationInfo, Paging, VersionInfo };