node-server-engine 1.4.8 → 1.5.0
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.
- package/.commitlintrc.js +27 -0
- package/.releaserc.js +56 -0
- package/README.md +154 -2
- package/dist/const/tokenIssuer.js +1 -0
- package/dist/const/tokenIssuer.js.map +1 -1
- package/dist/db/models/SequelizeMeta.js +3 -1
- package/dist/db/models/SequelizeMeta.js.map +1 -1
- package/dist/entities/ElasticSearch/ElasticSearch.js +1 -2
- package/dist/entities/ElasticSearch/ElasticSearch.js.map +1 -1
- package/dist/entities/SocketClient/SocketClient.js +1 -0
- package/dist/entities/SocketClient/SocketClient.js.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/middleware/checkPermission/checkPermission.d.ts +1 -1
- package/dist/middleware/checkPermission/checkPermission.js +4 -2
- package/dist/middleware/checkPermission/checkPermission.js.map +1 -1
- package/dist/utils/createHttpServer/createHttpServer.js +1 -1
- package/dist/utils/createHttpServer/createHttpServer.js.map +1 -1
- package/dist/utils/jwt/jwt.js +1 -1
- package/dist/utils/jwt/jwt.js.map +1 -1
- package/dist/utils/semverCompare/semverCompare.js +1 -5
- package/dist/utils/semverCompare/semverCompare.js.map +1 -1
- package/package.json +30 -19
- package/.env.example +0 -186
- package/.github/workflows/publish.yml +0 -41
- package/.prettierrc +0 -7
- package/Dockerfile +0 -31
- package/babel.config.json +0 -34
- package/eslint.config.mjs +0 -11
- package/src/const/DebeziumEvent.ts +0 -6
- package/src/const/LogSeverity.ts +0 -7
- package/src/const/index.ts +0 -5
- package/src/const/metrics.ts +0 -6
- package/src/const/mime.ts +0 -37
- package/src/const/tokenIssuer.ts +0 -7
- package/src/db/migrations/20241030121500-create-sequelize-meta-table.ts +0 -29
- package/src/db/models/SequelizeMeta.ts +0 -16
- package/src/db/models/index.ts +0 -2
- package/src/entities/ElasticSearch/ElasticSearch.ts +0 -103
- package/src/entities/ElasticSearch/ElasticSearch.types.ts +0 -7
- package/src/entities/ElasticSearch/index.ts +0 -2
- package/src/entities/Endpoint/Endpoint.test.ts +0 -248
- package/src/entities/Endpoint/Endpoint.ts +0 -221
- package/src/entities/Endpoint/Endpoint.types.ts +0 -181
- package/src/entities/Endpoint/index.ts +0 -2
- package/src/entities/EngineError/EngineError.ts +0 -28
- package/src/entities/EngineError/EngineError.types.ts +0 -15
- package/src/entities/EngineError/index.ts +0 -2
- package/src/entities/KeySet/KeySet.test.ts +0 -126
- package/src/entities/KeySet/KeySet.ts +0 -172
- package/src/entities/KeySet/KeySet.types.ts +0 -28
- package/src/entities/KeySet/index.ts +0 -2
- package/src/entities/LifecycleController/LifecycleController.test.ts +0 -48
- package/src/entities/LifecycleController/LifecycleController.ts +0 -24
- package/src/entities/LifecycleController/LifecycleController.types.ts +0 -5
- package/src/entities/LifecycleController/index.ts +0 -2
- package/src/entities/Localizator/Localizator.ts +0 -139
- package/src/entities/Localizator/Localizator.types.ts +0 -52
- package/src/entities/Localizator/guessNamingConvention/guessNamingConvention.test.ts +0 -165
- package/src/entities/Localizator/guessNamingConvention/guessNamingConvention.ts +0 -58
- package/src/entities/Localizator/guessNamingConvention/index.ts +0 -1
- package/src/entities/Localizator/index.ts +0 -2
- package/src/entities/MessageHandler/MessageHandler.test.ts +0 -130
- package/src/entities/MessageHandler/MessageHandler.ts +0 -72
- package/src/entities/MessageHandler/MessageHandler.types.ts +0 -15
- package/src/entities/MessageHandler/index.ts +0 -2
- package/src/entities/PubSub/PubSub.test.ts +0 -297
- package/src/entities/PubSub/PubSub.ts +0 -202
- package/src/entities/PubSub/PubSub.types.ts +0 -76
- package/src/entities/PubSub/handleMessage/handleMessage.test.ts +0 -102
- package/src/entities/PubSub/handleMessage/handleMessage.ts +0 -65
- package/src/entities/PubSub/handleMessage/index.ts +0 -1
- package/src/entities/PubSub/index.ts +0 -2
- package/src/entities/PushNotification/PushNotification.test.ts +0 -35
- package/src/entities/PushNotification/PushNotification.ts +0 -44
- package/src/entities/PushNotification/PushNotification.types.ts +0 -25
- package/src/entities/PushNotification/index.ts +0 -2
- package/src/entities/Redis/Redis.ts +0 -71
- package/src/entities/Redis/Redis.types.ts +0 -19
- package/src/entities/Redis/Redis.validate.ts +0 -17
- package/src/entities/Redis/index.ts +0 -2
- package/src/entities/Sequelize/Sequelize.config.ts +0 -59
- package/src/entities/Sequelize/Sequelize.test.ts +0 -21
- package/src/entities/Sequelize/Sequelize.ts +0 -75
- package/src/entities/Sequelize/Sequelize.types.ts +0 -10
- package/src/entities/Sequelize/Sequelize.validate.ts +0 -15
- package/src/entities/Sequelize/index.ts +0 -2
- package/src/entities/Server/Server.const.ts +0 -56
- package/src/entities/Server/Server.test.ts +0 -272
- package/src/entities/Server/Server.ts +0 -471
- package/src/entities/Server/Server.types.ts +0 -88
- package/src/entities/Server/index.ts +0 -2
- package/src/entities/SocketClient/SocketClient.test.ts +0 -392
- package/src/entities/SocketClient/SocketClient.ts +0 -401
- package/src/entities/SocketClient/SocketClient.types.ts +0 -62
- package/src/entities/SocketClient/index.ts +0 -2
- package/src/entities/SocketClient/parseMessage/index.ts +0 -1
- package/src/entities/SocketClient/parseMessage/parseMessage.test.ts +0 -20
- package/src/entities/SocketClient/parseMessage/parseMessage.ts +0 -26
- package/src/entities/Storage/Storage.test.ts +0 -58
- package/src/entities/Storage/Storage.ts +0 -219
- package/src/entities/Storage/Storage.types.ts +0 -57
- package/src/entities/Storage/index.ts +0 -2
- package/src/entities/ValidationError/ValidationError.ts +0 -34
- package/src/entities/ValidationError/index.ts +0 -1
- package/src/entities/WebError/WebError.test.ts +0 -18
- package/src/entities/WebError/WebError.ts +0 -23
- package/src/entities/WebError/WebError.types.ts +0 -9
- package/src/entities/WebError/index.ts +0 -2
- package/src/entities/index.ts +0 -16
- package/src/index.ts +0 -6
- package/src/metrics/debug.ts +0 -10
- package/src/metrics/index.ts +0 -2
- package/src/metrics/request.ts +0 -17
- package/src/middleware/authHmac/authHmac.test.ts +0 -86
- package/src/middleware/authHmac/authHmac.ts +0 -56
- package/src/middleware/authHmac/authHmac.types.ts +0 -7
- package/src/middleware/authHmac/index.ts +0 -2
- package/src/middleware/authJwt/authJwt.test.ts +0 -54
- package/src/middleware/authJwt/authJwt.ts +0 -55
- package/src/middleware/authJwt/authJwt.types.ts +0 -14
- package/src/middleware/authJwt/index.ts +0 -2
- package/src/middleware/authStatic/authStatic.test.ts +0 -36
- package/src/middleware/authStatic/authStatic.ts +0 -45
- package/src/middleware/authStatic/index.ts +0 -1
- package/src/middleware/authTls/authTls.test.ts +0 -138
- package/src/middleware/authTls/authTls.ts +0 -119
- package/src/middleware/authTls/authTls.types.ts +0 -13
- package/src/middleware/authTls/index.ts +0 -2
- package/src/middleware/checkPermission/checkPermission.ts +0 -33
- package/src/middleware/checkPermission/index.ts +0 -1
- package/src/middleware/error/error.test.ts +0 -60
- package/src/middleware/error/error.ts +0 -25
- package/src/middleware/error/index.ts +0 -1
- package/src/middleware/fileUploader/fileUploader.ts +0 -154
- package/src/middleware/fileUploader/fileUploader.types.ts +0 -35
- package/src/middleware/fileUploader/index.ts +0 -2
- package/src/middleware/fileUploader/isMultiPart/index.ts +0 -1
- package/src/middleware/fileUploader/isMultiPart/isMultipart.ts +0 -9
- package/src/middleware/fileUploader/validate/index.ts +0 -1
- package/src/middleware/fileUploader/validate/validate.ts +0 -27
- package/src/middleware/fourOhFour/fourOhFour.test.ts +0 -14
- package/src/middleware/fourOhFour/fourOhFour.ts +0 -13
- package/src/middleware/fourOhFour/index.ts +0 -1
- package/src/middleware/geminiFileUploader/geminiFileUploader.ts +0 -68
- package/src/middleware/geminiFileUploader/index.ts +0 -1
- package/src/middleware/healthCheck/healthCheck.test.ts +0 -12
- package/src/middleware/healthCheck/healthCheck.ts +0 -14
- package/src/middleware/healthCheck/index.ts +0 -1
- package/src/middleware/index.ts +0 -17
- package/src/middleware/metrics/index.ts +0 -1
- package/src/middleware/metrics/metrics.test.ts +0 -46
- package/src/middleware/metrics/metrics.ts +0 -24
- package/src/middleware/multiPartFileUploader/index.ts +0 -2
- package/src/middleware/multiPartFileUploader/multiPartFileUploader.ts +0 -249
- package/src/middleware/multiPartFileUploader/multiPartFileUploader.types.ts +0 -23
- package/src/middleware/multiPartFileUploader/validate/index.ts +0 -1
- package/src/middleware/multiPartFileUploader/validate/validate.ts +0 -27
- package/src/middleware/requestMetrics/index.ts +0 -1
- package/src/middleware/requestMetrics/requestMetrics.test.ts +0 -77
- package/src/middleware/requestMetrics/requestMetrics.ts +0 -20
- package/src/middleware/swaggerDocs/index.ts +0 -2
- package/src/middleware/swaggerDocs/swaggerDocs.ts +0 -114
- package/src/middleware/swaggerDocs/swaggerDocs.types.ts +0 -41
- package/src/middleware/userResolver/index.ts +0 -1
- package/src/middleware/userResolver/userResolver.ts +0 -53
- package/src/middleware/validate/index.ts +0 -1
- package/src/middleware/validate/validate.test.ts +0 -43
- package/src/middleware/validate/validate.ts +0 -25
- package/src/middleware/version/index.ts +0 -1
- package/src/middleware/version/version.test.ts +0 -23
- package/src/middleware/version/version.ts +0 -12
- package/src/utils/checkEnvironment/index.ts +0 -49
- package/src/utils/createHttpServer/createHttpServer.test.ts +0 -24
- package/src/utils/createHttpServer/createHttpServer.ts +0 -34
- package/src/utils/createHttpServer/createHttpServer.validate.ts +0 -17
- package/src/utils/createHttpServer/index.ts +0 -1
- package/src/utils/createSortedObject/createSortedObject.ts +0 -20
- package/src/utils/createSortedObject/createSortedObjet.test.ts +0 -47
- package/src/utils/createSortedObject/index.ts +0 -1
- package/src/utils/dbMigration/dbMigration.test.ts +0 -209
- package/src/utils/dbMigration/dbMigration.ts +0 -199
- package/src/utils/dbMigration/dbMigration.types.ts +0 -11
- package/src/utils/dbMigration/index.ts +0 -2
- package/src/utils/dbMigration/migrateMetadataTable/index.ts +0 -1
- package/src/utils/dbMigration/migrateMetadataTable/migrateMetadataTable.test.ts +0 -59
- package/src/utils/dbMigration/migrateMetadataTable/migrateMetadataTable.ts +0 -102
- package/src/utils/envAssert/envAssert.ts +0 -31
- package/src/utils/envAssert/index.ts +0 -1
- package/src/utils/envAssert/validators/hostList.ts +0 -17
- package/src/utils/envAssert/validators/index.ts +0 -5
- package/src/utils/envAssert/validators/ipList.ts +0 -13
- package/src/utils/envAssert/validators/path.ts +0 -13
- package/src/utils/envAssert/validators/string.ts +0 -9
- package/src/utils/envAssert/validators/stringList.ts +0 -13
- package/src/utils/filter/filter.ts +0 -17
- package/src/utils/filter/index.ts +0 -1
- package/src/utils/geminiFileUpload/geminiFileUpload.ts +0 -93
- package/src/utils/geminiFileUpload/index.ts +0 -1
- package/src/utils/hmac/checkEnv/checkEnv.test.ts +0 -18
- package/src/utils/hmac/checkEnv/checkEnv.ts +0 -9
- package/src/utils/hmac/checkEnv/index.ts +0 -1
- package/src/utils/hmac/createHmac/createHmac.ts +0 -33
- package/src/utils/hmac/createHmac/index.ts +0 -1
- package/src/utils/hmac/index.ts +0 -4
- package/src/utils/hmac/index.types.ts +0 -13
- package/src/utils/hmac/signPayload/index.ts +0 -1
- package/src/utils/hmac/signPayload/signPayload.ts +0 -16
- package/src/utils/hmac/verifySignature/index.ts +0 -1
- package/src/utils/hmac/verifySignature/verifySignature.ts +0 -24
- package/src/utils/index.ts +0 -29
- package/src/utils/jwt/index.ts +0 -2
- package/src/utils/jwt/jwt.test.ts +0 -28
- package/src/utils/jwt/jwt.ts +0 -182
- package/src/utils/jwt/jwt.types.ts +0 -21
- package/src/utils/report/index.ts +0 -3
- package/src/utils/report/output.ts +0 -45
- package/src/utils/report/output.types.ts +0 -70
- package/src/utils/report/report.test.ts +0 -133
- package/src/utils/report/report.ts +0 -133
- package/src/utils/report/report.types.ts +0 -13
- package/src/utils/request/index.ts +0 -1
- package/src/utils/request/request.test.ts +0 -26
- package/src/utils/request/request.ts +0 -48
- package/src/utils/secretManager/index.ts +0 -2
- package/src/utils/secretManager/secretLoader.ts +0 -62
- package/src/utils/secretManager/secretResolver.ts +0 -35
- package/src/utils/semverCompare/index.ts +0 -1
- package/src/utils/semverCompare/semverCompare.test.ts +0 -49
- package/src/utils/semverCompare/semverCompare.ts +0 -60
- package/src/utils/sendEmail/index.ts +0 -2
- package/src/utils/sendEmail/sendEmail.ts +0 -61
- package/src/utils/sendEmail/sendEmail.types.ts +0 -61
- package/src/utils/sendPush/index.ts +0 -2
- package/src/utils/sendPush/sendPush.ts +0 -20
- package/src/utils/sendPush/sendPush.types.ts +0 -25
- package/src/utils/tlsConfig/index.ts +0 -2
- package/src/utils/tlsConfig/tlsConfig.test.ts +0 -32
- package/src/utils/tlsConfig/tlsConfig.ts +0 -47
- package/src/utils/tlsConfig/tlsConfig.types.ts +0 -11
- package/src/utils/tlsConfig/tlsConfig.validate.ts +0 -25
- package/src/utils/tlsRequest/index.ts +0 -1
- package/src/utils/tlsRequest/tlsRequest.test.ts +0 -63
- package/src/utils/tlsRequest/tlsRequest.ts +0 -12
- package/src/utils/trimPathSlash/index.ts +0 -1
- package/src/utils/trimPathSlash/trimPathSlash.test.ts +0 -26
- package/src/utils/trimPathSlash/trimPathSlash.ts +0 -8
- package/test/env.ts +0 -53
- package/test/factory/index.ts +0 -8
- package/test/factory/sequelizeMeta.ts +0 -12
- package/test/hooks.ts +0 -35
- package/test/index.ts +0 -3
- package/test/stub/index.ts +0 -3
- package/test/stub/stubLocales.ts +0 -68
- package/test/stub/stubPubSub.ts +0 -7
- package/test/stub/stubStorage.ts +0 -77
- package/test/stub/stubStorage.types.ts +0 -11
- package/test/utils/app.ts +0 -31
- package/test/utils/index.ts +0 -1
- package/tsconfig.build.json +0 -5
- 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,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';
|
package/src/utils/hmac/index.ts
DELETED
|
@@ -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
|
-
}
|
package/src/utils/index.ts
DELETED
|
@@ -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';
|
package/src/utils/jwt/index.ts
DELETED
|
@@ -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
|
-
});
|