@nest-omni/core 1.0.28 → 1.0.30
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/constants/language-code.d.ts +2 -2
- package/constants/language-code.js +2 -2
- package/decorators/api-page-ok-response.decorator.d.ts +1 -1
- package/decorators/api-page-ok-response.decorator.js +3 -3
- package/decorators/field.decorators.d.ts +1 -1
- package/decorators/field.decorators.js +1 -1
- package/decorators/omni-auth.decorator.d.ts +7 -3
- package/decorators/omni-auth.decorator.js +20 -14
- package/decorators/transform.decorators.js +17 -11
- package/i18n/en_US/validation.json +2 -1
- package/i18n/zh_CN/validation.json +3 -2
- package/interceptors/language-interceptor.service.js +4 -4
- package/package.json +1 -1
- package/providers/context.provider.d.ts +2 -0
- package/providers/context.provider.js +6 -0
- package/setup/bootstrap.setup.js +1 -1
- package/shared/services/api-config.service.js +7 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/validators/is-exists.validator.js +1 -0
- package/validators/is-unique.validator.js +1 -0
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.supportedLanguageCount = exports.LanguageCode = void 0;
|
|
4
4
|
var LanguageCode;
|
|
5
5
|
(function (LanguageCode) {
|
|
6
|
-
LanguageCode["en_US"] = "
|
|
7
|
-
LanguageCode["zh_CN"] = "
|
|
6
|
+
LanguageCode["en_US"] = "en-US";
|
|
7
|
+
LanguageCode["zh_CN"] = "zh-CN";
|
|
8
8
|
})(LanguageCode || (exports.LanguageCode = LanguageCode = {}));
|
|
9
9
|
exports.supportedLanguageCount = Object.values(LanguageCode).length;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ApiPageResponse = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const swagger_1 = require("@nestjs/swagger");
|
|
6
6
|
const page_dto_1 = require("../common/dto/page.dto");
|
|
7
|
-
function
|
|
7
|
+
function ApiPageResponse(options) {
|
|
8
8
|
return (0, common_1.applyDecorators)((0, swagger_1.ApiExtraModels)(page_dto_1.PageDto), (0, swagger_1.ApiExtraModels)(options.type), (0, swagger_1.ApiOkResponse)({
|
|
9
9
|
description: options.description,
|
|
10
10
|
schema: {
|
|
@@ -22,4 +22,4 @@ function ApiPageOkResponse(options) {
|
|
|
22
22
|
},
|
|
23
23
|
}));
|
|
24
24
|
}
|
|
25
|
-
exports.
|
|
25
|
+
exports.ApiPageResponse = ApiPageResponse;
|
|
@@ -66,6 +66,6 @@ export declare function DateField(options?: Omit<ApiPropertyOptions, 'type'> & I
|
|
|
66
66
|
export declare function DateFieldOptional(options?: Omit<ApiPropertyOptions, 'type' | 'required'> & IDateFieldOptions): PropertyDecorator;
|
|
67
67
|
export declare function IpFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IIPFieldOptions & IStringFieldOptions): PropertyDecorator;
|
|
68
68
|
export declare function IpField(options: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions & IIPFieldOptions): PropertyDecorator;
|
|
69
|
-
export declare function ObjectField(options
|
|
69
|
+
export declare function ObjectField(options?: Omit<ApiPropertyOptions, 'type'> & IFieldOptions): PropertyDecorator;
|
|
70
70
|
export declare function ObjectFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IFieldOptions): PropertyDecorator;
|
|
71
71
|
export {};
|
|
@@ -421,7 +421,7 @@ function IpField(options) {
|
|
|
421
421
|
return (0, common_1.applyDecorators)(...decorators);
|
|
422
422
|
}
|
|
423
423
|
exports.IpField = IpField;
|
|
424
|
-
function ObjectField(options) {
|
|
424
|
+
function ObjectField(options = {}) {
|
|
425
425
|
const decorators = [
|
|
426
426
|
(0, class_transformer_1.Type)(() => Object),
|
|
427
427
|
(0, class_validator_1.IsObject)({
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
export interface IOmniAuth {
|
|
2
|
-
uid:
|
|
2
|
+
uid: string;
|
|
3
3
|
username: string;
|
|
4
4
|
tenantId: string;
|
|
5
5
|
appId: string;
|
|
6
|
+
admin: boolean;
|
|
7
|
+
role: string;
|
|
6
8
|
}
|
|
7
|
-
export declare const OmniAuth: (...dataOrPipes: (
|
|
8
|
-
export declare function getOmniAuthData
|
|
9
|
+
export declare const OmniAuth: (...dataOrPipes: (import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>> | keyof IOmniAuth)[]) => ParameterDecorator;
|
|
10
|
+
export declare function getOmniAuthData<T extends keyof IOmniAuth>(request: {
|
|
11
|
+
headers: Record<string, string>;
|
|
12
|
+
}, key?: T): IOmniAuth[T] | IOmniAuth;
|
|
@@ -2,34 +2,40 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getOmniAuthData = exports.OmniAuth = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
|
-
const
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
6
|
const config_1 = require("@nestjs/config");
|
|
7
|
-
exports.OmniAuth = (0, common_1.createParamDecorator)((
|
|
8
|
-
return getOmniAuthData(ctx.switchToHttp().getRequest(),
|
|
7
|
+
exports.OmniAuth = (0, common_1.createParamDecorator)((key, ctx) => {
|
|
8
|
+
return getOmniAuthData(ctx.switchToHttp().getRequest(), key);
|
|
9
9
|
});
|
|
10
|
-
function getOmniAuthData(
|
|
11
|
-
const headers =
|
|
10
|
+
function getOmniAuthData(request, key) {
|
|
11
|
+
const headers = request.headers;
|
|
12
12
|
let user;
|
|
13
|
-
const configService = new config_1.ConfigService(
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
if (process.env.NODE_ENV === 'dev' || process.env.NODE_ENV === 'uat') {
|
|
13
|
+
const configService = new config_1.ConfigService(request);
|
|
14
|
+
if ((0, lodash_1.isEmpty)(headers['x-userid']) || (0, lodash_1.isEmpty)(headers['x-username'])) {
|
|
15
|
+
if (process.env.NODE_ENV === 'dev') {
|
|
17
16
|
user = {
|
|
18
17
|
uid: configService.get('MOCK_UID'),
|
|
19
18
|
username: configService.get('MOCK_USERNAME'),
|
|
20
19
|
appId: configService.get('MOCK_APP_ID'),
|
|
21
20
|
tenantId: configService.get('MOCK_TENANT_ID'),
|
|
21
|
+
admin: configService.get('MOCK_ADMIN', false),
|
|
22
|
+
role: configService.get('MOCK_ROLE', ''),
|
|
22
23
|
};
|
|
23
24
|
}
|
|
25
|
+
else {
|
|
26
|
+
throw new Error('User information not found in headers.');
|
|
27
|
+
}
|
|
24
28
|
}
|
|
25
29
|
else {
|
|
26
30
|
user = {
|
|
27
|
-
uid: headers['x-userid'],
|
|
28
|
-
username: headers['x-username'],
|
|
29
|
-
appId: headers['x-appid'],
|
|
30
|
-
tenantId: headers['x-tenantid'],
|
|
31
|
+
uid: headers['x-userid'] || '',
|
|
32
|
+
username: headers['x-username'] || '',
|
|
33
|
+
appId: headers['x-appid'] || '',
|
|
34
|
+
tenantId: headers['x-tenantid'] || '',
|
|
35
|
+
admin: headers['x-admin'] === '1',
|
|
36
|
+
role: headers['x-role'] || '',
|
|
31
37
|
};
|
|
32
38
|
}
|
|
33
|
-
return
|
|
39
|
+
return key ? user[key] : user;
|
|
34
40
|
}
|
|
35
41
|
exports.getOmniAuthData = getOmniAuthData;
|
|
@@ -2,28 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PhoneNumberSerializer = exports.S3UrlParser = exports.ToUpperCase = exports.ToLowerCase = exports.ToArray = exports.ToInt = exports.ToBoolean = exports.Trim = void 0;
|
|
4
4
|
const class_transformer_1 = require("class-transformer");
|
|
5
|
+
const libphonenumber_js_1 = require("libphonenumber-js");
|
|
5
6
|
const lodash_1 = require("lodash");
|
|
6
7
|
const providers_1 = require("../providers");
|
|
7
|
-
const libphonenumber_js_1 = require("libphonenumber-js");
|
|
8
8
|
function Trim() {
|
|
9
9
|
return (0, class_transformer_1.Transform)((params) => {
|
|
10
10
|
const value = params.value;
|
|
11
11
|
if ((0, lodash_1.isArray)(value)) {
|
|
12
|
-
return (0, lodash_1.map)(value, (v) => (0, lodash_1.trim)(v).
|
|
12
|
+
return (0, lodash_1.map)(value, (v) => (0, lodash_1.trim)(v).replaceAll(/\s\s+/g, ' '));
|
|
13
13
|
}
|
|
14
|
-
return (0, lodash_1.trim)(value).
|
|
14
|
+
return (0, lodash_1.trim)(value).replaceAll(/\s\s+/g, ' ');
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
exports.Trim = Trim;
|
|
18
18
|
function ToBoolean() {
|
|
19
19
|
return (0, class_transformer_1.Transform)((params) => {
|
|
20
20
|
switch (params.value) {
|
|
21
|
-
case 'true':
|
|
21
|
+
case 'true': {
|
|
22
22
|
return true;
|
|
23
|
-
|
|
23
|
+
}
|
|
24
|
+
case 'false': {
|
|
24
25
|
return false;
|
|
25
|
-
|
|
26
|
+
}
|
|
27
|
+
default: {
|
|
26
28
|
return params.value;
|
|
29
|
+
}
|
|
27
30
|
}
|
|
28
31
|
}, { toClassOnly: true });
|
|
29
32
|
}
|
|
@@ -38,8 +41,8 @@ exports.ToInt = ToInt;
|
|
|
38
41
|
function ToArray() {
|
|
39
42
|
return (0, class_transformer_1.Transform)((params) => {
|
|
40
43
|
const value = params.value;
|
|
41
|
-
if (
|
|
42
|
-
return
|
|
44
|
+
if (!value) {
|
|
45
|
+
return value;
|
|
43
46
|
}
|
|
44
47
|
return (0, lodash_1.castArray)(value);
|
|
45
48
|
}, { toClassOnly: true });
|
|
@@ -79,12 +82,15 @@ function S3UrlParser() {
|
|
|
79
82
|
return (0, class_transformer_1.Transform)((params) => {
|
|
80
83
|
const key = params.value;
|
|
81
84
|
switch (params.type) {
|
|
82
|
-
case class_transformer_1.TransformationType.CLASS_TO_PLAIN:
|
|
85
|
+
case class_transformer_1.TransformationType.CLASS_TO_PLAIN: {
|
|
83
86
|
return providers_1.GeneratorProvider.getS3PublicUrl(key);
|
|
84
|
-
|
|
87
|
+
}
|
|
88
|
+
case class_transformer_1.TransformationType.PLAIN_TO_CLASS: {
|
|
85
89
|
return providers_1.GeneratorProvider.getS3Key(key);
|
|
86
|
-
|
|
90
|
+
}
|
|
91
|
+
default: {
|
|
87
92
|
return key;
|
|
93
|
+
}
|
|
88
94
|
}
|
|
89
95
|
});
|
|
90
96
|
}
|
|
@@ -34,5 +34,6 @@
|
|
|
34
34
|
"IS_UNIQUE": "{property} with the same value `{value}` exists",
|
|
35
35
|
"IS_EXISTS": "{property} value `{value}` does not exists",
|
|
36
36
|
"IS_FQDN": "{property} value `{value}` not a valid FQDN",
|
|
37
|
-
"IS_IP": "{property} value `{value}` not a valid IP"
|
|
37
|
+
"IS_IP": "{property} value `{value}` not a valid IP",
|
|
38
|
+
"IS_OBJECT": "{property} value `{value}` not a valid Object"
|
|
38
39
|
}
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"IS_NOT_EMPTY": "{property}不能为空",
|
|
34
34
|
"IS_UNIQUE": "存在相同值为`{value}`的{property}",
|
|
35
35
|
"IS_EXISTS": "{property}值`{value}`不存在",
|
|
36
|
-
"IS_FQDN": "{property}
|
|
37
|
-
"IS_IP": "{property}
|
|
36
|
+
"IS_FQDN": "{property} 值 `{value}` 必须是有效域名",
|
|
37
|
+
"IS_IP": "{property} 值 `{value}` 必须是有效IP",
|
|
38
|
+
"IS_OBJECT": "{property} 值 `{value}` 必须是有效对象"
|
|
38
39
|
}
|
|
@@ -12,11 +12,11 @@ const constants_1 = require("../constants");
|
|
|
12
12
|
const providers_1 = require("../providers");
|
|
13
13
|
let LanguageInterceptor = class LanguageInterceptor {
|
|
14
14
|
intercept(context, next) {
|
|
15
|
+
var _a;
|
|
15
16
|
const request = context.switchToHttp().getRequest();
|
|
16
|
-
const language = request.headers['
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
const language = request.headers['accept-language'];
|
|
18
|
+
const lang = (_a = constants_1.LanguageCode[language]) !== null && _a !== void 0 ? _a : constants_1.LanguageCode.en_US;
|
|
19
|
+
providers_1.ContextProvider.setLanguage(lang);
|
|
20
20
|
return next.handle();
|
|
21
21
|
}
|
|
22
22
|
};
|
package/package.json
CHANGED
|
@@ -28,5 +28,7 @@ export declare class ContextProvider {
|
|
|
28
28
|
static getAuthUserField<T extends keyof IOmniAuth>(field: T): IOmniAuth[T];
|
|
29
29
|
static getAuthUser(): IOmniAuth;
|
|
30
30
|
static getAppId(): string;
|
|
31
|
+
static getRole(): string;
|
|
32
|
+
static getAdmin(): boolean;
|
|
31
33
|
static getTenantId(): string;
|
|
32
34
|
}
|
|
@@ -59,6 +59,12 @@ class ContextProvider {
|
|
|
59
59
|
static getAppId() {
|
|
60
60
|
return ContextProvider.getAuthUserField('appId');
|
|
61
61
|
}
|
|
62
|
+
static getRole() {
|
|
63
|
+
return ContextProvider.getAuthUserField('role');
|
|
64
|
+
}
|
|
65
|
+
static getAdmin() {
|
|
66
|
+
return ContextProvider.getAuthUserField('admin');
|
|
67
|
+
}
|
|
62
68
|
static getTenantId() {
|
|
63
69
|
return ContextProvider.getAuthUserField('tenantId');
|
|
64
70
|
}
|
package/setup/bootstrap.setup.js
CHANGED
|
@@ -69,7 +69,7 @@ function bootstrapSetup(AppModule, SetupSwagger) {
|
|
|
69
69
|
limit: '50mb',
|
|
70
70
|
}), new nestjs_cls_1.ClsMiddleware({}).use, (0, __1.RequestIdMiddleware)(), (0, __1.PowerByMiddleware)(), (0, __1.OmniAuthMiddleware)());
|
|
71
71
|
app.useStaticAssets('public', { prefix: '/' });
|
|
72
|
-
app.useGlobalInterceptors(new auth_user_interceptor_1.AuthUserInterceptor(), new __1.TranslationInterceptor(), new nestjs_pino_1.LoggerErrorInterceptor(), new nestjs_sentry_1.SentryInterceptor({
|
|
72
|
+
app.useGlobalInterceptors(new __1.LanguageInterceptor(), new auth_user_interceptor_1.AuthUserInterceptor(), new __1.TranslationInterceptor(), new nestjs_pino_1.LoggerErrorInterceptor(), new nestjs_sentry_1.SentryInterceptor({
|
|
73
73
|
filters: [
|
|
74
74
|
{
|
|
75
75
|
type: common_1.HttpException,
|
|
@@ -117,6 +117,12 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
|
|
|
117
117
|
logging: this.getBoolean('DB_LOG_ENABLED'),
|
|
118
118
|
maxQueryExecutionTime: 3000,
|
|
119
119
|
namingStrategy: new common_2.SnakeNamingStrategy(),
|
|
120
|
+
cache: this.getBoolean('DB_CACHE_ENABLED')
|
|
121
|
+
? {
|
|
122
|
+
type: 'ioredis',
|
|
123
|
+
options: this.ioRedisConfig,
|
|
124
|
+
}
|
|
125
|
+
: false,
|
|
120
126
|
};
|
|
121
127
|
}
|
|
122
128
|
get awsS3Config() {
|
|
@@ -218,6 +224,7 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
|
|
|
218
224
|
get isRedisEnabled() {
|
|
219
225
|
return (this.getBoolean('BULL_ENABLED') ||
|
|
220
226
|
this.getBoolean('CACHE_ENABLED') ||
|
|
227
|
+
this.getBoolean('DB_CACHE_ENABLED') ||
|
|
221
228
|
(this.sessionEnabled && this.getBoolean('SESSION_REDIS_ENABLED')));
|
|
222
229
|
}
|
|
223
230
|
get bullConfig() {
|