@futdevpro/nts-dynamo 1.3.58 → 1.3.60

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 (205) hide show
  1. package/package.json +19 -19
  2. package/src/_models/dynamobe-endpoint-control.ts +39 -30
  3. package/src/_models/fullstack-models/control-models/dynamobe-data-params.ts +19 -0
  4. package/src/_models/fullstack-models/control-models/dynamobe-data-property-params.ts +2 -2
  5. package/src/_models/fullstack-models/data-models/custom-data.ts +8 -4
  6. package/src/_models/fullstack-models/data-models/usage-session.ts +19 -16
  7. package/src/_models/index.ts +1 -0
  8. package/src/_modules/test-route/custom-data.service.ts +0 -2
  9. package/src/_modules/usage-route/usage.service.ts +0 -3
  10. package/src/_services/dynamobe-app.ts +280 -0
  11. package/src/_services/dynamobe-auth.service.ts +16 -1
  12. package/src/_services/dynamobe-controller.service.ts +6 -1
  13. package/src/_services/dynamobe-data.service.ts +7 -9
  14. package/src/_services/dynamobe-db-service-collection.service.ts +1 -1
  15. package/src/_services/dynamobe-db.service.ts +44 -44
  16. package/src/_services/dynamobe-email-service-collection.service.ts +13 -0
  17. package/src/_services/dynamobe-email.service.ts +1 -1
  18. package/src/_services/dynamobe-global-collection.service.ts +57 -0
  19. package/src/_services/dynamobe-global.service.ts +50 -5
  20. package/src/_services/dynamobe-routing-module.service.ts +10 -6
  21. package/src/_services/dynamobe-server.ts +16 -12
  22. package/src/dynamobe-global.settings.ts +10 -0
  23. package/src/sync.ffs_db +0 -0
  24. package/src/version.json +1 -1
  25. package/lib/_constants/dynamobe-global.settings.d.ts +0 -3
  26. package/lib/_constants/dynamobe-global.settings.d.ts.map +0 -1
  27. package/lib/_constants/dynamobe-global.settings.js +0 -12
  28. package/lib/_constants/dynamobe-global.settings.js.map +0 -1
  29. package/lib/_enums/data-model-type.enum.d.ts +0 -6
  30. package/lib/_enums/data-model-type.enum.d.ts.map +0 -1
  31. package/lib/_enums/data-model-type.enum.js +0 -10
  32. package/lib/_enums/data-model-type.enum.js.map +0 -1
  33. package/lib/_enums/dynamobe-data-service-function.enum.d.ts +0 -8
  34. package/lib/_enums/dynamobe-data-service-function.enum.d.ts.map +0 -1
  35. package/lib/_enums/dynamobe-data-service-function.enum.js +0 -15
  36. package/lib/_enums/dynamobe-data-service-function.enum.js.map +0 -1
  37. package/lib/_enums/dynamobe-route-security.enum.d.ts +0 -6
  38. package/lib/_enums/dynamobe-route-security.enum.d.ts.map +0 -1
  39. package/lib/_enums/dynamobe-route-security.enum.js +0 -10
  40. package/lib/_enums/dynamobe-route-security.enum.js.map +0 -1
  41. package/lib/_enums/http/http-call-type.enum.d.ts +0 -8
  42. package/lib/_enums/http/http-call-type.enum.d.ts.map +0 -1
  43. package/lib/_enums/http/http-call-type.enum.js +0 -12
  44. package/lib/_enums/http/http-call-type.enum.js.map +0 -1
  45. package/lib/_enums/http/http-response-type.enum.d.ts +0 -7
  46. package/lib/_enums/http/http-response-type.enum.d.ts.map +0 -1
  47. package/lib/_enums/http/http-response-type.enum.js +0 -11
  48. package/lib/_enums/http/http-response-type.enum.js.map +0 -1
  49. package/lib/_enums/index.d.ts +0 -8
  50. package/lib/_enums/index.d.ts.map +0 -1
  51. package/lib/_enums/index.js +0 -39
  52. package/lib/_enums/index.js.map +0 -1
  53. package/lib/_enums/log-style.enum.d.ts +0 -26
  54. package/lib/_enums/log-style.enum.d.ts.map +0 -1
  55. package/lib/_enums/log-style.enum.js +0 -30
  56. package/lib/_enums/log-style.enum.js.map +0 -1
  57. package/lib/_enums/predefined-data-types.enum.d.ts +0 -8
  58. package/lib/_enums/predefined-data-types.enum.d.ts.map +0 -1
  59. package/lib/_enums/predefined-data-types.enum.js +0 -12
  60. package/lib/_enums/predefined-data-types.enum.js.map +0 -1
  61. package/lib/_models/dynamobe-api-call-params.d.ts +0 -35
  62. package/lib/_models/dynamobe-api-call-params.d.ts.map +0 -1
  63. package/lib/_models/dynamobe-api-call-params.js +0 -24
  64. package/lib/_models/dynamobe-api-call-params.js.map +0 -1
  65. package/lib/_models/dynamobe-app-params.d.ts +0 -15
  66. package/lib/_models/dynamobe-app-params.d.ts.map +0 -1
  67. package/lib/_models/dynamobe-app-params.js +0 -14
  68. package/lib/_models/dynamobe-app-params.js.map +0 -1
  69. package/lib/_models/dynamobe-data-model-params.d.ts +0 -13
  70. package/lib/_models/dynamobe-data-model-params.d.ts.map +0 -1
  71. package/lib/_models/dynamobe-data-model-params.js +0 -15
  72. package/lib/_models/dynamobe-data-model-params.js.map +0 -1
  73. package/lib/_models/dynamobe-endpoint-control.d.ts +0 -29
  74. package/lib/_models/dynamobe-endpoint-control.d.ts.map +0 -1
  75. package/lib/_models/dynamobe-endpoint-control.js +0 -86
  76. package/lib/_models/dynamobe-endpoint-control.js.map +0 -1
  77. package/lib/_models/dynamobe-global-settings.d.ts +0 -9
  78. package/lib/_models/dynamobe-global-settings.d.ts.map +0 -1
  79. package/lib/_models/dynamobe-global-settings.js +0 -3
  80. package/lib/_models/dynamobe-global-settings.js.map +0 -1
  81. package/lib/_models/fullstack-models/control-models/daily-usage-data.d.ts +0 -18
  82. package/lib/_models/fullstack-models/control-models/daily-usage-data.d.ts.map +0 -1
  83. package/lib/_models/fullstack-models/control-models/daily-usage-data.js +0 -22
  84. package/lib/_models/fullstack-models/control-models/daily-usage-data.js.map +0 -1
  85. package/lib/_models/fullstack-models/control-models/dynamobe-data-property-params.d.ts +0 -28
  86. package/lib/_models/fullstack-models/control-models/dynamobe-data-property-params.d.ts.map +0 -1
  87. package/lib/_models/fullstack-models/control-models/dynamobe-data-property-params.js +0 -67
  88. package/lib/_models/fullstack-models/control-models/dynamobe-data-property-params.js.map +0 -1
  89. package/lib/_models/fullstack-models/control-models/dynamobe-error.d.ts +0 -18
  90. package/lib/_models/fullstack-models/control-models/dynamobe-error.d.ts.map +0 -1
  91. package/lib/_models/fullstack-models/control-models/dynamobe-error.js +0 -188
  92. package/lib/_models/fullstack-models/control-models/dynamobe-error.js.map +0 -1
  93. package/lib/_models/fullstack-models/control-models/geo-ip-location.d.ts +0 -26
  94. package/lib/_models/fullstack-models/control-models/geo-ip-location.d.ts.map +0 -1
  95. package/lib/_models/fullstack-models/control-models/geo-ip-location.js +0 -3
  96. package/lib/_models/fullstack-models/control-models/geo-ip-location.js.map +0 -1
  97. package/lib/_models/fullstack-models/control-models/usage-action.d.ts +0 -9
  98. package/lib/_models/fullstack-models/control-models/usage-action.d.ts.map +0 -1
  99. package/lib/_models/fullstack-models/control-models/usage-action.js +0 -13
  100. package/lib/_models/fullstack-models/control-models/usage-action.js.map +0 -1
  101. package/lib/_models/fullstack-models/control-models/usage-data.d.ts +0 -14
  102. package/lib/_models/fullstack-models/control-models/usage-data.d.ts.map +0 -1
  103. package/lib/_models/fullstack-models/control-models/usage-data.js +0 -16
  104. package/lib/_models/fullstack-models/control-models/usage-data.js.map +0 -1
  105. package/lib/_models/fullstack-models/data-models/custom-data.d.ts +0 -16
  106. package/lib/_models/fullstack-models/data-models/custom-data.d.ts.map +0 -1
  107. package/lib/_models/fullstack-models/data-models/custom-data.js +0 -24
  108. package/lib/_models/fullstack-models/data-models/custom-data.js.map +0 -1
  109. package/lib/_models/fullstack-models/data-models/metadata.d.ts +0 -17
  110. package/lib/_models/fullstack-models/data-models/metadata.d.ts.map +0 -1
  111. package/lib/_models/fullstack-models/data-models/metadata.js +0 -17
  112. package/lib/_models/fullstack-models/data-models/metadata.js.map +0 -1
  113. package/lib/_models/fullstack-models/data-models/usage-session.d.ts +0 -34
  114. package/lib/_models/fullstack-models/data-models/usage-session.d.ts.map +0 -1
  115. package/lib/_models/fullstack-models/data-models/usage-session.js +0 -49
  116. package/lib/_models/fullstack-models/data-models/usage-session.js.map +0 -1
  117. package/lib/_models/index.d.ts +0 -15
  118. package/lib/_models/index.d.ts.map +0 -1
  119. package/lib/_models/index.js +0 -32
  120. package/lib/_models/index.js.map +0 -1
  121. package/lib/_modules/index.d.ts +0 -5
  122. package/lib/_modules/index.d.ts.map +0 -1
  123. package/lib/_modules/index.js +0 -9
  124. package/lib/_modules/index.js.map +0 -1
  125. package/lib/_modules/test-route/custom-data.service.d.ts +0 -6
  126. package/lib/_modules/test-route/custom-data.service.d.ts.map +0 -1
  127. package/lib/_modules/test-route/custom-data.service.js +0 -13
  128. package/lib/_modules/test-route/custom-data.service.js.map +0 -1
  129. package/lib/_modules/test-route/test-controller.d.ts +0 -6
  130. package/lib/_modules/test-route/test-controller.d.ts.map +0 -1
  131. package/lib/_modules/test-route/test-controller.js +0 -126
  132. package/lib/_modules/test-route/test-controller.js.map +0 -1
  133. package/lib/_modules/usage-route/usage-controller.d.ts +0 -7
  134. package/lib/_modules/usage-route/usage-controller.d.ts.map +0 -1
  135. package/lib/_modules/usage-route/usage-controller.js +0 -89
  136. package/lib/_modules/usage-route/usage-controller.js.map +0 -1
  137. package/lib/_modules/usage-route/usage.service.d.ts +0 -19
  138. package/lib/_modules/usage-route/usage.service.d.ts.map +0 -1
  139. package/lib/_modules/usage-route/usage.service.js +0 -111
  140. package/lib/_modules/usage-route/usage.service.js.map +0 -1
  141. package/lib/_services/dynamobe-api.service.d.ts +0 -10
  142. package/lib/_services/dynamobe-api.service.d.ts.map +0 -1
  143. package/lib/_services/dynamobe-api.service.js +0 -131
  144. package/lib/_services/dynamobe-api.service.js.map +0 -1
  145. package/lib/_services/dynamobe-app.d.ts +0 -12
  146. package/lib/_services/dynamobe-app.d.ts.map +0 -1
  147. package/lib/_services/dynamobe-app.js +0 -39
  148. package/lib/_services/dynamobe-app.js.map +0 -1
  149. package/lib/_services/dynamobe-auth.service.d.ts +0 -26
  150. package/lib/_services/dynamobe-auth.service.d.ts.map +0 -1
  151. package/lib/_services/dynamobe-auth.service.js +0 -25
  152. package/lib/_services/dynamobe-auth.service.js.map +0 -1
  153. package/lib/_services/dynamobe-controller.service.d.ts +0 -11
  154. package/lib/_services/dynamobe-controller.service.d.ts.map +0 -1
  155. package/lib/_services/dynamobe-controller.service.js +0 -12
  156. package/lib/_services/dynamobe-controller.service.js.map +0 -1
  157. package/lib/_services/dynamobe-data.service.d.ts +0 -52
  158. package/lib/_services/dynamobe-data.service.d.ts.map +0 -1
  159. package/lib/_services/dynamobe-data.service.js +0 -225
  160. package/lib/_services/dynamobe-data.service.js.map +0 -1
  161. package/lib/_services/dynamobe-db-service-collection.service.d.ts +0 -6
  162. package/lib/_services/dynamobe-db-service-collection.service.d.ts.map +0 -1
  163. package/lib/_services/dynamobe-db-service-collection.service.js +0 -8
  164. package/lib/_services/dynamobe-db-service-collection.service.js.map +0 -1
  165. package/lib/_services/dynamobe-db.service.d.ts +0 -151
  166. package/lib/_services/dynamobe-db.service.d.ts.map +0 -1
  167. package/lib/_services/dynamobe-db.service.js +0 -578
  168. package/lib/_services/dynamobe-db.service.js.map +0 -1
  169. package/lib/_services/dynamobe-email-service-collection.service.d.ts +0 -6
  170. package/lib/_services/dynamobe-email-service-collection.service.d.ts.map +0 -1
  171. package/lib/_services/dynamobe-email-service-collection.service.js +0 -8
  172. package/lib/_services/dynamobe-email-service-collection.service.js.map +0 -1
  173. package/lib/_services/dynamobe-email.service.d.ts +0 -34
  174. package/lib/_services/dynamobe-email.service.d.ts.map +0 -1
  175. package/lib/_services/dynamobe-email.service.js +0 -145
  176. package/lib/_services/dynamobe-email.service.js.map +0 -1
  177. package/lib/_services/dynamobe-global.service.d.ts +0 -23
  178. package/lib/_services/dynamobe-global.service.d.ts.map +0 -1
  179. package/lib/_services/dynamobe-global.service.js +0 -85
  180. package/lib/_services/dynamobe-global.service.js.map +0 -1
  181. package/lib/_services/dynamobe-routing-module.service.d.ts +0 -26
  182. package/lib/_services/dynamobe-routing-module.service.d.ts.map +0 -1
  183. package/lib/_services/dynamobe-routing-module.service.js +0 -113
  184. package/lib/_services/dynamobe-routing-module.service.js.map +0 -1
  185. package/lib/_services/dynamobe-server.d.ts +0 -32
  186. package/lib/_services/dynamobe-server.d.ts.map +0 -1
  187. package/lib/_services/dynamobe-server.js +0 -178
  188. package/lib/_services/dynamobe-server.js.map +0 -1
  189. package/lib/_services/dynamobe-shared.service.d.ts +0 -101
  190. package/lib/_services/dynamobe-shared.service.d.ts.map +0 -1
  191. package/lib/_services/dynamobe-shared.service.js +0 -295
  192. package/lib/_services/dynamobe-shared.service.js.map +0 -1
  193. package/lib/_services/dynamobe-singleton.service.d.ts +0 -6
  194. package/lib/_services/dynamobe-singleton.service.d.ts.map +0 -1
  195. package/lib/_services/dynamobe-singleton.service.js +0 -16
  196. package/lib/_services/dynamobe-singleton.service.js.map +0 -1
  197. package/lib/_services/index.d.ts +0 -15
  198. package/lib/_services/index.d.ts.map +0 -1
  199. package/lib/_services/index.js +0 -41
  200. package/lib/_services/index.js.map +0 -1
  201. package/lib/index.d.ts +0 -5
  202. package/lib/index.d.ts.map +0 -1
  203. package/lib/index.js +0 -12
  204. package/lib/index.js.map +0 -1
  205. package/lib/tsconfig.tsbuildinfo +0 -2107
package/package.json CHANGED
@@ -1,46 +1,46 @@
1
1
  {
2
2
  "name": "@futdevpro/nts-dynamo",
3
- "version": "01.03.58",
3
+ "version": "01.03.60",
4
4
  "description": "Dynamic NodeTS (NodeJS-Typescript), MongoDB Backend System Framework by Future Development Ltd.",
5
- "main": "./lib/index.js",
6
- "module": "./lib/index.js",
7
- "types": "./lib/index.d.ts",
8
- "typings": "./lib/index.d.ts",
5
+ "main": "./src/index.ts",
6
+ "module": "./src/index.ts",
7
+ "types": "./src/index.ts",
8
+ "typings": "./src/index.ts",
9
9
  "exports": {
10
10
  ".": {
11
- "default": "./lib/index.js",
12
- "types": "./lib/index.d.ts"
11
+ "default": "./src/index.ts",
12
+ "types": "./src/index.ts"
13
13
  },
14
14
  "./enums": {
15
- "default": "./lib/_enums/index.js",
16
- "types": "./lib/_enums/index.d.ts"
15
+ "default": "./src/_enums/index.ts",
16
+ "types": "./src/_enums/index.ts"
17
17
  },
18
18
  "./models": {
19
- "default": "./lib/_models/index.js",
20
- "types": "./lib/_models/index.d.ts"
19
+ "default": "./src/_models/index.ts",
20
+ "types": "./src/_models/index.ts"
21
21
  },
22
22
  "./modules": {
23
- "default": "./lib/_modules/index.js",
24
- "types": "./lib/_modules/index.d.ts"
23
+ "default": "./src/_modules/index.ts",
24
+ "types": "./src/_modules/index.ts"
25
25
  },
26
26
  "./services": {
27
- "default": "./lib/_services/index.js",
28
- "types": "./lib/_services/index.d.ts"
27
+ "default": "./src/_services/index.ts",
28
+ "types": "./src/_services/index.ts"
29
29
  }
30
30
  },
31
31
  "typesVersions": {
32
32
  "*": {
33
33
  "enums": [
34
- "lib/_enums/index.d.ts"
34
+ "src/_enums/index.ts"
35
35
  ],
36
36
  "models": [
37
- "lib/_models/index.d.ts"
37
+ "src/_models/index.ts"
38
38
  ],
39
39
  "modules": [
40
- "lib/_modules/index.d.ts"
40
+ "src/_modules/index.ts"
41
41
  ],
42
42
  "services": [
43
- "lib/_services/index.d.ts"
43
+ "src/_services/index.ts"
44
44
  ]
45
45
  }
46
46
  },
@@ -63,27 +63,31 @@ export class DynamoBEEndpointParams{
63
63
 
64
64
  getPreLog(): (req: Request, res: Response, next: NextFunction) => Promise<void> {
65
65
  return async (req: Request, res: Response, next: NextFunction) => {
66
- if (this.logRequest) {
67
- if (this.logRequestsContent) {
68
- let inputs = '';
69
- for(let i = 0; i < this.pathParams.length; i++) {
70
- inputs += ` ${this.pathParams[i]}: ${req.params[this.pathParams[i]]}`;
71
- if (i + 1 < this.pathParams.length || req.body && req.body !== {}) {
72
- inputs += ',';
66
+ try {
67
+ if (this.logRequest) {
68
+ if (this.logRequestsContent) {
69
+ let inputs = '';
70
+ for(let i = 0; i < this.pathParams.length; i++) {
71
+ inputs += ` ${this.pathParams[i]}: ${req.params[this.pathParams[i]]}`;
72
+ if (i + 1 < this.pathParams.length || req.body && req.body !== {}) {
73
+ inputs += ',';
74
+ }
73
75
  }
74
- }
75
76
 
76
- if (req.body && 0 < Object.keys(req.body).length) {
77
- console.log(`==> incoming ${this.name} request...${inputs} body:`, req.body);
77
+ if (req.body && 0 < Object.keys(req.body).length) {
78
+ console.log(`==> incoming ${this.name} request...${inputs} body:`, req.body);
79
+ } else {
80
+ console.log(`==> incoming ${this.name} request...${inputs}`);
81
+ }
78
82
  } else {
79
- console.log(`==> incoming ${this.name} request...${inputs}`);
83
+ console.log(`==> incoming ${this.name} request...`);
80
84
  }
81
- } else {
82
- console.log(`==> incoming ${this.name} request...`);
83
85
  }
84
- }
85
86
 
86
- next();
87
+ next();
88
+ } catch (error) {
89
+ this.error(res, error);
90
+ }
87
91
  };
88
92
  }
89
93
 
@@ -92,9 +96,10 @@ export class DynamoBEEndpointParams{
92
96
  try {
93
97
  const issuer: string = DBE_Global_S.getAuthService().getAccountIdFromRequest(req);
94
98
 
95
- await this.tasks.forEach(async (task: (req: Request, res: Response, issuer?: string) => Promise<void>) => {
96
- await task(req, res, issuer);
97
- });
99
+ console.log(`A ${this.name} ${this.tasks.length}`);
100
+ for (let i = 0; i < this.tasks.length; i++) {
101
+ await this.tasks[i](req, res, issuer);
102
+ }
98
103
 
99
104
  if (this.logRequest) {
100
105
  if (this.logResponseContent) {
@@ -105,21 +110,25 @@ export class DynamoBEEndpointParams{
105
110
  }
106
111
  }
107
112
  } catch (error) {
108
- DBE_Shared.logError(`${this.name} ERROR`, error, '\n');
109
- res.status(error.status ? error.status : 501);
110
- res.send(error);
111
-
112
- if (this.logRequest) {
113
- if (this.logResponseContent) {
114
- DBE_Shared.logError(` <<<===== ${this.name} error sent.`);
115
- DBE_Shared.logError('sorry, the logResponseContent is not implemented yet.');
116
- } else {
117
- DBE_Shared.logError(` <<<===== ${this.name} error sent.`);
118
- }
119
- }
113
+ this.error(res, error);
120
114
  }
121
115
  };
122
116
  }
117
+
118
+ error(res: Response, error): void {
119
+ DBE_Shared.logError(`${this.name} ERROR`, error, '\n');
120
+ res.status(error.status ? error.status : 501);
121
+ res.send(error);
122
+
123
+ if (this.logRequest) {
124
+ if (this.logResponseContent) {
125
+ DBE_Shared.logError(` <<<===== ${this.name} error sent.`);
126
+ DBE_Shared.logError('sorry, the logResponseContent is not implemented yet.');
127
+ } else {
128
+ DBE_Shared.logError(` <<<===== ${this.name} error sent.`);
129
+ }
130
+ }
131
+ }
123
132
  }
124
133
 
125
134
 
@@ -0,0 +1,19 @@
1
+
2
+ import { DynamoBEDataPropertyParams } from './dynamobe-data-property-params';
3
+
4
+ export class DynamoBEDataParams {
5
+ dataName: string;
6
+ dbName: string;
7
+ modelParams: DynamoBEDataPropertyParams[];
8
+
9
+ constructor(
10
+ set: {
11
+ dataName: string,
12
+ modelParams: DynamoBEDataPropertyParams[],
13
+ }
14
+ ) {
15
+ this.dataName = set.dataName;
16
+ this.dbName = set.dataName.charAt(0).toUpperCase() + set.dataName.slice(1);
17
+ this.modelParams = set.modelParams ? set.modelParams : [];
18
+ }
19
+ }
@@ -10,7 +10,7 @@ export class DynamoBEDataPropertyParams {
10
10
  index?: boolean;
11
11
 
12
12
  isDependencyHook?: boolean;
13
- dependencyDBServiceName?: string;
13
+ dependencyName?: string;
14
14
 
15
15
  minlength?: number;
16
16
  maxlength?: number;
@@ -56,7 +56,7 @@ export class DynamoBEDataPropertyParams {
56
56
  if (set.isDependencyHook) {
57
57
  if (set.dependencyDBServiceName) {
58
58
  this.isDependencyHook = set.isDependencyHook;
59
- this.dependencyDBServiceName = set.dependencyDBServiceName;
59
+ this.dependencyName = set.dependencyDBServiceName;
60
60
  } else {
61
61
  this.isDependencyHook = set.isDependencyHook;
62
62
  console.log('DYNAMO ERROR: \n dependencyDBServiceName missing for dependencyHook', '\n\n', new Error());
@@ -1,5 +1,5 @@
1
1
 
2
- import { DynamoBEDataPropertyParams } from '../control-models/dynamobe-data-property-params';
2
+ import { DynamoBEDataParams } from '../control-models/dynamobe-data-params';
3
3
  import { Metadata } from './metadata';
4
4
 
5
5
  export class CustomData extends Metadata {
@@ -32,6 +32,10 @@ export class CustomData extends Metadata {
32
32
  }
33
33
  }
34
34
 
35
- export const customDataModelParams: DynamoBEDataPropertyParams[] = [
36
- { key: 'data', type: 'string', required: true },
37
- ];
35
+ export const customDataModelParams = new DynamoBEDataParams({
36
+ dataName: 'customData',
37
+ modelParams: [
38
+ { key: 'data', type: 'string', required: true },
39
+ ]
40
+ })
41
+
@@ -1,8 +1,8 @@
1
1
 
2
- import { DynamoBEDataPropertyParams } from '../control-models/dynamobe-data-property-params';
3
2
  import { GeoIpLocation } from '../control-models/geo-ip-location';
4
3
  import { Metadata } from './metadata';
5
4
  import { DynamoUsageData } from '../control-models/usage-data';
5
+ import { DynamoBEDataParams } from '../control-models/dynamobe-data-params';
6
6
 
7
7
  export class DynamoUsageSession extends Metadata {
8
8
  date?: string;
@@ -65,18 +65,21 @@ export class DynamoUsageSession extends Metadata {
65
65
  }
66
66
  }
67
67
 
68
- export const usageSessionModelParams: DynamoBEDataPropertyParams[] = [
69
- { key: 'date', type: 'string',
70
- required: true, index: true
71
- },
72
- { key: 'sessionStart', type: 'Date',
73
- required: true, index: true
74
- },
75
- { key: 'sessionEnd', type: 'Date' },
76
- { key: 'address', type: 'string' },
77
- { key: 'issuer', type: 'string' },
78
- { key: 'locationData', type: 'IpApiLocation' },
79
- { key: 'usageData', type: 'UsageData[]' },
80
- { key: 'totalSessionTime', type: 'number' },
81
- { key: 'loggedInAs', type: 'string' },
82
- ];
68
+ export const usageSessionModelParams = new DynamoBEDataParams({
69
+ dataName: 'usageSession',
70
+ modelParams: [
71
+ { key: 'date', type: 'string',
72
+ required: true, index: true
73
+ },
74
+ { key: 'sessionStart', type: 'Date',
75
+ required: true, index: true
76
+ },
77
+ { key: 'sessionEnd', type: 'Date' },
78
+ { key: 'address', type: 'string' },
79
+ { key: 'issuer', type: 'string' },
80
+ { key: 'locationData', type: 'IpApiLocation' },
81
+ { key: 'usageData', type: 'UsageData[]' },
82
+ { key: 'totalSessionTime', type: 'number' },
83
+ { key: 'loggedInAs', type: 'string' },
84
+ ]
85
+ })
@@ -13,6 +13,7 @@ export * from './fullstack-models/control-models/dynamobe-error';
13
13
  export * from './fullstack-models/control-models/geo-ip-location';
14
14
  export * from './fullstack-models/control-models/usage-action';
15
15
  export * from './fullstack-models/control-models/usage-data';
16
+ export * from './fullstack-models/control-models/dynamobe-data-params';
16
17
  // FULLSTACK - DATA MODELS
17
18
  export * from './fullstack-models/data-models/custom-data';
18
19
  export * from './fullstack-models/data-models/metadata';
@@ -3,7 +3,6 @@
3
3
 
4
4
  import { CustomData, customDataModelParams } from '../../_models/fullstack-models/data-models/custom-data';
5
5
  import { DynamoBEDataService } from '../../_services/dynamobe-data.service';
6
- import { DBE_Global_S } from '../../_services/dynamobe-global.service';
7
6
 
8
7
  export class CustomDataService extends DynamoBEDataService<CustomData> {
9
8
 
@@ -12,7 +11,6 @@ export class CustomDataService extends DynamoBEDataService<CustomData> {
12
11
  issuer?: string,
13
12
  ) {
14
13
  super(
15
- DBE_Global_S.getDBServiceCollection().customDataDBService,
16
14
  new CustomData(customData),
17
15
  customDataModelParams,
18
16
  issuer
@@ -6,7 +6,6 @@ import { Request } from 'express';
6
6
  import { DynamoUsageData } from '../../_models/fullstack-models/control-models/usage-data';
7
7
  import { DailyUsageData } from '../../_models/fullstack-models/control-models/daily-usage-data';
8
8
  import { DynamoUsageSession, usageSessionModelParams } from '../../_models/fullstack-models/data-models/usage-session';
9
- import { DBE_Global_S } from '../../_services/dynamobe-global.service';
10
9
 
11
10
  export class UsageService extends DynamoBEDataService<DynamoUsageSession> {
12
11
  usageData: DynamoUsageData[] = [];
@@ -20,12 +19,10 @@ export class UsageService extends DynamoBEDataService<DynamoUsageSession> {
20
19
  }
21
20
  ) {
22
21
  super(
23
- DBE_Global_S.getDBServiceCollection().usageDataDBService,
24
22
  new DynamoUsageSession(set?.usageSession),
25
23
  usageSessionModelParams,
26
24
  set?.issuer
27
25
  );
28
-
29
26
  this.usageData = set?.usageData ? set?.usageData : [];
30
27
  }
31
28
 
@@ -1,16 +1,51 @@
1
1
 
2
2
  import { DynamoBEAppParams } from '../_models/dynamobe-app-params';
3
3
  /* import * as Mongoose from 'mongoose'; */
4
+ /* import * as Express from 'express'; */
4
5
  import Mongoose = require("mongoose");
6
+ import Express = require("express");
7
+ import * as Https from 'https';
8
+ import * as FileSystem from 'fs';
9
+ import * as BodyParser from 'body-parser';
10
+
5
11
  import { DBE_Shared } from './dynamobe-shared.service';
6
12
  import { DynamoBESingletonService } from './dynamobe-singleton.service';
13
+ import { DynamoBERouteSecurity } from '../_enums/dynamobe-route-security.enum';
14
+ import { DynamoBERountingModule } from './dynamobe-routing-module.service';
15
+ import { DBE_Global_S } from './dynamobe-global.service';
16
+ import { DynamoBEEndpointParams } from '../_models/dynamobe-endpoint-control';
7
17
 
18
+ /**
19
+ * This will be the main service of our server project,
20
+ * follow the types and type instructions while setting up your project
21
+ *
22
+ * In this service, there are abstract functions that you will need to implement,
23
+ * where you need to set up the main params for your application.
24
+ */
8
25
  export abstract class DynamoBEApp extends DynamoBESingletonService {
9
26
 
10
27
  protected params: DynamoBEAppParams;
11
28
 
12
29
  protected mongoose = Mongoose;
13
30
 
31
+ protected security: DynamoBERouteSecurity;
32
+
33
+ protected httpPort?: number;
34
+ protected httpsPort?: number;
35
+
36
+ protected cert?: {
37
+ keyPath: FileSystem.PathLike,
38
+ certPath: FileSystem.PathLike,
39
+ };
40
+
41
+ private secureExpress: Express.Application;
42
+ private httpsServer: Https.Server;
43
+ private openExpress: Express.Application;
44
+
45
+ protected routingModules: DynamoBERountingModule[];
46
+
47
+ protected log: boolean;
48
+
14
49
  constructor(){
15
50
  super();
16
51
 
@@ -22,6 +57,22 @@ export abstract class DynamoBEApp extends DynamoBESingletonService {
22
57
  this.startDB();
23
58
 
24
59
  this.setGlobalServiceCollection();
60
+ this.log = DBE_Global_S.getGlobalSettings().logSetup;
61
+
62
+ this.setupRoutingModules();
63
+ this.setSecurity();
64
+
65
+ this.initExpresses();
66
+ this.startExpresses();
67
+
68
+ if (this.security !== DynamoBERouteSecurity.secure) {
69
+ this.mountOpenRoutes();
70
+ }
71
+ if (this.security !== DynamoBERouteSecurity.open && this.cert) {
72
+ this.mountSecureRoutes();
73
+ }
74
+
75
+ if (this.log) console.log(`\nRoutes mounted.... server using security: ${this.security}`);
25
76
  } catch (error) {
26
77
  DBE_Shared.logError('\nApplication start failed.\n', error);
27
78
  }
@@ -45,6 +96,235 @@ export abstract class DynamoBEApp extends DynamoBESingletonService {
45
96
  );
46
97
  }
47
98
 
99
+ private initExpresses() {
100
+ if (this.security !== DynamoBERouteSecurity.secure) {
101
+ if (!this.httpPort) {
102
+ let errorMsg: string =
103
+ `You have open routes, but httpPort is not set!` +
104
+ `\nsecurity: ${this.security}` +
105
+ `\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
106
+
107
+ errorMsg += '\n\nThe routes setted to use open server:';
108
+ this.routingModules.forEach((module: DynamoBERountingModule) => {
109
+ if (module.security != DynamoBERouteSecurity.secure) {
110
+ errorMsg += `\n ${module.route} (security: ${module.security}) \n subroutes using open sever:`;
111
+ module.endpoints.forEach((endpoint: DynamoBEEndpointParams) => {
112
+ if (endpoint.security != DynamoBERouteSecurity.secure) {
113
+ errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
114
+ }
115
+ });
116
+ }
117
+ });
118
+ DBE_Shared.logError(errorMsg);
119
+
120
+ let error = new Error('Open routes cannot be established!');
121
+ let errorStack: string[] = error.stack.split('\n');
122
+ errorStack.splice(1, 2);
123
+ error.stack = errorStack.join('\n');
124
+
125
+ throw error;
126
+ }
127
+
128
+ this.initOpenExpress();
129
+ }
130
+
131
+ if (this.security !== DynamoBERouteSecurity.open) {
132
+ if (!this.cert || !this.httpsPort) {
133
+ let errorMsg: string =
134
+ `You have secure routes, but the certification paths or httpsPort are not set!` +
135
+ `\nsecurity: ${this.security}` +
136
+ `\nset...` +
137
+ `\n httpsPort and` +
138
+ `\n cert: {` +
139
+ `\n keyPath: FileSystem.PathLike,` +
140
+ `\n certPath: FileSystem.PathLike,` +
141
+ `\n }` +
142
+ `\nin DynamoBEServer - setupRoutingModules() to enable secure routes.`;
143
+
144
+ errorMsg += '\n\nThe routes setted to use secure server:';
145
+ this.routingModules.forEach((module: DynamoBERountingModule) => {
146
+ if (module.security != DynamoBERouteSecurity.open) {
147
+ errorMsg += `\n ${module.route} (security: ${module.security}) \n subroutes using secure sever:`;
148
+ module.endpoints.forEach((endpoint: DynamoBEEndpointParams) => {
149
+ if (endpoint.security != DynamoBERouteSecurity.open) {
150
+ errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
151
+ }
152
+ });
153
+ }
154
+ });
155
+ DBE_Shared.logError(errorMsg);
156
+
157
+ let error = new Error('Secure routes cannot be established!');
158
+ let errorStack: string[] = error.stack.split('\n');
159
+ errorStack.splice(1, 2);
160
+ error.stack = errorStack.join('\n');
161
+
162
+ throw error;
163
+ }
164
+
165
+ this.initSecureExpress();
166
+ }
167
+ }
168
+
169
+ private initOpenExpress(): void {
170
+ this.openExpress = Express();
171
+ this.openExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
172
+ this.openExpress.use(BodyParser.json({ limit: '50mb' }));
173
+ }
174
+
175
+ private initSecureExpress(): void {
176
+ this.secureExpress = Express();
177
+ this.secureExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
178
+ this.secureExpress.use(BodyParser.json({ limit: '50mb' }));
179
+
180
+ const options = {
181
+ key: FileSystem.readFileSync(this.cert.keyPath),
182
+ cert: FileSystem.readFileSync(this.cert.certPath),
183
+ };
184
+ this.httpsServer = Https.createServer(options, this.secureExpress);
185
+ }
186
+
187
+ private async startExpresses(): Promise<void> {
188
+ if (this.security !== DynamoBERouteSecurity.open) {
189
+ this.httpsServer
190
+ .listen(this.httpsPort, 'localhost', 0, () => {
191
+ DBE_Shared.logSuccess(`\nHTTPS (secure) server is listening on port ${this.httpsPort}\n`);
192
+ })
193
+ .on('error', (error) => {
194
+ DBE_Shared.logError(`https (secure) server ERROR`, error);
195
+ })
196
+ .on('uncaughtException', (ex) => {
197
+ DBE_Shared.logWarning(`https (secure) server uncaughtException`, ex);
198
+ });
199
+ }
200
+
201
+ if (this.security !== DynamoBERouteSecurity.secure) {
202
+ this.openExpress
203
+ .listen(this.httpPort, () => {
204
+ DBE_Shared.logSuccess(`\nHTTP (-open-) server is listening on port ${this.httpPort}\n`);
205
+ })
206
+ .on('error', (error) => {
207
+ DBE_Shared.logError(`http (-open-) server ERROR`, error);
208
+ })
209
+ .on('uncaughtException', (ex) => {
210
+ DBE_Shared.logWarning(`http (-open-) server uncaughtException`, ex);
211
+ });
212
+ }
213
+ }
214
+
215
+ private mountSecureRoutes (): void {
216
+ this.routingModules.forEach((module: DynamoBERountingModule) => {
217
+ if (module.security !== DynamoBERouteSecurity.open) {
218
+ if (this.log) console.log(`route mount (secure): ${module.route}`);
219
+ const existingRoutes: DynamoBERountingModule[] = this.routingModules.filter(
220
+ (mod: DynamoBERountingModule) => mod.route === module.route);
221
+ if (1 < existingRoutes.length) {
222
+ let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
223
+ let errorStack: string[] = error.stack.split('\n');
224
+ errorStack.splice(1, 4);
225
+ error.stack = errorStack.join('\n');
226
+
227
+ throw error;
228
+ }
229
+ this.secureExpress.use(module.route, module.secureRouter);
230
+ }
231
+ });
232
+ }
233
+
234
+ private mountOpenRoutes (): void {
235
+ this.routingModules.forEach((module: DynamoBERountingModule) => {
236
+ if (module.security !== DynamoBERouteSecurity.secure) {
237
+ if (this.log) console.log(`route mount (open): ${module.route}`);
238
+ const existingRoutes: DynamoBERountingModule[] = this.routingModules.filter(
239
+ (mod: DynamoBERountingModule) => mod.route === module.route);
240
+ if (1 < existingRoutes.length) {
241
+ let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
242
+ let errorStack: string[] = error.stack.split('\n');
243
+ errorStack.splice(1, 4);
244
+ error.stack = errorStack.join('\n');
245
+
246
+ throw error;
247
+ }
248
+ this.openExpress.use(module.route, module.openRouter);
249
+ }
250
+ });
251
+ }
252
+
253
+ private setSecurity(): void {
254
+ this.routingModules.forEach((module: DynamoBERountingModule) => {
255
+ if (!this.security) {
256
+ this.security = module.security;
257
+ } else if (this.security !== module.security) {
258
+ this.security = DynamoBERouteSecurity.both;
259
+ }
260
+ });
261
+ }
262
+
263
+ /**
264
+ * You must setup app params in this function like this:
265
+ *
266
+ * @example
267
+ * this.params = new DynamoBEAppParams({
268
+ * name: 'Sample Server',
269
+ * title: 'A BIG nice header that will be logged on start',
270
+ * version: version,
271
+ * dbName: 'sampleapp',
272
+ * });
273
+ */
48
274
  abstract setupAppParams(): void;
275
+
276
+ /**
277
+ * You must setup globalServiceCollection and dbServices in this function
278
+ *
279
+ * @example
280
+ * DBE_Global_S.setServices({
281
+ * authService: AuthService.getInstance(),
282
+ * emailServiceCollection: EmailServiceCollectionService.getInstance(),
283
+ * dbModels: [
284
+ * accountModelParams,
285
+ * projectModelParams,
286
+ * ...
287
+ * ]
288
+ * });
289
+ *
290
+ * DBE_Global_S.setGlobalSettings({
291
+ * defaultRouteSecurity: DynamoBERouteSecurity.secure,
292
+ * logSetup: true,
293
+ * });
294
+ *
295
+ */
49
296
  abstract setGlobalServiceCollection(): void;
297
+
298
+ /**
299
+ * You must setup endpoints and required services in this function
300
+ *
301
+ * @example
302
+ * this.httpPort = env.httpPort;
303
+ * this.httpsPort = env.httpsPort;
304
+
305
+ * this.cert = {
306
+ * keyPath: Path.join(__dirname, './_assets/cert/ucc.key'),
307
+ * certPath: Path.join(__dirname, './_assets/cert/ucc.crt'),
308
+ * };
309
+
310
+ * this.routingModules = [
311
+ * new DynamoBERountingModule({
312
+ * route: '/api/account',
313
+ * controllers: [
314
+ * AccountController.getInstance(),
315
+ * PersonalInformationController.getInstance(),
316
+ * ...
317
+ * ]
318
+ * }),
319
+ * new DynamoBERountingModule({
320
+ * route: '/api/project',
321
+ * controllers: [
322
+ * ProjectController.getInstance(),
323
+ * ProjectExtensionController.getInstance(),
324
+ * ]
325
+ * }),
326
+ * ...
327
+ * ];
328
+ */
329
+ abstract setupRoutingModules(): void;
50
330
  }
@@ -3,11 +3,26 @@ import { NextFunction, Request, Response } from 'express';
3
3
  import { DynamoBEError } from '../_models/fullstack-models/control-models/dynamobe-error';
4
4
  import { DynamoBESingletonService } from './dynamobe-singleton.service';
5
5
 
6
+ /**
7
+ * Extend this class as an Auth Service implementation
8
+ *
9
+ * You should use singleton instance getting function by implementing a
10
+ * static getInstance() function
11
+ * @example
12
+ * export class AuthService extends DynamoBEAuthService {
13
+ *
14
+ * static getInstance(): AuthService {
15
+ * return AuthService.getSingletonInstance();
16
+ * }
17
+ * ...
18
+ */
6
19
  export abstract class DynamoBEAuthService extends DynamoBESingletonService {
7
20
 
8
21
  /**
22
+ * this function returns the 'authorization' header from the Request,
23
+ * or throws error, if its missing
9
24
  *
10
- * @param req
25
+ * @param req
11
26
  * @returns
12
27
  */
13
28
  static getTokenFromRequest(req: Request): string {
@@ -1,6 +1,7 @@
1
1
 
2
2
 
3
3
  import { DynamoBEEndpointParams } from '../_models/dynamobe-endpoint-control';
4
+ import { DBE_Shared } from './dynamobe-shared.service';
4
5
  import { DynamoBESingletonService } from './dynamobe-singleton.service';
5
6
 
6
7
  export abstract class DynamoBEController extends DynamoBESingletonService {
@@ -10,7 +11,11 @@ export abstract class DynamoBEController extends DynamoBESingletonService {
10
11
  protected constructor(){
11
12
  super();
12
13
 
13
- this.setupEndpoints();
14
+ try {
15
+ this.setupEndpoints();
16
+ } catch (error) {
17
+ DBE_Shared.logError(`DynamoBEController ERROR setup failed:`, error);
18
+ }
14
19
  }
15
20
 
16
21
  /**