@nest-omni/core 1.0.31 → 1.0.34
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 +52 -0
- package/common/abstract.entity.js +2 -1
- package/decorators/field.decorators.d.ts +10 -2
- package/decorators/field.decorators.js +57 -6
- package/decorators/user.decorator.d.ts +9 -5
- package/decorators/user.decorator.js +22 -20
- package/decorators/user_auth.decorator.js +1 -1
- package/decorators/validator.decorators.d.ts +1 -0
- package/decorators/validator.decorators.js +21 -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 +9 -1
- package/providers/context.provider.d.ts +4 -4
- package/providers/context.provider.js +5 -6
- package/shared/serviceRegistryModule.js +2 -1
- package/shared/services/api-config.service.js +7 -5
- 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,52 @@
|
|
|
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
|
+
const hygen_1 = require("hygen");
|
|
8
|
+
const logger_1 = require("hygen/dist/logger");
|
|
9
|
+
const process = require("node:process");
|
|
10
|
+
const _hygen_1 = require(".hygen");
|
|
11
|
+
program.version('0.1.0').option('-v, --verbose', 'output extra information');
|
|
12
|
+
program
|
|
13
|
+
.command('create <project>')
|
|
14
|
+
.description('initialize a new project')
|
|
15
|
+
.action((project) => {
|
|
16
|
+
console.log(`Initializing project ${project}`);
|
|
17
|
+
});
|
|
18
|
+
program
|
|
19
|
+
.command('i18n')
|
|
20
|
+
.description('add class-validator i18n support to the project')
|
|
21
|
+
.action(() => {
|
|
22
|
+
copyRecursiveSync(path.join(__dirname, 'i18n'), './i18n');
|
|
23
|
+
});
|
|
24
|
+
program
|
|
25
|
+
.command('crud')
|
|
26
|
+
.description('generate CRUD operations for a module')
|
|
27
|
+
.action(() => {
|
|
28
|
+
console.log(`Generating CRUD operations for module`);
|
|
29
|
+
(0, hygen_1.runner)(['new', 'crud'], {
|
|
30
|
+
templates: _hygen_1.templates,
|
|
31
|
+
helpers: _hygen_1.helpers,
|
|
32
|
+
cwd: process.cwd(),
|
|
33
|
+
logger: new logger_1.default(console.log.bind(console)),
|
|
34
|
+
debug: !!process.env.DEBUG,
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
program.parse(process.argv);
|
|
38
|
+
function copyRecursiveSync(src, dest) {
|
|
39
|
+
const exists = fs.existsSync(src);
|
|
40
|
+
const stats = exists && fs.statSync(src);
|
|
41
|
+
const isDirectory = exists && stats.isDirectory();
|
|
42
|
+
console.log(`Copied ${src} to ${dest}`);
|
|
43
|
+
if (isDirectory) {
|
|
44
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
45
|
+
fs.readdirSync(src).forEach((childItemName) => {
|
|
46
|
+
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
fs.copyFileSync(src, dest);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -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,10 @@ interface IEmailFieldOptions {
|
|
|
30
30
|
interface IIPFieldOptions {
|
|
31
31
|
version?: ValidatorJS.IPVersion;
|
|
32
32
|
}
|
|
33
|
+
interface IURLFieldOptions {
|
|
34
|
+
urlOptions?: ValidatorJS.IsURLOptions;
|
|
35
|
+
simpleUrl?: boolean;
|
|
36
|
+
}
|
|
33
37
|
interface IFQDNFieldOptions extends ValidatorJS.IsFQDNOptions {
|
|
34
38
|
}
|
|
35
39
|
type IClassFieldOptions = IFieldOptions;
|
|
@@ -58,8 +62,8 @@ export declare function PhoneField(options?: Omit<ApiPropertyOptions, 'type'> &
|
|
|
58
62
|
export declare function PhoneFieldOptional(options?: Omit<ApiPropertyOptions, 'type' | 'required'> & IFieldOptions): PropertyDecorator;
|
|
59
63
|
export declare function UUIDField(options?: Omit<ApiPropertyOptions, 'type' | 'format' | 'isArray'> & IFieldOptions): PropertyDecorator;
|
|
60
64
|
export declare function UUIDFieldOptional(options?: Omit<ApiPropertyOptions, 'type' | 'required' | 'isArray'> & IFieldOptions): PropertyDecorator;
|
|
61
|
-
export declare function URLField(options?: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions): PropertyDecorator;
|
|
62
|
-
export declare function URLFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions): PropertyDecorator;
|
|
65
|
+
export declare function URLField(options?: Omit<ApiPropertyOptions, 'type'> & IURLFieldOptions & IStringFieldOptions): PropertyDecorator;
|
|
66
|
+
export declare function URLFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IURLFieldOptions & IStringFieldOptions): PropertyDecorator;
|
|
63
67
|
export declare function FQDNField(options?: Omit<ApiPropertyOptions, 'type'> & IFQDNFieldOptions & IStringFieldOptions): PropertyDecorator;
|
|
64
68
|
export declare function FQDNFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IFQDNFieldOptions & IStringFieldOptions): PropertyDecorator;
|
|
65
69
|
export declare function DateField(options?: Omit<ApiPropertyOptions, 'type'> & IDateFieldOptions): PropertyDecorator;
|
|
@@ -68,4 +72,8 @@ export declare function IpFieldOptional(options?: Omit<ApiPropertyOptions, 'type
|
|
|
68
72
|
export declare function IpField(options: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions & IIPFieldOptions): PropertyDecorator;
|
|
69
73
|
export declare function ObjectField(options?: Omit<ApiPropertyOptions, 'type'> & IFieldOptions): PropertyDecorator;
|
|
70
74
|
export declare function ObjectFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IFieldOptions): PropertyDecorator;
|
|
75
|
+
export declare function TimeZoneField(options?: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions): PropertyDecorator;
|
|
76
|
+
export declare function TimeZoneFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions): PropertyDecorator;
|
|
77
|
+
export declare function LocaleField(options?: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions): PropertyDecorator;
|
|
78
|
+
export declare function LocaleFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions): PropertyDecorator;
|
|
71
79
|
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");
|
|
@@ -326,13 +326,19 @@ function UUIDFieldOptional(options = {}) {
|
|
|
326
326
|
}
|
|
327
327
|
exports.UUIDFieldOptional = UUIDFieldOptional;
|
|
328
328
|
function URLField(options = {}) {
|
|
329
|
-
const decorators = [
|
|
330
|
-
|
|
329
|
+
const decorators = [StringField(Object.assign({}, options))];
|
|
330
|
+
if (options.simpleUrl) {
|
|
331
|
+
decorators.push((0, validator_decorators_1.IsHttpUrl)({
|
|
331
332
|
each: options.each,
|
|
332
333
|
message: (0, nestjs_i18n_1.i18nValidationMessage)('validation.IS_URL'),
|
|
333
|
-
})
|
|
334
|
-
|
|
335
|
-
|
|
334
|
+
}));
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
decorators.push((0, class_validator_1.IsUrl)(options.urlOptions, {
|
|
338
|
+
each: options.each,
|
|
339
|
+
message: (0, nestjs_i18n_1.i18nValidationMessage)('validation.IS_URL'),
|
|
340
|
+
}));
|
|
341
|
+
}
|
|
336
342
|
if (options.nullable) {
|
|
337
343
|
decorators.push((0, validator_decorators_1.IsNullable)({ each: options.each }));
|
|
338
344
|
}
|
|
@@ -445,3 +451,48 @@ function ObjectFieldOptional(options = {}) {
|
|
|
445
451
|
return (0, common_1.applyDecorators)((0, validator_decorators_1.IsEmptyable)(), ObjectField(Object.assign({ required: false }, options)));
|
|
446
452
|
}
|
|
447
453
|
exports.ObjectFieldOptional = ObjectFieldOptional;
|
|
454
|
+
function TimeZoneField(options = {}) {
|
|
455
|
+
const decorators = [
|
|
456
|
+
StringField(Object.assign({}, options)),
|
|
457
|
+
(0, class_validator_1.IsTimeZone)({
|
|
458
|
+
each: options.each,
|
|
459
|
+
message: (0, nestjs_i18n_1.i18nValidationMessage)('validation.IS_TIME_ZONE'),
|
|
460
|
+
}),
|
|
461
|
+
];
|
|
462
|
+
if (options.nullable) {
|
|
463
|
+
decorators.push((0, validator_decorators_1.IsNullable)({ each: options.each }));
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
decorators.push((0, class_validator_1.NotEquals)(null, { each: options.each }));
|
|
467
|
+
}
|
|
468
|
+
return (0, common_1.applyDecorators)(...decorators);
|
|
469
|
+
}
|
|
470
|
+
exports.TimeZoneField = TimeZoneField;
|
|
471
|
+
function TimeZoneFieldOptional(options = {}) {
|
|
472
|
+
return (0, common_1.applyDecorators)((0, validator_decorators_1.IsEmptyable)(), TimeZoneField(Object.assign({ required: false }, options)));
|
|
473
|
+
}
|
|
474
|
+
exports.TimeZoneFieldOptional = TimeZoneFieldOptional;
|
|
475
|
+
function LocaleField(options = {}) {
|
|
476
|
+
const decorators = [
|
|
477
|
+
StringField(Object.assign({}, options)),
|
|
478
|
+
(0, class_validator_1.IsLocale)({
|
|
479
|
+
each: options.each,
|
|
480
|
+
message: (0, nestjs_i18n_1.i18nValidationMessage)('validation.IS_LOCALE'),
|
|
481
|
+
}),
|
|
482
|
+
];
|
|
483
|
+
if (options.nullable) {
|
|
484
|
+
decorators.push((0, validator_decorators_1.IsNullable)({ each: options.each }));
|
|
485
|
+
}
|
|
486
|
+
else {
|
|
487
|
+
decorators.push((0, class_validator_1.NotEquals)(null, { each: options.each }));
|
|
488
|
+
}
|
|
489
|
+
if (options.swagger !== false) {
|
|
490
|
+
decorators.push((0, swagger_1.ApiProperty)(Object.assign({ type: String }, options)));
|
|
491
|
+
}
|
|
492
|
+
return (0, common_1.applyDecorators)(...decorators);
|
|
493
|
+
}
|
|
494
|
+
exports.LocaleField = LocaleField;
|
|
495
|
+
function LocaleFieldOptional(options = {}) {
|
|
496
|
+
return (0, common_1.applyDecorators)((0, validator_decorators_1.IsEmptyable)(), LocaleField(Object.assign({ required: false }, options)));
|
|
497
|
+
}
|
|
498
|
+
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
|
}));
|
|
@@ -8,3 +8,4 @@ export declare function IsTmpKey(validationOptions?: ValidationOptions): Propert
|
|
|
8
8
|
export declare function IsUndefinable(options?: ValidationOptions): PropertyDecorator;
|
|
9
9
|
export declare function IsEmptyable(options?: ValidationOptions): PropertyDecorator;
|
|
10
10
|
export declare function IsNullable(options?: ValidationOptions): PropertyDecorator;
|
|
11
|
+
export declare function IsHttpUrl(validationOptions?: ValidationOptions): (object: any, propertyName: string) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IsNullable = exports.IsEmptyable = exports.IsUndefinable = exports.IsTmpKey = exports.IsPhoneNumber = exports.IsPassword = void 0;
|
|
3
|
+
exports.IsHttpUrl = exports.IsNullable = exports.IsEmptyable = exports.IsUndefinable = exports.IsTmpKey = exports.IsPhoneNumber = exports.IsPassword = void 0;
|
|
4
4
|
const class_validator_1 = require("class-validator");
|
|
5
5
|
const lodash_1 = require("lodash");
|
|
6
6
|
function IsPassword(validationOptions) {
|
|
@@ -57,3 +57,23 @@ function IsNullable(options) {
|
|
|
57
57
|
return (0, class_validator_1.ValidateIf)((obj, value) => value !== null, options);
|
|
58
58
|
}
|
|
59
59
|
exports.IsNullable = IsNullable;
|
|
60
|
+
function IsHttpUrl(validationOptions) {
|
|
61
|
+
return function (object, propertyName) {
|
|
62
|
+
(0, class_validator_1.registerDecorator)({
|
|
63
|
+
name: 'isHttpUrl',
|
|
64
|
+
target: object.constructor,
|
|
65
|
+
propertyName: propertyName,
|
|
66
|
+
options: validationOptions,
|
|
67
|
+
validator: {
|
|
68
|
+
validate(value) {
|
|
69
|
+
const httpUrlPattern = /^(https?:\/\/)/i;
|
|
70
|
+
return typeof value === 'string' && httpUrlPattern.test(value);
|
|
71
|
+
},
|
|
72
|
+
defaultMessage() {
|
|
73
|
+
return 'URL must start with http:// or https://';
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
exports.IsHttpUrl = IsHttpUrl;
|
|
@@ -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.34",
|
|
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": {
|
|
@@ -59,5 +64,8 @@
|
|
|
59
64
|
"typeorm": "^0.3.17",
|
|
60
65
|
"typeorm-transactional": "~0.4.1",
|
|
61
66
|
"uuid": "^9.0.1"
|
|
67
|
+
},
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"hygen": "^6.2.11"
|
|
62
70
|
}
|
|
63
71
|
}
|
|
@@ -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');
|
|
@@ -43,11 +43,12 @@ function findValidRootPath() {
|
|
|
43
43
|
const envFile = `${process.env.NODE_ENV || ''}.env`;
|
|
44
44
|
for (const rootPath of possibleRootPaths) {
|
|
45
45
|
const envFilePath = path.join(rootPath, 'config', envFile);
|
|
46
|
+
console.log('Checking for env file:', envFilePath);
|
|
46
47
|
if ((0, fs_1.existsSync)(envFilePath)) {
|
|
47
48
|
return { rootPath, envFilePath };
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
|
-
throw new Error(
|
|
51
|
+
throw new Error(`No valid .env file: ${envFilePath}`);
|
|
51
52
|
}
|
|
52
53
|
const { envFilePath, rootPath } = findValidRootPath();
|
|
53
54
|
services_1.ApiConfigService.rootPath = rootPath;
|
|
@@ -58,7 +58,7 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
|
|
|
58
58
|
return Number(value);
|
|
59
59
|
}
|
|
60
60
|
catch (_a) {
|
|
61
|
-
throw new Error(key
|
|
61
|
+
throw new Error(`key:${key}, value:${value} - is not a number`);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
getBoolean(key) {
|
|
@@ -73,7 +73,7 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
|
|
|
73
73
|
if (!(0, lodash_1.isNil)(defaultValue)) {
|
|
74
74
|
return defaultValue;
|
|
75
75
|
}
|
|
76
|
-
throw new Error(value
|
|
76
|
+
throw new Error(`value:${value} - is not a boolean`);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
getString(key) {
|
|
@@ -261,12 +261,14 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
|
|
|
261
261
|
}
|
|
262
262
|
return 'error';
|
|
263
263
|
},
|
|
264
|
-
|
|
264
|
+
wrapSerializers: true,
|
|
265
|
+
customProps: (req, res) => {
|
|
265
266
|
return {
|
|
266
267
|
env: this.nodeEnv,
|
|
267
268
|
appName: this.getString('NAME'),
|
|
268
269
|
user: req === null || req === void 0 ? void 0 : req.user,
|
|
269
|
-
body: req === null || req === void 0 ? void 0 : req.body,
|
|
270
|
+
'req.body': req === null || req === void 0 ? void 0 : req.body,
|
|
271
|
+
'res.body': res === null || res === void 0 ? void 0 : res.body,
|
|
270
272
|
};
|
|
271
273
|
},
|
|
272
274
|
redact: {
|
|
@@ -288,7 +290,7 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
|
|
|
288
290
|
get(key) {
|
|
289
291
|
const value = this.configService.get(key);
|
|
290
292
|
if ((0, lodash_1.isNil)(value)) {
|
|
291
|
-
throw new Error(key
|
|
293
|
+
throw new Error(`key:'${key}' - environment does not set`);
|
|
292
294
|
}
|
|
293
295
|
return value;
|
|
294
296
|
}
|