eh-commons 0.0.1-testing.97 → 0.0.2-testing.78
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/.prettierrc +2 -1
- package/dist/clients/index.d.ts +3 -0
- package/dist/clients/index.js +20 -0
- package/dist/clients/index.js.map +1 -0
- package/dist/clients/rest.client.d.ts +18 -0
- package/dist/clients/rest.client.js +101 -0
- package/dist/clients/rest.client.js.map +1 -0
- package/dist/clients/session.client.d.ts +3 -4
- package/dist/clients/session.client.js +4 -4
- package/dist/clients/session.client.js.map +1 -1
- package/dist/index.d.ts +22 -35
- package/dist/index.js +29 -55
- package/dist/index.js.map +1 -1
- package/dist/models/commons/interfaces/base.interface.d.ts +2 -2
- package/dist/models/interfaces/session/session.interface.d.ts +2 -2
- package/dist/models/rewards/embedded/origin.embedded.schema.d.ts +2 -2
- package/dist/models/rewards/embedded/rewards.embedded.d.ts +2 -2
- package/dist/models/s3/embedded/file-log.embedded.d.ts +2 -2
- package/dist/models/s3/embedded/file-meta.embedded.d.ts +2 -2
- package/dist/models/s3/embedded/file-record.embedded.d.ts +2 -2
- package/dist/models/s3/embedded/file-state.embedded.d.ts +2 -2
- package/dist/models/s3/embedded/file.embedded.d.ts +2 -2
- package/dist/models/s3/embedded/initiator.embedded.d.ts +2 -2
- package/dist/models/s3/embedded/s3.embedded.d.ts +2 -2
- package/dist/models/session/interfaces/session-client-data.interface.d.ts +2 -2
- package/dist/models/util/embedded/address.embedded.d.ts +2 -2
- package/dist/models/util/embedded/author.embedded.d.ts +2 -2
- package/dist/models/util/embedded/contact.embedded.d.ts +2 -2
- package/dist/models/util/embedded/geo-location.embedded.d.ts +2 -2
- package/dist/models/util/embedded/i18n.embedded.d.ts +2 -2
- package/dist/models/util/embedded/record.embedded.d.ts +2 -2
- package/dist/models/util/interfaces/person.interface.d.ts +0 -7
- package/dist/models/util/interfaces/person.interface.js +0 -2
- package/dist/models/wrappers/rest-wrapper.class.js +1 -4
- package/dist/models/wrappers/rest-wrapper.class.js.map +1 -1
- package/dist/modules/core/index.d.ts +6 -0
- package/dist/modules/core/index.js +23 -0
- package/dist/modules/core/index.js.map +1 -0
- package/dist/modules/core/models/enums/feed-type.enum.d.ts +6 -0
- package/dist/modules/core/models/enums/feed-type.enum.js +11 -0
- package/dist/modules/core/models/enums/feed-type.enum.js.map +1 -0
- package/dist/modules/core/models/interfaces/feed-thin.interface.d.ts +9 -0
- package/dist/modules/core/models/interfaces/feed-thin.interface.js +3 -0
- package/dist/modules/core/models/interfaces/feed-thin.interface.js.map +1 -0
- package/dist/modules/core/models/interfaces/index.d.ts +4 -0
- package/dist/modules/core/models/interfaces/index.js +21 -0
- package/dist/modules/core/models/interfaces/index.js.map +1 -0
- package/dist/modules/core/models/interfaces/range.interface.d.ts +4 -0
- package/dist/modules/core/models/interfaces/range.interface.js +3 -0
- package/dist/modules/core/models/interfaces/range.interface.js.map +1 -0
- package/dist/modules/core/models/interfaces/ref.interface.d.ts +6 -0
- package/dist/modules/core/models/interfaces/ref.interface.js +3 -0
- package/dist/modules/core/models/interfaces/ref.interface.js.map +1 -0
- package/dist/modules/core/models/interfaces/scope.interface.d.ts +14 -0
- package/dist/modules/core/models/interfaces/scope.interface.js +3 -0
- package/dist/modules/core/models/interfaces/scope.interface.js.map +1 -0
- package/dist/modules/core/models/schemas/index.d.ts +2 -0
- package/dist/modules/core/models/schemas/index.js +19 -0
- package/dist/modules/core/models/schemas/index.js.map +1 -0
- package/dist/modules/core/models/schemas/range.embedded.d.ts +14 -0
- package/dist/modules/core/models/schemas/range.embedded.js +29 -0
- package/dist/modules/core/models/schemas/range.embedded.js.map +1 -0
- package/dist/modules/core/models/schemas/scope.embedded.d.ts +25 -0
- package/dist/modules/core/models/schemas/scope.embedded.js +63 -0
- package/dist/modules/core/models/schemas/scope.embedded.js.map +1 -0
- package/dist/modules/dictionary/index.d.ts +5 -0
- package/dist/modules/dictionary/index.js +22 -0
- package/dist/modules/dictionary/index.js.map +1 -0
- package/dist/modules/dictionary/models/dtos/dictionary-list.dto.d.ts +10 -0
- package/dist/modules/dictionary/models/dtos/dictionary-list.dto.js +59 -0
- package/dist/modules/dictionary/models/dtos/dictionary-list.dto.js.map +1 -0
- package/dist/modules/dictionary/models/interfaces/index.d.ts +27 -0
- package/dist/modules/dictionary/models/interfaces/index.js +3 -0
- package/dist/modules/dictionary/models/interfaces/index.js.map +1 -0
- package/dist/modules/dictionary/models/schemas/index.d.ts +21 -0
- package/dist/modules/dictionary/models/schemas/index.js +47 -0
- package/dist/modules/dictionary/models/schemas/index.js.map +1 -0
- package/dist/modules/dictionary/services/dictionary.service.d.ts +13 -14
- package/dist/modules/dictionary/services/dictionary.service.js +43 -96
- package/dist/modules/dictionary/services/dictionary.service.js.map +1 -1
- package/dist/modules/dmm/dmm.module.d.ts +2 -0
- package/dist/modules/dmm/dmm.module.js +26 -0
- package/dist/modules/dmm/dmm.module.js.map +1 -0
- package/dist/modules/dmm/index.d.ts +4 -0
- package/dist/modules/dmm/index.js +21 -0
- package/dist/modules/dmm/index.js.map +1 -0
- package/dist/modules/dmm/models/interfaces/index.d.ts +12 -0
- package/dist/modules/dmm/models/interfaces/index.js +3 -0
- package/dist/modules/dmm/models/interfaces/index.js.map +1 -0
- package/dist/modules/dmm/models/schemas/index.d.ts +23 -0
- package/dist/modules/dmm/models/schemas/index.js +58 -0
- package/dist/modules/dmm/models/schemas/index.js.map +1 -0
- package/dist/modules/dmm/services/dmm.service.d.ts +26 -0
- package/dist/modules/dmm/services/dmm.service.js +40 -0
- package/dist/modules/dmm/services/dmm.service.js.map +1 -0
- package/dist/modules/emis/emis.module.d.ts +2 -0
- package/dist/modules/emis/emis.module.js +24 -0
- package/dist/modules/emis/emis.module.js.map +1 -0
- package/dist/modules/emis/index.d.ts +3 -0
- package/dist/modules/emis/index.js +20 -0
- package/dist/modules/emis/index.js.map +1 -0
- package/dist/modules/emis/models/interfaces/emis.interface.d.ts +34 -0
- package/dist/modules/emis/models/interfaces/emis.interface.js +3 -0
- package/dist/modules/emis/models/interfaces/emis.interface.js.map +1 -0
- package/dist/modules/emis/services/emis.service.d.ts +8 -0
- package/dist/modules/emis/services/emis.service.js +37 -0
- package/dist/modules/emis/services/emis.service.js.map +1 -0
- package/dist/modules/iam/iam.module.d.ts +2 -0
- package/dist/modules/iam/iam.module.js +24 -0
- package/dist/modules/iam/iam.module.js.map +1 -0
- package/dist/modules/iam/index.d.ts +5 -0
- package/dist/modules/iam/index.js +22 -0
- package/dist/modules/iam/index.js.map +1 -0
- package/dist/modules/iam/models/enums/index.d.ts +6 -0
- package/dist/modules/iam/models/enums/index.js +11 -0
- package/dist/modules/iam/models/enums/index.js.map +1 -0
- package/dist/modules/iam/models/interfaces/index.d.ts +101 -0
- package/dist/modules/iam/models/interfaces/index.js +3 -0
- package/dist/modules/iam/models/interfaces/index.js.map +1 -0
- package/dist/modules/iam/models/schemas/embedded/person.embedded.d.ts +19 -0
- package/dist/modules/iam/models/schemas/embedded/person.embedded.js +41 -0
- package/dist/modules/iam/models/schemas/embedded/person.embedded.js.map +1 -0
- package/dist/modules/iam/models/schemas/embedded/user-person-info.embedded.d.ts +17 -0
- package/dist/modules/iam/models/schemas/embedded/user-person-info.embedded.js +31 -0
- package/dist/modules/iam/models/schemas/embedded/user-person-info.embedded.js.map +1 -0
- package/dist/modules/iam/models/schemas/index.d.ts +2 -0
- package/dist/modules/iam/models/schemas/index.js +19 -0
- package/dist/modules/iam/models/schemas/index.js.map +1 -0
- package/dist/modules/iam/services/iam.service.d.ts +9 -0
- package/dist/modules/iam/services/iam.service.js +40 -0
- package/dist/modules/iam/services/iam.service.js.map +1 -0
- package/dist/modules/otp/index.d.ts +3 -0
- package/dist/modules/otp/index.js +20 -0
- package/dist/modules/otp/index.js.map +1 -0
- package/dist/modules/otp/models/interfaces/index.d.ts +18 -0
- package/dist/modules/otp/models/interfaces/index.js +3 -0
- package/dist/modules/otp/models/interfaces/index.js.map +1 -0
- package/dist/modules/otp/otp.module.d.ts +2 -0
- package/dist/modules/otp/otp.module.js +24 -0
- package/dist/modules/otp/otp.module.js.map +1 -0
- package/dist/modules/otp/services/otp.service.d.ts +11 -0
- package/dist/modules/otp/services/otp.service.js +48 -0
- package/dist/modules/otp/services/otp.service.js.map +1 -0
- package/dist/modules/session/functions/index.d.ts +5 -0
- package/dist/modules/session/functions/index.js +28 -0
- package/dist/modules/session/functions/index.js.map +1 -0
- package/dist/modules/session/guards/permission.guard.d.ts +15 -0
- package/dist/modules/session/guards/permission.guard.js +118 -0
- package/dist/modules/session/guards/permission.guard.js.map +1 -0
- package/dist/modules/session/guards/user.guard.d.ts +12 -0
- package/dist/modules/session/guards/user.guard.js +88 -0
- package/dist/modules/session/guards/user.guard.js.map +1 -0
- package/dist/modules/session/index.d.ts +9 -0
- package/dist/modules/session/index.js +26 -0
- package/dist/modules/session/index.js.map +1 -0
- package/dist/modules/session/models/classes/index.d.ts +3 -0
- package/dist/modules/session/models/classes/index.js +7 -0
- package/dist/modules/session/models/classes/index.js.map +1 -0
- package/dist/modules/session/models/interfaces/index.d.ts +54 -0
- package/dist/modules/session/models/interfaces/index.js +7 -0
- package/dist/modules/session/models/interfaces/index.js.map +1 -0
- package/dist/modules/session/reflectors/permission.reflector.d.ts +2 -0
- package/dist/modules/session/reflectors/permission.reflector.js +6 -0
- package/dist/modules/session/reflectors/permission.reflector.js.map +1 -0
- package/dist/modules/session/services/redis.service.d.ts +16 -0
- package/dist/modules/session/services/redis.service.js +94 -0
- package/dist/modules/session/services/redis.service.js.map +1 -0
- package/dist/modules/session/services/session-v1.service.d.ts +12 -0
- package/dist/modules/session/services/session-v1.service.js +36 -0
- package/dist/modules/session/services/session-v1.service.js.map +1 -0
- package/dist/modules/session/services/session-v2.service.d.ts +17 -0
- package/dist/modules/session/services/session-v2.service.js +102 -0
- package/dist/modules/session/services/session-v2.service.js.map +1 -0
- package/dist/modules/session/session.module.d.ts +2 -0
- package/dist/modules/session/session.module.js +27 -0
- package/dist/modules/session/session.module.js.map +1 -0
- package/dist/modules/storage/index.d.ts +4 -0
- package/dist/modules/storage/index.js +21 -0
- package/dist/modules/storage/index.js.map +1 -0
- package/dist/modules/storage/models/inerfaces/index.d.ts +7 -0
- package/dist/modules/storage/models/inerfaces/index.js +3 -0
- package/dist/modules/storage/models/inerfaces/index.js.map +1 -0
- package/dist/modules/storage/models/schemas/index.d.ts +36 -0
- package/dist/modules/storage/models/schemas/index.js +62 -0
- package/dist/modules/storage/models/schemas/index.js.map +1 -0
- package/dist/modules/storage/services/storage.service.d.ts +9 -0
- package/dist/modules/storage/services/storage.service.js +35 -0
- package/dist/modules/storage/services/storage.service.js.map +1 -0
- package/dist/modules/storage/storage.module.d.ts +2 -0
- package/dist/modules/storage/storage.module.js +24 -0
- package/dist/modules/storage/storage.module.js.map +1 -0
- package/dist/pipes/index.d.ts +13 -0
- package/dist/pipes/index.js +64 -0
- package/dist/pipes/index.js.map +1 -0
- package/dist/pipes/validate-mongo-id.pipe.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -18
- package/src/clients/index.ts +3 -0
- package/src/clients/rest.client.ts +112 -0
- package/src/clients/session.client.ts +10 -20
- package/src/index.ts +36 -164
- package/src/models/commons/interfaces/base.interface.ts +2 -2
- package/src/models/interfaces/session/session.interface.ts +6 -6
- package/src/models/session/interfaces/session-client-data.interface.ts +2 -2
- package/src/models/util/interfaces/person.interface.ts +1 -7
- package/src/models/wrappers/rest-wrapper.class.ts +1 -4
- package/src/modules/core/index.ts +6 -0
- package/src/modules/core/models/enums/feed-type.enum.ts +6 -0
- package/src/modules/core/models/interfaces/feed-thin.interface.ts +10 -0
- package/src/modules/core/models/interfaces/index.ts +4 -0
- package/src/modules/core/models/interfaces/range.interface.ts +4 -0
- package/src/modules/core/models/interfaces/ref.interface.ts +7 -0
- package/src/modules/core/models/interfaces/scope.interface.ts +15 -0
- package/src/modules/core/models/schemas/index.ts +2 -0
- package/src/modules/core/models/schemas/range.embedded.ts +13 -0
- package/src/modules/core/models/schemas/scope.embedded.ts +41 -0
- package/src/modules/dictionary/index.ts +5 -0
- package/src/modules/dictionary/{dtos → models/dtos}/dictionary-list.dto.ts +9 -16
- package/src/modules/dictionary/models/interfaces/index.ts +31 -0
- package/src/modules/dictionary/models/schemas/index.ts +28 -0
- package/src/modules/dictionary/services/dictionary.service.ts +55 -149
- package/src/modules/dmm/dmm.module.ts +13 -0
- package/src/modules/dmm/index.ts +4 -0
- package/src/modules/dmm/models/interfaces/index.ts +13 -0
- package/src/modules/dmm/models/schemas/index.ts +36 -0
- package/src/modules/dmm/services/dmm.service.ts +33 -0
- package/src/modules/emis/emis.module.ts +11 -0
- package/src/modules/emis/index.ts +3 -0
- package/src/modules/emis/models/interfaces/emis.interface.ts +37 -0
- package/src/modules/emis/services/emis.service.ts +30 -0
- package/src/modules/iam/iam.module.ts +11 -0
- package/src/modules/iam/index.ts +5 -0
- package/src/modules/iam/models/enums/index.ts +6 -0
- package/src/modules/iam/models/interfaces/index.ts +114 -0
- package/src/{models/util → modules/iam/models/schemas}/embedded/person.embedded.ts +5 -1
- package/src/modules/iam/models/schemas/embedded/user-person-info.embedded.ts +16 -0
- package/src/modules/iam/models/schemas/index.ts +2 -0
- package/src/modules/iam/services/iam.service.ts +35 -0
- package/src/modules/otp/index.ts +3 -0
- package/src/modules/otp/models/interfaces/index.ts +20 -0
- package/src/modules/otp/otp.module.ts +11 -0
- package/src/modules/otp/services/otp.service.ts +48 -0
- package/src/modules/session/functions/index.ts +24 -0
- package/src/modules/session/guards/permission.guard.ts +122 -0
- package/src/modules/session/guards/user.guard.ts +88 -0
- package/src/modules/session/index.ts +9 -0
- package/src/modules/session/models/classes/index.ts +3 -0
- package/src/modules/session/models/interfaces/index.ts +57 -0
- package/src/modules/{cache/reflector → session/reflectors}/permission.reflector.ts +1 -1
- package/src/modules/{cache → session}/services/redis.service.ts +23 -20
- package/src/modules/session/services/session-v1.service.ts +30 -0
- package/src/modules/session/services/session-v2.service.ts +113 -0
- package/src/modules/session/session.module.ts +14 -0
- package/src/modules/storage/index.ts +4 -0
- package/src/modules/storage/models/inerfaces/index.ts +8 -0
- package/src/modules/storage/models/schemas/index.ts +42 -0
- package/src/modules/storage/services/storage.service.ts +29 -0
- package/src/modules/storage/storage.module.ts +11 -0
- package/src/pipes/index.ts +49 -0
- package/src/pipes/validate-mongo-id.pipe.ts +1 -3
- package/src/functions/session/keyword.function.ts +0 -14
- package/src/models/dictionary/embedded/dictionary.embedded.ts +0 -31
- package/src/models/dictionary/interfaces/dictionary-embedded.interface.ts +0 -12
- package/src/models/dictionary/interfaces/dictionary-event.interface.ts +0 -6
- package/src/models/dictionary/interfaces/dictionary-setting.interface.ts +0 -5
- package/src/models/dictionary/interfaces/dictionary.interface.ts +0 -13
- package/src/models/session/interfaces/session-user-data.interface.ts +0 -16
- package/src/models/um/enums/client-type.enum.ts +0 -6
- package/src/models/um/enums/permission-include-strategy.enum.ts +0 -5
- package/src/models/um/interfaces/client.interface.ts +0 -23
- package/src/models/um/interfaces/credentials.interface.ts +0 -4
- package/src/models/um/interfaces/permission.interface.ts +0 -11
- package/src/models/um/interfaces/prof-info.interface.ts +0 -5
- package/src/models/um/interfaces/role.interface.ts +0 -14
- package/src/models/um/interfaces/user-client.interface.ts +0 -10
- package/src/models/um/interfaces/user.interface.ts +0 -20
- package/src/models/wrappers/permission-guard-config.wrapper.ts +0 -5
- package/src/modules/cache/cache.module.ts +0 -13
- package/src/modules/cache/guards/permission.guard.ts +0 -109
- package/src/modules/cache/services/session.service.ts +0 -23
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Types } from 'mongoose';
|
|
2
|
+
import { IAddress, IBase, IContact, IDictionaryEmbedded, II18n, IUserScope } from '../../../..';
|
|
3
|
+
|
|
4
|
+
export interface IRole extends IBase {
|
|
5
|
+
keyword: string;
|
|
6
|
+
name?: II18n;
|
|
7
|
+
description?: II18n;
|
|
8
|
+
permissions: IPermission[];
|
|
9
|
+
default?: boolean;
|
|
10
|
+
initial?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ICredentials {
|
|
14
|
+
username: string;
|
|
15
|
+
password: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface IPermission extends IBase {
|
|
19
|
+
name?: II18n;
|
|
20
|
+
description?: II18n;
|
|
21
|
+
keyword: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface IProfInfo {
|
|
25
|
+
subjects: IDictionaryEmbedded[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ICompleteRole {
|
|
29
|
+
_id: Types.ObjectId | string;
|
|
30
|
+
keyword: string;
|
|
31
|
+
name?: any;
|
|
32
|
+
description?: any;
|
|
33
|
+
permissions: IPermission[];
|
|
34
|
+
default?: boolean;
|
|
35
|
+
initial?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface IClient extends IBase {
|
|
39
|
+
originId: Types.ObjectId | string;
|
|
40
|
+
type: IDictionaryEmbedded;
|
|
41
|
+
parent: Types.ObjectId | IClient;
|
|
42
|
+
name: II18n;
|
|
43
|
+
address: IAddress;
|
|
44
|
+
highland: boolean;
|
|
45
|
+
code: string;
|
|
46
|
+
contacts: IContact[];
|
|
47
|
+
region: IDictionaryEmbedded;
|
|
48
|
+
district: IDictionaryEmbedded;
|
|
49
|
+
languageSectors: IDictionaryEmbedded[];
|
|
50
|
+
levels: IDictionaryEmbedded[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface IClientThin {
|
|
54
|
+
_id: Types.ObjectId | string;
|
|
55
|
+
originId: Types.ObjectId | string;
|
|
56
|
+
type: IDictionaryEmbedded;
|
|
57
|
+
parent: Types.ObjectId | IClient;
|
|
58
|
+
name: II18n;
|
|
59
|
+
address: IAddress;
|
|
60
|
+
highland: boolean;
|
|
61
|
+
code: string;
|
|
62
|
+
contacts: IContact[];
|
|
63
|
+
region: IDictionaryEmbedded;
|
|
64
|
+
district: IDictionaryEmbedded;
|
|
65
|
+
languageSectors: IDictionaryEmbedded[];
|
|
66
|
+
levels: IDictionaryEmbedded[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface ICompleteUserData {
|
|
70
|
+
_id: Types.ObjectId | string;
|
|
71
|
+
person: IPerson;
|
|
72
|
+
contacts: IContact[];
|
|
73
|
+
clients: ICompleteUserClient[];
|
|
74
|
+
credentials: ICredentials;
|
|
75
|
+
scope: IUserScope;
|
|
76
|
+
address: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface IUser extends IBase {
|
|
80
|
+
person: IPerson;
|
|
81
|
+
contacts: IContact[];
|
|
82
|
+
clients: IUserClient[];
|
|
83
|
+
profInfo: IProfInfo;
|
|
84
|
+
credentials: ICredentials;
|
|
85
|
+
level: IDictionaryEmbedded;
|
|
86
|
+
address?: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface ICompleteUserClient {
|
|
90
|
+
client: IClient;
|
|
91
|
+
roles: ICompleteRole[];
|
|
92
|
+
subjects: IDictionaryEmbedded[];
|
|
93
|
+
languageSectors: IDictionaryEmbedded[];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface IUserClient {
|
|
97
|
+
client: Types.ObjectId | IClient;
|
|
98
|
+
roles: Types.ObjectId[] | IRole[];
|
|
99
|
+
subjects: IDictionaryEmbedded[];
|
|
100
|
+
languageSectors: IDictionaryEmbedded[];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface IUserPersonInfo {
|
|
104
|
+
_id: Types.ObjectId | string;
|
|
105
|
+
person: IPerson;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface IPerson {
|
|
109
|
+
pid: string;
|
|
110
|
+
firstName: string;
|
|
111
|
+
lastName: string;
|
|
112
|
+
gender: number;
|
|
113
|
+
birthDate: Date;
|
|
114
|
+
}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
|
2
2
|
import { HydratedDocument } from 'mongoose';
|
|
3
|
-
import { IPerson } from '
|
|
3
|
+
import { IPerson } from '../../interfaces';
|
|
4
4
|
|
|
5
5
|
@Schema({ _id: false })
|
|
6
6
|
export class Person implements IPerson {
|
|
7
7
|
@Prop({ type: String, required: false })
|
|
8
8
|
pid: string;
|
|
9
|
+
|
|
9
10
|
@Prop({ type: String, required: false })
|
|
10
11
|
firstName: string;
|
|
12
|
+
|
|
11
13
|
@Prop({ type: String, required: false })
|
|
12
14
|
lastName: string;
|
|
15
|
+
|
|
13
16
|
@Prop({ type: Number, required: false })
|
|
14
17
|
gender: number;
|
|
18
|
+
|
|
15
19
|
@Prop({ type: Date, required: false })
|
|
16
20
|
birthDate: Date;
|
|
17
21
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
|
2
|
+
import { HydratedDocument, SchemaTypes, Types } from 'mongoose';
|
|
3
|
+
import { IUserPersonInfo } from '../../interfaces';
|
|
4
|
+
import { Person, PersonSchema } from './person.embedded';
|
|
5
|
+
|
|
6
|
+
@Schema({ _id: false })
|
|
7
|
+
export class UserPersonInfo implements IUserPersonInfo {
|
|
8
|
+
@Prop({ type: SchemaTypes.ObjectId, required: true })
|
|
9
|
+
_id: string | Types.ObjectId;
|
|
10
|
+
|
|
11
|
+
@Prop({ type: PersonSchema, required: true })
|
|
12
|
+
person: Person;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const UserPersonInfoSchema = SchemaFactory.createForClass(UserPersonInfo);
|
|
16
|
+
export type UserPersonInfoDocument = HydratedDocument<UserPersonInfo>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import { RestClient } from '../../../clients';
|
|
4
|
+
import { ICompleteUserData, IUserPersonInfo } from '../models/interfaces';
|
|
5
|
+
import * as qs from 'qs';
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class IAMService {
|
|
9
|
+
//#region Private Members
|
|
10
|
+
private readonly _client: RestClient;
|
|
11
|
+
//#endregion
|
|
12
|
+
|
|
13
|
+
//#region Constructor
|
|
14
|
+
constructor(private readonly _configService: ConfigService) {
|
|
15
|
+
this._client = new RestClient({
|
|
16
|
+
name: 'IAM_SERVICE',
|
|
17
|
+
baseUrl: this._configService.get('EH_UM__REST__BASE_URL', ''),
|
|
18
|
+
timeout: 30000,
|
|
19
|
+
accessToken: this._configService.get('EH_UM__REST__ACCESS_TOKEN', ''),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
|
|
24
|
+
//#region Public APIs
|
|
25
|
+
public async fetchByEmail(email: string): Promise<ICompleteUserData> {
|
|
26
|
+
const query = qs.stringify({ email });
|
|
27
|
+
return await this._client.get<ICompleteUserData>(`/internals/v1/users/init/private?${query}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public async fetchById(userId: string): Promise<IUserPersonInfo> {
|
|
31
|
+
return await this._client.get<IUserPersonInfo>(`/internals/v1/users/${userId}/profile`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface IOTPMetaData {
|
|
2
|
+
duration: number;
|
|
3
|
+
type: string;
|
|
4
|
+
appKeyword: string;
|
|
5
|
+
email: string;
|
|
6
|
+
senderName: string;
|
|
7
|
+
createAt: Date;
|
|
8
|
+
token: string;
|
|
9
|
+
expirationDuration: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface IOTPTokenState {
|
|
13
|
+
valid: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface IOTPCodeState extends IOTPTokenState {}
|
|
17
|
+
|
|
18
|
+
export interface IOTPTokenExists {
|
|
19
|
+
exists: boolean;
|
|
20
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { ConfigModule } from '@nestjs/config';
|
|
3
|
+
import { OTPService } from './services/otp.service';
|
|
4
|
+
|
|
5
|
+
@Module({
|
|
6
|
+
imports: [ConfigModule],
|
|
7
|
+
controllers: [],
|
|
8
|
+
providers: [OTPService],
|
|
9
|
+
exports: [OTPService],
|
|
10
|
+
})
|
|
11
|
+
export class OTPModule {}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import { RestClient } from '../../../clients';
|
|
4
|
+
import { IOTPCodeState, IOTPMetaData, IOTPTokenExists, IOTPTokenState } from '../models/interfaces';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Crap API designed by Clite Ogiashvili
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
@Injectable()
|
|
11
|
+
export class OTPService {
|
|
12
|
+
//#region Private Members
|
|
13
|
+
private readonly _client: RestClient;
|
|
14
|
+
//#endregion
|
|
15
|
+
|
|
16
|
+
//#region Constructor
|
|
17
|
+
constructor(private _configService: ConfigService) {
|
|
18
|
+
this._client = new RestClient({
|
|
19
|
+
name: 'OTP_SERVICE',
|
|
20
|
+
baseUrl: this._configService.get('EH_OTPS__REST__BASE_URL', ''),
|
|
21
|
+
timeout: 30000,
|
|
22
|
+
accessToken: this._configService.get('EH_OTPS__REST__ACCESS_TOKEN', ''),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
|
|
27
|
+
//#region Public APIs
|
|
28
|
+
public async init(senderName: string, email: string, appKeyword: string) {
|
|
29
|
+
const requestBody = { data: { senderName, email, appKeyword } };
|
|
30
|
+
return this._client.post<IOTPMetaData>(`/otp/email`, requestBody);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public async validateCode(token: string, code: string, email: string, appKeyword: string) {
|
|
34
|
+
const requestBody = { data: { email, code, appKeyword, token } };
|
|
35
|
+
return this._client.post<IOTPCodeState>(`/otp/email/validate`, requestBody);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public async validateToken(token: string, email: string, appKeyword: string) {
|
|
39
|
+
const requestBody = { data: { email, appKeyword, token } };
|
|
40
|
+
return this._client.post<IOTPTokenState>(`/otp/check`, requestBody);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public async validateTokenForResend(token: string, email: string, appKeyword: string) {
|
|
44
|
+
const requestBody = { data: { email, appKeyword, token } };
|
|
45
|
+
return this._client.post<IOTPTokenExists>(`/otp/resend/check`, requestBody);
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function generateSessionKeyword(token: string) {
|
|
2
|
+
return `sessions::${token}`;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function generateUserClientsKeyword(userId: string) {
|
|
6
|
+
return `user::${userId}::clients`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function generateUserClientPermissionKeyword(userId: string, clientId: string) {
|
|
10
|
+
return `user::${userId}::clients::${clientId}`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function generateUserSessionTokenKeyword(userId: string) {
|
|
14
|
+
return `user::${userId}::token`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getSessionTokenFromHeader(headers: any) {
|
|
18
|
+
let token = headers.authorization;
|
|
19
|
+
if (token) {
|
|
20
|
+
token = token.replace('bearer ', '');
|
|
21
|
+
token = token.replace('Bearer ', '');
|
|
22
|
+
}
|
|
23
|
+
return token;
|
|
24
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Injectable, CanActivate, ExecutionContext, HttpStatus } from '@nestjs/common';
|
|
2
|
+
import { Reflector } from '@nestjs/core';
|
|
3
|
+
import { Permission } from '../reflectors/permission.reflector';
|
|
4
|
+
import { RESTError } from '../../../models/wrappers/rest-wrapper.class';
|
|
5
|
+
import { Observable, map, mergeMap } from 'rxjs';
|
|
6
|
+
import { IClient, IPermission } from '../../iam';
|
|
7
|
+
import { IUserSessionData, IUserScope } from '../../session/models/interfaces';
|
|
8
|
+
import { SessionV1Service } from '../services/session-v1.service';
|
|
9
|
+
import { getSessionTokenFromHeader } from '../functions';
|
|
10
|
+
|
|
11
|
+
@Injectable()
|
|
12
|
+
export class PermissionGuard implements CanActivate {
|
|
13
|
+
//#region Constructor
|
|
14
|
+
constructor(
|
|
15
|
+
private readonly _sessionV1Service: SessionV1Service,
|
|
16
|
+
private readonly _reflector: Reflector,
|
|
17
|
+
) {}
|
|
18
|
+
//#endregion
|
|
19
|
+
|
|
20
|
+
//#region Lifecycle Events
|
|
21
|
+
public canActivate(context: ExecutionContext): Observable<boolean> {
|
|
22
|
+
const config = this._reflector.get(Permission, context.getHandler());
|
|
23
|
+
const request = context.switchToHttp().getRequest();
|
|
24
|
+
const queryParameters = request.query;
|
|
25
|
+
const headers = request.headers;
|
|
26
|
+
const token: string = getSessionTokenFromHeader(headers);
|
|
27
|
+
if (!token) {
|
|
28
|
+
throw new RESTError('unauthorized', null, HttpStatus.UNAUTHORIZED);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const clientId: string = this._getClientIdFromQuery(queryParameters);
|
|
32
|
+
const userData$ = this._sessionV1Service.getUserData(token);
|
|
33
|
+
const result$ = userData$.pipe(
|
|
34
|
+
map(this._validateUserData),
|
|
35
|
+
mergeMap((userData) => {
|
|
36
|
+
return this._sessionV1Service.getUserClientPermissions(userData.userId, clientId).pipe(
|
|
37
|
+
map((data) => {
|
|
38
|
+
return {
|
|
39
|
+
user: userData,
|
|
40
|
+
client: data?.client,
|
|
41
|
+
permissions: data?.permissions,
|
|
42
|
+
};
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
45
|
+
}),
|
|
46
|
+
mergeMap((data) => {
|
|
47
|
+
if (data?.user && !data.user.scope && data.client) {
|
|
48
|
+
return this._sessionV1Service.getClientData(data.user.userId).pipe(
|
|
49
|
+
map((clientsMap: any) => {
|
|
50
|
+
const clientData = clientsMap?.[data.client._id?.toString()];
|
|
51
|
+
if (clientData) {
|
|
52
|
+
data.user.scope = this._buildScopeFromClient(clientData);
|
|
53
|
+
}
|
|
54
|
+
return data;
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return new Observable<typeof data>((subscriber) => {
|
|
59
|
+
subscriber.next(data);
|
|
60
|
+
subscriber.complete();
|
|
61
|
+
});
|
|
62
|
+
}),
|
|
63
|
+
map((data) => {
|
|
64
|
+
this._setUserData(data?.user, data?.client, data?.permissions, request);
|
|
65
|
+
return this._checkPermission(data?.permissions, config.keyword);
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
return result$;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
|
|
72
|
+
//#region Private APIs
|
|
73
|
+
private _getClientIdFromQuery(queryParameters: any) {
|
|
74
|
+
return queryParameters.clientId;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private _checkPermission(userPermissions: IPermission[], allowedPermission: string): boolean {
|
|
78
|
+
if (allowedPermission) {
|
|
79
|
+
if (!userPermissions || !userPermissions.length) {
|
|
80
|
+
throw new RESTError('forbidden', null, HttpStatus.FORBIDDEN);
|
|
81
|
+
}
|
|
82
|
+
const check = userPermissions.some((item) => item.keyword === allowedPermission);
|
|
83
|
+
if (check) {
|
|
84
|
+
return true;
|
|
85
|
+
} else {
|
|
86
|
+
throw new RESTError('forbidden', null, HttpStatus.FORBIDDEN);
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private _setUserData(userData: IUserSessionData, client: IClient, permissions: IPermission[], request: Request) {
|
|
94
|
+
const userInfo = {
|
|
95
|
+
user: userData,
|
|
96
|
+
client,
|
|
97
|
+
permissions,
|
|
98
|
+
};
|
|
99
|
+
request['session'] = userInfo;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private _validateUserData(userData: IUserSessionData) {
|
|
103
|
+
if (!userData) {
|
|
104
|
+
throw new RESTError('unauthorized', null, HttpStatus.UNAUTHORIZED);
|
|
105
|
+
}
|
|
106
|
+
return userData;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private _buildScopeFromClient(clientData: any): IUserScope {
|
|
110
|
+
return {
|
|
111
|
+
levels: clientData.levels || [],
|
|
112
|
+
subjects: clientData.subjects || [],
|
|
113
|
+
schoolTypes: [],
|
|
114
|
+
languageSectors: clientData.languageSectors || [],
|
|
115
|
+
districts: clientData.district ? [clientData.district] : [],
|
|
116
|
+
gender: null,
|
|
117
|
+
birthDate: null,
|
|
118
|
+
highland: clientData.highland || false,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Injectable, CanActivate, ExecutionContext, HttpStatus } from '@nestjs/common';
|
|
2
|
+
import { RESTError } from '../../../models/wrappers/rest-wrapper.class';
|
|
3
|
+
import { Observable, map, mergeMap, of } from 'rxjs';
|
|
4
|
+
import { IClient, IPermission } from '../../iam';
|
|
5
|
+
import { IUserSessionData } from '../models/interfaces';
|
|
6
|
+
import { SessionV1Service } from '../services/session-v1.service';
|
|
7
|
+
import { getSessionTokenFromHeader } from '../functions';
|
|
8
|
+
|
|
9
|
+
@Injectable()
|
|
10
|
+
export class UserGuard implements CanActivate {
|
|
11
|
+
//#region Constructor
|
|
12
|
+
constructor(private readonly _sessionV1Service: SessionV1Service) {}
|
|
13
|
+
//#endregion
|
|
14
|
+
|
|
15
|
+
//#region Lifecycle Events
|
|
16
|
+
public canActivate(context: ExecutionContext): Observable<boolean> {
|
|
17
|
+
const request = context.switchToHttp().getRequest();
|
|
18
|
+
const queryParameters = request.query;
|
|
19
|
+
const headers = request.headers;
|
|
20
|
+
const token: string = getSessionTokenFromHeader(headers);
|
|
21
|
+
if (!token) {
|
|
22
|
+
return of(true);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const clientId: string = this._getClientIdFromQuery(queryParameters);
|
|
26
|
+
const userData$ = this._sessionV1Service.getUserData(token);
|
|
27
|
+
const result$ = userData$.pipe(
|
|
28
|
+
map(this._validateUserData),
|
|
29
|
+
mergeMap((userData) => {
|
|
30
|
+
if (!userData) return of(null);
|
|
31
|
+
return this._sessionV1Service.getUserClientPermissions(userData.userId, clientId).pipe(
|
|
32
|
+
map((data) => {
|
|
33
|
+
return {
|
|
34
|
+
user: userData,
|
|
35
|
+
client: data?.client,
|
|
36
|
+
permissions: data?.permissions,
|
|
37
|
+
};
|
|
38
|
+
}),
|
|
39
|
+
);
|
|
40
|
+
}),
|
|
41
|
+
map((data) => {
|
|
42
|
+
if (!data) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this._setUserData(data?.user, data?.client, data?.permissions, request);
|
|
47
|
+
return true;
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
return result$;
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
|
|
54
|
+
//#region Private APIs
|
|
55
|
+
private _getClientIdFromQuery(queryParameters: any) {
|
|
56
|
+
return queryParameters.clientId;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private _checkPermission(userPermissions: IPermission[], allowedPermission: string): boolean {
|
|
60
|
+
if (allowedPermission) {
|
|
61
|
+
if (!userPermissions || !userPermissions.length) {
|
|
62
|
+
throw new RESTError('forbidden', HttpStatus.FORBIDDEN);
|
|
63
|
+
}
|
|
64
|
+
const check = userPermissions.some((item) => item.keyword === allowedPermission);
|
|
65
|
+
if (check) {
|
|
66
|
+
return true;
|
|
67
|
+
} else {
|
|
68
|
+
throw new RESTError('forbidden', HttpStatus.FORBIDDEN);
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private _setUserData(userData: IUserSessionData, client: IClient, permissions: IPermission[], request: Request) {
|
|
76
|
+
const userInfo = {
|
|
77
|
+
user: userData,
|
|
78
|
+
client,
|
|
79
|
+
permissions,
|
|
80
|
+
};
|
|
81
|
+
request['session'] = userInfo;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private _validateUserData(userData: IUserSessionData) {
|
|
85
|
+
return userData;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './services/session-v1.service';
|
|
2
|
+
export * from './services/session-v2.service';
|
|
3
|
+
export * from './models/interfaces';
|
|
4
|
+
export * from './models/classes';
|
|
5
|
+
export * from './functions';
|
|
6
|
+
export * from './reflectors/permission.reflector';
|
|
7
|
+
export * from './guards/permission.guard';
|
|
8
|
+
export * from './guards/user.guard';
|
|
9
|
+
export * from './session.module';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { IAddress } from '../../../../models/util/interfaces/address.interface';
|
|
2
|
+
import { IContact } from '../../../../models/util/interfaces/contact.interface';
|
|
3
|
+
import { II18n } from '../../../../models/util/interfaces/i18n.interface';
|
|
4
|
+
import { IDictionaryEmbedded } from '../../../dictionary';
|
|
5
|
+
import { IResult } from 'ua-parser-js';
|
|
6
|
+
import { IClient, IPermission } from '../../../iam';
|
|
7
|
+
|
|
8
|
+
export class ISessionClientData {
|
|
9
|
+
clientId: string;
|
|
10
|
+
type: IDictionaryEmbedded;
|
|
11
|
+
name: II18n;
|
|
12
|
+
address: IAddress;
|
|
13
|
+
highland: boolean;
|
|
14
|
+
code: string;
|
|
15
|
+
contacts: IContact[];
|
|
16
|
+
region: IDictionaryEmbedded;
|
|
17
|
+
district: IDictionaryEmbedded;
|
|
18
|
+
languageSectors: IDictionaryEmbedded[];
|
|
19
|
+
levels: IDictionaryEmbedded[];
|
|
20
|
+
subjects: IDictionaryEmbedded[];
|
|
21
|
+
permissions: IPermission[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ISessionData {
|
|
25
|
+
sessionToken: string;
|
|
26
|
+
userInfo: IUserSessionData;
|
|
27
|
+
userClients: { [key: string]: ISessionClientData };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface IUserScope {
|
|
31
|
+
levels: IDictionaryEmbedded[];
|
|
32
|
+
subjects: IDictionaryEmbedded[];
|
|
33
|
+
schoolTypes: IDictionaryEmbedded[];
|
|
34
|
+
languageSectors: IDictionaryEmbedded[];
|
|
35
|
+
districts: IDictionaryEmbedded[];
|
|
36
|
+
gender: number;
|
|
37
|
+
birthDate: Date;
|
|
38
|
+
highland: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface IUserSessionData {
|
|
42
|
+
userId: string;
|
|
43
|
+
username: string;
|
|
44
|
+
fistName: string;
|
|
45
|
+
lastName: string;
|
|
46
|
+
contacts: IContact[];
|
|
47
|
+
pid: string;
|
|
48
|
+
scope: IUserScope;
|
|
49
|
+
address: string;
|
|
50
|
+
ua: IResult;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface IUserSession {
|
|
54
|
+
user: IUserSessionData;
|
|
55
|
+
client: IClient;
|
|
56
|
+
permissions: IPermission[];
|
|
57
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Reflector } from '@nestjs/core';
|
|
2
|
-
import { PermissionGuardConfig } from '
|
|
2
|
+
import { PermissionGuardConfig } from '../models/classes';
|
|
3
3
|
|
|
4
4
|
export const Permission = Reflector.createDecorator<PermissionGuardConfig>();
|
|
@@ -5,26 +5,32 @@ import { AppLogger } from '../../core/services/app-logger.service';
|
|
|
5
5
|
|
|
6
6
|
@Injectable()
|
|
7
7
|
export class RedisService {
|
|
8
|
-
|
|
9
|
-
private
|
|
10
|
-
private
|
|
8
|
+
//#region Private Members
|
|
9
|
+
private readonly _client: IORedis.Redis;
|
|
10
|
+
private readonly _clusterClient: IORedis.Cluster;
|
|
11
|
+
private readonly _isCluster: boolean;
|
|
12
|
+
//#endregion
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
//#region Constructor
|
|
15
|
+
constructor(private readonly _logger: AppLogger) {
|
|
13
16
|
const redisConnectionString = this._getString('REDIS__CS', null);
|
|
14
17
|
this._isCluster = this._getBoolean('REDIS__CLUSTER', false);
|
|
15
|
-
|
|
16
|
-
_logger.log('##########
|
|
18
|
+
|
|
19
|
+
_logger.log('########## REDIS__CLUSTER:' + this._isCluster);
|
|
20
|
+
_logger.log('########## REDIS__CS:' + redisConnectionString);
|
|
17
21
|
|
|
18
22
|
if (this._isCluster === true) {
|
|
19
23
|
const nodes = this._parseRedisClusterUrl(redisConnectionString);
|
|
20
|
-
_logger.log('########## NODES:' + JSON.stringify(nodes))
|
|
21
|
-
this.
|
|
24
|
+
_logger.log('########## NODES:' + JSON.stringify(nodes));
|
|
25
|
+
this._clusterClient = new IORedis.Cluster(nodes);
|
|
22
26
|
} else {
|
|
23
|
-
_logger.log('########## REDIS__SINGLE_NODE')
|
|
24
|
-
this.
|
|
27
|
+
_logger.log('########## REDIS__SINGLE_NODE');
|
|
28
|
+
this._client = new IORedis.Redis(redisConnectionString);
|
|
25
29
|
}
|
|
26
30
|
}
|
|
31
|
+
//#endregion
|
|
27
32
|
|
|
33
|
+
//#region Public APIs
|
|
28
34
|
async set(key: string, value: string, ttl?: number): Promise<string> {
|
|
29
35
|
let result: string | PromiseLike<string>;
|
|
30
36
|
if (ttl) {
|
|
@@ -45,18 +51,17 @@ export class RedisService {
|
|
|
45
51
|
|
|
46
52
|
public getRedisClient() {
|
|
47
53
|
if (!this._isCluster) {
|
|
48
|
-
return this.
|
|
54
|
+
return this._client;
|
|
49
55
|
} else {
|
|
50
|
-
return this.
|
|
56
|
+
return this._clusterClient;
|
|
51
57
|
}
|
|
52
58
|
}
|
|
59
|
+
//#endregion
|
|
53
60
|
|
|
61
|
+
//#region Private APIs
|
|
54
62
|
private _parseRedisClusterUrl(connectionString: string) {
|
|
55
63
|
if (!connectionString.startsWith('redis://')) {
|
|
56
|
-
throw new RESTError(
|
|
57
|
-
'invalid_connection_string',
|
|
58
|
-
'Invalid connection string format',
|
|
59
|
-
);
|
|
64
|
+
throw new RESTError('invalid_connection_string', 'Invalid connection string format');
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
return connectionString
|
|
@@ -67,10 +72,7 @@ export class RedisService {
|
|
|
67
72
|
const port = parseInt(portStr, 10);
|
|
68
73
|
|
|
69
74
|
if (!host || isNaN(port)) {
|
|
70
|
-
throw new RESTError(
|
|
71
|
-
'invalid_redis_host_port',
|
|
72
|
-
`Invalid host:port entry: ${entry}`,
|
|
73
|
-
);
|
|
75
|
+
throw new RESTError('invalid_redis_host_port', `Invalid host:port entry: ${entry}`);
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
return { host, port };
|
|
@@ -92,4 +94,5 @@ export class RedisService {
|
|
|
92
94
|
}
|
|
93
95
|
return value.toLowerCase() === 'true';
|
|
94
96
|
}
|
|
97
|
+
//#endregion
|
|
95
98
|
}
|