raiton 1.1.1 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/README.md +97 -1
- package/build/bin/index.mjs +7012 -47
- package/deno.json +9 -0
- package/package.json +28 -44
- package/scripts/update-version.ts +97 -0
- package/source/bin/bootstrapper.ts +15 -0
- package/source/bin/cli-tools.ts +68 -0
- package/source/bin/cli.ts +12 -0
- package/source/bin/constants.ts +5 -0
- package/source/bin/index.ts +6 -0
- package/source/commands/artifact.command.ts +28 -0
- package/source/commands/build.command.ts +31 -0
- package/source/commands/develop.command.ts +47 -0
- package/source/commands/grafts.command.ts +27 -0
- package/source/commands/start.command.ts +28 -0
- package/source/core/application.ts +163 -0
- package/source/core/builder.ts +144 -0
- package/source/core/bytes.util.ts +17 -0
- package/source/core/command.ts +24 -0
- package/source/core/commands.ts +44 -0
- package/source/core/config/config.ts +51 -0
- package/source/core/config/define.ts +13 -0
- package/source/core/config/index.ts +2 -0
- package/source/core/context.ts +33 -0
- package/source/core/controller/builder.ts +41 -0
- package/source/core/controller/compiler.ts +22 -0
- package/source/core/controller/index.ts +3 -0
- package/source/core/controller/metadata.ts +13 -0
- package/source/core/directories.ts +30 -0
- package/source/core/helpers/index.ts +1 -0
- package/source/core/helpers/raiton.ts +3 -0
- package/source/core/hooks.ts +28 -0
- package/source/core/index.ts +14 -0
- package/source/core/injection/index.ts +1 -0
- package/source/core/injection/injection.ts +219 -0
- package/source/core/middleware/compose.ts +40 -0
- package/source/core/middleware/index.ts +2 -0
- package/source/core/middleware/pipeline.ts +27 -0
- package/source/core/plugins/index.ts +2 -0
- package/source/core/plugins/plugin.ts +8 -0
- package/source/core/plugins/scope.ts +46 -0
- package/source/core/process.util.ts +12 -0
- package/source/core/raiton.ts +20 -0
- package/source/core/router/handler.ts +115 -0
- package/source/core/router/index.ts +4 -0
- package/source/core/router/matcher.ts +51 -0
- package/source/core/router/route.ts +63 -0
- package/source/core/router/router.ts +31 -0
- package/source/core/server.ts +26 -0
- package/source/core/thread.ts +112 -0
- package/source/env.d.ts +3 -0
- package/source/requirements.ts +27 -0
- package/source/sdk/artifacts.ts +79 -0
- package/source/sdk/constants/decorators.constant.ts +8 -0
- package/source/sdk/constants/index.ts +2 -0
- package/source/sdk/constants/microservices.constant.ts +4 -0
- package/source/sdk/controllers.ts +4 -0
- package/source/sdk/data-transfer-object.ts +15 -0
- package/source/sdk/decorators/access-guard.decorator.ts +9 -0
- package/source/sdk/decorators/controllable.decorator.ts +20 -0
- package/source/sdk/decorators/index.ts +5 -0
- package/source/sdk/decorators/injection.decorator.ts +46 -0
- package/source/sdk/decorators/middleware.decorator.ts +15 -0
- package/source/sdk/decorators/parametrable.ts +28 -0
- package/source/sdk/decorators/routable.decorator.ts +45 -0
- package/source/sdk/encryption.ts +157 -0
- package/source/sdk/enums/encrypted.enum.ts +23 -0
- package/source/sdk/enums/event.message.enum.ts +4 -0
- package/source/sdk/enums/http-method.enum.ts +10 -0
- package/{build/sdk/enums/http-parameters.enum.d.ts → source/sdk/enums/http-parameters.enum.ts} +3 -5
- package/source/sdk/enums/http-status.enum.ts +73 -0
- package/source/sdk/enums/index.ts +7 -0
- package/{build/sdk/enums/runtime.enum.d.ts → source/sdk/enums/runtime.enum.ts} +2 -4
- package/{build/sdk/enums/timestamp.enum.d.ts → source/sdk/enums/timestamp.enum.ts} +2 -4
- package/source/sdk/env.ts +40 -0
- package/source/sdk/exceptions/http-exception.ts +28 -0
- package/source/sdk/exceptions/index.ts +2 -0
- package/{build/sdk/throwable.d.ts → source/sdk/exceptions/throwable.ts} +35 -12
- package/source/sdk/index.ts +14 -0
- package/source/sdk/parameter-bag.ts +55 -0
- package/source/sdk/plugins/body-parser.plugin.ts +160 -0
- package/source/sdk/plugins/index.ts +2 -0
- package/source/sdk/plugins/security/body-limit.ts +19 -0
- package/source/sdk/plugins/security/cors.ts +44 -0
- package/source/sdk/plugins/security/headers.ts +14 -0
- package/source/sdk/plugins/security/index.ts +13 -0
- package/source/sdk/plugins/security/method-guard.ts +14 -0
- package/source/sdk/plugins/security/rate-limit.ts +42 -0
- package/source/sdk/repositories.ts +14 -0
- package/source/sdk/responses/error.ts +52 -0
- package/source/sdk/responses/helpers.ts +28 -0
- package/source/sdk/responses/http-throwable.ts +28 -0
- package/source/sdk/responses/http.ts +48 -0
- package/source/sdk/responses/index.ts +4 -0
- package/source/sdk/runtime/bun/server.ts +73 -0
- package/source/sdk/runtime/deno/server.ts +53 -0
- package/source/sdk/runtime/index.ts +47 -0
- package/source/sdk/runtime/node/server.ts +60 -0
- package/source/sdk/runtime/web/server.ts +57 -0
- package/source/sdk/services.ts +9 -0
- package/source/sdk/utilities/alias-path.util.ts +49 -0
- package/source/sdk/utilities/artifact.util.ts +18 -0
- package/source/sdk/utilities/callable.util.ts +27 -0
- package/source/sdk/utilities/index.ts +5 -0
- package/source/sdk/utilities/json.util.ts +21 -0
- package/source/sdk/utilities/path.util.ts +19 -0
- package/source/sdk/utilities/url.ts +5 -0
- package/source/sdk/utilities/utilities.util.ts +25 -0
- package/source/types/access-guards.ts +4 -0
- package/{build/types/application.d.ts → source/types/application.ts} +23 -7
- package/source/types/artifact.ts +44 -0
- package/source/types/builder.ts +44 -0
- package/source/types/config.ts +7 -0
- package/source/types/controller.ts +33 -0
- package/source/types/contruct.ts +3 -0
- package/source/types/core.ts +28 -0
- package/{build/types/directory.d.ts → source/types/directory.ts} +4 -4
- package/source/types/encryption.ts +17 -0
- package/source/types/generic.ts +3 -0
- package/source/types/http-responses.ts +8 -0
- package/source/types/index.ts +25 -0
- package/source/types/injection.ts +13 -0
- package/source/types/lifecycle.ts +11 -0
- package/source/types/middleware.ts +18 -0
- package/source/types/parseable.ts +7 -0
- package/source/types/plugin.ts +10 -0
- package/source/types/raiton.ts +7 -0
- package/source/types/responses.ts +20 -0
- package/source/types/router.ts +11 -0
- package/source/types/runtime.ts +56 -0
- package/{build/types/scheme.d.ts → source/types/scheme.ts} +33 -8
- package/source/types/server.ts +12 -0
- package/source/types/thread.ts +31 -0
- package/source/types/utilities.ts +4 -0
- package/source/types/values.ts +3 -0
- package/.releaserc.json +0 -39
- package/build/bin/bootstrapper.d.ts +0 -5
- package/build/bin/bootstrapper.mjs +0 -46
- package/build/bin/cli.d.ts +0 -5
- package/build/bin/cli.mjs +0 -6
- package/build/bin/index.d.ts +0 -1
- package/build/chunk-3PWMRP6G.mjs +0 -16
- package/build/chunk-52JR26TI.mjs +0 -29
- package/build/chunk-5LNOA4SK.mjs +0 -16
- package/build/chunk-AUGL35CF.mjs +0 -24
- package/build/chunk-BYYJRCB4.mjs +0 -10
- package/build/chunk-FFRJ4AUA.mjs +0 -16
- package/build/chunk-GPJSLV3Q.mjs +0 -50
- package/build/chunk-HVFHDVAH.mjs +0 -20
- package/build/chunk-IOCHNQMF.mjs +0 -13
- package/build/chunk-JATYBWHL.mjs +0 -36
- package/build/chunk-JWNBO7XV.mjs +0 -53
- package/build/chunk-K4IQQ2KF.mjs +0 -55
- package/build/chunk-K4KLOLSO.mjs +0 -645
- package/build/chunk-M2RZZJQR.mjs +0 -27
- package/build/chunk-MLFGBJDV.mjs +0 -12
- package/build/chunk-NB62GSFI.mjs +0 -27
- package/build/chunk-O7R3NJQN.mjs +0 -19
- package/build/chunk-P2YCCBFR.mjs +0 -14
- package/build/chunk-P3IRIFPT.mjs +0 -53
- package/build/chunk-QFSXFOEN.mjs +0 -56
- package/build/chunk-QHCQ4AUA.mjs +0 -14
- package/build/chunk-QI7OFSXB.mjs +0 -37
- package/build/chunk-RVH2YBNU.mjs +0 -111
- package/build/chunk-RXG7754R.mjs +0 -25
- package/build/chunk-S3ONGVNZ.mjs +0 -11
- package/build/chunk-SRR4467I.mjs +0 -29
- package/build/chunk-T6L55AUG.mjs +0 -32
- package/build/chunk-TOJFTPAY.mjs +0 -83
- package/build/chunk-UAPCBU3J.mjs +0 -12
- package/build/chunk-UCHBN3DV.mjs +0 -52
- package/build/chunk-UWM46HLZ.mjs +0 -18
- package/build/chunk-UZFCGVHP.mjs +0 -8
- package/build/chunk-VQINCGLQ.mjs +0 -59
- package/build/chunk-VRL4S7UF.mjs +0 -74
- package/build/chunk-WAWFDMOH.mjs +0 -72
- package/build/chunk-X3JFRRRQ.mjs +0 -45
- package/build/chunk-XFBLELHI.mjs +0 -34
- package/build/chunk-XIGE72LC.mjs +0 -34
- package/build/chunk-XW7EPAD7.mjs +0 -0
- package/build/chunk-YGIZFKLJ.mjs +0 -20
- package/build/chunk-YRVIAORI.mjs +0 -8
- package/build/chunk-YXU5W2CB.mjs +0 -12
- package/build/commands/artifact.command.d.ts +0 -14
- package/build/commands/artifact.command.mjs +0 -59
- package/build/commands/build.command.d.ts +0 -14
- package/build/commands/build.command.mjs +0 -65
- package/build/commands/develop.command.d.ts +0 -13
- package/build/commands/develop.command.mjs +0 -75
- package/build/commands/grafts.command.d.ts +0 -12
- package/build/commands/grafts.command.mjs +0 -58
- package/build/commands/start.command.d.ts +0 -12
- package/build/commands/start.command.mjs +0 -64
- package/build/core/application.d.ts +0 -27
- package/build/core/application.mjs +0 -124
- package/build/core/artifact.d.ts +0 -19
- package/build/core/artifact.mjs +0 -133
- package/build/core/builder.d.ts +0 -35
- package/build/core/builder.mjs +0 -45
- package/build/core/bytes.util.d.ts +0 -6
- package/build/core/bytes.util.mjs +0 -8
- package/build/core/command.d.ts +0 -15
- package/build/core/command.mjs +0 -6
- package/build/core/commands.d.ts +0 -13
- package/build/core/commands.mjs +0 -7
- package/build/core/config.d.ts +0 -10
- package/build/core/config.mjs +0 -7
- package/build/core/context.d.ts +0 -15
- package/build/core/context.mjs +0 -6
- package/build/core/controller/builder.d.ts +0 -10
- package/build/core/controller/builder.mjs +0 -45
- package/build/core/controller/compiler.d.ts +0 -6
- package/build/core/controller/compiler.mjs +0 -45
- package/build/core/controller/index.d.ts +0 -13
- package/build/core/controller/index.mjs +0 -50
- package/build/core/controller/metadata.d.ts +0 -10
- package/build/core/controller/metadata.mjs +0 -6
- package/build/core/directories.d.ts +0 -11
- package/build/core/directories.mjs +0 -8
- package/build/core/hmr.d.ts +0 -22
- package/build/core/hmr.mjs +0 -6
- package/build/core/hooks.d.ts +0 -12
- package/build/core/hooks.mjs +0 -6
- package/build/core/index.d.ts +0 -41
- package/build/core/index.mjs +0 -100
- package/build/core/middleware/compose.d.ts +0 -8
- package/build/core/middleware/compose.mjs +0 -6
- package/build/core/middleware/index.d.ts +0 -6
- package/build/core/middleware/index.mjs +0 -11
- package/build/core/middleware/pipeline.d.ts +0 -14
- package/build/core/middleware/pipeline.mjs +0 -7
- package/build/core/plugins/index.d.ts +0 -14
- package/build/core/plugins/index.mjs +0 -48
- package/build/core/plugins/plugin.d.ts +0 -17
- package/build/core/plugins/plugin.mjs +0 -6
- package/build/core/plugins/scope.d.ts +0 -24
- package/build/core/plugins/scope.mjs +0 -45
- package/build/core/process.util.d.ts +0 -3
- package/build/core/process.util.mjs +0 -6
- package/build/core/raiton.d.ts +0 -20
- package/build/core/raiton.mjs +0 -6
- package/build/core/router/handler.d.ts +0 -10
- package/build/core/router/handler.mjs +0 -45
- package/build/core/router/index.d.ts +0 -12
- package/build/core/router/index.mjs +0 -54
- package/build/core/router/matcher.d.ts +0 -21
- package/build/core/router/matcher.mjs +0 -6
- package/build/core/router/route.d.ts +0 -20
- package/build/core/router/route.mjs +0 -6
- package/build/core/router/router.d.ts +0 -16
- package/build/core/router/router.mjs +0 -8
- package/build/core/thread.d.ts +0 -30
- package/build/core/thread.mjs +0 -45
- package/build/env.d.d.ts +0 -2
- package/build/env.d.mjs +0 -0
- package/build/raiton-1.1.1.tgz +0 -0
- package/build/requirements.d.ts +0 -2
- package/build/requirements.mjs +0 -19
- package/build/sdk/artifacts.d.ts +0 -13
- package/build/sdk/artifacts.mjs +0 -45
- package/build/sdk/constants/decorators.constant.d.ts +0 -11
- package/build/sdk/constants/decorators.constant.mjs +0 -6
- package/build/sdk/constants/index.d.ts +0 -2
- package/build/sdk/constants/index.mjs +0 -11
- package/build/sdk/constants/microservices.constant.d.ts +0 -5
- package/build/sdk/constants/microservices.constant.mjs +0 -6
- package/build/sdk/controllers.d.ts +0 -4
- package/build/sdk/controllers.mjs +0 -6
- package/build/sdk/data-transfer-object.d.ts +0 -7
- package/build/sdk/data-transfer-object.mjs +0 -7
- package/build/sdk/decorators/access-guard.decorator.d.ts +0 -2
- package/build/sdk/decorators/access-guard.decorator.mjs +0 -0
- package/build/sdk/decorators/controllable.d.ts +0 -3
- package/build/sdk/decorators/controllable.mjs +0 -45
- package/build/sdk/decorators/controllers.decorator.d.ts +0 -2
- package/build/sdk/decorators/controllers.decorator.mjs +0 -0
- package/build/sdk/decorators/grafts.decorator.d.ts +0 -2
- package/build/sdk/decorators/grafts.decorator.mjs +0 -0
- package/build/sdk/decorators/index.d.ts +0 -3
- package/build/sdk/decorators/index.mjs +0 -75
- package/build/sdk/decorators/parameters.decorator.d.ts +0 -2
- package/build/sdk/decorators/parameters.decorator.mjs +0 -0
- package/build/sdk/decorators/parametrable.d.ts +0 -9
- package/build/sdk/decorators/parametrable.mjs +0 -57
- package/build/sdk/decorators/payload.decorator.d.ts +0 -2
- package/build/sdk/decorators/payload.decorator.mjs +0 -0
- package/build/sdk/decorators/routable.d.ts +0 -10
- package/build/sdk/decorators/routable.mjs +0 -59
- package/build/sdk/dependency-container.d.ts +0 -19
- package/build/sdk/dependency-container.mjs +0 -46
- package/build/sdk/encryption.d.ts +0 -27
- package/build/sdk/encryption.mjs +0 -141
- package/build/sdk/enums/encrypted.enum.d.ts +0 -15
- package/build/sdk/enums/encrypted.enum.mjs +0 -6
- package/build/sdk/enums/event.message.enum.d.ts +0 -6
- package/build/sdk/enums/event.message.enum.mjs +0 -6
- package/build/sdk/enums/http-parameters.enum.mjs +0 -6
- package/build/sdk/enums/http.enum.d.ts +0 -12
- package/build/sdk/enums/http.enum.mjs +0 -6
- package/build/sdk/enums/index.d.ts +0 -6
- package/build/sdk/enums/index.mjs +0 -27
- package/build/sdk/enums/runtime.enum.mjs +0 -6
- package/build/sdk/enums/timestamp.enum.mjs +0 -6
- package/build/sdk/env.d.ts +0 -6
- package/build/sdk/env.mjs +0 -74
- package/build/sdk/fastify.d.ts +0 -11
- package/build/sdk/fastify.mjs +0 -9
- package/build/sdk/grafts.d.ts +0 -15
- package/build/sdk/grafts.mjs +0 -71
- package/build/sdk/index.d.ts +0 -34
- package/build/sdk/index.mjs +0 -126
- package/build/sdk/json.d.ts +0 -17
- package/build/sdk/json.mjs +0 -87
- package/build/sdk/plugins/body-parser.plugin.d.ts +0 -17
- package/build/sdk/plugins/body-parser.plugin.mjs +0 -7
- package/build/sdk/plugins/index.d.ts +0 -17
- package/build/sdk/plugins/index.mjs +0 -48
- package/build/sdk/plugins/security/body-limit.d.ts +0 -17
- package/build/sdk/plugins/security/body-limit.mjs +0 -45
- package/build/sdk/plugins/security/cors.d.ts +0 -22
- package/build/sdk/plugins/security/cors.mjs +0 -45
- package/build/sdk/plugins/security/headers.d.ts +0 -17
- package/build/sdk/plugins/security/headers.mjs +0 -45
- package/build/sdk/plugins/security/index.d.ts +0 -25
- package/build/sdk/plugins/security/index.mjs +0 -45
- package/build/sdk/plugins/security/method-guard.d.ts +0 -17
- package/build/sdk/plugins/security/method-guard.mjs +0 -45
- package/build/sdk/plugins/security/rate-limit.d.ts +0 -21
- package/build/sdk/plugins/security/rate-limit.mjs +0 -45
- package/build/sdk/repositories.d.ts +0 -7
- package/build/sdk/repositories.mjs +0 -17
- package/build/sdk/request.d.ts +0 -4
- package/build/sdk/request.mjs +0 -6
- package/build/sdk/responses.d.ts +0 -8
- package/build/sdk/responses.mjs +0 -20
- package/build/sdk/routes.d.ts +0 -7
- package/build/sdk/routes.mjs +0 -61
- package/build/sdk/runtime/bun/server.d.ts +0 -6
- package/build/sdk/runtime/bun/server.mjs +0 -6
- package/build/sdk/runtime/deno/server.d.ts +0 -6
- package/build/sdk/runtime/deno/server.mjs +0 -6
- package/build/sdk/runtime/index.d.ts +0 -15
- package/build/sdk/runtime/index.mjs +0 -11
- package/build/sdk/runtime/node/reply.d.ts +0 -2
- package/build/sdk/runtime/node/reply.mjs +0 -0
- package/build/sdk/runtime/node/request.d.ts +0 -2
- package/build/sdk/runtime/node/request.mjs +0 -0
- package/build/sdk/runtime/node/server.d.ts +0 -6
- package/build/sdk/runtime/node/server.mjs +0 -6
- package/build/sdk/runtime/web/server.d.ts +0 -6
- package/build/sdk/runtime/web/server.mjs +0 -6
- package/build/sdk/schemes.d.ts +0 -120
- package/build/sdk/schemes.mjs +0 -129
- package/build/sdk/services.d.ts +0 -8
- package/build/sdk/services.mjs +0 -10
- package/build/sdk/throwable.mjs +0 -14
- package/build/sdk/utilities/alias-path.util.d.ts +0 -9
- package/build/sdk/utilities/alias-path.util.mjs +0 -6
- package/build/sdk/utilities/artifacts.util.d.ts +0 -3
- package/build/sdk/utilities/artifacts.util.mjs +0 -45
- package/build/sdk/utilities/callable.util.d.ts +0 -3
- package/build/sdk/utilities/callable.util.mjs +0 -6
- package/build/sdk/utilities/controller.util.d.ts +0 -3
- package/build/sdk/utilities/controller.util.mjs +0 -6
- package/build/sdk/utilities/index.d.ts +0 -7
- package/build/sdk/utilities/index.mjs +0 -62
- package/build/sdk/utilities/json.util.d.ts +0 -3
- package/build/sdk/utilities/json.util.mjs +0 -6
- package/build/sdk/utilities/parameters-arguments.util.d.ts +0 -2
- package/build/sdk/utilities/parameters-arguments.util.mjs +0 -0
- package/build/sdk/utilities/url.d.ts +0 -3
- package/build/sdk/utilities/url.mjs +0 -7
- package/build/sdk/utilities/utilities.util.d.ts +0 -6
- package/build/sdk/utilities/utilities.util.mjs +0 -8
- package/build/types/access-guards.d.ts +0 -6
- package/build/types/access-guards.mjs +0 -0
- package/build/types/application.mjs +0 -0
- package/build/types/artifact.d.ts +0 -21
- package/build/types/artifact.mjs +0 -0
- package/build/types/builder.d.ts +0 -32
- package/build/types/builder.mjs +0 -0
- package/build/types/config.d.ts +0 -6
- package/build/types/config.mjs +0 -0
- package/build/types/controller.d.ts +0 -25
- package/build/types/controller.mjs +0 -0
- package/build/types/contruct.d.ts +0 -3
- package/build/types/contruct.mjs +0 -0
- package/build/types/core.d.ts +0 -15
- package/build/types/core.mjs +0 -0
- package/build/types/data-transfer-object.d.ts +0 -5
- package/build/types/data-transfer-object.mjs +0 -0
- package/build/types/dependency-container.d.ts +0 -20
- package/build/types/dependency-container.mjs +0 -0
- package/build/types/directory.mjs +0 -0
- package/build/types/encryption.d.ts +0 -16
- package/build/types/encryption.mjs +0 -0
- package/build/types/generic.d.ts +0 -4
- package/build/types/generic.mjs +0 -0
- package/build/types/hmr.d.ts +0 -25
- package/build/types/hmr.mjs +0 -0
- package/build/types/http-responses.d.ts +0 -10
- package/build/types/http-responses.mjs +0 -0
- package/build/types/index.d.ts +0 -45
- package/build/types/index.mjs +0 -0
- package/build/types/middleware.d.ts +0 -12
- package/build/types/middleware.mjs +0 -0
- package/build/types/parameters.d.ts +0 -19
- package/build/types/parameters.mjs +0 -0
- package/build/types/parseable.d.ts +0 -5
- package/build/types/parseable.mjs +0 -0
- package/build/types/payload.d.ts +0 -6
- package/build/types/payload.mjs +0 -0
- package/build/types/plugin.d.ts +0 -20
- package/build/types/plugin.mjs +0 -0
- package/build/types/raiton.d.ts +0 -12
- package/build/types/raiton.mjs +0 -0
- package/build/types/repositories.d.ts +0 -8
- package/build/types/repositories.mjs +0 -0
- package/build/types/router.d.ts +0 -14
- package/build/types/router.mjs +0 -0
- package/build/types/runtime.d.ts +0 -37
- package/build/types/runtime.mjs +0 -0
- package/build/types/scheme.mjs +0 -0
- package/build/types/server.d.ts +0 -57
- package/build/types/server.mjs +0 -0
- package/build/types/services.d.ts +0 -8
- package/build/types/services.mjs +0 -0
- package/build/types/thread.d.ts +0 -24
- package/build/types/thread.mjs +0 -0
- package/build/types/utilities.d.ts +0 -6
- package/build/types/utilities.mjs +0 -0
- package/build/types/values.d.ts +0 -4
- package/build/types/values.mjs +0 -0
- /package/{build/chunk-4OWCGDUD.mjs → source/sdk/runtime/node/reply.ts} +0 -0
- /package/{build/chunk-DIWD7ZCJ.mjs → source/sdk/runtime/node/request.ts} +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export enum HttpStatus {
|
|
2
|
+
|
|
3
|
+
CONTINUE = 100,
|
|
4
|
+
SWITCHING_PROTOCOLS = 101,
|
|
5
|
+
PROCESSING = 102,
|
|
6
|
+
EARLY_HINTS = 103,
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
OK = 200,
|
|
10
|
+
CREATED = 201,
|
|
11
|
+
ACCEPTED = 202,
|
|
12
|
+
NON_AUTHORITATIVE_INFORMATION = 203,
|
|
13
|
+
NO_CONTENT = 204,
|
|
14
|
+
RESET_CONTENT = 205,
|
|
15
|
+
PARTIAL_CONTENT = 206,
|
|
16
|
+
MULTI_STATUS = 207,
|
|
17
|
+
ALREADY_REPORTED = 208,
|
|
18
|
+
IM_USED = 226,
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
MULTIPLE_CHOICES = 300,
|
|
22
|
+
MOVED_PERMANENTLY = 301,
|
|
23
|
+
FOUND = 302,
|
|
24
|
+
SEE_OTHER = 303,
|
|
25
|
+
NOT_MODIFIED = 304,
|
|
26
|
+
USE_PROXY = 305,
|
|
27
|
+
TEMPORARY_REDIRECT = 307,
|
|
28
|
+
PERMANENT_REDIRECT = 308,
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
BAD_REQUEST = 400,
|
|
32
|
+
UNAUTHORIZED = 401,
|
|
33
|
+
PAYMENT_REQUIRED = 402,
|
|
34
|
+
FORBIDDEN = 403,
|
|
35
|
+
NOT_FOUND = 404,
|
|
36
|
+
METHOD_NOT_ALLOWED = 405,
|
|
37
|
+
NOT_ACCEPTABLE = 406,
|
|
38
|
+
PROXY_AUTHENTICATION_REQUIRED = 407,
|
|
39
|
+
REQUEST_TIMEOUT = 408,
|
|
40
|
+
CONFLICT = 409,
|
|
41
|
+
GONE = 410,
|
|
42
|
+
LENGTH_REQUIRED = 411,
|
|
43
|
+
PRECONDITION_FAILED = 412,
|
|
44
|
+
PAYLOAD_TOO_LARGE = 413,
|
|
45
|
+
URI_TOO_LONG = 414,
|
|
46
|
+
UNSUPPORTED_MEDIA_TYPE = 415,
|
|
47
|
+
RANGE_NOT_SATISFIABLE = 416,
|
|
48
|
+
EXPECTATION_FAILED = 417,
|
|
49
|
+
IM_A_TEAPOT = 418,
|
|
50
|
+
MISDIRECTED_REQUEST = 421,
|
|
51
|
+
UNPROCESSABLE_ENTITY = 422,
|
|
52
|
+
LOCKED = 423,
|
|
53
|
+
FAILED_DEPENDENCY = 424,
|
|
54
|
+
TOO_EARLY = 425,
|
|
55
|
+
UPGRADE_REQUIRED = 426,
|
|
56
|
+
PRECONDITION_REQUIRED = 428,
|
|
57
|
+
TOO_MANY_REQUESTS = 429,
|
|
58
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
|
|
59
|
+
UNAVAILABLE_FOR_LEGAL_REASONS = 451,
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
INTERNAL_SERVER_ERROR = 500,
|
|
63
|
+
NOT_IMPLEMENTED = 501,
|
|
64
|
+
BAD_GATEWAY = 502,
|
|
65
|
+
SERVICE_UNAVAILABLE = 503,
|
|
66
|
+
GATEWAY_TIMEOUT = 504,
|
|
67
|
+
HTTP_VERSION_NOT_SUPPORTED = 505,
|
|
68
|
+
VARIANT_ALSO_NEGOTIATES = 506,
|
|
69
|
+
INSUFFICIENT_STORAGE = 507,
|
|
70
|
+
LOOP_DETECTED = 508,
|
|
71
|
+
NOT_EXTENDED = 510,
|
|
72
|
+
NETWORK_AUTHENTICATION_REQUIRED = 511,
|
|
73
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {IGenericValue} from "../types/generic";
|
|
2
|
+
import {getType} from "./utilities";
|
|
3
|
+
|
|
4
|
+
export function env<T>(key: string, type?: IGenericValue): T | undefined {
|
|
5
|
+
const value = process.env[key];
|
|
6
|
+
type = type || getType(value) as IGenericValue;
|
|
7
|
+
|
|
8
|
+
if (value) {
|
|
9
|
+
switch (type) {
|
|
10
|
+
|
|
11
|
+
case "bigInt":
|
|
12
|
+
return BigInt(value) as any;
|
|
13
|
+
|
|
14
|
+
case 'float':
|
|
15
|
+
return parseFloat(value) as any;
|
|
16
|
+
|
|
17
|
+
case 'boolean':
|
|
18
|
+
return Boolean(value) as any;
|
|
19
|
+
|
|
20
|
+
case "int":
|
|
21
|
+
return parseInt(value) as any;
|
|
22
|
+
|
|
23
|
+
default:
|
|
24
|
+
return value as any;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function envGroup(key: string): Record<string, IGenericValue | undefined> {
|
|
32
|
+
const filtered = Object.entries(process.env)
|
|
33
|
+
.filter(([index]) => key.startsWith(index))
|
|
34
|
+
const gen: Record<string, IGenericValue | undefined> = {}
|
|
35
|
+
|
|
36
|
+
for (const [index, value] of filtered)
|
|
37
|
+
gen[index] = env(value as any, undefined)
|
|
38
|
+
|
|
39
|
+
return gen;
|
|
40
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {HttpStatus} from "@/sdk/enums/http-status.enum";
|
|
2
|
+
import {Raiton} from "@/core";
|
|
3
|
+
import {HttpResponseBaseInterface} from "@/types";
|
|
4
|
+
|
|
5
|
+
export class HttpException extends Error {
|
|
6
|
+
|
|
7
|
+
constructor(
|
|
8
|
+
error: string | HttpResponseBaseInterface | Error,
|
|
9
|
+
public statusCode: HttpStatus = HttpStatus.INTERNAL_SERVER_ERROR,
|
|
10
|
+
) {
|
|
11
|
+
super(typeof error === 'string' ? error : error.message);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
render() {
|
|
15
|
+
return {
|
|
16
|
+
message: this.message,
|
|
17
|
+
statusCode: this.statusCode,
|
|
18
|
+
error: true,
|
|
19
|
+
stack: Raiton.thread?.builder?.options?.development
|
|
20
|
+
? this.stack?.split('\n').map(e => e.trim())
|
|
21
|
+
: undefined
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
toString() {
|
|
26
|
+
return `HttpException: ${this.message} with status code ${this.statusCode}`
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {LBadge, Logger} from "@protorians/logger";
|
|
2
|
+
import {EventBus, EventBusEnum} from "@protorians/events-bus";
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Represents a throwable error that extends the built-in JavaScript Error class.
|
|
3
6
|
* The Throwable class provides utility methods for triggering different levels
|
|
@@ -7,9 +10,14 @@
|
|
|
7
10
|
* throws an exception or exits the application depending on the severity level
|
|
8
11
|
* or the provided parameters.
|
|
9
12
|
*/
|
|
10
|
-
|
|
11
|
-
protected statusCode: number
|
|
12
|
-
|
|
13
|
+
export class Throwable extends Error {
|
|
14
|
+
constructor(message: string, protected statusCode: number = 500, label?: string) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'Throwable';
|
|
17
|
+
if (label) Logger.debug(LBadge.debug(label), message);
|
|
18
|
+
EventBus.dispatch(EventBusEnum.SERVER_THROW, {error: this})
|
|
19
|
+
}
|
|
20
|
+
|
|
13
21
|
/**
|
|
14
22
|
* Dispatches a system server error event and optionally throws an error.
|
|
15
23
|
*
|
|
@@ -18,7 +26,11 @@ declare class Throwable extends Error {
|
|
|
18
26
|
* @param statusCode
|
|
19
27
|
* @return {void} This method does not return a value.
|
|
20
28
|
*/
|
|
21
|
-
static error(message: string, soft
|
|
29
|
+
static error(message: string, soft: boolean = true, statusCode: number = 500): void {
|
|
30
|
+
EventBus.dispatch(EventBusEnum.SERVER_ERROR, {message, soft})
|
|
31
|
+
if (!soft) throw new Throwable(message, statusCode, 'ERR');
|
|
32
|
+
}
|
|
33
|
+
|
|
22
34
|
/**
|
|
23
35
|
* Emits a system server warning event and optionally throws an error based on the severity of the warning.
|
|
24
36
|
*
|
|
@@ -27,15 +39,24 @@ declare class Throwable extends Error {
|
|
|
27
39
|
* @param statusCode
|
|
28
40
|
* @return {void} This method does not return a value.
|
|
29
41
|
*/
|
|
30
|
-
static warning(message: string, soft
|
|
42
|
+
static warning(message: string, soft: boolean = true, statusCode: number = 500): void {
|
|
43
|
+
EventBus.dispatch(EventBusEnum.SERVER_WARNING, {message, soft})
|
|
44
|
+
if (!soft) throw new Throwable(message, statusCode, 'WRN');
|
|
45
|
+
}
|
|
46
|
+
|
|
31
47
|
/**
|
|
32
48
|
* Triggers a critical system event, dispatching an alert message and terminating the process.
|
|
33
49
|
*
|
|
34
50
|
* @param {string} message - The critical error message to be dispatched with the event.
|
|
35
51
|
* @return {void} This method does not return a value as it terminates the process.
|
|
36
52
|
*/
|
|
37
|
-
static critical(message: string): void
|
|
53
|
+
static critical(message: string): void {
|
|
54
|
+
Logger.debug(LBadge.debug('CRITICAL'), message);
|
|
55
|
+
EventBus.dispatch(EventBusEnum.SERVER_CRITICAL, {message})
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
38
58
|
}
|
|
59
|
+
|
|
39
60
|
/**
|
|
40
61
|
* A function that throws an error with a provided message and a specified error type.
|
|
41
62
|
*
|
|
@@ -45,7 +66,8 @@ declare class Throwable extends Error {
|
|
|
45
66
|
* @param statusCode
|
|
46
67
|
* @returns {void}
|
|
47
68
|
*/
|
|
48
|
-
|
|
69
|
+
export const throwError = (message: string, soft: boolean = true, statusCode: number = 500): void => Throwable.error(message, soft, statusCode);
|
|
70
|
+
|
|
49
71
|
/**
|
|
50
72
|
* Function to throw an error with a specified message.
|
|
51
73
|
*
|
|
@@ -53,7 +75,8 @@ declare const throwError: (message: string, soft?: boolean, statusCode?: number)
|
|
|
53
75
|
* @param statusCode
|
|
54
76
|
* @throws {Throwable} always throw an error with the provided message.
|
|
55
77
|
*/
|
|
56
|
-
|
|
78
|
+
export const throwException = (message: string, statusCode: number = 500): void => throwError(message, false, statusCode);
|
|
79
|
+
|
|
57
80
|
/**
|
|
58
81
|
* Emits a warning with the specified message and behavior.
|
|
59
82
|
*
|
|
@@ -63,7 +86,9 @@ declare const throwException: (message: string, statusCode?: number) => void;
|
|
|
63
86
|
* @param statusCode
|
|
64
87
|
* @returns {void} This function does not return any value.
|
|
65
88
|
*/
|
|
66
|
-
|
|
89
|
+
export const throwWarning = (message: string, soft: boolean = true, statusCode: number = 500): void =>
|
|
90
|
+
Throwable.warning(message, soft, statusCode);
|
|
91
|
+
|
|
67
92
|
/**
|
|
68
93
|
* A variable representing a function that throws a critical error.
|
|
69
94
|
*
|
|
@@ -73,6 +98,4 @@ declare const throwWarning: (message: string, soft?: boolean, statusCode?: numbe
|
|
|
73
98
|
* @param {string} message - The error message describing the critical error to be thrown.
|
|
74
99
|
* @returns {Throwable} The critical throwable generated with the provided message.
|
|
75
100
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
export { Throwable, throwCritical, throwError, throwException, throwWarning };
|
|
101
|
+
export const throwCritical = (message: string): void => Throwable.critical(message);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./enums/index"
|
|
2
|
+
export * from "./constants/index"
|
|
3
|
+
export * from "./decorators/index"
|
|
4
|
+
export * from "./responses/index"
|
|
5
|
+
export * from "./plugins/index"
|
|
6
|
+
export * from "./utilities/index"
|
|
7
|
+
export * from "./runtime/index"
|
|
8
|
+
export * from "./exceptions/index"
|
|
9
|
+
export * from "./controllers"
|
|
10
|
+
export * from "./data-transfer-object"
|
|
11
|
+
export * from "./encryption"
|
|
12
|
+
export * from "./parameter-bag"
|
|
13
|
+
export * from "./repositories"
|
|
14
|
+
export * from "./services"
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {ParseableEntriesType, ParseablePrimitiveType} from "@/types";
|
|
2
|
+
import {stabilizeJson} from "./utilities";
|
|
3
|
+
import {DynamicParameter, IDynamicParameters, IDynamicProps, IParameter,} from "@protorians/parameters";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export class ParameterBag<T extends ParseableEntriesType> {
|
|
7
|
+
|
|
8
|
+
protected _bag: IDynamicParameters<any>;
|
|
9
|
+
|
|
10
|
+
constructor(data: T) {
|
|
11
|
+
this._bag = new DynamicParameter(this.initializeData(data));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
protected initializeData(data: T): any {
|
|
15
|
+
const prepared = {} as IDynamicProps<T>
|
|
16
|
+
|
|
17
|
+
for (const [key, value] of Object.entries(data)) {
|
|
18
|
+
prepared[key as keyof T] = {
|
|
19
|
+
value,
|
|
20
|
+
} as IParameter<T[keyof T]>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return prepared
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get bag(): IDynamicParameters<any> {
|
|
27
|
+
return this._bag;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
records(data: T): this {
|
|
31
|
+
for (const [key, value] of Object.entries(data))
|
|
32
|
+
this._bag.update(key as keyof T, value);
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
render(): T {
|
|
37
|
+
return Object.fromEntries(this._bag.stack) as any as T;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
toString(): string {
|
|
41
|
+
return JSON.stringify(this.render());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static stabilize<T>(json: string | T | null): T {
|
|
45
|
+
return stabilizeJson<T>(json);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static from<T extends IDynamicProps<T>>(data: T): ParameterBag<T> {
|
|
49
|
+
return new ParameterBag<T>(data);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static records<T extends IDynamicProps<T>>(support: ParameterBag<T>, data: ParseablePrimitiveType<T>): ParameterBag<T> {
|
|
53
|
+
return support.records(this.stabilize(data));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type {MiddlewareParameters, Plugin} from "@/types";
|
|
2
|
+
import {RequestContext} from "@/core/context";
|
|
3
|
+
import {Logger} from "@protorians/logger";
|
|
4
|
+
import {tryParseJson} from "@/sdk/utilities/json.util";
|
|
5
|
+
|
|
6
|
+
export function bodyParserPlugin(): Plugin {
|
|
7
|
+
return {
|
|
8
|
+
name: 'body-parser-plugin',
|
|
9
|
+
setup: (scope) => {
|
|
10
|
+
scope.use(async ({context, next}: MiddlewareParameters) => {
|
|
11
|
+
const contentType = context.req.headers.get('content-type') || '';
|
|
12
|
+
|
|
13
|
+
if (context.req.body && !context.state.bodyParsed) {
|
|
14
|
+
try {
|
|
15
|
+
const rawBody = await readRawBody(context.req.body);
|
|
16
|
+
context.req.body = rawBody as unknown as any;
|
|
17
|
+
const bodyString = decode(rawBody);
|
|
18
|
+
|
|
19
|
+
readQueryBody(context);
|
|
20
|
+
await readMultipartBody(context, contentType);
|
|
21
|
+
readJsonBody(context, contentType, bodyString);
|
|
22
|
+
readUrlEncodedBody(context, contentType, bodyString);
|
|
23
|
+
readTextBody(context, contentType, bodyString);
|
|
24
|
+
|
|
25
|
+
if (!context.state.bodyParsed) {
|
|
26
|
+
context.state.bodyParsed = true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
} catch (e) {
|
|
30
|
+
Logger.error('Error parsing body:', e);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
await next();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function readJsonBody(ctx: RequestContext, contentType: string, body: any) {
|
|
41
|
+
if (contentType.includes('application/json')) {
|
|
42
|
+
ctx.req.body = tryParseJson(body) || {} as unknown as any;
|
|
43
|
+
ctx.state.bodyParsed = true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function readMultipartBody(ctx: RequestContext, contentType: string) {
|
|
48
|
+
if (contentType.includes('multipart/form-data')) {
|
|
49
|
+
const body = ctx.req.body;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const tempRequest = new Request(ctx.req.url, {
|
|
53
|
+
method: ctx.req.method,
|
|
54
|
+
headers: ctx.req.headers,
|
|
55
|
+
body: body as any
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const formData = await tempRequest.formData();
|
|
59
|
+
const record: Record<string, any> = {};
|
|
60
|
+
const files: Record<string, any> = {};
|
|
61
|
+
|
|
62
|
+
for (const [key, value] of formData.entries()) {
|
|
63
|
+
const v = value as any;
|
|
64
|
+
if (v && (v instanceof File)) {
|
|
65
|
+
files[key] = {
|
|
66
|
+
name: v.name,
|
|
67
|
+
type: v.type,
|
|
68
|
+
size: v.size,
|
|
69
|
+
lastModified: v.lastModified,
|
|
70
|
+
buffer: Buffer.from(await v.arrayBuffer())
|
|
71
|
+
};
|
|
72
|
+
} else {
|
|
73
|
+
record[key] = value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
ctx.req.body = record;
|
|
78
|
+
ctx.req.files = files;
|
|
79
|
+
ctx.req.file = Object.values(files)[0] || null;
|
|
80
|
+
ctx.state.bodyParsed = true;
|
|
81
|
+
} catch (e) {
|
|
82
|
+
Logger.error('Error parsing multipart body:', e);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function readUrlEncodedBody(ctx: RequestContext, contentType: string, body: string) {
|
|
88
|
+
if (contentType.includes('application/x-www-form-urlencoded')) {
|
|
89
|
+
const params = new URLSearchParams(body);
|
|
90
|
+
const record: Record<string, any> = {};
|
|
91
|
+
params.forEach((value, key) => {
|
|
92
|
+
record[key] = value;
|
|
93
|
+
});
|
|
94
|
+
ctx.req.body = record as unknown as any;
|
|
95
|
+
ctx.state.bodyParsed = true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function readTextBody(ctx: RequestContext, contentType: string, body: string) {
|
|
100
|
+
if (contentType.includes('text/')) {
|
|
101
|
+
ctx.req.body = body as unknown as any;
|
|
102
|
+
ctx.state.bodyParsed = true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function readQueryBody(ctx: RequestContext) {
|
|
107
|
+
const searchParams = new URLSearchParams(ctx.req.url.split('?')[1] || '');
|
|
108
|
+
const record = {} as Record<string, any>;
|
|
109
|
+
searchParams.forEach((value, key) => record[key] = value);
|
|
110
|
+
ctx.req.query = record as unknown as any;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function readRawBody(body: any): Promise<Uint8Array | string> {
|
|
114
|
+
if (body instanceof ReadableStream) {
|
|
115
|
+
const reader = body.getReader();
|
|
116
|
+
const chunks: Uint8Array[] = [];
|
|
117
|
+
while (true) {
|
|
118
|
+
const {done, value} = await reader.read();
|
|
119
|
+
if (done) break;
|
|
120
|
+
chunks.push(value);
|
|
121
|
+
}
|
|
122
|
+
const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
123
|
+
const result = new Uint8Array(totalLength);
|
|
124
|
+
let offset = 0;
|
|
125
|
+
for (const chunk of chunks) {
|
|
126
|
+
result.set(chunk, offset);
|
|
127
|
+
offset += chunk.length;
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (typeof body === 'object' && body !== null && 'on' in body && typeof body.on === 'function') {
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
const chunks: any[] = [];
|
|
135
|
+
body.on('data', (chunk: any) => chunks.push(chunk));
|
|
136
|
+
body.on('end', () => {
|
|
137
|
+
if (chunks.length > 0 && typeof chunks[0] === 'string') {
|
|
138
|
+
resolve(chunks.join(''));
|
|
139
|
+
} else {
|
|
140
|
+
const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
141
|
+
const result = new Uint8Array(totalLength);
|
|
142
|
+
let offset = 0;
|
|
143
|
+
for (const chunk of chunks) {
|
|
144
|
+
result.set(new Uint8Array(chunk), offset);
|
|
145
|
+
offset += chunk.length;
|
|
146
|
+
}
|
|
147
|
+
resolve(result);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
body.on('error', reject);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return body;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function decode(data: Uint8Array | string): string {
|
|
158
|
+
if (typeof data === 'string') return data;
|
|
159
|
+
return new TextDecoder().decode(data);
|
|
160
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {definePlugin} from "@/core/plugins";
|
|
2
|
+
import {MiddlewareParameters} from "@/types";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export const secureBodyLimit = (maxBytes = 1_000_000) =>
|
|
6
|
+
definePlugin((scope) => {
|
|
7
|
+
scope.use(async ({context, next}: MiddlewareParameters) => {
|
|
8
|
+
const len = Number(
|
|
9
|
+
context.req.headers.get('content-length') ?? 0
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
if (len > maxBytes) {
|
|
13
|
+
context.reply.status(413)
|
|
14
|
+
return context.send({ error: 'Payload too large' })
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
await next()
|
|
18
|
+
})
|
|
19
|
+
}, 'body-limit')
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {definePlugin} from "@/core/plugins";
|
|
2
|
+
import {Context, MiddlewareParameters, NextCallable} from "@/types";
|
|
3
|
+
|
|
4
|
+
export interface CorsOptions {
|
|
5
|
+
origin?: string | string[]
|
|
6
|
+
methods?: string[]
|
|
7
|
+
headers?: string[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const secureCors = (opts: CorsOptions = {}) =>
|
|
11
|
+
definePlugin((scope) => {
|
|
12
|
+
scope.use(async ({context, next}: MiddlewareParameters) => {
|
|
13
|
+
const origin = context.req.headers.get('origin')
|
|
14
|
+
|
|
15
|
+
if (opts.origin) {
|
|
16
|
+
const allowed = Array.isArray(opts.origin)
|
|
17
|
+
? opts.origin.includes(origin!)
|
|
18
|
+
: opts.origin === origin
|
|
19
|
+
|
|
20
|
+
if (allowed) {
|
|
21
|
+
context.reply.header('Access-Control-Allow-Origin', origin!)
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
context.reply.header('Access-Control-Allow-Origin', '*')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
context.reply.header(
|
|
28
|
+
'Access-Control-Allow-Methods',
|
|
29
|
+
(opts.methods ?? ['GET', 'POST', 'PUT', 'DELETE']).join(',')
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
context.reply.header(
|
|
33
|
+
'Access-Control-Allow-Headers',
|
|
34
|
+
(opts.headers ?? ['Content-Type', 'Authorization']).join(',')
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
if (context.req.method === 'OPTIONS') {
|
|
38
|
+
context.reply.status(204)
|
|
39
|
+
return context.send(null)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
await next()
|
|
43
|
+
})
|
|
44
|
+
}, 'cors')
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {definePlugin} from "@/core/plugins";
|
|
2
|
+
import {Context, MiddlewareParameters, NextCallable} from "@/types";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export const secureHeaders = definePlugin((scope) => {
|
|
6
|
+
scope.use(async ({context, next}: MiddlewareParameters) => {
|
|
7
|
+
context.reply.header('X-Content-Type-Options', 'nosniff')
|
|
8
|
+
context.reply.header('X-Frame-Options', 'DENY')
|
|
9
|
+
context.reply.header('Referrer-Policy', 'no-referrer')
|
|
10
|
+
context.reply.header('X-XSS-Protection', '1; mode=block')
|
|
11
|
+
|
|
12
|
+
await next()
|
|
13
|
+
})
|
|
14
|
+
}, 'security-headers')
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {secureHeaders} from './headers'
|
|
2
|
+
import {secureCors} from './cors'
|
|
3
|
+
import {secureRateLimit} from './rate-limit'
|
|
4
|
+
import {secureBodyLimit} from './body-limit'
|
|
5
|
+
import {secureMethodGuard} from './method-guard'
|
|
6
|
+
|
|
7
|
+
export class Security {
|
|
8
|
+
static headers = secureHeaders
|
|
9
|
+
static cors = secureCors
|
|
10
|
+
static rateLimit = secureRateLimit
|
|
11
|
+
static bodyLimit = secureBodyLimit
|
|
12
|
+
static methodGuard = secureMethodGuard
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {definePlugin} from "@/core/plugins";
|
|
2
|
+
import {Context, MiddlewareParameters, NextCallable} from "@/types";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export const secureMethodGuard = (allowed: string[]) =>
|
|
6
|
+
definePlugin((scope) => {
|
|
7
|
+
scope.use(async ({context, next}: MiddlewareParameters) => {
|
|
8
|
+
if (!allowed.includes(context.req.method)) {
|
|
9
|
+
context.reply.status(405)
|
|
10
|
+
return context.send({ error: 'Method not allowed' })
|
|
11
|
+
}
|
|
12
|
+
await next()
|
|
13
|
+
})
|
|
14
|
+
}, 'method-guard')
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {definePlugin} from "@/core/plugins";
|
|
2
|
+
import {Context, MiddlewareParameters, NextCallable} from "@/types";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export interface RateLimitOptions {
|
|
6
|
+
windowMs?: number
|
|
7
|
+
max?: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const secureRateLimit = (
|
|
11
|
+
opts: RateLimitOptions = {}
|
|
12
|
+
) =>
|
|
13
|
+
definePlugin((scope) => {
|
|
14
|
+
const hits = new Map<string, { count: number; ts: number }>()
|
|
15
|
+
|
|
16
|
+
const windowMs = opts.windowMs ?? 60_000
|
|
17
|
+
const max = opts.max ?? 100
|
|
18
|
+
|
|
19
|
+
scope.use(async ({context, next}: MiddlewareParameters) => {
|
|
20
|
+
const ip =
|
|
21
|
+
context.req.remoteAddress ?? 'unknown'
|
|
22
|
+
const now = Date.now()
|
|
23
|
+
|
|
24
|
+
const entry = hits.get(ip) ?? {count: 0, ts: now}
|
|
25
|
+
|
|
26
|
+
if (now - entry.ts > windowMs) {
|
|
27
|
+
entry.count = 0
|
|
28
|
+
entry.ts = now
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
entry.count++
|
|
32
|
+
|
|
33
|
+
hits.set(ip, entry)
|
|
34
|
+
|
|
35
|
+
if (entry.count > max) {
|
|
36
|
+
context.reply.status(429)
|
|
37
|
+
return context.send({error: 'Too many requests'})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
await next()
|
|
41
|
+
})
|
|
42
|
+
}, 'rate-limit')
|