@aneuhold/be-ts-db-lib 4.2.20 → 4.2.22
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/CHANGELOG.md +21 -1
- package/lib/index.d.ts +1 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -2
- package/lib/index.js.map +1 -1
- package/lib/index.ts +0 -2
- package/lib/repositories/common/UserRepository.d.ts.map +1 -1
- package/lib/repositories/common/UserRepository.js +0 -2
- package/lib/repositories/common/UserRepository.js.map +1 -1
- package/lib/repositories/common/UserRepository.ts +0 -3
- package/lib/services/GoogleAuthService.d.ts +1 -3
- package/lib/services/GoogleAuthService.d.ts.map +1 -1
- package/lib/services/GoogleAuthService.js +3 -15
- package/lib/services/GoogleAuthService.js.map +1 -1
- package/lib/services/GoogleAuthService.ts +6 -24
- package/lib/services/MigrationService.d.ts +5 -0
- package/lib/services/MigrationService.d.ts.map +1 -1
- package/lib/services/MigrationService.js +61 -33
- package/lib/services/MigrationService.js.map +1 -1
- package/lib/services/MigrationService.ts +77 -38
- package/lib/util/DbSchemaUpdater.d.ts.map +1 -1
- package/lib/util/DbSchemaUpdater.js +0 -2
- package/lib/util/DbSchemaUpdater.js.map +1 -1
- package/lib/util/DbSchemaUpdater.ts +0 -2
- package/package.json +3 -3
- package/lib/repositories/common/ApiKeyRepository.d.ts +0 -18
- package/lib/repositories/common/ApiKeyRepository.d.ts.map +0 -1
- package/lib/repositories/common/ApiKeyRepository.js +0 -45
- package/lib/repositories/common/ApiKeyRepository.js.map +0 -1
- package/lib/repositories/common/ApiKeyRepository.ts +0 -56
- package/lib/validators/common/ApiKeyValidator.d.ts +0 -9
- package/lib/validators/common/ApiKeyValidator.d.ts.map +0 -1
- package/lib/validators/common/ApiKeyValidator.js +0 -57
- package/lib/validators/common/ApiKeyValidator.js.map +0 -1
- package/lib/validators/common/ApiKeyValidator.ts +0 -69
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## 🔖 [4.2.22] (2026-03-26)
|
|
9
|
+
|
|
10
|
+
### 🏗️ Changed
|
|
11
|
+
|
|
12
|
+
- Refactored `MigrationService` to migrate `DashboardUserConfig` records instead of `User.projectAccess` fields; now backfills `enableAdminPage` and `enabledFeatures.adminPage` with safe defaults.
|
|
13
|
+
- Updated dependencies on `@aneuhold/be-ts-lib` to `^3.1.9` and `@aneuhold/core-ts-db-lib` to `^5.0.4`.
|
|
14
|
+
|
|
15
|
+
## 🔖 [4.2.21] (2026-03-20)
|
|
16
|
+
|
|
17
|
+
### 🏗️ Changed
|
|
18
|
+
|
|
19
|
+
- `GoogleAuthService.verifyAndFindUser` and `verifyAndFindOrCreateUser` no longer return `apiKey` in their result.
|
|
20
|
+
- Updated dependencies on `@aneuhold/be-ts-lib` to `^3.1.8` and `@aneuhold/core-ts-db-lib` to `^5.0.3`.
|
|
21
|
+
|
|
22
|
+
### 🔥 Removed
|
|
23
|
+
|
|
24
|
+
- Removed `ApiKeyRepository` class, its tests, and its subscriber registration in `UserRepository`.
|
|
25
|
+
- Removed `ApiKeyValidator` class and its usage in `DbSchemaUpdater`.
|
|
26
|
+
|
|
8
27
|
## 🔖 [4.2.20] (2026-03-19)
|
|
9
28
|
|
|
10
29
|
### ✅ Added
|
|
@@ -359,7 +378,8 @@ Updated dependencies: now requires `@aneuhold/core-ts-db-lib@^3.0.0`, `@aneuhold
|
|
|
359
378
|
- Updated workflow permissions to allow repository write access
|
|
360
379
|
|
|
361
380
|
<!-- Link References -->
|
|
362
|
-
|
|
381
|
+
[4.2.22]: https://github.com/aneuhold/ts-libs/compare/be-ts-db-lib-v4.2.21...be-ts-db-lib-v4.2.22
|
|
382
|
+
[4.2.21]: https://github.com/aneuhold/ts-libs/compare/be-ts-db-lib-v4.2.20...be-ts-db-lib-v4.2.21
|
|
363
383
|
[4.2.20]: https://github.com/aneuhold/ts-libs/compare/be-ts-db-lib-v4.2.19...be-ts-db-lib-v4.2.20
|
|
364
384
|
[4.2.19]: https://github.com/aneuhold/ts-libs/compare/be-ts-db-lib-v4.2.18...be-ts-db-lib-v4.2.19
|
|
365
385
|
[4.2.18]: https://github.com/aneuhold/ts-libs/compare/be-ts-db-lib-v4.2.17...be-ts-db-lib-v4.2.18
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import BaseRepository from './repositories/BaseRepository.js';
|
|
2
|
-
import ApiKeyRepository from './repositories/common/ApiKeyRepository.js';
|
|
3
2
|
import UserRepository from './repositories/common/UserRepository.js';
|
|
4
3
|
import DashboardBaseRepository from './repositories/dashboard/DashboardBaseRepository.js';
|
|
5
4
|
import DashboardBaseWithUserIdRepository from './repositories/dashboard/DashboardBaseWithUserIdRepository.js';
|
|
@@ -21,6 +20,6 @@ import WorkoutSetRepository from './repositories/workout/WorkoutSetRepository.js
|
|
|
21
20
|
import GoogleAuthService from './services/GoogleAuthService.js';
|
|
22
21
|
import DbOperationMetaData from './util/DbOperationMetaData.js';
|
|
23
22
|
import DocumentDb from './util/DocumentDb.js';
|
|
24
|
-
export {
|
|
23
|
+
export { BaseRepository, DashboardBaseRepository, DashboardBaseWithUserIdRepository, DashboardNonogramKatanaItemRepository, DashboardNonogramKatanaUpgradeRepository, DashboardTaskRepository, DashboardUserConfigRepository, DbOperationMetaData, DocumentDb, GoogleAuthService, UserRepository, WorkoutBaseRepository, WorkoutBaseWithUserIdRepository, WorkoutEquipmentTypeRepository, WorkoutExerciseCalibrationRepository, WorkoutExerciseRepository, WorkoutMesocycleRepository, WorkoutMicrocycleRepository, WorkoutMuscleGroupRepository, WorkoutSessionExerciseRepository, WorkoutSessionRepository, WorkoutSetRepository };
|
|
25
24
|
export type {};
|
|
26
25
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAC9D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAC9D,OAAO,cAAc,MAAM,yCAAyC,CAAC;AACrE,OAAO,uBAAuB,MAAM,qDAAqD,CAAC;AAC1F,OAAO,iCAAiC,MAAM,+DAA+D,CAAC;AAC9G,OAAO,qCAAqC,MAAM,mEAAmE,CAAC;AACtH,OAAO,wCAAwC,MAAM,sEAAsE,CAAC;AAC5H,OAAO,uBAAuB,MAAM,qDAAqD,CAAC;AAC1F,OAAO,6BAA6B,MAAM,2DAA2D,CAAC;AACtG,OAAO,qBAAqB,MAAM,iDAAiD,CAAC;AACpF,OAAO,+BAA+B,MAAM,2DAA2D,CAAC;AACxG,OAAO,8BAA8B,MAAM,0DAA0D,CAAC;AACtG,OAAO,oCAAoC,MAAM,gEAAgE,CAAC;AAClH,OAAO,yBAAyB,MAAM,qDAAqD,CAAC;AAC5F,OAAO,0BAA0B,MAAM,sDAAsD,CAAC;AAC9F,OAAO,2BAA2B,MAAM,uDAAuD,CAAC;AAChG,OAAO,4BAA4B,MAAM,wDAAwD,CAAC;AAClG,OAAO,gCAAgC,MAAM,4DAA4D,CAAC;AAC1G,OAAO,wBAAwB,MAAM,oDAAoD,CAAC;AAC1F,OAAO,oBAAoB,MAAM,gDAAgD,CAAC;AAClF,OAAO,iBAAiB,MAAM,iCAAiC,CAAC;AAChE,OAAO,mBAAmB,MAAM,+BAA+B,CAAC;AAChE,OAAO,UAAU,MAAM,sBAAsB,CAAC;AAG9C,OAAO,EACL,cAAc,EACd,uBAAuB,EACvB,iCAAiC,EACjC,qCAAqC,EACrC,wCAAwC,EACxC,uBAAuB,EACvB,6BAA6B,EAC7B,mBAAmB,EACnB,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,+BAA+B,EAC/B,8BAA8B,EAC9B,oCAAoC,EACpC,yBAAyB,EACzB,0BAA0B,EAC1B,2BAA2B,EAC3B,4BAA4B,EAC5B,gCAAgC,EAChC,wBAAwB,EACxB,oBAAoB,EACrB,CAAC;AAGF,YAAY,EAAE,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import BaseRepository from './repositories/BaseRepository.js';
|
|
2
|
-
import ApiKeyRepository from './repositories/common/ApiKeyRepository.js';
|
|
3
2
|
import UserRepository from './repositories/common/UserRepository.js';
|
|
4
3
|
import DashboardBaseRepository from './repositories/dashboard/DashboardBaseRepository.js';
|
|
5
4
|
import DashboardBaseWithUserIdRepository from './repositories/dashboard/DashboardBaseWithUserIdRepository.js';
|
|
@@ -22,5 +21,5 @@ import GoogleAuthService from './services/GoogleAuthService.js';
|
|
|
22
21
|
import DbOperationMetaData from './util/DbOperationMetaData.js';
|
|
23
22
|
import DocumentDb from './util/DocumentDb.js';
|
|
24
23
|
// Export all the functions and classes from this library
|
|
25
|
-
export {
|
|
24
|
+
export { BaseRepository, DashboardBaseRepository, DashboardBaseWithUserIdRepository, DashboardNonogramKatanaItemRepository, DashboardNonogramKatanaUpgradeRepository, DashboardTaskRepository, DashboardUserConfigRepository, DbOperationMetaData, DocumentDb, GoogleAuthService, UserRepository, WorkoutBaseRepository, WorkoutBaseWithUserIdRepository, WorkoutEquipmentTypeRepository, WorkoutExerciseCalibrationRepository, WorkoutExerciseRepository, WorkoutMesocycleRepository, WorkoutMicrocycleRepository, WorkoutMuscleGroupRepository, WorkoutSessionExerciseRepository, WorkoutSessionRepository, WorkoutSetRepository };
|
|
26
25
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAC9D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAC9D,OAAO,cAAc,MAAM,yCAAyC,CAAC;AACrE,OAAO,uBAAuB,MAAM,qDAAqD,CAAC;AAC1F,OAAO,iCAAiC,MAAM,+DAA+D,CAAC;AAC9G,OAAO,qCAAqC,MAAM,mEAAmE,CAAC;AACtH,OAAO,wCAAwC,MAAM,sEAAsE,CAAC;AAC5H,OAAO,uBAAuB,MAAM,qDAAqD,CAAC;AAC1F,OAAO,6BAA6B,MAAM,2DAA2D,CAAC;AACtG,OAAO,qBAAqB,MAAM,iDAAiD,CAAC;AACpF,OAAO,+BAA+B,MAAM,2DAA2D,CAAC;AACxG,OAAO,8BAA8B,MAAM,0DAA0D,CAAC;AACtG,OAAO,oCAAoC,MAAM,gEAAgE,CAAC;AAClH,OAAO,yBAAyB,MAAM,qDAAqD,CAAC;AAC5F,OAAO,0BAA0B,MAAM,sDAAsD,CAAC;AAC9F,OAAO,2BAA2B,MAAM,uDAAuD,CAAC;AAChG,OAAO,4BAA4B,MAAM,wDAAwD,CAAC;AAClG,OAAO,gCAAgC,MAAM,4DAA4D,CAAC;AAC1G,OAAO,wBAAwB,MAAM,oDAAoD,CAAC;AAC1F,OAAO,oBAAoB,MAAM,gDAAgD,CAAC;AAClF,OAAO,iBAAiB,MAAM,iCAAiC,CAAC;AAChE,OAAO,mBAAmB,MAAM,+BAA+B,CAAC;AAChE,OAAO,UAAU,MAAM,sBAAsB,CAAC;AAE9C,yDAAyD;AACzD,OAAO,EACL,cAAc,EACd,uBAAuB,EACvB,iCAAiC,EACjC,qCAAqC,EACrC,wCAAwC,EACxC,uBAAuB,EACvB,6BAA6B,EAC7B,mBAAmB,EACnB,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,+BAA+B,EAC/B,8BAA8B,EAC9B,oCAAoC,EACpC,yBAAyB,EACzB,0BAA0B,EAC1B,2BAA2B,EAC3B,4BAA4B,EAC5B,gCAAgC,EAChC,wBAAwB,EACxB,oBAAoB,EACrB,CAAC"}
|
package/lib/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import BaseRepository from './repositories/BaseRepository.js';
|
|
2
|
-
import ApiKeyRepository from './repositories/common/ApiKeyRepository.js';
|
|
3
2
|
import UserRepository from './repositories/common/UserRepository.js';
|
|
4
3
|
import DashboardBaseRepository from './repositories/dashboard/DashboardBaseRepository.js';
|
|
5
4
|
import DashboardBaseWithUserIdRepository from './repositories/dashboard/DashboardBaseWithUserIdRepository.js';
|
|
@@ -24,7 +23,6 @@ import DocumentDb from './util/DocumentDb.js';
|
|
|
24
23
|
|
|
25
24
|
// Export all the functions and classes from this library
|
|
26
25
|
export {
|
|
27
|
-
ApiKeyRepository,
|
|
28
26
|
BaseRepository,
|
|
29
27
|
DashboardBaseRepository,
|
|
30
28
|
DashboardBaseWithUserIdRepository,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserRepository.d.ts","sourceRoot":"","sources":["../../../src/repositories/common/UserRepository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC,OAAO,cAAc,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"UserRepository.d.ts","sourceRoot":"","sources":["../../../src/repositories/common/UserRepository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC,OAAO,cAAc,MAAM,sBAAsB,CAAC;AAWlD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,cAAc,CAAC,IAAI,CAAC;IAC9D,OAAO,CAAC,MAAM,CAAC,eAAe,CAAW;IAEzC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAA6B;IAE7D,OAAO;IAIP,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAalC;;OAEG;IACH,MAAM,CAAC,OAAO,IAAI,cAAc;IAO1B,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAWrE;;;;OAIG;IACG,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAQlE,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CAO5D"}
|
|
@@ -10,7 +10,6 @@ import WorkoutExerciseRepository from '../workout/WorkoutExerciseRepository.js';
|
|
|
10
10
|
import WorkoutMesocycleRepository from '../workout/WorkoutMesocycleRepository.js';
|
|
11
11
|
import WorkoutMicrocycleRepository from '../workout/WorkoutMicrocycleRepository.js';
|
|
12
12
|
import WorkoutMuscleGroupRepository from '../workout/WorkoutMuscleGroupRepository.js';
|
|
13
|
-
import ApiKeyRepository from './ApiKeyRepository.js';
|
|
14
13
|
/**
|
|
15
14
|
* The repository that contains {@link User} documents.
|
|
16
15
|
*/
|
|
@@ -21,7 +20,6 @@ export default class UserRepository extends BaseRepository {
|
|
|
21
20
|
super(UserRepository.COLLECTION_NAME, new UserValidator());
|
|
22
21
|
}
|
|
23
22
|
setupSubscribers() {
|
|
24
|
-
this.subscribeToChanges(ApiKeyRepository.getListenersForUserRepo());
|
|
25
23
|
this.subscribeToChanges(DashboardUserConfigRepository.getListenersForUserRepo());
|
|
26
24
|
this.subscribeToChanges(DashboardTaskRepository.getListenersForUserRepo());
|
|
27
25
|
this.subscribeToChanges(DashboardNonogramKatanaItemRepository.getListenersForUserRepo());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserRepository.js","sourceRoot":"","sources":["../../../src/repositories/common/UserRepository.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,MAAM,0CAA0C,CAAC;AACrE,OAAO,cAAc,MAAM,sBAAsB,CAAC;AAClD,OAAO,qCAAqC,MAAM,uDAAuD,CAAC;AAC1G,OAAO,wCAAwC,MAAM,0DAA0D,CAAC;AAChH,OAAO,uBAAuB,MAAM,yCAAyC,CAAC;AAC9E,OAAO,6BAA6B,MAAM,+CAA+C,CAAC;AAC1F,OAAO,8BAA8B,MAAM,8CAA8C,CAAC;AAC1F,OAAO,oCAAoC,MAAM,oDAAoD,CAAC;AACtG,OAAO,yBAAyB,MAAM,yCAAyC,CAAC;AAChF,OAAO,0BAA0B,MAAM,0CAA0C,CAAC;AAClF,OAAO,2BAA2B,MAAM,2CAA2C,CAAC;AACpF,OAAO,4BAA4B,MAAM,4CAA4C,CAAC;AACtF
|
|
1
|
+
{"version":3,"file":"UserRepository.js","sourceRoot":"","sources":["../../../src/repositories/common/UserRepository.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,MAAM,0CAA0C,CAAC;AACrE,OAAO,cAAc,MAAM,sBAAsB,CAAC;AAClD,OAAO,qCAAqC,MAAM,uDAAuD,CAAC;AAC1G,OAAO,wCAAwC,MAAM,0DAA0D,CAAC;AAChH,OAAO,uBAAuB,MAAM,yCAAyC,CAAC;AAC9E,OAAO,6BAA6B,MAAM,+CAA+C,CAAC;AAC1F,OAAO,8BAA8B,MAAM,8CAA8C,CAAC;AAC1F,OAAO,oCAAoC,MAAM,oDAAoD,CAAC;AACtG,OAAO,yBAAyB,MAAM,yCAAyC,CAAC;AAChF,OAAO,0BAA0B,MAAM,0CAA0C,CAAC;AAClF,OAAO,2BAA2B,MAAM,2CAA2C,CAAC;AACpF,OAAO,4BAA4B,MAAM,4CAA4C,CAAC;AACtF;;GAEG;AACH,MA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AAI,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC1C,IAAI,IAAI,EAAE,CAAC;YACT,OAAO;gBACL,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,GAAG,EAAE,IAAI,CAAC,GAAG;aACd,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,yBAAyB,CAAC,SAAiB;QAC/C,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;YACtC,mCAAmC,EAAE,SAAS;SAC/C,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,OAAe;QACpC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC1C,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,GAAG,EAAE,IAAI,CAAC,GAAG;SACd,CAAC,CAAC,CAAC;IACN,CAAC"}
|
|
@@ -12,8 +12,6 @@ import WorkoutExerciseRepository from '../workout/WorkoutExerciseRepository.js';
|
|
|
12
12
|
import WorkoutMesocycleRepository from '../workout/WorkoutMesocycleRepository.js';
|
|
13
13
|
import WorkoutMicrocycleRepository from '../workout/WorkoutMicrocycleRepository.js';
|
|
14
14
|
import WorkoutMuscleGroupRepository from '../workout/WorkoutMuscleGroupRepository.js';
|
|
15
|
-
import ApiKeyRepository from './ApiKeyRepository.js';
|
|
16
|
-
|
|
17
15
|
/**
|
|
18
16
|
* The repository that contains {@link User} documents.
|
|
19
17
|
*/
|
|
@@ -27,7 +25,6 @@ export default class UserRepository extends BaseRepository<User> {
|
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
protected setupSubscribers(): void {
|
|
30
|
-
this.subscribeToChanges(ApiKeyRepository.getListenersForUserRepo());
|
|
31
28
|
this.subscribeToChanges(DashboardUserConfigRepository.getListenersForUserRepo());
|
|
32
29
|
this.subscribeToChanges(DashboardTaskRepository.getListenersForUserRepo());
|
|
33
30
|
this.subscribeToChanges(DashboardNonogramKatanaItemRepository.getListenersForUserRepo());
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { User } from '@aneuhold/core-ts-db-lib';
|
|
2
2
|
/**
|
|
3
3
|
* Service for verifying Google ID tokens and finding or creating users.
|
|
4
4
|
* Handles account linking by email when a matching user exists without a
|
|
@@ -14,7 +14,6 @@ export default class GoogleAuthService {
|
|
|
14
14
|
*/
|
|
15
15
|
static verifyAndFindUser(googleCredentialToken: string): Promise<{
|
|
16
16
|
user: User;
|
|
17
|
-
apiKey: ApiKey;
|
|
18
17
|
} | null>;
|
|
19
18
|
/**
|
|
20
19
|
* Verifies a Google ID token and finds or creates the associated user.
|
|
@@ -23,7 +22,6 @@ export default class GoogleAuthService {
|
|
|
23
22
|
*/
|
|
24
23
|
static verifyAndFindOrCreateUser(googleCredentialToken: string): Promise<{
|
|
25
24
|
user: User;
|
|
26
|
-
apiKey: ApiKey;
|
|
27
25
|
}>;
|
|
28
26
|
/**
|
|
29
27
|
* Verifies a Google ID token and returns the Google ID and email.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GoogleAuthService.d.ts","sourceRoot":"","sources":["../../src/services/GoogleAuthService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"GoogleAuthService.d.ts","sourceRoot":"","sources":["../../src/services/GoogleAuthService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAKrD;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAsC;IAEpE;;;;;OAKG;WACU,iBAAiB,CAAC,qBAAqB,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;IAyB7F;;;;OAIG;WACU,yBAAyB,CAAC,qBAAqB,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC;IAwB9F;;;;OAIG;mBACkB,WAAW;CAmBjC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { GOOGLE_CLIENT_ID, ProjectName, UserSchema } from '@aneuhold/core-ts-db-lib';
|
|
2
2
|
import { OAuth2Client } from 'google-auth-library';
|
|
3
|
-
import ApiKeyRepository from '../repositories/common/ApiKeyRepository.js';
|
|
4
3
|
import UserRepository from '../repositories/common/UserRepository.js';
|
|
5
4
|
/**
|
|
6
5
|
* Service for verifying Google ID tokens and finding or creating users.
|
|
@@ -18,7 +17,6 @@ export default class GoogleAuthService {
|
|
|
18
17
|
static async verifyAndFindUser(googleCredentialToken) {
|
|
19
18
|
const { googleId, email } = await this.verifyToken(googleCredentialToken);
|
|
20
19
|
const userRepo = UserRepository.getRepo();
|
|
21
|
-
const apiKeyRepo = ApiKeyRepository.getRepo();
|
|
22
20
|
// 1. Look up by googleId
|
|
23
21
|
let user = await userRepo.get({ auth: { googleId } });
|
|
24
22
|
// 2. Fall back to email lookup (account linking)
|
|
@@ -33,11 +31,7 @@ export default class GoogleAuthService {
|
|
|
33
31
|
if (!user) {
|
|
34
32
|
return null;
|
|
35
33
|
}
|
|
36
|
-
|
|
37
|
-
if (!apiKey) {
|
|
38
|
-
throw new Error(`No API key found for user ${user._id}`);
|
|
39
|
-
}
|
|
40
|
-
return { user, apiKey };
|
|
34
|
+
return { user };
|
|
41
35
|
}
|
|
42
36
|
/**
|
|
43
37
|
* Verifies a Google ID token and finds or creates the associated user.
|
|
@@ -49,11 +43,9 @@ export default class GoogleAuthService {
|
|
|
49
43
|
if (result) {
|
|
50
44
|
return result;
|
|
51
45
|
}
|
|
52
|
-
// Create new user.
|
|
53
|
-
// creates an API key on user insertion.
|
|
46
|
+
// Create new user.
|
|
54
47
|
const { googleId, email } = await this.verifyToken(googleCredentialToken);
|
|
55
48
|
const userRepo = UserRepository.getRepo();
|
|
56
|
-
const apiKeyRepo = ApiKeyRepository.getRepo();
|
|
57
49
|
const newUser = UserSchema.parse({
|
|
58
50
|
userName: email,
|
|
59
51
|
email,
|
|
@@ -64,11 +56,7 @@ export default class GoogleAuthService {
|
|
|
64
56
|
if (!insertedUser) {
|
|
65
57
|
throw new Error('Failed to create user');
|
|
66
58
|
}
|
|
67
|
-
|
|
68
|
-
if (!apiKey) {
|
|
69
|
-
throw new Error(`No API key found for user ${insertedUser._id}`);
|
|
70
|
-
}
|
|
71
|
-
return { user: insertedUser, apiKey };
|
|
59
|
+
return { user: insertedUser };
|
|
72
60
|
}
|
|
73
61
|
/**
|
|
74
62
|
* Verifies a Google ID token and returns the Google ID and email.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GoogleAuthService.js","sourceRoot":"","sources":["../../src/services/GoogleAuthService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,
|
|
1
|
+
{"version":3,"file":"GoogleAuthService.js","sourceRoot":"","sources":["../../src/services/GoogleAuthService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,cAAc,MAAM,0CAA0C,CAAC;AAEtE;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IAC5B,MAAM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{ User } from '@aneuhold/core-ts-db-lib';
|
|
2
2
|
import { GOOGLE_CLIENT_ID, ProjectName, UserSchema } from '@aneuhold/core-ts-db-lib';
|
|
3
3
|
import { OAuth2Client } from 'google-auth-library';
|
|
4
|
-
import ApiKeyRepository from '../repositories/common/ApiKeyRepository.js';
|
|
5
4
|
import UserRepository from '../repositories/common/UserRepository.js';
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -18,13 +17,10 @@ export default class GoogleAuthService {
|
|
|
18
17
|
*
|
|
19
18
|
* @param googleCredentialToken - The Google ID token string from the client.
|
|
20
19
|
*/
|
|
21
|
-
static async verifyAndFindUser(
|
|
22
|
-
googleCredentialToken: string
|
|
23
|
-
): Promise<{ user: User; apiKey: ApiKey } | null> {
|
|
20
|
+
static async verifyAndFindUser(googleCredentialToken: string): Promise<{ user: User } | null> {
|
|
24
21
|
const { googleId, email } = await this.verifyToken(googleCredentialToken);
|
|
25
22
|
|
|
26
23
|
const userRepo = UserRepository.getRepo();
|
|
27
|
-
const apiKeyRepo = ApiKeyRepository.getRepo();
|
|
28
24
|
|
|
29
25
|
// 1. Look up by googleId
|
|
30
26
|
let user = await userRepo.get({ auth: { googleId } });
|
|
@@ -43,12 +39,7 @@ export default class GoogleAuthService {
|
|
|
43
39
|
return null;
|
|
44
40
|
}
|
|
45
41
|
|
|
46
|
-
|
|
47
|
-
if (!apiKey) {
|
|
48
|
-
throw new Error(`No API key found for user ${user._id}`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return { user, apiKey };
|
|
42
|
+
return { user };
|
|
52
43
|
}
|
|
53
44
|
|
|
54
45
|
/**
|
|
@@ -56,19 +47,15 @@ export default class GoogleAuthService {
|
|
|
56
47
|
*
|
|
57
48
|
* @param googleCredentialToken - The Google ID token string from the client.
|
|
58
49
|
*/
|
|
59
|
-
static async verifyAndFindOrCreateUser(
|
|
60
|
-
googleCredentialToken: string
|
|
61
|
-
): Promise<{ user: User; apiKey: ApiKey }> {
|
|
50
|
+
static async verifyAndFindOrCreateUser(googleCredentialToken: string): Promise<{ user: User }> {
|
|
62
51
|
const result = await this.verifyAndFindUser(googleCredentialToken);
|
|
63
52
|
if (result) {
|
|
64
53
|
return result;
|
|
65
54
|
}
|
|
66
55
|
|
|
67
|
-
// Create new user.
|
|
68
|
-
// creates an API key on user insertion.
|
|
56
|
+
// Create new user.
|
|
69
57
|
const { googleId, email } = await this.verifyToken(googleCredentialToken);
|
|
70
58
|
const userRepo = UserRepository.getRepo();
|
|
71
|
-
const apiKeyRepo = ApiKeyRepository.getRepo();
|
|
72
59
|
|
|
73
60
|
const newUser = UserSchema.parse({
|
|
74
61
|
userName: email,
|
|
@@ -81,12 +68,7 @@ export default class GoogleAuthService {
|
|
|
81
68
|
throw new Error('Failed to create user');
|
|
82
69
|
}
|
|
83
70
|
|
|
84
|
-
|
|
85
|
-
if (!apiKey) {
|
|
86
|
-
throw new Error(`No API key found for user ${insertedUser._id}`);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return { user: insertedUser, apiKey };
|
|
71
|
+
return { user: insertedUser };
|
|
90
72
|
}
|
|
91
73
|
|
|
92
74
|
/**
|
|
@@ -16,5 +16,10 @@ export default class MigrationService {
|
|
|
16
16
|
* @param dryRun Whether or not to actually make the changes or just log them.
|
|
17
17
|
*/
|
|
18
18
|
static migrateDb(dryRun?: boolean): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Migrates dashboard user configs that are missing enableAdminPage
|
|
21
|
+
* or the adminPage feature flag.
|
|
22
|
+
*/
|
|
23
|
+
private static migrateUserConfigs;
|
|
19
24
|
}
|
|
20
25
|
//# sourceMappingURL=MigrationService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MigrationService.d.ts","sourceRoot":"","sources":["../../src/services/MigrationService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MigrationService.d.ts","sourceRoot":"","sources":["../../src/services/MigrationService.ts"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC;;;;;;;;OAQG;WACU,SAAS,CAAC,MAAM,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAQrD;;;OAGG;mBACkB,kBAAkB;CAwExC"}
|
|
@@ -2,14 +2,19 @@
|
|
|
2
2
|
// @ts-nocheck
|
|
3
3
|
import { DR } from '@aneuhold/core-ts-lib';
|
|
4
4
|
import UserRepository from '../repositories/common/UserRepository.js';
|
|
5
|
+
import DashboardUserConfigRepository from '../repositories/dashboard/DashboardUserConfigRepository.js';
|
|
5
6
|
/**
|
|
6
|
-
* The default values for
|
|
7
|
-
* added here and defaulted to `false
|
|
8
|
-
* automatically.
|
|
7
|
+
* The default values for enabledFeatures. New feature flags should be
|
|
8
|
+
* added here and defaulted to `false`.
|
|
9
9
|
*/
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const ENABLED_FEATURES_DEFAULTS = {
|
|
11
|
+
financePage: false,
|
|
12
|
+
automationPage: false,
|
|
13
|
+
entertainmentPage: false,
|
|
14
|
+
homePageLinks: false,
|
|
15
|
+
useConfettiForTasks: false,
|
|
16
|
+
catImageOnHomePage: false,
|
|
17
|
+
adminPage: false
|
|
13
18
|
};
|
|
14
19
|
/**
|
|
15
20
|
* A service for migrating the DB to a new state after an existing document
|
|
@@ -29,40 +34,63 @@ export default class MigrationService {
|
|
|
29
34
|
* @param dryRun Whether or not to actually make the changes or just log them.
|
|
30
35
|
*/
|
|
31
36
|
static async migrateDb(dryRun = false) {
|
|
32
|
-
DR.logger.info(
|
|
37
|
+
DR.logger.info(`Starting migration... (dryRun=${dryRun})`);
|
|
38
|
+
await this.migrateUserConfigs(dryRun);
|
|
39
|
+
DR.logger.success('Migration complete.');
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Migrates dashboard user configs that are missing enableAdminPage
|
|
43
|
+
* or the adminPage feature flag.
|
|
44
|
+
*/
|
|
45
|
+
static async migrateUserConfigs(dryRun) {
|
|
46
|
+
const configRepo = DashboardUserConfigRepository.getRepo();
|
|
47
|
+
const allConfigs = await configRepo.getAll();
|
|
48
|
+
// Build a userId -> userName lookup
|
|
33
49
|
const userRepo = UserRepository.getRepo();
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
//
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
const allUsers = await userRepo.getAll();
|
|
51
|
+
const userNameMap = new Map(allUsers.map((u) => [u._id, u.userName]));
|
|
52
|
+
// Build all updates in memory first, tracking only changed fields
|
|
53
|
+
const updates = [];
|
|
54
|
+
for (const config of allConfigs) {
|
|
55
|
+
const changes = [];
|
|
56
|
+
const updateDoc = { _id: config._id };
|
|
57
|
+
if (config.enableAdminPage === undefined) {
|
|
58
|
+
changes.push('enableAdminPage: undefined → false');
|
|
59
|
+
updateDoc.enableAdminPage = false;
|
|
60
|
+
}
|
|
61
|
+
const existingFeatures = config.enabledFeatures ?? {};
|
|
62
|
+
if (!existingFeatures || existingFeatures.adminPage === undefined) {
|
|
63
|
+
changes.push('enabledFeatures.adminPage: undefined → false');
|
|
64
|
+
updateDoc.enabledFeatures = { ...ENABLED_FEATURES_DEFAULTS, ...existingFeatures };
|
|
65
|
+
}
|
|
66
|
+
if (changes.length === 0) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const userName = userNameMap.get(config.userId) ?? 'unknown';
|
|
70
|
+
updates.push({ configId: config._id, userName, changes, updateDoc });
|
|
71
|
+
}
|
|
72
|
+
DR.logger.info(`Found ${updates.length} of ${allConfigs.length} user configs needing admin page fields.`);
|
|
73
|
+
if (updates.length === 0) {
|
|
74
|
+
DR.logger.success('No user config migration needed.');
|
|
45
75
|
return;
|
|
46
76
|
}
|
|
77
|
+
// Log exactly what will change
|
|
78
|
+
for (const update of updates) {
|
|
79
|
+
DR.logger.info(` ${update.userName} (${update.configId}):`);
|
|
80
|
+
for (const change of update.changes) {
|
|
81
|
+
DR.logger.info(` ${change}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
47
84
|
if (dryRun) {
|
|
48
|
-
DR.logger.info(
|
|
49
|
-
usersToUpdate.forEach((user) => {
|
|
50
|
-
const existing = user.projectAccess ?? {};
|
|
51
|
-
const merged = { ...PROJECT_ACCESS_DEFAULTS, ...existing };
|
|
52
|
-
DR.logger.info(` - ${user.userName} (${user._id}): ${JSON.stringify(existing)} → ${JSON.stringify(merged)}`);
|
|
53
|
-
});
|
|
85
|
+
DR.logger.info(`Dry run complete. ${updates.length} configs would be updated.`);
|
|
54
86
|
return;
|
|
55
87
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
_id: user._id,
|
|
61
|
-
projectAccess: merged
|
|
62
|
-
});
|
|
63
|
-
DR.logger.info(`Updated user ${user.userName} (${user._id}): ${JSON.stringify(existing)} → ${JSON.stringify(merged)}`);
|
|
88
|
+
// Execute updates
|
|
89
|
+
for (const update of updates) {
|
|
90
|
+
await configRepo.update(update.updateDoc);
|
|
91
|
+
DR.logger.info(`Updated config for ${update.userName} (${update.configId})`);
|
|
64
92
|
}
|
|
65
|
-
DR.logger.success(`
|
|
93
|
+
DR.logger.success(`User config migration complete. Updated ${updates.length} configs.`);
|
|
66
94
|
}
|
|
67
95
|
}
|
|
68
96
|
//# sourceMappingURL=MigrationService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MigrationService.js","sourceRoot":"","sources":["../../src/services/MigrationService.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,cAAc;AACd,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,cAAc,MAAM,0CAA0C,CAAC;
|
|
1
|
+
{"version":3,"file":"MigrationService.js","sourceRoot":"","sources":["../../src/services/MigrationService.ts"],"names":[],"mappings":"AAAA,oBAAo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AO,EAAE,CAAC;YAC7B,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,QAAQ,KAAK,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC;YAC7D,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,MAAM,EAAE,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;QAED,IAAI,MAAM,EAAE,CAAC;YACX,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,OAAO,CAAC,MAAM,4BAA4B,CAAC,CAAC;YAChF,OAAO;QACT,CAAC;QAED,kBAAkB;QAClB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YAC1C,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,sBAAsB,MAAM,CAAC,QAAQ,KAAK,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC;QAC/E,CAAC;QAED,EAAE,CAAC,MAAM,CAAC,OAAO,CACf,2CAA2C,OAAO,CAAC,MAAM,WAAW,CACrE,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
// @ts-nocheck
|
|
3
3
|
import { DR } from '@aneuhold/core-ts-lib';
|
|
4
4
|
import UserRepository from '../repositories/common/UserRepository.js';
|
|
5
|
+
import DashboardUserConfigRepository from '../repositories/dashboard/DashboardUserConfigRepository.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
* The default values for
|
|
8
|
-
* added here and defaulted to `false
|
|
9
|
-
* automatically.
|
|
8
|
+
* The default values for enabledFeatures. New feature flags should be
|
|
9
|
+
* added here and defaulted to `false`.
|
|
10
10
|
*/
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const ENABLED_FEATURES_DEFAULTS = {
|
|
12
|
+
financePage: false,
|
|
13
|
+
automationPage: false,
|
|
14
|
+
entertainmentPage: false,
|
|
15
|
+
homePageLinks: false,
|
|
16
|
+
useConfettiForTasks: false,
|
|
17
|
+
catImageOnHomePage: false,
|
|
18
|
+
adminPage: false
|
|
14
19
|
};
|
|
15
20
|
|
|
16
21
|
/**
|
|
@@ -31,53 +36,87 @@ export default class MigrationService {
|
|
|
31
36
|
* @param dryRun Whether or not to actually make the changes or just log them.
|
|
32
37
|
*/
|
|
33
38
|
static async migrateDb(dryRun = false): Promise<void> {
|
|
34
|
-
DR.logger.info(
|
|
39
|
+
DR.logger.info(`Starting migration... (dryRun=${dryRun})`);
|
|
35
40
|
|
|
41
|
+
await this.migrateUserConfigs(dryRun);
|
|
42
|
+
|
|
43
|
+
DR.logger.success('Migration complete.');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Migrates dashboard user configs that are missing enableAdminPage
|
|
48
|
+
* or the adminPage feature flag.
|
|
49
|
+
*/
|
|
50
|
+
private static async migrateUserConfigs(dryRun: boolean): Promise<void> {
|
|
51
|
+
const configRepo = DashboardUserConfigRepository.getRepo();
|
|
52
|
+
const allConfigs = await configRepo.getAll();
|
|
53
|
+
|
|
54
|
+
// Build a userId -> userName lookup
|
|
36
55
|
const userRepo = UserRepository.getRepo();
|
|
37
|
-
const
|
|
56
|
+
const allUsers = await userRepo.getAll();
|
|
57
|
+
const userNameMap = new Map(allUsers.map((u) => [u._id, u.userName]));
|
|
58
|
+
|
|
59
|
+
// Build all updates in memory first, tracking only changed fields
|
|
60
|
+
const updates: Array<{
|
|
61
|
+
configId: string;
|
|
62
|
+
userName: string;
|
|
63
|
+
changes: string[];
|
|
64
|
+
updateDoc: Record<string, unknown>;
|
|
65
|
+
}> = [];
|
|
66
|
+
|
|
67
|
+
for (const config of allConfigs) {
|
|
68
|
+
const changes: string[] = [];
|
|
69
|
+
const updateDoc: Record<string, unknown> = { _id: config._id };
|
|
38
70
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
)
|
|
46
|
-
|
|
71
|
+
if (config.enableAdminPage === undefined) {
|
|
72
|
+
changes.push('enableAdminPage: undefined → false');
|
|
73
|
+
updateDoc.enableAdminPage = false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const existingFeatures = config.enabledFeatures ?? {};
|
|
77
|
+
if (!existingFeatures || existingFeatures.adminPage === undefined) {
|
|
78
|
+
changes.push('enabledFeatures.adminPage: undefined → false');
|
|
79
|
+
updateDoc.enabledFeatures = { ...ENABLED_FEATURES_DEFAULTS, ...existingFeatures };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (changes.length === 0) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const userName = userNameMap.get(config.userId) ?? 'unknown';
|
|
87
|
+
updates.push({ configId: config._id, userName, changes, updateDoc });
|
|
88
|
+
}
|
|
47
89
|
|
|
48
90
|
DR.logger.info(
|
|
49
|
-
`Found ${
|
|
91
|
+
`Found ${updates.length} of ${allConfigs.length} user configs needing admin page fields.`
|
|
50
92
|
);
|
|
51
93
|
|
|
52
|
-
if (
|
|
53
|
-
DR.logger.success('No migration needed.');
|
|
94
|
+
if (updates.length === 0) {
|
|
95
|
+
DR.logger.success('No user config migration needed.');
|
|
54
96
|
return;
|
|
55
97
|
}
|
|
56
98
|
|
|
99
|
+
// Log exactly what will change
|
|
100
|
+
for (const update of updates) {
|
|
101
|
+
DR.logger.info(` ${update.userName} (${update.configId}):`);
|
|
102
|
+
for (const change of update.changes) {
|
|
103
|
+
DR.logger.info(` ${change}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
57
107
|
if (dryRun) {
|
|
58
|
-
DR.logger.info(
|
|
59
|
-
usersToUpdate.forEach((user) => {
|
|
60
|
-
const existing = user.projectAccess ?? {};
|
|
61
|
-
const merged = { ...PROJECT_ACCESS_DEFAULTS, ...existing };
|
|
62
|
-
DR.logger.info(
|
|
63
|
-
` - ${user.userName} (${user._id}): ${JSON.stringify(existing)} → ${JSON.stringify(merged)}`
|
|
64
|
-
);
|
|
65
|
-
});
|
|
108
|
+
DR.logger.info(`Dry run complete. ${updates.length} configs would be updated.`);
|
|
66
109
|
return;
|
|
67
110
|
}
|
|
68
111
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
_id: user._id,
|
|
74
|
-
projectAccess: merged
|
|
75
|
-
});
|
|
76
|
-
DR.logger.info(
|
|
77
|
-
`Updated user ${user.userName} (${user._id}): ${JSON.stringify(existing)} → ${JSON.stringify(merged)}`
|
|
78
|
-
);
|
|
112
|
+
// Execute updates
|
|
113
|
+
for (const update of updates) {
|
|
114
|
+
await configRepo.update(update.updateDoc);
|
|
115
|
+
DR.logger.info(`Updated config for ${update.userName} (${update.configId})`);
|
|
79
116
|
}
|
|
80
117
|
|
|
81
|
-
DR.logger.success(
|
|
118
|
+
DR.logger.success(
|
|
119
|
+
`User config migration complete. Updated ${updates.length} configs.`
|
|
120
|
+
);
|
|
82
121
|
}
|
|
83
122
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DbSchemaUpdater.d.ts","sourceRoot":"","sources":["../../src/util/DbSchemaUpdater.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DbSchemaUpdater.d.ts","sourceRoot":"","sources":["../../src/util/DbSchemaUpdater.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;WACrB,uBAAuB,CAAC,MAAM,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAqBpE"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import ApiKeyValidator from '../validators/common/ApiKeyValidator.js';
|
|
2
1
|
import UserValidator from '../validators/common/UserValidator.js';
|
|
3
2
|
import DashboardNonogramKatanaItemValidator from '../validators/dashboard/NonogramKatanaItemValidator.js';
|
|
4
3
|
import DashboardNonogramKatanaUpgradeValidator from '../validators/dashboard/NonogramKatanaUpgradeValidator.js';
|
|
@@ -20,7 +19,6 @@ export default class DbSchemaUpdater {
|
|
|
20
19
|
static async updateSchemaForAllRepos(dryRun = false) {
|
|
21
20
|
// Common validators
|
|
22
21
|
await new UserValidator().validateRepositoryInDb(dryRun);
|
|
23
|
-
await new ApiKeyValidator().validateRepositoryInDb(dryRun);
|
|
24
22
|
// Dashboard validators
|
|
25
23
|
await new DashboardUserConfigValidator().validateRepositoryInDb(dryRun);
|
|
26
24
|
await new DashboardTaskValidator().validateRepositoryInDb(dryRun);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DbSchemaUpdater.js","sourceRoot":"","sources":["../../src/util/DbSchemaUpdater.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"DbSchemaUpdater.js","sourceRoot":"","sources":["../../src/util/DbSchemaUpdater.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,oCAAoC,MAAM,wDAAwD,CAAC;AAC1G,OAAO,uCAAuC,MAAM,2DAA2D,CAAC;AAChH,OAAO,sBAAsB,MAAM,0CAA0C,CAAC;AAC9E,OAAO,4BAA4B,MAAM,gDAAgD,CAAC;AAC1F,OAAO,6BAA6B,MAAM,iDAAiD,CAAC;AAC5F,OAAO,mCAAmC,MAAM,uDAAuD,CAAC;AACxG,OAAO,wBAAwB,MAAM,4CAA4C,CAAC;AAClF,OAAO,yBAAyB,MAAM,6CAA6C,CAAC;AACpF,OAAO,0BAA0B,MAAM,8CAA8C,CAAC;AACtF,OAAO,2BAA2B,MAAM,+CAA+C,CAAC;AACxF,OAAO,+BAA+B,MAAM,mDAAmD,CAAC;AAChG,OAAO,uBAAuB,MAAM,2CAA2C,CAAC;AAChF,OAAO,mBAAmB,MAAM,uCAAuC,CAAC;AAExE;;GAEG;AACH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
2
1
|
import UserValidator from '../validators/common/UserValidator.js';
|
|
3
2
|
import DashboardNonogramKatanaItemValidator from '../validators/dashboard/NonogramKatanaItemValidator.js';
|
|
4
3
|
import DashboardNonogramKatanaUpgradeValidator from '../validators/dashboard/NonogramKatanaUpgradeValidator.js';
|
|
@@ -21,7 +20,6 @@ export default class DbSchemaUpdater {
|
|
|
21
20
|
static async updateSchemaForAllRepos(dryRun = false): Promise<void> {
|
|
22
21
|
// Common validators
|
|
23
22
|
await new UserValidator().validateRepositoryInDb(dryRun);
|
|
24
|
-
await new ApiKeyValidator().validateRepositoryInDb(dryRun);
|
|
25
23
|
|
|
26
24
|
// Dashboard validators
|
|
27
25
|
await new DashboardUserConfigValidator().validateRepositoryInDb(dryRun);
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@aneuhold/be-ts-db-lib",
|
|
3
3
|
"author": "Anton G. Neuhold Jr.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "4.2.
|
|
5
|
+
"version": "4.2.22",
|
|
6
6
|
"description": "A backend database library meant to actually interact with various databases in personal projects",
|
|
7
7
|
"packageManager": "pnpm@10.25.0",
|
|
8
8
|
"type": "module",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"MongoDB"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@aneuhold/be-ts-lib": "^3.1.
|
|
62
|
-
"@aneuhold/core-ts-db-lib": "^5.0.
|
|
61
|
+
"@aneuhold/be-ts-lib": "^3.1.9",
|
|
62
|
+
"@aneuhold/core-ts-db-lib": "^5.0.4",
|
|
63
63
|
"@aneuhold/core-ts-lib": "^2.4.3",
|
|
64
64
|
"bson": "^7.0.0",
|
|
65
65
|
"google-auth-library": "^10.6.1",
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ApiKey, User } from '@aneuhold/core-ts-db-lib';
|
|
2
|
-
import type { RepoListeners } from '../../services/RepoSubscriptionService.js';
|
|
3
|
-
import BaseRepository from '../BaseRepository.js';
|
|
4
|
-
/**
|
|
5
|
-
* The repository that contains {@link ApiKey} documents.
|
|
6
|
-
*/
|
|
7
|
-
export default class ApiKeyRepository extends BaseRepository<ApiKey> {
|
|
8
|
-
private static COLLECTION_NAME;
|
|
9
|
-
private static singletonInstance;
|
|
10
|
-
static getListenersForUserRepo(): RepoListeners<User>;
|
|
11
|
-
private constructor();
|
|
12
|
-
protected setupSubscribers(): void;
|
|
13
|
-
/**
|
|
14
|
-
* Gets the singleton instance of the {@link ApiKeyRepository}.
|
|
15
|
-
*/
|
|
16
|
-
static getRepo(): ApiKeyRepository;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=ApiKeyRepository.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ApiKeyRepository.d.ts","sourceRoot":"","sources":["../../../src/repositories/common/ApiKeyRepository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAE/E,OAAO,cAAc,MAAM,sBAAsB,CAAC;AAElD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,cAAc,CAAC,MAAM,CAAC;IAClE,OAAO,CAAC,MAAM,CAAC,eAAe,CAAa;IAE3C,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAA+B;IAE/D,MAAM,CAAC,uBAAuB,IAAI,aAAa,CAAC,IAAI,CAAC;IA0BrD,OAAO;IAIP,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAElC;;OAEG;WACW,OAAO,IAAI,gBAAgB;CAM1C"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { ApiKeySchema } from '@aneuhold/core-ts-db-lib';
|
|
2
|
-
import ApiKeyValidator from '../../validators/common/ApiKeyValidator.js';
|
|
3
|
-
import BaseRepository from '../BaseRepository.js';
|
|
4
|
-
/**
|
|
5
|
-
* The repository that contains {@link ApiKey} documents.
|
|
6
|
-
*/
|
|
7
|
-
export default class ApiKeyRepository extends BaseRepository {
|
|
8
|
-
static COLLECTION_NAME = 'apiKeys';
|
|
9
|
-
static singletonInstance;
|
|
10
|
-
static getListenersForUserRepo() {
|
|
11
|
-
const apiKeyRepo = ApiKeyRepository.getRepo();
|
|
12
|
-
return {
|
|
13
|
-
deleteOne: async (userId) => {
|
|
14
|
-
await (await apiKeyRepo.getCollection()).deleteOne({
|
|
15
|
-
userId
|
|
16
|
-
});
|
|
17
|
-
},
|
|
18
|
-
deleteList: async (userIds) => {
|
|
19
|
-
await (await apiKeyRepo.getCollection()).deleteMany({
|
|
20
|
-
userId: { $in: userIds }
|
|
21
|
-
});
|
|
22
|
-
},
|
|
23
|
-
insertNew: async (user) => {
|
|
24
|
-
await apiKeyRepo.insertNew(ApiKeySchema.parse({ userId: user._id }));
|
|
25
|
-
},
|
|
26
|
-
insertMany: async (users) => {
|
|
27
|
-
await apiKeyRepo.insertMany(users.map((user) => ApiKeySchema.parse({ userId: user._id })));
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
constructor() {
|
|
32
|
-
super(ApiKeyRepository.COLLECTION_NAME, new ApiKeyValidator());
|
|
33
|
-
}
|
|
34
|
-
setupSubscribers() { }
|
|
35
|
-
/**
|
|
36
|
-
* Gets the singleton instance of the {@link ApiKeyRepository}.
|
|
37
|
-
*/
|
|
38
|
-
static getRepo() {
|
|
39
|
-
if (!ApiKeyRepository.singletonInstance) {
|
|
40
|
-
ApiKeyRepository.singletonInstance = new ApiKeyRepository();
|
|
41
|
-
}
|
|
42
|
-
return ApiKeyRepository.singletonInstance;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=ApiKeyRepository.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ApiKeyRepository.js","sourceRoot":"","sources":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AAK,CAAC,gBAAgB,CAAC,eAAe,EAAE,IAAI,eAAe,EAAE,CAAC,CAAC;IACjE,CAAC;IAES,gBAAgB,KAAU,CAAC;IAErC;;OAEG;IACI,MAAM,CAAC,OAAO;QACnB,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;YACxC,gBAAgB,CAAC,iBAAiB,GAAG,IAAI,gBAAgB,EAAE,CAAC;QAC9D,CAAC;QACD,OAAO,gBAAgB,CAAC,iBAAiB,CAAC;IAC5C,CAAC"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { ApiKey, User } from '@aneuhold/core-ts-db-lib';
|
|
2
|
-
import { ApiKeySchema } from '@aneuhold/core-ts-db-lib';
|
|
3
|
-
import type { RepoListeners } from '../../services/RepoSubscriptionService.js';
|
|
4
|
-
import ApiKeyValidator from '../../validators/common/ApiKeyValidator.js';
|
|
5
|
-
import BaseRepository from '../BaseRepository.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The repository that contains {@link ApiKey} documents.
|
|
9
|
-
*/
|
|
10
|
-
export default class ApiKeyRepository extends BaseRepository<ApiKey> {
|
|
11
|
-
private static COLLECTION_NAME = 'apiKeys';
|
|
12
|
-
|
|
13
|
-
private static singletonInstance: ApiKeyRepository | undefined;
|
|
14
|
-
|
|
15
|
-
static getListenersForUserRepo(): RepoListeners<User> {
|
|
16
|
-
const apiKeyRepo = ApiKeyRepository.getRepo();
|
|
17
|
-
return {
|
|
18
|
-
deleteOne: async (userId) => {
|
|
19
|
-
await (
|
|
20
|
-
await apiKeyRepo.getCollection()
|
|
21
|
-
).deleteOne({
|
|
22
|
-
userId
|
|
23
|
-
});
|
|
24
|
-
},
|
|
25
|
-
deleteList: async (userIds) => {
|
|
26
|
-
await (
|
|
27
|
-
await apiKeyRepo.getCollection()
|
|
28
|
-
).deleteMany({
|
|
29
|
-
userId: { $in: userIds }
|
|
30
|
-
});
|
|
31
|
-
},
|
|
32
|
-
insertNew: async (user) => {
|
|
33
|
-
await apiKeyRepo.insertNew(ApiKeySchema.parse({ userId: user._id }));
|
|
34
|
-
},
|
|
35
|
-
insertMany: async (users) => {
|
|
36
|
-
await apiKeyRepo.insertMany(users.map((user) => ApiKeySchema.parse({ userId: user._id })));
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
private constructor() {
|
|
42
|
-
super(ApiKeyRepository.COLLECTION_NAME, new ApiKeyValidator());
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
protected setupSubscribers(): void {}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Gets the singleton instance of the {@link ApiKeyRepository}.
|
|
49
|
-
*/
|
|
50
|
-
public static getRepo(): ApiKeyRepository {
|
|
51
|
-
if (!ApiKeyRepository.singletonInstance) {
|
|
52
|
-
ApiKeyRepository.singletonInstance = new ApiKeyRepository();
|
|
53
|
-
}
|
|
54
|
-
return ApiKeyRepository.singletonInstance;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ApiKey } from '@aneuhold/core-ts-db-lib';
|
|
2
|
-
import IValidator from '../BaseValidator.js';
|
|
3
|
-
export default class ApiKeyValidator extends IValidator<ApiKey> {
|
|
4
|
-
constructor();
|
|
5
|
-
protected validateNewObjectBusinessLogic(newApiKey: ApiKey): Promise<void>;
|
|
6
|
-
protected validateUpdateObjectBusinessLogic(updatedApiKey: Partial<ApiKey>): Promise<void>;
|
|
7
|
-
validateRepositoryInDb(dryRun: boolean): Promise<void>;
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=ApiKeyValidator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ApiKeyValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/common/ApiKeyValidator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAMvD,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAE7C,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU,CAAC,MAAM,CAAC;;cAK7C,8BAA8B,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBhF,SAAS,CAAC,iCAAiC,CAAC,aAAa,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAUpF,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAwB7D"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ApiKeySchema } from '@aneuhold/core-ts-db-lib';
|
|
2
|
-
import { DR, ErrorUtils } from '@aneuhold/core-ts-lib';
|
|
3
|
-
import ApiKeyRepository from '../../repositories/common/ApiKeyRepository.js';
|
|
4
|
-
import UserRepository from '../../repositories/common/UserRepository.js';
|
|
5
|
-
import IValidator from '../BaseValidator.js';
|
|
6
|
-
export default class ApiKeyValidator extends IValidator {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(ApiKeySchema, ApiKeySchema.partial());
|
|
9
|
-
}
|
|
10
|
-
async validateNewObjectBusinessLogic(newApiKey) {
|
|
11
|
-
// Check if the user exists
|
|
12
|
-
const userRepo = UserRepository.getRepo();
|
|
13
|
-
const userInDb = await userRepo.get({ _id: newApiKey.userId });
|
|
14
|
-
if (!userInDb) {
|
|
15
|
-
DR.logger.error(`User with ID: ${newApiKey.userId} does not exist in the database.`);
|
|
16
|
-
ErrorUtils.throwError(`User with ID: ${newApiKey.userId} does not exist in the database.`, newApiKey);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
// Check if the user already has an API key
|
|
20
|
-
const apiKeyRepo = ApiKeyRepository.getRepo();
|
|
21
|
-
const apiKeyInDb = await apiKeyRepo.get({ userId: newApiKey.userId });
|
|
22
|
-
if (apiKeyInDb) {
|
|
23
|
-
DR.logger.error(`User with ID: ${newApiKey.userId} already has an API key.`);
|
|
24
|
-
ErrorUtils.throwError(`User with ID: ${newApiKey.userId} already has an API key.`, newApiKey);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
validateUpdateObjectBusinessLogic(updatedApiKey) {
|
|
28
|
-
// Throw, because API keys should not be updated. Only created and deleted.
|
|
29
|
-
DR.logger.error(`API keys should not be updated at this time. Only created and deleted.`);
|
|
30
|
-
ErrorUtils.throwError(`API keys should not be updated at this time. Only created and deleted.`, updatedApiKey);
|
|
31
|
-
return Promise.resolve();
|
|
32
|
-
}
|
|
33
|
-
async validateRepositoryInDb(dryRun) {
|
|
34
|
-
const apiKeyRepo = ApiKeyRepository.getRepo();
|
|
35
|
-
const allApiKeys = await apiKeyRepo.getAll();
|
|
36
|
-
const allUserIds = await UserRepository.getRepo().getAllIdsAsHash();
|
|
37
|
-
await this.runStandardValidationForRepository({
|
|
38
|
-
dryRun,
|
|
39
|
-
docName: 'API Key',
|
|
40
|
-
allDocs: allApiKeys,
|
|
41
|
-
shouldDelete: (apiKey) => {
|
|
42
|
-
if (!allUserIds[apiKey.userId]) {
|
|
43
|
-
DR.logger.error(`API Key with ID: ${apiKey._id} has no valid associated user.`);
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
return false;
|
|
47
|
-
},
|
|
48
|
-
deletionFunction: async (docIdsToDelete) => {
|
|
49
|
-
await apiKeyRepo.deleteList(docIdsToDelete);
|
|
50
|
-
},
|
|
51
|
-
updateFunction: async (docsToUpdate) => {
|
|
52
|
-
await apiKeyRepo.updateMany(docsToUpdate);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=ApiKeyValidator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ApiKeyValidator.js","sourceRoot":"","sources":["../../../src/validators/common/ApiKeyValidator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;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';
|
|
4
|
-
import type { UUID } from 'crypto';
|
|
5
|
-
import ApiKeyRepository from '../../repositories/common/ApiKeyRepository.js';
|
|
6
|
-
import UserRepository from '../../repositories/common/UserRepository.js';
|
|
7
|
-
import IValidator from '../BaseValidator.js';
|
|
8
|
-
|
|
9
|
-
export default class ApiKeyValidator extends IValidator<ApiKey> {
|
|
10
|
-
constructor() {
|
|
11
|
-
super(ApiKeySchema, ApiKeySchema.partial());
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
protected async validateNewObjectBusinessLogic(newApiKey: ApiKey): Promise<void> {
|
|
15
|
-
// Check if the user exists
|
|
16
|
-
const userRepo = UserRepository.getRepo();
|
|
17
|
-
const userInDb = await userRepo.get({ _id: newApiKey.userId });
|
|
18
|
-
if (!userInDb) {
|
|
19
|
-
DR.logger.error(`User with ID: ${newApiKey.userId} does not exist in the database.`);
|
|
20
|
-
ErrorUtils.throwError(
|
|
21
|
-
`User with ID: ${newApiKey.userId} does not exist in the database.`,
|
|
22
|
-
newApiKey
|
|
23
|
-
);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
// Check if the user already has an API key
|
|
27
|
-
const apiKeyRepo = ApiKeyRepository.getRepo();
|
|
28
|
-
const apiKeyInDb = await apiKeyRepo.get({ userId: newApiKey.userId });
|
|
29
|
-
if (apiKeyInDb) {
|
|
30
|
-
DR.logger.error(`User with ID: ${newApiKey.userId} already has an API key.`);
|
|
31
|
-
ErrorUtils.throwError(`User with ID: ${newApiKey.userId} already has an API key.`, newApiKey);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
protected validateUpdateObjectBusinessLogic(updatedApiKey: Partial<ApiKey>): Promise<void> {
|
|
36
|
-
// Throw, because API keys should not be updated. Only created and deleted.
|
|
37
|
-
DR.logger.error(`API keys should not be updated at this time. Only created and deleted.`);
|
|
38
|
-
ErrorUtils.throwError(
|
|
39
|
-
`API keys should not be updated at this time. Only created and deleted.`,
|
|
40
|
-
updatedApiKey
|
|
41
|
-
);
|
|
42
|
-
return Promise.resolve();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async validateRepositoryInDb(dryRun: boolean): Promise<void> {
|
|
46
|
-
const apiKeyRepo = ApiKeyRepository.getRepo();
|
|
47
|
-
const allApiKeys = await apiKeyRepo.getAll();
|
|
48
|
-
const allUserIds = await UserRepository.getRepo().getAllIdsAsHash();
|
|
49
|
-
|
|
50
|
-
await this.runStandardValidationForRepository({
|
|
51
|
-
dryRun,
|
|
52
|
-
docName: 'API Key',
|
|
53
|
-
allDocs: allApiKeys,
|
|
54
|
-
shouldDelete: (apiKey: ApiKey) => {
|
|
55
|
-
if (!allUserIds[apiKey.userId]) {
|
|
56
|
-
DR.logger.error(`API Key with ID: ${apiKey._id} has no valid associated user.`);
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
return false;
|
|
60
|
-
},
|
|
61
|
-
deletionFunction: async (docIdsToDelete: UUID[]) => {
|
|
62
|
-
await apiKeyRepo.deleteList(docIdsToDelete);
|
|
63
|
-
},
|
|
64
|
-
updateFunction: async (docsToUpdate: ApiKey[]) => {
|
|
65
|
-
await apiKeyRepo.updateMany(docsToUpdate);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|