@bearei/server-common 0.0.147 → 0.0.149
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.interface.js → access.enum.js} +1 -1
- package/dist/access/access.enum.js.map +1 -0
- package/dist/access/access.guard.js +9 -10
- package/dist/access/access.guard.js.map +1 -1
- package/dist/access/access.interceptor.js +15 -7
- package/dist/access/access.interceptor.js.map +1 -1
- package/dist/access/index.d.ts +1 -1
- package/dist/access/index.js +1 -1
- package/dist/access/index.js.map +1 -1
- package/dist/action-log/action-log.interface.d.ts +2 -1
- package/dist/action-log/action-log.service.js +3 -3
- package/dist/action-log/action-log.service.js.map +1 -1
- package/dist/app.entity.d.ts +1 -1
- package/dist/app.entity.js +4 -4
- package/dist/app.entity.js.map +1 -1
- package/dist/app.enum.d.ts +23 -0
- package/dist/app.enum.js +31 -0
- package/dist/app.enum.js.map +1 -0
- package/dist/app.interface.d.ts +0 -32
- package/dist/app.interface.js +0 -38
- package/dist/app.interface.js.map +1 -1
- package/dist/base/base.interface.d.ts +3 -3
- package/dist/base/base.service.d.ts +1 -1
- package/dist/base/base.service.js +20 -24
- package/dist/base/base.service.js.map +1 -1
- package/dist/decorators/is-captcha.decorator.js +2 -1
- package/dist/decorators/is-captcha.decorator.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/external/external.interface.d.ts +3 -1
- package/dist/external/external.service.js +3 -4
- package/dist/external/external.service.js.map +1 -1
- package/dist/jwt/jwt.service.js +1 -2
- package/dist/jwt/jwt.service.js.map +1 -1
- package/dist/permission/index.d.ts +1 -0
- package/dist/permission/index.js +1 -0
- package/dist/permission/index.js.map +1 -1
- package/dist/permission/permission.enum.d.ts +74 -0
- package/dist/permission/permission.enum.js +79 -0
- package/dist/permission/permission.enum.js.map +1 -0
- package/dist/permission/permission.guard.d.ts +0 -74
- package/dist/permission/permission.guard.js +3 -78
- package/dist/permission/permission.guard.js.map +1 -1
- package/dist/subscription/index.d.ts +1 -0
- package/dist/subscription/index.js +1 -0
- package/dist/subscription/index.js.map +1 -1
- package/dist/subscription/subscription.enum.d.ts +5 -0
- package/dist/subscription/subscription.enum.js +10 -0
- package/dist/subscription/subscription.enum.js.map +1 -0
- package/dist/subscription/subscription.guard.d.ts +0 -5
- package/dist/subscription/subscription.guard.js +4 -10
- package/dist/subscription/subscription.guard.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils/error.utils.d.ts +1 -1
- package/dist/utils/error.utils.js +9 -9
- package/dist/utils/error.utils.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/sign.utils.js +3 -4
- package/dist/utils/sign.utils.js.map +1 -1
- package/dist/utils/utils.enum.d.ts +10 -0
- package/dist/utils/utils.enum.js +15 -0
- package/dist/utils/utils.enum.js.map +1 -0
- package/package.json +1 -1
- package/dist/access/access.interface.js.map +0 -1
- /package/dist/access/{access.interface.d.ts → access.enum.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access.enum.js","sourceRoot":"","sources":["../../src/access/access.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,MAGX;AAHD,WAAY,MAAM;IACV,yBAAe,CAAA;IACf,uBAAa,CAAA;AACrB,CAAC,EAHW,MAAM,sBAAN,MAAM,QAGjB"}
|
|
@@ -13,11 +13,10 @@ exports.AccessGuard = void 0;
|
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const config_1 = require("@nestjs/config");
|
|
15
15
|
const core_1 = require("@nestjs/core");
|
|
16
|
-
const app_interface_1 = require("../app.interface");
|
|
17
16
|
const decorators_1 = require("../decorators");
|
|
18
17
|
const jwt_1 = require("../jwt");
|
|
19
18
|
const utils_1 = require("../utils");
|
|
20
|
-
const
|
|
19
|
+
const access_enum_1 = require("./access.enum");
|
|
21
20
|
let AccessGuard = class AccessGuard {
|
|
22
21
|
configService;
|
|
23
22
|
jwtService;
|
|
@@ -37,18 +36,18 @@ let AccessGuard = class AccessGuard {
|
|
|
37
36
|
const authorization = headers['x-ei-internal-authorization'] ? 'x-ei-internal-authorization' : 'authorization';
|
|
38
37
|
const token = (0, utils_1.formatToken)(headers)(authorization);
|
|
39
38
|
if (!token) {
|
|
40
|
-
(0, utils_1.throwHTTPError)({ code: '401001', message: 'Authentication token does not exist' })(
|
|
39
|
+
(0, utils_1.throwHTTPError)({ code: '401001', message: 'Authentication token does not exist' })(utils_1.HTTPError.UNAUTHORIZED);
|
|
41
40
|
}
|
|
42
41
|
const handleJWTPayload = (request) => {
|
|
43
|
-
const handleCompareResult = (request) => (
|
|
44
|
-
if (!
|
|
42
|
+
const handleCompareResult = (request) => (value) => {
|
|
43
|
+
if (!value) {
|
|
45
44
|
(0, utils_1.throwHTTPError)({
|
|
46
45
|
code: '401007',
|
|
47
46
|
message: 'Internal service signature verification failed'
|
|
48
|
-
})(
|
|
47
|
+
})(utils_1.HTTPError.UNAUTHORIZED);
|
|
49
48
|
}
|
|
50
|
-
request.internalAccess =
|
|
51
|
-
return
|
|
49
|
+
request.internalAccess = value;
|
|
50
|
+
return value;
|
|
52
51
|
};
|
|
53
52
|
return (requiredAccesses) => ({ sub: subject, iss: issuer }) => {
|
|
54
53
|
request.issuer = issuer;
|
|
@@ -60,12 +59,12 @@ let AccessGuard = class AccessGuard {
|
|
|
60
59
|
serviceName: this.configService.get('service.name')
|
|
61
60
|
})(subject).then(handleCompareResult(request));
|
|
62
61
|
}
|
|
63
|
-
const disabledGuestAccess = subject === 'guest' && !new Set(requiredAccesses).has(
|
|
62
|
+
const disabledGuestAccess = subject === 'guest' && !new Set(requiredAccesses).has(access_enum_1.Access.GUEST);
|
|
64
63
|
if (disabledGuestAccess) {
|
|
65
64
|
(0, utils_1.throwHTTPError)({
|
|
66
65
|
code: '401002',
|
|
67
66
|
message: 'Guest user do not have access to current resource'
|
|
68
|
-
})(
|
|
67
|
+
})(utils_1.HTTPError.UNAUTHORIZED);
|
|
69
68
|
}
|
|
70
69
|
return Boolean(subject);
|
|
71
70
|
};
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"access.guard.js","sourceRoot":"","sources":["../../src/access/access.guard.ts"],"names":[],"mappings":"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"}
|
|
@@ -8,18 +8,26 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.AccessInterceptor = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
|
+
const utils_1 = require("../utils");
|
|
11
12
|
let AccessInterceptor = class AccessInterceptor {
|
|
12
13
|
intercept(context, next) {
|
|
13
14
|
const request = context.switchToHttp().getRequest();
|
|
14
|
-
if (
|
|
15
|
-
|
|
15
|
+
if (request.headers['x-ei-internal-authorization']) {
|
|
16
|
+
return next.handle();
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
request.headers['x-ei-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
request.headers['x-ei-
|
|
18
|
+
const invalidRequestHeader = [
|
|
19
|
+
request.headers['x-ei-domainId'],
|
|
20
|
+
request.headers['x-ei-ip'],
|
|
21
|
+
request.headers['x-ei-subject'],
|
|
22
|
+
request.headers['x-ei-subscription']
|
|
23
|
+
].some(Boolean);
|
|
24
|
+
if (invalidRequestHeader) {
|
|
25
|
+
(0, utils_1.throwHTTPError)({ code: '400007', message: 'Invalid request header' })(utils_1.HTTPError.BAD_REQUEST);
|
|
22
26
|
}
|
|
27
|
+
request.headers['x-ei-domainId'] = request.issuer;
|
|
28
|
+
request.headers['x-ei-ip'] = request.headers['x-forwarded-for'] ?? request.headers['x-real-ip'];
|
|
29
|
+
request.headers['x-ei-subject'] = request.subject;
|
|
30
|
+
request.headers['x-ei-subscription'] = Boolean(request.subscription);
|
|
23
31
|
return next.handle();
|
|
24
32
|
}
|
|
25
33
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access.interceptor.js","sourceRoot":"","sources":["../../src/access/access.interceptor.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAyF;
|
|
1
|
+
{"version":3,"file":"access.interceptor.js","sourceRoot":"","sources":["../../src/access/access.interceptor.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAyF;AAEzF,oCAAkD;AAG3C,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IACtB,SAAS,CAAC,OAAyB,EAAE,IAAiB;QAC9C,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAe,CAAA;QAEhE,IAAI,OAAO,CAAC,OAAO,CAAC,6BAA6B,CAAC,EAAE,CAAC;YAC7C,OAAO,IAAI,CAAC,MAAM,EAAE,CAAA;QAC5B,CAAC;QAED,MAAM,oBAAoB,GAAG;YACrB,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC;YAChC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;YAC1B,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC;YAC/B,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC;SAC3C,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAEf,IAAI,oBAAoB,EAAE,CAAC;YACnB,IAAA,sBAAc,EAAC,EAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,wBAAwB,EAAC,CAAC,CAAC,iBAAS,CAAC,WAAW,CAAC,CAAA;QAClG,CAAC;QAED,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,OAAO,CAAC,MAAM,CAAA;QACjD,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;QAC/F,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,OAAO,CAAA;QACjD,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;QAEpE,OAAO,IAAI,CAAC,MAAM,EAAE,CAAA;IAC5B,CAAC;CACR,CAAA;AA1BY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;GACA,iBAAiB,CA0B7B"}
|
package/dist/access/index.d.ts
CHANGED
package/dist/access/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./access.enum"), exports);
|
|
17
18
|
__exportStar(require("./access.guard"), exports);
|
|
18
19
|
__exportStar(require("./access.interceptor"), exports);
|
|
19
|
-
__exportStar(require("./access.interface"), exports);
|
|
20
20
|
//# sourceMappingURL=index.js.map
|
package/dist/access/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/access/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA8B;AAC9B,uDAAoC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/access/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B;AAC7B,iDAA8B;AAC9B,uDAAoC"}
|
|
@@ -11,7 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ActionLogService = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
|
-
const
|
|
14
|
+
const app_enum_1 = require("../app.enum");
|
|
15
15
|
const external_1 = require("../external");
|
|
16
16
|
let ActionLogService = class ActionLogService {
|
|
17
17
|
externalService;
|
|
@@ -19,10 +19,10 @@ let ActionLogService = class ActionLogService {
|
|
|
19
19
|
this.externalService = externalService;
|
|
20
20
|
}
|
|
21
21
|
success(options) {
|
|
22
|
-
return async (data) => this.create({ ...options, result:
|
|
22
|
+
return async (data) => this.create({ ...options, result: app_enum_1.ActionResult.SUCCESS })(data);
|
|
23
23
|
}
|
|
24
24
|
failure(options) {
|
|
25
|
-
return async (data) => this.create({ ...options, result:
|
|
25
|
+
return async (data) => this.create({ ...options, result: app_enum_1.ActionResult.FAILURE })(data);
|
|
26
26
|
}
|
|
27
27
|
create({ headers, enabledLog = true, ...restOptions }) {
|
|
28
28
|
return async (data) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-log.service.js","sourceRoot":"","sources":["../../src/action-log/action-log.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"action-log.service.js","sourceRoot":"","sources":["../../src/action-log/action-log.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyC;AACzC,0CAAwC;AACxC,0CAA2C;AAIpC,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACQ;IAA7B,YAA6B,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IAAG,CAAC;IAEjE,OAAO,CAAC,OAAyB;QACzB,OAAO,KAAK,EAAE,IAA6B,EAAE,EAAE,CACvC,IAAI,CAAC,MAAM,CAAC,EAAC,GAAG,OAAO,EAAE,MAAM,EAAE,uBAAY,CAAC,OAAO,EAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IAC7E,CAAC;IAED,OAAO,CAAC,OAAyB;QACzB,OAAO,KAAK,EAAE,IAA6B,EAAE,EAAE,CACvC,IAAI,CAAC,MAAM,CAAC,EAAC,GAAG,OAAO,EAAE,MAAM,EAAE,uBAAY,CAAC,OAAO,EAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IAC7E,CAAC;IAED,MAAM,CAAC,EAAC,OAAO,EAAE,UAAU,GAAG,IAAI,EAAE,GAAG,WAAW,EAAyB;QACnE,OAAO,KAAK,EAAE,IAA6B,EAAE,EAAE;YACvC,IAAI,CAAC,UAAU,EAAE,CAAC;gBACV,OAAM;YACd,CAAC;YAED,MAAM,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,EAAC,GAAG,WAAW,EAAE,IAAI,EAAC,CAAC,CAAA;QACnF,CAAC,CAAA;IACT,CAAC;CACR,CAAA;AAtBY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;qCAEyC,0BAAe;GADxD,gBAAgB,CAsB5B"}
|
package/dist/app.entity.d.ts
CHANGED
package/dist/app.entity.js
CHANGED
|
@@ -16,7 +16,7 @@ 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
|
-
const
|
|
19
|
+
const app_enum_1 = require("./app.enum");
|
|
20
20
|
let CommonEntity = class CommonEntity extends typeorm_1.BaseEntity {
|
|
21
21
|
primaryId;
|
|
22
22
|
id;
|
|
@@ -34,10 +34,10 @@ let CommonEntity = class CommonEntity extends typeorm_1.BaseEntity {
|
|
|
34
34
|
}
|
|
35
35
|
beforeSoftRemove() {
|
|
36
36
|
this.deletedAt = dayjs_1.default.utc().toDate();
|
|
37
|
-
this.entityStatus =
|
|
37
|
+
this.entityStatus = app_enum_1.EntityStatus.SOFT_REMOVED;
|
|
38
38
|
}
|
|
39
39
|
beforeRecover() {
|
|
40
|
-
this.entityStatus =
|
|
40
|
+
this.entityStatus = app_enum_1.EntityStatus.RECOVERED;
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
exports.CommonEntity = CommonEntity;
|
|
@@ -50,7 +50,7 @@ __decorate([
|
|
|
50
50
|
__metadata("design:type", String)
|
|
51
51
|
], CommonEntity.prototype, "id", void 0);
|
|
52
52
|
__decorate([
|
|
53
|
-
(0, typeorm_1.Column)({ default:
|
|
53
|
+
(0, typeorm_1.Column)({ default: app_enum_1.EntityStatus.STANDARD, enum: app_enum_1.EntityStatus, nullable: false, type: 'enum' }),
|
|
54
54
|
__metadata("design:type", String)
|
|
55
55
|
], CommonEntity.prototype, "entityStatus", void 0);
|
|
56
56
|
__decorate([
|
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,
|
|
1
|
+
{"version":3,"file":"app.entity.js","sourceRoot":"","sources":["../src/app.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAyB;AACzB,mCAA6B;AAC7B,qCAagB;AAChB,yCAAuC;AAIhC,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,oBAAU;IAEpC,SAAS,CAAQ;IAGjB,EAAE,CAAQ;IAGV,YAAY,CAAc;IAG1B,SAAS,CAAM;IAGf,SAAS,CAAM;IAGf,OAAO,CAAQ;IAGf,SAAS,CAAM;IAGf,YAAY;QACJ,IAAI,CAAC,EAAE,GAAG,IAAA,eAAM,GAAE,CAAA;QAClB,IAAI,CAAC,SAAS,GAAG,eAAK,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAA;IAC7C,CAAC;IAGD,YAAY;QACJ,IAAI,CAAC,SAAS,GAAG,eAAK,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAA;IAC7C,CAAC;IAGD,gBAAgB;QACR,IAAI,CAAC,SAAS,GAAG,eAAK,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAA;QACrC,IAAI,CAAC,YAAY,GAAG,uBAAY,CAAC,YAAY,CAAA;IACrD,CAAC;IAGD,aAAa;QACL,IAAI,CAAC,YAAY,GAAG,uBAAY,CAAC,SAAS,CAAA;IAClD,CAAC;CACR,CAAA;AA3CY,oCAAY;AAEjB;IADC,IAAA,gCAAsB,EAAC,UAAU,CAAC;;+CAClB;AAGjB;IADC,IAAA,gBAAM,EAAC,EAAC,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAC,CAAC;;wCAC7C;AAGV;IADC,IAAA,gBAAM,EAAC,EAAC,OAAO,EAAE,uBAAY,CAAC,QAAQ,EAAE,IAAI,EAAE,uBAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAC,CAAC;;kDAClE;AAG1B;IADC,IAAA,0BAAgB,EAAC,EAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,EAAC,CAAC;8BAC9C,IAAI;+CAAA;AAGf;IADC,IAAA,0BAAgB,EAAC,EAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,EAAC,CAAC;8BAC9C,IAAI;+CAAA;AAGf;IADC,IAAA,uBAAa,EAAC,EAAC,QAAQ,EAAE,KAAK,EAAC,CAAC;;6CAClB;AAGf;IADC,IAAA,0BAAgB,EAAC,EAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,aAAa,EAAC,CAAC;8BAC5C,IAAI;+CAAA;AAGf;IADC,IAAA,sBAAY,GAAE;;;;gDAId;AAGD;IADC,IAAA,sBAAY,GAAE;;;;gDAGd;AAGD;IADC,IAAA,0BAAgB,GAAE;;;;oDAIlB;AAGD;IADC,IAAA,uBAAa,GAAE;;;;iDAGf;uBA1CI,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,CA2CxB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare enum EntityStatus {
|
|
2
|
+
RECOVERED = "recovered",
|
|
3
|
+
SOFT_REMOVED = "softRemoved",
|
|
4
|
+
STANDARD = "standard"
|
|
5
|
+
}
|
|
6
|
+
export declare enum Language {
|
|
7
|
+
EN_US = "enUS",
|
|
8
|
+
ZH_CN = "zhCN"
|
|
9
|
+
}
|
|
10
|
+
export declare enum ActionResult {
|
|
11
|
+
FAILURE = "failure",
|
|
12
|
+
SUCCESS = "success"
|
|
13
|
+
}
|
|
14
|
+
export declare enum Action {
|
|
15
|
+
CREATE = "create",
|
|
16
|
+
DELETE = "delete",
|
|
17
|
+
EXPORT = "export",
|
|
18
|
+
IMPORT = "import",
|
|
19
|
+
SIGN_IN = "signIn",
|
|
20
|
+
SIGN_OUT = "signOut",
|
|
21
|
+
SIGN_UP = "signUp",
|
|
22
|
+
UPDATE = "update"
|
|
23
|
+
}
|
package/dist/app.enum.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Action = exports.ActionResult = exports.Language = exports.EntityStatus = void 0;
|
|
4
|
+
var EntityStatus;
|
|
5
|
+
(function (EntityStatus) {
|
|
6
|
+
EntityStatus["RECOVERED"] = "recovered";
|
|
7
|
+
EntityStatus["SOFT_REMOVED"] = "softRemoved";
|
|
8
|
+
EntityStatus["STANDARD"] = "standard";
|
|
9
|
+
})(EntityStatus || (exports.EntityStatus = EntityStatus = {}));
|
|
10
|
+
var Language;
|
|
11
|
+
(function (Language) {
|
|
12
|
+
Language["EN_US"] = "enUS";
|
|
13
|
+
Language["ZH_CN"] = "zhCN";
|
|
14
|
+
})(Language || (exports.Language = Language = {}));
|
|
15
|
+
var ActionResult;
|
|
16
|
+
(function (ActionResult) {
|
|
17
|
+
ActionResult["FAILURE"] = "failure";
|
|
18
|
+
ActionResult["SUCCESS"] = "success";
|
|
19
|
+
})(ActionResult || (exports.ActionResult = ActionResult = {}));
|
|
20
|
+
var Action;
|
|
21
|
+
(function (Action) {
|
|
22
|
+
Action["CREATE"] = "create";
|
|
23
|
+
Action["DELETE"] = "delete";
|
|
24
|
+
Action["EXPORT"] = "export";
|
|
25
|
+
Action["IMPORT"] = "import";
|
|
26
|
+
Action["SIGN_IN"] = "signIn";
|
|
27
|
+
Action["SIGN_OUT"] = "signOut";
|
|
28
|
+
Action["SIGN_UP"] = "signUp";
|
|
29
|
+
Action["UPDATE"] = "update";
|
|
30
|
+
})(Action || (exports.Action = Action = {}));
|
|
31
|
+
//# sourceMappingURL=app.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.enum.js","sourceRoot":"","sources":["../src/app.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,YAIX;AAJD,WAAY,YAAY;IAChB,uCAAuB,CAAA;IACvB,4CAA4B,CAAA;IAC5B,qCAAqB,CAAA;AAC7B,CAAC,EAJW,YAAY,4BAAZ,YAAY,QAIvB;AAED,IAAY,QAGX;AAHD,WAAY,QAAQ;IACZ,0BAAc,CAAA;IACd,0BAAc,CAAA;AACtB,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB;AAED,IAAY,YAGX;AAHD,WAAY,YAAY;IAChB,mCAAmB,CAAA;IACnB,mCAAmB,CAAA;AAC3B,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB;AAED,IAAY,MASX;AATD,WAAY,MAAM;IACV,2BAAiB,CAAA;IACjB,2BAAiB,CAAA;IACjB,2BAAiB,CAAA;IACjB,2BAAiB,CAAA;IACjB,4BAAkB,CAAA;IAClB,8BAAoB,CAAA;IACpB,4BAAkB,CAAA;IAClB,2BAAiB,CAAA;AACzB,CAAC,EATW,MAAM,sBAAN,MAAM,QASjB"}
|
package/dist/app.interface.d.ts
CHANGED
|
@@ -1,40 +1,8 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import { CommonEntity } from './app.entity';
|
|
3
|
-
export declare enum EntityStatus {
|
|
4
|
-
SOFT_REMOVED = "softRemoved",
|
|
5
|
-
RECOVERED = "recovered"
|
|
6
|
-
}
|
|
7
|
-
export declare enum Language {
|
|
8
|
-
EN_US = "enUS",
|
|
9
|
-
ZH_CN = "zhCN"
|
|
10
|
-
}
|
|
11
3
|
export type Order = 'ASC' | 'DESC';
|
|
12
4
|
export type CustomHeaders = Record<'x-ei-client' | 'x-ei-domain-id' | 'x-ei-internal-authorization' | 'x-ei-ip' | 'x-ei-subject' | 'x-ei-subscription', string>;
|
|
13
5
|
export type RequestHeaders = Record<string, string> | CustomHeaders | AxiosRequestConfig['headers'];
|
|
14
|
-
export declare enum HTTPError {
|
|
15
|
-
BAD_REQUEST = "badRequest",
|
|
16
|
-
FORBIDDEN = "forbidden",
|
|
17
|
-
HTTP_EXCEPTION = "httpException",
|
|
18
|
-
INTERNAL_SERVER_ERROR = "internalServerError",
|
|
19
|
-
NOT_FOUND = "notFound",
|
|
20
|
-
REQUEST_TIMEOUT = "requestTimeout",
|
|
21
|
-
UNAUTHORIZED = "unauthorized",
|
|
22
|
-
UNPROCESSABLE_ENTITY = "unprocessableEntity"
|
|
23
|
-
}
|
|
24
|
-
export declare enum ActionResult {
|
|
25
|
-
FAILURE = "failure",
|
|
26
|
-
SUCCESS = "success"
|
|
27
|
-
}
|
|
28
|
-
export declare enum Action {
|
|
29
|
-
CREATE = "create",
|
|
30
|
-
DELETE = "delete",
|
|
31
|
-
EXPORT = "export",
|
|
32
|
-
IMPORT = "import",
|
|
33
|
-
SIGN_IN = "signIn",
|
|
34
|
-
SIGN_OUT = "signOut",
|
|
35
|
-
SIGN_UP = "signUp",
|
|
36
|
-
UPDATE = "update"
|
|
37
|
-
}
|
|
38
6
|
export interface FindResult<T extends CommonEntity> {
|
|
39
7
|
limit: string;
|
|
40
8
|
offset: string;
|
package/dist/app.interface.js
CHANGED
|
@@ -1,41 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Action = exports.ActionResult = exports.HTTPError = exports.Language = exports.EntityStatus = void 0;
|
|
4
|
-
var EntityStatus;
|
|
5
|
-
(function (EntityStatus) {
|
|
6
|
-
EntityStatus["SOFT_REMOVED"] = "softRemoved";
|
|
7
|
-
EntityStatus["RECOVERED"] = "recovered";
|
|
8
|
-
})(EntityStatus || (exports.EntityStatus = EntityStatus = {}));
|
|
9
|
-
var Language;
|
|
10
|
-
(function (Language) {
|
|
11
|
-
Language["EN_US"] = "enUS";
|
|
12
|
-
Language["ZH_CN"] = "zhCN";
|
|
13
|
-
})(Language || (exports.Language = Language = {}));
|
|
14
|
-
var HTTPError;
|
|
15
|
-
(function (HTTPError) {
|
|
16
|
-
HTTPError["BAD_REQUEST"] = "badRequest";
|
|
17
|
-
HTTPError["FORBIDDEN"] = "forbidden";
|
|
18
|
-
HTTPError["HTTP_EXCEPTION"] = "httpException";
|
|
19
|
-
HTTPError["INTERNAL_SERVER_ERROR"] = "internalServerError";
|
|
20
|
-
HTTPError["NOT_FOUND"] = "notFound";
|
|
21
|
-
HTTPError["REQUEST_TIMEOUT"] = "requestTimeout";
|
|
22
|
-
HTTPError["UNAUTHORIZED"] = "unauthorized";
|
|
23
|
-
HTTPError["UNPROCESSABLE_ENTITY"] = "unprocessableEntity";
|
|
24
|
-
})(HTTPError || (exports.HTTPError = HTTPError = {}));
|
|
25
|
-
var ActionResult;
|
|
26
|
-
(function (ActionResult) {
|
|
27
|
-
ActionResult["FAILURE"] = "failure";
|
|
28
|
-
ActionResult["SUCCESS"] = "success";
|
|
29
|
-
})(ActionResult || (exports.ActionResult = ActionResult = {}));
|
|
30
|
-
var Action;
|
|
31
|
-
(function (Action) {
|
|
32
|
-
Action["CREATE"] = "create";
|
|
33
|
-
Action["DELETE"] = "delete";
|
|
34
|
-
Action["EXPORT"] = "export";
|
|
35
|
-
Action["IMPORT"] = "import";
|
|
36
|
-
Action["SIGN_IN"] = "signIn";
|
|
37
|
-
Action["SIGN_OUT"] = "signOut";
|
|
38
|
-
Action["SIGN_UP"] = "signUp";
|
|
39
|
-
Action["UPDATE"] = "update";
|
|
40
|
-
})(Action || (exports.Action = Action = {}));
|
|
41
3
|
//# sourceMappingURL=app.interface.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.interface.js","sourceRoot":"","sources":["../src/app.interface.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"app.interface.js","sourceRoot":"","sources":["../src/app.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DeepPartial, FindManyOptions, FindOptionsWhere, Repository } from 'typeorm';
|
|
2
2
|
import { ActionLogOptions } from '../action-log';
|
|
3
3
|
import { IndexDTO, NotIdDTO } from '../app.dto';
|
|
4
|
-
import {
|
|
5
|
-
import { ThrowHTTPErrorOptions } from '../utils';
|
|
4
|
+
import { RequestHeaders } from '../app.interface';
|
|
5
|
+
import { HTTPError, ThrowHTTPErrorOptions } from '../utils';
|
|
6
6
|
export interface BaseServiceOptions<T> extends Pick<ActionLogOptions, 'enabledLog'> {
|
|
7
7
|
entityOptions: DeepPartial<T>;
|
|
8
8
|
findOptions: FindOptionsWhere<T>;
|
|
@@ -36,8 +36,8 @@ export type CountResult = {
|
|
|
36
36
|
count?: string;
|
|
37
37
|
};
|
|
38
38
|
export interface UpdateAssociationOptions<T> extends Omit<BaseServiceOptions<T>, 'entityOptions' | 'findOptions'>, Pick<FindOptions<T>, 'findOptions'> {
|
|
39
|
-
updateEntityOptions?: Record<string, DeepPartial<T>>;
|
|
40
39
|
entityIds: string[];
|
|
40
|
+
updateEntityOptions?: Record<string, DeepPartial<T>>;
|
|
41
41
|
}
|
|
42
42
|
export interface FindOneOptions<T> extends Omit<BaseServiceOptions<T>, 'headers' | 'entityOptions'> {
|
|
43
43
|
actionLogOptions?: ActionLogOptions;
|
|
@@ -24,5 +24,5 @@ export declare class BaseService {
|
|
|
24
24
|
protected?: boolean;
|
|
25
25
|
}) => Promise<void>;
|
|
26
26
|
actionLogSuccess<T extends CommonEntity>(actionLogOptions: ActionLogOptions): (entity: T | T[]) => Promise<void>;
|
|
27
|
-
throwError({ errorType, ...restOptions }: ThrowErrorOptions): (actionLogOptions
|
|
27
|
+
throwError({ errorType, ...restOptions }: ThrowErrorOptions): (actionLogOptions?: ActionLogOptions) => Promise<void>;
|
|
28
28
|
}
|
|
@@ -13,7 +13,7 @@ exports.BaseService = void 0;
|
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const typeorm_1 = require("typeorm");
|
|
15
15
|
const action_log_1 = require("../action-log");
|
|
16
|
-
const
|
|
16
|
+
const app_enum_1 = require("../app.enum");
|
|
17
17
|
const utils_1 = require("../utils");
|
|
18
18
|
let BaseService = class BaseService {
|
|
19
19
|
actionLogService;
|
|
@@ -22,7 +22,7 @@ let BaseService = class BaseService {
|
|
|
22
22
|
}
|
|
23
23
|
create({ enabledLog = true, entityOptions, headers, preValidateOptions, serviceName }) {
|
|
24
24
|
const actionLogOptions = {
|
|
25
|
-
action:
|
|
25
|
+
action: app_enum_1.Action.CREATE,
|
|
26
26
|
enabledLog,
|
|
27
27
|
headers,
|
|
28
28
|
message: `Create a ${serviceName}`,
|
|
@@ -51,7 +51,7 @@ let BaseService = class BaseService {
|
|
|
51
51
|
}
|
|
52
52
|
del({ findOptions, serviceName, headers, enabledLog = true }) {
|
|
53
53
|
const actionLogOptions = {
|
|
54
|
-
action:
|
|
54
|
+
action: app_enum_1.Action.DELETE,
|
|
55
55
|
enabledLog,
|
|
56
56
|
headers,
|
|
57
57
|
message: `Delete a ${serviceName}`,
|
|
@@ -71,7 +71,7 @@ let BaseService = class BaseService {
|
|
|
71
71
|
}
|
|
72
72
|
update({ enabledLog = true, entityOptions, findOptions, headers, preValidateOptions, serviceName }) {
|
|
73
73
|
const actionLogOptions = {
|
|
74
|
-
action:
|
|
74
|
+
action: app_enum_1.Action.UPDATE,
|
|
75
75
|
enabledLog,
|
|
76
76
|
headers,
|
|
77
77
|
message: `Update a ${serviceName}`,
|
|
@@ -80,12 +80,9 @@ let BaseService = class BaseService {
|
|
|
80
80
|
};
|
|
81
81
|
const handleFindOptions = (accumulator, [key, value]) => typeof value !== 'undefined' ? [...accumulator, key] : accumulator;
|
|
82
82
|
const handlePreValidateFindOptions = (rawPreValidateFindOptions) => (entity) => (accumulator, value) => value ?
|
|
83
|
-
{
|
|
84
|
-
...accumulator,
|
|
85
|
-
[value]: rawPreValidateFindOptions[value] ?? entity[value]
|
|
86
|
-
}
|
|
83
|
+
{ ...accumulator, [value]: rawPreValidateFindOptions[value] ?? entity[value] }
|
|
87
84
|
: accumulator;
|
|
88
|
-
const
|
|
85
|
+
const handleUpdatePreValidate = (preValidateOptions) => (actionLogOptions) => async ({ entity, repository }) => {
|
|
89
86
|
const { findOptions: rawPreValidateFindOptions, validateKeys = [], ...restPreValidateOptions } = preValidateOptions;
|
|
90
87
|
const preValidateKeys = [
|
|
91
88
|
...new Set([
|
|
@@ -116,7 +113,10 @@ let BaseService = class BaseService {
|
|
|
116
113
|
const nextActionLogOptions = { ...actionLogOptions, raw };
|
|
117
114
|
await this.checkProhibited(nextActionLogOptions)(entity);
|
|
118
115
|
if (preValidateOptions) {
|
|
119
|
-
await
|
|
116
|
+
await handleUpdatePreValidate(preValidateOptions)(nextActionLogOptions)({
|
|
117
|
+
entity,
|
|
118
|
+
repository
|
|
119
|
+
});
|
|
120
120
|
}
|
|
121
121
|
repository.merge(entity, entityOptions);
|
|
122
122
|
return async (entityManager) => {
|
|
@@ -135,9 +135,7 @@ let BaseService = class BaseService {
|
|
|
135
135
|
const where = {
|
|
136
136
|
...Object.entries(restFindOptions).reduce((accumulator, [key, value]) => typeof value !== 'undefined' ? { ...accumulator, [key]: value } : accumulator, {}),
|
|
137
137
|
...(ids && { id: (0, typeorm_1.In)(ids) }),
|
|
138
|
-
...(createdAtRanges && {
|
|
139
|
-
createdAt: (0, typeorm_1.Between)(createdAtRanges[0], createdAtRanges[1])
|
|
140
|
-
})
|
|
138
|
+
...(createdAtRanges && { createdAt: (0, typeorm_1.Between)(createdAtRanges[0], createdAtRanges[1]) })
|
|
141
139
|
};
|
|
142
140
|
return async (repository) => {
|
|
143
141
|
if (ids && !ids.length) {
|
|
@@ -197,9 +195,7 @@ let BaseService = class BaseService {
|
|
|
197
195
|
{ ...accumulator, [key]: value }
|
|
198
196
|
: accumulator, {}),
|
|
199
197
|
...(ids && { id: (0, typeorm_1.In)(ids) }),
|
|
200
|
-
...(createdAtRanges && {
|
|
201
|
-
createdAt: (0, typeorm_1.Between)(createdAtRanges[0], createdAtRanges[1])
|
|
202
|
-
})
|
|
198
|
+
...(createdAtRanges && { createdAt: (0, typeorm_1.Between)(createdAtRanges[0], createdAtRanges[1]) })
|
|
203
199
|
};
|
|
204
200
|
const distinctOnAliasFields = distinctOnFields ?
|
|
205
201
|
distinctOnFields.map(field => `${entityName}.${field}`)
|
|
@@ -225,7 +221,7 @@ let BaseService = class BaseService {
|
|
|
225
221
|
if (!entity) {
|
|
226
222
|
const fields = Object.keys(findOptions);
|
|
227
223
|
await this.throwError({
|
|
228
|
-
errorType:
|
|
224
|
+
errorType: utils_1.HTTPError.NOT_FOUND,
|
|
229
225
|
message: `The ${serviceName} does not exist. Find by fields
|
|
230
226
|
${JSON.stringify(fields)}`
|
|
231
227
|
})(actionLogOptions);
|
|
@@ -239,7 +235,7 @@ let BaseService = class BaseService {
|
|
|
239
235
|
const entityIds = [...entityIdsSet];
|
|
240
236
|
return (associationKey) => {
|
|
241
237
|
const actionLogOptions = {
|
|
242
|
-
action:
|
|
238
|
+
action: app_enum_1.Action.UPDATE,
|
|
243
239
|
enabledLog,
|
|
244
240
|
headers,
|
|
245
241
|
message: `Update ${serviceName} and ${associationKey} associations`,
|
|
@@ -279,7 +275,7 @@ let BaseService = class BaseService {
|
|
|
279
275
|
const entitiesToRecover = await Promise.all(entities.reduce((accumulator, entity) => {
|
|
280
276
|
const recover = entityIdsSet.has(entity[associationKey]) &&
|
|
281
277
|
entity.deletedAt &&
|
|
282
|
-
|
|
278
|
+
app_enum_1.EntityStatus[entity.entityStatus] === 'SOFT_REMOVED';
|
|
283
279
|
if (recover) {
|
|
284
280
|
repository.merge(entity, updateEntityOptions[entity[associationKey]]);
|
|
285
281
|
return [...accumulator, entity.recover()];
|
|
@@ -313,9 +309,9 @@ let BaseService = class BaseService {
|
|
|
313
309
|
]);
|
|
314
310
|
await this.throwError({
|
|
315
311
|
code: '400001',
|
|
316
|
-
errorType:
|
|
317
|
-
message: `When using "or" as a validation method,
|
|
318
|
-
|
|
312
|
+
errorType: utils_1.HTTPError.BAD_REQUEST,
|
|
313
|
+
message: `When using "or" as a validation method, "orValidateKeysGroups"
|
|
314
|
+
must be a nested array. ${orValidateKeysGroups}`
|
|
319
315
|
})(actionLogOptions);
|
|
320
316
|
}
|
|
321
317
|
const orValidateKeysGroupsSet = new Set(orValidateKeysGroups?.flat());
|
|
@@ -353,7 +349,7 @@ let BaseService = class BaseService {
|
|
|
353
349
|
});
|
|
354
350
|
await this.throwError({
|
|
355
351
|
code: '400002',
|
|
356
|
-
errorType:
|
|
352
|
+
errorType: utils_1.HTTPError.BAD_REQUEST,
|
|
357
353
|
message: `The ${serviceName} fields already exists. ${JSON.stringify(fields)}`
|
|
358
354
|
})(actionLogOptions);
|
|
359
355
|
}
|
|
@@ -364,7 +360,7 @@ let BaseService = class BaseService {
|
|
|
364
360
|
entity.protected &&
|
|
365
361
|
(await this.throwError({
|
|
366
362
|
code: '403001',
|
|
367
|
-
errorType:
|
|
363
|
+
errorType: utils_1.HTTPError.FORBIDDEN,
|
|
368
364
|
message: `ALL actions on default ${actionLogOptions.serviceName} are prohibited`
|
|
369
365
|
})(actionLogOptions));
|
|
370
366
|
}
|