@loomcore/api 0.2.20 → 0.2.21
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/controllers/auth.controller.js +9 -4
- package/dist/services/generic-api-service/generic-api-service.interface.d.ts +2 -1
- package/dist/services/generic-api-service/generic-api.service.d.ts +1 -0
- package/dist/services/generic-api-service/generic-api.service.js +3 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EmptyUserContext, passwordValidator, TokenResponseSpec, } from "@loomcore/common/models";
|
|
1
|
+
import { EmptyUserContext, passwordValidator, TokenResponseSpec, UserSpec, } from "@loomcore/common/models";
|
|
2
2
|
import { entityUtils } from "@loomcore/common/utils";
|
|
3
3
|
import { config } from "../config/base-api-config.js";
|
|
4
4
|
import { BadRequestError, UnauthenticatedError } from "../errors/index.js";
|
|
@@ -16,8 +16,12 @@ export class AuthController {
|
|
|
16
16
|
loginResponseSpec;
|
|
17
17
|
constructor(app, database, options = {}) {
|
|
18
18
|
this.database = database;
|
|
19
|
+
const userSpecFromService = options.userService?.getModelSpec();
|
|
20
|
+
const inheritedUserSpec = userSpecFromService && userSpecFromService !== UserSpec
|
|
21
|
+
? userSpecFromService
|
|
22
|
+
: undefined;
|
|
19
23
|
const resolved = resolveAuthUserSpecs({
|
|
20
|
-
userSpec: options.userSpec,
|
|
24
|
+
userSpec: options.userSpec ?? inheritedUserSpec,
|
|
21
25
|
publicUserSpec: options.publicUserSpec,
|
|
22
26
|
});
|
|
23
27
|
this.userSpec = resolved.userSpec;
|
|
@@ -27,8 +31,9 @@ export class AuthController {
|
|
|
27
31
|
this.userService =
|
|
28
32
|
options.userService ?? new UserService(database, this.userSpec);
|
|
29
33
|
this.organizationService = new OrganizationService(database);
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
const jwtUserModelSpec = options.userSpec ?? inheritedUserSpec ?? options.publicUserSpec;
|
|
35
|
+
if (jwtUserModelSpec) {
|
|
36
|
+
setAuthUserContextSpec(createUserContextSpec(jwtUserModelSpec));
|
|
32
37
|
}
|
|
33
38
|
this.mapRoutes(app);
|
|
34
39
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { IEntity, IPagedResult, IQueryOptions, IUserContext } from "@loomcore/common/models";
|
|
1
|
+
import type { IEntity, IModelSpec, IPagedResult, IQueryOptions, IUserContext } from "@loomcore/common/models";
|
|
2
2
|
import type { AppIdType } from "@loomcore/common/types";
|
|
3
3
|
import type { ValueError } from "@sinclair/typebox/errors";
|
|
4
4
|
import type { PostProcessEntityCustomFunction, PrepareQueryCustomFunction } from "../../controllers/types.js";
|
|
5
5
|
import type { DeleteResult } from "../../databases/models/delete-result.js";
|
|
6
6
|
import type { Operation } from "../../databases/operations/operation.js";
|
|
7
7
|
export interface IGenericApiService<T extends IEntity> {
|
|
8
|
+
getModelSpec(): IModelSpec;
|
|
8
9
|
validate(doc: any, isPartial?: boolean): ValueError[] | null;
|
|
9
10
|
validateMany(docs: any[], isPartial?: boolean): ValueError[] | null;
|
|
10
11
|
prepareQuery(userContext: IUserContext | undefined, queryObject: IQueryOptions, operations: Operation[]): {
|
|
@@ -12,6 +12,7 @@ export declare class GenericApiService<T extends IEntity> implements IGenericApi
|
|
|
12
12
|
protected singularResourceName: string;
|
|
13
13
|
protected modelSpec: IModelSpec;
|
|
14
14
|
constructor(database: IDatabase, pluralResourceName: string, singularResourceName: string, modelSpec: IModelSpec);
|
|
15
|
+
getModelSpec(): IModelSpec;
|
|
15
16
|
getAll(userContext: IUserContext): Promise<T[]>;
|
|
16
17
|
getAll<TCustom extends IEntity>(userContext: IUserContext, prepareQueryCustom: PrepareQueryCustomFunction, postProcessEntityCustom: PostProcessEntityCustomFunction<T, TCustom>): Promise<TCustom[]>;
|
|
17
18
|
prepareQuery(userContext: IUserContext | undefined, queryObject: IQueryOptions, operations: Operation[]): {
|
|
@@ -16,6 +16,9 @@ export class GenericApiService {
|
|
|
16
16
|
this.modelSpec = modelSpec;
|
|
17
17
|
this.database = database;
|
|
18
18
|
}
|
|
19
|
+
getModelSpec() {
|
|
20
|
+
return this.modelSpec;
|
|
21
|
+
}
|
|
19
22
|
async getAll(userContext, prepareQueryCustom, postProcessEntityCustom) {
|
|
20
23
|
let operations = [];
|
|
21
24
|
if (prepareQueryCustom) {
|