@futdevpro/nts-dynamo 1.7.16 → 1.7.20
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/.eslintrc.json +171 -0
- package/lib/_constants/mocks/app-extended-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/app-extended-server.mock.js.map +1 -1
- package/lib/_constants/mocks/app-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/app-server.mock.js.map +1 -1
- package/lib/_constants/mocks/data-model.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/data-model.mock.js.map +1 -1
- package/lib/_constants/mocks/email-service-collection.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/email-service-collection.mock.js.map +1 -1
- package/lib/_constants/mocks/email-service.mock.js +3 -3
- package/lib/_constants/mocks/email-service.mock.js.map +1 -1
- package/lib/_constants/mocks/endpoint.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/endpoint.mock.js.map +1 -1
- package/lib/_constants/mocks/socket-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/socket-server.mock.js.map +1 -1
- package/lib/_enums/index.js +1 -1
- package/lib/_enums/index.js.map +1 -1
- package/lib/_models/control-models/api-call-params.control-model.d.ts +2 -2
- package/lib/_models/control-models/api-call-params.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/api-call-params.control-model.js.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model copy.d.ts.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model copy.js.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model.js.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.js +15 -9
- package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/lib/_models/control-models/http-settings.control-model.d.ts +1 -1
- package/lib/_models/control-models/http-settings.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/http-settings.control-model.js +3 -1
- package/lib/_models/control-models/http-settings.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-client-service-params.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-event.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
- package/lib/_modules/custom-data/custom-data.controller.d.ts.map +1 -1
- package/lib/_modules/custom-data/custom-data.controller.js +2 -1
- package/lib/_modules/custom-data/custom-data.controller.js.map +1 -1
- package/lib/_modules/custom-data/get-custom-data-routing-module.util.d.ts.map +1 -1
- package/lib/_modules/custom-data/get-custom-data-routing-module.util.js.map +1 -1
- package/lib/_modules/test/get-test-routing-module.util.d.ts.map +1 -1
- package/lib/_modules/test/get-test-routing-module.util.js.map +1 -1
- package/lib/_modules/test/test.controller.d.ts.map +1 -1
- package/lib/_modules/test/test.controller.js.map +1 -1
- package/lib/_modules/usage/get-usage-routing-module.util.d.ts.map +1 -1
- package/lib/_modules/usage/get-usage-routing-module.util.js +1 -1
- package/lib/_modules/usage/get-usage-routing-module.util.js.map +1 -1
- package/lib/_modules/usage/usage.controller.d.ts.map +1 -1
- package/lib/_modules/usage/usage.controller.js +15 -14
- package/lib/_modules/usage/usage.controller.js.map +1 -1
- package/lib/_modules/usage/usage.data-service.d.ts +3 -1
- package/lib/_modules/usage/usage.data-service.d.ts.map +1 -1
- package/lib/_modules/usage/usage.data-service.js +24 -16
- package/lib/_modules/usage/usage.data-service.js.map +1 -1
- package/lib/_services/base/data.service.d.ts.map +1 -1
- package/lib/_services/base/data.service.js +45 -23
- package/lib/_services/base/data.service.js.map +1 -1
- package/lib/_services/base/db.service.d.ts.map +1 -1
- package/lib/_services/base/db.service.js +82 -53
- package/lib/_services/base/db.service.js.map +1 -1
- package/lib/_services/base/singleton.service.d.ts.map +1 -1
- package/lib/_services/base/singleton.service.js.map +1 -1
- package/lib/_services/core/api.service.d.ts +21 -13
- package/lib/_services/core/api.service.d.ts.map +1 -1
- package/lib/_services/core/api.service.js +192 -143
- package/lib/_services/core/api.service.js.map +1 -1
- package/lib/_services/core/auth.service.d.ts.map +1 -1
- package/lib/_services/core/auth.service.js.map +1 -1
- package/lib/_services/core/email.service.d.ts +50 -36
- package/lib/_services/core/email.service.d.ts.map +1 -1
- package/lib/_services/core/email.service.js +329 -94
- package/lib/_services/core/email.service.js.map +1 -1
- package/lib/_services/core/global.service.d.ts.map +1 -1
- package/lib/_services/core/global.service.js +30 -19
- package/lib/_services/core/global.service.js.map +1 -1
- package/lib/_services/route/controller.service.d.ts.map +1 -1
- package/lib/_services/route/controller.service.js.map +1 -1
- package/lib/_services/route/routing-module.service.d.ts.map +1 -1
- package/lib/_services/route/routing-module.service.js +2 -2
- package/lib/_services/route/routing-module.service.js.map +1 -1
- package/lib/_services/server/app-extended.server.d.ts.map +1 -1
- package/lib/_services/server/app-extended.server.js +19 -14
- package/lib/_services/server/app-extended.server.js.map +1 -1
- package/lib/_services/server/app-extended.server.spec.js +1 -0
- package/lib/_services/server/app-extended.server.spec.js.map +1 -1
- package/lib/_services/server/app.server.d.ts +4 -3
- package/lib/_services/server/app.server.d.ts.map +1 -1
- package/lib/_services/server/app.server.js +107 -52
- package/lib/_services/server/app.server.js.map +1 -1
- package/lib/_services/server/app.server.spec.js +1 -0
- package/lib/_services/server/app.server.spec.js.map +1 -1
- package/lib/_services/shared.static-service.js.map +1 -1
- package/lib/_services/socket/socket-client.service.js.map +1 -1
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/nodemon.json +3 -1
- package/package.json +9 -8
- package/src/_constants/mocks/app-extended-server.mock.ts +6 -2
- package/src/_constants/mocks/app-server.mock.ts +7 -1
- package/src/_constants/mocks/data-model.mock.ts +2 -2
- package/src/_constants/mocks/email-service-collection.mock.ts +2 -1
- package/src/_constants/mocks/email-service.mock.ts +2 -2
- package/src/_constants/mocks/endpoint.mock.ts +28 -26
- package/src/_constants/mocks/socket-server.mock.ts +12 -4
- package/src/_enums/index.ts +1 -1
- package/src/_models/control-models/api-call-params.control-model.ts +3 -2
- package/src/_models/control-models/app-system-controls.control-model copy.ts +1 -1
- package/src/_models/control-models/app-system-controls.control-model.ts +1 -1
- package/src/_models/control-models/endpoint-params.control-model.ts +39 -16
- package/src/_models/control-models/http-settings.control-model.ts +4 -2
- package/src/_modules/custom-data/custom-data.controller.ts +55 -51
- package/src/_modules/custom-data/get-custom-data-routing-module.util.ts +7 -3
- package/src/_modules/test/get-test-routing-module.util.ts +7 -3
- package/src/_modules/test/test.controller.ts +98 -96
- package/src/_modules/usage/get-usage-routing-module.util.ts +8 -4
- package/src/_modules/usage/usage.controller.ts +108 -102
- package/src/_modules/usage/usage.data-service.ts +54 -28
- package/src/_services/base/data.service.ts +133 -34
- package/src/_services/base/db.service.ts +254 -171
- package/src/_services/base/singleton.service.ts +1 -1
- package/src/_services/core/api.service.ts +348 -218
- package/src/_services/core/auth.service.ts +2 -0
- package/src/_services/core/email.service.ts +537 -129
- package/src/_services/core/global.service.ts +56 -26
- package/src/_services/route/controller.service.ts +3 -1
- package/src/_services/route/routing-module.service.ts +33 -16
- package/src/_services/server/app-extended.server.spec.ts +22 -17
- package/src/_services/server/app-extended.server.ts +108 -45
- package/src/_services/server/app.server.spec.ts +17 -12
- package/src/_services/server/app.server.ts +264 -138
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Dynamo_Log } from '@futdevpro/fsm-dynamo';
|
|
2
1
|
|
|
3
2
|
/**
|
|
4
3
|
*
|
|
@@ -12,6 +11,7 @@ export class DynamoNTS_SingletonService {
|
|
|
12
11
|
if (!this.instance) {
|
|
13
12
|
this.instance = new this();
|
|
14
13
|
}
|
|
14
|
+
|
|
15
15
|
return this.instance;
|
|
16
16
|
}
|
|
17
17
|
/// --- --- --- SINGLETON --- --- --- ///
|
|
@@ -4,26 +4,41 @@ import { Dynamo_Error, Dynamo_Log } from '@futdevpro/fsm-dynamo';
|
|
|
4
4
|
|
|
5
5
|
import { DynamoNTS_HttpCallType } from '../../_enums/http/http-call-type.enum';
|
|
6
6
|
import { DynamoNTS_HttpResponseType } from '../../_enums/http/http-response-type.enum';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
DynamoNTS_ApiCallParams
|
|
9
|
+
} from '../../_models/control-models/api-call-params.control-model';
|
|
8
10
|
import { dynamoNTS_globalSettings } from '../../_constants';
|
|
9
11
|
|
|
12
|
+
export interface DynamoNTS_ApiCallInputParams<T_Body = any> {
|
|
13
|
+
pathParams?: {
|
|
14
|
+
/**
|
|
15
|
+
* path params setted in endpoint
|
|
16
|
+
*/
|
|
17
|
+
[param: string]: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* api call's body
|
|
21
|
+
*/
|
|
22
|
+
body?: T_Body;
|
|
23
|
+
}
|
|
24
|
+
|
|
10
25
|
/**
|
|
11
26
|
* This predefined Api service contains the basic API call function which can be used in various ways
|
|
12
27
|
*/
|
|
13
28
|
export class DynamoNTS_ApiService {
|
|
14
29
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
30
|
+
static defaultErrorUserMsg =
|
|
31
|
+
`We encountered a BackEnd API Error, ` +
|
|
32
|
+
`\nplease contact the responsible development team.\n` +
|
|
33
|
+
`\n(Internal BE to BE error)`;
|
|
19
34
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
public static async startApiCall<
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param callParams
|
|
38
|
+
* @param inputParams
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
public static async startApiCall<T_Response, T_Body = any>(
|
|
27
42
|
/**
|
|
28
43
|
* you must setup the basic api call params with this.
|
|
29
44
|
* follow the instructions in the constructor: new DynamoNTS_ApiCallParams({ ... })
|
|
@@ -32,235 +47,350 @@ export class DynamoNTS_ApiService {
|
|
|
32
47
|
/**
|
|
33
48
|
* you can pass data and other inputs in this section
|
|
34
49
|
*/
|
|
35
|
-
inputParams?:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
inputParams?: DynamoNTS_ApiCallInputParams<T_Body>
|
|
51
|
+
): Promise<T_Response> {
|
|
52
|
+
try {
|
|
53
|
+
let a: T_Response;
|
|
54
|
+
let url: string = callParams.baseUrl + callParams.endPoint;
|
|
55
|
+
const axios = Axios.default.create();
|
|
56
|
+
|
|
57
|
+
if (callParams?.httpOptions?.headers) {
|
|
58
|
+
this.setupHeaders(callParams, axios);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (inputParams?.pathParams) {
|
|
62
|
+
url = this.setupPathParams(inputParams.pathParams, url);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* if (inputParams?.queryParams) {
|
|
66
|
+
this.setupQueryParams<T_Body>(inputParams, callParams);
|
|
67
|
+
} */
|
|
68
|
+
|
|
69
|
+
if (dynamoNTS_globalSettings.logApiEvents) {
|
|
70
|
+
this.logEvent(url, inputParams, callParams);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
switch (callParams.type) {
|
|
74
|
+
case DynamoNTS_HttpCallType.get:
|
|
75
|
+
if (inputParams?.body) {
|
|
76
|
+
Dynamo_Log.warn('WARNING you cant send body in get calls');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
a = await this.get<T_Response>(axios, url, callParams);
|
|
80
|
+
break;
|
|
81
|
+
|
|
82
|
+
case DynamoNTS_HttpCallType.delete:
|
|
83
|
+
if (inputParams?.body) {
|
|
84
|
+
Dynamo_Log.warn('WARNING you cant send body in delete calls');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
a = await this.delete<T_Response>(axios, url, callParams);
|
|
88
|
+
break;
|
|
89
|
+
|
|
90
|
+
case DynamoNTS_HttpCallType.post:
|
|
91
|
+
case DynamoNTS_HttpCallType.put:
|
|
92
|
+
case DynamoNTS_HttpCallType.patch:
|
|
93
|
+
if (!inputParams?.body) {
|
|
94
|
+
if (!inputParams) {
|
|
95
|
+
inputParams = {};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
inputParams.body = {} as T_Body;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
a = await this.postPutPatch<T_Response, T_Body>(axios, callParams, url, inputParams);
|
|
102
|
+
break;
|
|
103
|
+
|
|
104
|
+
default:
|
|
105
|
+
Dynamo_Log.error('DYNAMOBE ERROR: \n wrong api call type'/* , '\n\n', new Error() */);
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (callParams.getFullResponse) {
|
|
110
|
+
return a as Axios.AxiosResponse as T_Response;
|
|
111
|
+
|
|
112
|
+
} else {
|
|
113
|
+
return a as T_Response;
|
|
114
|
+
}
|
|
115
|
+
} catch (error) {
|
|
116
|
+
this.handleError<T_Body>(callParams, error, inputParams);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* private static setupQueryParams<T_Body = any>(
|
|
121
|
+
inputParams: DynamoNTS_ApiCallInputParams<T_Body>, callParams: DynamoNTS_ApiCallParams) {
|
|
122
|
+
const httpParams = new HttpParams();
|
|
123
|
+
|
|
124
|
+
for (const queryParamKey in inputParams.queryParams) {
|
|
125
|
+
if (inputParams.queryParams[queryParamKey]) {
|
|
126
|
+
switch (typeof inputParams.queryParams[queryParamKey]) {
|
|
127
|
+
case 'number':
|
|
128
|
+
httpParams.set(queryParamKey, inputParams.queryParams[queryParamKey].toString());
|
|
129
|
+
break;
|
|
130
|
+
|
|
131
|
+
case 'string':
|
|
132
|
+
httpParams.set(queryParamKey, inputParams.queryParams[queryParamKey]);
|
|
133
|
+
break;
|
|
134
|
+
|
|
135
|
+
default:
|
|
136
|
+
console.error('DYNAMOBE ERROR: \n wrong query param type', '\n\n', new Error());
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
callParams.httpOptions.params = httpParams;
|
|
142
|
+
} */
|
|
143
|
+
|
|
144
|
+
private static handleError<T_Body>(
|
|
145
|
+
callParams: DynamoNTS_ApiCallParams,
|
|
146
|
+
error: any,
|
|
147
|
+
inputParams: {
|
|
148
|
+
pathParams?: { [param: string]: string; };
|
|
42
149
|
/**
|
|
43
150
|
* api call's body
|
|
44
151
|
*/
|
|
45
|
-
body?:
|
|
152
|
+
body?: T_Body;
|
|
46
153
|
}
|
|
47
|
-
):
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
154
|
+
): void {
|
|
155
|
+
Dynamo_Log.error(
|
|
156
|
+
`\n> API ERROR: ${callParams?.name} failed...` +
|
|
157
|
+
`\n${callParams?.baseUrl}${callParams?.endPoint}` +
|
|
158
|
+
`\ncallParams:`, callParams
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
if (error && callParams?.httpOptions?.responseType === DynamoNTS_HttpResponseType.text) {
|
|
162
|
+
error.error = JSON.parse(error?.error);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if ((error?.response?.data as Dynamo_Error)?.flag?.includes('DYNAMO')) {
|
|
166
|
+
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL` /* , new Error() */);
|
|
167
|
+
|
|
168
|
+
throw new Dynamo_Error({
|
|
169
|
+
...this._getDefaultErrorSettings(
|
|
170
|
+
callParams.name + ' startApiCall',
|
|
171
|
+
error.response.data
|
|
172
|
+
),
|
|
173
|
+
|
|
174
|
+
errorCode: 'NTS-API-SAC1',
|
|
175
|
+
message: 'API call failed on the other end! error response found...',
|
|
176
|
+
additionalContent: {
|
|
177
|
+
callParams,
|
|
178
|
+
inputParams,
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
} else if (error.code === 'ENOTFOUND') {
|
|
183
|
+
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL` /* , new Error() */);
|
|
184
|
+
|
|
185
|
+
throw new Dynamo_Error({
|
|
186
|
+
...this._getDefaultErrorSettings(
|
|
187
|
+
callParams.name + ' startApiCall',
|
|
188
|
+
error
|
|
189
|
+
),
|
|
190
|
+
|
|
191
|
+
status: 404,
|
|
192
|
+
errorCode: 'NTS-API-SAC2',
|
|
193
|
+
message: 'DNS error; address cannot be resolved!',
|
|
194
|
+
additionalContent: {
|
|
195
|
+
callParams,
|
|
196
|
+
inputParams,
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
} else if (error.code === 'ECONNREFUSED') {
|
|
201
|
+
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL` /* , new Error() */);
|
|
202
|
+
|
|
203
|
+
throw new Dynamo_Error({
|
|
204
|
+
...this._getDefaultErrorSettings(
|
|
205
|
+
callParams.name + ' startApiCall',
|
|
206
|
+
error
|
|
207
|
+
),
|
|
208
|
+
|
|
209
|
+
status: 404,
|
|
210
|
+
errorCode: 'NTS-API-SAC3',
|
|
211
|
+
message: `Can't connect to the endpoin!`,
|
|
212
|
+
additionalContent: {
|
|
213
|
+
callParams,
|
|
214
|
+
inputParams,
|
|
61
215
|
}
|
|
216
|
+
});
|
|
62
217
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
218
|
+
} else if (error.config && error.message) {
|
|
219
|
+
|
|
220
|
+
throw new Dynamo_Error({
|
|
221
|
+
...this._getDefaultErrorSettings(
|
|
222
|
+
callParams.name + ' startApiCall',
|
|
223
|
+
error
|
|
224
|
+
),
|
|
225
|
+
|
|
226
|
+
status: +error.message.substring(error.message.length - 4, 3),
|
|
227
|
+
errorCode: 'NTS-API-SAC4',
|
|
228
|
+
additionalContent: {
|
|
229
|
+
callParams,
|
|
230
|
+
inputParams,
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
} else {
|
|
234
|
+
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL`, error /*, '\n\n' , new Error() */);
|
|
235
|
+
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
private static async postPutPatch<T_Response, T_Body>(
|
|
241
|
+
axios: Axios.AxiosInstance,
|
|
242
|
+
callParams: DynamoNTS_ApiCallParams,
|
|
243
|
+
url: string,
|
|
244
|
+
inputParams: DynamoNTS_ApiCallInputParams<T_Body>
|
|
245
|
+
): Promise<T_Response> {
|
|
246
|
+
return await axios[callParams.type]<T_Response>(
|
|
247
|
+
url,
|
|
248
|
+
inputParams.body,
|
|
249
|
+
callParams.httpOptions
|
|
250
|
+
).then((res: Axios.AxiosResponse): T_Response => {
|
|
251
|
+
if (dynamoNTS_globalSettings.logApiEvents) {
|
|
252
|
+
if (dynamoNTS_globalSettings.logApiResponseContents) {
|
|
253
|
+
Dynamo_Log.success(`> ${callParams.name} api call was successful`, res.data);
|
|
254
|
+
|
|
255
|
+
} else {
|
|
256
|
+
Dynamo_Log.success(`> ${callParams.name} api call was successful`);
|
|
82
257
|
}
|
|
258
|
+
}
|
|
83
259
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
break;
|
|
92
|
-
case 'string':
|
|
93
|
-
httpParams.set(queryParamKey, inputParams.queryParams[queryParamKey]);
|
|
94
|
-
break;
|
|
95
|
-
default:
|
|
96
|
-
console.error('DYNAMOBE ERROR: \n wrong query param type', '\n\n', new Error());
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
callParams.httpOptions.params = httpParams;
|
|
102
|
-
} */
|
|
260
|
+
if (callParams.getFullResponse) {
|
|
261
|
+
return res as T_Response;
|
|
262
|
+
} else {
|
|
263
|
+
return res.data;
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
103
267
|
|
|
268
|
+
private static async delete<T_Response>(
|
|
269
|
+
axios: Axios.AxiosInstance,
|
|
270
|
+
url: string,
|
|
271
|
+
callParams: DynamoNTS_ApiCallParams
|
|
272
|
+
): Promise<T_Response> {
|
|
273
|
+
return await axios.delete<T_Response>(url, callParams.httpOptions).then(
|
|
274
|
+
(res: Axios.AxiosResponse): T_Response => {
|
|
104
275
|
if (dynamoNTS_globalSettings.logApiEvents) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (dynamoNTS_globalSettings.logApiRequestSettings) {
|
|
111
|
-
Dynamo_Log.log(`callParams:`, callParams);
|
|
112
|
-
Dynamo_Log.log('inputParams:', {
|
|
113
|
-
pathParams: inputParams.pathParams ?? {},
|
|
114
|
-
body: inputParams.body ?? null
|
|
115
|
-
});
|
|
116
|
-
}
|
|
276
|
+
if (dynamoNTS_globalSettings.logApiResponseContents) {
|
|
277
|
+
Dynamo_Log.success(`${callParams.name} was successful`, res.data);
|
|
278
|
+
} else {
|
|
279
|
+
Dynamo_Log.success(`${callParams.name} was successful`);
|
|
280
|
+
}
|
|
117
281
|
}
|
|
118
282
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
break;
|
|
140
|
-
case DynamoNTS_HttpCallType.delete:
|
|
141
|
-
if (inputParams?.body) {
|
|
142
|
-
Dynamo_Log.warn('WARNING you cant send body in delete calls');
|
|
143
|
-
}
|
|
144
|
-
await privateAxiosInstance.delete<T>(url, callParams.httpOptions).then((res: Axios.AxiosResponse ) => {
|
|
145
|
-
if (callParams.getFullResponse) {
|
|
146
|
-
a = res;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (dynamoNTS_globalSettings.logApiEvents) {
|
|
150
|
-
if (dynamoNTS_globalSettings.logApiResponseContents) {
|
|
151
|
-
Dynamo_Log.success(`${callParams.name} was successful`, res.data);
|
|
152
|
-
} else {
|
|
153
|
-
Dynamo_Log.success(`${callParams.name} was successful`);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
break;
|
|
158
|
-
case DynamoNTS_HttpCallType.post:
|
|
159
|
-
case DynamoNTS_HttpCallType.put:
|
|
160
|
-
case DynamoNTS_HttpCallType.patch:
|
|
161
|
-
if (!inputParams?.body) {
|
|
162
|
-
if (!inputParams) {
|
|
163
|
-
inputParams = {};
|
|
164
|
-
}
|
|
165
|
-
inputParams.body = {};
|
|
166
|
-
}
|
|
167
|
-
await privateAxiosInstance[callParams.type]<T>(url, inputParams.body, callParams.httpOptions).then((res: Axios.AxiosResponse ) => {
|
|
168
|
-
if (callParams.getFullResponse) {
|
|
169
|
-
a = res;
|
|
170
|
-
} else {
|
|
171
|
-
a = res.data;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (dynamoNTS_globalSettings.logApiEvents) {
|
|
175
|
-
if (dynamoNTS_globalSettings.logApiResponseContents) {
|
|
176
|
-
Dynamo_Log.success(`> ${callParams.name} api call was successful`, res.data);
|
|
177
|
-
} else {
|
|
178
|
-
Dynamo_Log.success(`> ${callParams.name} api call was successful`);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
break;
|
|
183
|
-
default:
|
|
184
|
-
Dynamo_Log.error('DYNAMOBE ERROR: \n wrong api call type'/* , '\n\n', new Error() */);
|
|
185
|
-
break;
|
|
283
|
+
if (callParams.getFullResponse) {
|
|
284
|
+
return res as T_Response;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
private static async get<T_Response>(
|
|
291
|
+
axios: Axios.AxiosInstance,
|
|
292
|
+
url: string,
|
|
293
|
+
callParams: DynamoNTS_ApiCallParams
|
|
294
|
+
): Promise<T_Response> {
|
|
295
|
+
return await axios.get<T_Response>(url, callParams.httpOptions).then(
|
|
296
|
+
(res: Axios.AxiosResponse): T_Response => {
|
|
297
|
+
if (dynamoNTS_globalSettings.logApiEvents) {
|
|
298
|
+
if (dynamoNTS_globalSettings.logApiResponseContents) {
|
|
299
|
+
Dynamo_Log.success(`${callParams.name} was successful`, res.data);
|
|
300
|
+
} else {
|
|
301
|
+
Dynamo_Log.success(`${callParams.name} was successful`);
|
|
302
|
+
}
|
|
186
303
|
}
|
|
187
304
|
|
|
188
305
|
if (callParams.getFullResponse) {
|
|
189
|
-
|
|
306
|
+
return res as T_Response;
|
|
190
307
|
} else {
|
|
191
|
-
|
|
308
|
+
return res.data;
|
|
192
309
|
}
|
|
193
|
-
|
|
310
|
+
}
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
private static logEvent<T_Body>(
|
|
315
|
+
url: string,
|
|
316
|
+
inputParams: DynamoNTS_ApiCallInputParams<T_Body>,
|
|
317
|
+
callParams: DynamoNTS_ApiCallParams
|
|
318
|
+
): void {
|
|
319
|
+
if (dynamoNTS_globalSettings.logApiRequestContents) {
|
|
320
|
+
Dynamo_Log.log(`< outgoing API call: ${url} \nbody:`, inputParams?.body);
|
|
321
|
+
|
|
322
|
+
} else {
|
|
323
|
+
Dynamo_Log.log(`< outgoing API call: ${url}`);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (dynamoNTS_globalSettings.logApiRequestSettings) {
|
|
327
|
+
Dynamo_Log.log(`callParams:`, callParams);
|
|
328
|
+
Dynamo_Log.log('inputParams:', {
|
|
329
|
+
pathParams: inputParams.pathParams ?? {},
|
|
330
|
+
body: inputParams.body ?? null,
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
private static setupHeaders(
|
|
336
|
+
callParams: DynamoNTS_ApiCallParams,
|
|
337
|
+
axios: Axios.AxiosInstance
|
|
338
|
+
): void {
|
|
339
|
+
for (const headerKey in callParams.httpOptions.headers) {
|
|
340
|
+
if (callParams.httpOptions.headers[headerKey]) {
|
|
341
|
+
axios.defaults.headers.common[headerKey] = callParams.httpOptions.headers[headerKey];
|
|
342
|
+
|
|
343
|
+
} else {
|
|
194
344
|
Dynamo_Log.error(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
`\ncallParams:`, callParams
|
|
345
|
+
'DYNAMOBE ERROR: \n missing header:',
|
|
346
|
+
headerKey
|
|
198
347
|
);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
199
351
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
throw new Dynamo_Error({
|
|
221
|
-
...this._getDefaultErrorSettings(
|
|
222
|
-
callParams.name + ' startApiCall',
|
|
223
|
-
error
|
|
224
|
-
),
|
|
225
|
-
|
|
226
|
-
status: 404,
|
|
227
|
-
errorCode: 'NTS-API-SAC2',
|
|
228
|
-
message: 'DNS error; address cannot be resolved!',
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
} else if (error.code === 'ECONNREFUSED') {
|
|
232
|
-
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL`/* , new Error() */);
|
|
233
|
-
|
|
234
|
-
throw new Dynamo_Error({
|
|
235
|
-
...this._getDefaultErrorSettings(
|
|
236
|
-
callParams.name + ' startApiCall',
|
|
237
|
-
error
|
|
238
|
-
),
|
|
239
|
-
|
|
240
|
-
status: 404,
|
|
241
|
-
errorCode: 'NTS-API-SAC3',
|
|
242
|
-
message: `Can't connect to the endpoin!`,
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
} else if (error.config && error.message) {
|
|
246
|
-
|
|
247
|
-
throw new Dynamo_Error({
|
|
248
|
-
...this._getDefaultErrorSettings(
|
|
249
|
-
callParams.name + ' startApiCall',
|
|
250
|
-
error
|
|
251
|
-
),
|
|
252
|
-
|
|
253
|
-
status: +error.message.substring(error.message.length - 4, 3),
|
|
254
|
-
errorCode: 'NTS-API-SAC4',
|
|
255
|
-
});
|
|
256
|
-
} else {
|
|
257
|
-
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL`, error/*, '\n\n' , new Error() */);
|
|
352
|
+
private static setupPathParams(
|
|
353
|
+
pathParams: { [param: string]: string; },
|
|
354
|
+
url: string
|
|
355
|
+
): string {
|
|
356
|
+
for (const pathParamKey in pathParams) {
|
|
357
|
+
if (pathParams[pathParamKey]) {
|
|
358
|
+
const paramType = typeof pathParams[pathParamKey];
|
|
359
|
+
|
|
360
|
+
switch (paramType) {
|
|
361
|
+
case 'number':
|
|
362
|
+
url = url.replace(
|
|
363
|
+
`:${pathParamKey}`,
|
|
364
|
+
pathParams[pathParamKey].toString()
|
|
365
|
+
);
|
|
366
|
+
break;
|
|
367
|
+
|
|
368
|
+
case 'string':
|
|
369
|
+
url = url.replace(`:${pathParamKey}`, pathParams[pathParamKey]);
|
|
370
|
+
break;
|
|
258
371
|
|
|
259
|
-
|
|
372
|
+
default:
|
|
373
|
+
Dynamo_Log.error(
|
|
374
|
+
`DYNAMOBE ERROR: \n wrong path param type: (${pathParamKey}): ${paramType} ` +
|
|
375
|
+
`\n${pathParams[pathParamKey]}` +
|
|
376
|
+
`\nMUST BE string or number` +
|
|
377
|
+
`\n\n`,
|
|
378
|
+
new Error()
|
|
379
|
+
);
|
|
380
|
+
break;
|
|
260
381
|
}
|
|
382
|
+
} else {
|
|
383
|
+
Dynamo_Log.error(
|
|
384
|
+
'DYNAMOBE ERROR: \n missing pathParam:',
|
|
385
|
+
pathParamKey /* , '\n\n', new Error() */
|
|
386
|
+
);
|
|
387
|
+
}
|
|
261
388
|
}
|
|
389
|
+
|
|
390
|
+
return url;
|
|
262
391
|
}
|
|
263
|
-
|
|
392
|
+
|
|
393
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
264
394
|
private static _getDefaultErrorSettings(fnName: string, error: Error | Dynamo_Error) {
|
|
265
395
|
return {
|
|
266
396
|
status: (error as Dynamo_Error)?.___status ?? 500,
|
|
@@ -269,7 +399,7 @@ export class DynamoNTS_ApiService {
|
|
|
269
399
|
userMessage: this.defaultErrorUserMsg,
|
|
270
400
|
issuerService: `${this?.constructor?.name}-${this?.name}-DynamoNTS_ApiService`,
|
|
271
401
|
error: error,
|
|
272
|
-
}
|
|
402
|
+
};
|
|
273
403
|
}
|
|
274
404
|
}
|
|
275
405
|
|
|
@@ -35,6 +35,7 @@ export abstract class DynamoNTS_AuthService extends DynamoNTS_SingletonService {
|
|
|
35
35
|
*/
|
|
36
36
|
static getTokenFromRequest(req: Request): string {
|
|
37
37
|
const authHeader = req.headers['authorization'];
|
|
38
|
+
|
|
38
39
|
if (!authHeader) {
|
|
39
40
|
throw new Dynamo_Error({
|
|
40
41
|
status: 401,
|
|
@@ -47,6 +48,7 @@ export abstract class DynamoNTS_AuthService extends DynamoNTS_SingletonService {
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
const token = authHeader.split(' ')[1];
|
|
51
|
+
|
|
50
52
|
if (!token) {
|
|
51
53
|
throw new Dynamo_Error({
|
|
52
54
|
status: 401,
|