@node-c/core 1.0.0-alpha9 → 1.0.0-beta0
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/coverage/src/app.ts.html +349 -0
- package/coverage/src/common/configProvider/configProvider.module.ts.html +160 -0
- package/coverage/src/common/configProvider/configProvider.service.ts.html +658 -0
- package/coverage/src/common/configProvider/index.html +146 -0
- package/coverage/src/common/configProvider/index.ts.html +94 -0
- package/coverage/src/common/definitions/common.constants.ts.html +160 -0
- package/coverage/src/common/definitions/common.errors.ts.html +124 -0
- package/coverage/src/common/definitions/index.html +146 -0
- package/coverage/src/common/definitions/index.ts.html +94 -0
- package/coverage/src/common/utils/index.html +131 -0
- package/coverage/src/common/utils/index.ts.html +88 -0
- package/coverage/src/common/utils/utils.loadDynamicModules.ts.html +265 -0
- package/coverage/src/domain/entityService/domain.entity.service.ts.html +784 -0
- package/coverage/src/domain/entityService/index.html +131 -0
- package/coverage/src/domain/entityService/index.ts.html +91 -0
- package/coverage/src/index.html +116 -0
- package/coverage/src/persistance/entityService/index.html +131 -0
- package/coverage/src/persistance/entityService/index.ts.html +91 -0
- package/coverage/src/persistance/entityService/persistance.entity.service.ts.html +268 -0
- package/dist/app.d.ts +2 -2
- package/dist/app.js +27 -15
- package/dist/app.js.map +1 -1
- package/dist/common/configProvider/configProvider.definitions.d.ts +156 -20
- package/dist/common/configProvider/configProvider.definitions.js +21 -7
- package/dist/common/configProvider/configProvider.definitions.js.map +1 -1
- package/dist/common/configProvider/configProvider.module.js +13 -2
- package/dist/common/configProvider/configProvider.module.js.map +1 -1
- package/dist/common/configProvider/configProvider.service.js +21 -18
- package/dist/common/configProvider/configProvider.service.js.map +1 -1
- package/dist/common/definitions/common.constants.d.ts +2 -1
- package/dist/common/definitions/common.constants.js +1 -0
- package/dist/common/definitions/common.constants.js.map +1 -1
- package/dist/common/utils/base64UrlEncode/base64UrlEncode.method.d.ts +1 -0
- package/dist/common/utils/base64UrlEncode/base64UrlEncode.method.js +9 -0
- package/dist/common/utils/base64UrlEncode/base64UrlEncode.method.js.map +1 -0
- package/dist/common/utils/base64UrlEncode/index.d.ts +1 -0
- package/dist/{persistance/entityService → common/utils/base64UrlEncode}/index.js +1 -2
- package/dist/common/utils/base64UrlEncode/index.js.map +1 -0
- package/dist/common/utils/getNested/getNested.definitions.d.ts +4 -0
- package/dist/common/utils/getNested/getNested.definitions.js +3 -0
- package/dist/common/utils/getNested/getNested.definitions.js.map +1 -0
- package/dist/common/utils/getNested/getNested.method.d.ts +6 -0
- package/dist/common/utils/getNested/getNested.method.js +88 -0
- package/dist/common/utils/getNested/getNested.method.js.map +1 -0
- package/dist/common/utils/getNested/index.d.ts +2 -0
- package/dist/common/utils/getNested/index.js +19 -0
- package/dist/common/utils/getNested/index.js.map +1 -0
- package/dist/common/utils/httpRequest/httpRequest.definitions.d.ts +19 -0
- package/dist/common/utils/httpRequest/httpRequest.definitions.js +3 -0
- package/dist/common/utils/httpRequest/httpRequest.definitions.js.map +1 -0
- package/dist/common/utils/httpRequest/httpRequest.method.d.ts +2 -0
- package/dist/common/utils/httpRequest/httpRequest.method.js +56 -0
- package/dist/common/utils/httpRequest/httpRequest.method.js.map +1 -0
- package/dist/common/utils/httpRequest/index.d.ts +2 -0
- package/dist/common/utils/httpRequest/index.js +19 -0
- package/dist/common/utils/httpRequest/index.js.map +1 -0
- package/dist/common/utils/index.d.ts +5 -1
- package/dist/common/utils/index.js +5 -1
- package/dist/common/utils/index.js.map +1 -1
- package/dist/common/utils/loadDynamicModules/index.d.ts +1 -0
- package/dist/common/utils/loadDynamicModules/index.js +18 -0
- package/dist/common/utils/loadDynamicModules/index.js.map +1 -0
- package/dist/common/utils/{utils.loadDynamicModules.d.ts → loadDynamicModules/utils.loadDynamicModules.d.ts} +1 -1
- package/dist/common/utils/loadDynamicModules/utils.loadDynamicModules.js.map +1 -0
- package/dist/common/utils/setNested/index.d.ts +2 -0
- package/dist/common/utils/setNested/index.js +19 -0
- package/dist/common/utils/setNested/index.js.map +1 -0
- package/dist/common/utils/setNested/setNested.definitions.d.ts +4 -0
- package/dist/common/utils/setNested/setNested.definitions.js +3 -0
- package/dist/common/utils/setNested/setNested.definitions.js.map +1 -0
- package/dist/common/utils/setNested/setNested.method.d.ts +2 -0
- package/dist/common/utils/setNested/setNested.method.js +70 -0
- package/dist/common/utils/setNested/setNested.method.js.map +1 -0
- package/dist/data/entityService/data.entity.service.d.ts +17 -0
- package/dist/data/entityService/data.entity.service.definitions.d.ts +117 -0
- package/dist/data/entityService/data.entity.service.definitions.js +28 -0
- package/dist/data/entityService/data.entity.service.definitions.js.map +1 -0
- package/dist/{persistance/entityService/persistance.entity.service.js → data/entityService/data.entity.service.js} +41 -9
- package/dist/data/entityService/data.entity.service.js.map +1 -0
- package/dist/data/entityService/index.d.ts +2 -0
- package/dist/data/entityService/index.js +19 -0
- package/dist/data/entityService/index.js.map +1 -0
- package/dist/domain/entityService/domain.entity.service.d.ts +28 -13
- package/dist/domain/entityService/domain.entity.service.definitions.d.ts +26 -19
- package/dist/domain/entityService/domain.entity.service.definitions.js +6 -6
- package/dist/domain/entityService/domain.entity.service.definitions.js.map +1 -1
- package/dist/domain/entityService/domain.entity.service.js +77 -69
- package/dist/domain/entityService/domain.entity.service.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +11 -10
- package/src/app.spec.ts +138 -0
- package/src/app.ts +115 -0
- package/src/common/configProvider/configProvider.definitions.ts +445 -0
- package/src/common/configProvider/configProvider.module.spec.ts +90 -0
- package/src/common/configProvider/configProvider.module.ts +25 -0
- package/src/common/configProvider/configProvider.service.spec.ts +206 -0
- package/src/common/configProvider/configProvider.service.ts +204 -0
- package/src/common/configProvider/index.ts +3 -0
- package/src/common/definitions/common.constants.ts +27 -0
- package/src/common/definitions/common.definitions.ts +13 -0
- package/src/common/definitions/common.errors.ts +13 -0
- package/src/common/definitions/index.ts +3 -0
- package/src/common/utils/base64UrlEncode/base64UrlEncode.method.ts +4 -0
- package/src/common/utils/base64UrlEncode/index.ts +1 -0
- package/src/common/utils/getNested/getNested.definitions.ts +4 -0
- package/src/common/utils/getNested/getNested.method.ts +108 -0
- package/src/common/utils/getNested/getNested.spec.ts +151 -0
- package/src/common/utils/getNested/index.ts +2 -0
- package/src/common/utils/httpRequest/httpRequest.definitions.ts +22 -0
- package/src/common/utils/httpRequest/httpRequest.method.ts +46 -0
- package/src/common/utils/httpRequest/index.ts +2 -0
- package/src/common/utils/index.ts +5 -0
- package/src/common/utils/loadDynamicModules/index.ts +1 -0
- package/src/common/utils/loadDynamicModules/utils.loadDynamicModules.spec.ts +111 -0
- package/src/common/utils/loadDynamicModules/utils.loadDynamicModules.ts +69 -0
- package/src/common/utils/setNested/index.ts +2 -0
- package/src/common/utils/setNested/setNested.definitions.ts +4 -0
- package/src/common/utils/setNested/setNested.method.ts +83 -0
- package/src/common/utils/setNested/setNested.spec.ts +184 -0
- package/src/data/entityService/data.entity.service.definitions.ts +154 -0
- package/src/data/entityService/data.entity.service.spec.ts +112 -0
- package/src/data/entityService/data.entity.service.ts +144 -0
- package/src/data/entityService/index.ts +2 -0
- package/src/domain/entityService/domain.entity.service.definitions.ts +142 -0
- package/src/domain/entityService/domain.entity.service.spec.ts +126 -0
- package/src/domain/entityService/domain.entity.service.ts +421 -0
- package/src/domain/entityService/index.ts +2 -0
- package/src/index.ts +6 -0
- package/src/vitest.config.ts +9 -0
- package/dist/common/utils/utils.loadDynamicModules.js.map +0 -1
- package/dist/persistance/entityService/index.d.ts +0 -2
- package/dist/persistance/entityService/index.js.map +0 -1
- package/dist/persistance/entityService/persistance.entity.service.d.ts +0 -11
- package/dist/persistance/entityService/persistance.entity.service.definitions.d.ts +0 -76
- package/dist/persistance/entityService/persistance.entity.service.definitions.js +0 -23
- package/dist/persistance/entityService/persistance.entity.service.definitions.js.map +0 -1
- package/dist/persistance/entityService/persistance.entity.service.js.map +0 -1
- /package/dist/common/utils/{utils.loadDynamicModules.js → loadDynamicModules/utils.loadDynamicModules.js} +0 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { GenericObject, HttpMethod } from '../definitions';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* This object contains the names of the fields within the modules, by module category.
|
|
5
|
+
*/
|
|
6
|
+
export const APP_CONFIG_FROM_ENV_KEYS: AppConfigFromEnvKeys = {
|
|
7
|
+
API: {
|
|
8
|
+
HTTP: {
|
|
9
|
+
API_KEY: 'apiKey',
|
|
10
|
+
API_SECRET: 'apiSecret',
|
|
11
|
+
API_SECRET_ALGORITHM: 'apiSecretAlgorithm',
|
|
12
|
+
HOSTNAME: 'hostname',
|
|
13
|
+
PORT: 'port'
|
|
14
|
+
},
|
|
15
|
+
REST: {
|
|
16
|
+
API_KEY: 'apiKey',
|
|
17
|
+
API_SECRET: 'apiSecret',
|
|
18
|
+
API_SECRET_ALGORITHM: 'apiSecretAlgorithm',
|
|
19
|
+
HOSTNAME: 'hostname',
|
|
20
|
+
PORT: 'port'
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
DOMAIN: {
|
|
24
|
+
IAM: {
|
|
25
|
+
JWT_ACCESS_SECRET: 'jwtAccessSecret',
|
|
26
|
+
JWT_REFRESH_SECRET: 'jwtRefreshSecret'
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
DATA: {
|
|
30
|
+
NOSQL: {
|
|
31
|
+
HOST: 'host',
|
|
32
|
+
PASSWORD: 'password',
|
|
33
|
+
SENTINEL_PASSWORD: 'sentinelPassword',
|
|
34
|
+
PORT: 'port',
|
|
35
|
+
USER: 'user'
|
|
36
|
+
},
|
|
37
|
+
RDB: {
|
|
38
|
+
DATABASE_NAME: 'database',
|
|
39
|
+
HOST: 'host',
|
|
40
|
+
PASSWORD: 'password',
|
|
41
|
+
PORT: 'port',
|
|
42
|
+
USER: 'user'
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/*
|
|
48
|
+
* This object contains the names of the module categories and the modules themselves.
|
|
49
|
+
* The module names here are examples, corresponding to the object above.
|
|
50
|
+
* In order for this to work, each module in the .env files should have a key ending with
|
|
51
|
+
* _MODULE_TYPE, whose value correesponds to the values define in the 'children' here.
|
|
52
|
+
*/
|
|
53
|
+
export const APP_CONFIG_FROM_ENV_KEYS_PARENT_NAMES: AppConfigFromEnvKeysParentNames = {
|
|
54
|
+
API: {
|
|
55
|
+
children: {
|
|
56
|
+
HTTP: 'http',
|
|
57
|
+
REST: 'rest'
|
|
58
|
+
},
|
|
59
|
+
name: 'api'
|
|
60
|
+
},
|
|
61
|
+
DOMAIN: {
|
|
62
|
+
children: {
|
|
63
|
+
IAM: 'iam'
|
|
64
|
+
},
|
|
65
|
+
name: 'domain'
|
|
66
|
+
},
|
|
67
|
+
DATA: {
|
|
68
|
+
children: {
|
|
69
|
+
DB: 'db',
|
|
70
|
+
REDIS: 'redis',
|
|
71
|
+
VALKEY: 'valkey'
|
|
72
|
+
},
|
|
73
|
+
name: 'data'
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
type AppConfigIntermediate = AppConfigCommon & AppConfigProfile & AppConfigFromEnv;
|
|
78
|
+
export type AppConfig = AppConfigIntermediate & Required<Pick<AppConfigIntermediate, 'api'>>;
|
|
79
|
+
type AppConfigAPIHTTPIntermediate = AppConfigCommonAPIHTTP & AppConfigFromEnvAPIHTTP;
|
|
80
|
+
export type AppConfigAPIHTTP = AppConfigAPIHTTPIntermediate &
|
|
81
|
+
Required<Pick<AppConfigAPIHTTPIntermediate, 'allowedOrigins' | 'anonymousAccessRoutes' | 'hostname' | 'port'>>;
|
|
82
|
+
export type AppConfigAPIREST = AppConfigCommonAPIREST & AppConfigFromEnvAPIREST;
|
|
83
|
+
|
|
84
|
+
export type AppConfigDomainIAM = AppConfigCommonDomainIAM & AppConfigFromEnvDomainIAM & AppConfigProfileDomainIAM;
|
|
85
|
+
|
|
86
|
+
export enum AppConfigDomainIAMAuthenticationStep {
|
|
87
|
+
// eslint-disable-next-line no-unused-vars
|
|
88
|
+
Complete = 'complete',
|
|
89
|
+
// eslint-disable-next-line no-unused-vars
|
|
90
|
+
Initiate = 'initiate'
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export type AppConfigDataNoSQL = AppConfigCommonDataNoSQL & AppConfigFromEnvDataNoSQL & AppConfigProfileDataNoSQL;
|
|
94
|
+
export type AppConfigDataRDB = AppConfigCommonDataClickHouse &
|
|
95
|
+
AppConfigCommonDataRDB &
|
|
96
|
+
AppConfigCommonDataClickHouse &
|
|
97
|
+
AppConfigFromEnvDataRDB &
|
|
98
|
+
AppConfigProfileDataClickHouse &
|
|
99
|
+
AppConfigProfileDataRDB;
|
|
100
|
+
|
|
101
|
+
/*
|
|
102
|
+
* Config data held in the common config file.
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
export interface AppConfigCommon {
|
|
106
|
+
api?: { [apiName: string]: GenericObject | AppConfigCommonAPIHTTP | AppConfigCommonAPIREST };
|
|
107
|
+
domain: { [domainName: string]: GenericObject | AppConfigCommonDomainIAM };
|
|
108
|
+
general: {
|
|
109
|
+
projectName: string;
|
|
110
|
+
projectRootPath: string;
|
|
111
|
+
projectVersion: string;
|
|
112
|
+
};
|
|
113
|
+
data: {
|
|
114
|
+
[moduleName: string]:
|
|
115
|
+
| GenericObject
|
|
116
|
+
| AppConfigCommonDataClickHouse
|
|
117
|
+
| AppConfigCommonDataNoSQL
|
|
118
|
+
| AppConfigCommonDataRDB;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface AppConfigCommonAPIHTTP {
|
|
123
|
+
allowedOrigins?: string[];
|
|
124
|
+
anonymousAccessRoutes?: Record<string, HttpMethod[]>;
|
|
125
|
+
endpointSecurityMode?: EndpointSecurityMode;
|
|
126
|
+
hostname?: string;
|
|
127
|
+
port?: number;
|
|
128
|
+
}
|
|
129
|
+
export type AppConfigCommonAPIREST = AppConfigCommonAPIHTTP;
|
|
130
|
+
|
|
131
|
+
export interface AppConfigCommonDomainIAM {
|
|
132
|
+
accessTokenExpiryTimeInMinutes?: number;
|
|
133
|
+
authServiceSettings?: GenericObject<{
|
|
134
|
+
secretKey?: {
|
|
135
|
+
secretKeyHMACAlgorithm?: string;
|
|
136
|
+
};
|
|
137
|
+
oauth2?: {
|
|
138
|
+
accessTokenAudiences?: string[];
|
|
139
|
+
accessTokenEmailField?: string;
|
|
140
|
+
accessTokenGrantUrl?: string;
|
|
141
|
+
authorizationUrl?: string;
|
|
142
|
+
codeChallengeMethod: string; // code_challenge_method
|
|
143
|
+
defaultScope?: string;
|
|
144
|
+
issuerUri?: string;
|
|
145
|
+
redirectUri?: string; // redirect_uri
|
|
146
|
+
verifyTokensLocally?: boolean;
|
|
147
|
+
};
|
|
148
|
+
processExternalTokensOnVerify?: boolean;
|
|
149
|
+
steps: AppConfigCommonDomainIAMAuthServiceConfigStepSettings;
|
|
150
|
+
}>;
|
|
151
|
+
defaultUserIdentifierField: string;
|
|
152
|
+
refreshTokenExpiryTimeInMinutes?: number;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface AppConfigCommonDomainIAMAuthServiceConfigBaseStepSettings {
|
|
156
|
+
findUser?: boolean;
|
|
157
|
+
findUserBeforeAuth?: boolean;
|
|
158
|
+
stepResultPublicFields?: string[];
|
|
159
|
+
validWithoutUser?: boolean;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface AppConfigCommonDomainIAMAuthServiceConfigCacheSettings {
|
|
163
|
+
cacheFieldName: string;
|
|
164
|
+
inputFieldName: string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface AppConfigCommonDomainIAMAuthServiceConfigCachePopulationSettings {
|
|
168
|
+
data?: boolean | AppConfigCommonDomainIAMAuthServiceConfigCacheSettings[];
|
|
169
|
+
options?: boolean | AppConfigCommonDomainIAMAuthServiceConfigCacheSettings[];
|
|
170
|
+
result?: boolean | AppConfigCommonDomainIAMAuthServiceConfigCacheSettings[];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface AppConfigCommonDomainIAMAuthServiceConfigCacheUsageSettings {
|
|
174
|
+
data?: AppConfigCommonDomainIAMAuthServiceConfigCacheUsageSettingsItem;
|
|
175
|
+
options?: AppConfigCommonDomainIAMAuthServiceConfigCacheUsageSettingsItem;
|
|
176
|
+
result?: AppConfigCommonDomainIAMAuthServiceConfigCacheUsageSettingsItem;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export interface AppConfigCommonDomainIAMAuthServiceConfigCacheUsageSettingsItem {
|
|
180
|
+
overwrite?: boolean;
|
|
181
|
+
use: boolean;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface AppConfigCommonDomainIAMAuthServiceConfigCompleteSettings
|
|
185
|
+
extends AppConfigCommonDomainIAMAuthServiceConfigBaseStepSettings {
|
|
186
|
+
authReturnsTokens?: boolean;
|
|
187
|
+
cache?: {
|
|
188
|
+
settings: AppConfigCommonDomainIAMAuthServiceConfigCacheSettings;
|
|
189
|
+
use?: AppConfigCommonDomainIAMAuthServiceConfigCacheUsageSettings;
|
|
190
|
+
};
|
|
191
|
+
createUser?: boolean;
|
|
192
|
+
decodeReturnedTokens?: boolean;
|
|
193
|
+
findUserInAuthResultBy?: { userFieldName: string; resultFieldName: string };
|
|
194
|
+
useReturnedTokens?: boolean;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export interface AppConfigCommonDomainIAMAuthServiceConfigInitiateSettings
|
|
198
|
+
extends AppConfigCommonDomainIAMAuthServiceConfigBaseStepSettings {
|
|
199
|
+
cache?: {
|
|
200
|
+
populate?: AppConfigCommonDomainIAMAuthServiceConfigCachePopulationSettings;
|
|
201
|
+
settings: AppConfigCommonDomainIAMAuthServiceConfigCacheSettings;
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface AppConfigCommonDomainIAMAuthServiceConfigStepSettings {
|
|
206
|
+
[AppConfigDomainIAMAuthenticationStep.Complete]: AppConfigCommonDomainIAMAuthServiceConfigCompleteSettings;
|
|
207
|
+
[AppConfigDomainIAMAuthenticationStep.Initiate]: AppConfigCommonDomainIAMAuthServiceConfigInitiateSettings;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export type AppConfigCommonData = {
|
|
211
|
+
failOnConnectionError?: boolean;
|
|
212
|
+
settingsPerEntity?: Record<string, AppConfigCommonDataEntityServiceSettings>;
|
|
213
|
+
} & AppConfigCommonDataEntityServiceSettings;
|
|
214
|
+
|
|
215
|
+
export interface AppConfigCommonDataEntityServiceSettings {
|
|
216
|
+
processFiltersAllowedFieldsEnabled?: boolean;
|
|
217
|
+
processInputAllowedFieldsEnabled?: boolean;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export interface AppConfigCommonDataClickHouse extends AppConfigCommonData {
|
|
221
|
+
application?: string;
|
|
222
|
+
requestTimeout?: number;
|
|
223
|
+
type: RDBType;
|
|
224
|
+
useHostParam?: boolean;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface AppConfigCommonDataNoSQL extends AppConfigCommonData {
|
|
228
|
+
clusterMode?: boolean;
|
|
229
|
+
defaultIndividualSearchEnabled?: boolean;
|
|
230
|
+
defaultTTL?: number;
|
|
231
|
+
sentinelMasterName?: string;
|
|
232
|
+
sentinelMode?: boolean;
|
|
233
|
+
sentinelRole?: 'master' | 'slave';
|
|
234
|
+
storeDelimiter?: string;
|
|
235
|
+
storeKey: string;
|
|
236
|
+
settingsPerEntity?: Record<string, AppConfigCommonDataNoSQLEntityServiceSettings>;
|
|
237
|
+
type: NoSQLType;
|
|
238
|
+
useHashmap?: boolean;
|
|
239
|
+
usePasswordForSentinelPassword?: boolean;
|
|
240
|
+
validationSettings?: AppConfigCommonDataNoSQLValidationSettings;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export interface AppConfigCommonDataNoSQLEntityServiceSettings extends AppConfigCommonDataEntityServiceSettings {
|
|
244
|
+
defaultIndividualSearchEnabled?: boolean;
|
|
245
|
+
ttl?: number;
|
|
246
|
+
validationSettings?: AppConfigCommonDataNoSQLValidationSettings;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface AppConfigCommonDataNoSQLValidationSettings {
|
|
250
|
+
throwErrorOnExtraProperies?: boolean;
|
|
251
|
+
isEnabled?: boolean;
|
|
252
|
+
whitelistProperties?: boolean;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export interface AppConfigCommonDataRDB extends AppConfigCommonData {
|
|
256
|
+
connectionName: string;
|
|
257
|
+
type: RDBType;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/*
|
|
261
|
+
* Config data coming from env files.
|
|
262
|
+
*/
|
|
263
|
+
|
|
264
|
+
export interface AppConfigFromEnv {
|
|
265
|
+
api?: { [apiName: string]: GenericObject | AppConfigFromEnvAPIHTTP | AppConfigFromEnvAPIREST };
|
|
266
|
+
domain?: { [domainName: string]: GenericObject | AppConfigFromEnvDomainIAM };
|
|
267
|
+
data?: {
|
|
268
|
+
[moduleName: string]: GenericObject | AppConfigFromEnvDataNoSQL | AppConfigFromEnvDataRDB;
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export interface AppConfigFromEnvAPIHTTP extends AppConfigCommonAPIHTTP {
|
|
273
|
+
apiKey?: string;
|
|
274
|
+
apiSecret?: string;
|
|
275
|
+
apiSecretAlgorithm?: string;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export type AppConfigFromEnvAPIREST = AppConfigFromEnvAPIHTTP;
|
|
279
|
+
|
|
280
|
+
export interface AppConfigFromEnvDomainIAM {
|
|
281
|
+
jwtAccessSecret: string;
|
|
282
|
+
jwtRefreshSecret: string;
|
|
283
|
+
authServiceSettings?: GenericObject<{
|
|
284
|
+
secretKey?: {
|
|
285
|
+
hashingSecret?: string;
|
|
286
|
+
};
|
|
287
|
+
oauth2?: {
|
|
288
|
+
clientId: string; // client_id
|
|
289
|
+
clientSecret: string; // client_secret
|
|
290
|
+
};
|
|
291
|
+
}>;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export interface AppConfigFromEnvKeys {
|
|
295
|
+
[moduleCategory: string]: {
|
|
296
|
+
[moduleType: string]: Record<string, string>;
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export interface AppConfigFromEnvKeysParentNames {
|
|
301
|
+
[moduleCategory: string]: {
|
|
302
|
+
children: Record<string, string>;
|
|
303
|
+
name: string;
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export interface AppConfigFromEnvDataNoSQL {
|
|
308
|
+
host: string;
|
|
309
|
+
password: string;
|
|
310
|
+
port: number;
|
|
311
|
+
sentinelPassword?: string;
|
|
312
|
+
user?: string;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export interface AppConfigFromEnvDataRDB {
|
|
316
|
+
database: string;
|
|
317
|
+
host: string;
|
|
318
|
+
password: string;
|
|
319
|
+
port: number;
|
|
320
|
+
user: string;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/*
|
|
324
|
+
* Config data coming from configProfile files.
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
export interface AppConfigProfile {
|
|
328
|
+
api?: { [apiName: string]: GenericObject | AppConfigProfileAPIHTTP | AppConfigProfileAPIREST };
|
|
329
|
+
domain?: { [domainName: string]: GenericObject | AppConfigProfileDomainIAM };
|
|
330
|
+
general: {
|
|
331
|
+
environment: AppEnvironment;
|
|
332
|
+
projectName?: string;
|
|
333
|
+
projectVersion?: string;
|
|
334
|
+
};
|
|
335
|
+
data?: {
|
|
336
|
+
[dataModuleName: string]:
|
|
337
|
+
| GenericObject
|
|
338
|
+
| AppConfigProfileDataClickHouse
|
|
339
|
+
| AppConfigProfileDataNoSQL
|
|
340
|
+
| AppConfigProfileDataRDB;
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export type AppConfigProfileAPIHTTP = AppConfigCommonAPIHTTP;
|
|
345
|
+
export type AppConfigProfileAPIREST = AppConfigProfileAPIHTTP;
|
|
346
|
+
|
|
347
|
+
export interface AppConfigProfileDomainIAM {
|
|
348
|
+
accessTokenExpiryTimeInMinutes?: number;
|
|
349
|
+
authServiceSettings?: GenericObject<{
|
|
350
|
+
oauth2?: {
|
|
351
|
+
accessTokenAudiences?: string[];
|
|
352
|
+
accessTokenEmailField?: string;
|
|
353
|
+
accessTokenGrantUrl?: string;
|
|
354
|
+
authorizationUrl?: string;
|
|
355
|
+
codeChallengeMethod: string; // code_challenge_method
|
|
356
|
+
defaultScope?: string;
|
|
357
|
+
issuerUri?: string;
|
|
358
|
+
redirectUri?: string; // redirect_uri
|
|
359
|
+
verifyTokensLocally?: boolean;
|
|
360
|
+
};
|
|
361
|
+
processExternalTokensOnVerify?: boolean;
|
|
362
|
+
}>;
|
|
363
|
+
refreshTokenExpiryTimeInMinutes?: number;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export type AppConfigProfileDataClickHouse = AppConfigCommonDataClickHouse & {
|
|
367
|
+
protocol?: string;
|
|
368
|
+
};
|
|
369
|
+
export type AppConfigProfileDataNoSQL = AppConfigCommonDataNoSQL;
|
|
370
|
+
export type AppConfigProfileDataRDB = AppConfigCommonDataRDB & {
|
|
371
|
+
typeormExtraOptions?: GenericObject;
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
export enum AppEnvironment {
|
|
375
|
+
// eslint-disable-next-line no-unused-vars
|
|
376
|
+
Development = 'development',
|
|
377
|
+
// eslint-disable-next-line no-unused-vars
|
|
378
|
+
Local = 'local',
|
|
379
|
+
// eslint-disable-next-line no-unused-vars
|
|
380
|
+
Production = 'production',
|
|
381
|
+
// eslint-disable-next-line no-unused-vars
|
|
382
|
+
Staging = 'staging',
|
|
383
|
+
// eslint-disable-next-line no-unused-vars
|
|
384
|
+
Test = 'test'
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/*
|
|
388
|
+
* Other config-related definitions.
|
|
389
|
+
*/
|
|
390
|
+
|
|
391
|
+
export interface ConfigProviderModuleOptions extends LoadConfigOptions {
|
|
392
|
+
appConfigs: LoadConfigAppConfigs;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// TODO: figure out how to move this to the Domain-IAM package
|
|
396
|
+
export enum EndpointSecurityMode {
|
|
397
|
+
// eslint-disable-next-line no-unused-vars
|
|
398
|
+
Lax = 'lax',
|
|
399
|
+
// eslint-disable-next-line no-unused-vars
|
|
400
|
+
Strict = 'strict'
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export interface GenerateOrmconfigOptions {
|
|
404
|
+
entitiesPathInModule: string;
|
|
405
|
+
migrationsPathInModule: string;
|
|
406
|
+
moduleName: string;
|
|
407
|
+
modulePathInProject: string;
|
|
408
|
+
seedsPathInModule?: string;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// TODO: figure out how to move this to the Redis package
|
|
412
|
+
export enum NoSQLType {
|
|
413
|
+
// eslint-disable-next-line no-unused-vars
|
|
414
|
+
Redis = 'redis',
|
|
415
|
+
// eslint-disable-next-line no-unused-vars
|
|
416
|
+
Valkey = 'valkey'
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// TODO: figure out how to move this to the RDB package
|
|
420
|
+
export enum RDBType {
|
|
421
|
+
// eslint-disable-next-line no-unused-vars
|
|
422
|
+
Aurora = 'aurora',
|
|
423
|
+
// eslint-disable-next-line no-unused-vars
|
|
424
|
+
ClickHouse = 'clickhouse',
|
|
425
|
+
// eslint-disable-next-line no-unused-vars
|
|
426
|
+
MySQL = 'mysql',
|
|
427
|
+
// eslint-disable-next-line no-unused-vars
|
|
428
|
+
PG = 'postgres'
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
export type LoadConfigAppConfigs<
|
|
432
|
+
AppConfigCommonType extends AppConfigCommon = AppConfigCommon,
|
|
433
|
+
AppConfigProfileType extends AppConfigProfile = AppConfigProfile
|
|
434
|
+
> =
|
|
435
|
+
| {
|
|
436
|
+
appConfigCommon: AppConfigCommonType;
|
|
437
|
+
}
|
|
438
|
+
| GenericObject<AppConfigProfileType>;
|
|
439
|
+
|
|
440
|
+
export interface LoadConfigOptions {
|
|
441
|
+
envKeys?: AppConfigFromEnvKeys;
|
|
442
|
+
envKeysParentNames?: AppConfigFromEnvKeysParentNames;
|
|
443
|
+
useEnvFile?: boolean;
|
|
444
|
+
useEnvFileWithPriority?: boolean;
|
|
445
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { AppConfig, AppEnvironment, ConfigProviderModuleOptions } from './configProvider.definitions';
|
|
4
|
+
import { ConfigProviderModule } from './configProvider.module';
|
|
5
|
+
import { ConfigProviderService } from './configProvider.service';
|
|
6
|
+
|
|
7
|
+
import { Constants } from '../definitions';
|
|
8
|
+
|
|
9
|
+
// Helper type predicate: checks if a provider is a factory provider for a given token.
|
|
10
|
+
function isFactoryProvider<T, U>(
|
|
11
|
+
provider: unknown,
|
|
12
|
+
token: T
|
|
13
|
+
): provider is { provide: T; useFactory: () => Promise<U> } {
|
|
14
|
+
if (typeof provider !== 'object' || provider === null) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const p = provider as { provide?: T; useFactory?: unknown };
|
|
18
|
+
return p.provide === token && typeof p.useFactory === 'function';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe('ConfigProviderModule', () => {
|
|
22
|
+
// Create a fake AppConfig with full type information.
|
|
23
|
+
const fakeAppConfig: AppConfig = {
|
|
24
|
+
api: {},
|
|
25
|
+
domain: {},
|
|
26
|
+
general: {
|
|
27
|
+
environment: AppEnvironment.Local,
|
|
28
|
+
projectName: 'TestProject',
|
|
29
|
+
projectRootPath: '/fake/path',
|
|
30
|
+
projectVersion: '1.0.0'
|
|
31
|
+
},
|
|
32
|
+
data: {}
|
|
33
|
+
};
|
|
34
|
+
const fakeEnvKeys = {
|
|
35
|
+
API: {
|
|
36
|
+
HTTP: { HOST: 'hostname', PORT: 'port' }
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const fakeEnvKeysParentNames = {
|
|
40
|
+
API: {
|
|
41
|
+
children: { TEST: 'test' },
|
|
42
|
+
name: 'api'
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const fakeModuleOptions: ConfigProviderModuleOptions = {
|
|
46
|
+
appConfigs: { appConfigCommon: fakeAppConfig },
|
|
47
|
+
envKeys: fakeEnvKeys,
|
|
48
|
+
envKeysParentNames: fakeEnvKeysParentNames
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
describe('register()', () => {
|
|
52
|
+
it('should return a dynamic module with proper configuration', async () => {
|
|
53
|
+
// Spy on loadConfig so that the factory returns our fake config.
|
|
54
|
+
const loadConfigSpy = vi.spyOn(ConfigProviderService, 'loadConfig').mockResolvedValue(fakeAppConfig);
|
|
55
|
+
const dynamicModule = ConfigProviderModule.register(fakeModuleOptions);
|
|
56
|
+
// Verify dynamic module properties.
|
|
57
|
+
expect(dynamicModule.global).toBe(true);
|
|
58
|
+
expect(dynamicModule.module).toBe(ConfigProviderModule);
|
|
59
|
+
expect(dynamicModule.providers).toEqual(
|
|
60
|
+
expect.arrayContaining([expect.objectContaining({ provide: Constants.CONFIG }), ConfigProviderService])
|
|
61
|
+
);
|
|
62
|
+
expect(dynamicModule.exports).toEqual([Constants.CONFIG, ConfigProviderService]);
|
|
63
|
+
// Locate the provider with the injection token.
|
|
64
|
+
const configProvider = dynamicModule.providers?.find(p =>
|
|
65
|
+
isFactoryProvider<Constants, AppConfig>(p, Constants.CONFIG)
|
|
66
|
+
) as unknown as { useFactory: () => Promise<ConfigProviderService> };
|
|
67
|
+
expect(configProvider).toBeDefined();
|
|
68
|
+
// Call the useFactory and verify it returns the fake config.
|
|
69
|
+
const producedConfig = await configProvider.useFactory();
|
|
70
|
+
expect(producedConfig).toEqual(fakeAppConfig);
|
|
71
|
+
expect(loadConfigSpy).toHaveBeenCalledWith(
|
|
72
|
+
{ appConfigCommon: fakeAppConfig },
|
|
73
|
+
{
|
|
74
|
+
envKeys: fakeEnvKeys,
|
|
75
|
+
envKeysParentNames: fakeEnvKeysParentNames
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
it('should propagate errors from the loadConfig factory', async () => {
|
|
80
|
+
const error = new Error('Load config failed');
|
|
81
|
+
vi.spyOn(ConfigProviderService, 'loadConfig').mockRejectedValue(error);
|
|
82
|
+
const dynamicModule = ConfigProviderModule.register(fakeModuleOptions);
|
|
83
|
+
const configProvider = dynamicModule.providers?.find(p =>
|
|
84
|
+
isFactoryProvider<Constants, AppConfig>(p, Constants.CONFIG)
|
|
85
|
+
) as unknown as { useFactory: () => Promise<ConfigProviderService> };
|
|
86
|
+
expect(configProvider).toBeDefined();
|
|
87
|
+
await expect(configProvider.useFactory()).rejects.toThrow('Load config failed');
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DynamicModule, Module } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import { ConfigProviderModuleOptions } from './configProvider.definitions';
|
|
4
|
+
import { ConfigProviderService } from './configProvider.service';
|
|
5
|
+
|
|
6
|
+
import { Constants } from '../definitions';
|
|
7
|
+
|
|
8
|
+
@Module({})
|
|
9
|
+
export class ConfigProviderModule {
|
|
10
|
+
static register(options: ConfigProviderModuleOptions): DynamicModule {
|
|
11
|
+
const { appConfigs, ...otherOptions } = options;
|
|
12
|
+
return {
|
|
13
|
+
global: true,
|
|
14
|
+
module: ConfigProviderModule,
|
|
15
|
+
providers: [
|
|
16
|
+
{
|
|
17
|
+
provide: Constants.CONFIG,
|
|
18
|
+
useFactory: async () => await ConfigProviderService.loadConfig(appConfigs, { ...otherOptions })
|
|
19
|
+
},
|
|
20
|
+
ConfigProviderService
|
|
21
|
+
],
|
|
22
|
+
exports: [Constants.CONFIG, ConfigProviderService]
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|