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,59 +0,0 @@
1
- // import {expect} from 'chai';
2
- // import { faker } from '@faker-js/faker';
3
- // import {QueryTypes} from 'sequelize';
4
- // import {testRecreateDB} from '../dbMigration';
5
- // import {migrateMetadataTable} from './migrateMetadataTable';
6
- // import {sequelize} from 'entities/Sequelize';
7
-
8
- // describe('Utils - DB Migration - Migrate Metadata Table', function () {
9
- // before(async () => {
10
- // sequelize.init();
11
- // await testRecreateDB({clean: true});
12
- // });
13
-
14
- // afterEach(async () => {
15
- // await testRecreateDB({clean: true});
16
- // });
17
-
18
- // // it('should create the metadata table if it does not exist', async () => {
19
- // // await migrateMetadataTable(sequelize);
20
-
21
- // // const tables = await sequelize.query<[string]>(
22
- // // "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'",
23
- // // {type: QueryTypes.SELECT},
24
- // // );
25
- // // const hasTable = tables.some((table) => table[0] === 'sequelize_meta');
26
- // // expect(hasTable).to.be.true;
27
- // // });
28
-
29
- // it('should copy legacy table data to the new table', async () => {
30
- // await sequelize.query('CREATE TABLE SequelizeMeta (name varchar(100) PRIMARY KEY)', {
31
- // type: QueryTypes.RAW,
32
- // });
33
-
34
- // const migrations = [faker.lorem.word(), faker.lorem.word(), faker.lorem.word()];
35
- // await sequelize.query(
36
- // `INSERT INTO "SequelizeMeta" ("name") VALUES ('${migrations[0]}'), ('${migrations[1]}'), ('${migrations[2]}')`,
37
- // {
38
- // type: QueryTypes.RAW,
39
- // },
40
- // );
41
-
42
- // await migrateMetadataTable(sequelize);
43
-
44
- // const results = await sequelize.query<{
45
- // /** Name of the migration */
46
- // name: string;
47
- // /** Version at which the migration was executed */
48
- // version: string;
49
- // }>('SELECT * FROM sequelize_meta', {
50
- // type: QueryTypes.SELECT,
51
- // });
52
-
53
- // expect(results).to.have.length(3);
54
- // results.forEach((result) => {
55
- // expect(migrations).to.include(result.name);
56
- // expect(result.version).to.be.null;
57
- // });
58
- // });
59
- // });
@@ -1,102 +0,0 @@
1
- import { Sequelize, QueryTypes } from 'sequelize';
2
- import { SequelizeMeta } from 'db/models';
3
- import { reportDebug } from 'utils/report';
4
-
5
- const namespace = 'engine:utils:dbMigration';
6
-
7
- /**
8
- * Run migrations on the metadata table
9
- * The table containing the migrations metadata cannot be handled through migrations
10
- * Therefore, we use a more classic approach with this function and pure SQL queries
11
- */
12
- export async function migrateMetadataTable(
13
- sequelize: Sequelize
14
- ): Promise<void> {
15
- reportDebug({ namespace, message: 'Executing metadata migration routine' });
16
-
17
- const query = `SELECT table_name FROM information_schema.tables`;
18
-
19
- // We check if we have a custom sequelize_meta table yet
20
- const tables = await sequelize.query<Array<string>>(query, {
21
- type: QueryTypes.SELECT
22
- });
23
-
24
- const hasCustomSequelizeMeta =
25
- process.env.SQL_TYPE === 'postgres'
26
- ? tables.some((table) => table[0] === 'sequelize_meta')
27
- : tables.some((table) => Object.values(table)[0] === 'sequelize_meta');
28
- const hasLegacySequelizeMeta =
29
- process.env.SQL_TYPE === 'postgres'
30
- ? tables.some((table) => table[0] === 'SequelizeMeta')
31
- : tables.some((table) => Object.values(table)[0] === 'SequelizeMeta');
32
- if (!hasCustomSequelizeMeta) {
33
- reportDebug({
34
- namespace,
35
- message: 'No metadata table found, creating new one'
36
- });
37
-
38
- // Define SQL for creating the table based on the database type
39
- let createTableQuery = '';
40
-
41
- switch (process.env.SQL_TYPE) {
42
- case 'mysql':
43
- case 'postgres':
44
- createTableQuery = `
45
- CREATE TABLE sequelize_meta (
46
- name VARCHAR(100) PRIMARY KEY,
47
- version VARCHAR(25),
48
- createdAt TIMESTAMP NOT NULL,
49
- updatedAt TIMESTAMP NOT NULL
50
- )`;
51
- break;
52
- case 'mssql':
53
- createTableQuery = `
54
- CREATE TABLE sequelize_meta (
55
- name VARCHAR(100) PRIMARY KEY,
56
- version VARCHAR(25),
57
- createdAt DATETIME NOT NULL,
58
- updatedAt DATETIME NOT NULL
59
- )`;
60
- break;
61
- default:
62
- throw new Error('Unsupported SQL type');
63
- }
64
-
65
- // Create the new sequelize_meta table if it does not exist
66
- await sequelize.query(createTableQuery, { type: QueryTypes.RAW });
67
-
68
- // Migrate the data from the old table to the new one if needed
69
- if (hasLegacySequelizeMeta) {
70
- reportDebug({
71
- namespace,
72
- message: 'Legacy metadata table found, migrating data'
73
- });
74
-
75
- const migrations = await sequelize.query<SequelizeMeta>(
76
- 'SELECT name FROM SequelizeMeta ORDER BY name',
77
- {
78
- type: QueryTypes.SELECT
79
- }
80
- );
81
-
82
- const insertQuery = `
83
- INSERT INTO sequelize_meta (name, version, createdAt, updatedAt) VALUES
84
- ${migrations
85
- .map((migration) => {
86
- switch (process.env.SQL_TYPE) {
87
- case 'mysql':
88
- case 'postgres':
89
- return `('${migration.name}', NULL, NOW(), NOW())`;
90
- case 'mssql':
91
- return `('${migration.name}', NULL, GETDATE(), GETDATE())`;
92
- default:
93
- throw new Error('Unsupported SQL type');
94
- }
95
- })
96
- .join(',')}
97
- `;
98
-
99
- await sequelize.query(insertQuery, { type: QueryTypes.INSERT });
100
- }
101
- }
102
- }
@@ -1,31 +0,0 @@
1
- import { bool, num, host, email, port, url, json } from 'envalid';
2
-
3
- import {
4
- envIsIpList,
5
- envIsPath,
6
- envIsHostList,
7
- envIsStringList,
8
- envIsString
9
- } from './validators';
10
-
11
- /**
12
- * envalid validators to use with checkEnvironment made with evalid.makeValidator and validator.js
13
- * is* functions. + Also Added isString, isHost, and isIPList.
14
- *
15
- *
16
- * envalid docs: https://github.com/af/envalid
17
- */
18
- export const envAssert = {
19
- isString: envIsString,
20
- isBoolean: bool,
21
- isNumber: num,
22
- isEmail: email,
23
- isHost: host,
24
- isPort: port,
25
- isURL: url,
26
- isJSON: json,
27
- isIPList: envIsIpList,
28
- isPath: envIsPath,
29
- isHostList: envIsHostList,
30
- isStringList: envIsStringList
31
- };
@@ -1 +0,0 @@
1
- export * from './envAssert';
@@ -1,17 +0,0 @@
1
- import { makeValidator } from 'envalid';
2
- import validator from 'validator';
3
-
4
- /**
5
- * Validate that a string is a list of comma separated host names
6
- */
7
- export const envIsHostList = makeValidator((value): boolean => {
8
- if (!value) throw new Error('expected a host name');
9
- const hosts = value.split(',');
10
- const valid = hosts.every(
11
- (host) =>
12
- validator.isIP(host.trim()) ||
13
- validator.isFQDN(host.trim(), { require_tld: false })
14
- );
15
- if (!valid) throw new Error('expected a host name');
16
- return valid;
17
- });
@@ -1,5 +0,0 @@
1
- export * from './ipList';
2
- export * from './path';
3
- export * from './hostList';
4
- export * from './stringList';
5
- export * from './string';
@@ -1,13 +0,0 @@
1
- import { makeValidator } from 'envalid';
2
- import validator from 'validator';
3
-
4
- /**
5
- * Validate that a string is a list of comma separated ip (V4/V6) addresses
6
- */
7
- export const envIsIpList = makeValidator((value): boolean => {
8
- if (!value) throw new Error('expected an ip address');
9
- const ips = value.split(',');
10
- const valid = ips.every((v) => validator.isIP(v));
11
- if (!valid) throw new Error('expected an ip address');
12
- return valid;
13
- });
@@ -1,13 +0,0 @@
1
- import { makeValidator } from 'envalid';
2
-
3
- const pathRegex = /^(\.\.\/(?:\.\.\/)*)?(?!.*?\/\/)(?!(?:.*\/)?\.+(?:\/|$)).+$/;
4
-
5
- /**
6
- * Validate that a string is a system path (linux only)
7
- */
8
- export const envIsPath = makeValidator((value): boolean => {
9
- if (!value) throw new Error('expected a path');
10
- const valid = pathRegex.test(value);
11
- if (!valid) throw new Error('expected a path');
12
- return valid;
13
- });
@@ -1,9 +0,0 @@
1
- import { makeValidator } from 'envalid';
2
-
3
- /**
4
- * Validate that aa value is a string
5
- */
6
- export const envIsString = makeValidator((value): boolean => {
7
- if (!value || typeof value !== 'string') throw new Error('expected a string');
8
- return value.length > 0;
9
- });
@@ -1,13 +0,0 @@
1
- import { makeValidator } from 'envalid';
2
-
3
- /**
4
- * Validate that a string is a list of comma separated strings
5
-
6
- */
7
- export const envIsStringList = makeValidator((value): boolean => {
8
- if (!value) throw new Error('expected a string');
9
- const strings = value.split(',');
10
- const valid = strings.every((v) => typeof v === 'string');
11
- if (!valid) throw new Error('expected a string');
12
- return valid;
13
- });
@@ -1,17 +0,0 @@
1
- /**
2
- * Filters an object, returns a copy of that object with only the keys specified in the whitelist
3
- * @param object - The object to filter
4
- * @param whitelist - A list of keys to keep
5
- */
6
- export function filter<T extends Record<string, unknown>>(
7
- object: T,
8
- whitelist: Array<string>
9
- ): T {
10
- const copy: Record<string, unknown> = {};
11
- for (const key of Object.keys(object)) {
12
- if (whitelist.includes(key)) {
13
- copy[key] = object[key];
14
- }
15
- }
16
- return copy as T;
17
- }
@@ -1 +0,0 @@
1
- export * from './filter';
@@ -1,93 +0,0 @@
1
- import { GoogleAIFileManager } from '@google/generative-ai/server';
2
- import fs from 'fs';
3
- import path from 'path';
4
- import tmp from 'tmp';
5
- import { reportError, reportDebug } from 'utils/report';
6
-
7
- const namespace = 'engine:utils:geminiFileUpload';
8
-
9
- const fileManager = new GoogleAIFileManager(process.env.GOOGLE_AI_KEY || '');
10
-
11
- export async function geminiFileUpload(
12
- buffer: Buffer,
13
- mimeType: string,
14
- originalName: string
15
- ): Promise<
16
- | { success: true; originalname: string; fileUri: string; mimeType: string }
17
- | { success: false; error: unknown }
18
- > {
19
- let tempFile;
20
- try {
21
- // 1. Create Temp File
22
- tempFile = tmp.fileSync({ postfix: path.extname(originalName) });
23
- fs.writeFileSync(tempFile.name, buffer);
24
-
25
- // 2. Upload File
26
- const uploadResult = await fileManager.uploadFile(tempFile.name, {
27
- mimeType,
28
- displayName: originalName
29
- });
30
-
31
- if (!uploadResult || !uploadResult.file) {
32
- throw new Error('Upload failed: No file returned');
33
- }
34
-
35
- const file = uploadResult.file;
36
- reportDebug({
37
- namespace,
38
- message: 'Uploaded file successfully',
39
- data: { displayName: file.displayName, name: file.name }
40
- });
41
-
42
- reportDebug({
43
- namespace,
44
- message: 'Waiting for file processing...'
45
- });
46
-
47
- // 3. Poll Until File is Processed
48
- let geminiFile = await fileManager.getFile(file.name);
49
- while (geminiFile?.state === 'PROCESSING') {
50
- process.stdout.write('.');
51
- await new Promise((resolve) => setTimeout(resolve, 10000));
52
- geminiFile = await fileManager.getFile(file.name);
53
- }
54
-
55
- if (!geminiFile || geminiFile.state !== 'ACTIVE') {
56
- const errorMessage = `File processing failed for ${file.name}`;
57
- reportError(errorMessage);
58
- return { success: false, error: new Error(errorMessage) };
59
- }
60
-
61
- reportDebug({
62
- namespace,
63
- message: 'File is ready'
64
- });
65
-
66
- return {
67
- success: true,
68
- originalname: file.name,
69
- fileUri: file.uri,
70
- mimeType: file.mimeType
71
- };
72
- } catch (error) {
73
- reportError({
74
- namespace,
75
- message: 'Error during Gemini file upload and processing',
76
- error
77
- });
78
- return { success: false, error };
79
- } finally {
80
- // Ensure cleanup of temp file
81
- if (tempFile) {
82
- try {
83
- tempFile.removeCallback();
84
- } catch (cleanupError) {
85
- reportError({
86
- namespace,
87
- message: 'Error cleaning up temp file',
88
- error: cleanupError
89
- });
90
- }
91
- }
92
- }
93
- }
@@ -1 +0,0 @@
1
- export * from './geminiFileUpload';
@@ -1,18 +0,0 @@
1
- import { expect } from 'chai';
2
- import { assertPayloadSignatureSecret } from './checkEnv';
3
-
4
- describe('Utils - HMAC - Check environment', () => {
5
- it('should pass if environment variables are set', () => {
6
- process.env.PAYLOAD_SIGNATURE_SECRET = 'secret';
7
- expect(() => {
8
- assertPayloadSignatureSecret();
9
- }).to.not.throw();
10
- });
11
-
12
- it('should throw an error if the environment vairable is not set', () => {
13
- delete process.env.PAYLOAD_SIGNATURE_SECRET;
14
- expect(() => {
15
- assertPayloadSignatureSecret();
16
- }).to.throw();
17
- });
18
- });
@@ -1,9 +0,0 @@
1
- import { assertEnvironment } from 'utils/checkEnvironment';
2
- import { envAssert } from 'utils/envAssert';
3
-
4
- /**
5
- * Check that secret used to sign payloads is properly set in the environment
6
- */
7
- export function assertPayloadSignatureSecret(): void {
8
- assertEnvironment({ PAYLOAD_SIGNATURE_SECRET: envAssert.isString() });
9
- }
@@ -1 +0,0 @@
1
- export * from './checkEnv';
@@ -1,33 +0,0 @@
1
- import crypto from 'crypto';
2
- import { assertPayloadSignatureSecret } from '../checkEnv';
3
- import { HmacOptions } from '../index.types';
4
- import { createSortedObject } from 'utils/createSortedObject';
5
-
6
- /** Calculates the HMAC signature for a given payload */
7
- export function createHmac(
8
- payload: unknown,
9
- options: HmacOptions = {}
10
- ): Buffer | string {
11
- // Check env if no secret is specified
12
- if (!options.secret) {
13
- assertPayloadSignatureSecret();
14
- }
15
- // Set default values
16
- const settings = {
17
- algorithm: options.algorithm ?? 'sha512',
18
- sort: options.sort ?? true,
19
- encode: options.encode,
20
- secret: options.secret ?? (process.env.PAYLOAD_SIGNATURE_SECRET as string)
21
- };
22
-
23
- // Stringify the payload
24
- const sortedPayload = settings.sort ? createSortedObject(payload) : payload;
25
- const stringifiedPayload = JSON.stringify(sortedPayload);
26
-
27
- // Calculate the hash
28
- const hmac = crypto
29
- .createHmac(settings.algorithm, settings.secret)
30
- .update(stringifiedPayload);
31
-
32
- return settings.encode ? hmac.digest(settings.encode) : hmac.digest();
33
- }
@@ -1 +0,0 @@
1
- export * from './createHmac';
@@ -1,4 +0,0 @@
1
- export * from './signPayload';
2
- export * from './verifySignature';
3
- export * from './createHmac';
4
- export * from './index.types';
@@ -1,13 +0,0 @@
1
- import { BinaryToTextEncoding } from 'crypto';
2
-
3
- /** HMAC calculation options */
4
- export interface HmacOptions {
5
- /** Secret used to sign the payload */
6
- secret?: string;
7
- /** Hashing algorithm to use (default: SHA-512) */
8
- algorithm?: string;
9
- /** Should the object keys be sorted alphabetically (default: true) */
10
- sort?: boolean;
11
- /** The encoding of the signature (default: base64) */
12
- encode?: BinaryToTextEncoding;
13
- }
@@ -1 +0,0 @@
1
- export * from './signPayload';
@@ -1,16 +0,0 @@
1
- import { createHmac } from '../createHmac';
2
- import { HmacOptions } from '../index.types';
3
-
4
- /** Add signature to a payload */
5
- export function signPayload<T>(
6
- payload: T,
7
- options: HmacOptions = {}
8
- ): T & {
9
- /** HMAC signature of the payload */
10
- signature: string;
11
- } {
12
- return {
13
- ...payload,
14
- signature: createHmac(payload, { ...options, encode: 'base64' }) as string
15
- };
16
- }
@@ -1 +0,0 @@
1
- export * from './verifySignature';
@@ -1,24 +0,0 @@
1
- import crypto from 'crypto';
2
- import { createHmac } from '../createHmac';
3
- import { HmacOptions } from '../index.types';
4
-
5
- /** Checks the signature of a payload */
6
- export function verifySignature(
7
- payload: Record<string, unknown>,
8
- signature: string,
9
- options: HmacOptions = {}
10
- ): boolean {
11
- if (!payload || !signature) return false;
12
- // Obtain a buffer digest
13
- const digest = createHmac(payload, {
14
- ...options,
15
- encode: undefined
16
- }) as Buffer;
17
- // Transform the signature to buffer
18
- const checksum = Buffer.from(signature, options.encode ?? 'base64');
19
- // Compare signature with the calculated digest
20
- return (
21
- checksum.length === digest.length &&
22
- crypto.timingSafeEqual(digest, checksum)
23
- );
24
- }
@@ -1,29 +0,0 @@
1
- // general
2
- export * from './report';
3
- export * from './filter';
4
- export * from './semverCompare';
5
- export * from './dbMigration';
6
-
7
- // env
8
- export * from './checkEnvironment';
9
- export * from './envAssert';
10
-
11
- // auth
12
- export * from './createSortedObject';
13
- export * from './jwt';
14
- export * from './hmac';
15
-
16
- // Networking
17
- export * from './createHttpServer';
18
- export * from './request';
19
- export * from './tlsConfig';
20
- export * from './sendPush';
21
- export * from './sendEmail';
22
-
23
- // String manipulation
24
- export * from './trimPathSlash';
25
-
26
- export * from './secretManager';
27
-
28
- // File Upload
29
- export * from './geminiFileUpload';
@@ -1,2 +0,0 @@
1
- export * from './jwt';
2
- export * from './jwt.types';
@@ -1,28 +0,0 @@
1
- import { randomUUID } from 'crypto';
2
- import { generateAccessToken } from 'backend-test-tools';
3
- import { expect } from 'chai';
4
- import { faker } from '@faker-js/faker';
5
- import { jwtVerify } from './jwt';
6
- import { TokenIssuer } from 'const';
7
-
8
- describe('Utils - JWT', () => {
9
- it('should pass a default token', async () => {
10
- const id = randomUUID();
11
- const token = generateAccessToken(id);
12
- const result = await jwtVerify(token);
13
- expect(result.sub).to.equal(id);
14
- });
15
-
16
- it('should pass a token with one correct audience [Auth-service]', async () => {
17
- const id = randomUUID();
18
- const token = generateAccessToken(id, {
19
- audience: [
20
- process.env.ACCESS_TOKEN_AUDIENCE as string,
21
- faker.lorem.word()
22
- ],
23
- issuer: process.env.ACCESS_TOKEN_ISSUER
24
- });
25
- const result = await jwtVerify(token, TokenIssuer.AUTH_SERVICE);
26
- expect(result.sub).to.equal(id);
27
- });
28
- });