node-server-engine 1.4.9 → 1.5.1

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 (277) hide show
  1. package/.commitlintrc.js +27 -0
  2. package/.releaserc.js +56 -0
  3. package/README.md +154 -2
  4. package/dist/const/tokenIssuer.js +1 -0
  5. package/dist/const/tokenIssuer.js.map +1 -1
  6. package/dist/db/models/SequelizeMeta.js +3 -1
  7. package/dist/db/models/SequelizeMeta.js.map +1 -1
  8. package/dist/entities/ElasticSearch/ElasticSearch.js +1 -2
  9. package/dist/entities/ElasticSearch/ElasticSearch.js.map +1 -1
  10. package/dist/entities/Sequelize/Sequelize.js +4 -1
  11. package/dist/entities/Sequelize/Sequelize.js.map +1 -1
  12. package/dist/entities/Server/Server.js +8 -11
  13. package/dist/entities/Server/Server.js.map +1 -1
  14. package/dist/entities/SocketClient/SocketClient.d.ts +4 -1
  15. package/dist/entities/SocketClient/SocketClient.js +5 -1
  16. package/dist/entities/SocketClient/SocketClient.js.map +1 -1
  17. package/dist/index.js +1 -2
  18. package/dist/index.js.map +1 -1
  19. package/dist/middleware/checkPermission/checkPermission.d.ts +1 -1
  20. package/dist/middleware/checkPermission/checkPermission.js +4 -2
  21. package/dist/middleware/checkPermission/checkPermission.js.map +1 -1
  22. package/dist/utils/createSortedObject/createSortedObject.d.ts +5 -1
  23. package/dist/utils/createSortedObject/createSortedObject.js +13 -4
  24. package/dist/utils/createSortedObject/createSortedObject.js.map +1 -1
  25. package/dist/utils/dbMigration/dbMigration.js +34 -15
  26. package/dist/utils/dbMigration/dbMigration.js.map +1 -1
  27. package/dist/utils/geminiFileUpload/geminiFileUpload.js +2 -1
  28. package/dist/utils/geminiFileUpload/geminiFileUpload.js.map +1 -1
  29. package/dist/utils/jwt/jwt.js +1 -1
  30. package/dist/utils/jwt/jwt.js.map +1 -1
  31. package/dist/utils/report/report.d.ts +9 -3
  32. package/dist/utils/report/report.js +29 -12
  33. package/dist/utils/report/report.js.map +1 -1
  34. package/dist/utils/secretManager/secretLoader.js +5 -1
  35. package/dist/utils/secretManager/secretLoader.js.map +1 -1
  36. package/dist/utils/semverCompare/semverCompare.d.ts +4 -4
  37. package/dist/utils/semverCompare/semverCompare.js +16 -18
  38. package/dist/utils/semverCompare/semverCompare.js.map +1 -1
  39. package/package.json +30 -19
  40. package/.env.example +0 -186
  41. package/.github/workflows/publish.yml +0 -41
  42. package/.prettierrc +0 -7
  43. package/Dockerfile +0 -31
  44. package/babel.config.json +0 -34
  45. package/eslint.config.mjs +0 -11
  46. package/src/const/DebeziumEvent.ts +0 -6
  47. package/src/const/LogSeverity.ts +0 -7
  48. package/src/const/index.ts +0 -5
  49. package/src/const/metrics.ts +0 -6
  50. package/src/const/mime.ts +0 -37
  51. package/src/const/tokenIssuer.ts +0 -7
  52. package/src/db/migrations/20241030121500-create-sequelize-meta-table.ts +0 -29
  53. package/src/db/models/SequelizeMeta.ts +0 -16
  54. package/src/db/models/index.ts +0 -2
  55. package/src/entities/ElasticSearch/ElasticSearch.ts +0 -103
  56. package/src/entities/ElasticSearch/ElasticSearch.types.ts +0 -7
  57. package/src/entities/ElasticSearch/index.ts +0 -2
  58. package/src/entities/Endpoint/Endpoint.test.ts +0 -248
  59. package/src/entities/Endpoint/Endpoint.ts +0 -221
  60. package/src/entities/Endpoint/Endpoint.types.ts +0 -181
  61. package/src/entities/Endpoint/index.ts +0 -2
  62. package/src/entities/EngineError/EngineError.ts +0 -28
  63. package/src/entities/EngineError/EngineError.types.ts +0 -15
  64. package/src/entities/EngineError/index.ts +0 -2
  65. package/src/entities/KeySet/KeySet.test.ts +0 -126
  66. package/src/entities/KeySet/KeySet.ts +0 -172
  67. package/src/entities/KeySet/KeySet.types.ts +0 -28
  68. package/src/entities/KeySet/index.ts +0 -2
  69. package/src/entities/LifecycleController/LifecycleController.test.ts +0 -48
  70. package/src/entities/LifecycleController/LifecycleController.ts +0 -24
  71. package/src/entities/LifecycleController/LifecycleController.types.ts +0 -5
  72. package/src/entities/LifecycleController/index.ts +0 -2
  73. package/src/entities/Localizator/Localizator.ts +0 -139
  74. package/src/entities/Localizator/Localizator.types.ts +0 -52
  75. package/src/entities/Localizator/guessNamingConvention/guessNamingConvention.test.ts +0 -165
  76. package/src/entities/Localizator/guessNamingConvention/guessNamingConvention.ts +0 -58
  77. package/src/entities/Localizator/guessNamingConvention/index.ts +0 -1
  78. package/src/entities/Localizator/index.ts +0 -2
  79. package/src/entities/MessageHandler/MessageHandler.test.ts +0 -130
  80. package/src/entities/MessageHandler/MessageHandler.ts +0 -72
  81. package/src/entities/MessageHandler/MessageHandler.types.ts +0 -15
  82. package/src/entities/MessageHandler/index.ts +0 -2
  83. package/src/entities/PubSub/PubSub.test.ts +0 -297
  84. package/src/entities/PubSub/PubSub.ts +0 -202
  85. package/src/entities/PubSub/PubSub.types.ts +0 -76
  86. package/src/entities/PubSub/handleMessage/handleMessage.test.ts +0 -102
  87. package/src/entities/PubSub/handleMessage/handleMessage.ts +0 -65
  88. package/src/entities/PubSub/handleMessage/index.ts +0 -1
  89. package/src/entities/PubSub/index.ts +0 -2
  90. package/src/entities/PushNotification/PushNotification.test.ts +0 -35
  91. package/src/entities/PushNotification/PushNotification.ts +0 -44
  92. package/src/entities/PushNotification/PushNotification.types.ts +0 -25
  93. package/src/entities/PushNotification/index.ts +0 -2
  94. package/src/entities/Redis/Redis.ts +0 -71
  95. package/src/entities/Redis/Redis.types.ts +0 -19
  96. package/src/entities/Redis/Redis.validate.ts +0 -17
  97. package/src/entities/Redis/index.ts +0 -2
  98. package/src/entities/Sequelize/Sequelize.config.ts +0 -59
  99. package/src/entities/Sequelize/Sequelize.test.ts +0 -21
  100. package/src/entities/Sequelize/Sequelize.ts +0 -75
  101. package/src/entities/Sequelize/Sequelize.types.ts +0 -10
  102. package/src/entities/Sequelize/Sequelize.validate.ts +0 -15
  103. package/src/entities/Sequelize/index.ts +0 -2
  104. package/src/entities/Server/Server.const.ts +0 -56
  105. package/src/entities/Server/Server.test.ts +0 -272
  106. package/src/entities/Server/Server.ts +0 -471
  107. package/src/entities/Server/Server.types.ts +0 -88
  108. package/src/entities/Server/index.ts +0 -2
  109. package/src/entities/SocketClient/SocketClient.test.ts +0 -392
  110. package/src/entities/SocketClient/SocketClient.ts +0 -401
  111. package/src/entities/SocketClient/SocketClient.types.ts +0 -62
  112. package/src/entities/SocketClient/index.ts +0 -2
  113. package/src/entities/SocketClient/parseMessage/index.ts +0 -1
  114. package/src/entities/SocketClient/parseMessage/parseMessage.test.ts +0 -20
  115. package/src/entities/SocketClient/parseMessage/parseMessage.ts +0 -26
  116. package/src/entities/Storage/Storage.test.ts +0 -58
  117. package/src/entities/Storage/Storage.ts +0 -219
  118. package/src/entities/Storage/Storage.types.ts +0 -57
  119. package/src/entities/Storage/index.ts +0 -2
  120. package/src/entities/ValidationError/ValidationError.ts +0 -34
  121. package/src/entities/ValidationError/index.ts +0 -1
  122. package/src/entities/WebError/WebError.test.ts +0 -18
  123. package/src/entities/WebError/WebError.ts +0 -23
  124. package/src/entities/WebError/WebError.types.ts +0 -9
  125. package/src/entities/WebError/index.ts +0 -2
  126. package/src/entities/index.ts +0 -16
  127. package/src/index.ts +0 -6
  128. package/src/metrics/debug.ts +0 -10
  129. package/src/metrics/index.ts +0 -2
  130. package/src/metrics/request.ts +0 -17
  131. package/src/middleware/authHmac/authHmac.test.ts +0 -86
  132. package/src/middleware/authHmac/authHmac.ts +0 -56
  133. package/src/middleware/authHmac/authHmac.types.ts +0 -7
  134. package/src/middleware/authHmac/index.ts +0 -2
  135. package/src/middleware/authJwt/authJwt.test.ts +0 -54
  136. package/src/middleware/authJwt/authJwt.ts +0 -55
  137. package/src/middleware/authJwt/authJwt.types.ts +0 -14
  138. package/src/middleware/authJwt/index.ts +0 -2
  139. package/src/middleware/authStatic/authStatic.test.ts +0 -36
  140. package/src/middleware/authStatic/authStatic.ts +0 -45
  141. package/src/middleware/authStatic/index.ts +0 -1
  142. package/src/middleware/authTls/authTls.test.ts +0 -138
  143. package/src/middleware/authTls/authTls.ts +0 -119
  144. package/src/middleware/authTls/authTls.types.ts +0 -13
  145. package/src/middleware/authTls/index.ts +0 -2
  146. package/src/middleware/checkPermission/checkPermission.ts +0 -33
  147. package/src/middleware/checkPermission/index.ts +0 -1
  148. package/src/middleware/error/error.test.ts +0 -60
  149. package/src/middleware/error/error.ts +0 -25
  150. package/src/middleware/error/index.ts +0 -1
  151. package/src/middleware/fileUploader/fileUploader.ts +0 -154
  152. package/src/middleware/fileUploader/fileUploader.types.ts +0 -35
  153. package/src/middleware/fileUploader/index.ts +0 -2
  154. package/src/middleware/fileUploader/isMultiPart/index.ts +0 -1
  155. package/src/middleware/fileUploader/isMultiPart/isMultipart.ts +0 -9
  156. package/src/middleware/fileUploader/validate/index.ts +0 -1
  157. package/src/middleware/fileUploader/validate/validate.ts +0 -27
  158. package/src/middleware/fourOhFour/fourOhFour.test.ts +0 -14
  159. package/src/middleware/fourOhFour/fourOhFour.ts +0 -13
  160. package/src/middleware/fourOhFour/index.ts +0 -1
  161. package/src/middleware/geminiFileUploader/geminiFileUploader.ts +0 -68
  162. package/src/middleware/geminiFileUploader/index.ts +0 -1
  163. package/src/middleware/healthCheck/healthCheck.test.ts +0 -12
  164. package/src/middleware/healthCheck/healthCheck.ts +0 -14
  165. package/src/middleware/healthCheck/index.ts +0 -1
  166. package/src/middleware/index.ts +0 -17
  167. package/src/middleware/metrics/index.ts +0 -1
  168. package/src/middleware/metrics/metrics.test.ts +0 -46
  169. package/src/middleware/metrics/metrics.ts +0 -24
  170. package/src/middleware/multiPartFileUploader/index.ts +0 -2
  171. package/src/middleware/multiPartFileUploader/multiPartFileUploader.ts +0 -249
  172. package/src/middleware/multiPartFileUploader/multiPartFileUploader.types.ts +0 -23
  173. package/src/middleware/multiPartFileUploader/validate/index.ts +0 -1
  174. package/src/middleware/multiPartFileUploader/validate/validate.ts +0 -27
  175. package/src/middleware/requestMetrics/index.ts +0 -1
  176. package/src/middleware/requestMetrics/requestMetrics.test.ts +0 -77
  177. package/src/middleware/requestMetrics/requestMetrics.ts +0 -20
  178. package/src/middleware/swaggerDocs/index.ts +0 -2
  179. package/src/middleware/swaggerDocs/swaggerDocs.ts +0 -114
  180. package/src/middleware/swaggerDocs/swaggerDocs.types.ts +0 -41
  181. package/src/middleware/userResolver/index.ts +0 -1
  182. package/src/middleware/userResolver/userResolver.ts +0 -53
  183. package/src/middleware/validate/index.ts +0 -1
  184. package/src/middleware/validate/validate.test.ts +0 -43
  185. package/src/middleware/validate/validate.ts +0 -25
  186. package/src/middleware/version/index.ts +0 -1
  187. package/src/middleware/version/version.test.ts +0 -23
  188. package/src/middleware/version/version.ts +0 -12
  189. package/src/utils/checkEnvironment/index.ts +0 -49
  190. package/src/utils/createHttpServer/createHttpServer.test.ts +0 -24
  191. package/src/utils/createHttpServer/createHttpServer.ts +0 -34
  192. package/src/utils/createHttpServer/createHttpServer.validate.ts +0 -17
  193. package/src/utils/createHttpServer/index.ts +0 -1
  194. package/src/utils/createSortedObject/createSortedObject.ts +0 -20
  195. package/src/utils/createSortedObject/createSortedObjet.test.ts +0 -47
  196. package/src/utils/createSortedObject/index.ts +0 -1
  197. package/src/utils/dbMigration/dbMigration.test.ts +0 -209
  198. package/src/utils/dbMigration/dbMigration.ts +0 -199
  199. package/src/utils/dbMigration/dbMigration.types.ts +0 -11
  200. package/src/utils/dbMigration/index.ts +0 -2
  201. package/src/utils/dbMigration/migrateMetadataTable/index.ts +0 -1
  202. package/src/utils/dbMigration/migrateMetadataTable/migrateMetadataTable.test.ts +0 -59
  203. package/src/utils/dbMigration/migrateMetadataTable/migrateMetadataTable.ts +0 -102
  204. package/src/utils/envAssert/envAssert.ts +0 -31
  205. package/src/utils/envAssert/index.ts +0 -1
  206. package/src/utils/envAssert/validators/hostList.ts +0 -17
  207. package/src/utils/envAssert/validators/index.ts +0 -5
  208. package/src/utils/envAssert/validators/ipList.ts +0 -13
  209. package/src/utils/envAssert/validators/path.ts +0 -13
  210. package/src/utils/envAssert/validators/string.ts +0 -9
  211. package/src/utils/envAssert/validators/stringList.ts +0 -13
  212. package/src/utils/filter/filter.ts +0 -17
  213. package/src/utils/filter/index.ts +0 -1
  214. package/src/utils/geminiFileUpload/geminiFileUpload.ts +0 -93
  215. package/src/utils/geminiFileUpload/index.ts +0 -1
  216. package/src/utils/hmac/checkEnv/checkEnv.test.ts +0 -18
  217. package/src/utils/hmac/checkEnv/checkEnv.ts +0 -9
  218. package/src/utils/hmac/checkEnv/index.ts +0 -1
  219. package/src/utils/hmac/createHmac/createHmac.ts +0 -33
  220. package/src/utils/hmac/createHmac/index.ts +0 -1
  221. package/src/utils/hmac/index.ts +0 -4
  222. package/src/utils/hmac/index.types.ts +0 -13
  223. package/src/utils/hmac/signPayload/index.ts +0 -1
  224. package/src/utils/hmac/signPayload/signPayload.ts +0 -16
  225. package/src/utils/hmac/verifySignature/index.ts +0 -1
  226. package/src/utils/hmac/verifySignature/verifySignature.ts +0 -24
  227. package/src/utils/index.ts +0 -29
  228. package/src/utils/jwt/index.ts +0 -2
  229. package/src/utils/jwt/jwt.test.ts +0 -28
  230. package/src/utils/jwt/jwt.ts +0 -182
  231. package/src/utils/jwt/jwt.types.ts +0 -21
  232. package/src/utils/report/index.ts +0 -3
  233. package/src/utils/report/output.ts +0 -45
  234. package/src/utils/report/output.types.ts +0 -70
  235. package/src/utils/report/report.test.ts +0 -133
  236. package/src/utils/report/report.ts +0 -133
  237. package/src/utils/report/report.types.ts +0 -13
  238. package/src/utils/request/index.ts +0 -1
  239. package/src/utils/request/request.test.ts +0 -26
  240. package/src/utils/request/request.ts +0 -48
  241. package/src/utils/secretManager/index.ts +0 -2
  242. package/src/utils/secretManager/secretLoader.ts +0 -62
  243. package/src/utils/secretManager/secretResolver.ts +0 -35
  244. package/src/utils/semverCompare/index.ts +0 -1
  245. package/src/utils/semverCompare/semverCompare.test.ts +0 -49
  246. package/src/utils/semverCompare/semverCompare.ts +0 -60
  247. package/src/utils/sendEmail/index.ts +0 -2
  248. package/src/utils/sendEmail/sendEmail.ts +0 -61
  249. package/src/utils/sendEmail/sendEmail.types.ts +0 -61
  250. package/src/utils/sendPush/index.ts +0 -2
  251. package/src/utils/sendPush/sendPush.ts +0 -20
  252. package/src/utils/sendPush/sendPush.types.ts +0 -25
  253. package/src/utils/tlsConfig/index.ts +0 -2
  254. package/src/utils/tlsConfig/tlsConfig.test.ts +0 -32
  255. package/src/utils/tlsConfig/tlsConfig.ts +0 -47
  256. package/src/utils/tlsConfig/tlsConfig.types.ts +0 -11
  257. package/src/utils/tlsConfig/tlsConfig.validate.ts +0 -25
  258. package/src/utils/tlsRequest/index.ts +0 -1
  259. package/src/utils/tlsRequest/tlsRequest.test.ts +0 -63
  260. package/src/utils/tlsRequest/tlsRequest.ts +0 -12
  261. package/src/utils/trimPathSlash/index.ts +0 -1
  262. package/src/utils/trimPathSlash/trimPathSlash.test.ts +0 -26
  263. package/src/utils/trimPathSlash/trimPathSlash.ts +0 -8
  264. package/test/env.ts +0 -53
  265. package/test/factory/index.ts +0 -8
  266. package/test/factory/sequelizeMeta.ts +0 -12
  267. package/test/hooks.ts +0 -35
  268. package/test/index.ts +0 -3
  269. package/test/stub/index.ts +0 -3
  270. package/test/stub/stubLocales.ts +0 -68
  271. package/test/stub/stubPubSub.ts +0 -7
  272. package/test/stub/stubStorage.ts +0 -77
  273. package/test/stub/stubStorage.types.ts +0 -11
  274. package/test/utils/app.ts +0 -31
  275. package/test/utils/index.ts +0 -1
  276. package/tsconfig.build.json +0 -5
  277. package/tsconfig.json +0 -32
@@ -1,62 +0,0 @@
1
- import { SecretManagerServiceClient } from '@google-cloud/secret-manager';
2
- import { EngineError } from 'entities/EngineError';
3
-
4
- // Cache to store preloaded secrets
5
- export const secretCache: { [key: string]: string } = {};
6
- let secretClient: SecretManagerServiceClient;
7
-
8
- /**
9
- * Initialize the Secret Manager client and preload secrets.
10
- * @param secretEnvVars List of env var names that contain secret paths
11
- */
12
- export const initializeSecrets = async (
13
- secretEnvVars: string[]
14
- ): Promise<void> => {
15
- if (process.env.NODE_ENV !== 'production') {
16
- console.log('Development mode → using local files for secrets');
17
- return; // No need to preload anything
18
- }
19
-
20
- try {
21
- // Default creds (for GCP runtime)
22
- secretClient = new SecretManagerServiceClient();
23
-
24
- const secretNames = secretEnvVars.filter((name) => process.env[name]);
25
- if (secretNames.length === 0) {
26
- throw new EngineError({
27
- message: 'No secret names defined in environment variables'
28
- });
29
- }
30
-
31
- // Fetch all secrets from GCP Secret Manager
32
- for (const name of secretNames) {
33
- const secretPath = process.env[name];
34
- if (!secretPath) {
35
- throw new EngineError({
36
- message: `Secret path for ${name} is not defined`
37
- });
38
- }
39
-
40
- try {
41
- const [version] = await secretClient.accessSecretVersion({
42
- name: secretPath
43
- });
44
- const payload = version.payload?.data?.toString('utf-8');
45
- if (!payload) {
46
- throw new EngineError({
47
- message: `Secret ${name} not found or empty`
48
- });
49
- }
50
- secretCache[name] = payload;
51
- } catch (err) {
52
- throw new EngineError({
53
- message: `Error accessing secret ${name}: ${(err as Error).message}`
54
- });
55
- }
56
- }
57
- } catch (err) {
58
- throw new EngineError({
59
- message: `Failed to initialize secrets: ${(err as Error).message}`
60
- });
61
- }
62
- };
@@ -1,35 +0,0 @@
1
- import fs from 'fs';
2
- import { EngineError } from 'entities/EngineError';
3
- import { secretCache } from './secretLoader';
4
-
5
- /**
6
- * Retrieve a secret value (production) or file content (development).
7
- * @param name The env var name that contains either the secret path (prod) or local file path (dev)
8
- */
9
- export const getSecretOrFile = (name: string): string => {
10
- if (process.env.NODE_ENV === 'production') {
11
- const secretValue = secretCache[name];
12
-
13
- if (!secretValue) {
14
- throw new EngineError({
15
- message: `Secret value for ${name} not found in cache`
16
- });
17
- }
18
- return secretValue;
19
- } else {
20
- const localPath = process.env[name];
21
- if (!localPath) {
22
- throw new EngineError({
23
- message: `Local path for ${name} is not defined`
24
- });
25
- }
26
-
27
- try {
28
- return fs.readFileSync(localPath, 'utf-8');
29
- } catch (err) {
30
- throw new EngineError({
31
- message: `Error reading local file for ${name}: ${(err as Error).message}`
32
- });
33
- }
34
- }
35
- };
@@ -1 +0,0 @@
1
- export * from './semverCompare';
@@ -1,49 +0,0 @@
1
- import { expect } from 'chai';
2
- import { semverCompare } from './semverCompare';
3
- import { EngineError } from 'entities/EngineError';
4
-
5
- describe('Utils - SemVer Compare', function () {
6
- it('Should throw an error if given a wrong formatted item', () => {
7
- expect(() => semverCompare('1.0.0', 'test')).to.throw(EngineError);
8
- expect(() => semverCompare('wrong', '1.0.0')).to.throw(EngineError);
9
- });
10
-
11
- it('Should compare majors', () => {
12
- expect(semverCompare('1.0.0', '2.0.0')).to.equal(-1);
13
- expect(semverCompare('2.0.0', '1.0.0')).to.equal(1);
14
- });
15
-
16
- it('Should compare minors', () => {
17
- expect(semverCompare('1.1.0', '1.2.0')).to.equal(-1);
18
- expect(semverCompare('2.5.0', '2.3.0')).to.equal(1);
19
- });
20
-
21
- it('Should compare patches', () => {
22
- expect(semverCompare('1.1.1', '1.1.2')).to.equal(-1);
23
- expect(semverCompare('2.5.6', '2.5.0')).to.equal(1);
24
- });
25
-
26
- it('Should compare patches', () => {
27
- expect(semverCompare('1.1.1', '1.1.2')).to.equal(-1);
28
- expect(semverCompare('2.5.6', '2.5.0')).to.equal(1);
29
- });
30
-
31
- it('Should compare releases types', () => {
32
- expect(semverCompare('1.1.1-rc.1', '1.1.1')).to.equal(-1);
33
- expect(semverCompare('1.1.1-beta.1', '1.1.1-rc.1')).to.equal(-1);
34
- expect(semverCompare('1.1.1-alpha.1', '1.1.1-beta.1')).to.equal(-1);
35
- expect(semverCompare('2.5.5', '2.5.5-rc.1')).to.equal(1);
36
- expect(semverCompare('2.5.5-rc.1', '2.5.5-beta.1')).to.equal(1);
37
- expect(semverCompare('2.5.5-beta.1', '2.5.5-alpha.1')).to.equal(1);
38
- });
39
-
40
- it('Should compare pre-release versions', () => {
41
- expect(semverCompare('1.1.1-alpha.1', '1.1.1-alpha.2')).to.equal(-1);
42
- expect(semverCompare('2.5.6-rc.5', '2.5.6-rc.3')).to.equal(1);
43
- });
44
-
45
- it('Should handle equality', () => {
46
- expect(semverCompare('1.1.1', '1.1.1')).to.equal(0);
47
- expect(semverCompare('2.5.6-rc.5', '2.5.6-rc.5')).to.equal(0);
48
- });
49
- });
@@ -1,60 +0,0 @@
1
- import validator from 'validator';
2
- import { EngineError } from 'entities/EngineError';
3
-
4
- // Regex to validate our SemVer style and capture the different parts
5
- const SEMVER_REGEX =
6
- /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(?:(alpha|beta|rc)(?:\.(0|[1-9]\d*))))?$/;
7
-
8
- /**
9
- * Comparison function for our SemVer strings, includes support ofr pre-releases
10
- * @param {string} v1
11
- * @param {string} v2
12
- * @return {number} - -1 if v1 < v2, 0 if v1 = v2, +1 if v1 > v2
13
- */
14
- export function semverCompare(v1: string, v2: string): 1 | -1 | 0 {
15
- const [match1, match2] = [v1, v2].map((v) => v.match(SEMVER_REGEX));
16
- if (!match1 || !match2)
17
- throw new EngineError({
18
- message: 'Provided invalid SemVer string, can not compare',
19
- data: { v1, v2 }
20
- });
21
- const [
22
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
23
- [_1, major1, minor1, patch1, preType1, preVersion1],
24
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
25
- [_2, major2, minor2, patch2, preType2, preVersion2]
26
- ] = [match1, match2].map((group) =>
27
- // We parse to int the parts that can be
28
- group.map((item) => (item && validator.isInt(item) ? parseInt(item) : item))
29
- );
30
-
31
- // Compare majors first
32
- if (major1 < major2) return -1;
33
- if (major1 > major2) return 1;
34
-
35
- // Compare minors second
36
- if (minor1 < minor2) return -1;
37
- if (minor1 > minor2) return 1;
38
-
39
- // Compare patch third
40
- if (patch1 < patch2) return -1;
41
- if (patch1 > patch2) return 1;
42
-
43
- // Compare pre-release type
44
- // Release > pre-release
45
- if (!preType1 && !preType2) return 0;
46
- if (preType1 && !preType2) return -1;
47
- if (!preType1 && preType2) return 1;
48
-
49
- // RC > Beta > Alpha
50
- if (preType1 !== 'rc' && preType2 === 'rc') return -1;
51
- if (preType1 === 'rc' && preType2 !== 'rc') return 1;
52
- if (preType1 !== 'beta' && preType2 === 'beta') return -1;
53
- if (preType1 === 'beta' && preType2 !== 'beta') return 1;
54
-
55
- // Finally compare the pre-release versions
56
- if (preVersion1 < preVersion2) return -1;
57
- if (preVersion1 > preVersion2) return 1;
58
-
59
- return 0;
60
- }
@@ -1,2 +0,0 @@
1
- export * from './sendEmail';
2
- export * from './sendEmail.types';
@@ -1,61 +0,0 @@
1
- import { EmailOptions, EmailResult, EmailStatus } from './sendEmail.types';
2
- import nodemailer, {
3
- Transporter,
4
- SendMailOptions,
5
- SentMessageInfo
6
- } from 'nodemailer';
7
-
8
- /**
9
- * Sends an email using Nodemailer.
10
- * @param emailOptions - Configuration options for sending the email.
11
- * @returns A Promise that resolves with an EmailResult indicating success or failure.
12
- */
13
- export const sendEmail = async (
14
- emailOptions: EmailOptions
15
- ): Promise<EmailResult> => {
16
- try {
17
- // Create a transport with SMTP configuration
18
- const transporter: Transporter = nodemailer.createTransport({
19
- host: process.env.SMTP_HOST,
20
- port: parseInt(process.env.SMTP_PORT || '587', 10),
21
- secure: process.env.SMTP_PORT === '465' ? true : false,
22
- auth: {
23
- user: process.env.SMTP_USER,
24
- pass: process.env.SMTP_PASS
25
- },
26
- tls: {
27
- rejectUnauthorized: process.env.SMTP_PORT === '465' ? true : false
28
- }
29
- });
30
-
31
- // Construct email options
32
- const mailOptions: SendMailOptions = {
33
- from: emailOptions.from,
34
- to: emailOptions.to,
35
- cc: emailOptions.cc,
36
- bcc: emailOptions.bcc,
37
- subject: emailOptions.subject,
38
- text: emailOptions.text,
39
- html: emailOptions.html,
40
- attachments: emailOptions.attachments,
41
- replyTo: emailOptions.replyTo,
42
- headers: emailOptions.headers,
43
- priority: emailOptions.priority
44
- };
45
-
46
- // Send email
47
- const info: SentMessageInfo = await transporter.sendMail(mailOptions);
48
-
49
- // Determine email status
50
- let status: EmailStatus = 'sent';
51
- if (info.response.includes('queued')) {
52
- status = 'queued';
53
- } else if (info.response.includes('delivered')) {
54
- status = 'delivered';
55
- }
56
-
57
- return { status, messageId: info.messageId };
58
- } catch (error) {
59
- return { status: 'failed', error: (error as Error).message };
60
- }
61
- };
@@ -1,61 +0,0 @@
1
- /** Structure representing email options for sending an email */
2
- export interface EmailOptions {
3
- /** Sender's email address (optional, defaults to the authenticated user) */
4
- from?: string;
5
-
6
- /** Recipient(s) of the email - can be a string or an array of strings */
7
- to: string | string[];
8
-
9
- /** Carbon Copy (CC) recipients (optional) */
10
- cc?: string | string[];
11
-
12
- /** Blind Carbon Copy (BCC) recipients (optional) */
13
- bcc?: string | string[];
14
-
15
- /** Subject of the email */
16
- subject: string;
17
-
18
- /** Plain text version of the email body (optional) */
19
- text?: string;
20
-
21
- /** HTML version of the email body (optional) */
22
- html?: string;
23
-
24
- /** Attachments to include in the email (optional) */
25
- attachments?: {
26
- /** Name of the attached file */
27
- filename: string;
28
- /** Content of the attachment (Buffer or string) */
29
- content?: string | Buffer;
30
- /** File path of the attachment (alternative to `content`) */
31
- path?: string;
32
- /** MIME type of the attachment */
33
- contentType?: string;
34
- /** Encoding of the attachment (e.g., base64, utf-8) */
35
- encoding?: string;
36
- /** Content ID for inline images (optional) */
37
- cid?: string;
38
- }[];
39
-
40
- /** Email address for replies (optional) */
41
- replyTo?: string;
42
-
43
- /** Custom headers for the email (optional) */
44
- headers?: { [key: string]: string };
45
-
46
- /** Email priority level (optional) */
47
- priority?: 'high' | 'normal' | 'low';
48
- }
49
-
50
- /** Possible statuses for email delivery */
51
- export type EmailStatus = 'sent' | 'delivered' | 'queued' | 'failed';
52
-
53
- /** Structure representing the result of an email sending operation */
54
- export interface EmailResult {
55
- /** Status of the email operation */
56
- status: EmailStatus;
57
- /** Message ID returned by the mail server (if available) */
58
- messageId?: string;
59
- /** Error message in case of failure (if any) */
60
- error?: string;
61
- }
@@ -1,2 +0,0 @@
1
- export * from './sendPush';
2
- export * from './sendPush.types';
@@ -1,20 +0,0 @@
1
- import { SendPushNotification } from './sendPush.types';
2
- import { tlsRequest } from 'utils/tlsRequest';
3
-
4
- /**
5
- * Send a push notification through the push service
6
- * @param userId - ID of the user that should receive the notification
7
- * @param notification - Notification that should be sent
8
- * @return Push service response
9
- */
10
- export async function sendPush(
11
- userId: string,
12
- notification: SendPushNotification
13
- ): Promise<unknown> {
14
- return tlsRequest({
15
- method: 'post',
16
- url: '/push',
17
- baseURL: process.env.PUSH_SERVICE_URL,
18
- data: { userId, ...notification }
19
- });
20
- }
@@ -1,25 +0,0 @@
1
- /** Stricture representing a push notification to send */
2
- export interface SendPushNotification {
3
- /** Title of the notification */
4
- title?: string;
5
- /** Body of the notification */
6
- body?: string;
7
- /** Data payload of the notification */
8
- payload?: unknown;
9
- /** Indicates that the notification is a VOIP notification */
10
- voip?: boolean;
11
- /** Indicate that it is a background notification (data only, low priority) */
12
- background?: boolean;
13
- /** Push token can be specified here is we want to send to a given user */
14
- token?: string;
15
- /** Indicates that the data content can be mutated by the client (iOS) */
16
- mutable?: boolean;
17
- /** Indicates that the notification requires some client side processing to be displayed (iOS) */
18
- contentAvailable?: boolean;
19
- /** Time to live of the notification in seconds. After this the notification will not be distributed */
20
- ttl?: number;
21
- /** Indicate that it is a high priority notification */
22
- priority?: boolean;
23
- /** Notifications with the same string here will be collapsed in the system tray */
24
- collapseId?: string;
25
- }
@@ -1,2 +0,0 @@
1
- export * from './tlsConfig';
2
- export * from './tlsConfig.types';
@@ -1,32 +0,0 @@
1
- import path from 'path';
2
- import { expect } from 'chai';
3
- import { validateTlsConfig } from './tlsConfig.validate';
4
-
5
- describe('utils - TLS Config', () => {
6
- beforeEach(() => {
7
- delete process.env.TLS_REQUEST_KEY;
8
- delete process.env.TLS_REQUEST_CERT;
9
- delete process.env.TLS_REQUEST_CA;
10
- delete process.env.TLS_SERVER_KEY;
11
- delete process.env.TLS_SERVER_CERT;
12
- delete process.env.TLS_CA;
13
- });
14
-
15
- it('should accept Request TLS environment variables', () => {
16
- process.env.TLS_REQUEST_KEY = path.resolve('certs/client.key');
17
- process.env.TLS_REQUEST_CERT = path.resolve('certs/client.crt');
18
- process.env.TLS_REQUEST_CA = path.resolve('certs/ca.crt');
19
- expect(validateTlsConfig).to.throw;
20
- });
21
-
22
- it('should accept Server TLS environment variables', () => {
23
- process.env.TLS_SERVER_KEY = path.resolve('certs/server.key');
24
- process.env.TLS_SERVER_CERT = path.resolve('certs/server.crt');
25
- process.env.TLS_CA = path.resolve('certs/ca.crt');
26
- expect(validateTlsConfig).to.throw;
27
- });
28
-
29
- it('should throw an EngineError if no environment setting', () => {
30
- expect(validateTlsConfig).to.throw;
31
- });
32
- });
@@ -1,47 +0,0 @@
1
- import fs from 'fs';
2
- import https, { Agent } from 'https';
3
- import { TlsConfig } from './tlsConfig.types';
4
- import { validateTlsConfig } from './tlsConfig.validate';
5
- import { EngineError } from 'entities/EngineError';
6
-
7
- export let tlsConfig: undefined | TlsConfig;
8
- export let httpsAgent: undefined | Agent;
9
-
10
- /**
11
- * Load TLS config by its Environment setting.
12
- */
13
- export function loadTlsConfig(): void {
14
- // Check that environment variables are correctly set
15
- validateTlsConfig();
16
- tlsConfig = undefined;
17
-
18
- if (process.env.TLS_REQUEST_KEY || process.env.TLS_SERVER_KEY) {
19
- tlsConfig = {
20
- key: fs.readFileSync(
21
- (process.env.TLS_REQUEST_KEY ?? process.env.TLS_SERVER_KEY) as string,
22
- 'utf-8'
23
- ),
24
- cert: fs.readFileSync(
25
- (process.env.TLS_REQUEST_CERT ?? process.env.TLS_SERVER_CERT) as string,
26
- 'utf-8'
27
- ),
28
- ca: fs.readFileSync(
29
- (process.env.TLS_REQUEST_CA ?? process.env.TLS_CA) as string,
30
- 'utf-8'
31
- ),
32
- passphrase: (process.env.TLS_REQUEST_KEY_PASSPHRASE ??
33
- process.env.TLS_SERVER_KEY_PASSPHRASE) as string
34
- } as TlsConfig;
35
- httpsAgent = new https.Agent({
36
- key: tlsConfig.key,
37
- cert: tlsConfig.cert,
38
- ca: tlsConfig.ca,
39
- passphrase: tlsConfig.passphrase
40
- });
41
- }
42
- if (!tlsConfig || !(tlsConfig.ca && tlsConfig.cert && tlsConfig.key)) {
43
- throw new EngineError({
44
- message: 'TLS environment variables are not set correctly'
45
- });
46
- }
47
- }
@@ -1,11 +0,0 @@
1
- /** TLS properties */
2
- export interface TlsConfig {
3
- /** Path to the private key file */
4
- key: string;
5
- /** Path to the certificate file */
6
- cert: string;
7
- /** Path to the CA certificate file */
8
- ca: string;
9
- /** Passphrase to use to unwrap the private key */
10
- passphrase?: string;
11
- }
@@ -1,25 +0,0 @@
1
- import { assertEnvironment, envAssert } from 'utils';
2
- /**
3
- * Verify that the environment variables
4
- */
5
- export function validateTlsConfig(): void {
6
- // We only check if there is at least the host specified
7
- if (process.env.TLS_REQUEST_CERT) {
8
- assertEnvironment({ TLS_REQUEST_KEY: envAssert.isPath() });
9
- assertEnvironment({ TLS_REQUEST_CERT: envAssert.isPath() });
10
- assertEnvironment({ TLS_REQUEST_CA: envAssert.isPath() });
11
- // Optional variables
12
- if (process.env.TLS_REQUEST_KEY_PASSPHRASE) {
13
- assertEnvironment({ TLS_REQUEST_KEY_PASSPHRASE: envAssert.isString() });
14
- }
15
- } else if (process.env.TLS_SERVER_CERT) {
16
- // if no TLS Request setting, TLS Server setting is essential.
17
- assertEnvironment({ TLS_SERVER_KEY: envAssert.isPath() });
18
- assertEnvironment({ TLS_SERVER_CERT: envAssert.isPath() });
19
- assertEnvironment({ TLS_CA: envAssert.isPath() });
20
- // Optional variables
21
- if (process.env.TLS_SERVER_KEY_PASSPHRASE) {
22
- assertEnvironment({ TLS_SERVER_KEY_PASSPHRASE: envAssert.isString() });
23
- }
24
- }
25
- }
@@ -1 +0,0 @@
1
- export * from './tlsRequest';
@@ -1,63 +0,0 @@
1
- import path from 'path';
2
- import { AxiosRequestConfig } from 'axios';
3
- import { expect } from 'chai';
4
- import { tlsRequest } from './tlsRequest';
5
- import { Endpoint, EndpointAuthType, EndpointMethod } from 'entities/Endpoint';
6
- import { Server } from 'entities/Server';
7
- import { stubPubSub } from 'test';
8
- import { loadTlsConfig } from 'utils/tlsConfig';
9
-
10
- describe('utils - TLS Request', () => {
11
- let server: Server;
12
- const testPath = '/test';
13
- const success = { success: true };
14
- let option: AxiosRequestConfig;
15
-
16
- before(async () => {
17
- process.env.TLS_SERVER_KEY = path.resolve('certs/server.key');
18
- process.env.TLS_SERVER_CERT = path.resolve('certs/server.crt');
19
- process.env.TLS_CA = path.resolve('certs/ca.crt');
20
-
21
- const endpoint = new Endpoint({
22
- path: testPath,
23
- method: EndpointMethod.GET,
24
- authType: EndpointAuthType.TLS,
25
- handler: (request, response): void => {
26
- response.json(success);
27
- },
28
- validator: {}
29
- });
30
- server = new Server({ endpoints: [endpoint] });
31
-
32
- await server.init();
33
- });
34
-
35
- beforeEach(() => {
36
- delete process.env.TLS_REQUEST_KEY;
37
- delete process.env.TLS_REQUEST_CERT;
38
- delete process.env.TLS_REQUEST_CA;
39
- delete process.env.TLS_SERVER_KEY;
40
- delete process.env.TLS_SERVER_CERT;
41
- delete process.env.TLS_CA;
42
- option = {
43
- url: testPath,
44
- baseURL: `https://localhost:${process.env.PORT as string}`
45
- };
46
- stubPubSub();
47
- });
48
-
49
- after(async () => {
50
- await server.shutdown();
51
- });
52
-
53
- it('should successfully establish a TLS connection', async () => {
54
- process.env.TLS_REQUEST_KEY = path.resolve('certs/client.key');
55
- process.env.TLS_REQUEST_CERT = path.resolve('certs/client.crt');
56
- process.env.TLS_REQUEST_CA = path.resolve('certs/ca.crt');
57
-
58
- loadTlsConfig();
59
-
60
- const { data } = await tlsRequest(option);
61
- expect(data).to.deep.equal(success);
62
- });
63
- });
@@ -1,12 +0,0 @@
1
- import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
- import { request } from 'utils/request';
3
- import { httpsAgent, loadTlsConfig } from 'utils/tlsConfig';
4
-
5
- /** Make a network request using TLS, this exposes the server client certificates to the destination */
6
- export async function tlsRequest<T = unknown>(
7
- options: AxiosRequestConfig
8
- ): Promise<AxiosResponse<T>> {
9
- // if the config is not initial, will do that.
10
- if (!httpsAgent) loadTlsConfig();
11
- return request<T>({ httpsAgent, ...options });
12
- }
@@ -1 +0,0 @@
1
- export * from './trimPathSlash';
@@ -1,26 +0,0 @@
1
- import { expect } from 'chai';
2
- import { faker } from '@faker-js/faker';
3
- import { trimPathSlash } from './trimPathSlash';
4
-
5
- describe('Trim Path Slash', function () {
6
- it('should remove starting slash', function () {
7
- const result = trimPathSlash(`/${faker.lorem.word()}`);
8
- expect(result[0]).to.not.equal('/');
9
- });
10
-
11
- it('should remove ending slash', function () {
12
- const result = trimPathSlash(`${faker.lorem.word()}/`);
13
- expect(result[result.length]).to.not.equal('/');
14
- });
15
-
16
- it('should remove both slash', function () {
17
- const result = trimPathSlash(`/${faker.lorem.word()}/`);
18
- expect(result[0]).to.not.equal('/');
19
- expect(result[result.length]).to.not.equal('/');
20
- });
21
-
22
- it('should preserve slash in the string', function () {
23
- const result = trimPathSlash(`${faker.lorem.word()}/${faker.lorem.word()}`);
24
- expect(result).to.include('/');
25
- });
26
- });
@@ -1,8 +0,0 @@
1
- /**
2
- * Remove slashes if they are the first or last chars of a string
3
- * @param url - URL to which slashes should be stripped
4
- * @return Cleaned-up string
5
- */
6
- export function trimPathSlash(url: string): string {
7
- return url.replace(/\/$/, '').replace(/^\//, '');
8
- }