node-server-engine 1.1.2 → 1.1.3
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/.env.example +193 -193
- package/.mocharc.js +13 -13
- package/.nycrc +18 -18
- package/.prettierrc +7 -7
- package/Dockerfile +30 -30
- package/README.md +991 -1025
- package/babel.config.json +35 -35
- package/dist/const/DebeziumEvent.js.map +1 -1
- package/dist/const/LogSeverity.js.map +1 -1
- package/dist/const/index.js.map +1 -1
- package/dist/const/metrics.js.map +1 -1
- package/dist/const/mime.js.map +1 -1
- package/dist/const/tokenIssuer.js.map +1 -1
- package/dist/db/migrations/20241030121500-create-sequelize-meta-table.js.map +1 -1
- package/dist/db/models/SequelizeMeta.js.map +1 -1
- package/dist/db/models/index.js.map +1 -1
- package/dist/entities/ElasticSearch/ElasticSearch.js +7 -7
- package/dist/entities/ElasticSearch/ElasticSearch.js.map +1 -1
- package/dist/entities/ElasticSearch/ElasticSearch.types.js.map +1 -1
- package/dist/entities/ElasticSearch/index.js.map +1 -1
- package/dist/entities/Endpoint/Endpoint.js +8 -8
- package/dist/entities/Endpoint/Endpoint.js.map +1 -1
- package/dist/entities/Endpoint/Endpoint.types.js.map +1 -1
- package/dist/entities/Endpoint/index.js.map +1 -1
- package/dist/entities/EngineError/EngineError.js +2 -2
- package/dist/entities/EngineError/EngineError.js.map +1 -1
- package/dist/entities/EngineError/EngineError.types.js.map +1 -1
- package/dist/entities/EngineError/index.js.map +1 -1
- package/dist/entities/KeySet/KeySet.js +3 -3
- package/dist/entities/KeySet/KeySet.js.map +1 -1
- package/dist/entities/KeySet/KeySet.types.js.map +1 -1
- package/dist/entities/KeySet/index.js.map +1 -1
- package/dist/entities/LifecycleController/LifecycleController.js.map +1 -1
- package/dist/entities/LifecycleController/LifecycleController.types.js.map +1 -1
- package/dist/entities/LifecycleController/index.js.map +1 -1
- package/dist/entities/Localizator/Localizator.js +7 -7
- package/dist/entities/Localizator/Localizator.js.map +1 -1
- package/dist/entities/Localizator/Localizator.types.js.map +1 -1
- package/dist/entities/Localizator/guessNamingConvention/guessNamingConvention.js.map +1 -1
- package/dist/entities/Localizator/guessNamingConvention/index.js.map +1 -1
- package/dist/entities/Localizator/index.js.map +1 -1
- package/dist/entities/MessageHandler/MessageHandler.js +2 -2
- package/dist/entities/MessageHandler/MessageHandler.js.map +1 -1
- package/dist/entities/MessageHandler/MessageHandler.types.js.map +1 -1
- package/dist/entities/MessageHandler/index.js.map +1 -1
- package/dist/entities/PubSub/PubSub.js +25 -25
- package/dist/entities/PubSub/PubSub.js.map +1 -1
- package/dist/entities/PubSub/PubSub.types.js.map +1 -1
- package/dist/entities/PubSub/handleMessage/handleMessage.js +6 -6
- package/dist/entities/PubSub/handleMessage/handleMessage.js.map +1 -1
- package/dist/entities/PubSub/handleMessage/index.js.map +1 -1
- package/dist/entities/PubSub/index.js.map +1 -1
- package/dist/entities/PushNotification/PushNotification.js +4 -4
- package/dist/entities/PushNotification/PushNotification.js.map +1 -1
- package/dist/entities/PushNotification/PushNotification.types.js.map +1 -1
- package/dist/entities/PushNotification/index.js.map +1 -1
- package/dist/entities/Redis/Redis.js +8 -8
- package/dist/entities/Redis/Redis.js.map +1 -1
- package/dist/entities/Redis/Redis.types.js.map +1 -1
- package/dist/entities/Redis/Redis.validate.js +2 -2
- package/dist/entities/Redis/Redis.validate.js.map +1 -1
- package/dist/entities/Redis/index.js.map +1 -1
- package/dist/entities/Sequelize/Sequelize.config.js +42 -2
- package/dist/entities/Sequelize/Sequelize.config.js.map +1 -1
- package/dist/entities/Sequelize/Sequelize.js +3 -3
- package/dist/entities/Sequelize/Sequelize.js.map +1 -1
- package/dist/entities/Sequelize/Sequelize.types.js.map +1 -1
- package/dist/entities/Sequelize/Sequelize.validate.js +2 -2
- package/dist/entities/Sequelize/Sequelize.validate.js.map +1 -1
- package/dist/entities/Sequelize/index.js.map +1 -1
- package/dist/entities/Server/Server.const.js.map +1 -1
- package/dist/entities/Server/Server.js +2 -2
- package/dist/entities/Server/Server.js.map +1 -1
- package/dist/entities/Server/Server.types.js.map +1 -1
- package/dist/entities/Server/index.js.map +1 -1
- package/dist/entities/SocketClient/SocketClient.js +15 -15
- package/dist/entities/SocketClient/SocketClient.js.map +1 -1
- package/dist/entities/SocketClient/SocketClient.types.js.map +1 -1
- package/dist/entities/SocketClient/index.js.map +1 -1
- package/dist/entities/SocketClient/parseMessage/index.js.map +1 -1
- package/dist/entities/SocketClient/parseMessage/parseMessage.js +2 -2
- package/dist/entities/SocketClient/parseMessage/parseMessage.js.map +1 -1
- package/dist/entities/Storage/Storage.js +20 -20
- package/dist/entities/Storage/Storage.js.map +1 -1
- package/dist/entities/Storage/Storage.types.js.map +1 -1
- package/dist/entities/Storage/index.js.map +1 -1
- package/dist/entities/ValidationError/ValidationError.js.map +1 -1
- package/dist/entities/ValidationError/index.js.map +1 -1
- package/dist/entities/WebError/WebError.js +4 -4
- package/dist/entities/WebError/WebError.js.map +1 -1
- package/dist/entities/WebError/WebError.types.js.map +1 -1
- package/dist/entities/WebError/index.js.map +1 -1
- package/dist/entities/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/metrics/debug.js.map +1 -1
- package/dist/metrics/index.js.map +1 -1
- package/dist/metrics/request.js.map +1 -1
- package/dist/middleware/authAdmin/authAdmin.js.map +1 -1
- package/dist/middleware/authAdmin/authAdmin.types.js.map +1 -1
- package/dist/middleware/authAdmin/index.js.map +1 -1
- package/dist/middleware/authHmac/authHmac.js.map +1 -1
- package/dist/middleware/authHmac/authHmac.types.js.map +1 -1
- package/dist/middleware/authHmac/index.js.map +1 -1
- package/dist/middleware/authJwt/authJwt.js.map +1 -1
- package/dist/middleware/authJwt/authJwt.types.js.map +1 -1
- package/dist/middleware/authJwt/index.js.map +1 -1
- package/dist/middleware/authStatic/authStatic.js +3 -3
- package/dist/middleware/authStatic/authStatic.js.map +1 -1
- package/dist/middleware/authStatic/index.js.map +1 -1
- package/dist/middleware/authTls/authTls.js +8 -8
- package/dist/middleware/authTls/authTls.js.map +1 -1
- package/dist/middleware/authTls/authTls.types.js.map +1 -1
- package/dist/middleware/authTls/index.js.map +1 -1
- package/dist/middleware/checkPermission/checkPermission.js.map +1 -1
- package/dist/middleware/error/error.js.map +1 -1
- package/dist/middleware/error/index.js.map +1 -1
- package/dist/middleware/fileUploader/compressAvatar/compressAvatar.js +2 -2
- package/dist/middleware/fileUploader/compressAvatar/compressAvatar.js.map +1 -1
- package/dist/middleware/fileUploader/compressAvatar/compressAvatar.types.js.map +1 -1
- package/dist/middleware/fileUploader/compressAvatar/index.js.map +1 -1
- package/dist/middleware/fileUploader/fileUploader.js +12 -12
- package/dist/middleware/fileUploader/fileUploader.js.map +1 -1
- package/dist/middleware/fileUploader/fileUploader.types.js.map +1 -1
- package/dist/middleware/fileUploader/index.js.map +1 -1
- package/dist/middleware/fileUploader/isMultiPart/index.js.map +1 -1
- package/dist/middleware/fileUploader/isMultiPart/isMultipart.js.map +1 -1
- package/dist/middleware/fileUploader/validate/index.js.map +1 -1
- package/dist/middleware/fileUploader/validate/validate.js.map +1 -1
- package/dist/middleware/fourOhFour/fourOhFour.js.map +1 -1
- package/dist/middleware/fourOhFour/index.js.map +1 -1
- package/dist/middleware/geminiFileUploader/geminiFileUploader.js.map +1 -1
- package/dist/middleware/geminiFileUploader/index.js.map +1 -1
- package/dist/middleware/healthCheck/healthCheck.js +2 -2
- package/dist/middleware/healthCheck/healthCheck.js.map +1 -1
- package/dist/middleware/healthCheck/index.js.map +1 -1
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/metrics/index.js.map +1 -1
- package/dist/middleware/metrics/metrics.js.map +1 -1
- package/dist/middleware/requestMetrics/index.js.map +1 -1
- package/dist/middleware/requestMetrics/requestMetrics.js.map +1 -1
- package/dist/middleware/swaggerDocs/index.js.map +1 -1
- package/dist/middleware/swaggerDocs/swaggerDocs.js +7 -7
- package/dist/middleware/swaggerDocs/swaggerDocs.js.map +1 -1
- package/dist/middleware/swaggerDocs/swaggerDocs.types.js.map +1 -1
- package/dist/middleware/userResolver/index.js.map +1 -1
- package/dist/middleware/userResolver/userResolver.js.map +1 -1
- package/dist/middleware/validate/index.js.map +1 -1
- package/dist/middleware/validate/validate.js.map +1 -1
- package/dist/middleware/version/index.js.map +1 -1
- package/dist/middleware/version/version.js +3 -3
- package/dist/middleware/version/version.js.map +1 -1
- package/dist/utils/checkEnvironment/index.js +13 -13
- package/dist/utils/checkEnvironment/index.js.map +1 -1
- package/dist/utils/createHttpServer/createHttpServer.js.map +1 -1
- package/dist/utils/createHttpServer/createHttpServer.validate.js +2 -2
- package/dist/utils/createHttpServer/createHttpServer.validate.js.map +1 -1
- package/dist/utils/createHttpServer/index.js.map +1 -1
- package/dist/utils/createSortedObject/createSortedObject.js.map +1 -1
- package/dist/utils/createSortedObject/index.js.map +1 -1
- package/dist/utils/dbMigration/dbMigration.js +8 -8
- package/dist/utils/dbMigration/dbMigration.js.map +1 -1
- package/dist/utils/dbMigration/dbMigration.types.js.map +1 -1
- package/dist/utils/dbMigration/index.js.map +1 -1
- package/dist/utils/dbMigration/migrateMetadataTable/index.js.map +1 -1
- package/dist/utils/dbMigration/migrateMetadataTable/migrateMetadataTable.d.ts +2 -2
- package/dist/utils/dbMigration/migrateMetadataTable/migrateMetadataTable.js +47 -15
- package/dist/utils/dbMigration/migrateMetadataTable/migrateMetadataTable.js.map +1 -1
- package/dist/utils/envAssert/envAssert.js +6 -6
- package/dist/utils/envAssert/envAssert.js.map +1 -1
- package/dist/utils/envAssert/index.js.map +1 -1
- package/dist/utils/envAssert/validators/hostList.js +2 -2
- package/dist/utils/envAssert/validators/hostList.js.map +1 -1
- package/dist/utils/envAssert/validators/index.js.map +1 -1
- package/dist/utils/envAssert/validators/ipList.js +2 -2
- package/dist/utils/envAssert/validators/ipList.js.map +1 -1
- package/dist/utils/envAssert/validators/path.js +2 -2
- package/dist/utils/envAssert/validators/path.js.map +1 -1
- package/dist/utils/envAssert/validators/string.js +2 -2
- package/dist/utils/envAssert/validators/string.js.map +1 -1
- package/dist/utils/envAssert/validators/stringList.js +3 -3
- package/dist/utils/envAssert/validators/stringList.js.map +1 -1
- package/dist/utils/filter/filter.js +4 -4
- package/dist/utils/filter/filter.js.map +1 -1
- package/dist/utils/filter/index.js.map +1 -1
- package/dist/utils/getDynamicLink/getDynamicLink.js.map +1 -1
- package/dist/utils/getDynamicLink/getDynamicLink.types.js.map +1 -1
- package/dist/utils/getDynamicLink/getDynamicLink.validate.js.map +1 -1
- package/dist/utils/getDynamicLink/index.js.map +1 -1
- package/dist/utils/hmac/checkEnv/checkEnv.js +2 -2
- package/dist/utils/hmac/checkEnv/checkEnv.js.map +1 -1
- package/dist/utils/hmac/checkEnv/index.js.map +1 -1
- package/dist/utils/hmac/createHmac/createHmac.js.map +1 -1
- package/dist/utils/hmac/createHmac/index.js.map +1 -1
- package/dist/utils/hmac/index.js.map +1 -1
- package/dist/utils/hmac/index.types.js.map +1 -1
- package/dist/utils/hmac/signPayload/index.js.map +1 -1
- package/dist/utils/hmac/signPayload/signPayload.js.map +1 -1
- package/dist/utils/hmac/verifySignature/index.js.map +1 -1
- package/dist/utils/hmac/verifySignature/verifySignature.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/jwt/index.js.map +1 -1
- package/dist/utils/jwt/jwt.js.map +1 -1
- package/dist/utils/jwt/jwt.types.js.map +1 -1
- package/dist/utils/report/index.js.map +1 -1
- package/dist/utils/report/output.js.map +1 -1
- package/dist/utils/report/output.types.js.map +1 -1
- package/dist/utils/report/report.js.map +1 -1
- package/dist/utils/report/report.types.js.map +1 -1
- package/dist/utils/request/index.js.map +1 -1
- package/dist/utils/request/request.js.map +1 -1
- package/dist/utils/semverCompare/index.js.map +1 -1
- package/dist/utils/semverCompare/semverCompare.js +5 -5
- package/dist/utils/semverCompare/semverCompare.js.map +1 -1
- package/dist/utils/sendEmail/index.js.map +1 -1
- package/dist/utils/sendEmail/sendEmail.js +8 -8
- package/dist/utils/sendEmail/sendEmail.js.map +1 -1
- package/dist/utils/sendEmail/sendEmail.types.js.map +1 -1
- package/dist/utils/sendPush/index.js.map +1 -1
- package/dist/utils/sendPush/sendPush.js +5 -5
- package/dist/utils/sendPush/sendPush.js.map +1 -1
- package/dist/utils/sendPush/sendPush.types.js.map +1 -1
- package/dist/utils/tlsConfig/index.js.map +1 -1
- package/dist/utils/tlsConfig/tlsConfig.js +2 -2
- package/dist/utils/tlsConfig/tlsConfig.js.map +1 -1
- package/dist/utils/tlsConfig/tlsConfig.types.js.map +1 -1
- package/dist/utils/tlsConfig/tlsConfig.validate.js +2 -2
- package/dist/utils/tlsConfig/tlsConfig.validate.js.map +1 -1
- package/dist/utils/tlsRequest/index.js.map +1 -1
- package/dist/utils/tlsRequest/tlsRequest.js.map +1 -1
- package/dist/utils/trimPathSlash/index.js.map +1 -1
- package/dist/utils/trimPathSlash/trimPathSlash.js +4 -4
- package/dist/utils/trimPathSlash/trimPathSlash.js.map +1 -1
- package/eslint.config.mjs +11 -11
- package/package.json +164 -161
- package/src/const/DebeziumEvent.ts +6 -6
- package/src/const/LogSeverity.ts +7 -7
- package/src/const/index.ts +5 -5
- package/src/const/metrics.ts +6 -6
- package/src/const/mime.ts +37 -37
- package/src/const/tokenIssuer.ts +9 -9
- package/src/db/migrations/20241030121500-create-sequelize-meta-table.ts +29 -29
- package/src/db/models/SequelizeMeta.ts +16 -16
- package/src/db/models/index.ts +2 -2
- package/src/entities/ElasticSearch/ElasticSearch.ts +103 -103
- package/src/entities/ElasticSearch/ElasticSearch.types.ts +7 -7
- package/src/entities/ElasticSearch/index.ts +2 -2
- package/src/entities/Endpoint/Endpoint.test.ts +337 -337
- package/src/entities/Endpoint/Endpoint.ts +202 -202
- package/src/entities/Endpoint/Endpoint.types.ts +205 -205
- package/src/entities/Endpoint/index.ts +2 -2
- package/src/entities/EngineError/EngineError.ts +28 -28
- package/src/entities/EngineError/EngineError.types.ts +15 -15
- package/src/entities/EngineError/index.ts +2 -2
- package/src/entities/KeySet/KeySet.test.ts +126 -126
- package/src/entities/KeySet/KeySet.ts +172 -172
- package/src/entities/KeySet/KeySet.types.ts +28 -28
- package/src/entities/KeySet/index.ts +2 -2
- package/src/entities/LifecycleController/LifecycleController.test.ts +48 -48
- package/src/entities/LifecycleController/LifecycleController.ts +24 -24
- package/src/entities/LifecycleController/LifecycleController.types.ts +5 -5
- package/src/entities/LifecycleController/index.ts +2 -2
- package/src/entities/Localizator/Localizator.ts +139 -139
- package/src/entities/Localizator/Localizator.types.ts +52 -52
- package/src/entities/Localizator/guessNamingConvention/guessNamingConvention.test.ts +165 -165
- package/src/entities/Localizator/guessNamingConvention/guessNamingConvention.ts +58 -58
- package/src/entities/Localizator/guessNamingConvention/index.ts +1 -1
- package/src/entities/Localizator/index.ts +2 -2
- package/src/entities/MessageHandler/MessageHandler.test.ts +130 -130
- package/src/entities/MessageHandler/MessageHandler.ts +72 -72
- package/src/entities/MessageHandler/MessageHandler.types.ts +15 -15
- package/src/entities/MessageHandler/index.ts +2 -2
- package/src/entities/PubSub/PubSub.test.ts +297 -297
- package/src/entities/PubSub/PubSub.ts +202 -202
- package/src/entities/PubSub/PubSub.types.ts +76 -76
- package/src/entities/PubSub/handleMessage/handleMessage.test.ts +102 -102
- package/src/entities/PubSub/handleMessage/handleMessage.ts +65 -65
- package/src/entities/PubSub/handleMessage/index.ts +1 -1
- package/src/entities/PubSub/index.ts +2 -2
- package/src/entities/PushNotification/PushNotification.test.ts +35 -35
- package/src/entities/PushNotification/PushNotification.ts +44 -44
- package/src/entities/PushNotification/PushNotification.types.ts +25 -25
- package/src/entities/PushNotification/index.ts +2 -2
- package/src/entities/Redis/Redis.ts +71 -71
- package/src/entities/Redis/Redis.types.ts +19 -19
- package/src/entities/Redis/Redis.validate.ts +17 -17
- package/src/entities/Redis/index.ts +2 -2
- package/src/entities/Sequelize/Sequelize.config.ts +59 -29
- package/src/entities/Sequelize/Sequelize.test.ts +21 -21
- package/src/entities/Sequelize/Sequelize.ts +75 -75
- package/src/entities/Sequelize/Sequelize.types.ts +10 -10
- package/src/entities/Sequelize/Sequelize.validate.ts +15 -15
- package/src/entities/Sequelize/index.ts +2 -2
- package/src/entities/Server/Server.const.ts +56 -56
- package/src/entities/Server/Server.test.ts +272 -272
- package/src/entities/Server/Server.ts +445 -445
- package/src/entities/Server/Server.types.ts +88 -88
- package/src/entities/Server/index.ts +2 -2
- package/src/entities/SocketClient/SocketClient.test.ts +392 -392
- package/src/entities/SocketClient/SocketClient.ts +401 -401
- package/src/entities/SocketClient/SocketClient.types.ts +62 -62
- package/src/entities/SocketClient/index.ts +2 -2
- package/src/entities/SocketClient/parseMessage/index.ts +1 -1
- package/src/entities/SocketClient/parseMessage/parseMessage.test.ts +20 -20
- package/src/entities/SocketClient/parseMessage/parseMessage.ts +26 -26
- package/src/entities/Storage/Storage.test.ts +58 -58
- package/src/entities/Storage/Storage.ts +219 -219
- package/src/entities/Storage/Storage.types.ts +57 -57
- package/src/entities/Storage/index.ts +2 -2
- package/src/entities/ValidationError/ValidationError.ts +34 -34
- package/src/entities/ValidationError/index.ts +1 -1
- package/src/entities/WebError/WebError.test.ts +18 -18
- package/src/entities/WebError/WebError.ts +23 -23
- package/src/entities/WebError/WebError.types.ts +9 -9
- package/src/entities/WebError/index.ts +2 -2
- package/src/entities/index.ts +16 -16
- package/src/index.ts +4 -4
- package/src/metrics/debug.ts +10 -10
- package/src/metrics/index.ts +2 -2
- package/src/metrics/request.ts +17 -17
- package/src/middleware/authAdmin/authAdmin.test.ts +199 -199
- package/src/middleware/authAdmin/authAdmin.ts +114 -114
- package/src/middleware/authAdmin/authAdmin.types.ts +19 -19
- package/src/middleware/authAdmin/index.ts +2 -2
- package/src/middleware/authHmac/authHmac.test.ts +86 -86
- package/src/middleware/authHmac/authHmac.ts +56 -56
- package/src/middleware/authHmac/authHmac.types.ts +7 -7
- package/src/middleware/authHmac/index.ts +2 -2
- package/src/middleware/authJwt/authJwt.test.ts +54 -54
- package/src/middleware/authJwt/authJwt.ts +55 -55
- package/src/middleware/authJwt/authJwt.types.ts +14 -14
- package/src/middleware/authJwt/index.ts +2 -2
- package/src/middleware/authStatic/authStatic.test.ts +36 -36
- package/src/middleware/authStatic/authStatic.ts +45 -45
- package/src/middleware/authStatic/index.ts +1 -1
- package/src/middleware/authTls/authTls.test.ts +138 -138
- package/src/middleware/authTls/authTls.ts +106 -106
- package/src/middleware/authTls/authTls.types.ts +13 -13
- package/src/middleware/authTls/index.ts +2 -2
- package/src/middleware/checkPermission/checkPermission.ts +32 -32
- package/src/middleware/error/error.test.ts +60 -60
- package/src/middleware/error/error.ts +25 -25
- package/src/middleware/error/index.ts +1 -1
- package/src/middleware/fileUploader/compressAvatar/compressAvatar.ts +25 -25
- package/src/middleware/fileUploader/compressAvatar/compressAvatar.types.ts +12 -12
- package/src/middleware/fileUploader/compressAvatar/index.ts +2 -2
- package/src/middleware/fileUploader/fileUploader.test.ts +310 -310
- package/src/middleware/fileUploader/fileUploader.ts +303 -303
- package/src/middleware/fileUploader/fileUploader.types.ts +52 -52
- package/src/middleware/fileUploader/index.ts +2 -2
- package/src/middleware/fileUploader/isMultiPart/index.ts +1 -1
- package/src/middleware/fileUploader/isMultiPart/isMultipart.ts +9 -9
- package/src/middleware/fileUploader/validate/index.ts +1 -1
- package/src/middleware/fileUploader/validate/validate.ts +27 -27
- package/src/middleware/fourOhFour/fourOhFour.test.ts +14 -14
- package/src/middleware/fourOhFour/fourOhFour.ts +13 -13
- package/src/middleware/fourOhFour/index.ts +1 -1
- package/src/middleware/geminiFileUploader/geminiFileUploader.ts +117 -117
- package/src/middleware/geminiFileUploader/index.ts +1 -1
- package/src/middleware/healthCheck/healthCheck.test.ts +12 -12
- package/src/middleware/healthCheck/healthCheck.ts +14 -14
- package/src/middleware/healthCheck/index.ts +1 -1
- package/src/middleware/index.ts +17 -17
- package/src/middleware/metrics/index.ts +1 -1
- package/src/middleware/metrics/metrics.test.ts +46 -46
- package/src/middleware/metrics/metrics.ts +24 -24
- package/src/middleware/requestMetrics/index.ts +1 -1
- package/src/middleware/requestMetrics/requestMetrics.test.ts +77 -77
- package/src/middleware/requestMetrics/requestMetrics.ts +20 -20
- package/src/middleware/swaggerDocs/index.ts +2 -2
- package/src/middleware/swaggerDocs/swaggerDocs.ts +114 -114
- package/src/middleware/swaggerDocs/swaggerDocs.types.ts +41 -41
- package/src/middleware/userResolver/index.ts +1 -1
- package/src/middleware/userResolver/userResolver.test.ts +35 -35
- package/src/middleware/userResolver/userResolver.ts +35 -35
- package/src/middleware/validate/index.ts +1 -1
- package/src/middleware/validate/validate.test.ts +43 -43
- package/src/middleware/validate/validate.ts +25 -25
- package/src/middleware/version/index.ts +1 -1
- package/src/middleware/version/version.test.ts +23 -23
- package/src/middleware/version/version.ts +12 -12
- package/src/utils/checkEnvironment/index.ts +49 -49
- package/src/utils/createHttpServer/createHttpServer.test.ts +24 -24
- package/src/utils/createHttpServer/createHttpServer.ts +34 -34
- package/src/utils/createHttpServer/createHttpServer.validate.ts +17 -17
- package/src/utils/createHttpServer/index.ts +1 -1
- package/src/utils/createSortedObject/createSortedObject.ts +20 -20
- package/src/utils/createSortedObject/createSortedObjet.test.ts +47 -47
- package/src/utils/createSortedObject/index.ts +1 -1
- package/src/utils/dbMigration/dbMigration.test.ts +209 -209
- package/src/utils/dbMigration/dbMigration.ts +199 -199
- package/src/utils/dbMigration/dbMigration.types.ts +11 -11
- package/src/utils/dbMigration/index.ts +2 -2
- package/src/utils/dbMigration/migrateMetadataTable/index.ts +1 -1
- package/src/utils/dbMigration/migrateMetadataTable/migrateMetadataTable.test.ts +59 -59
- package/src/utils/dbMigration/migrateMetadataTable/migrateMetadataTable.ts +102 -70
- package/src/utils/envAssert/envAssert.ts +31 -31
- package/src/utils/envAssert/index.ts +1 -1
- package/src/utils/envAssert/validators/hostList.ts +17 -17
- package/src/utils/envAssert/validators/index.ts +5 -5
- package/src/utils/envAssert/validators/ipList.ts +13 -13
- package/src/utils/envAssert/validators/path.ts +13 -13
- package/src/utils/envAssert/validators/string.ts +9 -9
- package/src/utils/envAssert/validators/stringList.ts +13 -13
- package/src/utils/filter/filter.ts +17 -17
- package/src/utils/filter/index.ts +1 -1
- package/src/utils/getDynamicLink/getDynamicLink.test.ts +51 -51
- package/src/utils/getDynamicLink/getDynamicLink.ts +28 -28
- package/src/utils/getDynamicLink/getDynamicLink.types.ts +11 -11
- package/src/utils/getDynamicLink/getDynamicLink.validate.ts +6 -6
- package/src/utils/getDynamicLink/index.ts +2 -2
- package/src/utils/hmac/checkEnv/checkEnv.test.ts +18 -18
- package/src/utils/hmac/checkEnv/checkEnv.ts +9 -9
- package/src/utils/hmac/checkEnv/index.ts +1 -1
- package/src/utils/hmac/createHmac/createHmac.ts +33 -33
- package/src/utils/hmac/createHmac/index.ts +1 -1
- package/src/utils/hmac/index.ts +4 -4
- package/src/utils/hmac/index.types.ts +13 -13
- package/src/utils/hmac/signPayload/index.ts +1 -1
- package/src/utils/hmac/signPayload/signPayload.ts +16 -16
- package/src/utils/hmac/verifySignature/index.ts +1 -1
- package/src/utils/hmac/verifySignature/verifySignature.ts +24 -24
- package/src/utils/index.ts +26 -26
- package/src/utils/jwt/index.ts +2 -2
- package/src/utils/jwt/jwt.test.ts +41 -41
- package/src/utils/jwt/jwt.ts +204 -204
- package/src/utils/jwt/jwt.types.ts +21 -21
- package/src/utils/report/index.ts +3 -3
- package/src/utils/report/output.ts +45 -45
- package/src/utils/report/output.types.ts +70 -70
- package/src/utils/report/report.test.ts +133 -133
- package/src/utils/report/report.ts +134 -134
- package/src/utils/report/report.types.ts +13 -13
- package/src/utils/request/index.ts +1 -1
- package/src/utils/request/request.test.ts +26 -26
- package/src/utils/request/request.ts +48 -48
- package/src/utils/semverCompare/index.ts +1 -1
- package/src/utils/semverCompare/semverCompare.test.ts +49 -49
- package/src/utils/semverCompare/semverCompare.ts +60 -60
- package/src/utils/sendEmail/index.ts +1 -1
- package/src/utils/sendEmail/sendEmail.ts +27 -27
- package/src/utils/sendEmail/sendEmail.types.ts +7 -7
- package/src/utils/sendPush/index.ts +2 -2
- package/src/utils/sendPush/sendPush.ts +20 -20
- package/src/utils/sendPush/sendPush.types.ts +25 -25
- package/src/utils/tlsConfig/index.ts +2 -2
- package/src/utils/tlsConfig/tlsConfig.test.ts +32 -32
- package/src/utils/tlsConfig/tlsConfig.ts +47 -47
- package/src/utils/tlsConfig/tlsConfig.types.ts +11 -11
- package/src/utils/tlsConfig/tlsConfig.validate.ts +25 -25
- package/src/utils/tlsRequest/index.ts +1 -1
- package/src/utils/tlsRequest/tlsRequest.test.ts +63 -63
- package/src/utils/tlsRequest/tlsRequest.ts +12 -12
- package/src/utils/trimPathSlash/index.ts +1 -1
- package/src/utils/trimPathSlash/trimPathSlash.test.ts +26 -26
- package/src/utils/trimPathSlash/trimPathSlash.ts +8 -8
- package/test/env.ts +56 -56
- package/test/factory/index.ts +8 -8
- package/test/factory/sequelizeMeta.ts +12 -12
- package/test/hooks.ts +37 -37
- package/test/index.ts +3 -3
- package/test/stub/index.ts +3 -3
- package/test/stub/stubLocales.ts +68 -68
- package/test/stub/stubPubSub.ts +7 -7
- package/test/stub/stubStorage.ts +77 -77
- package/test/stub/stubStorage.types.ts +11 -11
- package/test/utils/app.ts +31 -31
- package/test/utils/index.ts +1 -1
- package/tsconfig.build.json +5 -5
- package/tsconfig.json +32 -32
|
@@ -1,219 +1,219 @@
|
|
|
1
|
-
import { randomUUID } from 'crypto';
|
|
2
|
-
import { Readable } from 'stream';
|
|
3
|
-
import {
|
|
4
|
-
Storage as CloudStorage,
|
|
5
|
-
CreateWriteStreamOptions,
|
|
6
|
-
File
|
|
7
|
-
} from '@google-cloud/storage';
|
|
8
|
-
import fileSizeParser from 'filesize-parser';
|
|
9
|
-
import mimeTypes from 'mime-types';
|
|
10
|
-
import {
|
|
11
|
-
UploadDestinationOptions,
|
|
12
|
-
StorageUploadedFile,
|
|
13
|
-
UploaderOptions,
|
|
14
|
-
StorageGetResponse,
|
|
15
|
-
StorageDownloadResponse
|
|
16
|
-
} from './Storage.types';
|
|
17
|
-
import { WebError } from 'entities/WebError';
|
|
18
|
-
import { reportDebug } from 'utils/report';
|
|
19
|
-
import { trimPathSlash } from 'utils/trimPathSlash';
|
|
20
|
-
|
|
21
|
-
const namespace = 'engine:storage';
|
|
22
|
-
|
|
23
|
-
export const Storage = {
|
|
24
|
-
cloudStorage: new CloudStorage({
|
|
25
|
-
projectId: process.env.GC_PROJECT,
|
|
26
|
-
keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS
|
|
27
|
-
}),
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Upload a file to the cloud storage
|
|
31
|
-
* @param readStream - Stream of the file content
|
|
32
|
-
* @param bucket - Bucket in which the file should be stored
|
|
33
|
-
* @param destinationOptions - Options for the destination generator [see: generateFileDestination(options)]
|
|
34
|
-
* @param storageOptions - Storage library options
|
|
35
|
-
* @param uploaderOptions - Options for this service's specific behavior
|
|
36
|
-
* @return {Promise<Object>} - Details regarding the uploaded file's metadata
|
|
37
|
-
*/
|
|
38
|
-
async upload(
|
|
39
|
-
readStream: Readable,
|
|
40
|
-
bucket: string,
|
|
41
|
-
destinationOptions: UploadDestinationOptions = {},
|
|
42
|
-
storageOptions: CreateWriteStreamOptions = {},
|
|
43
|
-
uploaderOptions: UploaderOptions = {}
|
|
44
|
-
): Promise<StorageUploadedFile> {
|
|
45
|
-
const { maxSize } = uploaderOptions;
|
|
46
|
-
|
|
47
|
-
let file: File;
|
|
48
|
-
reportDebug({
|
|
49
|
-
namespace,
|
|
50
|
-
message: 'Uploading file to storage',
|
|
51
|
-
data: { bucket, destinationOptions, storageOptions, uploaderOptions }
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// Generate the file path
|
|
55
|
-
// We either use a given file name, or we generate a random file name
|
|
56
|
-
const { fileName, directory } = destinationOptions;
|
|
57
|
-
|
|
58
|
-
// Upload file with given file name
|
|
59
|
-
if (fileName) {
|
|
60
|
-
// Only keep required slashes in full path
|
|
61
|
-
const trimmedDirectory = trimPathSlash(directory ?? '/');
|
|
62
|
-
const path = `${trimmedDirectory}/${fileName}`;
|
|
63
|
-
file = this.cloudStorage.bucket(bucket).file(path);
|
|
64
|
-
}
|
|
65
|
-
// Generate random destination for file and check that it is not already occupied
|
|
66
|
-
else {
|
|
67
|
-
do {
|
|
68
|
-
const path = this.generateFileDestination(destinationOptions);
|
|
69
|
-
file = this.cloudStorage.bucket(bucket).file(path);
|
|
70
|
-
} while ((await file.exists())[0]);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Pipe user's file stream to the storage
|
|
74
|
-
return new Promise((resolve, reject) => {
|
|
75
|
-
let receivedSize = 0;
|
|
76
|
-
const writeStream = file.createWriteStream(storageOptions);
|
|
77
|
-
const intMaxSize = maxSize && fileSizeParser(maxSize);
|
|
78
|
-
// Calculate transferred size and write to storage stream
|
|
79
|
-
readStream.on('data', function (data: Buffer) {
|
|
80
|
-
receivedSize += data.length;
|
|
81
|
-
// Fail if transferred data over max size
|
|
82
|
-
if (intMaxSize && receivedSize > intMaxSize) {
|
|
83
|
-
reject(
|
|
84
|
-
new WebError({
|
|
85
|
-
statusCode: 413,
|
|
86
|
-
errorCode: 'file-too-large',
|
|
87
|
-
message: 'Request contains a file that is over the maximum size',
|
|
88
|
-
hint: { maxSize },
|
|
89
|
-
data: {
|
|
90
|
-
bucket,
|
|
91
|
-
destinationOptions,
|
|
92
|
-
storageOptions,
|
|
93
|
-
receivedSize,
|
|
94
|
-
maxSize
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
writeStream.write(data);
|
|
101
|
-
});
|
|
102
|
-
// Error handling
|
|
103
|
-
readStream.on('error', (err) => {
|
|
104
|
-
reject(err);
|
|
105
|
-
});
|
|
106
|
-
writeStream.on('error', (err) => {
|
|
107
|
-
reject(err);
|
|
108
|
-
});
|
|
109
|
-
// Graceful termination of the read
|
|
110
|
-
readStream.on('end', () => {
|
|
111
|
-
writeStream.end();
|
|
112
|
-
});
|
|
113
|
-
// Graceful termination of the write
|
|
114
|
-
writeStream.on('finish', () => {
|
|
115
|
-
(async (): Promise<void> => {
|
|
116
|
-
const [metadata] = (await file.getMetadata()) as [
|
|
117
|
-
StorageUploadedFile,
|
|
118
|
-
unknown
|
|
119
|
-
];
|
|
120
|
-
reportDebug({
|
|
121
|
-
namespace,
|
|
122
|
-
message: 'File uploaded to storage',
|
|
123
|
-
data: metadata
|
|
124
|
-
});
|
|
125
|
-
resolve(metadata);
|
|
126
|
-
})().catch((error) => {
|
|
127
|
-
reject(error);
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Return the read stream for a given file and bucket
|
|
135
|
-
*/
|
|
136
|
-
async get(bucket: string, path: string): Promise<StorageGetResponse> {
|
|
137
|
-
const file = this.cloudStorage.bucket(bucket).file(path);
|
|
138
|
-
const [[metadata], [data]] = (await Promise.all([
|
|
139
|
-
file.getMetadata(),
|
|
140
|
-
file.download()
|
|
141
|
-
])) as [[StorageUploadedFile, unknown], [Buffer]];
|
|
142
|
-
reportDebug({
|
|
143
|
-
namespace,
|
|
144
|
-
message: 'Downloaded file from storage',
|
|
145
|
-
data: { bucket, path, metadata }
|
|
146
|
-
});
|
|
147
|
-
return {
|
|
148
|
-
data,
|
|
149
|
-
metadata
|
|
150
|
-
};
|
|
151
|
-
},
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Return the read stream for a given file and bucket
|
|
155
|
-
*/
|
|
156
|
-
async download(
|
|
157
|
-
bucket: string,
|
|
158
|
-
path: string
|
|
159
|
-
): Promise<StorageDownloadResponse> {
|
|
160
|
-
const file = this.cloudStorage.bucket(bucket).file(path);
|
|
161
|
-
const [metadata] = (await file.getMetadata()) as [
|
|
162
|
-
StorageUploadedFile,
|
|
163
|
-
unknown
|
|
164
|
-
];
|
|
165
|
-
reportDebug({
|
|
166
|
-
namespace,
|
|
167
|
-
message: 'Fetched file stream from storage',
|
|
168
|
-
data: { bucket, path, metadata }
|
|
169
|
-
});
|
|
170
|
-
return {
|
|
171
|
-
stream: file.createReadStream(),
|
|
172
|
-
metadata
|
|
173
|
-
};
|
|
174
|
-
},
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Return the read stream for a given file path and bucket
|
|
178
|
-
* @param {String} bucket
|
|
179
|
-
* @param {String} path
|
|
180
|
-
*/
|
|
181
|
-
getFileStream(bucket: string, path: string): Readable {
|
|
182
|
-
const file = this.cloudStorage.bucket(bucket).file(path);
|
|
183
|
-
reportDebug({
|
|
184
|
-
namespace,
|
|
185
|
-
message: "Fetched file stream from storage's bucket",
|
|
186
|
-
data: { bucket, path }
|
|
187
|
-
});
|
|
188
|
-
return file.createReadStream();
|
|
189
|
-
},
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Delete a file from the cloud storage
|
|
193
|
-
*/
|
|
194
|
-
async delete(bucket: string, path: string): Promise<void> {
|
|
195
|
-
reportDebug({
|
|
196
|
-
namespace,
|
|
197
|
-
message: 'Deleting file from storage',
|
|
198
|
-
data: { bucket, path }
|
|
199
|
-
});
|
|
200
|
-
await this.cloudStorage.bucket(bucket).file(path).delete();
|
|
201
|
-
},
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Builds the full file path on the cloud and generates it a random name
|
|
205
|
-
*/
|
|
206
|
-
generateFileDestination(options: UploadDestinationOptions = {}): string {
|
|
207
|
-
const { directory = '/', mime, noExtension = false } = options;
|
|
208
|
-
|
|
209
|
-
// use provided mime type default otherwise
|
|
210
|
-
const extension =
|
|
211
|
-
mime && mimeTypes.extension(mime) ? mimeTypes.extension(mime) : undefined;
|
|
212
|
-
// Build the full name
|
|
213
|
-
const fullName =
|
|
214
|
-
extension && !noExtension ? `${randomUUID()}.${extension}` : randomUUID();
|
|
215
|
-
// Only keep required slashes in full path
|
|
216
|
-
const trimmedDirectory = trimPathSlash(directory);
|
|
217
|
-
return `${trimmedDirectory ? `${trimmedDirectory}/` : ''}${fullName}`;
|
|
218
|
-
}
|
|
219
|
-
};
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
import { Readable } from 'stream';
|
|
3
|
+
import {
|
|
4
|
+
Storage as CloudStorage,
|
|
5
|
+
CreateWriteStreamOptions,
|
|
6
|
+
File
|
|
7
|
+
} from '@google-cloud/storage';
|
|
8
|
+
import fileSizeParser from 'filesize-parser';
|
|
9
|
+
import mimeTypes from 'mime-types';
|
|
10
|
+
import {
|
|
11
|
+
UploadDestinationOptions,
|
|
12
|
+
StorageUploadedFile,
|
|
13
|
+
UploaderOptions,
|
|
14
|
+
StorageGetResponse,
|
|
15
|
+
StorageDownloadResponse
|
|
16
|
+
} from './Storage.types';
|
|
17
|
+
import { WebError } from 'entities/WebError';
|
|
18
|
+
import { reportDebug } from 'utils/report';
|
|
19
|
+
import { trimPathSlash } from 'utils/trimPathSlash';
|
|
20
|
+
|
|
21
|
+
const namespace = 'engine:storage';
|
|
22
|
+
|
|
23
|
+
export const Storage = {
|
|
24
|
+
cloudStorage: new CloudStorage({
|
|
25
|
+
projectId: process.env.GC_PROJECT,
|
|
26
|
+
keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS
|
|
27
|
+
}),
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Upload a file to the cloud storage
|
|
31
|
+
* @param readStream - Stream of the file content
|
|
32
|
+
* @param bucket - Bucket in which the file should be stored
|
|
33
|
+
* @param destinationOptions - Options for the destination generator [see: generateFileDestination(options)]
|
|
34
|
+
* @param storageOptions - Storage library options
|
|
35
|
+
* @param uploaderOptions - Options for this service's specific behavior
|
|
36
|
+
* @return {Promise<Object>} - Details regarding the uploaded file's metadata
|
|
37
|
+
*/
|
|
38
|
+
async upload(
|
|
39
|
+
readStream: Readable,
|
|
40
|
+
bucket: string,
|
|
41
|
+
destinationOptions: UploadDestinationOptions = {},
|
|
42
|
+
storageOptions: CreateWriteStreamOptions = {},
|
|
43
|
+
uploaderOptions: UploaderOptions = {}
|
|
44
|
+
): Promise<StorageUploadedFile> {
|
|
45
|
+
const { maxSize } = uploaderOptions;
|
|
46
|
+
|
|
47
|
+
let file: File;
|
|
48
|
+
reportDebug({
|
|
49
|
+
namespace,
|
|
50
|
+
message: 'Uploading file to storage',
|
|
51
|
+
data: { bucket, destinationOptions, storageOptions, uploaderOptions }
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Generate the file path
|
|
55
|
+
// We either use a given file name, or we generate a random file name
|
|
56
|
+
const { fileName, directory } = destinationOptions;
|
|
57
|
+
|
|
58
|
+
// Upload file with given file name
|
|
59
|
+
if (fileName) {
|
|
60
|
+
// Only keep required slashes in full path
|
|
61
|
+
const trimmedDirectory = trimPathSlash(directory ?? '/');
|
|
62
|
+
const path = `${trimmedDirectory}/${fileName}`;
|
|
63
|
+
file = this.cloudStorage.bucket(bucket).file(path);
|
|
64
|
+
}
|
|
65
|
+
// Generate random destination for file and check that it is not already occupied
|
|
66
|
+
else {
|
|
67
|
+
do {
|
|
68
|
+
const path = this.generateFileDestination(destinationOptions);
|
|
69
|
+
file = this.cloudStorage.bucket(bucket).file(path);
|
|
70
|
+
} while ((await file.exists())[0]);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Pipe user's file stream to the storage
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
let receivedSize = 0;
|
|
76
|
+
const writeStream = file.createWriteStream(storageOptions);
|
|
77
|
+
const intMaxSize = maxSize && fileSizeParser(maxSize);
|
|
78
|
+
// Calculate transferred size and write to storage stream
|
|
79
|
+
readStream.on('data', function (data: Buffer) {
|
|
80
|
+
receivedSize += data.length;
|
|
81
|
+
// Fail if transferred data over max size
|
|
82
|
+
if (intMaxSize && receivedSize > intMaxSize) {
|
|
83
|
+
reject(
|
|
84
|
+
new WebError({
|
|
85
|
+
statusCode: 413,
|
|
86
|
+
errorCode: 'file-too-large',
|
|
87
|
+
message: 'Request contains a file that is over the maximum size',
|
|
88
|
+
hint: { maxSize },
|
|
89
|
+
data: {
|
|
90
|
+
bucket,
|
|
91
|
+
destinationOptions,
|
|
92
|
+
storageOptions,
|
|
93
|
+
receivedSize,
|
|
94
|
+
maxSize
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
writeStream.write(data);
|
|
101
|
+
});
|
|
102
|
+
// Error handling
|
|
103
|
+
readStream.on('error', (err) => {
|
|
104
|
+
reject(err);
|
|
105
|
+
});
|
|
106
|
+
writeStream.on('error', (err) => {
|
|
107
|
+
reject(err);
|
|
108
|
+
});
|
|
109
|
+
// Graceful termination of the read
|
|
110
|
+
readStream.on('end', () => {
|
|
111
|
+
writeStream.end();
|
|
112
|
+
});
|
|
113
|
+
// Graceful termination of the write
|
|
114
|
+
writeStream.on('finish', () => {
|
|
115
|
+
(async (): Promise<void> => {
|
|
116
|
+
const [metadata] = (await file.getMetadata()) as [
|
|
117
|
+
StorageUploadedFile,
|
|
118
|
+
unknown
|
|
119
|
+
];
|
|
120
|
+
reportDebug({
|
|
121
|
+
namespace,
|
|
122
|
+
message: 'File uploaded to storage',
|
|
123
|
+
data: metadata
|
|
124
|
+
});
|
|
125
|
+
resolve(metadata);
|
|
126
|
+
})().catch((error) => {
|
|
127
|
+
reject(error);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Return the read stream for a given file and bucket
|
|
135
|
+
*/
|
|
136
|
+
async get(bucket: string, path: string): Promise<StorageGetResponse> {
|
|
137
|
+
const file = this.cloudStorage.bucket(bucket).file(path);
|
|
138
|
+
const [[metadata], [data]] = (await Promise.all([
|
|
139
|
+
file.getMetadata(),
|
|
140
|
+
file.download()
|
|
141
|
+
])) as [[StorageUploadedFile, unknown], [Buffer]];
|
|
142
|
+
reportDebug({
|
|
143
|
+
namespace,
|
|
144
|
+
message: 'Downloaded file from storage',
|
|
145
|
+
data: { bucket, path, metadata }
|
|
146
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
data,
|
|
149
|
+
metadata
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Return the read stream for a given file and bucket
|
|
155
|
+
*/
|
|
156
|
+
async download(
|
|
157
|
+
bucket: string,
|
|
158
|
+
path: string
|
|
159
|
+
): Promise<StorageDownloadResponse> {
|
|
160
|
+
const file = this.cloudStorage.bucket(bucket).file(path);
|
|
161
|
+
const [metadata] = (await file.getMetadata()) as [
|
|
162
|
+
StorageUploadedFile,
|
|
163
|
+
unknown
|
|
164
|
+
];
|
|
165
|
+
reportDebug({
|
|
166
|
+
namespace,
|
|
167
|
+
message: 'Fetched file stream from storage',
|
|
168
|
+
data: { bucket, path, metadata }
|
|
169
|
+
});
|
|
170
|
+
return {
|
|
171
|
+
stream: file.createReadStream(),
|
|
172
|
+
metadata
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Return the read stream for a given file path and bucket
|
|
178
|
+
* @param {String} bucket
|
|
179
|
+
* @param {String} path
|
|
180
|
+
*/
|
|
181
|
+
getFileStream(bucket: string, path: string): Readable {
|
|
182
|
+
const file = this.cloudStorage.bucket(bucket).file(path);
|
|
183
|
+
reportDebug({
|
|
184
|
+
namespace,
|
|
185
|
+
message: "Fetched file stream from storage's bucket",
|
|
186
|
+
data: { bucket, path }
|
|
187
|
+
});
|
|
188
|
+
return file.createReadStream();
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Delete a file from the cloud storage
|
|
193
|
+
*/
|
|
194
|
+
async delete(bucket: string, path: string): Promise<void> {
|
|
195
|
+
reportDebug({
|
|
196
|
+
namespace,
|
|
197
|
+
message: 'Deleting file from storage',
|
|
198
|
+
data: { bucket, path }
|
|
199
|
+
});
|
|
200
|
+
await this.cloudStorage.bucket(bucket).file(path).delete();
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Builds the full file path on the cloud and generates it a random name
|
|
205
|
+
*/
|
|
206
|
+
generateFileDestination(options: UploadDestinationOptions = {}): string {
|
|
207
|
+
const { directory = '/', mime, noExtension = false } = options;
|
|
208
|
+
|
|
209
|
+
// use provided mime type default otherwise
|
|
210
|
+
const extension =
|
|
211
|
+
mime && mimeTypes.extension(mime) ? mimeTypes.extension(mime) : undefined;
|
|
212
|
+
// Build the full name
|
|
213
|
+
const fullName =
|
|
214
|
+
extension && !noExtension ? `${randomUUID()}.${extension}` : randomUUID();
|
|
215
|
+
// Only keep required slashes in full path
|
|
216
|
+
const trimmedDirectory = trimPathSlash(directory);
|
|
217
|
+
return `${trimmedDirectory ? `${trimmedDirectory}/` : ''}${fullName}`;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { Readable } from 'stream';
|
|
2
|
-
|
|
3
|
-
/** Options to set where an uploaded file is stored in the bucket */
|
|
4
|
-
export interface UploadDestinationOptions {
|
|
5
|
-
/** Directory of the bucket in which the file is stored. Defaults to the root directory */
|
|
6
|
-
directory?: string;
|
|
7
|
-
/** Name under which the file is stored. If specified, the file is stored with that name. Otherwise random name generation is done */
|
|
8
|
-
fileName?: string;
|
|
9
|
-
/** When using random file name generation (ie: fileName is undefined). We use the MIME type to determine which is the best extension to apply to the file */
|
|
10
|
-
mime?: string;
|
|
11
|
-
/** When using random file name generation (ie: fileName is undefined), use this parameter to skip adding an extension to the file */
|
|
12
|
-
noExtension?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** Options of the file uploader */
|
|
16
|
-
export interface UploaderOptions {
|
|
17
|
-
/** Maximum size of the file (ex: 2MB) */
|
|
18
|
-
maxSize?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** Object representing a file that has been uploaded */
|
|
22
|
-
export interface StorageUploadedFile {
|
|
23
|
-
/** Bucket in which the file has been uploaded */
|
|
24
|
-
bucket: string;
|
|
25
|
-
/** Name of the stored object with path */
|
|
26
|
-
name: string;
|
|
27
|
-
/** Content-type of the file */
|
|
28
|
-
contentType: string;
|
|
29
|
-
/** Byte size of the file */
|
|
30
|
-
size: string;
|
|
31
|
-
/** ISO string of the creation date */
|
|
32
|
-
timeCreated: string;
|
|
33
|
-
/** ISO string of the update date */
|
|
34
|
-
updated: string;
|
|
35
|
-
/** MD5 hash of the content */
|
|
36
|
-
md5Hash: string;
|
|
37
|
-
/** CRC32C hash of the content */
|
|
38
|
-
crc32c: string;
|
|
39
|
-
/** Storage class applied */
|
|
40
|
-
storageClass: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Return type for a file download */
|
|
44
|
-
export interface StorageGetResponse {
|
|
45
|
-
/** The file raw binary content */
|
|
46
|
-
data: Buffer;
|
|
47
|
-
/** The file's metadata */
|
|
48
|
-
metadata: StorageUploadedFile;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Return time for a file streaming fetching */
|
|
52
|
-
export interface StorageDownloadResponse {
|
|
53
|
-
/** A readable stream with the file's content */
|
|
54
|
-
stream: Readable;
|
|
55
|
-
/** The file's metadata */
|
|
56
|
-
metadata: StorageUploadedFile;
|
|
57
|
-
}
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
|
|
3
|
+
/** Options to set where an uploaded file is stored in the bucket */
|
|
4
|
+
export interface UploadDestinationOptions {
|
|
5
|
+
/** Directory of the bucket in which the file is stored. Defaults to the root directory */
|
|
6
|
+
directory?: string;
|
|
7
|
+
/** Name under which the file is stored. If specified, the file is stored with that name. Otherwise random name generation is done */
|
|
8
|
+
fileName?: string;
|
|
9
|
+
/** When using random file name generation (ie: fileName is undefined). We use the MIME type to determine which is the best extension to apply to the file */
|
|
10
|
+
mime?: string;
|
|
11
|
+
/** When using random file name generation (ie: fileName is undefined), use this parameter to skip adding an extension to the file */
|
|
12
|
+
noExtension?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Options of the file uploader */
|
|
16
|
+
export interface UploaderOptions {
|
|
17
|
+
/** Maximum size of the file (ex: 2MB) */
|
|
18
|
+
maxSize?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Object representing a file that has been uploaded */
|
|
22
|
+
export interface StorageUploadedFile {
|
|
23
|
+
/** Bucket in which the file has been uploaded */
|
|
24
|
+
bucket: string;
|
|
25
|
+
/** Name of the stored object with path */
|
|
26
|
+
name: string;
|
|
27
|
+
/** Content-type of the file */
|
|
28
|
+
contentType: string;
|
|
29
|
+
/** Byte size of the file */
|
|
30
|
+
size: string;
|
|
31
|
+
/** ISO string of the creation date */
|
|
32
|
+
timeCreated: string;
|
|
33
|
+
/** ISO string of the update date */
|
|
34
|
+
updated: string;
|
|
35
|
+
/** MD5 hash of the content */
|
|
36
|
+
md5Hash: string;
|
|
37
|
+
/** CRC32C hash of the content */
|
|
38
|
+
crc32c: string;
|
|
39
|
+
/** Storage class applied */
|
|
40
|
+
storageClass: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Return type for a file download */
|
|
44
|
+
export interface StorageGetResponse {
|
|
45
|
+
/** The file raw binary content */
|
|
46
|
+
data: Buffer;
|
|
47
|
+
/** The file's metadata */
|
|
48
|
+
metadata: StorageUploadedFile;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Return time for a file streaming fetching */
|
|
52
|
+
export interface StorageDownloadResponse {
|
|
53
|
+
/** A readable stream with the file's content */
|
|
54
|
+
stream: Readable;
|
|
55
|
+
/** The file's metadata */
|
|
56
|
+
metadata: StorageUploadedFile;
|
|
57
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './Storage';
|
|
2
|
-
export * from './Storage.types';
|
|
1
|
+
export * from './Storage';
|
|
2
|
+
export * from './Storage.types';
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ValidationError as ExpressValidationError,
|
|
3
|
-
Result
|
|
4
|
-
} from 'express-validator';
|
|
5
|
-
import { LogSeverity } from 'const';
|
|
6
|
-
import { EngineError } from 'entities/EngineError';
|
|
7
|
-
import { WebError } from 'entities/WebError';
|
|
8
|
-
|
|
9
|
-
/** Error class for request/message validation errors */
|
|
10
|
-
export class ValidationError extends WebError {
|
|
11
|
-
/** Create an ValidationError this represents errors in parsing incoming messages/requests */
|
|
12
|
-
public constructor(validationResult: Result<ExpressValidationError>) {
|
|
13
|
-
if (validationResult.isEmpty())
|
|
14
|
-
throw new EngineError({
|
|
15
|
-
message:
|
|
16
|
-
'Attempted to create a validation error while validation was successful'
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const errors = validationResult.array();
|
|
20
|
-
// Hint that is sent to the client as logged as data
|
|
21
|
-
const hint = errors.reduce(
|
|
22
|
-
(hint, error) => ({ ...hint, [error.type]: error.msg as string }),
|
|
23
|
-
{}
|
|
24
|
-
);
|
|
25
|
-
super({
|
|
26
|
-
message: 'Request did not pass validation',
|
|
27
|
-
errorCode: 'invalid-request',
|
|
28
|
-
statusCode: 400,
|
|
29
|
-
severity: LogSeverity.WARNING,
|
|
30
|
-
data: hint,
|
|
31
|
-
hint
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
ValidationError as ExpressValidationError,
|
|
3
|
+
Result
|
|
4
|
+
} from 'express-validator';
|
|
5
|
+
import { LogSeverity } from 'const';
|
|
6
|
+
import { EngineError } from 'entities/EngineError';
|
|
7
|
+
import { WebError } from 'entities/WebError';
|
|
8
|
+
|
|
9
|
+
/** Error class for request/message validation errors */
|
|
10
|
+
export class ValidationError extends WebError {
|
|
11
|
+
/** Create an ValidationError this represents errors in parsing incoming messages/requests */
|
|
12
|
+
public constructor(validationResult: Result<ExpressValidationError>) {
|
|
13
|
+
if (validationResult.isEmpty())
|
|
14
|
+
throw new EngineError({
|
|
15
|
+
message:
|
|
16
|
+
'Attempted to create a validation error while validation was successful'
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const errors = validationResult.array();
|
|
20
|
+
// Hint that is sent to the client as logged as data
|
|
21
|
+
const hint = errors.reduce(
|
|
22
|
+
(hint, error) => ({ ...hint, [error.type]: error.msg as string }),
|
|
23
|
+
{}
|
|
24
|
+
);
|
|
25
|
+
super({
|
|
26
|
+
message: 'Request did not pass validation',
|
|
27
|
+
errorCode: 'invalid-request',
|
|
28
|
+
statusCode: 400,
|
|
29
|
+
severity: LogSeverity.WARNING,
|
|
30
|
+
data: hint,
|
|
31
|
+
hint
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './ValidationError';
|
|
1
|
+
export * from './ValidationError';
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
import { WebError } from './WebError';
|
|
3
|
-
|
|
4
|
-
describe('Entity - WebError', () => {
|
|
5
|
-
it('should set the error code and message', () => {
|
|
6
|
-
const statusCode = 401;
|
|
7
|
-
const errorCode = 'example-errorCode';
|
|
8
|
-
const message = 'this is an example message';
|
|
9
|
-
const error = new WebError({
|
|
10
|
-
message,
|
|
11
|
-
errorCode,
|
|
12
|
-
statusCode
|
|
13
|
-
});
|
|
14
|
-
expect(error.message).to.equal(message);
|
|
15
|
-
expect(error.errorCode).to.equal(errorCode);
|
|
16
|
-
expect(error.statusCode).to.equal(statusCode);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { WebError } from './WebError';
|
|
3
|
+
|
|
4
|
+
describe('Entity - WebError', () => {
|
|
5
|
+
it('should set the error code and message', () => {
|
|
6
|
+
const statusCode = 401;
|
|
7
|
+
const errorCode = 'example-errorCode';
|
|
8
|
+
const message = 'this is an example message';
|
|
9
|
+
const error = new WebError({
|
|
10
|
+
message,
|
|
11
|
+
errorCode,
|
|
12
|
+
statusCode
|
|
13
|
+
});
|
|
14
|
+
expect(error.message).to.equal(message);
|
|
15
|
+
expect(error.errorCode).to.equal(errorCode);
|
|
16
|
+
expect(error.statusCode).to.equal(statusCode);
|
|
17
|
+
});
|
|
18
|
+
});
|