@bearei/server-common 0.0.119 → 0.0.121
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/access/access.guard.js +21 -10
- package/dist/access/access.guard.js.map +1 -1
- package/dist/access/access.interceptor.js +3 -1
- package/dist/access/access.interceptor.js.map +1 -1
- package/dist/action-logs/action-logs.service.js +4 -1
- package/dist/action-logs/action-logs.service.js.map +1 -1
- package/dist/app.dto.js +3 -3
- package/dist/app.dto.js.map +1 -1
- package/dist/app.entity.d.ts +1 -1
- package/dist/app.entity.js +22 -17
- package/dist/app.entity.js.map +1 -1
- package/dist/app.interface.d.ts +2 -2
- package/dist/app.interface.js.map +1 -1
- package/dist/base/base.service.d.ts +11 -11
- package/dist/base/base.service.js +111 -33
- package/dist/base/base.service.js.map +1 -1
- package/dist/decorators/is-password.decorator.js +1 -1
- package/dist/decorators/is-password.decorator.js.map +1 -1
- package/dist/decorators/public.decorator.js.map +1 -1
- package/dist/external/external.module.js +5 -1
- package/dist/external/external.module.js.map +1 -1
- package/dist/external/external.service.js +13 -4
- package/dist/external/external.service.js.map +1 -1
- package/dist/jwt/jwt.module.js +16 -4
- package/dist/jwt/jwt.module.js.map +1 -1
- package/dist/jwt/jwt.service.js.map +1 -1
- package/dist/permissions/permissions.guard.js +8 -2
- package/dist/permissions/permissions.guard.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils/error.util.js.map +1 -1
- package/dist/utils/response.util.js +11 -2
- package/dist/utils/response.util.js.map +1 -1
- package/dist/utils/sign.util.js +1 -1
- package/dist/utils/sign.util.js.map +1 -1
- package/package.json +1 -1
|
@@ -28,21 +28,26 @@ let AccessGuard = class AccessGuard {
|
|
|
28
28
|
this.reflector = reflector;
|
|
29
29
|
}
|
|
30
30
|
canActivate(context) {
|
|
31
|
-
const requiredAccesses = this.reflector.getAllAndOverride(decorators_1.IS_PUBLIC_KEY, [
|
|
32
|
-
context.getClass(),
|
|
33
|
-
context.getHandler()
|
|
34
|
-
]);
|
|
31
|
+
const requiredAccesses = this.reflector.getAllAndOverride(decorators_1.IS_PUBLIC_KEY, [context.getClass(), context.getHandler()]);
|
|
35
32
|
const request = context.switchToHttp().getRequest();
|
|
36
33
|
const headers = request.headers;
|
|
37
|
-
const authorization = headers['x-ei-internal-authorization'] ?
|
|
34
|
+
const authorization = headers['x-ei-internal-authorization'] ?
|
|
35
|
+
'x-ei-internal-authorization'
|
|
36
|
+
: 'authorization';
|
|
38
37
|
const token = (0, utils_1.formatToken)(headers)(authorization);
|
|
39
38
|
if (!token) {
|
|
40
|
-
(0, utils_1.throwHTTPError)({
|
|
39
|
+
(0, utils_1.throwHTTPError)({
|
|
40
|
+
code: '401001',
|
|
41
|
+
message: 'Authentication token does not exist'
|
|
42
|
+
})(app_interface_1.HTTPError.UNAUTHORIZED);
|
|
41
43
|
}
|
|
42
44
|
const handleJWTPayload = (request) => {
|
|
43
45
|
const handleCompareResult = (request) => (result) => {
|
|
44
46
|
if (!result) {
|
|
45
|
-
(0, utils_1.throwHTTPError)({
|
|
47
|
+
(0, utils_1.throwHTTPError)({
|
|
48
|
+
code: '401007',
|
|
49
|
+
message: 'Internal service signature verification failed'
|
|
50
|
+
})(app_interface_1.HTTPError.UNAUTHORIZED);
|
|
46
51
|
}
|
|
47
52
|
request['internalAccess'] = result;
|
|
48
53
|
return result;
|
|
@@ -57,14 +62,20 @@ let AccessGuard = class AccessGuard {
|
|
|
57
62
|
serviceName: this.configService.get('service.name')
|
|
58
63
|
})(subject).then(handleCompareResult(request));
|
|
59
64
|
}
|
|
60
|
-
const disableGuestAccess = subject === 'guest' &&
|
|
65
|
+
const disableGuestAccess = subject === 'guest' &&
|
|
66
|
+
!requiredAccesses?.includes(access_interface_1.Access.GUEST);
|
|
61
67
|
if (disableGuestAccess) {
|
|
62
|
-
(0, utils_1.throwHTTPError)({
|
|
68
|
+
(0, utils_1.throwHTTPError)({
|
|
69
|
+
code: '401002',
|
|
70
|
+
message: 'Guest user do not have access to current resource'
|
|
71
|
+
})(app_interface_1.HTTPError.UNAUTHORIZED);
|
|
63
72
|
}
|
|
64
73
|
return Boolean(subject);
|
|
65
74
|
};
|
|
66
75
|
};
|
|
67
|
-
return this.jwtService
|
|
76
|
+
return this.jwtService
|
|
77
|
+
.verifyAsync(token)
|
|
78
|
+
.then(handleJWTPayload(request)(requiredAccesses));
|
|
68
79
|
}
|
|
69
80
|
};
|
|
70
81
|
exports.AccessGuard = AccessGuard;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access.guard.js","sourceRoot":"","sources":["../../src/access/access.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAwE;AACxE,2CAA4C;AAC5C,uCAAsC;AACtC,oDAA0C;AAC1C,8CAA2C;AAE3C,gCAA6C;AAC7C,oCAAiE;AACjE,yDAAyC;AAGlC,IAAM,WAAW,GAAjB,MAAM,WAAW;IAEC;IACA;IACA;IAHrB,YACqB,UAAsB,EACtB,aAA4B,EAC5B,SAAoB;QAFpB,eAAU,GAAV,UAAU,CAAY;QACtB,kBAAa,GAAb,aAAa,CAAe;QAC5B,cAAS,GAAT,SAAS,CAAW;IACtC,CAAC;IAEJ,WAAW,CAAC,OAAyB;QACjC,MAAM,gBAAgB,GAAa,IAAI,CAAC,SAAS,CAAC,iBAAiB,
|
|
1
|
+
{"version":3,"file":"access.guard.js","sourceRoot":"","sources":["../../src/access/access.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAwE;AACxE,2CAA4C;AAC5C,uCAAsC;AACtC,oDAA0C;AAC1C,8CAA2C;AAE3C,gCAA6C;AAC7C,oCAAiE;AACjE,yDAAyC;AAGlC,IAAM,WAAW,GAAjB,MAAM,WAAW;IAEC;IACA;IACA;IAHrB,YACqB,UAAsB,EACtB,aAA4B,EAC5B,SAAoB;QAFpB,eAAU,GAAV,UAAU,CAAY;QACtB,kBAAa,GAAb,aAAa,CAAe;QAC5B,cAAS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
|
const request = context.switchToHttp().getRequest();
|
|
14
14
|
if (!request.headers['x-ei-ip']) {
|
|
15
|
-
request.headers['x-ei-ip'] =
|
|
15
|
+
request.headers['x-ei-ip'] =
|
|
16
|
+
request.headers['x-forwarded-for'] ??
|
|
17
|
+
request.headers['x-real-ip'];
|
|
16
18
|
}
|
|
17
19
|
if (!request.headers['x-ei-subject']) {
|
|
18
20
|
request.headers['x-ei-subject'] = request.subject;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access.interceptor.js","sourceRoot":"","sources":["../../src/access/access.interceptor.ts"],"names":[],"mappings":";;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"access.interceptor.js","sourceRoot":"","sources":["../../src/access/access.interceptor.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAKuB;AAGhB,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC1B,SAAS,CAAC,OAAyB,EAAE,IAAiB;QAClD,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAA;QAEnD,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9B,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;gBACtB,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC;oBAClC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;QACpC,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;YACnC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,OAAO,CAAA;QACrD,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC;YACpC,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,OAAO,CAAC,MAAM,CAAA;QACrD,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,EAAE,CAAA;IACxB,CAAC;CACJ,CAAA;AApBY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;GACA,iBAAiB,CAoB7B"}
|
|
@@ -27,7 +27,10 @@ let ActionLogsService = class ActionLogsService {
|
|
|
27
27
|
create({ headers, enableLogging = true, ...args }) {
|
|
28
28
|
return async (data) => {
|
|
29
29
|
if (enableLogging) {
|
|
30
|
-
await this.externalService.createActionLogs(headers)({
|
|
30
|
+
await this.externalService.createActionLogs(headers)({
|
|
31
|
+
...args,
|
|
32
|
+
data
|
|
33
|
+
});
|
|
31
34
|
}
|
|
32
35
|
};
|
|
33
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-logs.service.js","sourceRoot":"","sources":["../../src/action-logs/action-logs.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyC;AACzC,oDAA6C;AAC7C,0CAA2C;
|
|
1
|
+
{"version":3,"file":"action-logs.service.js","sourceRoot":"","sources":["../../src/action-logs/action-logs.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyC;AACzC,oDAA6C;AAC7C,0CAA2C;AAOpC,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IACG;IAA7B,YAA6B,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IAAG,CAAC;IAEjE,OAAO,CAAC,OAA0B;QAC9B,OAAO,KAAK,EAAE,IAA6B,EAAE,EAAE,CAC3C,IAAI,CAAC,MAAM,CAAC,EAAC,GAAG,OAAO,EAAE,MAAM,EAAE,4BAAY,CAAC,OAAO,EAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IACrE,CAAC;IAED,OAAO,CAAC,OAA0B;QAC9B,OAAO,KAAK,EAAE,IAA6B,EAAE,EAAE,CAC3C,IAAI,CAAC,MAAM,CAAC,EAAC,GAAG,OAAO,EAAE,MAAM,EAAE,4BAAY,CAAC,OAAO,EAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IACrE,CAAC;IAED,MAAM,CAAC,EAAC,OAAO,EAAE,aAAa,GAAG,IAAI,EAAE,GAAG,IAAI,EAA0B;QACpE,OAAO,KAAK,EAAE,IAA6B,EAAE,EAAE;YAC3C,IAAI,aAAa,EAAE,CAAC;gBAChB,MAAM,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;oBACjD,GAAG,IAAI;oBACP,IAAI;iBACP,CAAC,CAAA;YACN,CAAC;QACL,CAAC,CAAA;IACL,CAAC;CACJ,CAAA;AAvBY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAEqC,0BAAe;GADpD,iBAAiB,CAuB7B"}
|
package/dist/app.dto.js
CHANGED
|
@@ -42,7 +42,7 @@ __decorate([
|
|
|
42
42
|
], IndexDTO.prototype, "size", void 0);
|
|
43
43
|
__decorate([
|
|
44
44
|
(0, class_validator_1.IsBoolean)(),
|
|
45
|
-
(0, class_transformer_1.Transform)(({ value }) =>
|
|
45
|
+
(0, class_transformer_1.Transform)(({ value }) => typeof value === 'string' ? value === 'true' : value),
|
|
46
46
|
__metadata("design:type", Boolean)
|
|
47
47
|
], IndexDTO.prototype, "count", void 0);
|
|
48
48
|
__decorate([
|
|
@@ -53,7 +53,7 @@ __decorate([
|
|
|
53
53
|
(0, class_validator_1.ArrayMaxSize)(1024),
|
|
54
54
|
(0, class_validator_1.ArrayMinSize)(1),
|
|
55
55
|
(0, decorators_1.IsNanoid)({ each: true }),
|
|
56
|
-
(0, class_transformer_1.Transform)(({ value }) =>
|
|
56
|
+
(0, class_transformer_1.Transform)(({ value }) => typeof value === 'string' ? value.split(',') : value),
|
|
57
57
|
__metadata("design:type", Array)
|
|
58
58
|
], IndexDTO.prototype, "ids", void 0);
|
|
59
59
|
__decorate([
|
|
@@ -61,7 +61,7 @@ __decorate([
|
|
|
61
61
|
(0, class_validator_1.ArrayMinSize)(2),
|
|
62
62
|
(0, class_validator_1.IsDateString)(undefined, { each: true }),
|
|
63
63
|
(0, decorators_1.IsNanoid)({ each: true }),
|
|
64
|
-
(0, class_transformer_1.Transform)(({ value }) =>
|
|
64
|
+
(0, class_transformer_1.Transform)(({ value }) => typeof value === 'string' ? value.split(',') : value),
|
|
65
65
|
__metadata("design:type", Array)
|
|
66
66
|
], IndexDTO.prototype, "createdAtRange", void 0);
|
|
67
67
|
class ByIdDTO {
|
package/dist/app.dto.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.dto.js","sourceRoot":"","sources":["../src/app.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAA2C;AAC3C,qDAWwB;AAExB,6CAAqC;AAErC,MAAa,QAAQ;IAEjB,EAAE,CAAS;IAKX,IAAI,CAAS;IAMb,IAAI,CAAS;
|
|
1
|
+
{"version":3,"file":"app.dto.js","sourceRoot":"","sources":["../src/app.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAA2C;AAC3C,qDAWwB;AAExB,6CAAqC;AAErC,MAAa,QAAQ;IAEjB,EAAE,CAAS;IAKX,IAAI,CAAS;IAMb,IAAI,CAAS;IAMb,KAAK,CAAU;IAGf,KAAK,CAAQ;IAQb,GAAG,CAAW;IASd,cAAc,CAAW;CAC5B;AAxCD,4BAwCC;AAtCG;IADC,IAAA,qBAAQ,GAAE;;oCACA;AAKX;IAHC,IAAA,0BAAQ,EAAC,EAAC,QAAQ,EAAE,KAAK,EAAC,CAAC;IAC3B,IAAA,qBAAG,EAAC,CAAC,CAAC;IACN,IAAA,6BAAS,EAAC,CAAC,EAAC,KAAK,EAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;;sCAC7C;AAMb;IAJC,IAAA,0BAAQ,EAAC,EAAC,QAAQ,EAAE,KAAK,EAAC,CAAC;IAC3B,IAAA,qBAAG,EAAC,IAAI,CAAC;IACT,IAAA,qBAAG,EAAC,CAAC,CA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IAAA,2BAAS,GAAE;IACX,IAAA,qBAAQ,GAAE;;mCACD;AAGd,MAAa,UAAU;IAGnB,KAAK,CAAQ;CAChB;AAJD,gCAIC;AADG;IAFC,IAAA,2BAAS,GAAE;IACX,IAAA,yBAAO,GAAE;;yCACG;AAGjB,MAAa,QAAQ;IAEjB,KAAK,CAAS;CACjB;AAHD,4BAGC;AADG;IADC,IAAA,qBAAQ,GAAE;;uCACG"}
|
package/dist/app.entity.d.ts
CHANGED
package/dist/app.entity.js
CHANGED
|
@@ -12,12 +12,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.CommonEntity = void 0;
|
|
16
16
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
17
17
|
const nanoid_1 = require("nanoid");
|
|
18
18
|
const typeorm_1 = require("typeorm");
|
|
19
19
|
const app_interface_1 = require("./app.interface");
|
|
20
|
-
let
|
|
20
|
+
let CommonEntity = class CommonEntity extends typeorm_1.BaseEntity {
|
|
21
21
|
privateId;
|
|
22
22
|
id;
|
|
23
23
|
entityStatus;
|
|
@@ -39,61 +39,66 @@ let AppEntity = class AppEntity extends typeorm_1.BaseEntity {
|
|
|
39
39
|
this.entityStatus = app_interface_1.EntityStatus.RECOVERED;
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
|
-
exports.
|
|
42
|
+
exports.CommonEntity = CommonEntity;
|
|
43
43
|
__decorate([
|
|
44
44
|
(0, typeorm_1.PrimaryGeneratedColumn)('identity'),
|
|
45
45
|
__metadata("design:type", Number)
|
|
46
|
-
],
|
|
46
|
+
], CommonEntity.prototype, "privateId", void 0);
|
|
47
47
|
__decorate([
|
|
48
48
|
(0, typeorm_1.Column)({ length: 32, nullable: false, type: 'varchar' }),
|
|
49
49
|
__metadata("design:type", String)
|
|
50
|
-
],
|
|
50
|
+
], CommonEntity.prototype, "id", void 0);
|
|
51
51
|
__decorate([
|
|
52
|
-
(0, typeorm_1.Column)({
|
|
52
|
+
(0, typeorm_1.Column)({
|
|
53
|
+
default: app_interface_1.EntityStatus.RECOVERED,
|
|
54
|
+
enum: app_interface_1.EntityStatus,
|
|
55
|
+
nullable: false,
|
|
56
|
+
type: 'enum'
|
|
57
|
+
}),
|
|
53
58
|
__metadata("design:type", String)
|
|
54
|
-
],
|
|
59
|
+
], CommonEntity.prototype, "entityStatus", void 0);
|
|
55
60
|
__decorate([
|
|
56
61
|
(0, typeorm_1.CreateDateColumn)({ nullable: false, type: 'timestamptz' }),
|
|
57
62
|
__metadata("design:type", String)
|
|
58
|
-
],
|
|
63
|
+
], CommonEntity.prototype, "createdAt", void 0);
|
|
59
64
|
__decorate([
|
|
60
65
|
(0, typeorm_1.UpdateDateColumn)({ nullable: false, type: 'timestamptz' }),
|
|
61
66
|
__metadata("design:type", String)
|
|
62
|
-
],
|
|
67
|
+
], CommonEntity.prototype, "updatedAt", void 0);
|
|
63
68
|
__decorate([
|
|
64
69
|
(0, typeorm_1.VersionColumn)({ nullable: false }),
|
|
65
70
|
__metadata("design:type", String)
|
|
66
|
-
],
|
|
71
|
+
], CommonEntity.prototype, "version", void 0);
|
|
67
72
|
__decorate([
|
|
68
73
|
(0, typeorm_1.DeleteDateColumn)(),
|
|
69
74
|
__metadata("design:type", String)
|
|
70
|
-
],
|
|
75
|
+
], CommonEntity.prototype, "deletedAt", void 0);
|
|
71
76
|
__decorate([
|
|
72
77
|
(0, typeorm_1.BeforeInsert)(),
|
|
73
78
|
__metadata("design:type", Function),
|
|
74
79
|
__metadata("design:paramtypes", []),
|
|
75
80
|
__metadata("design:returntype", void 0)
|
|
76
|
-
],
|
|
81
|
+
], CommonEntity.prototype, "beforeInsert", null);
|
|
77
82
|
__decorate([
|
|
78
83
|
(0, typeorm_1.BeforeUpdate)(),
|
|
79
84
|
__metadata("design:type", Function),
|
|
80
85
|
__metadata("design:paramtypes", []),
|
|
81
86
|
__metadata("design:returntype", void 0)
|
|
82
|
-
],
|
|
87
|
+
], CommonEntity.prototype, "beforeUpdate", null);
|
|
83
88
|
__decorate([
|
|
84
89
|
(0, typeorm_1.BeforeSoftRemove)(),
|
|
85
90
|
__metadata("design:type", Function),
|
|
86
91
|
__metadata("design:paramtypes", []),
|
|
87
92
|
__metadata("design:returntype", void 0)
|
|
88
|
-
],
|
|
93
|
+
], CommonEntity.prototype, "beforeSoftRemove", null);
|
|
89
94
|
__decorate([
|
|
90
95
|
(0, typeorm_1.BeforeRecover)(),
|
|
91
96
|
__metadata("design:type", Function),
|
|
92
97
|
__metadata("design:paramtypes", []),
|
|
93
98
|
__metadata("design:returntype", void 0)
|
|
94
|
-
],
|
|
95
|
-
exports.
|
|
99
|
+
], CommonEntity.prototype, "beforeRecover", null);
|
|
100
|
+
exports.CommonEntity = CommonEntity = __decorate([
|
|
96
101
|
(0, typeorm_1.Index)(['createdAt']),
|
|
97
102
|
(0, typeorm_1.Index)(['id'], { unique: true })
|
|
98
|
-
],
|
|
103
|
+
], CommonEntity);
|
|
99
104
|
//# sourceMappingURL=app.entity.js.map
|
package/dist/app.entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.entity.js","sourceRoot":"","sources":["../src/app.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAyB;AACzB,mCAA6B;AAC7B,qCAagB;AAChB,mDAA4C;AAIrC,IAAM,
|
|
1
|
+
{"version":3,"file":"app.entity.js","sourceRoot":"","sources":["../src/app.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAyB;AACzB,mCAA6B;AAC7B,qCAagB;AAChB,mDAA4C;AAIrC,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,oBAAU;IAExC,SAAS,CAAQ;IAGjB,EAAE,CAAQ;IAQV,YAAY,CAAc;IAG1B,SAAS,CAAQ;IAGjB,SAAS,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C,IAAA,0BAAgB,GAAE;;;;oDAGlB;AAGD;IADC,IAAA,uBAAa,GAAE;;;;iDAGf;uBA9CQ,YAAY;IAFxB,IAAA,eAAK,EAAC,CAAC,WAAW,CAAC,CAAC;IACpB,IAAA,eAAK,EAAC,CAAC,IAAI,CAAC,EAAE,EAAC,MAAM,EAAE,IAAI,EAAC,CAAC;GACjB,YAAY,CA+CxB"}
|
package/dist/app.interface.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import { CommonEntity } from './app.entity';
|
|
3
3
|
export declare enum EntityStatus {
|
|
4
4
|
SOFT_REMOVED = "softRemoved",
|
|
5
5
|
RECOVERED = "recovered"
|
|
@@ -35,7 +35,7 @@ export declare enum Action {
|
|
|
35
35
|
SIGN_UP = "signUp",
|
|
36
36
|
UPDATE = "update"
|
|
37
37
|
}
|
|
38
|
-
export interface FindResult<T extends
|
|
38
|
+
export interface FindResult<T extends CommonEntity> {
|
|
39
39
|
limit: string;
|
|
40
40
|
offset: string;
|
|
41
41
|
results: T[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.interface.js","sourceRoot":"","sources":["../src/app.interface.ts"],"names":[],"mappings":";;;AAGA,IAAY,YAGX;AAHD,WAAY,YAAY;IACpB,4CAA4B,CAAA;IAC5B,uCAAuB,CAAA;AAC3B,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB;AAED,IAAY,QAGX;AAHD,WAAY,QAAQ;IAChB,0BAAc,CAAA;IACd,0BAAc,CAAA;AAClB,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB;
|
|
1
|
+
{"version":3,"file":"app.interface.js","sourceRoot":"","sources":["../src/app.interface.ts"],"names":[],"mappings":";;;AAGA,IAAY,YAGX;AAHD,WAAY,YAAY;IACpB,4CAA4B,CAAA;IAC5B,uCAAuB,CAAA;AAC3B,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB;AAED,IAAY,QAGX;AAHD,WAAY,QAAQ;IAChB,0BAAc,CAAA;IACd,0BAAc,CAAA;AAClB,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB;AAiBD,IAAY,SASX;AATD,WAAY,SAAS;IACjB,uCAA0B,CAAA;IAC1B,oCAAuB,CAAA;IACvB,6CAAgC,CAAA;IAChC,0DAA6C,CAAA;IAC7C,mCAAsB,CAAA;IACtB,+CAAkC,CAAA;IAClC,0CAA6B,CAAA;IAC7B,yDAA4C,CAAA;AAChD,CAAC,EATW,SAAS,yBAAT,SAAS,QASpB;AAED,IAAY,YAGX;AAHD,WAAY,YAAY;IACpB,mCAAmB,CAAA;IACnB,mCAAmB,CAAA;AACvB,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB;AAED,IAAY,MASX;AATD,WAAY,MAAM;IACd,2BAAiB,CAAA;IACjB,2BAAiB,CAAA;IACjB,2BAAiB,CAAA;IACjB,2BAAiB,CAAA;IACjB,4BAAkB,CAAA;IAClB,8BAAoB,CAAA;IACpB,4BAAkB,CAAA;IAClB,2BAAiB,CAAA;AACrB,CAAC,EATW,MAAM,sBAAN,MAAM,QASjB"}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { EntityManager, Repository } from 'typeorm';
|
|
2
2
|
import { ActionLogsOptions, ActionLogsService } from '../action-logs';
|
|
3
|
-
import {
|
|
3
|
+
import { CommonEntity } from '../app.entity';
|
|
4
4
|
import { CountOptions, CountResult, CreateOptions, DelOptions, FindOneOptions, FindOptions, PreValidateOptions, ThrowErrorOptions, UpdateAssociationOptions, UpdateOptions } from './base.interface';
|
|
5
5
|
export declare class BaseService {
|
|
6
6
|
private readonly actionLogsService;
|
|
7
7
|
constructor(actionLogsService: ActionLogsService);
|
|
8
|
-
create<T extends
|
|
9
|
-
del<T extends
|
|
10
|
-
update<T extends
|
|
11
|
-
find<T extends
|
|
8
|
+
create<T extends CommonEntity>({ enableLogging, entityOptions, headers, preValidateOptions, serviceName }: CreateOptions<T>): (repository: Repository<T>) => Promise<(entityManager?: EntityManager) => Promise<T>>;
|
|
9
|
+
del<T extends CommonEntity>({ findOptions, serviceName, headers, enableLogging }: DelOptions<T>): (repository: Repository<T>) => Promise<(entityManager?: EntityManager) => Promise<void>>;
|
|
10
|
+
update<T extends CommonEntity>({ enableLogging, entityOptions, findOptions, headers, preValidateOptions, serviceName }: UpdateOptions<T>): (repository: Repository<T>) => (rawEntity?: T) => Promise<(entityManager?: EntityManager) => Promise<T>>;
|
|
11
|
+
find<T extends CommonEntity>({ findOptions, findManyOptions }: FindOptions<T>): (repository: Repository<T>) => Promise<{
|
|
12
12
|
limit: string;
|
|
13
13
|
offset: string;
|
|
14
14
|
results: T[];
|
|
15
15
|
total: string;
|
|
16
16
|
}>;
|
|
17
|
-
count<T extends
|
|
18
|
-
findOne<T extends
|
|
19
|
-
updateAssociation<T extends
|
|
17
|
+
count<T extends CommonEntity>({ findOptions, findManyOptions }: CountOptions<T>): (repository: Repository<T>) => Promise<CountResult>;
|
|
18
|
+
findOne<T extends CommonEntity>({ serviceName, findOptions, actionLogsOptions }: FindOneOptions<T>): (repository: Repository<T>) => Promise<T>;
|
|
19
|
+
updateAssociation<T extends CommonEntity & {
|
|
20
20
|
protected?: boolean;
|
|
21
21
|
}>({ addEntityOptions, enableLogging, entityIds: rawEntityIds, findOptions, headers, serviceName }: UpdateAssociationOptions<T>): (associationKey: string) => (repository: Repository<T>) => Promise<(entityManager?: EntityManager) => Promise<T[]>>;
|
|
22
|
-
preValidate<T extends
|
|
23
|
-
checkProhibited<T extends
|
|
22
|
+
preValidate<T extends CommonEntity>({ actionLogsOptions, findOptions, orValidateKeysGroups, serviceName, validateMethod }: PreValidateOptions<T>): Promise<(repository: Repository<T>) => Promise<void>>;
|
|
23
|
+
checkProhibited<T extends CommonEntity>(actionLogsOptions?: ActionLogsOptions): (entity: T & {
|
|
24
24
|
protected?: boolean;
|
|
25
25
|
}) => Promise<void>;
|
|
26
|
-
actionLogsSuccess<T extends
|
|
26
|
+
actionLogsSuccess<T extends CommonEntity>(actionLogsOptions: ActionLogsOptions): (entity: T | T[]) => Promise<void>;
|
|
27
27
|
throwError({ errorType, ...args }: ThrowErrorOptions): (actionLogsOptions: ActionLogsOptions) => Promise<void>;
|
|
28
28
|
}
|
|
@@ -31,14 +31,19 @@ let BaseService = class BaseService {
|
|
|
31
31
|
};
|
|
32
32
|
return async (repository) => {
|
|
33
33
|
const preValidate = preValidateOptions?.findOptions &&
|
|
34
|
-
Object.entries(preValidateOptions.findOptions).filter(([, value]) => typeof value !== 'undefined')
|
|
35
|
-
.length;
|
|
34
|
+
Object.entries(preValidateOptions.findOptions).filter(([, value]) => typeof value !== 'undefined').length;
|
|
36
35
|
if (preValidate) {
|
|
37
|
-
await (await this.preValidate({
|
|
36
|
+
await (await this.preValidate({
|
|
37
|
+
...preValidateOptions,
|
|
38
|
+
serviceName,
|
|
39
|
+
actionLogsOptions
|
|
40
|
+
}))(repository);
|
|
38
41
|
}
|
|
39
42
|
const createdEntity = repository.create({ ...entityOptions });
|
|
40
43
|
return async (entityManager) => {
|
|
41
|
-
const entity = await (entityManager ?
|
|
44
|
+
const entity = await (entityManager ?
|
|
45
|
+
entityManager.save(createdEntity)
|
|
46
|
+
: createdEntity.save());
|
|
42
47
|
await this.actionLogsSuccess(actionLogsOptions)(entity);
|
|
43
48
|
return entity;
|
|
44
49
|
};
|
|
@@ -54,12 +59,20 @@ let BaseService = class BaseService {
|
|
|
54
59
|
serviceName
|
|
55
60
|
};
|
|
56
61
|
return async (repository) => {
|
|
57
|
-
const entity = await this.findOne({
|
|
58
|
-
|
|
62
|
+
const entity = await this.findOne({
|
|
63
|
+
serviceName,
|
|
64
|
+
findOptions,
|
|
65
|
+
actionLogsOptions
|
|
66
|
+
})(repository);
|
|
67
|
+
const raw = enableLogging ?
|
|
68
|
+
{ ...actionLogsOptions.raw, entity: { ...entity } }
|
|
69
|
+
: undefined;
|
|
59
70
|
await this.checkProhibited(actionLogsOptions)(entity);
|
|
60
71
|
await entity.softRemove();
|
|
61
72
|
return async (entityManager) => {
|
|
62
|
-
await (entityManager ?
|
|
73
|
+
await (entityManager ?
|
|
74
|
+
entityManager.save(entity)
|
|
75
|
+
: entity.save());
|
|
63
76
|
await this.actionLogsSuccess({ ...actionLogsOptions, raw })(entity);
|
|
64
77
|
};
|
|
65
78
|
};
|
|
@@ -77,7 +90,8 @@ let BaseService = class BaseService {
|
|
|
77
90
|
const handlePreValidateFindOptions = (rawPreValidateFindOptions) => (entity) => (accumulator, currentValue) => currentValue ?
|
|
78
91
|
{
|
|
79
92
|
...accumulator,
|
|
80
|
-
[currentValue]: rawPreValidateFindOptions[currentValue] ??
|
|
93
|
+
[currentValue]: rawPreValidateFindOptions[currentValue] ??
|
|
94
|
+
entity[currentValue]
|
|
81
95
|
}
|
|
82
96
|
: accumulator;
|
|
83
97
|
const updatePreValidate = (preValidateOptions) => (actionLogsOptions) => async ({ entity, repository }) => {
|
|
@@ -97,13 +111,27 @@ let BaseService = class BaseService {
|
|
|
97
111
|
await (await this.preValidate({
|
|
98
112
|
...otherPreValidateOptions,
|
|
99
113
|
actionLogsOptions,
|
|
100
|
-
findOptions: {
|
|
114
|
+
findOptions: {
|
|
115
|
+
...preValidateFindOptions,
|
|
116
|
+
notId: entity.id
|
|
117
|
+
},
|
|
101
118
|
serviceName
|
|
102
119
|
}))(repository);
|
|
103
120
|
};
|
|
104
121
|
return (repository) => async (rawEntity) => {
|
|
105
|
-
const entity = rawEntity ??
|
|
106
|
-
|
|
122
|
+
const entity = rawEntity ??
|
|
123
|
+
(await this.findOne({
|
|
124
|
+
actionLogsOptions,
|
|
125
|
+
findOptions,
|
|
126
|
+
serviceName
|
|
127
|
+
})(repository));
|
|
128
|
+
const raw = enableLogging ?
|
|
129
|
+
{
|
|
130
|
+
...actionLogsOptions.raw,
|
|
131
|
+
entity: { ...entity },
|
|
132
|
+
entityOptions
|
|
133
|
+
}
|
|
134
|
+
: undefined;
|
|
107
135
|
const nextActionLogsOptions = { ...actionLogsOptions, raw };
|
|
108
136
|
await this.checkProhibited(nextActionLogsOptions)(entity);
|
|
109
137
|
if (preValidateOptions) {
|
|
@@ -111,7 +139,9 @@ let BaseService = class BaseService {
|
|
|
111
139
|
}
|
|
112
140
|
repository.merge(entity, entityOptions);
|
|
113
141
|
return async (entityManager) => {
|
|
114
|
-
await (entityManager ?
|
|
142
|
+
await (entityManager ?
|
|
143
|
+
entityManager.save(entity)
|
|
144
|
+
: entity.save());
|
|
115
145
|
await this.actionLogsSuccess({ ...actionLogsOptions, raw })(entity);
|
|
116
146
|
return entity;
|
|
117
147
|
};
|
|
@@ -124,17 +154,25 @@ let BaseService = class BaseService {
|
|
|
124
154
|
const limit = size;
|
|
125
155
|
const offset = (page - 1) * size;
|
|
126
156
|
const where = {
|
|
127
|
-
...Object.entries(otherFindOptions).reduce((accumulator, [key, value]) => typeof value !== 'undefined' ?
|
|
157
|
+
...Object.entries(otherFindOptions).reduce((accumulator, [key, value]) => typeof value !== 'undefined' ?
|
|
158
|
+
{ ...accumulator, [key]: value }
|
|
159
|
+
: accumulator, {}),
|
|
128
160
|
...(ids && { id: (0, typeorm_1.In)(ids) }),
|
|
129
|
-
...(createdAtRange && {
|
|
161
|
+
...(createdAtRange && {
|
|
162
|
+
createdAt: (0, typeorm_1.Between)(createdAtRange[0], createdAtRange[1])
|
|
163
|
+
})
|
|
130
164
|
};
|
|
131
165
|
return async (repository) => {
|
|
132
166
|
const entityName = alias ?? repository.metadata.name;
|
|
133
167
|
const findQueryBuilder = repository.createQueryBuilder(entityName);
|
|
134
|
-
const distinctOnAliasFields = distinctOnFields ?
|
|
168
|
+
const distinctOnAliasFields = distinctOnFields ?
|
|
169
|
+
distinctOnFields.map(field => `${entityName}.${field}`)
|
|
170
|
+
: undefined;
|
|
135
171
|
const orderBy = distinctOnAliasFields ?
|
|
136
172
|
{
|
|
137
|
-
...distinctOnAliasFields.reduce((accumulator, currentValue) => currentValue ?
|
|
173
|
+
...distinctOnAliasFields.reduce((accumulator, currentValue) => currentValue ?
|
|
174
|
+
{ ...accumulator, [currentValue]: 'ASC' }
|
|
175
|
+
: accumulator, {}),
|
|
138
176
|
[`${entityName}.${orderByField}`]: order
|
|
139
177
|
}
|
|
140
178
|
: { [`${entityName}.${orderByField}`]: order };
|
|
@@ -146,9 +184,16 @@ let BaseService = class BaseService {
|
|
|
146
184
|
findQueryBuilder.withDeleted();
|
|
147
185
|
}
|
|
148
186
|
const [entities, { count }] = await Promise.all([
|
|
149
|
-
findQueryBuilder
|
|
187
|
+
findQueryBuilder
|
|
188
|
+
.where(where)
|
|
189
|
+
.limit(limit)
|
|
190
|
+
.offset(offset)
|
|
191
|
+
.getMany(),
|
|
150
192
|
isCount ?
|
|
151
|
-
this.count({
|
|
193
|
+
this.count({
|
|
194
|
+
findOptions: { createdAtRange, ids, ...otherFindOptions },
|
|
195
|
+
findManyOptions
|
|
196
|
+
})(repository)
|
|
152
197
|
: Promise.resolve({ count: undefined })
|
|
153
198
|
]);
|
|
154
199
|
return {
|
|
@@ -166,13 +211,17 @@ let BaseService = class BaseService {
|
|
|
166
211
|
const entityName = alias ?? repository.metadata.name;
|
|
167
212
|
const queryBuilder = repository.createQueryBuilder(entityName);
|
|
168
213
|
const where = {
|
|
169
|
-
...Object.entries(otherFindOptions).reduce((accumulator, [key, value]) => typeof value !== 'undefined' ?
|
|
214
|
+
...Object.entries(otherFindOptions).reduce((accumulator, [key, value]) => typeof value !== 'undefined' ?
|
|
215
|
+
{ ...accumulator, [key]: value }
|
|
216
|
+
: accumulator, {}),
|
|
170
217
|
...(ids && { id: (0, typeorm_1.In)(ids) }),
|
|
171
218
|
...(createdAtRange && {
|
|
172
219
|
createdAt: (0, typeorm_1.Between)(createdAtRange[0], createdAtRange[1])
|
|
173
220
|
})
|
|
174
221
|
};
|
|
175
|
-
const distinctOnAliasFields = distinctOnFields ?
|
|
222
|
+
const distinctOnAliasFields = distinctOnFields ?
|
|
223
|
+
distinctOnFields.map(field => `${entityName}.${field}`)
|
|
224
|
+
: undefined;
|
|
176
225
|
queryBuilder.where(where);
|
|
177
226
|
if (withDeleted) {
|
|
178
227
|
queryBuilder.withDeleted();
|
|
@@ -187,7 +236,9 @@ let BaseService = class BaseService {
|
|
|
187
236
|
findOne({ serviceName, findOptions, actionLogsOptions }) {
|
|
188
237
|
return async (repository) => {
|
|
189
238
|
const entity = await repository.findOne({
|
|
190
|
-
where: Object.entries(findOptions).reduce((accumulator, [key, value]) => typeof value !== 'undefined' ?
|
|
239
|
+
where: Object.entries(findOptions).reduce((accumulator, [key, value]) => typeof value !== 'undefined' ?
|
|
240
|
+
{ ...accumulator, [key]: value }
|
|
241
|
+
: accumulator, {})
|
|
191
242
|
});
|
|
192
243
|
if (!entity) {
|
|
193
244
|
const fields = JSON.stringify(Object.keys(findOptions));
|
|
@@ -238,14 +289,22 @@ let BaseService = class BaseService {
|
|
|
238
289
|
.map(entity => entity.softRemove()));
|
|
239
290
|
await Promise.all(entitiesToRemove.map(this.checkProhibited(actionLogsOptions)));
|
|
240
291
|
const entitiesToRecover = await Promise.all(entities
|
|
241
|
-
.filter(entity => entityIds.includes(entity[associationKey]) &&
|
|
292
|
+
.filter(entity => entityIds.includes(entity[associationKey]) &&
|
|
293
|
+
entity.deletedAt)
|
|
242
294
|
.map(entity => entity.recover()));
|
|
243
|
-
const entityActions = [
|
|
295
|
+
const entityActions = [
|
|
296
|
+
...entitiesToAdd,
|
|
297
|
+
...entitiesToRecover,
|
|
298
|
+
...entitiesToRemove
|
|
299
|
+
];
|
|
244
300
|
return async (entityManager) => {
|
|
245
301
|
const savedEntities = await (entityManager ?
|
|
246
302
|
entityManager.save(entityActions)
|
|
247
303
|
: repository.save(entityActions));
|
|
248
|
-
await this.actionLogsSuccess({
|
|
304
|
+
await this.actionLogsSuccess({
|
|
305
|
+
...actionLogsOptions,
|
|
306
|
+
raw
|
|
307
|
+
})(savedEntities);
|
|
249
308
|
return [...entities, ...entitiesToAdd].filter(filterSoftRemoved);
|
|
250
309
|
};
|
|
251
310
|
};
|
|
@@ -253,11 +312,15 @@ let BaseService = class BaseService {
|
|
|
253
312
|
}
|
|
254
313
|
async preValidate({ actionLogsOptions, findOptions, orValidateKeysGroups, serviceName, validateMethod = 'and' }) {
|
|
255
314
|
const handleOrKeys = ({ notId, ...args }) => (keys) => keys.reduce((accumulator, currentValue) => typeof currentValue !== 'undefined' ?
|
|
256
|
-
{
|
|
315
|
+
{
|
|
316
|
+
...accumulator,
|
|
317
|
+
[currentValue]: args[currentValue]
|
|
318
|
+
}
|
|
257
319
|
: accumulator, (notId ? { id: (0, typeorm_1.Not)(notId) } : {}));
|
|
258
320
|
const handleOrValidateWhere = (findOptions) => async (orValidateKeysGroups) => {
|
|
259
321
|
const { notId, ...otherFindOptions } = findOptions;
|
|
260
|
-
if (orValidateKeysGroups &&
|
|
322
|
+
if (orValidateKeysGroups &&
|
|
323
|
+
!orValidateKeysGroups.every(keys => Array.isArray(keys))) {
|
|
261
324
|
const orValidateKeysGroups = JSON.stringify([
|
|
262
325
|
['key1', 'key2'],
|
|
263
326
|
['key1', 'key3']
|
|
@@ -265,17 +328,23 @@ let BaseService = class BaseService {
|
|
|
265
328
|
await this.throwError({
|
|
266
329
|
code: '400001',
|
|
267
330
|
errorType: app_interface_1.HTTPError.BAD_REQUEST,
|
|
268
|
-
message: `When using "or" as a validation method,
|
|
331
|
+
message: `When using "or" as a validation method,
|
|
332
|
+
"orValidateKeysGroups" must be a nested array.
|
|
269
333
|
${orValidateKeysGroups}`
|
|
270
334
|
})(actionLogsOptions);
|
|
271
335
|
}
|
|
272
|
-
const flattedValidateOrKeys = [
|
|
336
|
+
const flattedValidateOrKeys = [
|
|
337
|
+
...new Set(orValidateKeysGroups?.flat())
|
|
338
|
+
];
|
|
273
339
|
const findOrOptions = orValidateKeysGroups?.map(handleOrKeys(findOptions)) ?? [];
|
|
274
340
|
return {
|
|
275
341
|
where: [
|
|
276
342
|
...Object.entries(otherFindOptions)
|
|
277
343
|
.filter(([key]) => !flattedValidateOrKeys.includes(key))
|
|
278
|
-
.map(([key, value]) => ({
|
|
344
|
+
.map(([key, value]) => ({
|
|
345
|
+
...(notId && { id: (0, typeorm_1.Not)(notId) }),
|
|
346
|
+
[key]: value
|
|
347
|
+
})),
|
|
279
348
|
...findOrOptions
|
|
280
349
|
],
|
|
281
350
|
findOrOptions
|
|
@@ -285,12 +354,20 @@ let BaseService = class BaseService {
|
|
|
285
354
|
const { where: orWhere, findOrOptions } = validateMethod === 'or' ?
|
|
286
355
|
await handleOrValidateWhere(findOptions)(orValidateKeysGroups)
|
|
287
356
|
: {};
|
|
288
|
-
const where = validateMethod === 'and' ?
|
|
357
|
+
const where = validateMethod === 'and' ?
|
|
358
|
+
{ ...otherFindOptions, ...(notId && { id: (0, typeorm_1.Not)(notId) }) }
|
|
359
|
+
: orWhere;
|
|
289
360
|
return async (repository) => {
|
|
290
|
-
const entity = await repository.findOne({
|
|
361
|
+
const entity = await repository.findOne({
|
|
362
|
+
select: Object.keys(otherFindOptions),
|
|
363
|
+
where
|
|
364
|
+
});
|
|
291
365
|
if (entity) {
|
|
292
366
|
const fields = JSON.stringify(Object.keys({
|
|
293
|
-
...findOrOptions?.reduce((accumulator, currentValue) => ({
|
|
367
|
+
...findOrOptions?.reduce((accumulator, currentValue) => ({
|
|
368
|
+
...accumulator,
|
|
369
|
+
...currentValue
|
|
370
|
+
}), {}),
|
|
294
371
|
...otherFindOptions
|
|
295
372
|
}));
|
|
296
373
|
await this.throwError({
|
|
@@ -324,7 +401,8 @@ let BaseService = class BaseService {
|
|
|
324
401
|
if (actionLogsOptions) {
|
|
325
402
|
await this.actionLogsService.failure({
|
|
326
403
|
...actionLogsOptions,
|
|
327
|
-
message: error
|
|
404
|
+
message: error
|
|
405
|
+
?.message
|
|
328
406
|
})({ error });
|
|
329
407
|
}
|
|
330
408
|
throw error;
|