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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authHmac.js","names":["_WebError","require","_hmac","_report","namespace","authHmac","options","req","res","next","payload","method","query","body","signature","signatureSettings","isGithub","headers","substr","algorithm","sort","encode","settings","secret","WebError","message","errorCode","statusCode","reportDebug","data","verifySignature"],"sources":["../../../src/middleware/authHmac/authHmac.ts"],"sourcesContent":["import { BinaryToTextEncoding } from 'crypto';\nimport { Request, Response, NextFunction } from 'express';\nimport { HmacPayload } from './authHmac.types';\nimport { EndpointAuthParams, EndpointAuthType } from 'entities/Endpoint';\nimport { WebError } from 'entities/WebError';\nimport { verifySignature } from 'utils/hmac';\nimport { reportDebug } from 'utils/report';\n\nconst namespace = 'engine:middleware:authHmac';\n\n/** Generate an HMAC authentication middleware */\nexport function authHmac(\n options: EndpointAuthParams<EndpointAuthType.HMAC> = {}\n): (req: Request, res: Response, next: NextFunction) => void {\n return (req: Request, res: Response, next: NextFunction): void => {\n const payload = (\n req.method === 'GET' ? req.query : req.body\n ) as HmacPayload;\n let signature: string | undefined;\n let signatureSettings;\n if (options.isGithub) {\n // For GitHub, the signature is in the header and is has specific settings\n signature =\n req.headers['x-hub-signature'] &&\n (req.headers['x-hub-signature'] as string).substr(5);\n signatureSettings = {\n algorithm: 'sha1',\n sort: false,\n encode: 'hex' as BinaryToTextEncoding\n };\n } else {\n // In our standard authentication, the signature is included in the payload\n signature = payload.signature;\n delete payload.signature;\n }\n const settings = { secret: options.secret, ...signatureSettings };\n if (!signature)\n throw new WebError({\n message: 'No signature was provided',\n errorCode: 'unauthorized',\n statusCode: 401\n });\n reportDebug({\n namespace,\n message: 'Performing HMAC authentication',\n data: { payload, signature, settings }\n });\n if (!verifySignature(payload, signature, settings))\n throw new WebError({\n message: 'Signature does not match hmac of payload',\n errorCode: 'unauthorized',\n statusCode: 401\n });\n next();\n };\n}\n"],"mappings":";;;;;;AAIA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAEA,MAAMG,SAAS,GAAG,4BAA4B;;AAE9C;AACO,SAASC,QAAQA,CACtBC,OAAkD,GAAG,CAAC,CAAC,EACI;EAC3D,OAAO,CAACC,GAAY,EAAEC,GAAa,EAAEC,IAAkB,KAAW;IAChE,MAAMC,OAAO,GACXH,GAAG,CAACI,MAAM,KAAK,KAAK,GAAGJ,GAAG,CAACK,KAAK,GAAGL,GAAG,CAACM,IACzB;IAChB,IAAIC,SAA6B;IACjC,IAAIC,iBAAiB;IACrB,IAAIT,OAAO,CAACU,QAAQ,EAAE;MACpB;MACAF,SAAS,GACPP,GAAG,CAACU,OAAO,CAAC,iBAAiB,CAAC,IAC7BV,GAAG,CAACU,OAAO,CAAC,iBAAiB,CAAC,CAAYC,MAAM,CAAC,CAAC,CAAC;MACtDH,iBAAiB,GAAG;QAClBI,SAAS,EAAE,MAAM;QACjBC,IAAI,EAAE,KAAK;QACXC,MAAM,EAAE;MACV,CAAC;IACH,CAAC,MAAM;MACL;MACAP,SAAS,GAAGJ,OAAO,CAACI,SAAS;MAC7B,OAAOJ,OAAO,CAACI,SAAS;IAC1B;IACA,MAAMQ,QAAQ,GAAG;MAAEC,MAAM,EAAEjB,OAAO,CAACiB,MAAM;MAAE,GAAGR;IAAkB,CAAC;IACjE,IAAI,CAACD,SAAS,EACZ,MAAM,IAAIU,kBAAQ,CAAC;MACjBC,OAAO,EAAE,2BAA2B;MACpCC,SAAS,EAAE,cAAc;MACzBC,UAAU,EAAE;IACd,CAAC,CAAC;IACJ,IAAAC,mBAAW,EAAC;MACVxB,SAAS;MACTqB,OAAO,EAAE,gCAAgC;MACzCI,IAAI,EAAE;QAAEnB,OAAO;QAAEI,SAAS;QAAEQ;MAAS;IACvC,CAAC,CAAC;IACF,IAAI,CAAC,IAAAQ,qBAAe,EAACpB,OAAO,EAAEI,SAAS,EAAEQ,QAAQ,CAAC,EAChD,MAAM,IAAIE,kBAAQ,CAAC;MACjBC,OAAO,EAAE,0CAA0C;MACnDC,SAAS,EAAE,cAAc;MACzBC,UAAU,EAAE;IACd,CAAC,CAAC;IACJlB,IAAI,CAAC,CAAC;EACR,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"authHmac.js","names":["_WebError","require","_hmac","_report","namespace","authHmac","options","req","res","next","payload","method","query","body","signature","signatureSettings","isGithub","headers","substr","algorithm","sort","encode","settings","secret","WebError","message","errorCode","statusCode","reportDebug","data","verifySignature"],"sources":["../../../src/middleware/authHmac/authHmac.ts"],"sourcesContent":["import { BinaryToTextEncoding } from 'crypto';\r\nimport { Request, Response, NextFunction } from 'express';\r\nimport { HmacPayload } from './authHmac.types';\r\nimport { EndpointAuthParams, EndpointAuthType } from 'entities/Endpoint';\r\nimport { WebError } from 'entities/WebError';\r\nimport { verifySignature } from 'utils/hmac';\r\nimport { reportDebug } from 'utils/report';\r\n\r\nconst namespace = 'engine:middleware:authHmac';\r\n\r\n/** Generate an HMAC authentication middleware */\r\nexport function authHmac(\r\n options: EndpointAuthParams<EndpointAuthType.HMAC> = {}\r\n): (req: Request, res: Response, next: NextFunction) => void {\r\n return (req: Request, res: Response, next: NextFunction): void => {\r\n const payload = (\r\n req.method === 'GET' ? req.query : req.body\r\n ) as HmacPayload;\r\n let signature: string | undefined;\r\n let signatureSettings;\r\n if (options.isGithub) {\r\n // For GitHub, the signature is in the header and is has specific settings\r\n signature =\r\n req.headers['x-hub-signature'] &&\r\n (req.headers['x-hub-signature'] as string).substr(5);\r\n signatureSettings = {\r\n algorithm: 'sha1',\r\n sort: false,\r\n encode: 'hex' as BinaryToTextEncoding\r\n };\r\n } else {\r\n // In our standard authentication, the signature is included in the payload\r\n signature = payload.signature;\r\n delete payload.signature;\r\n }\r\n const settings = { secret: options.secret, ...signatureSettings };\r\n if (!signature)\r\n throw new WebError({\r\n message: 'No signature was provided',\r\n errorCode: 'unauthorized',\r\n statusCode: 401\r\n });\r\n reportDebug({\r\n namespace,\r\n message: 'Performing HMAC authentication',\r\n data: { payload, signature, settings }\r\n });\r\n if (!verifySignature(payload, signature, settings))\r\n throw new WebError({\r\n message: 'Signature does not match hmac of payload',\r\n errorCode: 'unauthorized',\r\n statusCode: 401\r\n });\r\n next();\r\n };\r\n}\r\n"],"mappings":";;;;;;AAIA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAEA,MAAMG,SAAS,GAAG,4BAA4B;;AAE9C;AACO,SAASC,QAAQA,CACtBC,OAAkD,GAAG,CAAC,CAAC,EACI;EAC3D,OAAO,CAACC,GAAY,EAAEC,GAAa,EAAEC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":"authHmac.types.js","names":[],"sources":["../../../src/middleware/authHmac/authHmac.types.ts"],"sourcesContent":["/** Options for HMAC auth */\nexport interface HmacPayload {\n /** Generic object payload */\n [key: string]: unknown;\n /** HMAC signature of the whole payload */\n signature?: string;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"authHmac.types.js","names":[],"sources":["../../../src/middleware/authHmac/authHmac.types.ts"],"sourcesContent":["/** Options for HMAC auth */\r\nexport interface HmacPayload {\r\n /** Generic object payload */\r\n [key: string]: unknown;\r\n /** HMAC signature of the whole payload */\r\n signature?: string;\r\n}\r\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_authHmac","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_authHmac2"],"sources":["../../../src/middleware/authHmac/index.ts"],"sourcesContent":["export * from './authHmac';\nexport * from './authHmac.types';\n"],"mappings":";;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,SAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,SAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,SAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,UAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,UAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,UAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,UAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_authHmac","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_authHmac2"],"sources":["../../../src/middleware/authHmac/index.ts"],"sourcesContent":["export * from './authHmac';\r\nexport * from './authHmac.types';\r\n"],"mappings":";;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,SAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,SAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,SAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,UAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,UAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,UAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,UAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authJwt.js","names":["_const","require","_EngineError","_WebError","_jwt","_report","namespace","authJwt","process","env","ACCESS_TOKEN_AUDIENCE","EngineError","message","request","response","next","scheme","credentials","headers","authorization","split","toLowerCase","WebError","errorCode","statusCode","data","reportDebug","payload","jwtVerify","TokenIssuer","AUTH_SERVICE","user"],"sources":["../../../src/middleware/authJwt/authJwt.ts"],"sourcesContent":["import { Request, Response, NextFunction } from 'express';\nimport { TokenIssuer } from 'const';\nimport { EngineError } from 'entities/EngineError';\nimport { WebError } from 'entities/WebError';\nimport { jwtVerify } from 'utils/jwt';\nimport { reportDebug } from 'utils/report';\nimport {} from './authJwt.types';\n\nconst namespace = 'engine:middleware:authJwt';\n\n/** Generate a middleware to authenticate the client connection with a JWT */\nexport function authJwt(): (\n request: Request,\n response: Response,\n next: NextFunction\n) => Promise<void> {\n if (!process.env.ACCESS_TOKEN_AUDIENCE)\n throw new EngineError({\n message: 'Env variable ACCESS_TOKEN_AUDIENCE is not defined'\n });\n\n return async (\n request: Request,\n response: Response,\n next: NextFunction\n ): Promise<void> => {\n const [scheme, credentials] =\n request.headers?.authorization?.split(' ') ?? [];\n // No bearer token has been sent\n if (!credentials || scheme.toLowerCase() !== 'bearer') {\n throw new WebError({\n message: 'No bearer token found',\n errorCode: 'unauthorized',\n statusCode: 401,\n data: { authorization: request.headers?.authorization }\n });\n }\n reportDebug({\n namespace,\n message: 'Performing JWT authentication',\n data: { scheme, credentials }\n });\n // Verify token and extract its payload\n const payload = await jwtVerify(credentials, TokenIssuer.AUTH_SERVICE);\n reportDebug({\n namespace,\n message: 'Extracted user data from JWT',\n data: { payload, credentials }\n });\n // The user object on the request is hydrated with data from the token\n request.user = payload.user;\n\n next();\n };\n}\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,IAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACAA,OAAA;AAEA,MAAMK,SAAS,GAAG,2BAA2B;;AAE7C;AACO,SAASC,OAAOA,CAAA,EAIJ;EACjB,IAAI,CAACC,OAAO,CAACC,GAAG,CAACC,qBAAqB,EACpC,MAAM,IAAIC,wBAAW,CAAC;IACpBC,OAAO,EAAE;EACX,CAAC,CAAC;EAEJ,OAAO,OACLC,OAAgB,EAChBC,QAAkB,EAClBC,IAAkB,KACA;IAClB,MAAM,CAACC,MAAM,EAAEC,WAAW,CAAC,GACzBJ,OAAO,CAACK,OAAO,EAAEC,aAAa,EAAEC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE;IAClD;IACA,IAAI,CAACH,WAAW,IAAID,MAAM,CAACK,WAAW,CAAC,CAAC,KAAK,QAAQ,EAAE;MACrD,MAAM,IAAIC,kBAAQ,CAAC;QACjBV,OAAO,EAAE,uBAAuB;QAChCW,SAAS,EAAE,cAAc;QACzBC,UAAU,EAAE,GAAG;QACfC,IAAI,EAAE;UAAEN,aAAa,EAAEN,OAAO,CAACK,OAAO,EAAEC;QAAc;MACxD,CAAC,CAAC;IACJ;IACA,IAAAO,mBAAW,EAAC;MACVpB,SAAS;MACTM,OAAO,EAAE,+BAA+B;MACxCa,IAAI,EAAE;QAAET,MAAM;QAAEC;MAAY;IAC9B,CAAC,CAAC;IACF;IACA,MAAMU,OAAO,GAAG,MAAM,IAAAC,cAAS,EAACX,WAAW,EAAEY,kBAAW,CAACC,YAAY,CAAC;IACtE,IAAAJ,mBAAW,EAAC;MACVpB,SAAS;MACTM,OAAO,EAAE,8BAA8B;MACvCa,IAAI,EAAE;QAAEE,OAAO;QAAEV;MAAY;IAC/B,CAAC,CAAC;IACF;IACAJ,OAAO,CAACkB,IAAI,GAAGJ,OAAO,CAACI,IAAI;IAE3BhB,IAAI,CAAC,CAAC;EACR,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"authJwt.js","names":["_const","require","_EngineError","_WebError","_jwt","_report","namespace","authJwt","process","env","ACCESS_TOKEN_AUDIENCE","EngineError","message","request","response","next","scheme","credentials","headers","authorization","split","toLowerCase","WebError","errorCode","statusCode","data","reportDebug","payload","jwtVerify","TokenIssuer","AUTH_SERVICE","user"],"sources":["../../../src/middleware/authJwt/authJwt.ts"],"sourcesContent":["import { Request, Response, NextFunction } from 'express';\r\nimport { TokenIssuer } from 'const';\r\nimport { EngineError } from 'entities/EngineError';\r\nimport { WebError } from 'entities/WebError';\r\nimport { jwtVerify } from 'utils/jwt';\r\nimport { reportDebug } from 'utils/report';\r\nimport {} from './authJwt.types';\r\n\r\nconst namespace = 'engine:middleware:authJwt';\r\n\r\n/** Generate a middleware to authenticate the client connection with a JWT */\r\nexport function authJwt(): (\r\n request: Request,\r\n response: Response,\r\n next: NextFunction\r\n) => Promise<void> {\r\n if (!process.env.ACCESS_TOKEN_AUDIENCE)\r\n throw new EngineError({\r\n message: 'Env variable ACCESS_TOKEN_AUDIENCE is not defined'\r\n });\r\n\r\n return async (\r\n request: Request,\r\n response: Response,\r\n next: NextFunction\r\n ): Promise<void> => {\r\n const [scheme, credentials] =\r\n request.headers?.authorization?.split(' ') ?? [];\r\n // No bearer token has been sent\r\n if (!credentials || scheme.toLowerCase() !== 'bearer') {\r\n throw new WebError({\r\n message: 'No bearer token found',\r\n errorCode: 'unauthorized',\r\n statusCode: 401,\r\n data: { authorization: request.headers?.authorization }\r\n });\r\n }\r\n reportDebug({\r\n namespace,\r\n message: 'Performing JWT authentication',\r\n data: { scheme, credentials }\r\n });\r\n // Verify token and extract its payload\r\n const payload = await jwtVerify(credentials, TokenIssuer.AUTH_SERVICE);\r\n reportDebug({\r\n namespace,\r\n message: 'Extracted user data from JWT',\r\n data: { payload, credentials }\r\n });\r\n // The user object on the request is hydrated with data from the token\r\n request.user = payload.user;\r\n\r\n next();\r\n };\r\n}\r\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,IAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACAA,OAAA;AAEA,MAAMK,SAAS,GAAG,2BAA2B;;AAE7C;AACO,SAASC,OAAOA,CAAA,EAIJ;EACjB,IAAI,CAACC,OAAO,CAACC,GAAG,CAACC,qBAAqB,EACpC,MAAM,IAAIC,wBAAW,CAAC;IACpBC,OAAO,EAAE;EACX,CAAC,CAAC;EAEJ,OAAO,OACLC,OAAgB,EAChBC,QAAkB,EAClBC,IAAkB,KACA;IAClB,MAAM,CAACC,MAAM,EAAEC,WAAW,CAAC,GACzBJ,OAAO,CAACK,OAAO,EAAEC,aAAa,EAAEC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE;IAClD;IACA,IAAI,CAACH,WAAW,IAAID,MAAM,CAACK,WAAW,CAAC,CAAC,KAAK,QAAQ,EAAE;MACrD,MAAM,IAAIC,kBAAQ,CAAC;QACjBV,OAAO,EAAE,uBAAuB;QAChCW,SAAS,EAAE,cAAc;QACzBC,UAAU,EAAE,GAAG;QACfC,IAAI,EAAE;UAAEN,aAAa,EAAEN,OAAO,CAACK,OAAO,EAAEC;QAAc;MACxD,CAAC,CAAC;IACJ;IACA,IAAAO,mBAAW,EAAC;MACVpB,SAAS;MACTM,OAAO,EAAE,+BAA+B;MACxCa,IAAI,EAAE;QAAET,MAAM;QAAEC;MAAY;IAC9B,CAAC,CAAC;IACF;IACA,MAAMU,OAAO,GAAG,MAAM,IAAAC,cAAS,EAACX,WAAW,EAAEY,kBAAW,CAACC,YAAY,CAAC;IACtE,IAAAJ,mBAAW,EAAC;MACVpB,SAAS;MACTM,OAAO,EAAE,8BAA8B;MACvCa,IAAI,EAAE;QAAEE,OAAO;QAAEV;MAAY;IAC/B,CAAC,CAAC;IACF;IACAJ,OAAO,CAACkB,IAAI,GAAGJ,OAAO,CAACI,IAAI;IAE3BhB,IAAI,CAAC,CAAC;EACR,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authJwt.types.js","names":[],"sources":["../../../src/middleware/authJwt/authJwt.types.ts"],"sourcesContent":["export {};\n\n// Override the Express request object to add the files\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Express {\n /** Express request object */\n interface Request {\n /** User that identified using a JWT */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n user?: Record<string, any>;\n }\n }\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"authJwt.types.js","names":[],"sources":["../../../src/middleware/authJwt/authJwt.types.ts"],"sourcesContent":["export {};\r\n\r\n// Override the Express request object to add the files\r\ndeclare global {\r\n // eslint-disable-next-line @typescript-eslint/no-namespace\r\n namespace Express {\r\n /** Express request object */\r\n interface Request {\r\n /** User that identified using a JWT */\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n user?: Record<string, any>;\r\n }\r\n }\r\n}\r\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_authJwt","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_authJwt2"],"sources":["../../../src/middleware/authJwt/index.ts"],"sourcesContent":["export * from './authJwt';\nexport * from './authJwt.types';\n"],"mappings":";;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,QAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,QAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,QAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,SAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,SAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,SAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,SAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_authJwt","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_authJwt2"],"sources":["../../../src/middleware/authJwt/index.ts"],"sourcesContent":["export * from './authJwt';\r\nexport * from './authJwt.types';\r\n"],"mappings":";;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,QAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,QAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,QAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,SAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,SAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,SAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,SAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -8,9 +8,9 @@ var _WebError = require("../../entities/WebError");
|
|
|
8
8
|
var _utils = require("../../utils");
|
|
9
9
|
const namespace = 'engine:middleware:authStatic';
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Generate a middleware to authenticate the client connection with a static token
|
|
13
|
-
* @return {Function}
|
|
11
|
+
/**
|
|
12
|
+
* Generate a middleware to authenticate the client connection with a static token
|
|
13
|
+
* @return {Function}
|
|
14
14
|
*/
|
|
15
15
|
function authStatic() {
|
|
16
16
|
(0, _utils.assertEnvironment)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authStatic.js","names":["_WebError","require","_utils","namespace","authStatic","assertEnvironment","STATIC_TOKEN","envAssert","isString","req","res","next","scheme","credentials","headers","authorization","split","toLowerCase","WebError","statusCode","errorCode","message","data","reportDebug","process","env"],"sources":["../../../src/middleware/authStatic/authStatic.ts"],"sourcesContent":["import { Request, Response, NextFunction } from 'express';\nimport { WebError } from 'entities/WebError';\nimport { assertEnvironment, envAssert, reportDebug } from 'utils';\n\nconst namespace = 'engine:middleware:authStatic';\n\n/**\n * Generate a middleware to authenticate the client connection with a static token\n * @return {Function}\n */\nexport function authStatic(): (\n req: Request,\n res: Response,\n next: NextFunction\n) => void {\n assertEnvironment({ STATIC_TOKEN: envAssert.isString() });\n\n return (req: Request, res: Response, next: NextFunction): void => {\n const [scheme, credentials] = req.headers?.authorization?.split(' ') ?? [];\n // No bearer token has been sent\n if (!credentials || scheme.toLowerCase() !== 'bearer') {\n throw new WebError({\n statusCode: 401,\n errorCode: 'unauthorized',\n message: 'No bearer token found',\n data: { authorization: req.headers?.authorization }\n });\n }\n reportDebug({\n namespace,\n message: 'Performing Static authentication',\n data: { scheme, credentials }\n });\n // Verify token\n if (credentials !== process.env.STATIC_TOKEN) {\n throw new WebError({\n statusCode: 401,\n errorCode: 'unauthorized',\n message: 'Invalid token supplied',\n data: { credentials }\n });\n }\n next();\n };\n}\n"],"mappings":";;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEA,MAAME,SAAS,GAAG,8BAA8B;;AAEhD;AACA;AACA;AACA;AACO,SAASC,UAAUA,CAAA,EAIhB;EACR,IAAAC,wBAAiB,EAAC;IAAEC,YAAY,EAAEC,gBAAS,CAACC,QAAQ,CAAC;EAAE,CAAC,CAAC;EAEzD,OAAO,CAACC,GAAY,EAAEC,GAAa,EAAEC,IAAkB,KAAW;IAChE,MAAM,CAACC,MAAM,EAAEC,WAAW,CAAC,GAAGJ,GAAG,CAACK,OAAO,EAAEC,aAAa,EAAEC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE;IAC1E;IACA,IAAI,CAACH,WAAW,IAAID,MAAM,CAACK,WAAW,CAAC,CAAC,KAAK,QAAQ,EAAE;MACrD,MAAM,IAAIC,kBAAQ,CAAC;QACjBC,UAAU,EAAE,GAAG;QACfC,SAAS,EAAE,cAAc;QACzBC,OAAO,EAAE,uBAAuB;QAChCC,IAAI,EAAE;UAAEP,aAAa,EAAEN,GAAG,CAACK,OAAO,EAAEC;QAAc;MACpD,CAAC,CAAC;IACJ;IACA,IAAAQ,kBAAW,EAAC;MACVpB,SAAS;MACTkB,OAAO,EAAE,kCAAkC;MAC3CC,IAAI,EAAE;QAAEV,MAAM;QAAEC;MAAY;IAC9B,CAAC,CAAC;IACF;IACA,IAAIA,WAAW,KAAKW,OAAO,CAACC,GAAG,CAACnB,YAAY,EAAE;MAC5C,MAAM,IAAIY,kBAAQ,CAAC;QACjBC,UAAU,EAAE,GAAG;QACfC,SAAS,EAAE,cAAc;QACzBC,OAAO,EAAE,wBAAwB;QACjCC,IAAI,EAAE;UAAET;QAAY;MACtB,CAAC,CAAC;IACJ;IACAF,IAAI,CAAC,CAAC;EACR,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"authStatic.js","names":["_WebError","require","_utils","namespace","authStatic","assertEnvironment","STATIC_TOKEN","envAssert","isString","req","res","next","scheme","credentials","headers","authorization","split","toLowerCase","WebError","statusCode","errorCode","message","data","reportDebug","process","env"],"sources":["../../../src/middleware/authStatic/authStatic.ts"],"sourcesContent":["import { Request, Response, NextFunction } from 'express';\r\nimport { WebError } from 'entities/WebError';\r\nimport { assertEnvironment, envAssert, reportDebug } from 'utils';\r\n\r\nconst namespace = 'engine:middleware:authStatic';\r\n\r\n/**\r\n * Generate a middleware to authenticate the client connection with a static token\r\n * @return {Function}\r\n */\r\nexport function authStatic(): (\r\n req: Request,\r\n res: Response,\r\n next: NextFunction\r\n) => void {\r\n assertEnvironment({ STATIC_TOKEN: envAssert.isString() });\r\n\r\n return (req: Request, res: Response, next: NextFunction): void => {\r\n const [scheme, credentials] = req.headers?.authorization?.split(' ') ?? [];\r\n // No bearer token has been sent\r\n if (!credentials || scheme.toLowerCase() !== 'bearer') {\r\n throw new WebError({\r\n statusCode: 401,\r\n errorCode: 'unauthorized',\r\n message: 'No bearer token found',\r\n data: { authorization: req.headers?.authorization }\r\n });\r\n }\r\n reportDebug({\r\n namespace,\r\n message: 'Performing Static authentication',\r\n data: { scheme, credentials }\r\n });\r\n // Verify token\r\n if (credentials !== process.env.STATIC_TOKEN) {\r\n throw new WebError({\r\n statusCode: 401,\r\n errorCode: 'unauthorized',\r\n message: 'Invalid token supplied',\r\n data: { credentials }\r\n });\r\n }\r\n next();\r\n };\r\n}\r\n"],"mappings":";;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEA,MAAME,SAAS,GAAG,8BAA8B;;AAEhD;AACA;AACA;AACA;AACO,SAASC,UAAUA,CAAA,EAIhB;EACR,IAAAC,wBAAiB,EAAC;IAAEC,YAAY,EAAEC,gBAAS,CAACC,QAAQ,CAAC;EAAE,CAAC,CAAC;EAEzD,OAAO,CAACC,GAAY,EAAEC,GAAa,EAAEC,IAAkB,KAAW;IAChE,MAAM,CAACC,MAAM,EAAEC,WAAW,CAAC,GAAGJ,GAAG,CAACK,OAAO,EAAEC,aAAa,EAAEC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE;IAC1E;IACA,IAAI,CAACH,WAAW,IAAID,MAAM,CAACK,WAAW,CAAC,CAAC,KAAK,QAAQ,EAAE;MACrD,MAAM,IAAIC,kBAAQ,CAAC;QACjBC,UAAU,EAAE,GAAG;QACfC,SAAS,EAAE,cAAc;QACzBC,OAAO,EAAE,uBAAuB;QAChCC,IAAI,EAAE;UAAEP,aAAa,EAAEN,GAAG,CAACK,OAAO,EAAEC;QAAc;MACpD,CAAC,CAAC;IACJ;IACA,IAAAQ,kBAAW,EAAC;MACVpB,SAAS;MACTkB,OAAO,EAAE,kCAAkC;MAC3CC,IAAI,EAAE;QAAEV,MAAM;QAAEC;MAAY;IAC9B,CAAC,CAAC;IACF;IACA,IAAIA,WAAW,KAAKW,OAAO,CAACC,GAAG,CAACnB,YAAY,EAAE;MAC5C,MAAM,IAAIY,kBAAQ,CAAC;QACjBC,UAAU,EAAE,GAAG;QACfC,SAAS,EAAE,cAAc;QACzBC,OAAO,EAAE,wBAAwB;QACjCC,IAAI,EAAE;UAAET;QAAY;MACtB,CAAC,CAAC;IACJ;IACAF,IAAI,CAAC,CAAC;EACR,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_authStatic","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../../src/middleware/authStatic/index.ts"],"sourcesContent":["export * from './authStatic';\n"],"mappings":";;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,WAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,WAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,WAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_authStatic","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../../src/middleware/authStatic/index.ts"],"sourcesContent":["export * from './authStatic';\r\n"],"mappings":";;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,WAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,WAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,WAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -13,14 +13,14 @@ var _report = require("../../utils/report");
|
|
|
13
13
|
require("./authTls.types");
|
|
14
14
|
const namespace = 'engine:middleware:authTls';
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* Returns a middleware for TLS authentication
|
|
18
|
-
* Both client and server must have a certificate signed by the same CA
|
|
19
|
-
* Host name of the client is added to the express request object under 'request.user.host'
|
|
20
|
-
* A limited number of hosts can be specified with the environment variable ALLOWED_CLIENT_HOSTS
|
|
21
|
-
* @param {Object} options
|
|
22
|
-
* @param {Array<String>} options.whitelist - List of certificate Common Name or Alt Name that are permitted to make requests to this endpoint
|
|
23
|
-
* @return {Function}
|
|
16
|
+
/**
|
|
17
|
+
* Returns a middleware for TLS authentication
|
|
18
|
+
* Both client and server must have a certificate signed by the same CA
|
|
19
|
+
* Host name of the client is added to the express request object under 'request.user.host'
|
|
20
|
+
* A limited number of hosts can be specified with the environment variable ALLOWED_CLIENT_HOSTS
|
|
21
|
+
* @param {Object} options
|
|
22
|
+
* @param {Array<String>} options.whitelist - List of certificate Common Name or Alt Name that are permitted to make requests to this endpoint
|
|
23
|
+
* @return {Function}
|
|
24
24
|
*/
|
|
25
25
|
function authTls(options = {}) {
|
|
26
26
|
(0, _checkEnvironment.assertEnvironment)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authTls.js","names":["_WebError","require","_checkEnvironment","_envAssert","_report","namespace","authTls","options","assertEnvironment","TLS_SERVER_KEY","envAssert","isPath","TLS_SERVER_CERT","request","response","next","authTlsMiddleware","allowedClientHosts","loadEnv","process","env","ALLOWED_CLIENT_HOSTS","isHostList","split","map","value","trim","socket","authorized","WebError","errorCode","statusCode","message","clientCertificate","getPeerCertificate","subjects","subject","CN","push","subjectaltname","length","altNames","whitelist","reportDebug","data","certificate","allowed","includes","hosts"],"sources":["../../../src/middleware/authTls/authTls.ts"],"sourcesContent":["import { TLSSocket } from 'tls';\nimport { Request, Response, NextFunction } from 'express';\nimport { EndpointAuthParams, EndpointAuthType } from 'entities/Endpoint';\nimport { WebError } from 'entities/WebError';\nimport { assertEnvironment } from 'utils/checkEnvironment';\nimport { envAssert } from 'utils/envAssert';\nimport { reportDebug } from 'utils/report';\nimport {} from './authTls.types';\n\nconst namespace = 'engine:middleware:authTls';\n\n/**\n * Returns a middleware for TLS authentication\n * Both client and server must have a certificate signed by the same CA\n * Host name of the client is added to the express request object under 'request.user.host'\n * A limited number of hosts can be specified with the environment variable ALLOWED_CLIENT_HOSTS\n * @param {Object} options\n * @param {Array<String>} options.whitelist - List of certificate Common Name or Alt Name that are permitted to make requests to this endpoint\n * @return {Function}\n */\nexport function authTls(\n options: EndpointAuthParams<EndpointAuthType.TLS> = {}\n): (request: Request, response: Response, next: NextFunction) => void {\n assertEnvironment({\n TLS_SERVER_KEY: envAssert.isPath(),\n TLS_SERVER_CERT: envAssert.isPath()\n });\n\n return (request: Request, response: Response, next: NextFunction): void => {\n authTlsMiddleware(request, response, next, options);\n };\n}\n\nlet allowedClientHosts: Array<string> = [];\n\n/** Load TLS auth related environment variables */\nexport function loadEnv(): void {\n if (process.env.ALLOWED_CLIENT_HOSTS) {\n assertEnvironment({ ALLOWED_CLIENT_HOSTS: envAssert.isHostList() });\n allowedClientHosts = process.env.ALLOWED_CLIENT_HOSTS.split(',').map(\n (value) => value.trim()\n );\n } else {\n allowedClientHosts = [];\n }\n}\n\nloadEnv();\n\n/** Middleware that handles mTLS based authentication */\nexport function authTlsMiddleware(\n request: Request,\n response: Response,\n next: NextFunction,\n options: EndpointAuthParams<EndpointAuthType.TLS> = {}\n): void {\n const socket = request.socket as TLSSocket;\n // Check if the client's tls certificate is valid\n if (!socket?.authorized) {\n throw new WebError({\n errorCode: 'unauthorized',\n statusCode: 401,\n message: 'TLS certificate could not be validated'\n });\n }\n\n // Extract the subjects for the client certificate\n const clientCertificate = socket.getPeerCertificate();\n const subjects = [];\n if (clientCertificate.subject.CN) subjects.push(clientCertificate.subject.CN);\n if (clientCertificate.subjectaltname?.length) {\n const altNames = clientCertificate.subjectaltname\n .split(',')\n .map((subject) => subject.trim())\n .map((value) => value.split(':')[1]);\n subjects.push(...altNames);\n }\n\n const whitelist = options.whitelist ?? allowedClientHosts;\n reportDebug({\n namespace,\n message: 'Performing TLS authentication',\n data: { certificate: clientCertificate, whitelist, subjects }\n });\n // Check that the subject is authorized\n if (whitelist?.length) {\n let allowed = false;\n for (const subject of subjects) {\n if (whitelist.includes(subject)) {\n allowed = true;\n break;\n }\n }\n // Throw error if there is no subject in the whitelist\n if (!allowed)\n throw new WebError({\n errorCode: 'unauthorized',\n statusCode: 401,\n message: 'Client host is not in the whitelist',\n data: { subjects }\n });\n }\n // Pas subjects down\n request.hosts = subjects;\n next();\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACAA,OAAA;AAEA,MAAMI,SAAS,GAAG,2BAA2B;;AAE7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,OAAOA,CACrBC,OAAiD,GAAG,CAAC,CAAC,EACc;EACpE,IAAAC,mCAAiB,EAAC;IAChBC,cAAc,EAAEC,oBAAS,CAACC,MAAM,CAAC,CAAC;IA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B,CAACM,cAAc,EAAEC,MAAM,EAAE;IAC5C,MAAMC,QAAQ,GAAGR,iBAAiB,CAACM,cAAc,CAC9ChB,KAAK,CAAC,GAAG,CAAC,CACVC,GAAG,CAAEY,OAAO,IAAKA,OAAO,CAACV,IAAI,CAAC,CAAC,CAAC,CAChCF,GAAG,CAAEC,KAAK,IAAKA,KAAK,CAACF,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACtCY,QAAQ,CAACG,IAAI,CAAC,GAAGG,QAAQ,CAAC;EAC5B;EAEA,MAAMC,SAAS,GAAGnC,OAAO,CAACmC,SAAS,IAAIzB,kBAAkB;EACzD,IAAA0B,mBAAW,EAAC;IACVtC,SAAS;IACT2B,OAAO,EAAE,+BAA+B;IACxCY,IAAI,EAAE;MAAEC,WAAW,EAAEZ,iBAAiB;MAAES,SAAS;MAAEP;IAAS;EAC9D,CAAC,CAAC;EACF;EACA,IAAIO,SAAS,EAAEF,MAAM,EAAE;IACrB,IAAIM,OAAO,GAAG,KAAK;IACnB,KAAK,MAAMV,OAAO,IAAID,QAAQ,EAAE;MAC9B,IAAIO,SAAS,CAACK,QAAQ,CAACX,OAAO,CAAC,EAAE;QAC/BU,OAAO,GAAG,IAAI;QACd;MACF;IACF;IACA;IACA,IAAI,CAACA,OAAO,EACV,MAAM,IAAIjB,kBAAQ,CAAC;MACjBC,SAAS,EAAE,cAAc;MACzBC,UAAU,EAAE,GAAG;MACfC,OAAO,EAAE,qCAAqC;MAC9CY,IAAI,EAAE;QAAET;MAAS;IACnB,CAAC,CAAC;EACN;EACA;EACAtB,OAAO,CAACmC,KAAK,GAAGb,QAAQ;EACxBpB,IAAI,CAAC,CAAC;AACR","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"authTls.js","names":["_WebError","require","_checkEnvironment","_envAssert","_report","namespace","authTls","options","assertEnvironment","TLS_SERVER_KEY","envAssert","isPath","TLS_SERVER_CERT","request","response","next","authTlsMiddleware","allowedClientHosts","loadEnv","process","env","ALLOWED_CLIENT_HOSTS","isHostList","split","map","value","trim","socket","authorized","WebError","errorCode","statusCode","message","clientCertificate","getPeerCertificate","subjects","subject","CN","push","subjectaltname","length","altNames","whitelist","reportDebug","data","certificate","allowed","includes","hosts"],"sources":["../../../src/middleware/authTls/authTls.ts"],"sourcesContent":["import { TLSSocket } from 'tls';\r\nimport { Request, Response, NextFunction } from 'express';\r\nimport { EndpointAuthParams, EndpointAuthType } from 'entities/Endpoint';\r\nimport { WebError } from 'entities/WebError';\r\nimport { assertEnvironment } from 'utils/checkEnvironment';\r\nimport { envAssert } from 'utils/envAssert';\r\nimport { reportDebug } from 'utils/report';\r\nimport {} from './authTls.types';\r\n\r\nconst namespace = 'engine:middleware:authTls';\r\n\r\n/**\r\n * Returns a middleware for TLS authentication\r\n * Both client and server must have a certificate signed by the same CA\r\n * Host name of the client is added to the express request object under 'request.user.host'\r\n * A limited number of hosts can be specified with the environment variable ALLOWED_CLIENT_HOSTS\r\n * @param {Object} options\r\n * @param {Array<String>} options.whitelist - List of certificate Common Name or Alt Name that are permitted to make requests to this endpoint\r\n * @return {Function}\r\n */\r\nexport function authTls(\r\n options: EndpointAuthParams<EndpointAuthType.TLS> = {}\r\n): (request: Request, response: Response, next: NextFunction) => void {\r\n assertEnvironment({\r\n TLS_SERVER_KEY: envAssert.isPath(),\r\n TLS_SERVER_CERT: envAssert.isPath()\r\n });\r\n\r\n return (request: Request, response: Response, next: NextFunction): void => {\r\n authTlsMiddleware(request, response, next, options);\r\n };\r\n}\r\n\r\nlet allowedClientHosts: Array<string> = [];\r\n\r\n/** Load TLS auth related environment variables */\r\nexport function loadEnv(): void {\r\n if (process.env.ALLOWED_CLIENT_HOSTS) {\r\n assertEnvironment({ ALLOWED_CLIENT_HOSTS: envAssert.isHostList() });\r\n allowedClientHosts = process.env.ALLOWED_CLIENT_HOSTS.split(',').map(\r\n (value) => value.trim()\r\n );\r\n } else {\r\n allowedClientHosts = [];\r\n }\r\n}\r\n\r\nloadEnv();\r\n\r\n/** Middleware that handles mTLS based authentication */\r\nexport function authTlsMiddleware(\r\n request: Request,\r\n response: Response,\r\n next: NextFunction,\r\n options: EndpointAuthParams<EndpointAuthType.TLS> = {}\r\n): void {\r\n const socket = request.socket as TLSSocket;\r\n // Check if the client's tls certificate is valid\r\n if (!socket?.authorized) {\r\n throw new WebError({\r\n errorCode: 'unauthorized',\r\n statusCode: 401,\r\n message: 'TLS certificate could not be validated'\r\n });\r\n }\r\n\r\n // Extract the subjects for the client certificate\r\n const clientCertificate = socket.getPeerCertificate();\r\n const subjects = [];\r\n if (clientCertificate.subject.CN) subjects.push(clientCertificate.subject.CN);\r\n if (clientCertificate.subjectaltname?.length) {\r\n const altNames = clientCertificate.subjectaltname\r\n .split(',')\r\n .map((subject) => subject.trim())\r\n .map((value) => value.split(':')[1]);\r\n subjects.push(...altNames);\r\n }\r\n\r\n const whitelist = options.whitelist ?? allowedClientHosts;\r\n reportDebug({\r\n namespace,\r\n message: 'Performing TLS authentication',\r\n data: { certificate: clientCertificate, whitelist, subjects }\r\n });\r\n // Check that the subject is authorized\r\n if (whitelist?.length) {\r\n let allowed = false;\r\n for (const subject of subjects) {\r\n if (whitelist.includes(subject)) {\r\n allowed = true;\r\n break;\r\n }\r\n }\r\n // Throw error if there is no subject in the whitelist\r\n if (!allowed)\r\n throw new WebError({\r\n errorCode: 'unauthorized',\r\n statusCode: 401,\r\n message: 'Client host is not in the whitelist',\r\n data: { subjects }\r\n });\r\n }\r\n // Pas subjects down\r\n request.hosts = subjects;\r\n next();\r\n}\r\n"],"mappings":";;;;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACAA,OAAA;AAEA,MAAMI,SAAS,GAAG,2BAA2B;;AAE7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,OAAOA,CACrBC,OAAiD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sources":["../../../src/middleware/authTls/authTls.types.ts"],"sourcesContent":["// Override the Express request object to add the files\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Express {\n /** Express HTTP request */\n interface Request {\n /** Host names provided by the mTLS authenticated client */\n hosts?: Array<string>;\n }\n }\n}\n\nexport {};\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"authTls.types.js","names":[],"sources":["../../../src/middleware/authTls/authTls.types.ts"],"sourcesContent":["// Override the Express request object to add the files\r\ndeclare global {\r\n // eslint-disable-next-line @typescript-eslint/no-namespace\r\n namespace Express {\r\n /** Express HTTP request */\r\n interface Request {\r\n /** Host names provided by the mTLS authenticated client */\r\n hosts?: Array<string>;\r\n }\r\n }\r\n}\r\n\r\nexport {};\r\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_authTls","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../../src/middleware/authTls/index.ts"],"sourcesContent":["export * from './authTls';\nexport {} from './authTls.types';\n"],"mappings":";;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,QAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,QAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,QAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACAJ,OAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_authTls","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../../src/middleware/authTls/index.ts"],"sourcesContent":["export * from './authTls';\r\nexport {} from './authTls.types';\r\n"],"mappings":";;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,QAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,QAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,QAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACAJ,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkPermission.js","names":["checkPermission","requiredActions","req","res","next","user","permissions","status","json","message","requiredActionsArray","Array","isArray","requiredActionsLower","map","action","toLowerCase","hasPermission","some","permission","includes"],"sources":["../../../src/middleware/checkPermission/checkPermission.ts"],"sourcesContent":["import { Request, Response, NextFunction } from 'express';\n\n/** Middleware to check if the user has at least one of the required permissions (case-insensitive). */\nfunction checkPermission(requiredActions: string | string[]) {\n return function (req: Request, res: Response, next: NextFunction) {\n const user = req.user;\n\n if (!user || !user.permissions) {\n return res.status(403).json({ message: 'User does not have permissions' });\n }\n\n // Normalize input to an array of strings\n const requiredActionsArray = Array.isArray(requiredActions)\n ? requiredActions\n : [requiredActions];\n\n // Normalize required actions to lowercase\n const requiredActionsLower = requiredActionsArray.map(action => action.toLowerCase());\n\n // Check if the user has any of the required permissions (case-insensitive)\n const hasPermission = user.permissions.some((permission: string) =>\n requiredActionsLower.includes(permission.toLowerCase())\n );\n\n if (!hasPermission) {\n return res.status(403).json({ message: 'Permission denied' });\n }\n\n next();\n };\n}\n\nexport { checkPermission };"],"mappings":";;;;;;AAEA;AACA,SAASA,eAAeA,CAACC,eAAkC,EAAE;EAC3D,OAAO,UAAUC,GAAY,EAAEC,GAAa,EAAEC,IAAkB,EAAE;IAChE,MAAMC,IAAI,GAAGH,GAAG,CAACG,IAAI;IAErB,IAAI,CAACA,IAAI,IAAI,CAACA,IAAI,CAACC,WAAW,EAAE;MAC9B,OAAOH,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;QAAEC,OAAO,EAAE;MAAiC,CAAC,CAAC;IAC5E;;IAEA;IACA,MAAMC,oBAAoB,GAAGC,KAAK,CAACC,OAAO,CAACX,eAAe,CAAC,GACvDA,eAAe,GACf,CAACA,eAAe,CAAC;;IAErB;IACA,MAAMY,oBAAoB,GAAGH,oBAAoB,CAACI,GAAG,CAACC,MAAM,IAAIA,MAAM,CAACC,WAAW,CAAC,CAAC,CAAC;;IAErF;IACA,MAAMC,aAAa,GAAGZ,IAAI,CAACC,WAAW,CAACY,IAAI,CAAEC,UAAkB,IAC7DN,oBAAoB,CAACO,QAAQ,CAACD,UAAU,CAACH,WAAW,CAAC,CAAC,CACxD,CAAC;IAED,IAAI,CAACC,aAAa,EAAE;MAClB,OAAOd,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;QAAEC,OAAO,EAAE;MAAoB,CAAC,CAAC;IAC/D;IAEAL,IAAI,CAAC,CAAC;EACR,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"checkPermission.js","names":["checkPermission","requiredActions","req","res","next","user","permissions","status","json","message","requiredActionsArray","Array","isArray","requiredActionsLower","map","action","toLowerCase","hasPermission","some","permission","includes"],"sources":["../../../src/middleware/checkPermission/checkPermission.ts"],"sourcesContent":["import { Request, Response, NextFunction } from 'express';\r\n\r\n/** Middleware to check if the user has at least one of the required permissions (case-insensitive). */\r\nfunction checkPermission(requiredActions: string | string[]) {\r\n return function (req: Request, res: Response, next: NextFunction) {\r\n const user = req.user;\r\n\r\n if (!user || !user.permissions) {\r\n return res.status(403).json({ message: 'User does not have permissions' });\r\n }\r\n\r\n // Normalize input to an array of strings\r\n const requiredActionsArray = Array.isArray(requiredActions)\r\n ? requiredActions\r\n : [requiredActions];\r\n\r\n // Normalize required actions to lowercase\r\n const requiredActionsLower = requiredActionsArray.map(action => action.toLowerCase());\r\n\r\n // Check if the user has any of the required permissions (case-insensitive)\r\n const hasPermission = user.permissions.some((permission: string) =>\r\n requiredActionsLower.includes(permission.toLowerCase())\r\n );\r\n\r\n if (!hasPermission) {\r\n return res.status(403).json({ message: 'Permission denied' });\r\n }\r\n\r\n next();\r\n };\r\n}\r\n\r\nexport { checkPermission };"],"mappings":";;;;;;AAEA;AACA,SAASA,eAAeA,CAACC,eAAkC,EAAE;EAC3D,OAAO,UAAUC,GAAY,EAAEC,GAAa,EAAEC,IAAkB,EAAE;IAChE,MAAMC,IAAI,GAAGH,GAAG,CAACG,IAAI;IAErB,IAAI,CAACA,IAAI,IAAI,CAACA,IAAI,CAACC,WAAW,EAAE;MAC9B,OAAOH,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;QAAEC,OAAO,EAAE;MAAiC,CAAC,CAAC;IAC5E;;IAEA;IACA,MAAMC,oBAAoB,GAAGC,KAAK,CAACC,OAAO,CAACX,eAAe,CAAC,GACvDA,eAAe,GACf,CAACA,eAAe,CAAC;;IAErB;IACA,MAAMY,oBAAoB,GAAGH,oBAAoB,CAACI,GAAG,CAACC,MAAM,IAAIA,MAAM,CAACC,WAAW,CAAC,CAAC,CAAC;;IAErF;IACA,MAAMC,aAAa,GAAGZ,IAAI,CAACC,WAAW,CAACY,IAAI,CAAEC,UAAkB,IAC7DN,oBAAoB,CAACO,QAAQ,CAACD,UAAU,CAACH,WAAW,CAAC,CAAC,CACxD,CAAC;IAED,IAAI,CAACC,aAAa,EAAE;MAClB,OAAOd,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;QAAEC,OAAO,EAAE;MAAoB,CAAC,CAAC;IAC/D;IAEAL,IAAI,CAAC,CAAC;EACR,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","names":["_WebError","require","_report","namespace","error","request","response","next","reportDebug","message","data","reportError","WebError","status","statusCode","json","errorCode","hint"],"sources":["../../../src/middleware/error/error.ts"],"sourcesContent":["import { Request, Response, NextFunction } from 'express';\nimport { WebError } from 'entities/WebError';\nimport { reportError, reportDebug } from 'utils/report';\n\nconst namespace = 'engine:middleware:error';\n\n/** Handle errors globally */\nexport function error(\n error: Error,\n request: Request,\n response: Response,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n next: NextFunction\n): void {\n reportDebug({ namespace, message: 'Received error', data: { error } });\n reportError(error, request);\n if (error instanceof WebError) {\n response.status(error.statusCode).json({\n errorCode: error.errorCode,\n hint: error.hint\n });\n return;\n }\n response.status(500).json({ errorCode: 'server-error' });\n}\n"],"mappings":";;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAEA,MAAME,SAAS,GAAG,yBAAyB;;AAE3C;AACO,SAASC,KAAKA,CACnBA,KAAY,EACZC,OAAgB,EAChBC,QAAkB;AAClB;AACAC,IAAkB,EACZ;EACN,IAAAC,mBAAW,EAAC;IAAEL,SAAS;IAAEM,OAAO,EAAE,gBAAgB;IAAEC,IAAI,EAAE;MAAEN;IAAM;EAAE,CAAC,CAAC;EACtE,IAAAO,mBAAW,EAACP,KAAK,EAAEC,OAAO,CAAC;EAC3B,IAAID,KAAK,YAAYQ,kBAAQ,EAAE;IAC7BN,QAAQ,CAACO,MAAM,CAACT,KAAK,CAACU,UAAU,CAAC,CAACC,IAAI,CAAC;MACrCC,SAAS,EAAEZ,KAAK,CAACY,SAAS;MAC1BC,IAAI,EAAEb,KAAK,CAACa;IACd,CAAC,CAAC;IACF;EACF;EACAX,QAAQ,CAACO,MAAM,CAAC,GAAG,CAAC,CAACE,IAAI,CAAC;IAAEC,SAAS,EAAE;EAAe,CAAC,CAAC;AAC1D","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"error.js","names":["_WebError","require","_report","namespace","error","request","response","next","reportDebug","message","data","reportError","WebError","status","statusCode","json","errorCode","hint"],"sources":["../../../src/middleware/error/error.ts"],"sourcesContent":["import { Request, Response, NextFunction } from 'express';\r\nimport { WebError } from 'entities/WebError';\r\nimport { reportError, reportDebug } from 'utils/report';\r\n\r\nconst namespace = 'engine:middleware:error';\r\n\r\n/** Handle errors globally */\r\nexport function error(\r\n error: Error,\r\n request: Request,\r\n response: Response,\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n next: NextFunction\r\n): void {\r\n reportDebug({ namespace, message: 'Received error', data: { error } });\r\n reportError(error, request);\r\n if (error instanceof WebError) {\r\n response.status(error.statusCode).json({\r\n errorCode: error.errorCode,\r\n hint: error.hint\r\n });\r\n return;\r\n }\r\n response.status(500).json({ errorCode: 'server-error' });\r\n}\r\n"],"mappings":";;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAEA,MAAME,SAAS,GAAG,yBAAyB;;AAE3C;AACO,SAASC,KAAKA,CACnBA,KAAY,EACZC,OAAgB,EAChBC,QAAkB;AAClB;AACAC,IAAkB,EACZ;EACN,IAAAC,mBAAW,EAAC;IAAEL,SAAS;IAAEM,OAAO,EAAE,gBAAgB;IAAEC,IAAI,EAAE;MAAEN;IAAM;EAAE,CAAC,CAAC;EACtE,IAAAO,mBAAW,EAACP,KAAK,EAAEC,OAAO,CAAC;EAC3B,IAAID,KAAK,YAAYQ,kBAAQ,EAAE;IAC7BN,QAAQ,CAACO,MAAM,CAACT,KAAK,CAACU,UAAU,CAAC,CAACC,IAAI,CAAC;MACrCC,SAAS,EAAEZ,KAAK,CAACY,SAAS;MAC1BC,IAAI,EAAEb,KAAK,CAACa;IACd,CAAC,CAAC;IACF;EACF;EACAX,QAAQ,CAACO,MAAM,CAAC,GAAG,CAAC,CAACE,IAAI,CAAC;IAAEC,SAAS,EAAE;EAAe,CAAC,CAAC;AAC1D","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_error","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../../src/middleware/error/index.ts"],"sourcesContent":["export * from './error';\n"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_error","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../../src/middleware/error/index.ts"],"sourcesContent":["export * from './error';\r\n"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.compressAvatar = compressAvatar;
|
|
8
8
|
var _sharp = _interopRequireDefault(require("sharp"));
|
|
9
|
-
/**
|
|
10
|
-
* Compress the user's avatar before uploading
|
|
9
|
+
/**
|
|
10
|
+
* Compress the user's avatar before uploading
|
|
11
11
|
*/
|
|
12
12
|
function compressAvatar(fileStream, options) {
|
|
13
13
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compressAvatar.js","names":["_sharp","_interopRequireDefault","require","compressAvatar","fileStream","options","resize","height","width","quality","transform","sharp","fit","toFormat","pipe"],"sources":["../../../../src/middleware/fileUploader/compressAvatar/compressAvatar.ts"],"sourcesContent":["import { Readable } from 'stream';\nimport sharp from 'sharp';\nimport { CompressionOptions } from './compressAvatar.types';\n\n/**\n * Compress the user's avatar before uploading\n */\nexport function compressAvatar(\n fileStream: Readable,\n options: CompressionOptions\n): Readable {\n const {\n resize: { height, width },\n quality\n } = options;\n const transform = sharp()\n .resize(width, height, {\n fit: 'cover'\n })\n .toFormat('jpeg', {\n quality: quality\n });\n fileStream.pipe(transform);\n return fileStream;\n}\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA;AACA;AACA;AACO,SAASC,cAAcA,CAC5BC,UAAoB,EACpBC,OAA2B,EACjB;EACV,MAAM;IACJC,MAAM,EAAE;MAAEC,MAAM;MAAEC;IAAM,CAAC;IACzBC;EACF,CAAC,GAAGJ,OAAO;EACX,MAAMK,SAAS,GAAG,IAAAC,cAAK,EAAC,CAAC,CACtBL,MAAM,CAACE,KAAK,EAAED,MAAM,EAAE;IACrBK,GAAG,EAAE;EACP,CAAC,CAAC,CACDC,QAAQ,CAAC,MAAM,EAAE;IAChBJ,OAAO,EAAEA;EACX,CAAC,CAAC;EACJL,UAAU,CAACU,IAAI,CAACJ,SAAS,CAAC;EAC1B,OAAON,UAAU;AACnB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"compressAvatar.js","names":["_sharp","_interopRequireDefault","require","compressAvatar","fileStream","options","resize","height","width","quality","transform","sharp","fit","toFormat","pipe"],"sources":["../../../../src/middleware/fileUploader/compressAvatar/compressAvatar.ts"],"sourcesContent":["import { Readable } from 'stream';\r\nimport sharp from 'sharp';\r\nimport { CompressionOptions } from './compressAvatar.types';\r\n\r\n/**\r\n * Compress the user's avatar before uploading\r\n */\r\nexport function compressAvatar(\r\n fileStream: Readable,\r\n options: CompressionOptions\r\n): Readable {\r\n const {\r\n resize: { height, width },\r\n quality\r\n } = options;\r\n const transform = sharp()\r\n .resize(width, height, {\r\n fit: 'cover'\r\n })\r\n .toFormat('jpeg', {\r\n quality: quality\r\n });\r\n fileStream.pipe(transform);\r\n return fileStream;\r\n}\r\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA;AACA;AACA;AACO,SAASC,cAAcA,CAC5BC,UAAoB,EACpBC,OAA2B,EACjB;EACV,MAAM;IACJC,MAAM,EAAE;MAAEC,MAAM;MAAEC;IAAM,CAAC;IACzBC;EACF,CAAC,GAAGJ,OAAO;EACX,MAAMK,SAAS,GAAG,IAAAC,cAAK,EAAC,CAAC,CACtBL,MAAM,CAACE,KAAK,EAAED,MAAM,EAAE;IACrBK,GAAG,EAAE;EACP,CAAC,CAAC,CACDC,QAAQ,CAAC,MAAM,EAAE;IAChBJ,OAAO,EAAEA;EACX,CAAC,CAAC;EACJL,UAAU,CAACU,IAAI,CAACJ,SAAS,CAAC;EAC1B,OAAON,UAAU;AACnB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compressAvatar.types.js","names":[],"sources":["../../../../src/middleware/fileUploader/compressAvatar/compressAvatar.types.ts"],"sourcesContent":["/** Options to compress image */\nexport interface CompressionOptions {\n /** Set dimensions in which the image will be resized */\n resize: {\n /** Height of the resized image */\n height: number;\n /** Width of the resized image */\n width: number;\n };\n /** JPG quality factor to apply when compressing */\n quality: number;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"compressAvatar.types.js","names":[],"sources":["../../../../src/middleware/fileUploader/compressAvatar/compressAvatar.types.ts"],"sourcesContent":["/** Options to compress image */\r\nexport interface CompressionOptions {\r\n /** Set dimensions in which the image will be resized */\r\n resize: {\r\n /** Height of the resized image */\r\n height: number;\r\n /** Width of the resized image */\r\n width: number;\r\n };\r\n /** JPG quality factor to apply when compressing */\r\n quality: number;\r\n}\r\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_compressAvatar","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_compressAvatar2"],"sources":["../../../../src/middleware/fileUploader/compressAvatar/index.ts"],"sourcesContent":["export * from './compressAvatar';\nexport * from './compressAvatar.types';\n"],"mappings":";;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,eAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,eAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,eAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,gBAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,gBAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,gBAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,gBAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_compressAvatar","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_compressAvatar2"],"sources":["../../../../src/middleware/fileUploader/compressAvatar/index.ts"],"sourcesContent":["export * from './compressAvatar';\r\nexport * from './compressAvatar.types';\r\n"],"mappings":";;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,eAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,eAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,eAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,gBAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,gBAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,gBAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,gBAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -15,8 +15,8 @@ var _WebError = require("../../entities/WebError");
|
|
|
15
15
|
var _report = require("../../utils/report");
|
|
16
16
|
const namespace = 'engine:middleware:fileUploader';
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* Generate a custom fileUploader middleware
|
|
18
|
+
/**
|
|
19
|
+
* Generate a custom fileUploader middleware
|
|
20
20
|
*/
|
|
21
21
|
function fileUploader(options, validator) {
|
|
22
22
|
return (request, response, next) => fileUploaderMiddleware(request, response, next, options, validator);
|
|
@@ -53,9 +53,9 @@ function fileUploaderMiddleware(request, response, next, filesOptions, validator
|
|
|
53
53
|
});
|
|
54
54
|
let hasError = false;
|
|
55
55
|
|
|
56
|
-
/**
|
|
57
|
-
* Function called when an error happened in the process
|
|
58
|
-
* It immediately stops and drains all connection and deletes all files that have already been uploaded
|
|
56
|
+
/**
|
|
57
|
+
* Function called when an error happened in the process
|
|
58
|
+
* It immediately stops and drains all connection and deletes all files that have already been uploaded
|
|
59
59
|
*/
|
|
60
60
|
function triggerError(error) {
|
|
61
61
|
pendingWrites--;
|
|
@@ -100,15 +100,15 @@ function fileUploaderMiddleware(request, response, next, filesOptions, validator
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
/*
|
|
104
|
-
* On cancel request, while processing
|
|
103
|
+
/*
|
|
104
|
+
* On cancel request, while processing
|
|
105
105
|
*/
|
|
106
106
|
request.connection.on('close', function () {
|
|
107
107
|
if (!response.writableEnded) triggerError(new Error('Request cancelled'));
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
-
/**
|
|
111
|
-
* Once all the fields have been read they are checked against the validation schema
|
|
110
|
+
/**
|
|
111
|
+
* Once all the fields have been read they are checked against the validation schema
|
|
112
112
|
*/
|
|
113
113
|
async function validateFields() {
|
|
114
114
|
try {
|
|
@@ -257,9 +257,9 @@ function fileUploaderMiddleware(request, response, next, filesOptions, validator
|
|
|
257
257
|
});
|
|
258
258
|
});
|
|
259
259
|
|
|
260
|
-
/**
|
|
261
|
-
* Handle non file fields
|
|
262
|
-
* These fields will be pushed to the body as array of strings
|
|
260
|
+
/**
|
|
261
|
+
* Handle non file fields
|
|
262
|
+
* These fields will be pushed to the body as array of strings
|
|
263
263
|
*/
|
|
264
264
|
busboy.on('field', (fieldName, value) => {
|
|
265
265
|
if (!request.body) request.body = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileUploader.js","names":["_busboy","_interopRequireDefault","require","_compressAvatar","_isMultiPart","_validate","_Storage","_WebError","_report","namespace","fileUploader","options","validator","request","response","next","fileUploaderMiddleware","filesOptions","reportDebug","message","data","isMultipart","WebError","statusCode","errorCode","contentType","get","length","busboy","Busboy","headers","hasError","triggerError","error","pendingWrites","unpipe","on","read","bind","removeAllListeners","files","Object","values","forEach","file","Storage","delete","bucket","name","catch","reportError","readFinished","fieldsValidated","done","uploadedFiles","keys","some","required","includes","key","connection","writableEnded","Error","validateFields","validate","field","fileName","encoding","mimeType","destroy","find","fileOption","hint","mimeTypes","expected","fileToUpload","image","compressAvatar","uploadedFile","upload","directory","path","mime","noExtension","metadata","maxSize","push","originalFileName","fieldName","value","body","pipe"],"sources":["../../../src/middleware/fileUploader/fileUploader.ts"],"sourcesContent":["import Busboy from 'busboy';\nimport { Request, Response, NextFunction } from 'express';\nimport { Schema } from 'express-validator';\nimport { compressAvatar } from './compressAvatar';\nimport { FileUploaderConfig } from './fileUploader.types';\nimport { isMultipart } from './isMultiPart';\nimport { validate } from './validate';\nimport { Storage } from 'entities/Storage';\nimport { WebError } from 'entities/WebError';\nimport { reportError, reportDebug } from 'utils/report';\nimport { Readable } from 'stream';\n\nconst namespace = 'engine:middleware:fileUploader';\n\n/**\n * Generate a custom fileUploader middleware\n */\nexport function fileUploader(\n options: Array<FileUploaderConfig>,\n validator: Schema\n) {\n return (\n request: Request,\n response: Response,\n next: NextFunction\n ): Busboy.Busboy =>\n fileUploaderMiddleware(request, response, next, options, validator);\n}\n\n/** Handle file upload and generic multi-part parsing */\nexport function fileUploaderMiddleware(\n request: Request,\n response: Response,\n next: NextFunction,\n filesOptions: Array<FileUploaderConfig>,\n validator: Schema\n): Busboy.Busboy {\n reportDebug({\n namespace,\n message: 'Received request to upload file',\n data: { filesOptions, validator }\n });\n // Check that the request is a proper multipart request\n if (!isMultipart(request))\n throw new WebError({\n statusCode: 415,\n errorCode: 'invalid-content-type',\n message: 'Request is not of type multipart/form-data',\n data: { contentType: request.get('Content-Type') }\n });\n // If no files to handle ignore\n if (!filesOptions.length) next();\n // Parse multipart data with Busboy\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const busboy = new (Busboy as any)({\n headers: {\n ...request.headers,\n 'content-type': request.headers['content-type'] ?? ''\n }\n });\n\n let hasError = false;\n\n /**\n * Function called when an error happened in the process\n * It immediately stops and drains all connection and deletes all files that have already been uploaded\n */\n function triggerError(error: unknown): void {\n pendingWrites--;\n if (hasError) return;\n hasError = true;\n request.unpipe(busboy);\n request.on('readable', request.read.bind(request));\n busboy.removeAllListeners();\n next(error);\n if (request.files) {\n Object.values(request.files).forEach((files) => {\n files.forEach((file) => {\n Storage.delete(file.bucket, file.name).catch((error) => {\n reportError(error);\n });\n });\n });\n }\n }\n\n let readFinished = false;\n let fieldsValidated = false;\n let pendingWrites = 0;\n\n /** Function called when all the body has been parsed */\n function done(): void {\n if (readFinished && pendingWrites === 0 && fieldsValidated && !hasError) {\n const uploadedFiles = Object.keys(request.files ?? {});\n if (\n filesOptions.some(\n (options) => options.required && !uploadedFiles.includes(options.key)\n )\n ) {\n triggerError(\n new WebError({\n statusCode: 400,\n errorCode: 'missing-field',\n message: 'Some required files have not been uploaded',\n data: { filesOptions, validator, uploadedFiles }\n })\n );\n return;\n }\n next();\n }\n }\n\n /*\n * On cancel request, while processing\n */\n request.connection.on('close', function () {\n if (!response.writableEnded) triggerError(new Error('Request cancelled'));\n });\n\n /**\n * Once all the fields have been read they are checked against the validation schema\n */\n async function validateFields(): Promise<void> {\n try {\n await validate(request, validator);\n } catch (error) {\n triggerError(error);\n }\n reportDebug({\n namespace,\n message: 'Validation processed',\n data: { hasError, filesOptions, validator }\n });\n fieldsValidated = true;\n done();\n }\n\n busboy.on(\n 'file',\n (\n field: string,\n file: Readable,\n fileName: string,\n encoding: unknown,\n mimeType: string\n ) => {\n (async (): Promise<void> => {\n reportDebug({\n namespace,\n message: 'Found file in request',\n data: { hasError, field, fileName, encoding, mimeType, pendingWrites }\n });\n // Do not handle the stream if there has been an error previously\n if (hasError) file.destroy();\n pendingWrites++;\n // Find related file options based on the field name\n const options = filesOptions.find(\n (fileOption) => fileOption.key === field\n );\n // Make sure that the field is in the config\n if (!options) {\n triggerError(\n new WebError({\n statusCode: 400,\n errorCode: 'invalid-file-field',\n message: 'Request contains a file at an invalid field',\n hint: { field },\n data: { field }\n })\n );\n return;\n }\n reportDebug({\n namespace,\n message: 'Found options for file',\n data: {\n hasError,\n field,\n fileName,\n encoding,\n mimeType,\n pendingWrites,\n options\n }\n });\n // If a specific MIME type is required check it\n if (options.mimeTypes && !options.mimeTypes.includes(mimeType)) {\n triggerError(\n new WebError({\n statusCode: 415,\n errorCode: 'invalid-mime-type',\n message: 'Request contains a file with an invalid MIME type',\n hint: { field },\n data: { field, mimeType, expected: options.mimeTypes }\n })\n );\n return;\n }\n // Generate the destination path of the file and upload\n reportDebug({\n namespace,\n message: 'Starting file upload',\n data: {\n hasError,\n field,\n fileName,\n encoding,\n mimeType,\n pendingWrites,\n options\n }\n });\n try {\n const fileToUpload = options.image\n ? compressAvatar(file, options.image)\n : file;\n\n const uploadedFile = await Storage.upload(\n fileToUpload,\n options.bucket,\n {\n directory: options.path,\n mime: mimeType,\n noExtension: options.noExtension\n },\n {\n metadata: { contentType: mimeType }\n },\n { maxSize: options.maxSize }\n );\n\n reportDebug({\n namespace,\n message: 'File uploaded',\n data: {\n hasError,\n field,\n fileName,\n encoding,\n mimeType,\n pendingWrites,\n options,\n uploadedFile\n }\n });\n if (hasError) {\n // If some other failed before this one terminated\n // Delete file\n await Storage.delete(uploadedFile.bucket, uploadedFile.name);\n } else {\n // Handle successful upload\n // Add the file's data to the request\n pendingWrites--;\n if (!request.files) request.files = {};\n if (!request.files[field]) request.files[field] = [];\n request.files[field].push({\n ...uploadedFile,\n originalFileName: fileName\n });\n done();\n }\n } catch (error) {\n triggerError(error);\n }\n })().catch((error) => {\n triggerError(error);\n });\n }\n );\n\n /**\n * Handle non file fields\n * These fields will be pushed to the body as array of strings\n */\n busboy.on('field', (fieldName: string, value: unknown) => {\n if (!request.body) request.body = {};\n\n if (request.body[fieldName]) {\n request.body[fieldName].push(value);\n } else {\n request.body[fieldName] = [value];\n }\n });\n busboy.on('error', function (error: unknown) {\n triggerError(error);\n });\n busboy.on('finish', () => {\n (async (): Promise<void> => {\n reportDebug({\n namespace,\n message: 'Busboy finished reading',\n data: { hasError, filesOptions, validator, pendingWrites }\n });\n readFinished = true;\n await validateFields();\n done();\n })().catch((error) => {\n triggerError(error);\n });\n });\n return request.pipe(busboy);\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,eAAA,GAAAD,OAAA;AAEA,IAAAE,YAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAN,OAAA;AAGA,MAAMO,SAAS,GAAG,gCAAgC;;AAElD;AACA;AACA;AACO,SAASC,YAAYA,CAC1BC,OAAkC,EAClCC,SAAiB,EACjB;EACA,OAAO,CACLC,OAAgB,EAChBC,QAAkB,EAClBC,IAAkB,KAElBC,sBAAsB,CAACH,OAAO,EAAEC,QAAQ,EAAEC,IAAI,EAAEJ,OAAO,EAAEC,SAAS,CAAC;AACvE;;AAEA;AACO,SAASI,sBAAsBA,CACpCH,OAAgB,EAChBC,QAAkB,EAClBC,IAAkB,EAClBE,YAAuC,EACvCL,SAAiB,EACF;EACf,IAAAM,mBAAW,EAAC;IACVT,SAAS;IACTU,OAAO,EAAE,iCAAiC;IAC1CC,IAAI,EAAE;MAAEH,YAAY;MAAEL;IAAU;EAClC,CAAC,CAAC;EACF;EACA,IAAI,CAAC,IAAAS,wBAAW,EAACR,OAAO,CAAC,EACvB,MAAM,IAAIS,kBAAQ,CAAC;IACjBC,UAAU,EAAE,GAAG;IACfC,SAAS,EAAE,sBAAsB;IACjCL,OAAO,EAAE,4CAA4C;IACrDC,IAAI,EAAE;MAAEK,WAAW,EAAEZ,OAAO,CAACa,GAAG,CAAC,cAAc;IAAE;EACnD,CAAC,CAAC;EACJ;E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C,CAAC;MACtBV,IAAI,CAAC,CAAC;IACR,CAAC,EAAE,CAAC,CAACJ,KAAK,CAAEhB,KAAK,IAAK;MACpBD,YAAY,CAACC,KAAK,CAAC;IACrB,CAAC,CAAC;EACJ,CAAC,CAAC;EACF,OAAOpB,OAAO,CAAC8E,IAAI,CAAC/D,MAAM,CAAC;AAC7B","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"fileUploader.js","names":["_busboy","_interopRequireDefault","require","_compressAvatar","_isMultiPart","_validate","_Storage","_WebError","_report","namespace","fileUploader","options","validator","request","response","next","fileUploaderMiddleware","filesOptions","reportDebug","message","data","isMultipart","WebError","statusCode","errorCode","contentType","get","length","busboy","Busboy","headers","hasError","triggerError","error","pendingWrites","unpipe","on","read","bind","removeAllListeners","files","Object","values","forEach","file","Storage","delete","bucket","name","catch","reportError","readFinished","fieldsValidated","done","uploadedFiles","keys","some","required","includes","key","connection","writableEnded","Error","validateFields","validate","field","fileName","encoding","mimeType","destroy","find","fileOption","hint","mimeTypes","expected","fileToUpload","image","compressAvatar","uploadedFile","upload","directory","path","mime","noExtension","metadata","maxSize","push","originalFileName","fieldName","value","body","pipe"],"sources":["../../../src/middleware/fileUploader/fileUploader.ts"],"sourcesContent":["import Busboy from 'busboy';\r\nimport { Request, Response, NextFunction } from 'express';\r\nimport { Schema } from 'express-validator';\r\nimport { compressAvatar } from './compressAvatar';\r\nimport { FileUploaderConfig } from './fileUploader.types';\r\nimport { isMultipart } from './isMultiPart';\r\nimport { validate } from './validate';\r\nimport { Storage } from 'entities/Storage';\r\nimport { WebError } from 'entities/WebError';\r\nimport { reportError, reportDebug } from 'utils/report';\r\nimport { Readable } from 'stream';\r\n\r\nconst namespace = 'engine:middleware:fileUploader';\r\n\r\n/**\r\n * Generate a custom fileUploader middleware\r\n */\r\nexport function fileUploader(\r\n options: Array<FileUploaderConfig>,\r\n validator: Schema\r\n) {\r\n return (\r\n request: Request,\r\n response: Response,\r\n next: NextFunction\r\n ): Busboy.Busboy =>\r\n fileUploaderMiddleware(request, response, next, options, validator);\r\n}\r\n\r\n/** Handle file upload and generic multi-part parsing */\r\nexport function fileUploaderMiddleware(\r\n request: Request,\r\n response: Response,\r\n next: NextFunction,\r\n filesOptions: Array<FileUploaderConfig>,\r\n validator: Schema\r\n): Busboy.Busboy {\r\n reportDebug({\r\n namespace,\r\n message: 'Received request to upload file',\r\n data: { filesOptions, validator }\r\n });\r\n // Check that the request is a proper multipart request\r\n if (!isMultipart(request))\r\n throw new WebError({\r\n statusCode: 415,\r\n errorCode: 'invalid-content-type',\r\n message: 'Request is not of type multipart/form-data',\r\n data: { contentType: request.get('Content-Type') }\r\n });\r\n // If no files to handle ignore\r\n if (!filesOptions.length) next();\r\n // Parse multipart data with Busboy\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n const busboy = new (Busboy as any)({\r\n headers: {\r\n ...request.headers,\r\n 'content-type': request.headers['content-type'] ?? ''\r\n }\r\n });\r\n\r\n let hasError = false;\r\n\r\n /**\r\n * Function called when an error happened in the process\r\n * It immediately stops and drains all connection and deletes all files that have already been uploaded\r\n */\r\n function triggerError(error: unknown): void {\r\n pendingWrites--;\r\n if (hasError) return;\r\n hasError = true;\r\n request.unpipe(busboy);\r\n request.on('readable', request.read.bind(request));\r\n busboy.removeAllListeners();\r\n next(error);\r\n if (request.files) {\r\n Object.values(request.files).forEach((files) => {\r\n files.forEach((file) => {\r\n Storage.delete(file.bucket, file.name).catch((error) => {\r\n reportError(error);\r\n });\r\n });\r\n });\r\n }\r\n }\r\n\r\n let readFinished = false;\r\n let fieldsValidated = false;\r\n let pendingWrites = 0;\r\n\r\n /** Function called when all the body has been parsed */\r\n function done(): void {\r\n if (readFinished && pendingWrites === 0 && fieldsValidated && !hasError) {\r\n const uploadedFiles = Object.keys(request.files ?? {});\r\n if (\r\n filesOptions.some(\r\n (options) => options.required && !uploadedFiles.includes(options.key)\r\n )\r\n ) {\r\n triggerError(\r\n new WebError({\r\n statusCode: 400,\r\n errorCode: 'missing-field',\r\n message: 'Some required files have not been uploaded',\r\n data: { filesOptions, validator, uploadedFiles }\r\n })\r\n );\r\n return;\r\n }\r\n next();\r\n }\r\n }\r\n\r\n /*\r\n * On cancel request, while processing\r\n */\r\n request.connection.on('close', function () {\r\n if (!response.writableEnded) triggerError(new Error('Request cancelled'));\r\n });\r\n\r\n /**\r\n * Once all the fields have been read they are checked against the validation schema\r\n */\r\n async function validateFields(): Promise<void> {\r\n try {\r\n await validate(request, validator);\r\n } catch (error) {\r\n triggerError(error);\r\n }\r\n reportDebug({\r\n namespace,\r\n message: 'Validation processed',\r\n data: { hasError, filesOptions, validator }\r\n });\r\n fieldsValidated = true;\r\n done();\r\n }\r\n\r\n busboy.on(\r\n 'file',\r\n (\r\n field: string,\r\n file: Readable,\r\n fileName: string,\r\n encoding: unknown,\r\n mimeType: string\r\n ) => {\r\n (async (): Promise<void> => {\r\n reportDebug({\r\n namespace,\r\n message: 'Found file in request',\r\n data: { hasError, field, fileName, encoding, mimeType, pendingWrites }\r\n });\r\n // Do not handle the stream if there has been an error previously\r\n if (hasError) file.destroy();\r\n pendingWrites++;\r\n // Find related file options based on the field name\r\n const options = filesOptions.find(\r\n (fileOption) => fileOption.key === field\r\n );\r\n // Make sure that the field is in the config\r\n if (!options) {\r\n triggerError(\r\n new WebError({\r\n statusCode: 400,\r\n errorCode: 'invalid-file-field',\r\n message: 'Request contains a file at an invalid field',\r\n hint: { field },\r\n data: { field }\r\n })\r\n );\r\n return;\r\n }\r\n reportDebug({\r\n namespace,\r\n message: 'Found options for file',\r\n data: {\r\n hasError,\r\n field,\r\n fileName,\r\n encoding,\r\n mimeType,\r\n pendingWrites,\r\n options\r\n }\r\n });\r\n // If a specific MIME type is required check it\r\n if (options.mimeTypes && !options.mimeTypes.includes(mimeType)) {\r\n triggerError(\r\n new WebError({\r\n statusCode: 415,\r\n errorCode: 'invalid-mime-type',\r\n message: 'Request contains a file with an invalid MIME type',\r\n hint: { field },\r\n data: { field, mimeType, expected: options.mimeTypes }\r\n })\r\n );\r\n return;\r\n }\r\n // Generate the destination path of the file and upload\r\n reportDebug({\r\n namespace,\r\n message: 'Starting file upload',\r\n data: {\r\n hasError,\r\n field,\r\n fileName,\r\n encoding,\r\n mimeType,\r\n pendingWrites,\r\n options\r\n }\r\n });\r\n try {\r\n const fileToUpload = options.image\r\n ? compressAvatar(file, options.image)\r\n : file;\r\n\r\n const uploadedFile = await Storage.upload(\r\n fileToUpload,\r\n options.bucket,\r\n {\r\n directory: options.path,\r\n mime: mimeType,\r\n noExtension: options.noExtension\r\n },\r\n {\r\n metadata: { contentType: mimeType }\r\n },\r\n { maxSize: options.maxSize }\r\n );\r\n\r\n reportDebug({\r\n namespace,\r\n message: 'File uploaded',\r\n data: {\r\n hasError,\r\n field,\r\n fileName,\r\n encoding,\r\n mimeType,\r\n pendingWrites,\r\n options,\r\n uploadedFile\r\n }\r\n });\r\n if (hasError) {\r\n // If some other failed before this one terminated\r\n // Delete file\r\n await Storage.delete(uploadedFile.bucket, uploadedFile.name);\r\n } else {\r\n // Handle successful upload\r\n // Add the file's data to the request\r\n pendingWrites--;\r\n if (!request.files) request.files = {};\r\n if (!request.files[field]) request.files[field] = [];\r\n request.files[field].push({\r\n ...uploadedFile,\r\n originalFileName: fileName\r\n });\r\n done();\r\n }\r\n } catch (error) {\r\n triggerError(error);\r\n }\r\n })().catch((error) => {\r\n triggerError(error);\r\n });\r\n }\r\n );\r\n\r\n /**\r\n * Handle non file fields\r\n * These fields will be pushed to the body as array of strings\r\n */\r\n busboy.on('field', (fieldName: string, value: unknown) => {\r\n if (!request.body) request.body = {};\r\n\r\n if (request.body[fieldName]) {\r\n request.body[fieldName].push(value);\r\n } else {\r\n request.body[fieldName] = [value];\r\n }\r\n });\r\n busboy.on('error', function (error: unknown) {\r\n triggerError(error);\r\n });\r\n busboy.on('finish', () => {\r\n (async (): Promise<void> => {\r\n reportDebug({\r\n namespace,\r\n message: 'Busboy finished reading',\r\n data: { hasError, filesOptions, validator, pendingWrites }\r\n });\r\n readFinished = true;\r\n await validateFields();\r\n done();\r\n })().catch((error) => {\r\n triggerError(error);\r\n });\r\n });\r\n return request.pipe(busboy);\r\n}\r\n"],"mappings":";;;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,eAAA,GAAAD,OAAA;AAEA,IAAAE,YAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAN,OAAA;AAGA,MAAMO,SAAS,GAAG,gCAAgC;;AAElD;AACA;AACA;AACO,SAASC,YAAYA,CAC1BC,OAAkC,EAClCC,SAAiB,EACjB;EACA,OAAO,CACLC,OAAgB,EAChBC,QAAkB,EAClBC,IAAkB,KAElBC,sBAAsB,CAACH,OAAO,EAAEC,QAAQ,EAAEC,IAAI,EAAEJ,OAAO,EAAEC,SAAS,CAAC;AACvE;;AAEA;AACO,SAASI,sBAAsBA,CACpCH,OAAgB,EAChBC,QAAkB,EAClBC,IAAkB,EAClBE,YAAuC,EACvCL,SAAiB,EACF;EACf,IAAAM,mBAAW,EAAC;IACVT,SAAS;IACTU,OAAO,EAAE,iCAAiC;IAC1CC,IAAI,EAAE;MAAEH,YAAY;MAAEL;IAAU;EAClC,CAAC,CAAC;EACF;EACA,IAAI,CAAC,IAAAS,wBAAW,EAACR,OAAO,CAAC,EACvB,MAAM,IAAIS,kBAAQ,CAAC;IACjBC,UAAU,EAAE,GAAG;IACfC,SAAS,EAAE,sBAAsB;IACjCL,OAAO,EAAE,4CAA4C;IACrDC,IAAI,EAAE;MAAEK,WAAW,EAAEZ,OAAO,CAACa,GAAG,CAAC,cAAc;IAAE;EACnD,CAAC,CAAC;EACJ;EACA,IAAI,CAACT,YAAY,CAACU,MAAM,EAAEZ,IAAI,CAAC,CAAC;EAChC;EACA;EACA,MAAMa,MAAM,GAAG,IAAKC,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,CAACC,KAAK,CAAC;IACrB,CAAC,CAAC;EACJ,CAAC,CAAC;EACF,OAAOpB,OAAO,CAAC8E,IAAI,CAAC/D,MAAM,CAAC;AAC7B","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileUploader.types.js","names":[],"sources":["../../../src/middleware/fileUploader/fileUploader.types.ts"],"sourcesContent":["import { CompressionOptions } from './compressAvatar';\nimport { StorageUploadedFile } from 'entities/Storage';\n\n// Override the Express request object to add the files\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Express {\n /** Express request object */\n interface Request {\n /** Configuration for files that are uploaded with the request */\n files?: { [key: string]: Array<UploadedFile> };\n }\n }\n}\n\n/** Custom uploaded file metadata */\nexport interface UploadedFile extends StorageUploadedFile {\n /** File name that was given to the file by the client */\n originalFileName: string;\n}\n\n/** Outputs setting for the file upload. Defines where a file should be stored and how it should be processed. */\ninterface FileUploaderOutputs {\n /** Name of the output */\n name: string;\n /** Path to which this specific output is stored (defaults to default path if not set) */\n path?: string;\n /** Bucket to which this specific output is stored (defaults to default bucket if not set) */\n bucket?: string;\n}\n\n/** Configuration for a file upload */\nexport interface FileUploaderConfig {\n /** Field key for which this configuration applies */\n key: string;\n /** A list of supported MIME Types for the file */\n mimeTypes?: Array<string>;\n /** Base path where the file should be stored (default used when no output config is set, will be used as temporary storage when outputs are set) */\n path?: string;\n /** Bucket in which the file should be stored (will be used as temporary storage when outputs are set) */\n bucket: string;\n /** Maximum size of the file (ex: 2MB) */\n maxSize?: string;\n /** Indicates that the file must be present */\n required?: boolean;\n /** Do not store with an extension (will simply be a uuid) */\n noExtension?: boolean;\n /** Specify multiple outputs with processing */\n outputs?: Array<FileUploaderOutputs>;\n /** @deprecated compression of images */\n image?: CompressionOptions;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"fileUploader.types.js","names":[],"sources":["../../../src/middleware/fileUploader/fileUploader.types.ts"],"sourcesContent":["import { CompressionOptions } from './compressAvatar';\r\nimport { StorageUploadedFile } from 'entities/Storage';\r\n\r\n// Override the Express request object to add the files\r\ndeclare global {\r\n // eslint-disable-next-line @typescript-eslint/no-namespace\r\n namespace Express {\r\n /** Express request object */\r\n interface Request {\r\n /** Configuration for files that are uploaded with the request */\r\n files?: { [key: string]: Array<UploadedFile> };\r\n }\r\n }\r\n}\r\n\r\n/** Custom uploaded file metadata */\r\nexport interface UploadedFile extends StorageUploadedFile {\r\n /** File name that was given to the file by the client */\r\n originalFileName: string;\r\n}\r\n\r\n/** Outputs setting for the file upload. Defines where a file should be stored and how it should be processed. */\r\ninterface FileUploaderOutputs {\r\n /** Name of the output */\r\n name: string;\r\n /** Path to which this specific output is stored (defaults to default path if not set) */\r\n path?: string;\r\n /** Bucket to which this specific output is stored (defaults to default bucket if not set) */\r\n bucket?: string;\r\n}\r\n\r\n/** Configuration for a file upload */\r\nexport interface FileUploaderConfig {\r\n /** Field key for which this configuration applies */\r\n key: string;\r\n /** A list of supported MIME Types for the file */\r\n mimeTypes?: Array<string>;\r\n /** Base path where the file should be stored (default used when no output config is set, will be used as temporary storage when outputs are set) */\r\n path?: string;\r\n /** Bucket in which the file should be stored (will be used as temporary storage when outputs are set) */\r\n bucket: string;\r\n /** Maximum size of the file (ex: 2MB) */\r\n maxSize?: string;\r\n /** Indicates that the file must be present */\r\n required?: boolean;\r\n /** Do not store with an extension (will simply be a uuid) */\r\n noExtension?: boolean;\r\n /** Specify multiple outputs with processing */\r\n outputs?: Array<FileUploaderOutputs>;\r\n /** @deprecated compression of images */\r\n image?: CompressionOptions;\r\n}\r\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_fileUploader","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_fileUploader2"],"sources":["../../../src/middleware/fileUploader/index.ts"],"sourcesContent":["export * from './fileUploader';\nexport * from './fileUploader.types';\n"],"mappings":";;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,aAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,aAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,aAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,cAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,cAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,cAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,cAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_fileUploader","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_fileUploader2"],"sources":["../../../src/middleware/fileUploader/index.ts"],"sourcesContent":["export * from './fileUploader';\r\nexport * from './fileUploader.types';\r\n"],"mappings":";;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,aAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,aAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,aAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,cAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,cAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,cAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,cAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_isMultipart","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../../../src/middleware/fileUploader/isMultiPart/index.ts"],"sourcesContent":["export * from './isMultipart';\n"],"mappings":";;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,YAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,YAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,YAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_isMultipart","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../../../src/middleware/fileUploader/isMultiPart/index.ts"],"sourcesContent":["export * from './isMultipart';\r\n"],"mappings":";;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,YAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,YAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,YAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isMultipart.js","names":["multipartRegex","isMultipart","request","type","get","test","toLowerCase"],"sources":["../../../../src/middleware/fileUploader/isMultiPart/isMultipart.ts"],"sourcesContent":["import { Request } from 'express';\n\nconst multipartRegex = /^multipart\\/form-data.+$/;\n\n/** Determines if the content type of a request is multipart/form-data */\nexport function isMultipart(request: Request): boolean {\n const type = request.get('Content-Type');\n return !!type && multipartRegex.test(type.toLowerCase());\n}\n"],"mappings":";;;;;;AAEA,MAAMA,cAAc,GAAG,0BAA0B;;AAEjD;AACO,SAASC,WAAWA,CAACC,OAAgB,EAAW;EACrD,MAAMC,IAAI,GAAGD,OAAO,CAACE,GAAG,CAAC,cAAc,CAAC;EACxC,OAAO,CAAC,CAACD,IAAI,IAAIH,cAAc,CAACK,IAAI,CAACF,IAAI,CAACG,WAAW,CAAC,CAAC,CAAC;AAC1D","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"isMultipart.js","names":["multipartRegex","isMultipart","request","type","get","test","toLowerCase"],"sources":["../../../../src/middleware/fileUploader/isMultiPart/isMultipart.ts"],"sourcesContent":["import { Request } from 'express';\r\n\r\nconst multipartRegex = /^multipart\\/form-data.+$/;\r\n\r\n/** Determines if the content type of a request is multipart/form-data */\r\nexport function isMultipart(request: Request): boolean {\r\n const type = request.get('Content-Type');\r\n return !!type && multipartRegex.test(type.toLowerCase());\r\n}\r\n"],"mappings":";;;;;;AAEA,MAAMA,cAAc,GAAG,0BAA0B;;AAEjD;AACO,SAASC,WAAWA,CAACC,OAAgB,EAAW;EACrD,MAAMC,IAAI,GAAGD,OAAO,CAACE,GAAG,CAAC,cAAc,CAAC;EACxC,OAAO,CAAC,CAACD,IAAI,IAAIH,cAAc,CAACK,IAAI,CAACF,IAAI,CAACG,WAAW,CAAC,CAAC,CAAC;AAC1D","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_validate","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../../../src/middleware/fileUploader/validate/index.ts"],"sourcesContent":["export * from './validate';\n"],"mappings":";;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,SAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,SAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,SAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_validate","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../../../src/middleware/fileUploader/validate/index.ts"],"sourcesContent":["export * from './validate';\r\n"],"mappings":";;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,SAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,SAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,SAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","names":["_validate","require","validate","request","schema","Promise","resolve","reject","validationChain","validateMiddleware","flat","length","position","next","error","undefined"],"sources":["../../../../src/middleware/fileUploader/validate/validate.ts"],"sourcesContent":["import { Request } from 'express';\nimport { Schema } from 'express-validator';\nimport { validate as validateMiddleware } from 'middleware/validate';\n\n/** Validate a schema against a request using our validation middleware */\nexport async function validate(\n request: Request,\n schema: Schema\n): Promise<void> {\n return new Promise((resolve, reject) => {\n // Generate a validation chain using our middleware\n const validationChain = validateMiddleware(schema).flat();\n if (!validationChain.length) resolve();\n // Recursively go through each middleware by imitating the next function from express\n let position = -1;\n const next = (error?: unknown): void => {\n if (error) reject(error);\n position++;\n if (position === validationChain.length) {\n resolve();\n return;\n }\n validationChain[position](request, undefined, next);\n };\n next();\n });\n}\n"],"mappings":";;;;;;AAEA,IAAAA,SAAA,GAAAC,OAAA;AAEA;AACO,eAAeC,QAAQA,CAC5BC,OAAgB,EAChBC,MAAc,EACC;EACf,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACtC;IACA,MAAMC,eAAe,GAAG,IAAAC,kBAAkB,EAACL,MAAM,CAAC,CAACM,IAAI,CAAC,CAAC;IACzD,IAAI,CAACF,eAAe,CAACG,MAAM,EAAEL,OAAO,CAAC,CAAC;IACtC;IACA,IAAIM,QAAQ,GAAG,CAAC,CAAC;IACjB,MAAMC,IAAI,GAAIC,KAAe,IAAW;MACtC,IAAIA,KAAK,EAAEP,MAAM,CAACO,KAAK,CAAC;MACxBF,QAAQ,EAAE;MACV,IAAIA,QAAQ,KAAKJ,eAAe,CAACG,MAAM,EAAE;QACvCL,OAAO,CAAC,CAAC;QACT;MACF;MACAE,eAAe,CAACI,QAAQ,CAAC,CAACT,OAAO,EAAEY,SAAS,EAAEF,IAAI,CAAC;IACrD,CAAC;IACDA,IAAI,CAAC,CAAC;EACR,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"validate.js","names":["_validate","require","validate","request","schema","Promise","resolve","reject","validationChain","validateMiddleware","flat","length","position","next","error","undefined"],"sources":["../../../../src/middleware/fileUploader/validate/validate.ts"],"sourcesContent":["import { Request } from 'express';\r\nimport { Schema } from 'express-validator';\r\nimport { validate as validateMiddleware } from 'middleware/validate';\r\n\r\n/** Validate a schema against a request using our validation middleware */\r\nexport async function validate(\r\n request: Request,\r\n schema: Schema\r\n): Promise<void> {\r\n return new Promise((resolve, reject) => {\r\n // Generate a validation chain using our middleware\r\n const validationChain = validateMiddleware(schema).flat();\r\n if (!validationChain.length) resolve();\r\n // Recursively go through each middleware by imitating the next function from express\r\n let position = -1;\r\n const next = (error?: unknown): void => {\r\n if (error) reject(error);\r\n position++;\r\n if (position === validationChain.length) {\r\n resolve();\r\n return;\r\n }\r\n validationChain[position](request, undefined, next);\r\n };\r\n next();\r\n });\r\n}\r\n"],"mappings":";;;;;;AAEA,IAAAA,SAAA,GAAAC,OAAA;AAEA;AACO,eAAeC,QAAQA,CAC5BC,OAAgB,EAChBC,MAAc,EACC;EACf,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACtC;IACA,MAAMC,eAAe,GAAG,IAAAC,kBAAkB,EAACL,MAAM,CAAC,CAACM,IAAI,CAAC,CAAC;IACzD,IAAI,CAACF,eAAe,CAACG,MAAM,EAAEL,OAAO,CAAC,CAAC;IACtC;IACA,IAAIM,QAAQ,GAAG,CAAC,CAAC;IACjB,MAAMC,IAAI,GAAIC,KAAe,IAAW;MACtC,IAAIA,KAAK,EAAEP,MAAM,CAACO,KAAK,CAAC;MACxBF,QAAQ,EAAE;MACV,IAAIA,QAAQ,KAAKJ,eAAe,CAACG,MAAM,EAAE;QACvCL,OAAO,CAAC,CAAC;QACT;MACF;MACAE,eAAe,CAACI,QAAQ,CAAC,CAACT,OAAO,EAAEY,SAAS,EAAEF,IAAI,CAAC;IACrD,CAAC;IACDA,IAAI,CAAC,CAAC;EACR,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fourOhFour.js","names":["_utils","require","namespace","fourOhFour","request","response","reportDebug","message","method","path","sendStatus"],"sources":["../../../src/middleware/fourOhFour/fourOhFour.ts"],"sourcesContent":["import { Request, Response } from 'express';\nimport { reportDebug } from 'utils';\n\nconst namespace = 'engine:middleware:fourOhFour';\n\n/** Unhandled path middleware */\nexport function fourOhFour(request: Request, response: Response): void {\n reportDebug({\n namespace,\n message: `No route found [${request.method} - ${request.path}]`\n });\n response.sendStatus(404);\n}\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAEA,MAAMC,SAAS,GAAG,8BAA8B;;AAEhD;AACO,SAASC,UAAUA,CAACC,OAAgB,EAAEC,QAAkB,EAAQ;EACrE,IAAAC,kBAAW,EAAC;IACVJ,SAAS;IACTK,OAAO,EAAE,mBAAmBH,OAAO,CAACI,MAAM,MAAMJ,OAAO,CAACK,IAAI;EAC9D,CAAC,CAAC;EACFJ,QAAQ,CAACK,UAAU,CAAC,GAAG,CAAC;AAC1B","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"fourOhFour.js","names":["_utils","require","namespace","fourOhFour","request","response","reportDebug","message","method","path","sendStatus"],"sources":["../../../src/middleware/fourOhFour/fourOhFour.ts"],"sourcesContent":["import { Request, Response } from 'express';\r\nimport { reportDebug } from 'utils';\r\n\r\nconst namespace = 'engine:middleware:fourOhFour';\r\n\r\n/** Unhandled path middleware */\r\nexport function fourOhFour(request: Request, response: Response): void {\r\n reportDebug({\r\n namespace,\r\n message: `No route found [${request.method} - ${request.path}]`\r\n });\r\n response.sendStatus(404);\r\n}\r\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAEA,MAAMC,SAAS,GAAG,8BAA8B;;AAEhD;AACO,SAASC,UAAUA,CAACC,OAAgB,EAAEC,QAAkB,EAAQ;EACrE,IAAAC,kBAAW,EAAC;IACVJ,SAAS;IACTK,OAAO,EAAE,mBAAmBH,OAAO,CAACI,MAAM,MAAMJ,OAAO,CAACK,IAAI;EAC9D,CAAC,CAAC;EACFJ,QAAQ,CAACK,UAAU,CAAC,GAAG,CAAC;AAC1B","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_fourOhFour","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../../src/middleware/fourOhFour/index.ts"],"sourcesContent":["export * from './fourOhFour';\n"],"mappings":";;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,WAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,WAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,WAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_fourOhFour","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../../src/middleware/fourOhFour/index.ts"],"sourcesContent":["export * from './fourOhFour';\r\n"],"mappings":";;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,WAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,WAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,WAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geminiFileUploader.js","names":["_multer","_interopRequireDefault","require","_server","_fs","_path","_tmp","_report","_checkEnvironment","_envAssert","namespace","apiKey","process","env","GOOGLE_AI_KEY","fileManager","GoogleAIFileManager","storage","multer","memoryStorage","uploadToGemini","buffer","mimeType","originalName","tempFile","tmp","fileSync","postfix","path","extname","fs","writeFileSync","name","uploadResult","uploadFile","displayName","removeCallback","file","reportDebug","message","data","uri","waitForFilesActive","files","getFile","state","stdout","write","Promise","resolve","setTimeout","reportError","geminiFileUploader","req","res","next","checkEnvironment","envAssert","isString","uploadSingle","single","err","mimetype","uploadedFile","originalname","body","fileUri","error","console"],"sources":["../../../src/middleware/geminiFileUploader/geminiFileUploader.ts"],"sourcesContent":["import express from 'express';\nimport multer from 'multer';\nimport { GoogleAIFileManager } from '@google/generative-ai/server';\nimport fs from 'fs';\nimport path from 'path';\nimport tmp from 'tmp';\nimport { reportError, reportDebug } from 'utils/report';\nimport { checkEnvironment } from 'utils/checkEnvironment';\nimport { envAssert } from 'utils/envAssert';\n\nconst namespace = 'engine:middleware:geminiFileUploader';\n\nconst apiKey = process.env.GOOGLE_AI_KEY ?? '';\nconst fileManager = new GoogleAIFileManager(apiKey);\n\nconst storage = multer.memoryStorage();\n\nasync function uploadToGemini(\n buffer: Buffer,\n mimeType: string,\n originalName: string\n): Promise<{ name: string; uri: string; mimeType: string }> {\n // Add 'name' to the return type\n const tempFile = tmp.fileSync({ postfix: path.extname(originalName) });\n\n fs.writeFileSync(tempFile.name, buffer);\n\n const uploadResult = await fileManager.uploadFile(tempFile.name, {\n mimeType,\n displayName: originalName\n });\n\n tempFile.removeCallback();\n\n const file = uploadResult.file;\n reportDebug({\n namespace,\n message: 'Uploaded file',\n data: { displayName: file.displayName, name: file.name }\n });\n return { name: file.name, uri: file.uri, mimeType: file.mimeType }; // Include 'name' in the return object\n}\n\nasync function waitForFilesActive(\n files: { name: string; uri: string; mimeType: string }[]\n): Promise<void> {\n reportDebug({\n namespace,\n message: 'Waiting for file processing...'\n });\n for (const { name } of files) {\n let file = await fileManager.getFile(name);\n while (file.state === 'PROCESSING') {\n process.stdout.write('.');\n await new Promise((resolve) => setTimeout(resolve, 10_000));\n file = await fileManager.getFile(name);\n }\n if (file.state !== 'ACTIVE') {\n reportError(`File ${file.name} failed to process`);\n }\n }\n reportDebug({\n namespace,\n message: 'all files ready...\\n'\n });\n}\n\nexport async function geminiFileUploader(\n req: express.Request,\n res: express.Response,\n next: express.NextFunction\n): Promise<void> {\n try {\n checkEnvironment({\n GOOGLE_AI_KEY: envAssert.isString()\n });\n // Use multer.single() inside the middleware\n const uploadSingle = multer({ storage }).single('file');\n\n uploadSingle(req, res, async (err) => {\n if (err) {\n reportError(`Error uploading file`);\n next(err);\n return;\n }\n\n const file = req.file;\n if (!file) {\n reportError(`No file uploaded`);\n next(`No file uploaded`);\n return;\n }\n const mimeType = file.mimetype;\n\n const uploadedFile = await uploadToGemini(\n file.buffer,\n mimeType,\n file.originalname\n );\n\n await waitForFilesActive([uploadedFile]);\n\n // Set the fileUri and mimeType in the request object for the next middleware/route handler\n req.body.file = {\n fileUri: uploadedFile.uri,\n mimeType: uploadedFile.mimeType,\n originalname: file.originalname\n };\n\n next(); // Proceed to the next middleware or route handler\n });\n } catch (error) {\n console.error(error);\n reportError(`Failed to upload or process file`);\n next(error);\n }\n}\n"],"mappings":";;;;;;;AACA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,GAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,KAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,IAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AACA,IAAAO,UAAA,GAAAP,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,YAAY,GAAG,MAAM3C,cAAc,CACvCiB,IAAI,CAAChB,MAAM,EACXC,QAAQ,EACRe,IAAI,CAAC2B,YACP,CAAC;MAED,MAAMtB,kBAAkB,CAAC,CAACqB,YAAY,CAAC,CAAC;;MAExC;MACAV,GAAG,CAACY,IAAI,CAAC5B,IAAI,GAAG;QACd6B,OAAO,EAAEH,YAAY,CAACtB,GAAG;QACzBnB,QAAQ,EAAEyC,YAAY,CAACzC,QAAQ;QAC/B0C,YAAY,EAAE3B,IAAI,CAAC2B;MACrB,CAAC;MAEDT,IAAI,CAAC,CAAC,CAAC,CAAC;IACV,CAAC,CAAC;EACJ,CAAC,CAAC,OAAOY,KAAK,EAAE;IACdC,OAAO,CAACD,KAAK,CAACA,KAAK,CAAC;IACpB,IAAAhB,mBAAW,EAAC,kCAAkC,CAAC;IAC/CI,IAAI,CAACY,KAAK,CAAC;EACb;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"geminiFileUploader.js","names":["_multer","_interopRequireDefault","require","_server","_fs","_path","_tmp","_report","_checkEnvironment","_envAssert","namespace","apiKey","process","env","GOOGLE_AI_KEY","fileManager","GoogleAIFileManager","storage","multer","memoryStorage","uploadToGemini","buffer","mimeType","originalName","tempFile","tmp","fileSync","postfix","path","extname","fs","writeFileSync","name","uploadResult","uploadFile","displayName","removeCallback","file","reportDebug","message","data","uri","waitForFilesActive","files","getFile","state","stdout","write","Promise","resolve","setTimeout","reportError","geminiFileUploader","req","res","next","checkEnvironment","envAssert","isString","uploadSingle","single","err","mimetype","uploadedFile","originalname","body","fileUri","error","console"],"sources":["../../../src/middleware/geminiFileUploader/geminiFileUploader.ts"],"sourcesContent":["import express from 'express';\r\nimport multer from 'multer';\r\nimport { GoogleAIFileManager } from '@google/generative-ai/server';\r\nimport fs from 'fs';\r\nimport path from 'path';\r\nimport tmp from 'tmp';\r\nimport { reportError, reportDebug } from 'utils/report';\r\nimport { checkEnvironment } from 'utils/checkEnvironment';\r\nimport { envAssert } from 'utils/envAssert';\r\n\r\nconst namespace = 'engine:middleware:geminiFileUploader';\r\n\r\nconst apiKey = process.env.GOOGLE_AI_KEY ?? '';\r\nconst fileManager = new GoogleAIFileManager(apiKey);\r\n\r\nconst storage = multer.memoryStorage();\r\n\r\nasync function uploadToGemini(\r\n buffer: Buffer,\r\n mimeType: string,\r\n originalName: string\r\n): Promise<{ name: string; uri: string; mimeType: string }> {\r\n // Add 'name' to the return type\r\n const tempFile = tmp.fileSync({ postfix: path.extname(originalName) });\r\n\r\n fs.writeFileSync(tempFile.name, buffer);\r\n\r\n const uploadResult = await fileManager.uploadFile(tempFile.name, {\r\n mimeType,\r\n displayName: originalName\r\n });\r\n\r\n tempFile.removeCallback();\r\n\r\n const file = uploadResult.file;\r\n reportDebug({\r\n namespace,\r\n message: 'Uploaded file',\r\n data: { displayName: file.displayName, name: file.name }\r\n });\r\n return { name: file.name, uri: file.uri, mimeType: file.mimeType }; // Include 'name' in the return object\r\n}\r\n\r\nasync function waitForFilesActive(\r\n files: { name: string; uri: string; mimeType: string }[]\r\n): Promise<void> {\r\n reportDebug({\r\n namespace,\r\n message: 'Waiting for file processing...'\r\n });\r\n for (const { name } of files) {\r\n let file = await fileManager.getFile(name);\r\n while (file.state === 'PROCESSING') {\r\n process.stdout.write('.');\r\n await new Promise((resolve) => setTimeout(resolve, 10_000));\r\n file = await fileManager.getFile(name);\r\n }\r\n if (file.state !== 'ACTIVE') {\r\n reportError(`File ${file.name} failed to process`);\r\n }\r\n }\r\n reportDebug({\r\n namespace,\r\n message: 'all files ready...\\n'\r\n });\r\n}\r\n\r\nexport async function geminiFileUploader(\r\n req: express.Request,\r\n res: express.Response,\r\n next: express.NextFunction\r\n): Promise<void> {\r\n try {\r\n checkEnvironment({\r\n GOOGLE_AI_KEY: envAssert.isString()\r\n });\r\n // Use multer.single() inside the middleware\r\n const uploadSingle = multer({ storage }).single('file');\r\n\r\n uploadSingle(req, res, async (err) => {\r\n if (err) {\r\n reportError(`Error uploading file`);\r\n next(err);\r\n return;\r\n }\r\n\r\n const file = req.file;\r\n if (!file) {\r\n reportError(`No file uploaded`);\r\n next(`No file uploaded`);\r\n return;\r\n }\r\n const mimeType = file.mimetype;\r\n\r\n const uploadedFile = await uploadToGemini(\r\n file.buffer,\r\n mimeType,\r\n file.originalname\r\n );\r\n\r\n await waitForFilesActive([uploadedFile]);\r\n\r\n // Set the fileUri and mimeType in the request object for the next middleware/route handler\r\n req.body.file = {\r\n fileUri: uploadedFile.uri,\r\n mimeType: uploadedFile.mimeType,\r\n originalname: file.originalname\r\n };\r\n\r\n next(); // Proceed to the next middleware or route handler\r\n });\r\n } catch (error) {\r\n console.error(error);\r\n reportError(`Failed to upload or process file`);\r\n next(error);\r\n }\r\n}\r\n"],"mappings":";;;;;;;AACA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,GAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,KAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,IAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AACA,IAAAO,UAAA,GAAAP,OAAA;AAEA,MAAMQ,SAAS,GAAG,sCAAsC;AAExD,MAAMC,MAAM,GAAGC,OAAO,CAACC,GAAG,CAACC,aAAa,IAAI,EAAE;AAC9C,MAAMC,WAAW,GAAG,IAAIC,2BAAmB,CAACL,MAAM,CAAC;AAEnD,MAAMM,OAAO,GAAGC,eAAM,CAACC,aAAa,CAAC,CAAC;AAEtC,eAAeC,cAAcA,CAC3BC,MAAc,EACdC,QAAgB,EAChBC,YAAoB,EACsC;EAC1D;EACA,MAAMC,QAAQ,GAAGC,YAAG,CAACC,QAAQ,CAAC;IAAEC,OAAO,EAAEC,aAAI,CAACC,OAAO,CAACN,YAAY;EAAE,CAAC,CAAC;EAEtEO,WAAE,CAACC,aAAa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AAK,CAACA,KAAK,CAAC;IACpB,IAAAhB,mBAAW,EAAC,kCAAkC,CAAC;IAC/CI,IAAI,CAACY,KAAK,CAAC;EACb;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_geminiFileUploader","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../../src/middleware/geminiFileUploader/index.ts"],"sourcesContent":["export * from './geminiFileUploader';\n"],"mappings":";;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,mBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,mBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,mBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_geminiFileUploader","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../../../src/middleware/geminiFileUploader/index.ts"],"sourcesContent":["export * from './geminiFileUploader';\r\n"],"mappings":";;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,mBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,mBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,mBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.healthCheck = healthCheck;
|
|
7
7
|
var _express = require("express");
|
|
8
|
-
/**
|
|
9
|
-
* respond to Kubernetes health-checks with 200
|
|
8
|
+
/**
|
|
9
|
+
* respond to Kubernetes health-checks with 200
|
|
10
10
|
*/
|
|
11
11
|
function healthCheck(path = '/heartbeat') {
|
|
12
12
|
return (0, _express.Router)().get('/', (req, res) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"healthCheck.js","names":["_express","require","healthCheck","path","Router","get","req","res","sendStatus"],"sources":["../../../src/middleware/healthCheck/healthCheck.ts"],"sourcesContent":["import { Router, Request, Response } from 'express';\n\n/**\n * respond to Kubernetes health-checks with 200\n */\nexport function healthCheck(path = '/heartbeat'): Router {\n return Router()\n .get('/', (req: Request, res: Response) => {\n res.sendStatus(200);\n })\n .get(path, (req: Request, res: Response) => {\n res.sendStatus(200);\n });\n}\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACO,SAASC,WAAWA,CAACC,IAAI,GAAG,YAAY,EAAU;EACvD,OAAO,IAAAC,eAAM,EAAC,CAAC,CACZC,GAAG,CAAC,GAAG,EAAE,CAACC,GAAY,EAAEC,GAAa,KAAK;IACzCA,GAAG,CAACC,UAAU,CAAC,GAAG,CAAC;EACrB,CAAC,CAAC,CACDH,GAAG,CAACF,IAAI,EAAE,CAACG,GAAY,EAAEC,GAAa,KAAK;IAC1CA,GAAG,CAACC,UAAU,CAAC,GAAG,CAAC;EACrB,CAAC,CAAC;AACN","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"healthCheck.js","names":["_express","require","healthCheck","path","Router","get","req","res","sendStatus"],"sources":["../../../src/middleware/healthCheck/healthCheck.ts"],"sourcesContent":["import { Router, Request, Response } from 'express';\r\n\r\n/**\r\n * respond to Kubernetes health-checks with 200\r\n */\r\nexport function healthCheck(path = '/heartbeat'): Router {\r\n return Router()\r\n .get('/', (req: Request, res: Response) => {\r\n res.sendStatus(200);\r\n })\r\n .get(path, (req: Request, res: Response) => {\r\n res.sendStatus(200);\r\n });\r\n}\r\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACO,SAASC,WAAWA,CAACC,IAAI,GAAG,YAAY,EAAU;EACvD,OAAO,IAAAC,eAAM,EAAC,CAAC,CACZC,GAAG,CAAC,GAAG,EAAE,CAACC,GAAY,EAAEC,GAAa,KAAK;IACzCA,GAAG,CAACC,UAAU,CAAC,GAAG,CAAC;EACrB,CAAC,CAAC,CACDH,GAAG,CAACF,IAAI,EAAE,CAACG,GAAY,EAAEC,GAAa,KAAK;IAC1CA,GAAG,CAACC,UAAU,CAAC,GAAG,CAAC;EACrB,CAAC,CAAC;AACN","ignoreList":[]}
|