mongodb-dynamic-api 2.9.0 → 2.10.1
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 +14 -0
- package/package.json +1 -1
- package/src/filters/index.d.ts +1 -0
- package/src/filters/index.js +18 -0
- package/src/filters/index.js.map +1 -0
- package/src/guards/dynamic-api-jwt-auth.guard.d.ts +1 -1
- package/src/guards/dynamic-api-jwt-auth.guard.js.map +1 -1
- package/src/helpers/index.d.ts +1 -0
- package/src/helpers/index.js +1 -0
- package/src/helpers/index.js.map +1 -1
- package/src/helpers/repository.helper.d.ts +53 -0
- package/src/helpers/repository.helper.js +70 -0
- package/src/helpers/repository.helper.js.map +1 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/index.js.map +1 -1
- package/src/interfaces/dynamic-api-ability.interface.d.ts +1 -1
- package/src/models/soft-deletable-entity.model.js +1 -6
- package/src/models/soft-deletable-entity.model.js.map +1 -1
- package/src/modules/auth/auth.helper.d.ts +2 -2
- package/src/modules/auth/auth.helper.js +5 -3
- package/src/modules/auth/auth.helper.js.map +1 -1
- package/src/modules/auth/auth.module.js +10 -3
- package/src/modules/auth/auth.module.js.map +1 -1
- package/src/modules/auth/interfaces/auth-options.interface.d.ts +4 -1
- package/src/modules/auth/mixins/auth-controller.mixin.js +1 -1
- package/src/modules/auth/mixins/auth-controller.mixin.js.map +1 -1
- package/src/modules/auth/mixins/auth-policies-guard.mixin.js +4 -4
- package/src/modules/auth/mixins/auth-policies-guard.mixin.js.map +1 -1
- package/src/modules/auth/services/base-auth.service.d.ts +3 -1
- package/src/modules/auth/services/base-auth.service.js +16 -9
- package/src/modules/auth/services/base-auth.service.js.map +1 -1
- package/src/routes/aggregate/aggregate-controller.mixin.js +2 -1
- package/src/routes/aggregate/aggregate-controller.mixin.js.map +1 -1
- package/src/routes/aggregate/aggregate-gateway.mixin.js +5 -8
- package/src/routes/aggregate/aggregate-gateway.mixin.js.map +1 -1
- package/src/routes/create-many/create-many-gateway.mixin.js +2 -2
- package/src/routes/create-many/create-many-gateway.mixin.js.map +1 -1
- package/src/routes/create-one/create-one-gateway.mixin.js +2 -2
- package/src/routes/create-one/create-one-gateway.mixin.js.map +1 -1
- package/src/routes/delete-many/delete-many-gateway.mixin.js +2 -2
- package/src/routes/delete-many/delete-many-gateway.mixin.js.map +1 -1
- package/src/routes/delete-one/delete-one-gateway.mixin.js +2 -2
- package/src/routes/delete-one/delete-one-gateway.mixin.js.map +1 -1
- package/src/routes/duplicate-many/duplicate-many-gateway.mixin.js +2 -2
- package/src/routes/duplicate-many/duplicate-many-gateway.mixin.js.map +1 -1
- package/src/routes/duplicate-one/duplicate-one-gateway.mixin.js +2 -2
- package/src/routes/duplicate-one/duplicate-one-gateway.mixin.js.map +1 -1
- package/src/routes/get-many/get-many-gateway.mixin.js +2 -2
- package/src/routes/get-many/get-many-gateway.mixin.js.map +1 -1
- package/src/routes/get-one/get-one-gateway.mixin.js +2 -2
- package/src/routes/get-one/get-one-gateway.mixin.js.map +1 -1
- package/src/routes/replace-one/replace-one-gateway.mixin.js +2 -2
- package/src/routes/replace-one/replace-one-gateway.mixin.js.map +1 -1
- package/src/routes/update-many/update-many-gateway.mixin.js +2 -2
- package/src/routes/update-many/update-many-gateway.mixin.js.map +1 -1
- package/src/routes/update-one/update-one-gateway.mixin.js +2 -2
- package/src/routes/update-one/update-one-gateway.mixin.js.map +1 -1
- package/src/services/base/base.service.js +2 -1
- package/src/services/base/base.service.js.map +1 -1
- package/src/services/dynamic-api-global-state/dynamic-api-global-state.service.d.ts +1 -1
- package/src/services/dynamic-api-global-state/dynamic-api-global-state.service.js.map +1 -1
- package/src/version.json +1 -1
- package/test/dynamic-api-for-feature.e2e-spec.js +1 -20
- package/test/dynamic-api-for-feature.e2e-spec.js.map +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
Changelog
|
|
2
2
|
|
|
3
|
+
## [2.10.1](https://github.com/MikeDev75015/mongodb-dynamic-api/compare/v2.10.0...v2.10.1) (2025-07-19)
|
|
4
|
+
|
|
5
|
+
## [2.10.0](https://github.com/MikeDev75015/mongodb-dynamic-api/compare/v2.9.0...v2.10.0) (2025-02-22)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### helper
|
|
9
|
+
|
|
10
|
+
* **helper:** get repository from entity method ([e02c9b8a](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/e02c9b8a3476958c261b862971db9b3cbb5a5a9c))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### auth
|
|
14
|
+
|
|
15
|
+
* **auth:** add before save callback, improve some behaviors ([20df58a3](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/20df58a35b0ca00376c06e0f4e850e2fd5e81a99))
|
|
16
|
+
|
|
3
17
|
## [2.9.0](https://github.com/MikeDev75015/mongodb-dynamic-api/compare/v2.8.3...v2.9.0) (2025-02-16)
|
|
4
18
|
|
|
5
19
|
|
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ws-exception/dynamic-api-ws-exception.filter';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ws-exception/dynamic-api-ws-exception.filter"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/filters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iFAA+D"}
|
|
@@ -3,7 +3,7 @@ import { Reflector } from '@nestjs/core';
|
|
|
3
3
|
import { DynamicApiGlobalState } from '../interfaces';
|
|
4
4
|
declare const DynamicApiJwtAuthGuard_base: import("@nestjs/passport").Type<import("@nestjs/passport").IAuthGuard>;
|
|
5
5
|
export declare class DynamicApiJwtAuthGuard extends DynamicApiJwtAuthGuard_base {
|
|
6
|
-
private reflector;
|
|
6
|
+
private readonly reflector;
|
|
7
7
|
private readonly state;
|
|
8
8
|
constructor(reflector: Reflector, state: DynamicApiGlobalState);
|
|
9
9
|
canActivate(context: ExecutionContext): boolean | Promise<boolean> | import("rxjs").Observable<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-api-jwt-auth.guard.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/guards/dynamic-api-jwt-auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA8D;AAC9D,uCAAyC;AACzC,+CAA6C;AAC7C,8CAA8C;AAIvC,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,IAAA,oBAAS,EAAC,KAAK,CAAC;IAC1D,
|
|
1
|
+
{"version":3,"file":"dynamic-api-jwt-auth.guard.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/guards/dynamic-api-jwt-auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA8D;AAC9D,uCAAyC;AACzC,+CAA6C;AAC7C,8CAA8C;AAIvC,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,IAAA,oBAAS,EAAC,KAAK,CAAC;IAC1D,YACmB,SAAoB,EACpB,KAA4B;QAE7C,KAAK,EAAE,CAAC;QAHS,cAAS,GAAT,SAAS,CAAW;QACpB,UAAK,GAAL,KAAK,CAAuB;IAG/C,CAAC;IAED,WAAW,CAAC,OAAyB;QACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAU,0BAAa,EAAE;YACxE,OAAO,CAAC,UAAU,EAAE;YACpB,OAAO,CAAC,QAAQ,EAAE;SACnB,CAAC,CAAC;QAEH,IAAI,QAAQ,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;CACF,CAAA;AApBY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;qCAGmB,gBAAS;GAF5B,sBAAsB,CAoBlC"}
|
package/src/helpers/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './controller-ability-predicates.helper';
|
|
2
2
|
export * from './format.helper';
|
|
3
3
|
export * from './mixin-data.helper';
|
|
4
|
+
export * from './repository.helper';
|
|
4
5
|
export * from './route-decorators.helper';
|
|
5
6
|
export * from './route-description.helper';
|
|
6
7
|
export * from './schema.helper';
|
package/src/helpers/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./controller-ability-predicates.helper"), exports);
|
|
18
18
|
__exportStar(require("./format.helper"), exports);
|
|
19
19
|
__exportStar(require("./mixin-data.helper"), exports);
|
|
20
|
+
__exportStar(require("./repository.helper"), exports);
|
|
20
21
|
__exportStar(require("./route-decorators.helper"), exports);
|
|
21
22
|
__exportStar(require("./route-description.helper"), exports);
|
|
22
23
|
__exportStar(require("./schema.helper"), exports);
|
package/src/helpers/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yEAAuD;AACvD,kDAAgC;AAChC,sDAAoC;AACpC,4DAA0C;AAC1C,6DAA2C;AAC3C,kDAAgC;AAChC,yDAAuC;AACvC,0DAAwC;AACxC,6DAA2C;AAC3C,6DAA2C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yEAAuD;AACvD,kDAAgC;AAChC,sDAAoC;AACpC,sDAAoC;AACpC,4DAA0C;AAC1C,6DAA2C;AAC3C,kDAAgC;AAChC,yDAAuC;AACvC,0DAAwC;AACxC,6DAA2C;AAC3C,6DAA2C"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
+
/// <reference types="mongoose/types/callback" />
|
|
3
|
+
/// <reference types="mongoose/types/collection" />
|
|
4
|
+
/// <reference types="mongoose/types/connection" />
|
|
5
|
+
/// <reference types="mongoose/types/cursor" />
|
|
6
|
+
/// <reference types="mongoose/types/document" />
|
|
7
|
+
/// <reference types="mongoose/types/error" />
|
|
8
|
+
/// <reference types="mongoose/types/expressions" />
|
|
9
|
+
/// <reference types="mongoose/types/helpers" />
|
|
10
|
+
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
+
/// <reference types="mongoose/types/indexes" />
|
|
12
|
+
/// <reference types="mongoose/types/models" />
|
|
13
|
+
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
+
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
+
/// <reference types="mongoose/types/populate" />
|
|
16
|
+
/// <reference types="mongoose/types/query" />
|
|
17
|
+
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
+
/// <reference types="mongoose/types/schematypes" />
|
|
19
|
+
/// <reference types="mongoose/types/session" />
|
|
20
|
+
/// <reference types="mongoose/types/types" />
|
|
21
|
+
/// <reference types="mongoose/types/utility" />
|
|
22
|
+
/// <reference types="mongoose/types/validation" />
|
|
23
|
+
/// <reference types="mongoose/types/virtuals" />
|
|
24
|
+
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
+
import { Type } from '@nestjs/common';
|
|
26
|
+
import { GetPagingResultResponse, GetResultResponse, PipelineStage } from 'mongodb-pipeline-builder';
|
|
27
|
+
import { FilterQuery, QueryOptions } from 'mongoose';
|
|
28
|
+
import { BaseEntity } from '../models';
|
|
29
|
+
type DynamicApiRepository<Entity extends BaseEntity> = {
|
|
30
|
+
aggregate(pipeline: PipelineStage[]): Promise<GetResultResponse<Entity>>;
|
|
31
|
+
bulkCreate(toCreateList: Partial<Entity>[]): Promise<Entity[]>;
|
|
32
|
+
create(toCreate: Partial<Entity>): Promise<Entity>;
|
|
33
|
+
delete(query: {
|
|
34
|
+
id?: string;
|
|
35
|
+
idList?: string[];
|
|
36
|
+
}): Promise<boolean>;
|
|
37
|
+
find(query: FilterQuery<Entity>): Promise<Entity | null>;
|
|
38
|
+
findAll(query?: FilterQuery<Entity>): Promise<Entity[]>;
|
|
39
|
+
paginate(pipeline: PipelineStage[]): Promise<GetPagingResultResponse<Entity>>;
|
|
40
|
+
update(query: FilterQuery<Entity>, toUpdate: Partial<Entity>, options?: QueryOptions<Entity>): Promise<Entity | null>;
|
|
41
|
+
};
|
|
42
|
+
declare class RepositoryHelper {
|
|
43
|
+
static getRepository<Entity extends BaseEntity>(entity: Type<Entity>): Promise<DynamicApiRepository<Entity>>;
|
|
44
|
+
private static aggregate;
|
|
45
|
+
private static paginate;
|
|
46
|
+
private static findAll;
|
|
47
|
+
private static find;
|
|
48
|
+
private static create;
|
|
49
|
+
private static update;
|
|
50
|
+
private static delete;
|
|
51
|
+
private static bulkCreate;
|
|
52
|
+
}
|
|
53
|
+
export { RepositoryHelper, DynamicApiRepository };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RepositoryHelper = void 0;
|
|
4
|
+
const mongodb_pipeline_builder_1 = require("mongodb-pipeline-builder");
|
|
5
|
+
const services_1 = require("../services");
|
|
6
|
+
class RepositoryHelper {
|
|
7
|
+
static async getRepository(entity) {
|
|
8
|
+
const model = await services_1.DynamicApiGlobalStateService.getEntityModel(entity);
|
|
9
|
+
return {
|
|
10
|
+
aggregate: (pipeline) => RepositoryHelper.aggregate(model, pipeline),
|
|
11
|
+
bulkCreate: (toCreateList) => RepositoryHelper.bulkCreate(model, toCreateList),
|
|
12
|
+
create: (toCreate) => RepositoryHelper.create(model, toCreate),
|
|
13
|
+
delete: (query) => RepositoryHelper.delete(model, query),
|
|
14
|
+
find: (query) => RepositoryHelper.find(model, query),
|
|
15
|
+
findAll: (query) => RepositoryHelper.findAll(model, query),
|
|
16
|
+
paginate: (pipeline) => RepositoryHelper.paginate(model, pipeline),
|
|
17
|
+
update: (query, toUpdate, options) => RepositoryHelper.update(model, query, toUpdate, options),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
static aggregate(model, pipeline) {
|
|
21
|
+
return (0, mongodb_pipeline_builder_1.GetResult)(model, pipeline);
|
|
22
|
+
}
|
|
23
|
+
static paginate(model, pipeline) {
|
|
24
|
+
return (0, mongodb_pipeline_builder_1.GetPagingResult)(model, pipeline);
|
|
25
|
+
}
|
|
26
|
+
static async findAll(model, query = {}) {
|
|
27
|
+
const entities = await model.find(query).lean().exec();
|
|
28
|
+
return entities.map(entity => ({ ...entity, id: entity._id.toString() }));
|
|
29
|
+
}
|
|
30
|
+
static async find(model, query) {
|
|
31
|
+
const entity = await model.findOne(query).lean().exec();
|
|
32
|
+
if (!entity) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return { ...entity, id: entity._id.toString() };
|
|
36
|
+
}
|
|
37
|
+
static async create(model, toCreate) {
|
|
38
|
+
const entity = await model.create(toCreate);
|
|
39
|
+
return { ...entity.toObject(), id: entity._id.toString() };
|
|
40
|
+
}
|
|
41
|
+
static async update(model, query, toUpdate, options = {}) {
|
|
42
|
+
const entity = await model
|
|
43
|
+
.findOneAndUpdate(query, { $set: toUpdate }, { ...options, new: true })
|
|
44
|
+
.lean()
|
|
45
|
+
.exec();
|
|
46
|
+
if (!entity) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return { ...entity, id: entity._id.toString() };
|
|
50
|
+
}
|
|
51
|
+
static async delete(model, query) {
|
|
52
|
+
if (query.id) {
|
|
53
|
+
const { deletedCount } = await model.deleteOne({ _id: query.id }).exec();
|
|
54
|
+
return deletedCount === 1;
|
|
55
|
+
}
|
|
56
|
+
else if (query.idList) {
|
|
57
|
+
const { deletedCount } = await model.deleteMany({ _id: { $in: query.idList } }).exec();
|
|
58
|
+
return deletedCount === query.idList.length;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
static async bulkCreate(model, toCreate) {
|
|
65
|
+
const entities = await model.create(toCreate);
|
|
66
|
+
return entities.map(entity => ({ ...entity.toObject(), id: entity._id.toString() }));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.RepositoryHelper = RepositoryHelper;
|
|
70
|
+
//# sourceMappingURL=repository.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.helper.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/helpers/repository.helper.ts"],"names":[],"mappings":";;;AACA,uEAMkC;AAGlC,0CAA2D;AAiB3D,MAAM,gBAAgB;IACb,MAAM,CAAC,KAAK,CAAC,aAAa,CAA4B,MAAoB;QAC/E,MAAM,KAAK,GAAG,MAAM,uCA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"__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./builders"), exports);
|
|
18
18
|
__exportStar(require("./decorators"), exports);
|
|
19
19
|
__exportStar(require("./dtos"), exports);
|
|
20
|
+
__exportStar(require("./filters"), exports);
|
|
20
21
|
__exportStar(require("./gateways"), exports);
|
|
21
22
|
__exportStar(require("./guards"), exports);
|
|
22
23
|
__exportStar(require("./helpers"), exports);
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../libs/dynamic-api/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B;AAC7B,yCAAuB;AACvB,6CAA2B;AAC3B,2CAAyB;AACzB,4CAA0B;AAC1B,iDAA+B;AAC/B,+CAA6B;AAC7B,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,6CAA2B;AAC3B,0CAAwB;AACxB,uDAAqC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../libs/dynamic-api/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B;AAC7B,yCAAuB;AACvB,4CAA0B;AAC1B,6CAA2B;AAC3B,2CAAyB;AACzB,4CAA0B;AAC1B,iDAA+B;AAC/B,+CAA6B;AAC7B,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,6CAA2B;AAC3B,0CAAwB;AACxB,uDAAqC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseEntity } from '../models';
|
|
2
2
|
import { RouteType } from './dynamic-api-route-type.type';
|
|
3
3
|
type AbilityPredicate<Entity extends BaseEntity, User = any> = (entity: Entity, user: User) => boolean;
|
|
4
|
-
type AuthAbilityPredicate<User = any> = (user: User) => boolean;
|
|
4
|
+
type AuthAbilityPredicate<User = any, Body = unknown> = (user: User, body?: Body) => boolean;
|
|
5
5
|
type ControllerAbilityPredicate<Entity extends BaseEntity> = {
|
|
6
6
|
targets: RouteType[];
|
|
7
7
|
predicate: AbilityPredicate<Entity>;
|
|
@@ -15,17 +15,12 @@ const swagger_1 = require("@nestjs/swagger");
|
|
|
15
15
|
const class_transformer_1 = require("class-transformer");
|
|
16
16
|
const base_entity_model_1 = require("./base-entity.model");
|
|
17
17
|
class SoftDeletableEntity extends base_entity_model_1.BaseEntity {
|
|
18
|
-
constructor() {
|
|
19
|
-
super(...arguments);
|
|
20
|
-
this.isDeleted = false;
|
|
21
|
-
this.deletedAt = null;
|
|
22
|
-
}
|
|
23
18
|
}
|
|
24
19
|
exports.SoftDeletableEntity = SoftDeletableEntity;
|
|
25
20
|
__decorate([
|
|
26
21
|
(0, class_transformer_1.Exclude)(),
|
|
27
22
|
(0, mongoose_1.Prop)({ type: Boolean, default: false }),
|
|
28
|
-
__metadata("design:type",
|
|
23
|
+
__metadata("design:type", Boolean)
|
|
29
24
|
], SoftDeletableEntity.prototype, "isDeleted", void 0);
|
|
30
25
|
__decorate([
|
|
31
26
|
(0, swagger_1.ApiProperty)({ type: Date, nullable: true }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"soft-deletable-entity.model.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/models/soft-deletable-entity.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAAwC;AACxC,6CAA8C;AAC9C,yDAA4C;AAC5C,2DAAiD;AAEjD,MAAsB,mBAAoB,SAAQ,8BAAU;
|
|
1
|
+
{"version":3,"file":"soft-deletable-entity.model.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/models/soft-deletable-entity.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAAwC;AACxC,6CAA8C;AAC9C,yDAA4C;AAC5C,2DAAiD;AAEjD,MAAsB,mBAAoB,SAAQ,8BAAU;CAQ3D;AARD,kDAQC;AALC;IAFC,IAAA,2BAAO,GAAE;IACT,IAAA,eAAI,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;sDACrB;AAInB;IAFC,IAAA,qBAAW,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAA,eAAI,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;8BACzC,IAAI;sDAAQ"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Type, ValidationPipeOptions } from '@nestjs/common';
|
|
2
|
-
import { AuthAbilityPredicate, DynamicApiServiceCallback, DynamicAPIServiceProvider, GatewayOptions } from '../../interfaces';
|
|
2
|
+
import { AuthAbilityPredicate, DynamicApiServiceBeforeSaveCallback, DynamicApiServiceCallback, DynamicAPIServiceProvider, GatewayOptions } from '../../interfaces';
|
|
3
3
|
import { BaseEntity } from '../../models';
|
|
4
4
|
import { AuthControllerConstructor, AuthGatewayConstructor, DynamicApiLoginOptions, DynamicApiRegisterOptions, DynamicApiResetPasswordOptions, DynamicApiUpdateAccountOptions } from './interfaces';
|
|
5
5
|
declare const authServiceProviderName = "DynamicApiAuthService";
|
|
6
6
|
declare const authGatewayProviderName = "DynamicApiAuthGateway";
|
|
7
7
|
declare const localStrategyProviderName = "DynamicApiLocalStrategy";
|
|
8
8
|
declare function createLocalStrategyProvider<Entity extends BaseEntity>(loginField: keyof Entity, passwordField: keyof Entity, abilityPredicate: AuthAbilityPredicate | undefined): DynamicAPIServiceProvider;
|
|
9
|
-
declare function createAuthServiceProvider<Entity extends BaseEntity>(userEntity: Type<Entity>, { loginField, passwordField, additionalFields, callback: loginCallback }: DynamicApiLoginOptions<Entity>, registerCallback: DynamicApiServiceCallback<Entity> | undefined, resetPasswordOptions: DynamicApiResetPasswordOptions<Entity> | undefined, updateAccountCallback: DynamicApiServiceCallback<Entity> | undefined): DynamicAPIServiceProvider;
|
|
9
|
+
declare function createAuthServiceProvider<Entity extends BaseEntity>(userEntity: Type<Entity>, { loginField, passwordField, additionalFields, callback: loginCallback }: DynamicApiLoginOptions<Entity>, registerCallback: DynamicApiServiceCallback<Entity> | undefined, resetPasswordOptions: DynamicApiResetPasswordOptions<Entity> | undefined, updateAccountCallback: DynamicApiServiceCallback<Entity> | undefined, beforeRegisterCallback: DynamicApiServiceBeforeSaveCallback<Entity> | undefined, beforeUpdateAccountCallback: DynamicApiServiceBeforeSaveCallback<Entity> | undefined): DynamicAPIServiceProvider;
|
|
10
10
|
declare function createAuthController<Entity extends BaseEntity>(userEntity: Type<Entity>, { loginField, passwordField, additionalFields }: DynamicApiLoginOptions<Entity>, registerOptions: DynamicApiRegisterOptions<Entity> | undefined, validationPipeOptions: ValidationPipeOptions | undefined, resetPasswordOptions: DynamicApiResetPasswordOptions<Entity> | undefined, updateAccountOptions: DynamicApiUpdateAccountOptions<Entity> | undefined): AuthControllerConstructor<Entity>;
|
|
11
11
|
declare function createAuthGateway<Entity extends BaseEntity>(userEntity: Type<Entity>, loginOptions: DynamicApiLoginOptions<Entity>, registerOptions: DynamicApiRegisterOptions<Entity> | undefined, validationPipeOptions: ValidationPipeOptions | undefined, resetPasswordOptions: DynamicApiResetPasswordOptions<Entity> | undefined, updateAccountOptions: DynamicApiUpdateAccountOptions<Entity> | undefined, gatewayOptions: GatewayOptions): AuthGatewayConstructor<Entity>;
|
|
12
12
|
export { authServiceProviderName, authGatewayProviderName, createAuthController, createAuthServiceProvider, createAuthGateway, createLocalStrategyProvider, localStrategyProviderName, };
|
|
@@ -23,7 +23,7 @@ const mongoose_2 = require("mongoose");
|
|
|
23
23
|
const passport_local_1 = require("passport-local");
|
|
24
24
|
const decorators_1 = require("../../decorators");
|
|
25
25
|
const dynamic_api_module_1 = require("../../dynamic-api.module");
|
|
26
|
-
const
|
|
26
|
+
const filters_1 = require("../../filters");
|
|
27
27
|
const services_1 = require("../../services");
|
|
28
28
|
const mixins_1 = require("./mixins");
|
|
29
29
|
const services_2 = require("./services");
|
|
@@ -65,7 +65,7 @@ function createLocalStrategyProvider(loginField, passwordField, abilityPredicate
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
exports.createLocalStrategyProvider = createLocalStrategyProvider;
|
|
68
|
-
function createAuthServiceProvider(userEntity, { loginField, passwordField, additionalFields = [], callback: loginCallback }, registerCallback, resetPasswordOptions, updateAccountCallback) {
|
|
68
|
+
function createAuthServiceProvider(userEntity, { loginField, passwordField, additionalFields = [], callback: loginCallback }, registerCallback, resetPasswordOptions, updateAccountCallback, beforeRegisterCallback, beforeUpdateAccountCallback) {
|
|
69
69
|
let AuthService = class AuthService extends services_2.BaseAuthService {
|
|
70
70
|
constructor(model, jwtService, bcryptService) {
|
|
71
71
|
super(model, jwtService, bcryptService);
|
|
@@ -76,7 +76,9 @@ function createAuthServiceProvider(userEntity, { loginField, passwordField, addi
|
|
|
76
76
|
this.additionalRequestFields = additionalFields;
|
|
77
77
|
this.loginField = loginField;
|
|
78
78
|
this.passwordField = passwordField;
|
|
79
|
+
this.beforeRegisterCallback = beforeRegisterCallback;
|
|
79
80
|
this.registerCallback = registerCallback;
|
|
81
|
+
this.beforeUpdateAccountCallback = beforeUpdateAccountCallback;
|
|
80
82
|
this.updateAccountCallback = updateAccountCallback;
|
|
81
83
|
this.loginCallback = loginCallback;
|
|
82
84
|
this.resetPasswordOptions = resetPasswordOptions;
|
|
@@ -121,7 +123,7 @@ function createAuthGateway(userEntity, loginOptions, registerOptions, validation
|
|
|
121
123
|
};
|
|
122
124
|
AuthGateway = __decorate([
|
|
123
125
|
(0, websockets_1.WebSocketGateway)(gatewayOptions),
|
|
124
|
-
(0, common_1.UseFilters)(new
|
|
126
|
+
(0, common_1.UseFilters)(new filters_1.DynamicAPIWsExceptionFilter()),
|
|
125
127
|
(0, decorators_1.ValidatorPipe)(validationPipeOptions),
|
|
126
128
|
__param(0, (0, common_1.Inject)(authServiceProviderName)),
|
|
127
129
|
__metadata("design:paramtypes", [Object, jwt_1.JwtService])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.helper.js","sourceRoot":"","sources":["../../../../libs/dynamic-api/src/modules/auth/auth.helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"auth.helper.js","sourceRoot":"","sources":["../../../../libs/dynamic-api/src/modules/auth/auth.helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoJ;AACpJ,qCAAyC;AACzC,+CAA+C;AAC/C,+CAAoD;AACpD,6CAA0C;AAC1C,mDAAsD;AACtD,uCAAiC;AACjC,mDAA0C;AAC1C,iDAAiD;AACjD,iEAA4D;AAC5D,2CAA4D;AAG5D,6CAA+C;AAE/C,qCAAiE;AACjE,yCAA6C;AAE7C,MAAM,uBAAuB,GAAG,uBAAuB,CAAC;AAoJtD,0DAAuB;AAnJzB,MAAM,uBAAuB,GAAG,uBAAuB,CAAC;AAoJtD,0DAAuB;AAnJzB,MAAM,yBAAyB,GAAG,yBAAyB,CAAC;AAwJ1D,8DAAyB;AAtJ3B,SAAS,2BAA2B,CAClC,UAAwB,EACxB,aAA2B,EAC3B,gBAAkD;IAElD,IACM,aAAa,GADnB,MACM,aAAyC,SAAQ,IAAA,2BAAgB,EAAC,yBAAQ,CAAC;QAG/E,YAEE,WAAmD;YAEnD,KAAK,CAAC;gBACJ,aAAa,EAAE,UAAoB;gBACnC,aAAa,EAAE,aAAuB;aACvC,CAAC,CAAC;YALgB,gBAAW,GAAX,WAAW,CAAqB;YAJ3C,qBAAgB,GAAG,gBAAgB,CAAC;QAU9C,CAAC;QAED,KAAK,CAAC,QAAQ,CAAC,KAAa,EAAE,IAAY;YACxC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAC9D,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,MAAM,IAAI,8BAAqB,CAAC,qBAAqB,CAAC,CAAC;YACz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B;QACC,YAEqB,OAA4B,EAC5B,UAAsB;YAEzC,KAAK,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;YAHR,YAAO,GAAP,OAAO,CAAqB;YAC5B,eAAU,GAAV,UAAU,CAAY;QAG3C,CAAC;KACF,CAAA;IAdK,WAAW;QAHhB,IAAA,6BAAgB,EAAC,cAAc,CAAC;QAChC,IAAA,mBAAU,EAAC,IAAI,qCAA2B,EAAE,CAAC;QAC7C,IAAA,0BAAa,EAAC,qBAAqB,CAAC;QAShC,WAAA,IAAA,eAAM,EAAC,uBAAuB,CAAC,CAAA;iDAED,gBAAU;OAVvC,WAAW,CAchB;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAOC,8CAAiB"}
|
|
@@ -20,12 +20,19 @@ const strategies_1 = require("./strategies");
|
|
|
20
20
|
let AuthModule = AuthModule_1 = class AuthModule {
|
|
21
21
|
static forRoot(options, extraImports = []) {
|
|
22
22
|
const { userEntity, login: { loginField, passwordField, ...login }, register, updateAccount, resetPassword, jwt: { secret, expiresIn }, validationPipeOptions, webSocket, } = this.initializeAuthOptions(options);
|
|
23
|
-
const { resetPasswordCallback, changePasswordCallback, emailField, expirationInMinutes, changePasswordAbilityPredicate, } = resetPassword;
|
|
23
|
+
const { beforeChangePasswordCallback, resetPasswordCallback, changePasswordCallback, emailField, expirationInMinutes, changePasswordAbilityPredicate, } = resetPassword;
|
|
24
24
|
const resetPasswordOptions = resetPasswordCallback
|
|
25
|
-
? {
|
|
25
|
+
? {
|
|
26
|
+
beforeChangePasswordCallback,
|
|
27
|
+
resetPasswordCallback,
|
|
28
|
+
changePasswordCallback,
|
|
29
|
+
emailField,
|
|
30
|
+
expirationInMinutes,
|
|
31
|
+
changePasswordAbilityPredicate: changePasswordAbilityPredicate,
|
|
32
|
+
}
|
|
26
33
|
: undefined;
|
|
27
34
|
const AuthController = (0, auth_helper_1.createAuthController)(userEntity, { loginField, passwordField, ...login }, register, validationPipeOptions, resetPasswordOptions, updateAccount);
|
|
28
|
-
const AuthServiceProvider = (0, auth_helper_1.createAuthServiceProvider)(userEntity, { loginField, passwordField, ...login }, register.callback, resetPasswordOptions, updateAccount.callback);
|
|
35
|
+
const AuthServiceProvider = (0, auth_helper_1.createAuthServiceProvider)(userEntity, { loginField, passwordField, ...login }, register.callback, resetPasswordOptions, updateAccount.callback, register.beforeSaveCallback, updateAccount.beforeSaveCallback);
|
|
29
36
|
const LocalStrategyProvider = (0, auth_helper_1.createLocalStrategyProvider)(loginField, passwordField, login.abilityPredicate);
|
|
30
37
|
const schema = (0, helpers_1.buildSchemaFromEntity)(userEntity);
|
|
31
38
|
services_1.DynamicApiGlobalStateService.addEntitySchema(userEntity, schema);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../../../../libs/dynamic-api/src/modules/auth/auth.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAwC;AACxC,qCAAwC;AACxC,+CAAkD;AAClD,+CAAkD;AAClD,iEAA4D;AAC5D,2CAAmF;AAEnF,6CAA6E;AAC7E,+
|
|
1
|
+
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../../../../libs/dynamic-api/src/modules/auth/auth.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAwC;AACxC,qCAAwC;AACxC,+CAAkD;AAClD,+CAAkD;AAClD,iEAA4D;AAC5D,2CAAmF;AAEnF,6CAA6E;AAC7E,+CAAyJ;AAEzJ,6CAA2C;AAGpC,IAAM,UAAU,kBAAhB,MAAM,UAAU;IACrB,MAAM,CAAC,OAAO,CACZ,OAAsC,EACtC,eAAsB,EAAE;QAExB,MAAM,EACJ,UAAU,EACV,KAAK,EAAE,EACL,UAAU,EACV,aAAa,EACb,GAAG,KAAK,EACT,EACD,QAAQ,EACR,aAAa,EACb,aAAa,EACb,GAAG,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,EAC1B,qBAAqB,EACrB,SAAS,GACV,GAAG,IAAI,CAAC,q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gBAAgB,EAAE,KAAK,EAAE,gBAAgB,IAAI,EAAE;aAChD;YACD,QAAQ,EAAE;gBACR,GAAG,QAAQ;gBACX,gBAAgB,EAAE,QAAQ,EAAE,gBAAgB,IAAI,EAAE;gBAClD,SAAS,EAAE,QAAQ,EAAE,SAAS,IAAI,CAAC,CAAC,QAAQ,EAAE,gBAAgB;aAC/D;YACD,aAAa,EAAE;gBACb,GAAG,aAAa;gBAChB,yBAAyB,EAAE,aAAa,EAAE,yBAAyB,IAAI,EAAE;aAC1E;YACD,aAAa,EAAE;gBACb,GAAG,aAAa;gBAChB,UAAU,EAAE,CAAC,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,OAAuB,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;gBACrG,mBAAmB,EAAE,aAAa,EAAE,mBAAmB,IAAI,EAAE;aAC9D;YACD,qBAAqB,EAAE,qBAAqB;YAC5C,SAAS;SACV,CAAC;IACJ,CAAC;CACF,CAAA;AAnKY,gCAAU;qBAAV,UAAU;IADtB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,UAAU,CAmKtB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Type, ValidationPipeOptions } from '@nestjs/common';
|
|
2
|
-
import { AuthAbilityPredicate, DynamicApiResetPasswordCallback, DynamicApiServiceCallback, DynamicApiWebSocketOptions } from '../../../interfaces';
|
|
2
|
+
import { AuthAbilityPredicate, DynamicApiResetPasswordCallback, DynamicApiServiceBeforeSaveCallback, DynamicApiServiceCallback, DynamicApiWebSocketOptions } from '../../../interfaces';
|
|
3
3
|
import { BaseEntity } from '../../../models';
|
|
4
4
|
type DynamicApiJWTOptions = {
|
|
5
5
|
secret: string;
|
|
@@ -13,6 +13,7 @@ type DynamicApiLoginOptions<Entity extends BaseEntity = any> = {
|
|
|
13
13
|
additionalFields?: (keyof Entity)[];
|
|
14
14
|
};
|
|
15
15
|
type DynamicApiRegisterOptions<Entity extends BaseEntity = any> = {
|
|
16
|
+
beforeSaveCallback?: DynamicApiServiceBeforeSaveCallback<Entity>;
|
|
16
17
|
callback?: DynamicApiServiceCallback<Entity>;
|
|
17
18
|
protected?: boolean;
|
|
18
19
|
abilityPredicate?: AuthAbilityPredicate;
|
|
@@ -22,6 +23,7 @@ type DynamicApiRegisterOptions<Entity extends BaseEntity = any> = {
|
|
|
22
23
|
})[];
|
|
23
24
|
};
|
|
24
25
|
type DynamicApiUpdateAccountOptions<Entity extends BaseEntity = any> = {
|
|
26
|
+
beforeSaveCallback?: DynamicApiServiceBeforeSaveCallback<Entity>;
|
|
25
27
|
callback?: DynamicApiServiceCallback<Entity>;
|
|
26
28
|
abilityPredicate?: AuthAbilityPredicate;
|
|
27
29
|
additionalFieldsToExclude?: (keyof Entity)[];
|
|
@@ -29,6 +31,7 @@ type DynamicApiUpdateAccountOptions<Entity extends BaseEntity = any> = {
|
|
|
29
31
|
type DynamicApiResetPasswordOptions<Entity extends BaseEntity = any> = {
|
|
30
32
|
emailField?: keyof Entity | string;
|
|
31
33
|
expirationInMinutes?: number;
|
|
34
|
+
beforeChangePasswordCallback?: DynamicApiServiceBeforeSaveCallback<Entity>;
|
|
32
35
|
resetPasswordCallback?: DynamicApiResetPasswordCallback<Entity>;
|
|
33
36
|
changePasswordCallback?: DynamicApiServiceCallback<Entity>;
|
|
34
37
|
changePasswordAbilityPredicate?: AuthAbilityPredicate;
|
|
@@ -139,7 +139,7 @@ function AuthControllerMixin(userEntity, loginField, passwordField, additionalRe
|
|
|
139
139
|
__decorate([
|
|
140
140
|
(0, helpers_1.RouteDecoratorsHelper)(authRegisterDecorators),
|
|
141
141
|
(0, common_1.HttpCode)(common_1.HttpStatus.CREATED),
|
|
142
|
-
(0, swagger_1.
|
|
142
|
+
(0, swagger_1.ApiCreatedResponse)({ type: AuthPresenter }),
|
|
143
143
|
(0, common_1.Post)('register'),
|
|
144
144
|
__param(0, (0, common_1.Body)()),
|
|
145
145
|
__metadata("design:type", Function),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-controller.mixin.js","sourceRoot":"","sources":["../../../../../libs/dynamic-api/src/modules/auth/mixins/auth-controller.mixin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAwG;AACxG,
|
|
1
|
+
{"version":3,"file":"auth-controller.mixin.js","sourceRoot":"","sources":["../../../../../libs/dynamic-api/src/modules/auth/mixins/auth-controller.mixin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAwG;AACxG,6CAAyI;AACzI,gDAA0D;AAC1D,oDAAoE;AACpE,8CAAyD;AACzD,4CAAkD;AAElD,qEAAgE;AAChE,mEAA8D;AAC9D,sCAA6E;AAS7E,2EAAqE;AAErE,SAAS,mBAAmB,CAC1B,UAAwB,EACxB,UAAwB,EACxB,aAA2B,EAC3B,0BAA4C,EAAE,EAC9C,EACE,gBAAgB,EAAE,wBAAwB,EAC1C,SAAS,EAAE,iBAAiB,EAC5B,gBAAgB,EAAE,wBAAwB,MACL,EAAE,EACzC,uBAA+D,EAAE,EACjE,uBAA+D,EAAE;;IAEjE,IAAI,CAAC,UAAU,IAAI,CAAC,aAAa,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAGD,MAAM,wBAAyB,SAAQ,IAAA,kBAAQ,EAAC,UAAU,EAAE,CAAC,aAAa,CAAC,CAAC;KAI3E;SADE,aAAa;IAAd;QAFC,IAAA,qBAAW,GAAE;;sDAEU;IAI1B,MAAM,YAAa,SAAQ,IAAA,0BAAgB,EACzC,IAAA,kBAAQ,EAAC,UAAU,EAAE,CAAC,UAAU,CAAC,CAAC,EAClC,wBAAwB,CACzB;KAAG;IAEJ,MAAM,yBAAyB,GAAqB,EAAE,CAAC;IACvD,MAAM,wBAAwB,GAAqB,EAAE,CAAC;IAEtD,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC9B,wBAAwB,GAAG,EAAE,C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gB,CAAC;QACR,WAAA,IAAA,aAAI,GAAE,CAAA;;yCAAY,qCAAgB;;2DAEhD;IAMD;QAJC,IAAA,kCAAqB,EAAC,CAAC,CAAC,oBAAoB,EAAE,IAAA,mBAAM,GAAE,CAAC;QACvD,IAAA,kBAAS,EAAC,IAAI,2BAAkB,CAAC,CAAC,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;QACpE,IAAA,iBAAQ,EAAC,mBAAU,CAAC,UAAU,CAAC;QAC/B,IAAA,cAAK,EAAC,iBAAiB,CAAC;QACT,WAAA,IAAA,aAAI,GAAE,CAAA;;yCAAsC,uCAAiB;;4DAE5E;IAGH,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAEQ,kDAAmB"}
|
|
@@ -17,8 +17,8 @@ function AuthPoliciesGuardMixin(entity, abilityPredicate) {
|
|
|
17
17
|
this.abilityPredicate = abilityPredicate;
|
|
18
18
|
}
|
|
19
19
|
canActivate(context) {
|
|
20
|
-
const { user } = context.switchToHttp().getRequest();
|
|
21
|
-
if (this.abilityPredicate && (!user || !this.abilityPredicate(user))) {
|
|
20
|
+
const { user, body } = context.switchToHttp().getRequest();
|
|
21
|
+
if (this.abilityPredicate && (!user || !this.abilityPredicate(user, body))) {
|
|
22
22
|
throw new common_1.ForbiddenException('Access denied');
|
|
23
23
|
}
|
|
24
24
|
return true;
|
|
@@ -38,11 +38,11 @@ function AuthSocketPoliciesGuardMixin(entity, abilityPredicate) {
|
|
|
38
38
|
this.abilityPredicate = abilityPredicate;
|
|
39
39
|
}
|
|
40
40
|
async canActivate(context) {
|
|
41
|
-
const [socket] = context.getArgs();
|
|
41
|
+
const [socket, data, _, _event] = context.getArgs();
|
|
42
42
|
if (this.abilityPredicate) {
|
|
43
43
|
const accessToken = this.getAccessTokenFromSocketQuery(socket);
|
|
44
44
|
socket.user = await this.extractUserFromToken(accessToken);
|
|
45
|
-
if (!socket.user || !this.abilityPredicate(socket.user)) {
|
|
45
|
+
if (!socket.user || !this.abilityPredicate(socket.user, data)) {
|
|
46
46
|
throw new websockets_1.WsException('Access denied');
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-policies-guard.mixin.js","sourceRoot":"","sources":["../../../../../libs/dynamic-api/src/modules/auth/mixins/auth-policies-guard.mixin.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwF;AACxF,mDAAiD;AAGjD,sCAA+C;AAE/C,SAAS,sBAAsB,CAC7B,MAAoB,EACpB,gBAAkD;IAGlD,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;QAA3B;YACY,WAAM,GAAG,MAAM,CAAC;YAChB,qBAAgB,GAAG,gBAAgB,CAAC;QAahD,CAAC;QAXC,WAAW,CAAC,OAAyB;YACnC,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"auth-policies-guard.mixin.js","sourceRoot":"","sources":["../../../../../libs/dynamic-api/src/modules/auth/mixins/auth-policies-guard.mixin.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwF;AACxF,mDAAiD;AAGjD,sCAA+C;AAE/C,SAAS,sBAAsB,CAC7B,MAAoB,EACpB,gBAAkD;IAGlD,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;QAA3B;YACY,WAAM,GAAG,MAAM,CAAC;YAChB,qBAAgB,GAAG,gBAAgB,CAAC;QAahD,CAAC;QAXC,WAAW,CAAC,OAAyB;YACnC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;YAE3D,IAAI,IAAI,CAAC,gBAAgB,IAAI,CAC3B,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,CAC5C,EAAE,CAAC;gBACF,MAAM,IAAI,2BAAkB,CAAC,eAAe,CAAC,CAAC;YAChD,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAA;IAfK,qBAAqB;QAD1B,IAAA,mBAAU,GAAE;OACP,qBAAqB,CAe1B;IAED,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AA+BQ,wDAAsB;AA7B/B,SAAS,4BAA4B,CACnC,MAAoB,EACpB,gBAAkD;IAGlD,IAAM,2BAA2B,GAAjC,MAAM,2BAA4B,SAAQ,2BAAkB;QAA5D;;YACY,WAAM,GAAG,MAAM,CAAC;YAChB,qBAAgB,GAAG,gBAAgB,CAAC;QAiBhD,CAAC;QAfU,KAAK,CAAC,WAAW,CAAC,OAAyB;YAClD,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;YAEpD,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBAC1B,MAAM,WAAW,GAAG,IAAI,CAAC,6BAA6B,CAAC,MAAM,CAAC,CAAC;gBAE/D,MAAM,CAAC,IAAI,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;gBAE3D,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;oBAC9D,MAAM,IAAI,wBAAW,CAAC,eAAe,CAAC,CAAC;gBACzC,CAAC;YACH,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAA;IAnBK,2BAA2B;QADhC,IAAA,mBAAU,GAAE;OACP,2BAA2B,CAmBhC;IAED,OAAO,2BAA2B,CAAC;AACrC,CAAC;AAEgC,oEAA4B"}
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
import { Type } from '@nestjs/common';
|
|
26
26
|
import { JwtService } from '@nestjs/jwt';
|
|
27
27
|
import { Model } from 'mongoose';
|
|
28
|
-
import { DynamicApiServiceCallback } from '../../../interfaces';
|
|
28
|
+
import { DynamicApiServiceBeforeSaveCallback, DynamicApiServiceCallback } from '../../../interfaces';
|
|
29
29
|
import { BaseEntity } from '../../../models';
|
|
30
30
|
import { BaseService, BcryptService } from '../../../services';
|
|
31
31
|
import { DynamicApiResetPasswordOptions } from '../interfaces';
|
|
@@ -37,7 +37,9 @@ export declare abstract class BaseAuthService<Entity extends BaseEntity> extends
|
|
|
37
37
|
protected loginField: keyof Entity;
|
|
38
38
|
protected passwordField: keyof Entity;
|
|
39
39
|
protected additionalRequestFields: (keyof Entity)[];
|
|
40
|
+
protected beforeRegisterCallback: DynamicApiServiceBeforeSaveCallback<Entity>;
|
|
40
41
|
protected registerCallback: DynamicApiServiceCallback<Entity> | undefined;
|
|
42
|
+
protected beforeUpdateAccountCallback: DynamicApiServiceBeforeSaveCallback<Entity>;
|
|
41
43
|
protected updateAccountCallback: DynamicApiServiceCallback<Entity> | undefined;
|
|
42
44
|
protected loginCallback: DynamicApiServiceCallback<Entity> | undefined;
|
|
43
45
|
protected resetPasswordOptions: DynamicApiResetPasswordOptions<Entity> | undefined;
|
|
@@ -21,12 +21,7 @@ class BaseAuthService extends services_1.BaseService {
|
|
|
21
21
|
if (!user || !isPasswordValid) {
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
'_id',
|
|
26
|
-
this.loginField,
|
|
27
|
-
...this.additionalRequestFields,
|
|
28
|
-
];
|
|
29
|
-
return this.buildUserFields(user, fieldsToBuild);
|
|
24
|
+
return { ...user, id: user._id.toString() };
|
|
30
25
|
}
|
|
31
26
|
async login(user, fromMember = false) {
|
|
32
27
|
this.verifyArguments(user);
|
|
@@ -53,6 +48,10 @@ class BaseAuthService extends services_1.BaseService {
|
|
|
53
48
|
this.checkFieldsValidity(userToCreate);
|
|
54
49
|
try {
|
|
55
50
|
const hashedPassword = await this.bcryptService.hashPassword(userToCreate[this.passwordField]);
|
|
51
|
+
if (this.beforeRegisterCallback) {
|
|
52
|
+
userToCreate =
|
|
53
|
+
await this.beforeRegisterCallback(userToCreate, { hashedPassword }, this.callbackMethods);
|
|
54
|
+
}
|
|
56
55
|
const created = await this.model.create({ ...userToCreate, [this.passwordField]: hashedPassword });
|
|
57
56
|
if (this.registerCallback) {
|
|
58
57
|
const user = (await this.model.findOne({ _id: created._id }).lean().exec());
|
|
@@ -79,6 +78,11 @@ class BaseAuthService extends services_1.BaseService {
|
|
|
79
78
|
}
|
|
80
79
|
async updateAccount({ id }, update) {
|
|
81
80
|
this.verifyArguments(id, update);
|
|
81
|
+
if (this.beforeUpdateAccountCallback) {
|
|
82
|
+
const user = (await this.model.findOne({ _id: id }).lean().exec());
|
|
83
|
+
update =
|
|
84
|
+
await this.beforeUpdateAccountCallback({ ...user, id: user._id.toString() }, { update }, this.callbackMethods);
|
|
85
|
+
}
|
|
82
86
|
await this.model.updateOne({ _id: id }, { $set: update }).exec();
|
|
83
87
|
if (this.updateAccountCallback) {
|
|
84
88
|
const fullUser = (await this.model.findOne({ _id: id }).lean().exec());
|
|
@@ -148,11 +152,14 @@ class BaseAuthService extends services_1.BaseService {
|
|
|
148
152
|
return;
|
|
149
153
|
}
|
|
150
154
|
const hashedPassword = await this.bcryptService.hashPassword(newPassword);
|
|
151
|
-
|
|
155
|
+
if (this.resetPasswordOptions?.beforeChangePasswordCallback) {
|
|
156
|
+
const user = (await this.model.findOne({ _id: userId }).lean().exec());
|
|
157
|
+
await this.resetPasswordOptions.beforeChangePasswordCallback({ ...user, id: user._id.toString() }, { resetPasswordToken, newPassword, hashedPassword }, this.callbackMethods);
|
|
158
|
+
}
|
|
159
|
+
await this.model.updateOne({ _id: userId }, { $set: { [this.passwordField]: hashedPassword, resetPasswordToken: null } });
|
|
152
160
|
if (this.resetPasswordOptions?.changePasswordCallback) {
|
|
153
161
|
const user = (await this.model.findOne({ _id: userId }).lean().exec());
|
|
154
|
-
|
|
155
|
-
await this.resetPasswordOptions.changePasswordCallback(instance, this.callbackMethods);
|
|
162
|
+
await this.resetPasswordOptions.changePasswordCallback({ ...user, id: user._id.toString() }, this.callbackMethods);
|
|
156
163
|
}
|
|
157
164
|
}
|
|
158
165
|
buildUserFields(user, fieldsToBuild) {
|