@futdevpro/nts-dynamo 1.5.34 → 1.5.36

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 (99) hide show
  1. package/lib/_constants/dynamo-nts-global.settings.d.ts.map +1 -1
  2. package/lib/_constants/dynamo-nts-global.settings.js +6 -1
  3. package/lib/_constants/dynamo-nts-global.settings.js.map +1 -1
  4. package/lib/_enums/dynamo-nts-socket-security.enum.d.ts +5 -0
  5. package/lib/_enums/dynamo-nts-socket-security.enum.d.ts.map +1 -0
  6. package/lib/_enums/dynamo-nts-socket-security.enum.js +9 -0
  7. package/lib/_enums/dynamo-nts-socket-security.enum.js.map +1 -0
  8. package/lib/_enums/http/socket-event.enum.d.ts +7 -0
  9. package/lib/_enums/http/socket-event.enum.d.ts.map +1 -0
  10. package/lib/_enums/http/socket-event.enum.js +11 -0
  11. package/lib/_enums/http/socket-event.enum.js.map +1 -0
  12. package/lib/_enums/index.d.ts +2 -0
  13. package/lib/_enums/index.d.ts.map +1 -1
  14. package/lib/_enums/index.js +2 -0
  15. package/lib/_enums/index.js.map +1 -1
  16. package/lib/_models/dynamo-nts-endpoint-params.js +1 -1
  17. package/lib/_models/dynamo-nts-endpoint-params.js.map +1 -1
  18. package/lib/_models/dynamo-nts-global-settings.d.ts +11 -1
  19. package/lib/_models/dynamo-nts-global-settings.d.ts.map +1 -1
  20. package/lib/_models/dynamo-nts-routing-module-settings.d.ts +11 -0
  21. package/lib/_models/dynamo-nts-routing-module-settings.d.ts.map +1 -0
  22. package/lib/_models/dynamo-nts-routing-module-settings.js +3 -0
  23. package/lib/_models/dynamo-nts-routing-module-settings.js.map +1 -0
  24. package/lib/_models/dynamo-nts-socket-event-params.d.ts +29 -0
  25. package/lib/_models/dynamo-nts-socket-event-params.d.ts.map +1 -0
  26. package/lib/_models/dynamo-nts-socket-event-params.js +79 -0
  27. package/lib/_models/dynamo-nts-socket-event-params.js.map +1 -0
  28. package/lib/_models/dynamo-nts-socket-module-settings.d.ts +19 -0
  29. package/lib/_models/dynamo-nts-socket-module-settings.d.ts.map +1 -0
  30. package/lib/_models/dynamo-nts-socket-module-settings.js +27 -0
  31. package/lib/_models/dynamo-nts-socket-module-settings.js.map +1 -0
  32. package/lib/_models/index.d.ts +3 -0
  33. package/lib/_models/index.d.ts.map +1 -1
  34. package/lib/_models/index.js +3 -0
  35. package/lib/_models/index.js.map +1 -1
  36. package/lib/_modules/app-extended.index.d.ts +12 -0
  37. package/lib/_modules/app-extended.index.d.ts.map +1 -0
  38. package/lib/_modules/app-extended.index.js +19 -0
  39. package/lib/_modules/app-extended.index.js.map +1 -0
  40. package/lib/_modules/app.index.d.ts +1 -1
  41. package/lib/_modules/app.index.d.ts.map +1 -1
  42. package/lib/_modules/app.index.js +1 -1
  43. package/lib/_modules/app.index.js.map +1 -1
  44. package/lib/_modules/test/get-test-routing-module.d.ts.map +1 -1
  45. package/lib/_modules/test/get-test-routing-module.js.map +1 -1
  46. package/lib/_modules/usage/get-usage-routing-module.d.ts.map +1 -1
  47. package/lib/_modules/usage/get-usage-routing-module.js.map +1 -1
  48. package/lib/_services/dynamo-nts-app-extended.d.ts +21 -8
  49. package/lib/_services/dynamo-nts-app-extended.d.ts.map +1 -1
  50. package/lib/_services/dynamo-nts-app-extended.js +92 -54
  51. package/lib/_services/dynamo-nts-app-extended.js.map +1 -1
  52. package/lib/_services/dynamo-nts-app.d.ts +34 -31
  53. package/lib/_services/dynamo-nts-app.d.ts.map +1 -1
  54. package/lib/_services/dynamo-nts-app.js +1 -0
  55. package/lib/_services/dynamo-nts-app.js.map +1 -1
  56. package/lib/_services/dynamo-nts-global.service.d.ts +15 -0
  57. package/lib/_services/dynamo-nts-global.service.d.ts.map +1 -1
  58. package/lib/_services/dynamo-nts-global.service.js +55 -3
  59. package/lib/_services/dynamo-nts-global.service.js.map +1 -1
  60. package/lib/_services/dynamo-nts-routing-module.service.d.ts +2 -7
  61. package/lib/_services/dynamo-nts-routing-module.service.d.ts.map +1 -1
  62. package/lib/_services/dynamo-nts-routing-module.service.js +1 -1
  63. package/lib/_services/dynamo-nts-routing-module.service.js.map +1 -1
  64. package/lib/_services/dynamo-nts-socket-service-collection.service.d.ts +10 -0
  65. package/lib/_services/dynamo-nts-socket-service-collection.service.d.ts.map +1 -0
  66. package/lib/_services/dynamo-nts-socket-service-collection.service.js +14 -0
  67. package/lib/_services/dynamo-nts-socket-service-collection.service.js.map +1 -0
  68. package/lib/_services/dynamo-nts-socket.service.d.ts +46 -0
  69. package/lib/_services/dynamo-nts-socket.service.d.ts.map +1 -0
  70. package/lib/_services/dynamo-nts-socket.service.js +148 -0
  71. package/lib/_services/dynamo-nts-socket.service.js.map +1 -0
  72. package/lib/_services/index.d.ts +2 -0
  73. package/lib/_services/index.d.ts.map +1 -1
  74. package/lib/_services/index.js +2 -0
  75. package/lib/_services/index.js.map +1 -1
  76. package/lib/tsconfig.tsbuildinfo +324 -134
  77. package/package.json +10 -1
  78. package/src/_constants/dynamo-nts-global.settings.ts +9 -1
  79. package/src/_enums/dynamo-nts-socket-security.enum.ts +5 -0
  80. package/src/_enums/http/socket-event.enum.ts +7 -0
  81. package/src/_enums/index.ts +2 -0
  82. package/src/_models/dynamo-nts-endpoint-params.ts +1 -1
  83. package/src/_models/dynamo-nts-global-settings.ts +14 -1
  84. package/src/_models/dynamo-nts-routing-module-settings.ts +11 -0
  85. package/src/_models/dynamo-nts-socket-event-params.ts +99 -0
  86. package/src/_models/dynamo-nts-socket-module-settings.ts +42 -0
  87. package/src/_models/index.ts +3 -0
  88. package/src/_modules/app-extended.index.ts +20 -0
  89. package/src/_modules/app.index.ts +1 -1
  90. package/src/_modules/test/get-test-routing-module.ts +2 -1
  91. package/src/_modules/usage/get-usage-routing-module.ts +2 -1
  92. package/src/_services/dynamo-nts-app-extended.ts +93 -78
  93. package/src/_services/dynamo-nts-app.ts +34 -31
  94. package/src/_services/dynamo-nts-global.service.ts +57 -3
  95. package/src/_services/dynamo-nts-routing-module.service.ts +2 -7
  96. package/src/_services/dynamo-nts-socket-service-collection.service.ts +16 -0
  97. package/src/_services/dynamo-nts-socket.service.ts +183 -0
  98. package/src/_services/index.ts +2 -0
  99. package/src/_models/dynamo-module-settings.ts +0 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@futdevpro/nts-dynamo",
3
- "version": "01.05.34",
3
+ "version": "01.05.36",
4
4
  "description": "Dynamic NodeTS (NodeJS-Typescript), MongoDB Backend System Framework by Future Development Ltd.",
5
5
  "scripts": {
6
6
  "build": "npx tsc",
@@ -59,6 +59,12 @@
59
59
  "types": "./lib/_modules/app.index.d.ts",
60
60
  "typings": "./lib/_modules/app.index.d.ts"
61
61
  },
62
+ "./app-extended": {
63
+ "default": "./lib/_modules/app-extended.index.js",
64
+ "module": "./lib/_modules/app-extended.index.js",
65
+ "types": "./lib/_modules/app-extended.index.d.ts",
66
+ "typings": "./lib/_modules/app-extended.index.d.ts"
67
+ },
62
68
  "./auth": {
63
69
  "default": "./lib/_modules/auth.index.js",
64
70
  "module": "./lib/_modules/auth.index.js",
@@ -119,6 +125,9 @@
119
125
  "app": [
120
126
  "lib/_modules/app.index.d.ts"
121
127
  ],
128
+ "app-extended": [
129
+ "lib/_modules/app-extended.index.d.ts"
130
+ ],
122
131
  "auth": [
123
132
  "lib/_modules/auth.index.d.ts"
124
133
  ],
@@ -1,12 +1,20 @@
1
1
 
2
2
  import { DynamoNTS_RouteSecurity } from '../_enums/dynamo-nts-route-security.enum';
3
+ import { DynamoNTS_SocketSecurity } from '../_enums/dynamo-nts-socket-security.enum';
3
4
  import { DynamoNTS_GlobalSettings } from '../_models/dynamo-nts-global-settings';
4
5
 
5
6
  export const dynamoNTS_GlobalSettings: DynamoNTS_GlobalSettings = {
6
7
  baseUrl: '/api',
7
8
  defaultRouteSecurity: DynamoNTS_RouteSecurity.open,
9
+ defaultSocketSecurity: DynamoNTS_SocketSecurity.open,
10
+
8
11
  logSetup: false,
9
- logRequests: true,
12
+
13
+ logRequest: true,
10
14
  logRequestsContent: true,
11
15
  logResponseContent: false,
16
+
17
+ logMainSocketEvent: true,
18
+ logAllSocketEvent: false,
19
+ logEventContent: false,
12
20
  };
@@ -0,0 +1,5 @@
1
+
2
+ export enum DynamoNTS_SocketSecurity {
3
+ open = 'open',
4
+ secure = 'secure',
5
+ }
@@ -0,0 +1,7 @@
1
+
2
+ export enum DynamoNTS_SocketEvent {
3
+ connection = 'connection',
4
+ subscribe = 'subscribe',
5
+ event = 'event',
6
+ disconnect = 'disconnection'
7
+ }
@@ -4,8 +4,10 @@
4
4
  export * from './data-model-type.enum';
5
5
  export * from './dynamo-nts-data-service-function.enum';
6
6
  export * from './dynamo-nts-route-security.enum';
7
+ export * from './dynamo-nts-socket-security.enum';
7
8
  export * from './predefined-data-types.enum';
8
9
  // HTTP ENUMS
9
10
  export * from './http/http-call-type.enum';
10
11
  export * from './http/http-response-type.enum';
12
+ export * from './http/socket-event.enum';
11
13
 
@@ -58,7 +58,7 @@ export class DynamoNTS_EndpointParams{
58
58
  this.preProcessess = set.preProcessess ? set.preProcessess : [];
59
59
  this.tasks = set.tasks;
60
60
 
61
- this.logRequest = set.logRequest !== undefined ? set.logRequest : dynamoNTS_GlobalSettings.logRequests;
61
+ this.logRequest = set.logRequest !== undefined ? set.logRequest : dynamoNTS_GlobalSettings.logRequest;
62
62
  this.logRequestsContent = set.logRequestsContent !== undefined ? set.logRequestsContent : dynamoNTS_GlobalSettings.logRequestsContent;
63
63
  this.logResponseContent = set.logResponseContent !== undefined ? set.logResponseContent : dynamoNTS_GlobalSettings.logResponseContent;
64
64
 
@@ -1,13 +1,26 @@
1
1
  import { DynamoNTS_RouteSecurity } from '../_enums/dynamo-nts-route-security.enum';
2
+ import { DynamoNTS_SocketSecurity } from '../_enums/dynamo-nts-socket-security.enum';
2
3
 
3
4
  /**
5
+ *
6
+ *
7
+ * @param logRequestsContent only will log if the specific logRequest is also true
8
+ *
9
+ * @param logEventContent only will log if the specific socket event is also set to log
4
10
  *
5
11
  */
6
12
  export interface DynamoNTS_GlobalSettings {
7
13
  baseUrl: string;
8
14
  defaultRouteSecurity: DynamoNTS_RouteSecurity;
15
+ defaultSocketSecurity: DynamoNTS_SocketSecurity;
16
+
9
17
  logSetup?: boolean;
10
- logRequests?: boolean;
18
+
19
+ logRequest?: boolean;
11
20
  logRequestsContent?: boolean;
12
21
  logResponseContent?: boolean;
22
+
23
+ logMainSocketEvent?: boolean;
24
+ logAllSocketEvent?: boolean;
25
+ logEventContent?: boolean;
13
26
  }
@@ -0,0 +1,11 @@
1
+ import { DynamoNTS_RouteSecurity } from '../_enums';
2
+ import { DynamoNTS_Controller } from '../_services';
3
+
4
+ /**
5
+ *
6
+ */
7
+ export interface DynamoNTS_RoutingModuleSettings {
8
+ route: string;
9
+ controllers: DynamoNTS_Controller[];
10
+ securityOverride?: DynamoNTS_RouteSecurity;
11
+ }
@@ -0,0 +1,99 @@
1
+
2
+
3
+ import { DynamoNTS_Shared } from '../_services/dynamo-nts-shared.service';
4
+ import { dynamoNTS_GlobalSettings } from '../_constants';
5
+ import { DynamoNTS_SocketEvent } from '../_enums/http/socket-event.enum';
6
+
7
+ /**
8
+ *
9
+ */
10
+ export class DynamoNTS_SocketEventParams<T>{
11
+ event: DynamoNTS_SocketEvent | string;
12
+
13
+ preProcessess?: ((content?: T) => Promise<T>)[];
14
+ tasks: ((content?: T, issuer?: string) => Promise<void>)[];
15
+
16
+ logEvent: boolean;
17
+ logEventContent: boolean;
18
+
19
+ constructor(
20
+ set: {
21
+ event: DynamoNTS_SocketEvent | string,
22
+
23
+ preProcessess?: ((content?: T) => Promise<T>)[],
24
+ tasks: ((content?: T, issuer?: string) => Promise<void>)[],
25
+
26
+ logEvent?: boolean,
27
+ logEventContent?: boolean,
28
+ }
29
+ ) {
30
+ try {
31
+ this.event = set.event;
32
+
33
+ this.preProcessess = set.preProcessess ? set.preProcessess : [];
34
+ this.tasks = set.tasks;
35
+
36
+ if (set.logEvent !== undefined) {
37
+ this.logEvent = set.logEvent;
38
+ } else if (this.event === DynamoNTS_SocketEvent.connection || this.event === DynamoNTS_SocketEvent.disconnect) {
39
+ this.logEvent = dynamoNTS_GlobalSettings.logMainSocketEvent;
40
+ } else {
41
+ this.logEvent = dynamoNTS_GlobalSettings.logAllSocketEvent;
42
+ }
43
+ this.logEventContent = set.logEventContent !== undefined ? set.logEventContent : dynamoNTS_GlobalSettings.logEventContent;
44
+
45
+ if (this.logEvent) {
46
+ this.preProcessess.unshift(this.getPreLog());
47
+ }
48
+ } catch (error) {
49
+ DynamoNTS_Shared.logError(
50
+ `\nSocket Event params setup failed: ${set.event}`, error);
51
+ throw error;
52
+ }
53
+ }
54
+
55
+ /**
56
+ *
57
+ * @returns
58
+ */
59
+ getPreLog(): (content: T) => Promise<T> {
60
+ return async (content: T) => {
61
+ try {
62
+ if (this.logEvent) {
63
+ if (this.logEventContent) {
64
+ console.log(`==> incoming ${this.event} socket event... content:`, content);
65
+ } else {
66
+ console.log(`==> incoming ${this.event} socket event...`);
67
+ }
68
+ }
69
+ return content;
70
+ } catch (error) {
71
+ console.error('PreLog failed....', error);
72
+ }
73
+ };
74
+ }
75
+
76
+ /**
77
+ *
78
+ * @returns
79
+ */
80
+ getFullExecution(issuer?: string): (content?: T) => Promise<void> {
81
+ return async (content?: T) => {
82
+ try {
83
+ for (let i = 0; i < this.preProcessess.length; i++) {
84
+ content = await this.preProcessess[i](content);
85
+ }
86
+
87
+ for (let i = 0; i < this.tasks.length; i++) {
88
+ await this.tasks[i](content, issuer);
89
+ }
90
+ } catch (error) {
91
+ console.error(`Socket Event tasks failed to execute.... (${this.event})`, error, 'content:', content);
92
+ }
93
+ };
94
+ }
95
+ }
96
+
97
+
98
+
99
+
@@ -0,0 +1,42 @@
1
+
2
+ import { dynamoNTS_GlobalSettings } from '../_constants';
3
+ import { DynamoNTS_SocketSecurity } from '../_enums/dynamo-nts-socket-security.enum';
4
+ import { DynamoNTS_Shared } from '../_services';
5
+
6
+ /**
7
+ *
8
+ */
9
+ export class DynamoNTS_SocketServiceSettings {
10
+ name: string;
11
+ port: number;
12
+ security?: DynamoNTS_SocketSecurity;
13
+ groupActiveSocketsBy?: string;
14
+
15
+ getIdFromSubscrioption?: (content: any) => string;
16
+
17
+ constructor(
18
+ set: {
19
+ name: string,
20
+ port: number,
21
+ security?: DynamoNTS_SocketSecurity,
22
+ groupActiveSocketsBy?: string,
23
+
24
+ getIdFromSubscrioption?: (content: any) => string,
25
+ }
26
+ ) {
27
+ this.name = set.name;
28
+ this.port = set.port;
29
+ this.security = set.security ? set.security : dynamoNTS_GlobalSettings.defaultSocketSecurity;
30
+
31
+ if (set.getIdFromSubscrioption) {
32
+ this.getIdFromSubscrioption = set.getIdFromSubscrioption;
33
+ if (set.groupActiveSocketsBy) {
34
+ DynamoNTS_Shared.logError(
35
+ `setting groupActiveSocketsBy on DynamoNTS_SocketService (${this.name}) won't take effect, ` +
36
+ `since getIdFromSubscrioption is also setted, so it will be used instead`)
37
+ }
38
+ } else if (set.groupActiveSocketsBy) {
39
+ this.getIdFromSubscrioption = content => content[set.groupActiveSocketsBy];
40
+ }
41
+ }
42
+ }
@@ -5,4 +5,7 @@ export * from './dynamo-nts-api-call-params';
5
5
  export * from './dynamo-nts-app-params';
6
6
  export * from './dynamo-nts-endpoint-params';
7
7
  export * from './dynamo-nts-global-settings';
8
+ export * from './dynamo-nts-routing-module-settings';
9
+ export * from './dynamo-nts-socket-event-params';
10
+ export * from './dynamo-nts-socket-module-settings';
8
11
 
@@ -0,0 +1,20 @@
1
+
2
+ // SERVICES
3
+ export * from '../_services/dynamo-nts-app';
4
+ export * from '../_services/dynamo-nts-app-extended';
5
+ export * from '../_services/dynamo-nts-global.service';
6
+ export * from '../_services/dynamo-nts-routing-module.service';
7
+ export * from '../_services/dynamo-nts-shared.service';
8
+
9
+ // MODELS
10
+ export * from '../_models/dynamo-nts-app-params';
11
+ export * from '../_models/dynamo-nts-endpoint-params';
12
+ export * from '../_models/dynamo-nts-global-settings';
13
+ export * from '../_models/dynamo-nts-routing-module-settings';
14
+
15
+ // ENUMS
16
+ export * from '../_enums/dynamo-nts-route-security.enum';
17
+
18
+ // CONSTANTS
19
+ export * from '../_constants/dynamo-nts-global.settings';
20
+
@@ -1,7 +1,6 @@
1
1
 
2
2
  // SERVICES
3
3
  export * from '../_services/dynamo-nts-app';
4
- export * from '../_services/dynamo-nts-app-extended';
5
4
  export * from '../_services/dynamo-nts-global.service';
6
5
  export * from '../_services/dynamo-nts-routing-module.service';
7
6
  export * from '../_services/dynamo-nts-shared.service';
@@ -10,6 +9,7 @@ export * from '../_services/dynamo-nts-shared.service';
10
9
  export * from '../_models/dynamo-nts-app-params';
11
10
  export * from '../_models/dynamo-nts-endpoint-params';
12
11
  export * from '../_models/dynamo-nts-global-settings';
12
+ export * from '../_models/dynamo-nts-routing-module-settings';
13
13
 
14
14
  // ENUMS
15
15
  export * from '../_enums/dynamo-nts-route-security.enum';
@@ -1,7 +1,8 @@
1
1
 
2
2
  import { testModuleSettings } from '@futdevpro/fsm-dynamo/test-module';
3
3
  import { DynamoNTS_RouteSecurity } from '../../_enums/dynamo-nts-route-security.enum';
4
- import { DynamoNTS_RoutingModule, DynamoNTS_RoutingModuleSettings } from '../../_services/dynamo-nts-routing-module.service';
4
+ import { DynamoNTS_RoutingModuleSettings } from '../../_models/dynamo-nts-routing-module-settings';
5
+ import { DynamoNTS_RoutingModule } from '../../_services/dynamo-nts-routing-module.service';
5
6
  import { TestController } from './test-controller';
6
7
 
7
8
  export function getTestRoutingModule(securityOverride?: DynamoNTS_RouteSecurity): DynamoNTS_RoutingModule {
@@ -1,7 +1,8 @@
1
1
 
2
2
  import { usageModuleSettings } from '@futdevpro/fsm-dynamo/usage-module';
3
3
  import { DynamoNTS_RouteSecurity } from '../../_enums/dynamo-nts-route-security.enum';
4
- import { DynamoNTS_RoutingModule, DynamoNTS_RoutingModuleSettings } from '../../_services/dynamo-nts-routing-module.service';
4
+ import { DynamoNTS_RoutingModuleSettings } from '../../_models/dynamo-nts-routing-module-settings';
5
+ import { DynamoNTS_RoutingModule } from '../../_services/dynamo-nts-routing-module.service';
5
6
  import { UsageController } from './usage-controller';
6
7
 
7
8
  export function getUsageRoutingModule(securityOverride?: DynamoNTS_RouteSecurity): DynamoNTS_RoutingModule {
@@ -5,11 +5,8 @@ import * as Http from 'http';
5
5
  import { DynamoNTS_Shared } from './dynamo-nts-shared.service';
6
6
  import { DynamoNTS_RouteSecurity } from '../_enums/dynamo-nts-route-security.enum';
7
7
  import { DynamoNTS_App } from './dynamo-nts-app';
8
-
9
- export class DynamoBESocketModule { // NEW
10
- security:DynamoNTS_RouteSecurity;
11
- port:number
12
- }
8
+ import { DynamoNTS_SocketService } from './dynamo-nts-socket.service';
9
+ import { DynamoNTS_SocketSecurity } from '../_enums/dynamo-nts-socket-security.enum';
13
10
 
14
11
  /**
15
12
  * This will be the main service of our server project,
@@ -17,23 +14,36 @@ export class DynamoBESocketModule { // NEW
17
14
  *
18
15
  * In this service, there are abstract functions that you will need to implement,
19
16
  * where you need to set up the main params for your application.
17
+ *
18
+ * The extended App is containing socket server tools
19
+ *
20
+ * You need to add socketService definitions to setupRoutingModules
21
+ *
22
+ * @example
23
+ * ...
24
+ * this.socketServices = [
25
+ * NotificationService.getInstance(),
26
+ * ChatService.getInstance(),
27
+ * ...
28
+ * ];
29
+ * ...
20
30
  */
21
31
  export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
32
+
33
+ private socketSecurity: DynamoNTS_RouteSecurity;
22
34
 
23
- private openSocketServer: SocketIO.Server;
24
- /* private secureSocketServer: SocketIO.Server; */
25
-
26
- protected socketModules: DynamoBESocketModule[];
35
+ protected socketServices: DynamoNTS_SocketService[] = [];
27
36
 
28
37
  constructor(){
29
38
  super();
30
39
 
31
40
  try {
41
+ if (0 < this.socketServices.length) {
42
+ this.setSocketSecurity();
32
43
 
33
- if (0 < this.socketModules.length) { // NEW
34
- if (this.security !== DynamoNTS_RouteSecurity.secure) {
35
- this.initOpenSocketPorts();
36
- }
44
+ this.setupSocketServices();
45
+
46
+ if (this.log) console.log(`\nAll sockets setted up.... sockets using security: ${this.socketSecurity}`);
37
47
  }
38
48
  } catch (error) {
39
49
  DynamoNTS_Shared.logError('\nExtended Application start failed.\n', error);
@@ -43,81 +53,86 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
43
53
  /**
44
54
  *
45
55
  */
46
- private initOpenSocketPorts(): void { // NEW NEED SECURE AS WELL
47
- const httpSocketServer: Http.Server = Http.createServer(this.openExpress);
48
- this.openSocketServer = new SocketIO.Server(httpSocketServer);
49
-
50
- this.socketModules.forEach((module: DynamoBESocketModule) => {
51
- if (module.security !== DynamoNTS_RouteSecurity.secure) {
52
- if (this.log) console.log(`socket mount (open): ${module.port}`);
53
-
54
-
55
-
56
-
57
- const existingPorts: DynamoBESocketModule[] = this.socketModules.filter(
58
- (mod: DynamoBESocketModule) => mod.port === module.port);
56
+ private setSocketSecurity(): void {
57
+ console.log('setSecurityExtended');
58
+ this.socketServices.forEach((service: DynamoNTS_SocketService) => {
59
+ if (!this.socketSecurity) {
60
+ this.socketSecurity = DynamoNTS_RouteSecurity[service.security];
61
+ } else if (this.socketSecurity !== DynamoNTS_RouteSecurity.both && this.socketSecurity !== DynamoNTS_RouteSecurity[service.security]) {
62
+ this.socketSecurity = DynamoNTS_RouteSecurity.both;
63
+ }
64
+ });
65
+ }
59
66
 
60
- if (1 < existingPorts.length || this.httpPort === module.port || this.httpsPort === module.port) {
61
- let error = new Error(`PORT DUPLICATION: ${module.port}`);
67
+ /**
68
+ *
69
+ */
70
+ private setupSocketServices(): void {
71
+ let httpSocketServer: Http.Server;
72
+ if (this.socketSecurity !== DynamoNTS_RouteSecurity.secure) {
73
+ if (!this.openExpress) {
74
+ this.initOpenExpress();
75
+ }
76
+ httpSocketServer = Http.createServer(this.openExpress);
77
+ }
78
+ if (this.socketSecurity !== DynamoNTS_RouteSecurity.open) {
79
+ if (!this.httpsServer) {
80
+ if (this.cert) {
81
+ this.initSecureExpress();
82
+ } else {
83
+ let errorMsg: string =
84
+ `\nYou have secure socket service, but the certification paths are not set!` +
85
+ `\nset...` +
86
+ `\n cert: {` +
87
+ `\n keyPath: FileSystem.PathLike,` +
88
+ `\n certPath: FileSystem.PathLike,` +
89
+ `\n }` +
90
+ `\nin DynamoBEServer - setupRoutingModules() to enable secure routes.`;
91
+
92
+ errorMsg += '\n\nThe socket services setted to use secure server:';
93
+ this.socketServices.forEach((service: DynamoNTS_SocketService) => {
94
+ if (service.security != DynamoNTS_SocketSecurity.open) {
95
+ errorMsg += `\n ${service.name} (port: ${service.port})`;
96
+ }
97
+ });
98
+ DynamoNTS_Shared.logError(errorMsg);
99
+
100
+ let error = new Error('Secure routes cannot be established!');
62
101
  let errorStack: string[] = error.stack.split('\n');
63
- errorStack.splice(1, 4);
102
+ errorStack.splice(1, 2);
64
103
  error.stack = errorStack.join('\n');
65
104
 
66
105
  throw error;
67
106
  }
107
+ }
108
+ }
68
109
 
69
-
70
- const highlight = '\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' +
71
- '\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' +
72
- '\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' +
73
- '\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!';
74
-
75
- this.openSocketServer.on('disconnect', (socket) => {
76
- console.log(highlight, `\nnew DISCONNECT ALFA: \n\n`, socket);
77
- })
78
-
79
- this.openSocketServer.on('new message', (msg) => {
80
- console.log(highlight, `\nnew MESSAGE ALFA: \n\n`, msg);
81
- })
82
-
83
- this.openSocketServer.on('connection', (socket) => {
84
- console.log(highlight, `\nnew CONNECTION: \n\n`, socket);
85
-
86
- socket.on('disconnect', (socket) => {
87
- console.log(highlight, `\nnew DISCONNECT BETA: \n\n`, socket);
88
- });
89
-
90
- socket.on('new message', (msg) => {
91
- console.log(highlight, `\nnew MESSAGE BETA: \n\n`, msg);
92
- });
93
- })
94
-
95
-
96
-
97
- this.openSocketServer.listen(module.port);
98
-
110
+ this.socketServices.forEach((service: DynamoNTS_SocketService) => {
111
+ const existingPorts: DynamoNTS_SocketService[] = this.socketServices.filter(
112
+ (mod: DynamoNTS_SocketService) => mod.port === service.port);
99
113
 
114
+ if (1 < existingPorts.length || this.httpPort === service.port || this.httpsPort === service.port) {
115
+ let error = new Error(`PORT DUPLICATION: ${service.port}`);
116
+ let errorStack: string[] = error.stack.split('\n');
117
+ errorStack.splice(1, 4);
118
+ error.stack = errorStack.join('\n');
100
119
 
101
- this.openSocketServer.on('disconnect', (socket) => {
102
- console.log(highlight, `\nnew DISCONNECT ALFA: \n\n`, socket);
103
- })
104
-
105
- this.openSocketServer.on('new message', (msg) => {
106
- console.log(highlight, `\nnew MESSAGE ALFA: \n\n`, msg);
107
- })
108
-
109
- this.openSocketServer.on('connection', (socket) => {
110
- console.log(highlight, `\nnew CONNECTION: \n\n`, socket);
111
-
112
- socket.on('disconnect', (socket) => {
113
- console.log(highlight, `\nnew DISCONNECT BETA: \n\n`, socket);
114
- });
115
-
116
- socket.on('new message', (msg) => {
117
- console.log(highlight, `\nnew MESSAGE BETA: \n\n`, msg);
118
- });
119
- })
120
+ throw error;
121
+ }
120
122
 
123
+ if (service.security === DynamoNTS_SocketSecurity.open) {
124
+ if (this.log) console.log(`\nsocket setup (open): ${service.name}:${service.port}`);
125
+ service.setupSocketServer(new SocketIO.Server(httpSocketServer));
126
+ } else if (service.security === DynamoNTS_SocketSecurity.secure) {
127
+ if (this.log) console.log(`\nsocket setup (secure): ${service.name}:${service.port}`);
128
+ service.setupSocketServer(new SocketIO.Server(this.httpsServer));
129
+ } else {
130
+ let error = new Error(`INVALID Socket Service security: ${service.security} on ${service.name}`);
131
+ let errorStack: string[] = error.stack.split('\n');
132
+ errorStack.splice(1, 4);
133
+ error.stack = errorStack.join('\n');
134
+
135
+ throw error;
121
136
  }
122
137
  });
123
138
  }
@@ -36,9 +36,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
36
36
  certPath: FileSystem.PathLike,
37
37
  };
38
38
 
39
- private secureExpress: Express.Application;
40
- private httpsServer: Https.Server;
41
39
  protected openExpress: Express.Application;
40
+ private secureExpress: Express.Application;
41
+ protected httpsServer: Https.Server;
42
42
 
43
43
  protected routingModules: DynamoNTS_RoutingModule[];
44
44
 
@@ -175,7 +175,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
175
175
  /**
176
176
  *
177
177
  */
178
- private initOpenExpress(): void {
178
+ protected initOpenExpress(): void {
179
179
  this.openExpress = Express();
180
180
  this.openExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
181
181
  this.openExpress.use(BodyParser.json({ limit: '50mb' }));
@@ -184,7 +184,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
184
184
  /**
185
185
  *
186
186
  */
187
- private initSecureExpress(): void {
187
+ protected initSecureExpress(): void {
188
188
  this.secureExpress = Express();
189
189
  this.secureExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
190
190
  this.secureExpress.use(BodyParser.json({ limit: '50mb' }));
@@ -278,7 +278,8 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
278
278
  /**
279
279
  *
280
280
  */
281
- private setSecurity(): void {
281
+ protected setSecurity(): void {
282
+ console.log('setSecurity');
282
283
  this.routingModules.forEach((module: DynamoNTS_RoutingModule) => {
283
284
  if (!this.security) {
284
285
  this.security = module.security;
@@ -327,32 +328,34 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
327
328
  * You must setup endpoints and required services in this function
328
329
  *
329
330
  * @example
330
- * this.httpPort = env.httpPort;
331
- * this.httpsPort = env.httpsPort;
332
-
333
- * this.cert = {
334
- * keyPath: Path.join(__dirname, './_assets/cert/ucc.key'),
335
- * certPath: Path.join(__dirname, './_assets/cert/ucc.crt'),
336
- * };
337
-
338
- * this.routingModules = [
339
- * new DynamoBERountingModule({
340
- * route: '/api/account',
341
- * controllers: [
342
- * AccountController.getInstance(),
343
- * PersonalInformationController.getInstance(),
344
- * ...
345
- * ]
346
- * }),
347
- * new DynamoBERountingModule({
348
- * route: '/api/project',
349
- * controllers: [
350
- * ProjectController.getInstance(),
351
- * ProjectExtensionController.getInstance(),
352
- * ]
353
- * }),
354
- * ...
355
- * ];
331
+ * setupRoutingModules(): void {
332
+ * this.httpPort = env.httpPort;
333
+ * this.httpsPort = env.httpsPort;
334
+ *
335
+ * this.cert = {
336
+ * keyPath: Path.join(__dirname, './_assets/cert/ucc.key'),
337
+ * certPath: Path.join(__dirname, './_assets/cert/ucc.crt'),
338
+ * };
339
+ *
340
+ * this.routingModules = [
341
+ * new DynamoBERountingModule({
342
+ * route: '/api/account',
343
+ * controllers: [
344
+ * AccountController.getInstance(),
345
+ * PersonalInformationController.getInstance(),
346
+ * ...
347
+ * ]
348
+ * }),
349
+ * new DynamoBERountingModule({
350
+ * route: '/api/project',
351
+ * controllers: [
352
+ * ProjectController.getInstance(),
353
+ * ProjectExtensionController.getInstance(),
354
+ * ]
355
+ * }),
356
+ * ...
357
+ * ];
358
+ * }
356
359
  */
357
360
  abstract setupRoutingModules(): void;
358
361
  }