@nest-omni/core 1.0.31 → 1.0.33
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/.hygen/new/crud/entity.ejs.t +2 -1
- package/.hygen/new/crud/service.ejs.t +1 -1
- package/cli.d.ts +2 -0
- package/cli.js +54 -0
- package/common/abstract.entity.js +2 -1
- package/decorators/field.decorators.d.ts +8 -1
- package/decorators/field.decorators.js +47 -2
- package/decorators/user.decorator.d.ts +9 -5
- package/decorators/user.decorator.js +22 -20
- package/decorators/user_auth.decorator.js +1 -1
- package/i18n/en_US/validation.json +3 -1
- package/i18n/zh_CN/validation.json +3 -1
- package/interceptors/language-interceptor.service.js +1 -2
- package/middlewares/omni-auth.middleware.js +2 -2
- package/package.json +6 -1
- package/providers/context.provider.d.ts +4 -4
- package/providers/context.provider.js +5 -6
- package/tsconfig.tsbuildinfo +1 -1
- package/decorators/omni-auth.decorator.d.ts +0 -12
- package/decorators/omni-auth.decorator.js +0 -38
|
@@ -15,11 +15,12 @@ skip_if: <%= !blocks.includes('Entity') %>
|
|
|
15
15
|
TranslationEntityName = h.TranslationEntityName(name);
|
|
16
16
|
translationEntityName = h.changeCase.camel(TranslationEntityName);
|
|
17
17
|
%>import { Entity, Column } from 'typeorm';
|
|
18
|
-
|
|
18
|
+
import { StringField } from '@nest-omni/core';
|
|
19
19
|
import { AbstractEntity } from '@nest-omni/core/common/abstract.entity';
|
|
20
20
|
|
|
21
21
|
@Entity({ name: '<%= TableName %>' })
|
|
22
22
|
export class <%= EntityName %> extends AbstractEntity {
|
|
23
23
|
@Column({ type: 'varchar', nullable: false })
|
|
24
|
+
@StringField()
|
|
24
25
|
name: string;
|
|
25
26
|
}
|
|
@@ -60,7 +60,7 @@ import { <%= EntityName %> } from './<%= entityFileName %>';
|
|
|
60
60
|
@Injectable()
|
|
61
61
|
export class <%= ServiceName %> extends TypeOrmCrudService<<%= EntityName %>> {
|
|
62
62
|
constructor(
|
|
63
|
-
@InjectRepository(<%= EntityName %>) repo:Repository<<%= EntityName %>>,
|
|
63
|
+
@InjectRepository(<%= EntityName %>) repo: Repository<<%= EntityName %>>,
|
|
64
64
|
public i18n: I18nService,
|
|
65
65
|
) {
|
|
66
66
|
super(repo);
|
package/cli.d.ts
ADDED
package/cli.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const program = require("commander");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
program.version('0.1.0').option('-v, --verbose', 'output extra information');
|
|
8
|
+
program
|
|
9
|
+
.command('init <name>')
|
|
10
|
+
.description('initialize a new project')
|
|
11
|
+
.action((name) => {
|
|
12
|
+
console.log(`Initializing project ${name}`);
|
|
13
|
+
});
|
|
14
|
+
program
|
|
15
|
+
.command('i18n <locale>')
|
|
16
|
+
.description('add i18n support to the project')
|
|
17
|
+
.action((locale) => {
|
|
18
|
+
console.log(`Adding i18n support for locale: ${locale}`);
|
|
19
|
+
});
|
|
20
|
+
program
|
|
21
|
+
.command('crud <entity>')
|
|
22
|
+
.description('generate CRUD operations for an entity')
|
|
23
|
+
.action((entity) => {
|
|
24
|
+
console.log(`Generating CRUD operations for ${entity}`);
|
|
25
|
+
});
|
|
26
|
+
program.parse(process.argv);
|
|
27
|
+
function copyRecursiveSync(src, dest) {
|
|
28
|
+
const exists = fs.existsSync(src);
|
|
29
|
+
const stats = exists && fs.statSync(src);
|
|
30
|
+
const isDirectory = exists && stats.isDirectory();
|
|
31
|
+
if (isDirectory) {
|
|
32
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
33
|
+
fs.readdirSync(src).forEach((childItemName) => {
|
|
34
|
+
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
fs.copyFileSync(src, dest);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const directoriesToCopy = [
|
|
42
|
+
{ src: './node_modules/@nest-omni/core/i18n', dest: './i18n' },
|
|
43
|
+
{ src: './node_modules/@nest-omni/core/.hygen', dest: './.hygen' },
|
|
44
|
+
{ src: './node_modules/@nest-omni/core/.hygen.js', dest: './.hygen.js' },
|
|
45
|
+
];
|
|
46
|
+
directoriesToCopy.forEach(({ src, dest }) => {
|
|
47
|
+
try {
|
|
48
|
+
copyRecursiveSync(src, dest);
|
|
49
|
+
console.log(`Copied ${src} to ${dest}`);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
console.error(`Error copying ${src} to ${dest}:`, error);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
@@ -39,7 +39,7 @@ class AbstractEntity extends AbstractBaseEntity {
|
|
|
39
39
|
}
|
|
40
40
|
exports.AbstractEntity = AbstractEntity;
|
|
41
41
|
__decorate([
|
|
42
|
-
(0, typeorm_1.PrimaryGeneratedColumn)('increment'
|
|
42
|
+
(0, typeorm_1.PrimaryGeneratedColumn)('increment'),
|
|
43
43
|
(0, decorators_1.NumberFieldOptional)({ swagger: false }),
|
|
44
44
|
__metadata("design:type", Number)
|
|
45
45
|
], AbstractEntity.prototype, "id", void 0);
|
|
@@ -59,6 +59,7 @@ __decorate([
|
|
|
59
59
|
maxLength: 36,
|
|
60
60
|
minLength: 2,
|
|
61
61
|
example: '23247899-c237-4ab1-9639-3322029d2e1c',
|
|
62
|
+
swagger: false,
|
|
62
63
|
}),
|
|
63
64
|
__metadata("design:type", String)
|
|
64
65
|
], AbstractUuidPrimaryEntity.prototype, "id", void 0);
|
|
@@ -30,6 +30,9 @@ interface IEmailFieldOptions {
|
|
|
30
30
|
interface IIPFieldOptions {
|
|
31
31
|
version?: ValidatorJS.IPVersion;
|
|
32
32
|
}
|
|
33
|
+
interface IURLFieldOptions {
|
|
34
|
+
urlOptions?: ValidatorJS.IsURLOptions;
|
|
35
|
+
}
|
|
33
36
|
interface IFQDNFieldOptions extends ValidatorJS.IsFQDNOptions {
|
|
34
37
|
}
|
|
35
38
|
type IClassFieldOptions = IFieldOptions;
|
|
@@ -58,7 +61,7 @@ export declare function PhoneField(options?: Omit<ApiPropertyOptions, 'type'> &
|
|
|
58
61
|
export declare function PhoneFieldOptional(options?: Omit<ApiPropertyOptions, 'type' | 'required'> & IFieldOptions): PropertyDecorator;
|
|
59
62
|
export declare function UUIDField(options?: Omit<ApiPropertyOptions, 'type' | 'format' | 'isArray'> & IFieldOptions): PropertyDecorator;
|
|
60
63
|
export declare function UUIDFieldOptional(options?: Omit<ApiPropertyOptions, 'type' | 'required' | 'isArray'> & IFieldOptions): PropertyDecorator;
|
|
61
|
-
export declare function URLField(options?: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions): PropertyDecorator;
|
|
64
|
+
export declare function URLField(options?: Omit<ApiPropertyOptions, 'type'> & IURLFieldOptions & IStringFieldOptions): PropertyDecorator;
|
|
62
65
|
export declare function URLFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions): PropertyDecorator;
|
|
63
66
|
export declare function FQDNField(options?: Omit<ApiPropertyOptions, 'type'> & IFQDNFieldOptions & IStringFieldOptions): PropertyDecorator;
|
|
64
67
|
export declare function FQDNFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IFQDNFieldOptions & IStringFieldOptions): PropertyDecorator;
|
|
@@ -68,4 +71,8 @@ export declare function IpFieldOptional(options?: Omit<ApiPropertyOptions, 'type
|
|
|
68
71
|
export declare function IpField(options: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions & IIPFieldOptions): PropertyDecorator;
|
|
69
72
|
export declare function ObjectField(options?: Omit<ApiPropertyOptions, 'type'> & IFieldOptions): PropertyDecorator;
|
|
70
73
|
export declare function ObjectFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IFieldOptions): PropertyDecorator;
|
|
74
|
+
export declare function TimeZoneField(options?: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions): PropertyDecorator;
|
|
75
|
+
export declare function TimeZoneFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions): PropertyDecorator;
|
|
76
|
+
export declare function LocaleField(options?: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions): PropertyDecorator;
|
|
77
|
+
export declare function LocaleFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions): PropertyDecorator;
|
|
71
78
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ObjectFieldOptional = exports.ObjectField = exports.IpField = exports.IpFieldOptional = exports.DateFieldOptional = exports.DateField = exports.FQDNFieldOptional = exports.FQDNField = exports.URLFieldOptional = exports.URLField = exports.UUIDFieldOptional = exports.UUIDField = exports.PhoneFieldOptional = exports.PhoneField = exports.EmailFieldOptional = exports.EmailField = exports.ClassFieldOptional = exports.EnumFieldOptional = exports.ClassField = exports.EnumField = exports.getEnumDescription = exports.TmpKeyFieldOptional = exports.TmpKeyField = exports.TranslationsFieldOptional = exports.TranslationsField = exports.BooleanFieldOptional = exports.BooleanField = exports.PasswordFieldOptional = exports.PasswordField = exports.StringFieldOptional = exports.StringField = exports.NumberFieldOptional = exports.NumberField = void 0;
|
|
3
|
+
exports.LocaleFieldOptional = exports.LocaleField = exports.TimeZoneFieldOptional = exports.TimeZoneField = exports.ObjectFieldOptional = exports.ObjectField = exports.IpField = exports.IpFieldOptional = exports.DateFieldOptional = exports.DateField = exports.FQDNFieldOptional = exports.FQDNField = exports.URLFieldOptional = exports.URLField = exports.UUIDFieldOptional = exports.UUIDField = exports.PhoneFieldOptional = exports.PhoneField = exports.EmailFieldOptional = exports.EmailField = exports.ClassFieldOptional = exports.EnumFieldOptional = exports.ClassField = exports.EnumField = exports.getEnumDescription = exports.TmpKeyFieldOptional = exports.TmpKeyField = exports.TranslationsFieldOptional = exports.TranslationsField = exports.BooleanFieldOptional = exports.BooleanField = exports.PasswordFieldOptional = exports.PasswordField = exports.StringFieldOptional = exports.StringField = exports.NumberFieldOptional = exports.NumberField = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const swagger_1 = require("@nestjs/swagger");
|
|
6
6
|
const nestjs_i18n_1 = require("nestjs-i18n");
|
|
@@ -327,7 +327,7 @@ function UUIDFieldOptional(options = {}) {
|
|
|
327
327
|
exports.UUIDFieldOptional = UUIDFieldOptional;
|
|
328
328
|
function URLField(options = {}) {
|
|
329
329
|
const decorators = [
|
|
330
|
-
(0, class_validator_1.IsUrl)(
|
|
330
|
+
(0, class_validator_1.IsUrl)(options.urlOptions, {
|
|
331
331
|
each: options.each,
|
|
332
332
|
message: (0, nestjs_i18n_1.i18nValidationMessage)('validation.IS_URL'),
|
|
333
333
|
}),
|
|
@@ -445,3 +445,48 @@ function ObjectFieldOptional(options = {}) {
|
|
|
445
445
|
return (0, common_1.applyDecorators)((0, validator_decorators_1.IsEmptyable)(), ObjectField(Object.assign({ required: false }, options)));
|
|
446
446
|
}
|
|
447
447
|
exports.ObjectFieldOptional = ObjectFieldOptional;
|
|
448
|
+
function TimeZoneField(options = {}) {
|
|
449
|
+
const decorators = [
|
|
450
|
+
StringField(Object.assign({}, options)),
|
|
451
|
+
(0, class_validator_1.IsTimeZone)({
|
|
452
|
+
each: options.each,
|
|
453
|
+
message: (0, nestjs_i18n_1.i18nValidationMessage)('validation.IS_TIME_ZONE'),
|
|
454
|
+
}),
|
|
455
|
+
];
|
|
456
|
+
if (options.nullable) {
|
|
457
|
+
decorators.push((0, validator_decorators_1.IsNullable)({ each: options.each }));
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
decorators.push((0, class_validator_1.NotEquals)(null, { each: options.each }));
|
|
461
|
+
}
|
|
462
|
+
return (0, common_1.applyDecorators)(...decorators);
|
|
463
|
+
}
|
|
464
|
+
exports.TimeZoneField = TimeZoneField;
|
|
465
|
+
function TimeZoneFieldOptional(options = {}) {
|
|
466
|
+
return (0, common_1.applyDecorators)((0, validator_decorators_1.IsEmptyable)(), TimeZoneField(Object.assign({ required: false }, options)));
|
|
467
|
+
}
|
|
468
|
+
exports.TimeZoneFieldOptional = TimeZoneFieldOptional;
|
|
469
|
+
function LocaleField(options = {}) {
|
|
470
|
+
const decorators = [
|
|
471
|
+
StringField(Object.assign({}, options)),
|
|
472
|
+
(0, class_validator_1.IsLocale)({
|
|
473
|
+
each: options.each,
|
|
474
|
+
message: (0, nestjs_i18n_1.i18nValidationMessage)('validation.IS_LOCALE'),
|
|
475
|
+
}),
|
|
476
|
+
];
|
|
477
|
+
if (options.nullable) {
|
|
478
|
+
decorators.push((0, validator_decorators_1.IsNullable)({ each: options.each }));
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
decorators.push((0, class_validator_1.NotEquals)(null, { each: options.each }));
|
|
482
|
+
}
|
|
483
|
+
if (options.swagger !== false) {
|
|
484
|
+
decorators.push((0, swagger_1.ApiProperty)(Object.assign({ type: String }, options)));
|
|
485
|
+
}
|
|
486
|
+
return (0, common_1.applyDecorators)(...decorators);
|
|
487
|
+
}
|
|
488
|
+
exports.LocaleField = LocaleField;
|
|
489
|
+
function LocaleFieldOptional(options = {}) {
|
|
490
|
+
return (0, common_1.applyDecorators)((0, validator_decorators_1.IsEmptyable)(), LocaleField(Object.assign({ required: false }, options)));
|
|
491
|
+
}
|
|
492
|
+
exports.LocaleFieldOptional = LocaleFieldOptional;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
export interface IUser {
|
|
2
|
-
uid:
|
|
2
|
+
uid: string;
|
|
3
3
|
username: string;
|
|
4
|
-
tenantId
|
|
5
|
-
appId
|
|
4
|
+
tenantId: string;
|
|
5
|
+
appId: string;
|
|
6
|
+
admin: boolean;
|
|
7
|
+
role: string;
|
|
6
8
|
}
|
|
7
|
-
export declare const User: (...dataOrPipes: (
|
|
8
|
-
export declare function
|
|
9
|
+
export declare const User: (...dataOrPipes: (import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>> | keyof IUser)[]) => ParameterDecorator;
|
|
10
|
+
export declare function getOmniAuthData<T extends keyof IUser>(request: {
|
|
11
|
+
headers: Record<string, string>;
|
|
12
|
+
}, key?: T): IUser[T] | IUser;
|
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getOmniAuthData = exports.User = 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
|
-
|
|
8
|
-
|
|
7
|
+
const providers_1 = require("../providers");
|
|
8
|
+
exports.User = (0, common_1.createParamDecorator)((key) => {
|
|
9
|
+
const authUser = providers_1.ContextProvider.getAuthUser();
|
|
10
|
+
return key ? authUser[key] : authUser;
|
|
9
11
|
});
|
|
10
|
-
function
|
|
11
|
-
const headers =
|
|
12
|
-
let user
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const configService = new config_1.ConfigService(req);
|
|
17
|
-
if (lodash.isEmpty(headers['x-userid']) ||
|
|
18
|
-
lodash.isEmpty(headers['x-username'])) {
|
|
19
|
-
if (process.env.NODE_ENV === 'dev') {
|
|
12
|
+
function getOmniAuthData(request, key) {
|
|
13
|
+
const headers = request.headers;
|
|
14
|
+
let user;
|
|
15
|
+
const configService = new config_1.ConfigService(request);
|
|
16
|
+
if ((0, lodash_1.isEmpty)(headers['x-userid']) || (0, lodash_1.isEmpty)(headers['x-username'])) {
|
|
17
|
+
if (process.env.NODE_ENV === 'dev' || process.env.NODE_ENV === 'uat') {
|
|
20
18
|
user = {
|
|
21
19
|
uid: configService.get('MOCK_UID'),
|
|
22
20
|
username: configService.get('MOCK_USERNAME'),
|
|
23
21
|
appId: configService.get('MOCK_APP_ID'),
|
|
24
22
|
tenantId: configService.get('MOCK_TENANT_ID'),
|
|
23
|
+
admin: configService.get('MOCK_ADMIN', false),
|
|
24
|
+
role: configService.get('MOCK_ROLE', ''),
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
29
|
user = {
|
|
30
|
-
uid: headers['x-userid'],
|
|
31
|
-
username: headers['x-username'],
|
|
32
|
-
appId: headers['x-appid'],
|
|
33
|
-
tenantId: headers['x-tenantid'],
|
|
30
|
+
uid: headers['x-userid'] || '',
|
|
31
|
+
username: headers['x-username'] || '',
|
|
32
|
+
appId: headers['x-appid'] || '',
|
|
33
|
+
tenantId: headers['x-tenantid'] || '',
|
|
34
|
+
admin: headers['x-admin'] === '1',
|
|
35
|
+
role: headers['x-role'] || '',
|
|
34
36
|
};
|
|
35
|
-
return data ? user[data] : user;
|
|
36
37
|
}
|
|
38
|
+
return key ? user[key] : user;
|
|
37
39
|
}
|
|
38
|
-
exports.
|
|
40
|
+
exports.getOmniAuthData = getOmniAuthData;
|
|
@@ -8,7 +8,7 @@ function UserFilter(field) {
|
|
|
8
8
|
const obj = {};
|
|
9
9
|
return (0, common_1.applyDecorators)((0, crud_1.CrudAuth)({
|
|
10
10
|
filter: (req) => {
|
|
11
|
-
obj[field] = (0, user_decorator_1.
|
|
11
|
+
obj[field] = (0, user_decorator_1.getOmniAuthData)(req, 'uid');
|
|
12
12
|
return obj;
|
|
13
13
|
},
|
|
14
14
|
}));
|
|
@@ -35,5 +35,7 @@
|
|
|
35
35
|
"IS_EXISTS": "{property} value `{value}` does not exists",
|
|
36
36
|
"IS_FQDN": "{property} value `{value}` not a valid FQDN",
|
|
37
37
|
"IS_IP": "{property} value `{value}` not a valid IP",
|
|
38
|
-
"IS_OBJECT": "{property} value `{value}` not a valid Object"
|
|
38
|
+
"IS_OBJECT": "{property} value `{value}` not a valid Object",
|
|
39
|
+
"IS_TIME_ZONE": "{property} value `{value}` must be a valid IANA time-zone",
|
|
40
|
+
"IS_LOCALE": "{property} value `{value}` must be a valid locale"
|
|
39
41
|
}
|
|
@@ -35,5 +35,7 @@
|
|
|
35
35
|
"IS_EXISTS": "{property}值`{value}`不存在",
|
|
36
36
|
"IS_FQDN": "{property} 值 `{value}` 必须是有效域名",
|
|
37
37
|
"IS_IP": "{property} 值 `{value}` 必须是有效IP",
|
|
38
|
-
"IS_OBJECT": "{property} 值 `{value}` 必须是有效对象"
|
|
38
|
+
"IS_OBJECT": "{property} 值 `{value}` 必须是有效对象",
|
|
39
|
+
"IS_TIME_ZONE": "{property} 值 `{value}` 必须是有效时区",
|
|
40
|
+
"IS_LOCALE": "{property} 值 `{value}` 必须是有效语言"
|
|
39
41
|
}
|
|
@@ -14,8 +14,7 @@ let LanguageInterceptor = class LanguageInterceptor {
|
|
|
14
14
|
intercept(context, next) {
|
|
15
15
|
var _a;
|
|
16
16
|
const request = context.switchToHttp().getRequest();
|
|
17
|
-
const
|
|
18
|
-
const lang = (_a = constants_1.LanguageCode[language]) !== null && _a !== void 0 ? _a : constants_1.LanguageCode.en_US;
|
|
17
|
+
const lang = (_a = request.headers['accept-language']) !== null && _a !== void 0 ? _a : constants_1.LanguageCode.en_US;
|
|
19
18
|
providers_1.ContextProvider.setLanguage(lang);
|
|
20
19
|
return next.handle();
|
|
21
20
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OmniAuthMiddleware = void 0;
|
|
4
|
-
const
|
|
4
|
+
const user_decorator_1 = require("../decorators/user.decorator");
|
|
5
5
|
const providers_1 = require("../providers");
|
|
6
6
|
const OmniAuthMiddleware = () => {
|
|
7
7
|
return (req, res, next) => {
|
|
8
|
-
req.user = (0,
|
|
8
|
+
req.user = (0, user_decorator_1.getOmniAuthData)(req);
|
|
9
9
|
providers_1.ContextProvider.setAuthUser(req.user);
|
|
10
10
|
next();
|
|
11
11
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-omni/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.33",
|
|
4
4
|
"description": "framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -9,6 +9,11 @@
|
|
|
9
9
|
"test": "jest --passWithNoTests",
|
|
10
10
|
"lint": "eslint 'src/**/*.ts' --fix"
|
|
11
11
|
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"nest-omni": "nest start",
|
|
14
|
+
"i18n": "i18n",
|
|
15
|
+
"gen": "gen"
|
|
16
|
+
},
|
|
12
17
|
"author": "Jinpy",
|
|
13
18
|
"license": "Apache-2.0",
|
|
14
19
|
"devDependencies": {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IUser } from '../decorators/user.decorator';
|
|
2
2
|
export declare class ContextProvider {
|
|
3
3
|
private static readonly nameSpace;
|
|
4
4
|
private static readonly authUserKey;
|
|
@@ -22,11 +22,11 @@ export declare class ContextProvider {
|
|
|
22
22
|
};
|
|
23
23
|
static setRequestId(id: string): void;
|
|
24
24
|
static getRequestId(): string;
|
|
25
|
-
static setAuthUser(user:
|
|
25
|
+
static setAuthUser(user: IUser): void;
|
|
26
26
|
static setLanguage(language: string): void;
|
|
27
27
|
static getLanguage(): string;
|
|
28
|
-
static getAuthUserField<T extends keyof
|
|
29
|
-
static getAuthUser():
|
|
28
|
+
static getAuthUserField<T extends keyof IUser>(field?: T): IUser[T];
|
|
29
|
+
static getAuthUser(): IUser;
|
|
30
30
|
static getAppId(): string;
|
|
31
31
|
static getRole(): string;
|
|
32
32
|
static getAdmin(): boolean;
|
|
@@ -49,15 +49,14 @@ class ContextProvider {
|
|
|
49
49
|
return ContextProvider.get(ContextProvider.languageKey);
|
|
50
50
|
}
|
|
51
51
|
static getAuthUserField(field) {
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
return ContextProvider.getAuthUser()[field];
|
|
53
|
+
}
|
|
54
|
+
static getAuthUser() {
|
|
55
|
+
const auth = ContextProvider.get(ContextProvider.authUserKey);
|
|
54
56
|
if (!auth) {
|
|
55
57
|
throw new Error('User information not found.');
|
|
56
58
|
}
|
|
57
|
-
return auth
|
|
58
|
-
}
|
|
59
|
-
static getAuthUser() {
|
|
60
|
-
return ContextProvider.get(ContextProvider.authUserKey);
|
|
59
|
+
return auth;
|
|
61
60
|
}
|
|
62
61
|
static getAppId() {
|
|
63
62
|
return ContextProvider.getAuthUserField('appId');
|