@futdevpro/nts-dynamo 1.5.40 → 1.5.47

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.
Files changed (118) hide show
  1. package/futdevpro-nts-dynamo-01.05.41.tgz +0 -0
  2. package/futdevpro-nts-dynamo-01.05.42.tgz +0 -0
  3. package/futdevpro-nts-dynamo-01.05.43.tgz +0 -0
  4. package/futdevpro-nts-dynamo-01.05.44.tgz +0 -0
  5. package/futdevpro-nts-dynamo-01.05.45.tgz +0 -0
  6. package/lib/_enums/http/socket-event.enum.d.ts +2 -0
  7. package/lib/_enums/http/socket-event.enum.d.ts.map +1 -1
  8. package/lib/_enums/http/socket-event.enum.js +2 -0
  9. package/lib/_enums/http/socket-event.enum.js.map +1 -1
  10. package/lib/_models/dynamo-nts-endpoint-params.js +1 -1
  11. package/lib/_models/dynamo-nts-endpoint-params.js.map +1 -1
  12. package/lib/_models/dynamo-nts-socket-dictionary.d.ts +16 -0
  13. package/lib/_models/dynamo-nts-socket-dictionary.d.ts.map +1 -0
  14. package/lib/_models/dynamo-nts-socket-dictionary.js +31 -0
  15. package/lib/_models/dynamo-nts-socket-dictionary.js.map +1 -0
  16. package/lib/_models/dynamo-nts-socket-event-params.d.ts +2 -0
  17. package/lib/_models/dynamo-nts-socket-event-params.d.ts.map +1 -1
  18. package/lib/_models/dynamo-nts-socket-event-params.js +6 -5
  19. package/lib/_models/dynamo-nts-socket-event-params.js.map +1 -1
  20. package/lib/_models/index.d.ts +1 -0
  21. package/lib/_models/index.d.ts.map +1 -1
  22. package/lib/_models/index.js +1 -0
  23. package/lib/_models/index.js.map +1 -1
  24. package/lib/_modules/app-extended.index.d.ts +1 -0
  25. package/lib/_modules/app-extended.index.d.ts.map +1 -1
  26. package/lib/_modules/app-extended.index.js +1 -0
  27. package/lib/_modules/app-extended.index.js.map +1 -1
  28. package/lib/_modules/test/custom-data.service.d.ts +3 -3
  29. package/lib/_modules/test/custom-data.service.d.ts.map +1 -1
  30. package/lib/_modules/test/custom-data.service.js +4 -4
  31. package/lib/_modules/test/custom-data.service.js.map +1 -1
  32. package/lib/_modules/test/test-controller.js +6 -6
  33. package/lib/_modules/test/test-controller.js.map +1 -1
  34. package/lib/_modules/usage/usage-controller.js +1 -1
  35. package/lib/_modules/usage/usage-controller.js.map +1 -1
  36. package/lib/_modules/usage/usage.service.d.ts +6 -6
  37. package/lib/_modules/usage/usage.service.d.ts.map +1 -1
  38. package/lib/_modules/usage/usage.service.js +18 -10
  39. package/lib/_modules/usage/usage.service.js.map +1 -1
  40. package/lib/_services/dynamo-nts-api.service.d.ts.map +1 -1
  41. package/lib/_services/dynamo-nts-api.service.js +19 -8
  42. package/lib/_services/dynamo-nts-api.service.js.map +1 -1
  43. package/lib/_services/dynamo-nts-app-extended.d.ts +1 -1
  44. package/lib/_services/dynamo-nts-app-extended.d.ts.map +1 -1
  45. package/lib/_services/dynamo-nts-app-extended.js +2 -4
  46. package/lib/_services/dynamo-nts-app-extended.js.map +1 -1
  47. package/lib/_services/dynamo-nts-app.d.ts +1 -0
  48. package/lib/_services/dynamo-nts-app.d.ts.map +1 -1
  49. package/lib/_services/dynamo-nts-app.js +4 -1
  50. package/lib/_services/dynamo-nts-app.js.map +1 -1
  51. package/lib/_services/dynamo-nts-auth.service.d.ts.map +1 -1
  52. package/lib/_services/dynamo-nts-auth.service.js +10 -4
  53. package/lib/_services/dynamo-nts-auth.service.js.map +1 -1
  54. package/lib/_services/dynamo-nts-controller.service.d.ts +37 -0
  55. package/lib/_services/dynamo-nts-controller.service.d.ts.map +1 -1
  56. package/lib/_services/dynamo-nts-controller.service.js +37 -0
  57. package/lib/_services/dynamo-nts-controller.service.js.map +1 -1
  58. package/lib/_services/dynamo-nts-data.service.d.ts +21 -2
  59. package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
  60. package/lib/_services/dynamo-nts-data.service.js +121 -53
  61. package/lib/_services/dynamo-nts-data.service.js.map +1 -1
  62. package/lib/_services/dynamo-nts-db.service.d.ts +4 -4
  63. package/lib/_services/dynamo-nts-db.service.d.ts.map +1 -1
  64. package/lib/_services/dynamo-nts-db.service.js +148 -84
  65. package/lib/_services/dynamo-nts-db.service.js.map +1 -1
  66. package/lib/_services/dynamo-nts-email.service.d.ts.map +1 -1
  67. package/lib/_services/dynamo-nts-email.service.js +20 -16
  68. package/lib/_services/dynamo-nts-email.service.js.map +1 -1
  69. package/lib/_services/dynamo-nts-global.service.d.ts +5 -5
  70. package/lib/_services/dynamo-nts-global.service.d.ts.map +1 -1
  71. package/lib/_services/dynamo-nts-global.service.js.map +1 -1
  72. package/lib/_services/dynamo-nts-routing-module.service.d.ts.map +1 -1
  73. package/lib/_services/dynamo-nts-routing-module.service.js +17 -11
  74. package/lib/_services/dynamo-nts-routing-module.service.js.map +1 -1
  75. package/lib/_services/dynamo-nts-shared.service.d.ts +6 -0
  76. package/lib/_services/dynamo-nts-shared.service.d.ts.map +1 -1
  77. package/lib/_services/dynamo-nts-shared.service.js +8 -0
  78. package/lib/_services/dynamo-nts-shared.service.js.map +1 -1
  79. package/lib/_services/dynamo-nts-socket-service-collection.service.d.ts +1 -1
  80. package/lib/_services/dynamo-nts-socket-service-collection.service.d.ts.map +1 -1
  81. package/lib/_services/dynamo-nts-socket.service.d.ts +6 -9
  82. package/lib/_services/dynamo-nts-socket.service.d.ts.map +1 -1
  83. package/lib/_services/dynamo-nts-socket.service.js +25 -20
  84. package/lib/_services/dynamo-nts-socket.service.js.map +1 -1
  85. package/lib/_services/dynamobe-api.service.js +2 -2
  86. package/lib/_services/dynamobe-auth.service.js +2 -2
  87. package/lib/_services/dynamobe-data.service.d.ts +2 -2
  88. package/lib/_services/dynamobe-data.service.js +15 -15
  89. package/lib/_services/dynamobe-db.service.d.ts +4 -4
  90. package/lib/_services/dynamobe-db.service.js +28 -28
  91. package/lib/_services/dynamobe-email.service.js +4 -4
  92. package/lib/_services/dynamobe-global.service.d.ts +3 -3
  93. package/lib/_services/dynamobe-routing-module.service.js +3 -3
  94. package/lib/tsconfig.tsbuildinfo +1 -5564
  95. package/package.json +22 -12
  96. package/src/_enums/http/socket-event.enum.ts +2 -0
  97. package/src/_models/dynamo-nts-endpoint-params.ts +1 -1
  98. package/src/_models/dynamo-nts-socket-dictionary.ts +39 -0
  99. package/src/_models/dynamo-nts-socket-event-params.ts +8 -5
  100. package/src/_models/index.ts +1 -0
  101. package/src/_modules/app-extended.index.ts +1 -0
  102. package/src/_modules/test/custom-data.service.ts +4 -4
  103. package/src/_modules/test/test-controller.ts +7 -7
  104. package/src/_modules/usage/usage-controller.ts +2 -2
  105. package/src/_modules/usage/usage.service.ts +34 -26
  106. package/src/_services/dynamo-nts-api.service.ts +26 -9
  107. package/src/_services/dynamo-nts-app-extended.ts +9 -9
  108. package/src/_services/dynamo-nts-app.ts +2 -2
  109. package/src/_services/dynamo-nts-auth.service.ts +13 -5
  110. package/src/_services/dynamo-nts-controller.service.ts +37 -0
  111. package/src/_services/dynamo-nts-data.service.ts +123 -55
  112. package/src/_services/dynamo-nts-db.service.ts +181 -87
  113. package/src/_services/dynamo-nts-email.service.ts +21 -17
  114. package/src/_services/dynamo-nts-global.service.ts +12 -5
  115. package/src/_services/dynamo-nts-routing-module.service.ts +16 -10
  116. package/src/_services/dynamo-nts-shared.service.ts +9 -0
  117. package/src/_services/dynamo-nts-socket-service-collection.service.ts +1 -1
  118. package/src/_services/dynamo-nts-socket.service.ts +33 -29
package/package.json CHANGED
@@ -1,12 +1,19 @@
1
1
  {
2
2
  "name": "@futdevpro/nts-dynamo",
3
- "version": "01.05.40",
3
+ "version": "01.05.47",
4
4
  "description": "Dynamic NodeTS (NodeJS-Typescript), MongoDB Backend System Framework by Future Development Ltd.",
5
5
  "scripts": {
6
- "build": "npx tsc",
7
- "postbuild": "npm publish",
8
- "buildtgz": "npx tsc",
9
- "postbuildtgz": "npm pack"
6
+ "build": "npm run inb",
7
+ "inb": "npm i",
8
+ "postinb": "npm run pinb",
9
+ "pinb": "npx tsc",
10
+ "postpinb": "npm publish",
11
+
12
+ "build-tgz": "npm run inbt",
13
+ "inbt": "npm i",
14
+ "postinbt": "npm run pinbt",
15
+ "pinbt": "npx tsc",
16
+ "postbpinbt": "npm pack"
10
17
  },
11
18
  "main": "./lib/index.js",
12
19
  "module": "./lib/index.js",
@@ -169,7 +176,7 @@
169
176
  },
170
177
  "homepage": "https:/futdevpro.hu/projects/dynamo",
171
178
  "peerDependencies": {
172
- "@futdevpro/fsm-dynamo": "^1.5.24",
179
+ "@futdevpro/fsm-dynamo": "^1.5.28",
173
180
 
174
181
  "@types/express": "^4.17.7",
175
182
  "@types/geoip-lite": "^1.4.1",
@@ -179,13 +186,16 @@
179
186
  "geoip-lite": "^1.4.5",
180
187
  "mongoose": "^5.13.14",
181
188
  "nodemailer": "^6.7.5",
182
- "rxjs": "^7.4.0"
183
- },
184
- "dependencies": {
189
+ "rxjs": "^7.4.0",
190
+
185
191
  "@types/node": "~14.0.27",
186
- "socket.io": "^4.5.2",
187
192
  "ts-node": "~8.10.2",
188
- "tslib": "~2.0.1",
189
- "typescript": "~3.9.7"
193
+ "typescript": "~4.8.3"
194
+ },
195
+ "peerDevDependencies": {
196
+ "tslib": "~2.0.1"
197
+ },
198
+ "devDependencies": {
199
+ "socket.io": "^4.5.2"
190
200
  }
191
201
  }
@@ -2,6 +2,8 @@
2
2
  export enum DynamoNTS_SocketEvent {
3
3
  connection = 'connection',
4
4
  subscribe = 'subscribe',
5
+ subscriptionSuccessful = 'subscriptionSuccessful',
6
+ unsubscribe = 'unsubscribe',
5
7
  event = 'event',
6
8
  disconnect = 'disconnection'
7
9
  }
@@ -84,7 +84,7 @@ export class DynamoNTS_EndpointParams{
84
84
  let inputs = '';
85
85
  for(let i = 0; i < this.pathParams.length; i++) {
86
86
  inputs += ` ${this.pathParams[i]}: ${req.params[this.pathParams[i]]}`;
87
- if (i + 1 < this.pathParams.length || req.body && req.body !== {}) {
87
+ if (i + 1 < this.pathParams.length || req.body && `${req.body}` !== '{}') {
88
88
  inputs += ',';
89
89
  }
90
90
  }
@@ -0,0 +1,39 @@
1
+
2
+ import { Dynamo_Error } from '@futdevpro/fsm-dynamo';
3
+ import * as SocketIO from 'socket.io';
4
+
5
+ export class DynamoNTS_SocketDictionary {
6
+ issuerId: string;
7
+ sockets: SocketIO.Socket[];
8
+
9
+ constructor(
10
+ set?: {
11
+ issuerId: string,
12
+ sockets: SocketIO.Socket[],
13
+ }
14
+ ) {
15
+ this.issuerId = set.issuerId;
16
+ if (!set.sockets.length) {
17
+ throw new Dynamo_Error({
18
+ status: 406,
19
+ errorCode: 'NTS-SD0-C00',
20
+ addECToUserMsg: true,
21
+ message: 'trying to create DynamoNTS_SocketDictionary without a single active socket',
22
+ userMessage: 'We encountered an unhandled Server Error, please contact the responsible development team.'
23
+ });
24
+ }
25
+ this.sockets = set.sockets;
26
+ }
27
+
28
+ /**
29
+ * Emits event on all sockets
30
+ * @param event
31
+ * @param content
32
+ */
33
+ emitEvent(event: string, content: any) {
34
+ this.sockets.forEach((socket: SocketIO.Socket) => {
35
+ socket.emit(event, content);
36
+ });
37
+ }
38
+ }
39
+
@@ -8,6 +8,7 @@ import { DynamoNTS_SocketEvent } from '../_enums/http/socket-event.enum';
8
8
  *
9
9
  */
10
10
  export class DynamoNTS_SocketEventParams<T>{
11
+ socketName?: string;
11
12
  event: DynamoNTS_SocketEvent | string;
12
13
 
13
14
  preProcessess?: ((content?: T) => Promise<T>)[];
@@ -18,6 +19,7 @@ export class DynamoNTS_SocketEventParams<T>{
18
19
 
19
20
  constructor(
20
21
  set: {
22
+ socketName?: string,
21
23
  event: DynamoNTS_SocketEvent | string,
22
24
 
23
25
  preProcessess?: ((content?: T) => Promise<T>)[],
@@ -28,6 +30,7 @@ export class DynamoNTS_SocketEventParams<T>{
28
30
  }
29
31
  ) {
30
32
  try {
33
+ this.socketName = set.socketName;
31
34
  this.event = set.event;
32
35
 
33
36
  this.preProcessess = set.preProcessess ? set.preProcessess : [];
@@ -47,7 +50,7 @@ export class DynamoNTS_SocketEventParams<T>{
47
50
  }
48
51
  } catch (error) {
49
52
  DynamoNTS_Shared.logError(
50
- `\nSocket Event params setup failed: ${set.event}`, error);
53
+ `\nSocket Event params setup failed (${this.socketName}): ${set.event}`, error);
51
54
  throw error;
52
55
  }
53
56
  }
@@ -61,14 +64,14 @@ export class DynamoNTS_SocketEventParams<T>{
61
64
  try {
62
65
  if (this.logEvent) {
63
66
  if (this.logEventContent) {
64
- console.log(`==> incoming ${this.event} socket event... content:`, content);
67
+ console.log(`==> incoming ${this.socketName} socket event: ${this.event} content:`, content);
65
68
  } else {
66
- console.log(`==> incoming ${this.event} socket event...`);
69
+ console.log(`==> incoming ${this.socketName} socket event: ${this.event}...`);
67
70
  }
68
71
  }
69
72
  return content;
70
73
  } catch (error) {
71
- console.error('PreLog failed....', error);
74
+ console.error(`PreLog failed... (socket: ${this.socketName})`, error);
72
75
  }
73
76
  };
74
77
  }
@@ -88,7 +91,7 @@ export class DynamoNTS_SocketEventParams<T>{
88
91
  await this.tasks[i](content, issuer);
89
92
  }
90
93
  } catch (error) {
91
- console.error(`Socket Event tasks failed to execute.... (${this.event})`, error, 'content:', content);
94
+ console.error(`Socket Event tasks failed to execute on ${this.socketName}.... (${this.event})`, error, 'content:', content);
92
95
  }
93
96
  };
94
97
  }
@@ -8,4 +8,5 @@ export * from './dynamo-nts-global-settings';
8
8
  export * from './dynamo-nts-routing-module-settings';
9
9
  export * from './dynamo-nts-socket-event-params';
10
10
  export * from './dynamo-nts-socket-service-params';
11
+ export * from './dynamo-nts-socket-dictionary';
11
12
 
@@ -11,6 +11,7 @@ export * from '../_models/dynamo-nts-app-params';
11
11
  export * from '../_models/dynamo-nts-endpoint-params';
12
12
  export * from '../_models/dynamo-nts-global-settings';
13
13
  export * from '../_models/dynamo-nts-routing-module-settings';
14
+ export * from '../_models/dynamo-nts-socket-dictionary';
14
15
 
15
16
  // ENUMS
16
17
  export * from '../_enums/dynamo-nts-route-security.enum';
@@ -1,17 +1,17 @@
1
1
 
2
2
 
3
3
 
4
- import { CustomData, customDataModelParams } from '@futdevpro/fsm-dynamo/test-module';
4
+ import { Dynamo_CustomData, customDataModelParams } from '@futdevpro/fsm-dynamo/test-module';
5
5
  import { DynamoNTS_DataService } from '../../_services/dynamo-nts-data.service';
6
6
 
7
- export class CustomDataService extends DynamoNTS_DataService<CustomData> {
7
+ export class Dynamo_CustomDataService extends DynamoNTS_DataService<Dynamo_CustomData> {
8
8
 
9
9
  constructor(
10
- customData?: CustomData,
10
+ customData?: Dynamo_CustomData,
11
11
  issuer?: string,
12
12
  ) {
13
13
  super(
14
- new CustomData(customData),
14
+ new Dynamo_CustomData(customData),
15
15
  customDataModelParams,
16
16
  issuer
17
17
  );
@@ -4,7 +4,7 @@ import { testModuleSettings } from '@futdevpro/fsm-dynamo/test-module';
4
4
  import { HttpCallType } from '../../_enums/http/http-call-type.enum';
5
5
  import { DynamoNTS_EndpointParams } from '../../_models/dynamo-nts-endpoint-params';
6
6
  import { DynamoNTS_Controller } from '../../_services/dynamo-nts-controller.service';
7
- import { CustomDataService } from './custom-data.service';
7
+ import { Dynamo_CustomDataService } from './custom-data.service';
8
8
 
9
9
  export class TestController extends DynamoNTS_Controller {
10
10
 
@@ -92,12 +92,12 @@ export class TestController extends DynamoNTS_Controller {
92
92
 
93
93
  // CUSTOM DATA
94
94
  new DynamoNTS_EndpointParams({
95
- name: 'getCustomData',
95
+ name: 'getDynamo_CustomData',
96
96
  type: HttpCallType.get,
97
- endpoint: testModuleSettings.endPoints.getCustomData,
97
+ endpoint: testModuleSettings.endPoints.getDynamo_CustomData,
98
98
  tasks: [
99
99
  async (req: Request, res: Response) => {
100
- const customDataService = new CustomDataService({ _id: req.params.customId });
100
+ const customDataService = new Dynamo_CustomDataService({ _id: req.params.customId });
101
101
 
102
102
  await customDataService.getDataById();
103
103
 
@@ -112,12 +112,12 @@ export class TestController extends DynamoNTS_Controller {
112
112
  }),
113
113
 
114
114
  new DynamoNTS_EndpointParams({
115
- name: 'modifyCustomData',
115
+ name: 'modifyDynamo_CustomData',
116
116
  type: HttpCallType.post,
117
- endpoint: testModuleSettings.endPoints.modifyCustomData,
117
+ endpoint: testModuleSettings.endPoints.modifyDynamo_CustomData,
118
118
  tasks: [
119
119
  async (req: Request, res: Response, issuer: string) => {
120
- const customDataService = new CustomDataService(req.body, issuer);
120
+ const customDataService = new Dynamo_CustomDataService(req.body, issuer);
121
121
 
122
122
  await customDataService.saveData();
123
123
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { Request, Response } from 'express';
3
- import { usageModuleSettings, DynamoUsageSession } from '@futdevpro/fsm-dynamo/usage-module';
3
+ import { usageModuleSettings, Dynamo_UsageSession } from '@futdevpro/fsm-dynamo/usage-module';
4
4
  import { HttpCallType } from '../../_enums/http/http-call-type.enum';
5
5
  import { DynamoNTS_EndpointParams } from '../../_models/dynamo-nts-endpoint-params';
6
6
  import { DynamoNTS_AuthService } from '../../_services/dynamo-nts-auth.service';
@@ -30,7 +30,7 @@ export class UsageController extends DynamoNTS_Controller {
30
30
  const authService = DynamoNTS_GlobalService.getAuthService();
31
31
  const username = authService.getUsernameFromRequest(req);
32
32
  const usageService = new UsageService({
33
- usageSession: new DynamoUsageSession({
33
+ usageSession: new Dynamo_UsageSession({
34
34
  sessionStart: new Date(),
35
35
  issuer: username,
36
36
  }),
@@ -1,25 +1,25 @@
1
1
 
2
2
  import { Request } from 'express';
3
- import { DynamoNTS_Error } from '@futdevpro/fsm-dynamo';
4
- import { DynamoUsageSession, usageSessionModelParams, DynamoUsageData,
5
- DailyUsageData } from '@futdevpro/fsm-dynamo/usage-module';
3
+ import { Dynamo_Error } from '@futdevpro/fsm-dynamo';
4
+ import { Dynamo_UsageSession, usageSessionModelParams, Dynamo_UsageData,
5
+ Dynamo_DailyUsageData } from '@futdevpro/fsm-dynamo/usage-module';
6
6
 
7
7
  import { DynamoNTS_DataService } from '../../_services/dynamo-nts-data.service';
8
8
  import { DynamoNTS_Shared } from '../../_services/dynamo-nts-shared.service';
9
9
 
10
- export class UsageService extends DynamoNTS_DataService<DynamoUsageSession> {
11
- usageData: DynamoUsageData[] = [];
12
- simplifiedDailyUsage: DailyUsageData[] = [];
10
+ export class UsageService extends DynamoNTS_DataService<Dynamo_UsageSession> {
11
+ usageData: Dynamo_UsageData[] = [];
12
+ simplifiedDailyUsage: Dynamo_DailyUsageData[] = [];
13
13
 
14
14
  constructor(
15
15
  set?: {
16
- usageSession?: DynamoUsageSession,
17
- usageData?: DynamoUsageData[],
16
+ usageSession?: Dynamo_UsageSession,
17
+ usageData?: Dynamo_UsageData[],
18
18
  issuer?: string,
19
19
  }
20
20
  ) {
21
21
  super(
22
- new DynamoUsageSession(set?.usageSession),
22
+ new Dynamo_UsageSession(set?.usageSession),
23
23
  usageSessionModelParams,
24
24
  set?.issuer
25
25
  );
@@ -33,8 +33,10 @@ export class UsageService extends DynamoNTS_DataService<DynamoUsageSession> {
33
33
 
34
34
  /* console.log(`...getLocationDataFromRequest... ip: ${this.data.address}`, this.data.locationData); */
35
35
  } catch (error) {
36
- throw new DynamoNTS_Error({
37
- status: 417, message: 'getLocationDataFromRequest was unsuccessful',
36
+ throw new Dynamo_Error({
37
+ status: 417,
38
+ errorCode: 'NTS-US0-GLD',
39
+ message: 'getLocationDataFromRequest was unsuccessful',
38
40
  userMessage: `We were unable to deep analyze your request.`,
39
41
  error
40
42
  });
@@ -45,18 +47,18 @@ export class UsageService extends DynamoNTS_DataService<DynamoUsageSession> {
45
47
  try {
46
48
  await this.dataDBService.find({
47
49
  sessionStart: { $gte: DynamoNTS_Shared.oneWeekAgo() }
48
- }).then((res: DynamoUsageSession[]) => {
50
+ }).then((res: Dynamo_UsageSession[]) => {
49
51
  this.dataList = res;
50
52
  });
51
53
  this.simplifiedDailyUsage = [];
52
- this.dataList.forEach((session: DynamoUsageSession) => {
54
+ this.dataList.forEach((session: Dynamo_UsageSession) => {
53
55
  let dateIndex = this.simplifiedDailyUsage.findIndex(
54
- (dailyData: DailyUsageData) => dailyData.date === session.date
56
+ (dailyData: Dynamo_DailyUsageData) => dailyData.date === session.date
55
57
  );
56
58
  if (-1 < dateIndex) {
57
59
  this.simplifiedDailyUsage[dateIndex].visitations.push(session);
58
60
  } else {
59
- const newUsageSimple = new DailyUsageData({ date: session.date, visitations: [ session ] });
61
+ const newUsageSimple = new Dynamo_DailyUsageData({ date: session.date, visitations: [ session ] });
60
62
  this.simplifiedDailyUsage.push(newUsageSimple);
61
63
  dateIndex = this.simplifiedDailyUsage.length - 1;
62
64
  }
@@ -76,17 +78,19 @@ export class UsageService extends DynamoNTS_DataService<DynamoUsageSession> {
76
78
  });
77
79
 
78
80
  this.simplifiedDailyUsage.sort(
79
- (a: DailyUsageData, b: DailyUsageData) => +new Date(b.date) - +new Date(a.date)
81
+ (a: Dynamo_DailyUsageData, b: Dynamo_DailyUsageData) => +new Date(b.date) - +new Date(a.date)
80
82
  );
81
- this.simplifiedDailyUsage.forEach((daily: DailyUsageData) => {
83
+ this.simplifiedDailyUsage.forEach((daily: Dynamo_DailyUsageData) => {
82
84
  daily.visitations.sort(
83
- (a: DynamoUsageSession, b: DynamoUsageSession) => +a.sessionStart - +b.sessionStart
85
+ (a: Dynamo_UsageSession, b: Dynamo_UsageSession) => +a.sessionStart - +b.sessionStart
84
86
  );
85
87
  });
86
88
 
87
89
  } catch (error) {
88
- throw new DynamoNTS_Error({
89
- status: 417, message: 'getDailyUsage was unsuccessful',
90
+ throw new Dynamo_Error({
91
+ status: 417,
92
+ errorCode: 'NTS-US0-GLW',
93
+ message: 'getDailyUsage was unsuccessful',
90
94
  userMessage: `We've failed to collect last week's usage data.`,
91
95
  error
92
96
  });
@@ -98,7 +102,7 @@ export class UsageService extends DynamoNTS_DataService<DynamoUsageSession> {
98
102
  await this.getDataById();
99
103
  this.data.usageData = this.usageData;
100
104
  let totalTime = 0;
101
- this.data.usageData.forEach((data: DynamoUsageData) => {
105
+ this.data.usageData.forEach((data: Dynamo_UsageData) => {
102
106
  totalTime += data.timeSpentOnPage;
103
107
  });
104
108
  if (!this.data.locationData) {
@@ -107,8 +111,10 @@ export class UsageService extends DynamoNTS_DataService<DynamoUsageSession> {
107
111
  this.data.totalSessionTime = totalTime;
108
112
  await this.saveData();
109
113
  } catch (error) {
110
- throw new DynamoNTS_Error({
111
- status: 417, message: 'updateSessionData was unsuccessful',
114
+ throw new Dynamo_Error({
115
+ status: 417,
116
+ errorCode: 'NTS-US0-UU0',
117
+ message: 'updateSessionData was unsuccessful',
112
118
  userMessage: `The attempt to update Usage Data was unsuccessful.`,
113
119
  error
114
120
  });
@@ -124,12 +130,14 @@ export class UsageService extends DynamoNTS_DataService<DynamoUsageSession> {
124
130
  if (!this.data.locationData) {
125
131
  this.getLocationDataFromRequest(req);
126
132
  }
127
- this.data.usageData.sort((a: DynamoUsageData, b: DynamoUsageData) => +a.opened - +b.opened);
133
+ this.data.usageData.sort((a: Dynamo_UsageData, b: Dynamo_UsageData) => +a.opened - +b.opened);
128
134
  this.data.totalSessionTime = newTotalSessionTime;
129
135
  await this.saveData();
130
136
  } catch (error) {
131
- throw new DynamoNTS_Error({
132
- status: 417, message: 'closeSession was unsuccessful',
137
+ throw new Dynamo_Error({
138
+ status: 417,
139
+ errorCode: 'NTS-US0-CS0',
140
+ message: 'closeSession was unsuccessful',
133
141
  userMessage: `The attempt to close Usage Session was unsuccessful.`,
134
142
  error
135
143
  });
@@ -1,6 +1,6 @@
1
1
 
2
2
  import * as Axios from 'axios';
3
- import { DynamoNTS_Error } from '@futdevpro/fsm-dynamo';
3
+ import { Dynamo_Error } from '@futdevpro/fsm-dynamo';
4
4
 
5
5
  import { HttpCallType } from '../_enums/http/http-call-type.enum';
6
6
  import { HttpResponseType } from '../_enums/http/http-response-type.enum';
@@ -138,29 +138,46 @@ export class DynamoNTS_ApiService {
138
138
  return a as T;
139
139
  }
140
140
  } catch (error) {
141
- DynamoNTS_Shared.logError(`\nAPI ERRROR: ${callParams?.name} failed...` +
141
+ DynamoNTS_Shared.logError(`\nAPI ERROR: ${callParams?.name} failed...` +
142
142
  `\n${callParams?.baseUrl}${callParams?.endPoint}`);
143
+
143
144
  if (callParams?.httpOptions?.responseType === HttpResponseType.text) {
144
145
  error.error = JSON.parse(error.error);
145
146
  }
146
- if (error?.response?.data?.flag === 'DYNAMO-BE ERROR OBJECT') {
147
+
148
+ if (error?.response?.data?.flag === 'DYNAMO ERROR OBJECT') {
147
149
  DynamoNTS_Shared.logError(`\n${callParams.name} was UNSUCCESSFUL\n\n`, new Error());
148
- throw new DynamoNTS_Error(error.response.data);
150
+
151
+ throw new Dynamo_Error({
152
+ errorCode: 'NTS-API-002',
153
+ addECToUserMsg: true,
154
+ message: 'API call failed on the other end! error response found...',
155
+ userMessage: `We encountered a BackEnd API Error, please contact the responsible development team.`,
156
+ error: error.response.data
157
+ });
149
158
  } else if (error.code === 'ENOTFOUND') {
150
159
  DynamoNTS_Shared.logError(`\n${callParams.name} was UNSUCCESSFUL\n\n`, new Error());
151
- throw new DynamoNTS_Error({
152
- status: 404, message: 'DNS error; address cannot be resolved!',
153
- userMessage: `We encountered a BackEnd API Error, please contact the responsible development team. errorcode: 965-453-300`,
160
+
161
+ throw new Dynamo_Error({
162
+ status: 404,
163
+ errorCode: 'NTS-API-000',
164
+ addECToUserMsg: true,
165
+ message: 'DNS error; address cannot be resolved!',
166
+ userMessage: `We encountered a BackEnd API Error, please contact the responsible development team.`,
154
167
  error: error
155
168
  });
156
169
  } else if (error.config && error.message) {
157
- throw new DynamoNTS_Error({
170
+
171
+ throw new Dynamo_Error({
158
172
  status: +error.message.substring(error.message.length - 4, 3),
159
- userMessage: `We encountered a BackEnd API Error, please contact the responsible development team. errorcode: 965-453-303`,
173
+ errorCode: 'NTS-API-003',
174
+ addECToUserMsg: true,
175
+ userMessage: `We encountered a BackEnd API Error, please contact the responsible development team.`,
160
176
  error: error
161
177
  });
162
178
  } else {
163
179
  DynamoNTS_Shared.logError(`\n${callParams.name} was UNSUCCESSFUL`, error, '\n\n', new Error());
180
+
164
181
  throw error;
165
182
  }
166
183
  }
@@ -32,7 +32,7 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
32
32
 
33
33
  private socketSecurity: DynamoNTS_RouteSecurity;
34
34
 
35
- protected socketServices: DynamoNTS_SocketService[] = [];
35
+ protected socketServices: DynamoNTS_SocketService<any>[];
36
36
 
37
37
  constructor(){
38
38
  super();
@@ -47,11 +47,11 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
47
47
  } else {
48
48
  DynamoNTS_Shared.logWarning(
49
49
  '\nNo socketServices setted up while using Extended Application.',
50
- '\nYou should use DynamoNTS_App if you don`t need socket services.'
50
+ '\nYou should use DynamoNTS_App if you don`t need socket services.\n'
51
51
  );
52
52
  }
53
53
  } catch (error) {
54
- DynamoNTS_Shared.logError('\nExtended Application start failed.\n', error);
54
+ DynamoNTS_Shared.logError('\nExtended Application start failed.\n', error, '\n');
55
55
  }
56
56
  }
57
57
 
@@ -59,8 +59,7 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
59
59
  *
60
60
  */
61
61
  private setSocketSecurity(): void {
62
- console.log('setSecurityExtended');
63
- this.socketServices.forEach((service: DynamoNTS_SocketService) => {
62
+ this.socketServices.forEach((service: DynamoNTS_SocketService<any>) => {
64
63
  if (!this.socketSecurity) {
65
64
  this.socketSecurity = DynamoNTS_RouteSecurity[service.security];
66
65
  } else if (this.socketSecurity !== DynamoNTS_RouteSecurity.both && this.socketSecurity !== DynamoNTS_RouteSecurity[service.security]) {
@@ -95,7 +94,7 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
95
94
  `\nin DynamoBEServer - setupRoutingModules() to enable secure routes.`;
96
95
 
97
96
  errorMsg += '\n\nThe socket services setted to use secure server:';
98
- this.socketServices.forEach((service: DynamoNTS_SocketService) => {
97
+ this.socketServices.forEach((service: DynamoNTS_SocketService<any>) => {
99
98
  if (service.security != DynamoNTS_SocketSecurity.open) {
100
99
  errorMsg += `\n ${service.name} (port: ${service.port})`;
101
100
  }
@@ -112,9 +111,10 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
112
111
  }
113
112
  }
114
113
 
115
- this.socketServices.forEach((service: DynamoNTS_SocketService) => {
116
- const existingPorts: DynamoNTS_SocketService[] = this.socketServices.filter(
117
- (mod: DynamoNTS_SocketService) => mod.port === service.port);
114
+ this.socketServices.forEach((service: DynamoNTS_SocketService<any>) => {
115
+ const existingPorts: DynamoNTS_SocketService<any>[] = this.socketServices.filter(
116
+ (mod: DynamoNTS_SocketService<any>) => mod.port === service.port
117
+ );
118
118
 
119
119
  if (1 < existingPorts.length || this.httpPort === service.port || this.httpsPort === service.port) {
120
120
  let error = new Error(`PORT DUPLICATION: ${service.port}`);
@@ -92,10 +92,10 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
92
92
 
93
93
  this.mongoose.connect(
94
94
  this.params.dbUri,
95
- /* {
95
+ {
96
96
  useNewUrlParser: true,
97
97
  useUnifiedTopology: true
98
- } */
98
+ }
99
99
  );
100
100
  }
101
101
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { NextFunction, Request, Response } from 'express';
3
- import { DynamoNTS_Error } from '@futdevpro/fsm-dynamo';
3
+ import { Dynamo_Error } from '@futdevpro/fsm-dynamo';
4
4
 
5
5
  import { DynamoNTS_SingletonService } from './dynamo-nts-singleton.service';
6
6
 
@@ -29,18 +29,26 @@ export abstract class DynamoNTS_AuthService extends DynamoNTS_SingletonService {
29
29
  static getTokenFromRequest(req: Request): string {
30
30
  const authHeader = req.headers['authorization'];
31
31
  if (!authHeader) {
32
- throw new DynamoNTS_Error({
32
+ throw new Dynamo_Error({
33
+ status: 401,
34
+ errorCode: 'NTS-AS0-GT0',
35
+ addECToUserMsg: true,
33
36
  message: 'AuthHeader missing!',
34
- userMessage: `We encountered a BackEnd Auth Error, please contact the responsible development team. errorcode: 007-636-500`,
37
+ userMessage: `We encountered an unhandled BackEnd Auth Error, please contact the responsible development team.`,
35
38
  });
36
39
  }
40
+
37
41
  const token = authHeader.split(' ')[1];
38
42
  if (!token) {
39
- throw new DynamoNTS_Error({
43
+ throw new Dynamo_Error({
44
+ status: 401,
45
+ errorCode: 'NTS-AS0-GT1',
46
+ addECToUserMsg: true,
40
47
  message: 'Token missing!',
41
- userMessage: `We encountered a BackEnd Auth Error, please contact the responsible development team. errorcode: 007-636-501`,
48
+ userMessage: `We encountered an unhandled BackEnd Auth Error, please contact the responsible development team.`,
42
49
  });
43
50
  }
51
+
44
52
  return token;
45
53
  }
46
54
 
@@ -5,7 +5,44 @@ import { DynamoNTS_Shared } from './dynamo-nts-shared.service';
5
5
  import { DynamoNTS_SingletonService } from './dynamo-nts-singleton.service';
6
6
 
7
7
  /**
8
+ * Basic controller for endpoint handlings
8
9
  *
10
+ * @example
11
+ * export class UserMatchStatisticsController extends DynamoNTS_Controller {
12
+ *
13
+ * static getInstance(): UserMatchStatisticsController {
14
+ * return UserMatchStatisticsController.getSingletonInstance();
15
+ * }
16
+ *
17
+ * // SERVICES
18
+ * private authService: AuthService;
19
+ *
20
+ * setupEndpoints(): void {
21
+ * this.authService = AuthService.getInstance();
22
+ *
23
+ * this.endpoints = [
24
+ * new DynamoNTS_EndpointParams({
25
+ * name: 'getUserMatchStatistics',
26
+ * type: HttpCallType.get,
27
+ * endpoint: '/get/user-match-statistics/:userId',
28
+ * preProcessess: [ this.authService.authenticateTokenSelf ],
29
+ * tasks: [
30
+ * async (req: Request, res: Response) => {
31
+ * const userMatchStatistics = new UserMatchStatisticsService({
32
+ * data: { userId: req.params.userId }
33
+ * });
34
+ *
35
+ * await userMatchStatistics.getDataByDependencyId();
36
+ *
37
+ * res.send(
38
+ * userMatchStatistics.data
39
+ * );
40
+ * }
41
+ * ]
42
+ * }),
43
+ * ];
44
+ * }
45
+ * }
9
46
  */
10
47
  export abstract class DynamoNTS_Controller extends DynamoNTS_SingletonService {
11
48