@signal24/dk-server-foundation 26.213.615
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/.gitattributes +2 -0
- package/.gitlab-ci.yml +49 -0
- package/.oxlintrc.json +40 -0
- package/.prettierignore +3 -0
- package/.prettierrc.json +15 -0
- package/.serena/project.yml +111 -0
- package/.vscode/launch.json +15 -0
- package/.vscode/settings.json +12 -0
- package/.yarnrc.yml +5 -0
- package/CLAUDE.md +279 -0
- package/LICENSE +21 -0
- package/README.md +439 -0
- package/TEST_MIGRATION_GUIDE.md +348 -0
- package/dist/resources/proto/generated/test/test.d.ts +224 -0
- package/dist/resources/proto/generated/test/test.d.ts.map +1 -0
- package/dist/resources/proto/generated/test/test.js +2376 -0
- package/dist/resources/proto/generated/test/test.js.map +1 -0
- package/dist/src/app/base.d.ts +37 -0
- package/dist/src/app/base.d.ts.map +1 -0
- package/dist/src/app/base.js +244 -0
- package/dist/src/app/base.js.map +1 -0
- package/dist/src/app/config.d.ts +91 -0
- package/dist/src/app/config.d.ts.map +1 -0
- package/dist/src/app/config.js +33 -0
- package/dist/src/app/config.js.map +1 -0
- package/dist/src/app/config.loader.d.ts +14 -0
- package/dist/src/app/config.loader.d.ts.map +1 -0
- package/dist/src/app/config.loader.js +67 -0
- package/dist/src/app/config.loader.js.map +1 -0
- package/dist/src/app/const.d.ts +3 -0
- package/dist/src/app/const.d.ts.map +1 -0
- package/dist/src/app/const.js +6 -0
- package/dist/src/app/const.js.map +1 -0
- package/dist/src/app/dev.d.ts +6 -0
- package/dist/src/app/dev.d.ts.map +1 -0
- package/dist/src/app/dev.js +78 -0
- package/dist/src/app/dev.js.map +1 -0
- package/dist/src/app/index.d.ts +7 -0
- package/dist/src/app/index.d.ts.map +1 -0
- package/dist/src/app/index.js +12 -0
- package/dist/src/app/index.js.map +1 -0
- package/dist/src/app/openapi.d.ts +4 -0
- package/dist/src/app/openapi.d.ts.map +1 -0
- package/dist/src/app/openapi.js +6 -0
- package/dist/src/app/openapi.js.map +1 -0
- package/dist/src/app/resolver.d.ts +11 -0
- package/dist/src/app/resolver.d.ts.map +1 -0
- package/dist/src/app/resolver.js +60 -0
- package/dist/src/app/resolver.js.map +1 -0
- package/dist/src/app/shutdown.d.ts +12 -0
- package/dist/src/app/shutdown.d.ts.map +1 -0
- package/dist/src/app/shutdown.js +63 -0
- package/dist/src/app/shutdown.js.map +1 -0
- package/dist/src/app/state.d.ts +16 -0
- package/dist/src/app/state.d.ts.map +1 -0
- package/dist/src/app/state.js +12 -0
- package/dist/src/app/state.js.map +1 -0
- package/dist/src/auth/index.d.ts +3 -0
- package/dist/src/auth/index.d.ts.map +1 -0
- package/dist/src/auth/index.js +6 -0
- package/dist/src/auth/index.js.map +1 -0
- package/dist/src/auth/jwt.d.ts +76 -0
- package/dist/src/auth/jwt.d.ts.map +1 -0
- package/dist/src/auth/jwt.js +218 -0
- package/dist/src/auth/jwt.js.map +1 -0
- package/dist/src/auth/provider.d.ts +15 -0
- package/dist/src/auth/provider.d.ts.map +1 -0
- package/dist/src/auth/provider.js +50 -0
- package/dist/src/auth/provider.js.map +1 -0
- package/dist/src/cli/dksf-dev.d.ts +3 -0
- package/dist/src/cli/dksf-dev.d.ts.map +1 -0
- package/dist/src/cli/dksf-dev.js +359 -0
- package/dist/src/cli/dksf-dev.js.map +1 -0
- package/dist/src/cli/dksf-gen-proto.d.ts +3 -0
- package/dist/src/cli/dksf-gen-proto.d.ts.map +1 -0
- package/dist/src/cli/dksf-gen-proto.js +164 -0
- package/dist/src/cli/dksf-gen-proto.js.map +1 -0
- package/dist/src/cli/dksf-install.d.ts +3 -0
- package/dist/src/cli/dksf-install.d.ts.map +1 -0
- package/dist/src/cli/dksf-install.js +10 -0
- package/dist/src/cli/dksf-install.js.map +1 -0
- package/dist/src/cli/dksf-test.d.ts +3 -0
- package/dist/src/cli/dksf-test.d.ts.map +1 -0
- package/dist/src/cli/dksf-test.js +91 -0
- package/dist/src/cli/dksf-test.js.map +1 -0
- package/dist/src/cli/dksf-update.d.ts +3 -0
- package/dist/src/cli/dksf-update.d.ts.map +1 -0
- package/dist/src/cli/dksf-update.js +86 -0
- package/dist/src/cli/dksf-update.js.map +1 -0
- package/dist/src/database/common.d.ts +84 -0
- package/dist/src/database/common.d.ts.map +1 -0
- package/dist/src/database/common.js +380 -0
- package/dist/src/database/common.js.map +1 -0
- package/dist/src/database/dialect.d.ts +10 -0
- package/dist/src/database/dialect.d.ts.map +1 -0
- package/dist/src/database/dialect.js +56 -0
- package/dist/src/database/dialect.js.map +1 -0
- package/dist/src/database/entity.d.ts +62 -0
- package/dist/src/database/entity.d.ts.map +1 -0
- package/dist/src/database/entity.js +198 -0
- package/dist/src/database/entity.js.map +1 -0
- package/dist/src/database/index.d.ts +8 -0
- package/dist/src/database/index.d.ts.map +1 -0
- package/dist/src/database/index.js +15 -0
- package/dist/src/database/index.js.map +1 -0
- package/dist/src/database/migration/MigrationResetCommand.d.ts +11 -0
- package/dist/src/database/migration/MigrationResetCommand.d.ts.map +1 -0
- package/dist/src/database/migration/MigrationResetCommand.js +149 -0
- package/dist/src/database/migration/MigrationResetCommand.js.map +1 -0
- package/dist/src/database/migration/MigrationRunCommand.d.ts +11 -0
- package/dist/src/database/migration/MigrationRunCommand.d.ts.map +1 -0
- package/dist/src/database/migration/MigrationRunCommand.js +118 -0
- package/dist/src/database/migration/MigrationRunCommand.js.map +1 -0
- package/dist/src/database/migration/characters.d.ts +14 -0
- package/dist/src/database/migration/characters.d.ts.map +1 -0
- package/dist/src/database/migration/characters.js +56 -0
- package/dist/src/database/migration/characters.js.map +1 -0
- package/dist/src/database/migration/create/MigrationCreateCommand.d.ts +11 -0
- package/dist/src/database/migration/create/MigrationCreateCommand.d.ts.map +1 -0
- package/dist/src/database/migration/create/MigrationCreateCommand.js +104 -0
- package/dist/src/database/migration/create/MigrationCreateCommand.js.map +1 -0
- package/dist/src/database/migration/create/comparator.d.ts +3 -0
- package/dist/src/database/migration/create/comparator.d.ts.map +1 -0
- package/dist/src/database/migration/create/comparator.js +408 -0
- package/dist/src/database/migration/create/comparator.js.map +1 -0
- package/dist/src/database/migration/create/db-reader.d.ts +5 -0
- package/dist/src/database/migration/create/db-reader.d.ts.map +1 -0
- package/dist/src/database/migration/create/db-reader.js +473 -0
- package/dist/src/database/migration/create/db-reader.js.map +1 -0
- package/dist/src/database/migration/create/ddl-generator.d.ts +3 -0
- package/dist/src/database/migration/create/ddl-generator.d.ts.map +1 -0
- package/dist/src/database/migration/create/ddl-generator.js +725 -0
- package/dist/src/database/migration/create/ddl-generator.js.map +1 -0
- package/dist/src/database/migration/create/entity-reader.d.ts +4 -0
- package/dist/src/database/migration/create/entity-reader.d.ts.map +1 -0
- package/dist/src/database/migration/create/entity-reader.js +408 -0
- package/dist/src/database/migration/create/entity-reader.js.map +1 -0
- package/dist/src/database/migration/create/file-generator.d.ts +2 -0
- package/dist/src/database/migration/create/file-generator.d.ts.map +1 -0
- package/dist/src/database/migration/create/file-generator.js +55 -0
- package/dist/src/database/migration/create/file-generator.js.map +1 -0
- package/dist/src/database/migration/create/prompt.d.ts +4 -0
- package/dist/src/database/migration/create/prompt.d.ts.map +1 -0
- package/dist/src/database/migration/create/prompt.js +55 -0
- package/dist/src/database/migration/create/prompt.js.map +1 -0
- package/dist/src/database/migration/create/schema-model.d.ts +109 -0
- package/dist/src/database/migration/create/schema-model.d.ts.map +1 -0
- package/dist/src/database/migration/create/schema-model.js +24 -0
- package/dist/src/database/migration/create/schema-model.js.map +1 -0
- package/dist/src/database/migration/helpers.d.ts +2 -0
- package/dist/src/database/migration/helpers.d.ts.map +1 -0
- package/dist/src/database/migration/helpers.js +8 -0
- package/dist/src/database/migration/helpers.js.map +1 -0
- package/dist/src/database/migration/index.d.ts +9 -0
- package/dist/src/database/migration/index.d.ts.map +1 -0
- package/dist/src/database/migration/index.js +43 -0
- package/dist/src/database/migration/index.js.map +1 -0
- package/dist/src/database/migration/migration.entity.d.ts +8 -0
- package/dist/src/database/migration/migration.entity.d.ts.map +1 -0
- package/dist/src/database/migration/migration.entity.js +16 -0
- package/dist/src/database/migration/migration.entity.js.map +1 -0
- package/dist/src/database/mysql.d.ts +16 -0
- package/dist/src/database/mysql.d.ts.map +1 -0
- package/dist/src/database/mysql.js +140 -0
- package/dist/src/database/mysql.js.map +1 -0
- package/dist/src/database/postgres.d.ts +16 -0
- package/dist/src/database/postgres.d.ts.map +1 -0
- package/dist/src/database/postgres.js +91 -0
- package/dist/src/database/postgres.js.map +1 -0
- package/dist/src/database/types.d.ts +21 -0
- package/dist/src/database/types.d.ts.map +1 -0
- package/dist/src/database/types.js +27 -0
- package/dist/src/database/types.js.map +1 -0
- package/dist/src/health/health.module.d.ts +6 -0
- package/dist/src/health/health.module.d.ts.map +1 -0
- package/dist/src/health/health.module.js +32 -0
- package/dist/src/health/health.module.js.map +1 -0
- package/dist/src/health/healthcheck.controller.d.ts +10 -0
- package/dist/src/health/healthcheck.controller.d.ts.map +1 -0
- package/dist/src/health/healthcheck.controller.js +30 -0
- package/dist/src/health/healthcheck.controller.js.map +1 -0
- package/dist/src/health/healthcheck.service.d.ts +8 -0
- package/dist/src/health/healthcheck.service.d.ts.map +1 -0
- package/dist/src/health/healthcheck.service.js +20 -0
- package/dist/src/health/healthcheck.service.js.map +1 -0
- package/dist/src/health/index.d.ts +3 -0
- package/dist/src/health/index.d.ts.map +1 -0
- package/dist/src/health/index.js +6 -0
- package/dist/src/health/index.js.map +1 -0
- package/dist/src/helpers/async/context.d.ts +11 -0
- package/dist/src/helpers/async/context.d.ts.map +1 -0
- package/dist/src/helpers/async/context.js +75 -0
- package/dist/src/helpers/async/context.js.map +1 -0
- package/dist/src/helpers/async/process.d.ts +16 -0
- package/dist/src/helpers/async/process.d.ts.map +1 -0
- package/dist/src/helpers/async/process.js +44 -0
- package/dist/src/helpers/async/process.js.map +1 -0
- package/dist/src/helpers/async/promise.d.ts +5 -0
- package/dist/src/helpers/async/promise.d.ts.map +1 -0
- package/dist/src/helpers/async/promise.js +27 -0
- package/dist/src/helpers/async/promise.js.map +1 -0
- package/dist/src/helpers/data/array.d.ts +3 -0
- package/dist/src/helpers/data/array.d.ts.map +1 -0
- package/dist/src/helpers/data/array.js +17 -0
- package/dist/src/helpers/data/array.js.map +1 -0
- package/dist/src/helpers/data/objects.d.ts +12 -0
- package/dist/src/helpers/data/objects.d.ts.map +1 -0
- package/dist/src/helpers/data/objects.js +75 -0
- package/dist/src/helpers/data/objects.js.map +1 -0
- package/dist/src/helpers/data/serialization.d.ts +4 -0
- package/dist/src/helpers/data/serialization.d.ts.map +1 -0
- package/dist/src/helpers/data/serialization.js +15 -0
- package/dist/src/helpers/data/serialization.js.map +1 -0
- package/dist/src/helpers/data/transformer.d.ts +13 -0
- package/dist/src/helpers/data/transformer.d.ts.map +1 -0
- package/dist/src/helpers/data/transformer.js +55 -0
- package/dist/src/helpers/data/transformer.js.map +1 -0
- package/dist/src/helpers/framework/decorators.d.ts +5 -0
- package/dist/src/helpers/framework/decorators.d.ts.map +1 -0
- package/dist/src/helpers/framework/decorators.js +39 -0
- package/dist/src/helpers/framework/decorators.js.map +1 -0
- package/dist/src/helpers/framework/event.d.ts +3 -0
- package/dist/src/helpers/framework/event.d.ts.map +1 -0
- package/dist/src/helpers/framework/event.js +20 -0
- package/dist/src/helpers/framework/event.js.map +1 -0
- package/dist/src/helpers/framework/injection.d.ts +7 -0
- package/dist/src/helpers/framework/injection.d.ts.map +1 -0
- package/dist/src/helpers/framework/injection.js +52 -0
- package/dist/src/helpers/framework/injection.js.map +1 -0
- package/dist/src/helpers/index.d.ts +22 -0
- package/dist/src/helpers/index.d.ts.map +1 -0
- package/dist/src/helpers/index.js +32 -0
- package/dist/src/helpers/index.js.map +1 -0
- package/dist/src/helpers/io/package.d.ts +5 -0
- package/dist/src/helpers/io/package.d.ts.map +1 -0
- package/dist/src/helpers/io/package.js +31 -0
- package/dist/src/helpers/io/package.js.map +1 -0
- package/dist/src/helpers/io/stream.d.ts +18 -0
- package/dist/src/helpers/io/stream.d.ts.map +1 -0
- package/dist/src/helpers/io/stream.js +91 -0
- package/dist/src/helpers/io/stream.js.map +1 -0
- package/dist/src/helpers/redis/broadcast.d.ts +12 -0
- package/dist/src/helpers/redis/broadcast.d.ts.map +1 -0
- package/dist/src/helpers/redis/broadcast.js +99 -0
- package/dist/src/helpers/redis/broadcast.js.map +1 -0
- package/dist/src/helpers/redis/cache.d.ts +7 -0
- package/dist/src/helpers/redis/cache.d.ts.map +1 -0
- package/dist/src/helpers/redis/cache.js +28 -0
- package/dist/src/helpers/redis/cache.js.map +1 -0
- package/dist/src/helpers/redis/mutex.d.ts +24 -0
- package/dist/src/helpers/redis/mutex.d.ts.map +1 -0
- package/dist/src/helpers/redis/mutex.js +240 -0
- package/dist/src/helpers/redis/mutex.js.map +1 -0
- package/dist/src/helpers/redis/redis.d.ts +11 -0
- package/dist/src/helpers/redis/redis.d.ts.map +1 -0
- package/dist/src/helpers/redis/redis.js +59 -0
- package/dist/src/helpers/redis/redis.js.map +1 -0
- package/dist/src/helpers/security/crypto.d.ts +26 -0
- package/dist/src/helpers/security/crypto.d.ts.map +1 -0
- package/dist/src/helpers/security/crypto.js +121 -0
- package/dist/src/helpers/security/crypto.js.map +1 -0
- package/dist/src/helpers/security/validation.d.ts +4 -0
- package/dist/src/helpers/security/validation.d.ts.map +1 -0
- package/dist/src/helpers/security/validation.js +25 -0
- package/dist/src/helpers/security/validation.js.map +1 -0
- package/dist/src/helpers/utils/date.d.ts +4 -0
- package/dist/src/helpers/utils/date.d.ts.map +1 -0
- package/dist/src/helpers/utils/date.js +23 -0
- package/dist/src/helpers/utils/date.js.map +1 -0
- package/dist/src/helpers/utils/error.d.ts +24 -0
- package/dist/src/helpers/utils/error.d.ts.map +1 -0
- package/dist/src/helpers/utils/error.js +168 -0
- package/dist/src/helpers/utils/error.js.map +1 -0
- package/dist/src/helpers/utils/jsx.d.ts +3 -0
- package/dist/src/helpers/utils/jsx.d.ts.map +1 -0
- package/dist/src/helpers/utils/jsx.js +13 -0
- package/dist/src/helpers/utils/jsx.js.map +1 -0
- package/dist/src/helpers/utils/uuid.d.ts +3 -0
- package/dist/src/helpers/utils/uuid.d.ts.map +1 -0
- package/dist/src/helpers/utils/uuid.js +14 -0
- package/dist/src/helpers/utils/uuid.js.map +1 -0
- package/dist/src/http/auth.d.ts +46 -0
- package/dist/src/http/auth.d.ts.map +1 -0
- package/dist/src/http/auth.js +162 -0
- package/dist/src/http/auth.js.map +1 -0
- package/dist/src/http/context.d.ts +5 -0
- package/dist/src/http/context.d.ts.map +1 -0
- package/dist/src/http/context.js +22 -0
- package/dist/src/http/context.js.map +1 -0
- package/dist/src/http/cors.d.ts +36 -0
- package/dist/src/http/cors.d.ts.map +1 -0
- package/dist/src/http/cors.js +171 -0
- package/dist/src/http/cors.js.map +1 -0
- package/dist/src/http/errors.d.ts +3 -0
- package/dist/src/http/errors.d.ts.map +1 -0
- package/dist/src/http/errors.js +10 -0
- package/dist/src/http/errors.js.map +1 -0
- package/dist/src/http/index.d.ts +24 -0
- package/dist/src/http/index.d.ts.map +1 -0
- package/dist/src/http/index.js +25 -0
- package/dist/src/http/index.js.map +1 -0
- package/dist/src/http/kernel.d.ts +17 -0
- package/dist/src/http/kernel.d.ts.map +1 -0
- package/dist/src/http/kernel.js +133 -0
- package/dist/src/http/kernel.js.map +1 -0
- package/dist/src/http/middleware.d.ts +12 -0
- package/dist/src/http/middleware.d.ts.map +1 -0
- package/dist/src/http/middleware.js +61 -0
- package/dist/src/http/middleware.js.map +1 -0
- package/dist/src/http/overrides.d.ts +2 -0
- package/dist/src/http/overrides.d.ts.map +1 -0
- package/dist/src/http/overrides.js +19 -0
- package/dist/src/http/overrides.js.map +1 -0
- package/dist/src/http/store.d.ts +33 -0
- package/dist/src/http/store.d.ts.map +1 -0
- package/dist/src/http/store.js +102 -0
- package/dist/src/http/store.js.map +1 -0
- package/dist/src/http/uploads.d.ts +7 -0
- package/dist/src/http/uploads.d.ts.map +1 -0
- package/dist/src/http/uploads.js +8 -0
- package/dist/src/http/uploads.js.map +1 -0
- package/dist/src/http/workflow.d.ts +18 -0
- package/dist/src/http/workflow.d.ts.map +1 -0
- package/dist/src/http/workflow.js +181 -0
- package/dist/src/http/workflow.js.map +1 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +25 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/services/cli/invoke.d.ts +5 -0
- package/dist/src/services/cli/invoke.d.ts.map +1 -0
- package/dist/src/services/cli/invoke.js +45 -0
- package/dist/src/services/cli/invoke.js.map +1 -0
- package/dist/src/services/cli/repl.d.ts +5 -0
- package/dist/src/services/cli/repl.d.ts.map +1 -0
- package/dist/src/services/cli/repl.js +71 -0
- package/dist/src/services/cli/repl.js.map +1 -0
- package/dist/src/services/cli.d.ts +12 -0
- package/dist/src/services/cli.d.ts.map +1 -0
- package/dist/src/services/cli.js +76 -0
- package/dist/src/services/cli.js.map +1 -0
- package/dist/src/services/index.d.ts +7 -0
- package/dist/src/services/index.d.ts.map +1 -0
- package/dist/src/services/index.js +10 -0
- package/dist/src/services/index.js.map +1 -0
- package/dist/src/services/leader.d.ts +32 -0
- package/dist/src/services/leader.d.ts.map +1 -0
- package/dist/src/services/leader.js +174 -0
- package/dist/src/services/leader.js.map +1 -0
- package/dist/src/services/logger.d.ts +35 -0
- package/dist/src/services/logger.d.ts.map +1 -0
- package/dist/src/services/logger.js +245 -0
- package/dist/src/services/logger.js.map +1 -0
- package/dist/src/services/mail/index.d.ts +61 -0
- package/dist/src/services/mail/index.d.ts.map +1 -0
- package/dist/src/services/mail/index.js +90 -0
- package/dist/src/services/mail/index.js.map +1 -0
- package/dist/src/services/mail/postmark.d.ts +11 -0
- package/dist/src/services/mail/postmark.d.ts.map +1 -0
- package/dist/src/services/mail/postmark.js +42 -0
- package/dist/src/services/mail/postmark.js.map +1 -0
- package/dist/src/services/mail/smtp.d.ts +11 -0
- package/dist/src/services/mail/smtp.d.ts.map +1 -0
- package/dist/src/services/mail/smtp.js +61 -0
- package/dist/src/services/mail/smtp.js.map +1 -0
- package/dist/src/services/mesh.d.ts +65 -0
- package/dist/src/services/mesh.d.ts.map +1 -0
- package/dist/src/services/mesh.js +422 -0
- package/dist/src/services/mesh.js.map +1 -0
- package/dist/src/services/worker/bootstrap.d.ts +3 -0
- package/dist/src/services/worker/bootstrap.d.ts.map +1 -0
- package/dist/src/services/worker/bootstrap.js +70 -0
- package/dist/src/services/worker/bootstrap.js.map +1 -0
- package/dist/src/services/worker/cli.d.ts +23 -0
- package/dist/src/services/worker/cli.d.ts.map +1 -0
- package/dist/src/services/worker/cli.js +81 -0
- package/dist/src/services/worker/cli.js.map +1 -0
- package/dist/src/services/worker/entity.d.ts +18 -0
- package/dist/src/services/worker/entity.d.ts.map +1 -0
- package/dist/src/services/worker/entity.js +16 -0
- package/dist/src/services/worker/entity.js.map +1 -0
- package/dist/src/services/worker/index.d.ts +9 -0
- package/dist/src/services/worker/index.d.ts.map +1 -0
- package/dist/src/services/worker/index.js +40 -0
- package/dist/src/services/worker/index.js.map +1 -0
- package/dist/src/services/worker/observer.d.ts +18 -0
- package/dist/src/services/worker/observer.d.ts.map +1 -0
- package/dist/src/services/worker/observer.js +172 -0
- package/dist/src/services/worker/observer.js.map +1 -0
- package/dist/src/services/worker/queue.d.ts +8 -0
- package/dist/src/services/worker/queue.d.ts.map +1 -0
- package/dist/src/services/worker/queue.js +31 -0
- package/dist/src/services/worker/queue.js.map +1 -0
- package/dist/src/services/worker/runner.d.ts +17 -0
- package/dist/src/services/worker/runner.d.ts.map +1 -0
- package/dist/src/services/worker/runner.js +131 -0
- package/dist/src/services/worker/runner.js.map +1 -0
- package/dist/src/services/worker/types.d.ts +26 -0
- package/dist/src/services/worker/types.d.ts.map +1 -0
- package/dist/src/services/worker/types.js +29 -0
- package/dist/src/services/worker/types.js.map +1 -0
- package/dist/src/srpc/SrpcByteStream.d.ts +67 -0
- package/dist/src/srpc/SrpcByteStream.d.ts.map +1 -0
- package/dist/src/srpc/SrpcByteStream.js +319 -0
- package/dist/src/srpc/SrpcByteStream.js.map +1 -0
- package/dist/src/srpc/SrpcClient.d.ts +75 -0
- package/dist/src/srpc/SrpcClient.d.ts.map +1 -0
- package/dist/src/srpc/SrpcClient.js +445 -0
- package/dist/src/srpc/SrpcClient.js.map +1 -0
- package/dist/src/srpc/SrpcServer.d.ts +54 -0
- package/dist/src/srpc/SrpcServer.d.ts.map +1 -0
- package/dist/src/srpc/SrpcServer.js +456 -0
- package/dist/src/srpc/SrpcServer.js.map +1 -0
- package/dist/src/srpc/index.d.ts +7 -0
- package/dist/src/srpc/index.d.ts.map +1 -0
- package/dist/src/srpc/index.js +12 -0
- package/dist/src/srpc/index.js.map +1 -0
- package/dist/src/srpc/types.d.ts +129 -0
- package/dist/src/srpc/types.d.ts.map +1 -0
- package/dist/src/srpc/types.js +65 -0
- package/dist/src/srpc/types.js.map +1 -0
- package/dist/src/telemetry/index.d.ts +2 -0
- package/dist/src/telemetry/index.d.ts.map +1 -0
- package/dist/src/telemetry/index.js +5 -0
- package/dist/src/telemetry/index.js.map +1 -0
- package/dist/src/telemetry/otel/MariaDBInstrumentation.d.ts +22 -0
- package/dist/src/telemetry/otel/MariaDBInstrumentation.d.ts.map +1 -0
- package/dist/src/telemetry/otel/MariaDBInstrumentation.js +248 -0
- package/dist/src/telemetry/otel/MariaDBInstrumentation.js.map +1 -0
- package/dist/src/telemetry/otel/helpers.d.ts +27 -0
- package/dist/src/telemetry/otel/helpers.d.ts.map +1 -0
- package/dist/src/telemetry/otel/helpers.js +126 -0
- package/dist/src/telemetry/otel/helpers.js.map +1 -0
- package/dist/src/telemetry/otel/index.d.ts +14 -0
- package/dist/src/telemetry/otel/index.d.ts.map +1 -0
- package/dist/src/telemetry/otel/index.js +132 -0
- package/dist/src/telemetry/otel/index.js.map +1 -0
- package/dist/src/telemetry/otel/metrics.controller.d.ts +6 -0
- package/dist/src/telemetry/otel/metrics.controller.d.ts.map +1 -0
- package/dist/src/telemetry/otel/metrics.controller.js +63 -0
- package/dist/src/telemetry/otel/metrics.controller.js.map +1 -0
- package/dist/src/telemetry/sentry.d.ts +9 -0
- package/dist/src/telemetry/sentry.d.ts.map +1 -0
- package/dist/src/telemetry/sentry.js +62 -0
- package/dist/src/telemetry/sentry.js.map +1 -0
- package/dist/src/testapp/bootstrap.d.ts +1 -0
- package/dist/src/testapp/bootstrap.d.ts.map +1 -0
- package/dist/src/testapp/bootstrap.js +18 -0
- package/dist/src/testapp/bootstrap.js.map +1 -0
- package/dist/src/testapp/sample.d.ts +6 -0
- package/dist/src/testapp/sample.d.ts.map +1 -0
- package/dist/src/testapp/sample.js +228 -0
- package/dist/src/testapp/sample.js.map +1 -0
- package/dist/src/testapp/srpc-test.d.ts +27 -0
- package/dist/src/testapp/srpc-test.d.ts.map +1 -0
- package/dist/src/testapp/srpc-test.js +570 -0
- package/dist/src/testapp/srpc-test.js.map +1 -0
- package/dist/src/testing/expect.d.ts +25 -0
- package/dist/src/testing/expect.d.ts.map +1 -0
- package/dist/src/testing/expect.js +151 -0
- package/dist/src/testing/expect.js.map +1 -0
- package/dist/src/testing/fixtures.d.ts +19 -0
- package/dist/src/testing/fixtures.d.ts.map +1 -0
- package/dist/src/testing/fixtures.js +69 -0
- package/dist/src/testing/fixtures.js.map +1 -0
- package/dist/src/testing/index.d.ts +260 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +345 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/testing/requests.d.ts +10 -0
- package/dist/src/testing/requests.d.ts.map +1 -0
- package/dist/src/testing/requests.js +56 -0
- package/dist/src/testing/requests.js.map +1 -0
- package/dist/src/testing/sql.d.ts +11 -0
- package/dist/src/testing/sql.d.ts.map +1 -0
- package/dist/src/testing/sql.js +55 -0
- package/dist/src/testing/sql.js.map +1 -0
- package/dist/src/types/index.d.ts +57 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +73 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/phone.d.ts +11 -0
- package/dist/src/types/phone.d.ts.map +1 -0
- package/dist/src/types/phone.js +73 -0
- package/dist/src/types/phone.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/docs/README.md +38 -0
- package/docs/authentication.md +215 -0
- package/docs/cli.md +302 -0
- package/docs/configuration.md +176 -0
- package/docs/database.md +422 -0
- package/docs/getting-started.md +154 -0
- package/docs/health.md +53 -0
- package/docs/helpers.md +436 -0
- package/docs/http.md +253 -0
- package/docs/leader-service.md +98 -0
- package/docs/logging.md +150 -0
- package/docs/mail.md +161 -0
- package/docs/mesh-service.md +204 -0
- package/docs/srpc.md +261 -0
- package/docs/telemetry.md +166 -0
- package/docs/testing.md +222 -0
- package/docs/types.md +215 -0
- package/docs/worker.md +174 -0
- package/lefthook.yml +12 -0
- package/openapi.yaml +109 -0
- package/package.json +133 -0
- package/patches/@deepkit+type+1.0.19.patch +38 -0
- package/resources/proto/generated/test/test.ts +2721 -0
- package/resources/proto/sample.proto +85 -0
- package/resources/proto/test.proto +178 -0
- package/src/app/base.ts +257 -0
- package/src/app/config.loader.ts +66 -0
- package/src/app/config.ts +120 -0
- package/src/app/const.ts +4 -0
- package/src/app/dev.ts +70 -0
- package/src/app/index.ts +6 -0
- package/src/app/openapi.ts +3 -0
- package/src/app/resolver.ts +49 -0
- package/src/app/shutdown.ts +55 -0
- package/src/app/state.ts +19 -0
- package/src/auth/index.ts +2 -0
- package/src/auth/jwt.ts +275 -0
- package/src/auth/provider.ts +57 -0
- package/src/cli/dksf-dev.ts +363 -0
- package/src/cli/dksf-gen-proto.ts +176 -0
- package/src/cli/dksf-install.ts +11 -0
- package/src/cli/dksf-test.ts +95 -0
- package/src/cli/dksf-update.ts +101 -0
- package/src/database/CLAUDE.md +390 -0
- package/src/database/common.ts +385 -0
- package/src/database/dialect.ts +43 -0
- package/src/database/entity.ts +285 -0
- package/src/database/index.ts +7 -0
- package/src/database/migration/MigrationResetCommand.ts +152 -0
- package/src/database/migration/MigrationRunCommand.ts +118 -0
- package/src/database/migration/characters.ts +53 -0
- package/src/database/migration/create/MigrationCreateCommand.ts +94 -0
- package/src/database/migration/create/comparator.ts +467 -0
- package/src/database/migration/create/db-reader.ts +510 -0
- package/src/database/migration/create/ddl-generator.ts +755 -0
- package/src/database/migration/create/entity-reader.ts +462 -0
- package/src/database/migration/create/file-generator.ts +52 -0
- package/src/database/migration/create/prompt.ts +49 -0
- package/src/database/migration/create/schema-model.ts +102 -0
- package/src/database/migration/helpers.ts +3 -0
- package/src/database/migration/index.ts +35 -0
- package/src/database/migration/migration.entity.ts +10 -0
- package/src/database/mysql.ts +140 -0
- package/src/database/postgres.ts +97 -0
- package/src/database/types.ts +18 -0
- package/src/health/health.module.ts +30 -0
- package/src/health/healthcheck.controller.ts +17 -0
- package/src/health/healthcheck.service.ts +15 -0
- package/src/health/index.ts +2 -0
- package/src/helpers/CLAUDE.md +71 -0
- package/src/helpers/async/context.ts +67 -0
- package/src/helpers/async/process.ts +49 -0
- package/src/helpers/async/promise.ts +16 -0
- package/src/helpers/data/array.ts +11 -0
- package/src/helpers/data/objects.ts +64 -0
- package/src/helpers/data/serialization.ts +11 -0
- package/src/helpers/data/transformer.ts +54 -0
- package/src/helpers/framework/decorators.ts +27 -0
- package/src/helpers/framework/event.ts +11 -0
- package/src/helpers/framework/injection.ts +47 -0
- package/src/helpers/index.ts +34 -0
- package/src/helpers/io/package.ts +26 -0
- package/src/helpers/io/stream.ts +79 -0
- package/src/helpers/redis/broadcast.ts +94 -0
- package/src/helpers/redis/cache.ts +28 -0
- package/src/helpers/redis/mutex.ts +260 -0
- package/src/helpers/redis/redis.ts +60 -0
- package/src/helpers/security/crypto.ts +133 -0
- package/src/helpers/security/validation.ts +16 -0
- package/src/helpers/utils/date.ts +13 -0
- package/src/helpers/utils/error.ts +155 -0
- package/src/helpers/utils/jsx.ts +8 -0
- package/src/helpers/utils/uuid.ts +8 -0
- package/src/http/auth.ts +156 -0
- package/src/http/context.ts +15 -0
- package/src/http/cors.ts +159 -0
- package/src/http/errors.ts +9 -0
- package/src/http/index.ts +19 -0
- package/src/http/kernel.ts +138 -0
- package/src/http/middleware.ts +59 -0
- package/src/http/overrides.ts +20 -0
- package/src/http/store.ts +86 -0
- package/src/http/uploads.ts +6 -0
- package/src/http/workflow.ts +167 -0
- package/src/index.ts +19 -0
- package/src/services/cli/invoke.ts +39 -0
- package/src/services/cli/repl.ts +67 -0
- package/src/services/cli.ts +74 -0
- package/src/services/index.ts +6 -0
- package/src/services/leader.ts +201 -0
- package/src/services/logger.ts +258 -0
- package/src/services/mail/index.ts +117 -0
- package/src/services/mail/postmark.ts +37 -0
- package/src/services/mail/smtp.ts +46 -0
- package/src/services/mesh.ts +508 -0
- package/src/services/worker/CLAUDE.md +77 -0
- package/src/services/worker/bootstrap.ts +58 -0
- package/src/services/worker/cli.ts +63 -0
- package/src/services/worker/entity.ts +22 -0
- package/src/services/worker/index.ts +30 -0
- package/src/services/worker/observer.ts +180 -0
- package/src/services/worker/queue.ts +34 -0
- package/src/services/worker/runner.ts +146 -0
- package/src/services/worker/types.ts +32 -0
- package/src/srpc/CLAUDE.md +194 -0
- package/src/srpc/SRPC_MIGRATION_GUIDE.md +348 -0
- package/src/srpc/SrpcByteStream.ts +382 -0
- package/src/srpc/SrpcClient.ts +512 -0
- package/src/srpc/SrpcServer.ts +575 -0
- package/src/srpc/index.ts +15 -0
- package/src/srpc/types.ts +144 -0
- package/src/telemetry/index.ts +1 -0
- package/src/telemetry/otel/MariaDBInstrumentation.ts +297 -0
- package/src/telemetry/otel/helpers.ts +117 -0
- package/src/telemetry/otel/index.ts +150 -0
- package/src/telemetry/otel/metrics.controller.ts +50 -0
- package/src/telemetry/sentry.ts +58 -0
- package/src/testapp/bootstrap.ts +17 -0
- package/src/testapp/sample.ts +220 -0
- package/src/testapp/srpc-test.ts +684 -0
- package/src/testing/expect.ts +148 -0
- package/src/testing/fixtures.ts +62 -0
- package/src/testing/index.ts +355 -0
- package/src/testing/requests.ts +68 -0
- package/src/testing/sql.ts +50 -0
- package/src/types/index.ts +64 -0
- package/src/types/phone.ts +64 -0
- package/tests/app/app.spec.ts +53 -0
- package/tests/app/type.spec.ts +22 -0
- package/tests/auth/jwt.spec.ts +90 -0
- package/tests/database/entity.spec.ts +382 -0
- package/tests/database/locks.spec.ts +142 -0
- package/tests/database/migration-create-integration.spec.ts +234 -0
- package/tests/database/migration-create-unit.spec.ts +3896 -0
- package/tests/helpers/array.spec.ts +80 -0
- package/tests/helpers/cache.spec.ts +202 -0
- package/tests/helpers/crypto.spec.ts +236 -0
- package/tests/helpers/date.spec.ts +94 -0
- package/tests/helpers/error.spec.ts +233 -0
- package/tests/helpers/mutex.spec.ts +354 -0
- package/tests/helpers/objects.spec.ts +212 -0
- package/tests/helpers/package.spec.ts +90 -0
- package/tests/helpers/promise.spec.ts +119 -0
- package/tests/helpers/redis.spec.ts +50 -0
- package/tests/helpers/serialization.spec.ts +150 -0
- package/tests/helpers/stream.spec.ts +225 -0
- package/tests/helpers/validation.spec.ts +133 -0
- package/tests/services/leader.spec.ts +257 -0
- package/tests/services/logger.spec.ts +269 -0
- package/tests/services/mesh.spec.ts +814 -0
- package/tests/shared/db.ts +105 -0
- package/tests/shared/globalSetup.ts +48 -0
- package/tests/shared/helpers.ts +40 -0
- package/tests/srpc/SrpcByteStream.spec.ts +542 -0
- package/tests/tsconfig.json +4 -0
- package/tests/types/index.spec.ts +60 -0
- package/tests/types/phone.spec.ts +140 -0
- package/tsconfig.json +106 -0
- package/tsconfig.test.json +8 -0
- package/types.d.ts +6 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import RedisClient, { RedisOptions } from 'ioredis';
|
|
2
|
+
|
|
3
|
+
import { getAppConfig } from '../../app/resolver';
|
|
4
|
+
import { getPackageName } from '../io/package';
|
|
5
|
+
|
|
6
|
+
export function createRedisOptions(configPrefix?: string): { options: RedisOptions; prefix: string } {
|
|
7
|
+
const config = { ...getAppConfig() };
|
|
8
|
+
|
|
9
|
+
if (configPrefix) {
|
|
10
|
+
for (const key in config) {
|
|
11
|
+
if (key.startsWith(`${configPrefix}_REDIS_`)) {
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
+
(config as any)[key.substring(configPrefix.length + 1)] = (config as any)[key];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const prefix = config.REDIS_PREFIX ?? getPackageName() ?? 'app';
|
|
19
|
+
|
|
20
|
+
if (config.REDIS_SENTINEL_HOST) {
|
|
21
|
+
const options: RedisOptions = {
|
|
22
|
+
sentinels: [
|
|
23
|
+
{
|
|
24
|
+
host: config.REDIS_SENTINEL_HOST,
|
|
25
|
+
port: config.REDIS_SENTINEL_PORT
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
name: config.REDIS_SENTINEL_NAME
|
|
29
|
+
};
|
|
30
|
+
return { options, prefix };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (config.REDIS_HOST) {
|
|
34
|
+
const options: RedisOptions = { host: config.REDIS_HOST, port: config.REDIS_PORT };
|
|
35
|
+
return { options, prefix };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
throw new Error('REDIS_HOST or REDIS_SENTINEL_HOST must be configured');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const allClients = new Set<RedisClient>();
|
|
42
|
+
|
|
43
|
+
export function createRedis(configPrefix?: string): {
|
|
44
|
+
client: RedisClient;
|
|
45
|
+
prefix: string;
|
|
46
|
+
} {
|
|
47
|
+
const { options, prefix } = createRedisOptions(configPrefix);
|
|
48
|
+
const client = new RedisClient(options);
|
|
49
|
+
allClients.add(client);
|
|
50
|
+
client.on('end', () => allClients.delete(client));
|
|
51
|
+
return { client, prefix };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function disconnectAllRedis(): Promise<void> {
|
|
55
|
+
const clients = [...allClients];
|
|
56
|
+
allClients.clear();
|
|
57
|
+
await Promise.all(clients.map(c => c.quit().catch(() => {})));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// todo: register Redis instances with healthcheck controller
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { randomBytes as nativeRandomBytes } from 'crypto';
|
|
2
|
+
import * as crypto from 'crypto';
|
|
3
|
+
import { promisify } from 'util';
|
|
4
|
+
|
|
5
|
+
import { getAppConfig } from '../../app/resolver';
|
|
6
|
+
|
|
7
|
+
const nativeAsyncRandomBytes = promisify(nativeRandomBytes);
|
|
8
|
+
|
|
9
|
+
// TODO: slice long requests into multiple async requests as not to block the thread for too long
|
|
10
|
+
|
|
11
|
+
export async function randomBytes(length: number, shouldReturnHex?: never): Promise<Buffer>;
|
|
12
|
+
export async function randomBytes(length: number, shouldReturnHex: true): Promise<string>;
|
|
13
|
+
export async function randomBytes(length: number, shouldReturnHex?: true | never): Promise<Buffer | string> {
|
|
14
|
+
const bytes = await nativeAsyncRandomBytes(length);
|
|
15
|
+
return shouldReturnHex ? bytes.toString('hex') : bytes;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function randomBytesSync(length: number, shouldReturnHex?: never): Buffer;
|
|
19
|
+
export function randomBytesSync(length: number, shouldReturnHex: true): string;
|
|
20
|
+
export function randomBytesSync(length: number, shouldReturnHex?: true | never): Buffer | string {
|
|
21
|
+
const bytes = nativeRandomBytes(length);
|
|
22
|
+
return shouldReturnHex ? bytes.toString('hex') : bytes;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const PrintableCharacters = Array.from({ length: 127 - 32 }, (_, i) => String.fromCharCode(i + 32)).join('');
|
|
26
|
+
export const AlphanumericCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
27
|
+
export const UpperCaseAlphanumericCharacters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
28
|
+
export const NumericCharacters = '0123456789';
|
|
29
|
+
export async function randomString(length: number, source: string = PrintableCharacters): Promise<string> {
|
|
30
|
+
const reference = await randomBytes(length);
|
|
31
|
+
const result = Array.from({ length });
|
|
32
|
+
for (let i = 0; i < length; i++) {
|
|
33
|
+
result[i] = source[reference[i] % source.length];
|
|
34
|
+
}
|
|
35
|
+
return result.join('');
|
|
36
|
+
}
|
|
37
|
+
export function randomStringSync(length: number, source: string = PrintableCharacters): string {
|
|
38
|
+
const reference = randomBytesSync(length);
|
|
39
|
+
const result = Array.from({ length });
|
|
40
|
+
for (let i = 0; i < length; i++) {
|
|
41
|
+
result[i] = source[reference[i] % source.length];
|
|
42
|
+
}
|
|
43
|
+
return result.join('');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class Crypto {
|
|
47
|
+
static encrypt(data: string): string;
|
|
48
|
+
static encrypt(data: Buffer): Buffer;
|
|
49
|
+
static encrypt(data: string | Buffer): string | Buffer {
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
return this.getInstance().encrypt(data as any);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static decrypt(data: string): string;
|
|
55
|
+
static decrypt(data: Buffer): Buffer;
|
|
56
|
+
static decrypt(data: string | Buffer): string | Buffer {
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
+
return this.getInstance().decrypt(data as any);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private static instance: Crypto;
|
|
62
|
+
private static getInstance() {
|
|
63
|
+
if (!this.instance) {
|
|
64
|
+
this.instance = new Crypto();
|
|
65
|
+
}
|
|
66
|
+
return this.instance;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private key: Buffer;
|
|
70
|
+
private ivLength: number;
|
|
71
|
+
constructor() {
|
|
72
|
+
const appConfig = getAppConfig();
|
|
73
|
+
if (!appConfig.CRYPTO_SECRET) {
|
|
74
|
+
throw new Error('CRYPTO_SECRET is not set in application configuration');
|
|
75
|
+
}
|
|
76
|
+
if (appConfig.CRYPTO_SECRET.length === 64 && /^[0-9a-f]+$/i.test(appConfig.CRYPTO_SECRET)) {
|
|
77
|
+
this.key = Buffer.from(appConfig.CRYPTO_SECRET, 'hex');
|
|
78
|
+
} else if (appConfig.CRYPTO_SECRET.length !== 32) {
|
|
79
|
+
throw new Error('CRYPTO_SECRET must be 32 bytes (or 64 hex characters)');
|
|
80
|
+
} else {
|
|
81
|
+
this.key = Buffer.from(appConfig.CRYPTO_SECRET);
|
|
82
|
+
}
|
|
83
|
+
this.ivLength = appConfig.CRYPTO_IV_LENGTH;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
encrypt(data: string): string;
|
|
87
|
+
encrypt(data: Buffer): Buffer;
|
|
88
|
+
encrypt(data: string | Buffer): string | Buffer {
|
|
89
|
+
// Check if the input is a Buffer
|
|
90
|
+
const isBuffer = Buffer.isBuffer(data);
|
|
91
|
+
|
|
92
|
+
// Convert to a buffer if it's a string
|
|
93
|
+
if (!isBuffer) {
|
|
94
|
+
data = Buffer.from(data as string);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Generate a random initialization vector
|
|
98
|
+
const iv = crypto.randomBytes(this.ivLength);
|
|
99
|
+
const cipher = crypto.createCipheriv('aes-256-gcm', this.key, iv);
|
|
100
|
+
|
|
101
|
+
// Encrypt the data
|
|
102
|
+
const encryptedData = Buffer.concat([cipher.update(data), cipher.final()]);
|
|
103
|
+
|
|
104
|
+
// Concatenate iv, encrypted data, and authentication tag into a single Buffer
|
|
105
|
+
const outputData = Buffer.concat([iv, encryptedData, cipher.getAuthTag()]);
|
|
106
|
+
|
|
107
|
+
// Return the data encoded as base64 if input was a string, else return as Buffer
|
|
108
|
+
return isBuffer ? outputData : outputData.toString('base64');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
decrypt(data: string): string;
|
|
112
|
+
decrypt(data: Buffer): Buffer;
|
|
113
|
+
decrypt(data: string | Buffer): string | Buffer {
|
|
114
|
+
// Check if the input is a Buffer
|
|
115
|
+
const isBuffer = Buffer.isBuffer(data);
|
|
116
|
+
|
|
117
|
+
// Convert to Buffer if it's a string
|
|
118
|
+
const dataBuf = isBuffer ? data : Buffer.from(data, 'base64');
|
|
119
|
+
|
|
120
|
+
// Split the input into iv, encrypted data, and authentication tag
|
|
121
|
+
const iv = dataBuf.subarray(0, this.ivLength);
|
|
122
|
+
const authTag = dataBuf.subarray(dataBuf.length - 16);
|
|
123
|
+
const encryptedData = dataBuf.subarray(this.ivLength, dataBuf.length - 16);
|
|
124
|
+
|
|
125
|
+
// Decrypt the data
|
|
126
|
+
const decipher = crypto.createDecipheriv('aes-256-gcm', this.key, iv);
|
|
127
|
+
decipher.setAuthTag(authTag);
|
|
128
|
+
const decryptedData = Buffer.concat([decipher.update(encryptedData), decipher.final()]);
|
|
129
|
+
|
|
130
|
+
// Return the decrypted data as a string if the input was a string, else return as Buffer
|
|
131
|
+
return isBuffer ? decryptedData : decryptedData.toString('utf8');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { HttpBadRequestError } from '@deepkit/http';
|
|
2
|
+
import { ReceiveType, validate, ValidationError } from '@deepkit/type';
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
export function validateOrThrow<T>(data: any, type?: ReceiveType<T>): data is T {
|
|
6
|
+
const errors = validate<T>(data, type);
|
|
7
|
+
if (errors.length) throw new ValidationError(errors);
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
export function assertInput(value: any, field?: string): asserts value {
|
|
13
|
+
if (value === undefined || value === null) {
|
|
14
|
+
throw new HttpBadRequestError(field ? `${field} is required` : 'missing parameters');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { format } from 'date-fns';
|
|
2
|
+
|
|
3
|
+
export function extractDate(date: Date): string {
|
|
4
|
+
return format(date, 'yyyy-MM-dd');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function sleepMs(ms: number) {
|
|
8
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function sleepSecs(secs: number) {
|
|
12
|
+
return sleepMs(secs * 1000);
|
|
13
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { LoggerLevel } from '@deepkit/logger';
|
|
2
|
+
import * as Sentry from '@sentry/node';
|
|
3
|
+
import { compact, omit, pick } from 'lodash';
|
|
4
|
+
import { isNativeError } from 'util/types';
|
|
5
|
+
|
|
6
|
+
import { getAppConfig } from '../../app/resolver';
|
|
7
|
+
import { getTraceContext } from '../../telemetry';
|
|
8
|
+
import { isSentryInstalled } from '../../telemetry/sentry';
|
|
9
|
+
import { ArrowFunctionNoArgs, VoidFunction } from '../../types';
|
|
10
|
+
|
|
11
|
+
export const SentryLiftKeysToTagsFromLoggerContext = [];
|
|
12
|
+
|
|
13
|
+
export interface DecoratedError extends Error {
|
|
14
|
+
cause?: Error;
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
context?: Record<string, any>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
export function isError(e: any): e is Error {
|
|
21
|
+
return e instanceof Error || isNativeError(e);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
export function getErrorMessage(e: any): string {
|
|
26
|
+
return isError(e) ? e.message : String(e);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
export function toError(e: any, cause?: any): Error {
|
|
31
|
+
const baseError = isError(e) ? e : new Error(String(e));
|
|
32
|
+
if (cause) {
|
|
33
|
+
(baseError as DecoratedError).cause = toError(cause);
|
|
34
|
+
}
|
|
35
|
+
return baseError;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function tryOrErrorSync<T extends ArrowFunctionNoArgs>(fn: T): ReturnType<T> | Error {
|
|
39
|
+
try {
|
|
40
|
+
return fn();
|
|
41
|
+
} catch (e) {
|
|
42
|
+
return toError(e);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function tryOrError<T extends ArrowFunctionNoArgs>(fn: T): Promise<ReturnType<T> | Error> {
|
|
47
|
+
try {
|
|
48
|
+
return await fn();
|
|
49
|
+
} catch (e) {
|
|
50
|
+
return toError(e);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
+
export function tryWithReject<T extends (reject: VoidFunction) => Promise<any>>(fn: T): Promise<ReturnType<T>> {
|
|
56
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
57
|
+
return new Promise(async (resolve, reject) => {
|
|
58
|
+
try {
|
|
59
|
+
resolve(await fn(reject));
|
|
60
|
+
} catch (e) {
|
|
61
|
+
reject(e);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface IErrorContext {
|
|
67
|
+
scope?: string;
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
+
scopeData?: Record<string, any>;
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
+
loggerContext?: Record<string, any>;
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
+
data?: Record<string, any>;
|
|
74
|
+
}
|
|
75
|
+
const errorHandlerState: { reporter?: (level: LoggerLevel, err: Error, context: IErrorContext) => void } = {};
|
|
76
|
+
export function setGlobalErrorReporter(reporter: (label: LoggerLevel, err: Error, context: IErrorContext) => void) {
|
|
77
|
+
errorHandlerState.reporter = reporter;
|
|
78
|
+
}
|
|
79
|
+
export function reportError(level: LoggerLevel, err: Error, context: IErrorContext) {
|
|
80
|
+
if (errorHandlerState.reporter) {
|
|
81
|
+
errorHandlerState.reporter(level, err, context);
|
|
82
|
+
}
|
|
83
|
+
if (isSentryInstalled()) {
|
|
84
|
+
const tags = context.loggerContext ? pick(context.loggerContext, SentryLiftKeysToTagsFromLoggerContext) : {};
|
|
85
|
+
const Details = {
|
|
86
|
+
...context,
|
|
87
|
+
loggerContext: omit(context.loggerContext, SentryLiftKeysToTagsFromLoggerContext)
|
|
88
|
+
};
|
|
89
|
+
Sentry.captureException(err, {
|
|
90
|
+
tags,
|
|
91
|
+
extra: { Details },
|
|
92
|
+
level: level === LoggerLevel.alert ? 'fatal' : level === LoggerLevel.warning ? 'warning' : 'error'
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (level === LoggerLevel.alert) {
|
|
96
|
+
sendSlackAlertNotification(err, context);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function sendSlackAlertNotification(err: DecoratedError, context: IErrorContext) {
|
|
101
|
+
try {
|
|
102
|
+
const traceContext = getTraceContext();
|
|
103
|
+
const url = getAppConfig().ALERTS_SLACK_WEBHOOK_URL;
|
|
104
|
+
if (!url) return;
|
|
105
|
+
|
|
106
|
+
await fetch(url, {
|
|
107
|
+
method: 'POST',
|
|
108
|
+
headers: {
|
|
109
|
+
'Content-Type': 'application/json'
|
|
110
|
+
},
|
|
111
|
+
body: JSON.stringify({
|
|
112
|
+
text: compact([`:rotating_light: *${err.message}*`, err.cause && `cause: ${err.cause.message}`]).join('\n'),
|
|
113
|
+
attachments: [
|
|
114
|
+
{
|
|
115
|
+
color: 'danger',
|
|
116
|
+
fields: compact([
|
|
117
|
+
context.scope && {
|
|
118
|
+
title: 'Scope',
|
|
119
|
+
value: context.scope,
|
|
120
|
+
short: true
|
|
121
|
+
},
|
|
122
|
+
traceContext && {
|
|
123
|
+
title: 'Trace ID',
|
|
124
|
+
value: traceContext.traceId,
|
|
125
|
+
short: true
|
|
126
|
+
},
|
|
127
|
+
context.data && {
|
|
128
|
+
title: 'Alert Data',
|
|
129
|
+
value: JSON.stringify(context.data, null, 2),
|
|
130
|
+
short: false
|
|
131
|
+
},
|
|
132
|
+
err.context && {
|
|
133
|
+
title: 'Error Context',
|
|
134
|
+
value: JSON.stringify(err.context, null, 2),
|
|
135
|
+
short: false
|
|
136
|
+
},
|
|
137
|
+
context.scopeData && {
|
|
138
|
+
title: 'Scope Data',
|
|
139
|
+
value: JSON.stringify(context.scopeData, null, 2),
|
|
140
|
+
short: false
|
|
141
|
+
},
|
|
142
|
+
context.loggerContext && {
|
|
143
|
+
title: 'Logger Context',
|
|
144
|
+
value: JSON.stringify(context.loggerContext, null, 2),
|
|
145
|
+
short: false
|
|
146
|
+
}
|
|
147
|
+
])
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
})
|
|
151
|
+
});
|
|
152
|
+
} catch (err) {
|
|
153
|
+
console.error('Failed to send slack alert notification', err);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InjectorContext } from '@deepkit/injector';
|
|
2
|
+
import { ElementStruct, render } from '@deepkit/template';
|
|
3
|
+
|
|
4
|
+
import { resolve } from '../../app/resolver';
|
|
5
|
+
|
|
6
|
+
export async function jsxToHtml(jsx: ElementStruct) {
|
|
7
|
+
return render(resolve(InjectorContext).getRootInjector(), jsx) as Promise<string>;
|
|
8
|
+
}
|
package/src/http/auth.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { timingSafeEqual } from 'crypto';
|
|
2
|
+
import { HttpRequest, HttpUnauthorizedError, RouteParameterResolver, RouteParameterResolverContext } from '@deepkit/http';
|
|
3
|
+
import { ScopedLogger } from '@deepkit/logger';
|
|
4
|
+
import { ActiveRecordClassType } from '@deepkit/orm';
|
|
5
|
+
|
|
6
|
+
// can't import app here or bad things happen!!
|
|
7
|
+
import type { BaseAppConfig } from '../app';
|
|
8
|
+
import { JWT, ParsedJwt } from '../auth';
|
|
9
|
+
import { getEntity, getEntityOrUndefined } from '../database';
|
|
10
|
+
import { HttpMiddleware } from './middleware';
|
|
11
|
+
import { createCachingParameterResolver, getCompositeCacheKey, getOrCacheValue } from './store';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* base request JWT lookup
|
|
15
|
+
*/
|
|
16
|
+
export async function getJwtFromRequest(request: HttpRequest): Promise<ParsedJwt | undefined> {
|
|
17
|
+
return getOrCacheValue(request, ParsedJwt, _getJwtFromRequest);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function _getJwtFromRequest(request: HttpRequest): Promise<ParsedJwt | undefined> {
|
|
21
|
+
const jwt = await JWT.processWithRequest(request);
|
|
22
|
+
if (!jwt) return undefined;
|
|
23
|
+
if (!jwt.isValid) {
|
|
24
|
+
if (!jwt.isSignatureValid) throw new HttpUnauthorizedError('Invalid JWT signature');
|
|
25
|
+
if (!jwt.isNotExpired) throw new HttpUnauthorizedError('Expired JWT');
|
|
26
|
+
throw new HttpUnauthorizedError('Invalid JWT');
|
|
27
|
+
}
|
|
28
|
+
return jwt;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class ParsedJwtResolver implements RouteParameterResolver {
|
|
32
|
+
async resolve(context: RouteParameterResolverContext): Promise<ParsedJwt | undefined> {
|
|
33
|
+
const jwt = await getJwtFromRequest(context.request);
|
|
34
|
+
if (!jwt && !context.type.isOptional()) {
|
|
35
|
+
throw new HttpUnauthorizedError('Request does not contain required JWT');
|
|
36
|
+
}
|
|
37
|
+
return jwt;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* base request JWT user ID lookup
|
|
43
|
+
*/
|
|
44
|
+
const EntityIdSymbol = Symbol('EntityId');
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
export async function getEntityIdFromRequestJwt(request: HttpRequest): Promise<any> {
|
|
47
|
+
const jwt = await getJwtFromRequest(request);
|
|
48
|
+
return jwt?.subject;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* request JWT user ID to user object
|
|
53
|
+
*/
|
|
54
|
+
export async function getEntityFromRequestJwt<T extends ActiveRecordClassType>(
|
|
55
|
+
request: HttpRequest,
|
|
56
|
+
EntityClass: T
|
|
57
|
+
): Promise<InstanceType<T> | undefined> {
|
|
58
|
+
const entityId = await getEntityIdFromRequestJwt(request);
|
|
59
|
+
return entityId ? getEntity(EntityClass, entityId) : undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* auth middleware generator
|
|
64
|
+
*/
|
|
65
|
+
interface EntityValidator<T extends ActiveRecordClassType> {
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
+
getEntityIdFromRequest(request: HttpRequest): Promise<any>;
|
|
68
|
+
validateEntity?(request: HttpRequest, entity: InstanceType<T>): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
export function createAuthMiddleware<T extends ActiveRecordClassType>(EntityClass: T) {
|
|
71
|
+
return class extends HttpMiddleware implements EntityValidator<T> {
|
|
72
|
+
async handle(request: HttpRequest) {
|
|
73
|
+
const entityId = await getOrCacheValue(
|
|
74
|
+
request,
|
|
75
|
+
getCompositeCacheKey(EntityClass, EntityIdSymbol),
|
|
76
|
+
this.getEntityIdFromRequest.bind(this)
|
|
77
|
+
);
|
|
78
|
+
await this.loadAndValidateEntity(request, entityId);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async getEntityIdFromRequest(request: HttpRequest) {
|
|
82
|
+
const id = await getEntityIdFromRequestJwt(request);
|
|
83
|
+
if (!id) throw new HttpUnauthorizedError();
|
|
84
|
+
return id;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
+
async loadAndValidateEntity(request: HttpRequest, id: any) {
|
|
89
|
+
const validateFn = (this as EntityValidator<T>).validateEntity;
|
|
90
|
+
if (validateFn) {
|
|
91
|
+
const entity = await getOrCacheValue(request, EntityClass, () => getEntityOrUndefined(EntityClass, id));
|
|
92
|
+
if (!entity) throw new HttpUnauthorizedError();
|
|
93
|
+
await validateFn(request, entity);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* HTTP basic auth middleware
|
|
101
|
+
*/
|
|
102
|
+
export function createBasicAuthMiddleware(expectedUsername?: string) {
|
|
103
|
+
return class extends HttpMiddleware {
|
|
104
|
+
public config: BaseAppConfig;
|
|
105
|
+
|
|
106
|
+
constructor(public logger: ScopedLogger) {
|
|
107
|
+
super();
|
|
108
|
+
|
|
109
|
+
// todo:figure this out
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
111
|
+
this.config = require('../app').getAppConfig();
|
|
112
|
+
if (!this.config.AUTH_BASIC_SECRET) {
|
|
113
|
+
this.logger.error('No AUTH_BASIC_SECRET provided');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async handle(request: HttpRequest) {
|
|
118
|
+
const authHeader = request.headers['authorization'];
|
|
119
|
+
if (!authHeader) {
|
|
120
|
+
throw new HttpUnauthorizedError();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const [scheme, credentials] = authHeader.split(' ');
|
|
124
|
+
if (scheme.toLowerCase() !== 'basic') {
|
|
125
|
+
throw new HttpUnauthorizedError('Invalid authorization scheme');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const [username, password] = Buffer.from(credentials, 'base64').toString().split(':');
|
|
129
|
+
const secret = this.config.AUTH_BASIC_SECRET ?? '';
|
|
130
|
+
const usernameInvalid = expectedUsername && expectedUsername !== username;
|
|
131
|
+
const passwordBuf = Buffer.from(password);
|
|
132
|
+
const secretBuf = Buffer.from(secret);
|
|
133
|
+
const passwordInvalid = passwordBuf.length !== secretBuf.length || !timingSafeEqual(passwordBuf, secretBuf);
|
|
134
|
+
if (usernameInvalid || passwordInvalid) {
|
|
135
|
+
throw new HttpUnauthorizedError('Invalid credentials');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* standard authed entity resolver
|
|
143
|
+
*/
|
|
144
|
+
export async function resolveEntityFromRequestJwt<T extends ActiveRecordClassType>(context: RouteParameterResolverContext, EntityClass: T) {
|
|
145
|
+
const ent = await getEntityFromRequestJwt(context.request, EntityClass);
|
|
146
|
+
if (!ent && !context.type.isOptional()) {
|
|
147
|
+
throw new HttpUnauthorizedError();
|
|
148
|
+
}
|
|
149
|
+
return ent;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function createEntityFromRequestJwtParameterResolver<T extends ActiveRecordClassType>(EntityClass: T) {
|
|
153
|
+
return createCachingParameterResolver(EntityClass, async (context: RouteParameterResolverContext) => {
|
|
154
|
+
return resolveEntityFromRequestJwt(context, EntityClass);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HttpRequest } from '@deepkit/http';
|
|
2
|
+
import { uuid } from '@deepkit/type';
|
|
3
|
+
|
|
4
|
+
export const DefaultHttpContextProvider: (request: HttpRequest) => Record<string, string> = () => ({
|
|
5
|
+
reqId: uuid()
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
let httpContextProvider: (request: HttpRequest) => Record<string, string> = DefaultHttpContextProvider;
|
|
9
|
+
export function setHttpContextResolver(provider: (request: HttpRequest) => Record<string, string>) {
|
|
10
|
+
httpContextProvider = provider;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getHttpContextResolver() {
|
|
14
|
+
return httpContextProvider;
|
|
15
|
+
}
|