@aurostack/stacks 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +209 -0
- package/cli/src/extract.mjs +165 -0
- package/cli/src/fsx.mjs +197 -0
- package/cli/src/generate.mjs +235 -0
- package/cli/src/hooks.mjs +55 -0
- package/cli/src/manifest.mjs +163 -0
- package/cli/src/strip.mjs +208 -0
- package/cli/src/tokens.mjs +102 -0
- package/cli/stack.mjs +672 -0
- package/package.json +37 -0
- package/templates/nest-api/files/.bin/db.ts +123 -0
- package/templates/nest-api/files/.bin/dc.ts +74 -0
- package/templates/nest-api/files/.bin/helpers.ts +49 -0
- package/templates/nest-api/files/.bin/secrets.ts +68 -0
- package/templates/nest-api/files/.bin/start.ts +47 -0
- package/templates/nest-api/files/.dockerignore +7 -0
- package/templates/nest-api/files/.env.example +91 -0
- package/templates/nest-api/files/.env.test.example +75 -0
- package/templates/nest-api/files/.forgejo/workflows/build-and-push.yml +41 -0
- package/templates/nest-api/files/.forgejo/workflows/test-e2e.yml +83 -0
- package/templates/nest-api/files/.forgejo/workflows/test.yml +53 -0
- package/templates/nest-api/files/.npmrc.example +1 -0
- package/templates/nest-api/files/.nvmrc +1 -0
- package/templates/nest-api/files/.prettierrc +8 -0
- package/templates/nest-api/files/.swcrc +15 -0
- package/templates/nest-api/files/.watchmanconfig +3 -0
- package/templates/nest-api/files/.yarnrc.yml +1 -0
- package/templates/nest-api/files/Dockerfile +40 -0
- package/templates/nest-api/files/__mocks__/activation-twofa.js +7 -0
- package/templates/nest-api/files/__mocks__/activation.js +7 -0
- package/templates/nest-api/files/__mocks__/forgot-password.js +7 -0
- package/templates/nest-api/files/__mocks__/main-layout.js +7 -0
- package/templates/nest-api/files/__mocks__/password-changed.js +7 -0
- package/templates/nest-api/files/__mocks__/reset-password.js +7 -0
- package/templates/nest-api/files/__mocks__/set-password.js +7 -0
- package/templates/nest-api/files/__mocks__/welcome.js +7 -0
- package/templates/nest-api/files/_gitignore +62 -0
- package/templates/nest-api/files/compose.test.yml +33 -0
- package/templates/nest-api/files/compose.yml +39 -0
- package/templates/nest-api/files/emails/activation-twofa.tsx +58 -0
- package/templates/nest-api/files/emails/activation.tsx +36 -0
- package/templates/nest-api/files/emails/forgot-password.tsx +29 -0
- package/templates/nest-api/files/emails/main-layout.tsx +134 -0
- package/templates/nest-api/files/emails/password-changed.tsx +24 -0
- package/templates/nest-api/files/emails/reset-password.tsx +24 -0
- package/templates/nest-api/files/emails/set-password.tsx +25 -0
- package/templates/nest-api/files/emails/welcome.tsx +39 -0
- package/templates/nest-api/files/eslint.config.mjs +28 -0
- package/templates/nest-api/files/global.d.ts +5 -0
- package/templates/nest-api/files/nest-cli.json +8 -0
- package/templates/nest-api/files/package.json +150 -0
- package/templates/nest-api/files/prisma/schema/auth.prisma +75 -0
- package/templates/nest-api/files/prisma/schema/base.prisma +17 -0
- package/templates/nest-api/files/prisma/schema/enum.prisma +17 -0
- package/templates/nest-api/files/prisma/schema/notification.prisma +14 -0
- package/templates/nest-api/files/prisma.config.ts +13 -0
- package/templates/nest-api/files/public/.gitkeep +0 -0
- package/templates/nest-api/files/seeders/index.ts +27 -0
- package/templates/nest-api/files/seeders/util.ts +88 -0
- package/templates/nest-api/files/src/__tests__/app.controller.spec.ts +29 -0
- package/templates/nest-api/files/src/app.controller.ts +40 -0
- package/templates/nest-api/files/src/app.module.ts +268 -0
- package/templates/nest-api/files/src/app.resolver.ts +32 -0
- package/templates/nest-api/files/src/app.setup.ts +178 -0
- package/templates/nest-api/files/src/common/__tests__/auth.service.spec.ts +31 -0
- package/templates/nest-api/files/src/common/__tests__/cache.service.spec.ts +214 -0
- package/templates/nest-api/files/src/common/__tests__/config.service.spec.ts +56 -0
- package/templates/nest-api/files/src/common/__tests__/generator.service.spec.ts +114 -0
- package/templates/nest-api/files/src/common/__tests__/health.controller.spec.ts +72 -0
- package/templates/nest-api/files/src/common/__tests__/helpers.spec.ts +124 -0
- package/templates/nest-api/files/src/common/__tests__/mail.service.spec.ts +75 -0
- package/templates/nest-api/files/src/common/__tests__/prisma.indicator.spec.ts +39 -0
- package/templates/nest-api/files/src/common/__tests__/prisma.service.spec.ts +15 -0
- package/templates/nest-api/files/src/common/__tests__/records.spec.ts +87 -0
- package/templates/nest-api/files/src/common/__tests__/schemas.spec.ts +142 -0
- package/templates/nest-api/files/src/common/__tests__/throttler-storage.service.spec.ts +80 -0
- package/templates/nest-api/files/src/common/common.module.ts +72 -0
- package/templates/nest-api/files/src/common/constants/index.ts +2 -0
- package/templates/nest-api/files/src/common/constants/options.ts +52 -0
- package/templates/nest-api/files/src/common/constants/pino.ts +24 -0
- package/templates/nest-api/files/src/common/controllers/health.controller.ts +54 -0
- package/templates/nest-api/files/src/common/controllers/index.ts +2 -0
- package/templates/nest-api/files/src/common/controllers/metrics.controller.ts +21 -0
- package/templates/nest-api/files/src/common/decorators/index.ts +2 -0
- package/templates/nest-api/files/src/common/decorators/misc.decorator.ts +49 -0
- package/templates/nest-api/files/src/common/decorators/multi-part.decorator.ts +6 -0
- package/templates/nest-api/files/src/common/dto/filters.dto.ts +25 -0
- package/templates/nest-api/files/src/common/dto/index.ts +1 -0
- package/templates/nest-api/files/src/common/entity/index.ts +2 -0
- package/templates/nest-api/files/src/common/entity/ok.entity.ts +11 -0
- package/templates/nest-api/files/src/common/entity/pagination.entity.ts +24 -0
- package/templates/nest-api/files/src/common/exceptions/index.ts +1 -0
- package/templates/nest-api/files/src/common/exceptions/prisma.exception.ts +57 -0
- package/templates/nest-api/files/src/common/guards/feature-flag.guard.ts +51 -0
- package/templates/nest-api/files/src/common/guards/index.ts +1 -0
- package/templates/nest-api/files/src/common/interceptors/index.ts +1 -0
- package/templates/nest-api/files/src/common/interceptors/metrics.interceptor.ts +37 -0
- package/templates/nest-api/files/src/common/misc/helpers.ts +26 -0
- package/templates/nest-api/files/src/common/misc/index.ts +3 -0
- package/templates/nest-api/files/src/common/misc/origin-builder.ts +56 -0
- package/templates/nest-api/files/src/common/misc/prisma.indicator.ts +24 -0
- package/templates/nest-api/files/src/common/modules/index.ts +3 -0
- package/templates/nest-api/files/src/common/modules/logger.module.ts +104 -0
- package/templates/nest-api/files/src/common/modules/metrics.module.ts +28 -0
- package/templates/nest-api/files/src/common/modules/queue.module.ts +23 -0
- package/templates/nest-api/files/src/common/processors/index.ts +1 -0
- package/templates/nest-api/files/src/common/processors/mail/index.ts +47 -0
- package/templates/nest-api/files/src/common/processors/mail/process.ts +225 -0
- package/templates/nest-api/files/src/common/schemas/fields.ts +76 -0
- package/templates/nest-api/files/src/common/schemas/index.ts +1 -0
- package/templates/nest-api/files/src/common/services/auth-rate-limit.storage.ts +79 -0
- package/templates/nest-api/files/src/common/services/auth.service.ts +16 -0
- package/templates/nest-api/files/src/common/services/cache.service.ts +118 -0
- package/templates/nest-api/files/src/common/services/config.service.ts +388 -0
- package/templates/nest-api/files/src/common/services/feature-flag.service.ts +117 -0
- package/templates/nest-api/files/src/common/services/generator.service.ts +54 -0
- package/templates/nest-api/files/src/common/services/index.ts +10 -0
- package/templates/nest-api/files/src/common/services/logger.service.ts +14 -0
- package/templates/nest-api/files/src/common/services/mail.service.ts +44 -0
- package/templates/nest-api/files/src/common/services/prisma.service.ts +106 -0
- package/templates/nest-api/files/src/common/services/throttler-storage.service.ts +112 -0
- package/templates/nest-api/files/src/common/types/email.ts +55 -0
- package/templates/nest-api/files/src/common/types/index.ts +3 -0
- package/templates/nest-api/files/src/common/types/misc.ts +20 -0
- package/templates/nest-api/files/src/common/types/prisma.ts +18 -0
- package/templates/nest-api/files/src/common/utils/enum.ts +39 -0
- package/templates/nest-api/files/src/common/utils/helpers.ts +139 -0
- package/templates/nest-api/files/src/common/utils/index.ts +5 -0
- package/templates/nest-api/files/src/common/utils/ip.ts +22 -0
- package/templates/nest-api/files/src/common/utils/records.ts +66 -0
- package/templates/nest-api/files/src/common/utils/redis.keys.ts +31 -0
- package/templates/nest-api/files/src/lib/__tests__/access.spec.ts +33 -0
- package/templates/nest-api/files/src/lib/access.ts +114 -0
- package/templates/nest-api/files/src/lib/auth.ts +76 -0
- package/templates/nest-api/files/src/lib/rate-limit.ts +20 -0
- package/templates/nest-api/files/src/main.ts +28 -0
- package/templates/nest-api/files/src/media/__tests__/media.service.spec.ts +60 -0
- package/templates/nest-api/files/src/media/__tests__/s3.service.spec.ts +159 -0
- package/templates/nest-api/files/src/media/entity/file.entity.ts +7 -0
- package/templates/nest-api/files/src/media/entity/index.ts +1 -0
- package/templates/nest-api/files/src/media/media.module.ts +20 -0
- package/templates/nest-api/files/src/media/processors/index.ts +44 -0
- package/templates/nest-api/files/src/media/services/index.ts +2 -0
- package/templates/nest-api/files/src/media/services/media.service.ts +29 -0
- package/templates/nest-api/files/src/media/services/s3.service.ts +168 -0
- package/templates/nest-api/files/src/notifications/controllers/index.ts +1 -0
- package/templates/nest-api/files/src/notifications/controllers/notifications.controller.ts +72 -0
- package/templates/nest-api/files/src/notifications/dto/index.ts +1 -0
- package/templates/nest-api/files/src/notifications/dto/notification.dto.ts +11 -0
- package/templates/nest-api/files/src/notifications/entity/index.ts +1 -0
- package/templates/nest-api/files/src/notifications/entity/notification.entity.ts +37 -0
- package/templates/nest-api/files/src/notifications/notifications.module.ts +11 -0
- package/templates/nest-api/files/src/notifications/services/index.ts +1 -0
- package/templates/nest-api/files/src/notifications/services/notifications.service.ts +98 -0
- package/templates/nest-api/files/src/realtime/__tests__/events.gateway.spec.ts +88 -0
- package/templates/nest-api/files/src/realtime/__tests__/rooms.spec.ts +29 -0
- package/templates/nest-api/files/src/realtime/__tests__/ws-permissions.guard.spec.ts +54 -0
- package/templates/nest-api/files/src/realtime/adapters/redis-io.adapter.ts +57 -0
- package/templates/nest-api/files/src/realtime/constants/index.ts +68 -0
- package/templates/nest-api/files/src/realtime/decorators/index.ts +1 -0
- package/templates/nest-api/files/src/realtime/decorators/ws-permissions.decorator.ts +14 -0
- package/templates/nest-api/files/src/realtime/gateways/events.gateway.ts +187 -0
- package/templates/nest-api/files/src/realtime/guards/index.ts +2 -0
- package/templates/nest-api/files/src/realtime/guards/ws-auth.guard.ts +20 -0
- package/templates/nest-api/files/src/realtime/guards/ws-permissions.guard.ts +35 -0
- package/templates/nest-api/files/src/realtime/misc/session-from-socket.ts +54 -0
- package/templates/nest-api/files/src/realtime/realtime.module.ts +26 -0
- package/templates/nest-api/files/src/realtime/services/presence.service.ts +56 -0
- package/templates/nest-api/files/src/realtime/services/realtime.service.ts +72 -0
- package/templates/nest-api/files/src/users/__tests__/current-user.controller.spec.ts +77 -0
- package/templates/nest-api/files/src/users/__tests__/current-user.service.spec.ts +159 -0
- package/templates/nest-api/files/src/users/__tests__/user.entity.spec.ts +175 -0
- package/templates/nest-api/files/src/users/__tests__/users.controller.spec.ts +89 -0
- package/templates/nest-api/files/src/users/__tests__/users.service.spec.ts +398 -0
- package/templates/nest-api/files/src/users/controllers/current-user.controller.ts +82 -0
- package/templates/nest-api/files/src/users/controllers/index.ts +2 -0
- package/templates/nest-api/files/src/users/controllers/users.controller.ts +40 -0
- package/templates/nest-api/files/src/users/decorators/index.ts +1 -0
- package/templates/nest-api/files/src/users/decorators/permissions.decorator.ts +24 -0
- package/templates/nest-api/files/src/users/dto/avatar.dto.ts +13 -0
- package/templates/nest-api/files/src/users/dto/filters.dto.ts +8 -0
- package/templates/nest-api/files/src/users/dto/index.ts +2 -0
- package/templates/nest-api/files/src/users/entity/index.ts +1 -0
- package/templates/nest-api/files/src/users/entity/user.entity.ts +53 -0
- package/templates/nest-api/files/src/users/services/current-user.service.ts +46 -0
- package/templates/nest-api/files/src/users/services/index.ts +2 -0
- package/templates/nest-api/files/src/users/services/users.service.ts +88 -0
- package/templates/nest-api/files/src/users/users.module.ts +10 -0
- package/templates/nest-api/files/test/app.spec.ts +102 -0
- package/templates/nest-api/files/test/auth.spec.ts +108 -0
- package/templates/nest-api/files/test/current-user.spec.ts +154 -0
- package/templates/nest-api/files/test/factory/app.ts +172 -0
- package/templates/nest-api/files/test/factory/constants.ts +22 -0
- package/templates/nest-api/files/test/factory/dto.ts +27 -0
- package/templates/nest-api/files/test/factory/entity.ts +70 -0
- package/templates/nest-api/files/test/factory/gen.ts +75 -0
- package/templates/nest-api/files/test/factory/util.ts +21 -0
- package/templates/nest-api/files/test/notifications.spec.ts +176 -0
- package/templates/nest-api/files/test/rate-limit.spec.ts +180 -0
- package/templates/nest-api/files/test/setup.ts +1 -0
- package/templates/nest-api/files/test/users.spec.ts +437 -0
- package/templates/nest-api/files/tsconfig.build.json +13 -0
- package/templates/nest-api/files/tsconfig.json +35 -0
- package/templates/nest-api/files/vitest.config.ts +53 -0
- package/templates/nest-api/template.json +452 -0
- package/templates/node-worker/files/.bin/db.ts +123 -0
- package/templates/node-worker/files/.bin/helpers.ts +49 -0
- package/templates/node-worker/files/.bin/secrets.ts +68 -0
- package/templates/node-worker/files/.dockerignore +5 -0
- package/templates/node-worker/files/.env.example +21 -0
- package/templates/node-worker/files/.forgejo/workflows/build-and-push.yml +41 -0
- package/templates/node-worker/files/.nvmrc +1 -0
- package/templates/node-worker/files/.prettierignore +4 -0
- package/templates/node-worker/files/.prettierrc +8 -0
- package/templates/node-worker/files/.yarnrc.yml +5 -0
- package/templates/node-worker/files/Dockerfile +63 -0
- package/templates/node-worker/files/Dockerfile.dev +59 -0
- package/templates/node-worker/files/_gitignore +48 -0
- package/templates/node-worker/files/ecosystem.config.cjs +10 -0
- package/templates/node-worker/files/eslint.config.js +37 -0
- package/templates/node-worker/files/package.json +67 -0
- package/templates/node-worker/files/prisma/_gitignore +1 -0
- package/templates/node-worker/files/prisma/schema/base.prisma +36 -0
- package/templates/node-worker/files/prisma.config.ts +13 -0
- package/templates/node-worker/files/src/config.ts +55 -0
- package/templates/node-worker/files/src/db.ts +118 -0
- package/templates/node-worker/files/src/index.ts +7 -0
- package/templates/node-worker/files/src/logger.ts +45 -0
- package/templates/node-worker/files/src/types.ts +23 -0
- package/templates/node-worker/files/src/utils/browser.ts +16 -0
- package/templates/node-worker/files/src/utils/date.ts +68 -0
- package/templates/node-worker/files/src/utils/helpers.ts +17 -0
- package/templates/node-worker/files/src/utils/number.ts +47 -0
- package/templates/node-worker/files/src/utils/worker.ts +29 -0
- package/templates/node-worker/files/src/workers/constants.ts +6 -0
- package/templates/node-worker/files/src/workers/example/index.ts +27 -0
- package/templates/node-worker/files/src/workers/index.ts +1 -0
- package/templates/node-worker/files/tsconfig.json +30 -0
- package/templates/node-worker/template.json +135 -0
- package/templates/py-worker/files/.dockerignore +176 -0
- package/templates/py-worker/files/.env.example +20 -0
- package/templates/py-worker/files/.forgejo/workflows/build-amd-push.yml +39 -0
- package/templates/py-worker/files/Dockerfile +10 -0
- package/templates/py-worker/files/README.md +3 -0
- package/templates/py-worker/files/_gitignore +176 -0
- package/templates/py-worker/files/config.py +89 -0
- package/templates/py-worker/files/models/decorators.py +42 -0
- package/templates/py-worker/files/models/enums.py +32 -0
- package/templates/py-worker/files/models/mixins.py +61 -0
- package/templates/py-worker/files/requirements.txt +18 -0
- package/templates/py-worker/files/utils/db.py +67 -0
- package/templates/py-worker/files/utils/logger.py +97 -0
- package/templates/py-worker/files/utils/misc.py +45 -0
- package/templates/py-worker/files/utils/worker.py +80 -0
- package/templates/py-worker/files/worker.py +41 -0
- package/templates/py-worker/files/workers/hello/process.py +22 -0
- package/templates/py-worker/template.json +87 -0
- package/templates/react-app/README.md +78 -0
- package/templates/react-app/derive.sh +128 -0
- package/templates/react-app/files/.bin/openapi.js +32 -0
- package/templates/react-app/files/.bin/secrets.js +47 -0
- package/templates/react-app/files/.dockerignore +16 -0
- package/templates/react-app/files/.editorconfig +12 -0
- package/templates/react-app/files/.env.example +34 -0
- package/templates/react-app/files/.forgejo/workflows/build-and-push.yml +55 -0
- package/templates/react-app/files/.forgejo/workflows/ci.yml +39 -0
- package/templates/react-app/files/.husky/pre-commit +1 -0
- package/templates/react-app/files/.nvmrc +1 -0
- package/templates/react-app/files/.prettierignore +6 -0
- package/templates/react-app/files/.prettierrc +9 -0
- package/templates/react-app/files/.yarnrc.yml +2 -0
- package/templates/react-app/files/Dockerfile +52 -0
- package/templates/react-app/files/_gitignore +33 -0
- package/templates/react-app/files/build.sh +53 -0
- package/templates/react-app/files/docker/nginx.conf +134 -0
- package/templates/react-app/files/eslint.config.mjs +75 -0
- package/templates/react-app/files/index.html +62 -0
- package/templates/react-app/files/openapi-ts.config.ts +22 -0
- package/templates/react-app/files/package.json +80 -0
- package/templates/react-app/files/src/app/nav.tsx +32 -0
- package/templates/react-app/files/src/app/providers.tsx +39 -0
- package/templates/react-app/files/src/app/router.tsx +142 -0
- package/templates/react-app/files/src/app/store.ts +20 -0
- package/templates/react-app/files/src/features/auth/components/auth-card.tsx +23 -0
- package/templates/react-app/files/src/features/auth/components/checkbox-field.tsx +32 -0
- package/templates/react-app/files/src/features/auth/components/google-button.tsx +41 -0
- package/templates/react-app/files/src/features/auth/components/or-divider.tsx +9 -0
- package/templates/react-app/files/src/features/auth/components/password-field.tsx +70 -0
- package/templates/react-app/files/src/features/auth/components/submit-button.tsx +16 -0
- package/templates/react-app/files/src/features/auth/lib/auth-actions.ts +68 -0
- package/templates/react-app/files/src/features/auth/lib/password-strength.ts +20 -0
- package/templates/react-app/files/src/features/auth/lib/redirect.ts +6 -0
- package/templates/react-app/files/src/features/auth/lib/schemas.ts +37 -0
- package/templates/react-app/files/src/features/seo/routes.ts +65 -0
- package/templates/react-app/files/src/lib/env.ts +28 -0
- package/templates/react-app/files/src/lib/paths.ts +58 -0
- package/templates/react-app/files/src/main.tsx +19 -0
- package/templates/react-app/files/src/routes/admin/home.tsx +24 -0
- package/templates/react-app/files/src/routes/auth/forgot-password.tsx +93 -0
- package/templates/react-app/files/src/routes/auth/login.tsx +87 -0
- package/templates/react-app/files/src/routes/auth/reset-password.tsx +83 -0
- package/templates/react-app/files/src/routes/auth/signup.tsx +117 -0
- package/templates/react-app/files/src/routes/auth/verified.tsx +31 -0
- package/templates/react-app/files/src/routes/auth/verify-email.tsx +97 -0
- package/templates/react-app/files/src/routes/home.tsx +17 -0
- package/templates/react-app/files/src/routes/legal/privacy.tsx +26 -0
- package/templates/react-app/files/src/routes/legal/terms.tsx +28 -0
- package/templates/react-app/files/src/routes/marketing/home.tsx +18 -0
- package/templates/react-app/files/src/routes/settings.tsx +10 -0
- package/templates/react-app/files/src/shared/api/base-api.ts +24 -0
- package/templates/react-app/files/src/shared/api/base-query.ts +29 -0
- package/templates/react-app/files/src/shared/api/config.ts +21 -0
- package/templates/react-app/files/src/shared/api/index.ts +15 -0
- package/templates/react-app/files/src/shared/api/realtime-events.ts +34 -0
- package/templates/react-app/files/src/shared/api/socket.ts +41 -0
- package/templates/react-app/files/src/shared/api/store.ts +39 -0
- package/templates/react-app/files/src/shared/api/upload-query.ts +115 -0
- package/templates/react-app/files/src/shared/auth/client.ts +27 -0
- package/templates/react-app/files/src/shared/auth/config.ts +28 -0
- package/templates/react-app/files/src/shared/auth/guards.tsx +75 -0
- package/templates/react-app/files/src/shared/auth/hooks.ts +13 -0
- package/templates/react-app/files/src/shared/auth/index.ts +20 -0
- package/templates/react-app/files/src/shared/auth/logout.ts +23 -0
- package/templates/react-app/files/src/shared/auth/provider.tsx +52 -0
- package/templates/react-app/files/src/shared/auth/redirect.ts +65 -0
- package/templates/react-app/files/src/shared/auth/slice.ts +54 -0
- package/templates/react-app/files/src/shared/hooks/index.ts +6 -0
- package/templates/react-app/files/src/shared/layouts/app-shell/app-shell.tsx +225 -0
- package/templates/react-app/files/src/shared/layouts/app-shell/user-menu.tsx +74 -0
- package/templates/react-app/files/src/shared/layouts/auth-layout.tsx +137 -0
- package/templates/react-app/files/src/shared/layouts/error-boundary.tsx +38 -0
- package/templates/react-app/files/src/shared/layouts/index.ts +23 -0
- package/templates/react-app/files/src/shared/layouts/marketing/marketing-layout.tsx +29 -0
- package/templates/react-app/files/src/shared/layouts/marketing/section-heading.tsx +38 -0
- package/templates/react-app/files/src/shared/layouts/marketing/section.tsx +30 -0
- package/templates/react-app/files/src/shared/layouts/states/app-shell-skeleton.tsx +47 -0
- package/templates/react-app/files/src/shared/layouts/states/empty.tsx +22 -0
- package/templates/react-app/files/src/shared/layouts/states/forbidden.tsx +14 -0
- package/templates/react-app/files/src/shared/layouts/states/loading.tsx +11 -0
- package/templates/react-app/files/src/shared/layouts/states/not-found.tsx +21 -0
- package/templates/react-app/files/src/shared/layouts/states/page-skeleton.tsx +39 -0
- package/templates/react-app/files/src/shared/layouts/states/route-fallback.tsx +26 -0
- package/templates/react-app/files/src/shared/layouts/states/state-screen.tsx +22 -0
- package/templates/react-app/files/src/shared/types/README.md +28 -0
- package/templates/react-app/files/src/shared/types/api/index.ts +9 -0
- package/templates/react-app/files/src/shared/types/api/zod.gen.ts +5 -0
- package/templates/react-app/files/src/shared/types/index.ts +4 -0
- package/templates/react-app/files/src/shared/ui/components/brand/logo.tsx +51 -0
- package/templates/react-app/files/src/shared/ui/components/brand/social-icons.tsx +37 -0
- package/templates/react-app/files/src/shared/ui/components/form/form.tsx +120 -0
- package/templates/react-app/files/src/shared/ui/components/ui/alert.tsx +25 -0
- package/templates/react-app/files/src/shared/ui/components/ui/button.tsx +43 -0
- package/templates/react-app/files/src/shared/ui/components/ui/calendar.tsx +78 -0
- package/templates/react-app/files/src/shared/ui/components/ui/card.tsx +44 -0
- package/templates/react-app/files/src/shared/ui/components/ui/checkbox.tsx +16 -0
- package/templates/react-app/files/src/shared/ui/components/ui/date-picker.tsx +76 -0
- package/templates/react-app/files/src/shared/ui/components/ui/input.tsx +22 -0
- package/templates/react-app/files/src/shared/ui/components/ui/label.tsx +19 -0
- package/templates/react-app/files/src/shared/ui/components/ui/modal.tsx +94 -0
- package/templates/react-app/files/src/shared/ui/components/ui/popover.tsx +31 -0
- package/templates/react-app/files/src/shared/ui/components/ui/progress.tsx +33 -0
- package/templates/react-app/files/src/shared/ui/components/ui/search-input.tsx +69 -0
- package/templates/react-app/files/src/shared/ui/components/ui/select.tsx +80 -0
- package/templates/react-app/files/src/shared/ui/components/ui/skeleton.tsx +12 -0
- package/templates/react-app/files/src/shared/ui/components/ui/sonner.tsx +23 -0
- package/templates/react-app/files/src/shared/ui/components/ui/spinner.tsx +8 -0
- package/templates/react-app/files/src/shared/ui/components/ui/textarea.tsx +22 -0
- package/templates/react-app/files/src/shared/ui/index.ts +45 -0
- package/templates/react-app/files/src/shared/ui/lib/utils.ts +7 -0
- package/templates/react-app/files/src/shared/ui/lib/zod-setup.ts +28 -0
- package/templates/react-app/files/src/shared/ui/meta/brand.ts +18 -0
- package/templates/react-app/files/src/shared/ui/meta/meta-context.ts +30 -0
- package/templates/react-app/files/src/shared/ui/meta/meta-provider.tsx +24 -0
- package/templates/react-app/files/src/shared/ui/meta/page-meta.tsx +69 -0
- package/templates/react-app/files/src/shared/ui/meta/use-meta-config.ts +11 -0
- package/templates/react-app/files/src/shared/ui/styles/globals.css +285 -0
- package/templates/react-app/files/src/shared/ui/styles/theme.css +48 -0
- package/templates/react-app/files/src/shared/ui/theme/init-script.ts +23 -0
- package/templates/react-app/files/src/shared/ui/theme/theme-colors.ts +14 -0
- package/templates/react-app/files/src/shared/ui/theme/theme-context.ts +60 -0
- package/templates/react-app/files/src/shared/ui/theme/theme-provider.tsx +101 -0
- package/templates/react-app/files/src/shared/ui/theme/theme-toggle.tsx +40 -0
- package/templates/react-app/files/src/shared/ui/theme/use-theme.ts +11 -0
- package/templates/react-app/files/src/vite-env.d.ts +13 -0
- package/templates/react-app/files/tsconfig.json +26 -0
- package/templates/react-app/files/tsconfig.node.json +25 -0
- package/templates/react-app/files/vite.config.ts +344 -0
- package/templates/react-app/overrides/src/routes/auth/forgot-password.tsx +93 -0
- package/templates/react-app/overrides/src/routes/auth/login.tsx +87 -0
- package/templates/react-app/overrides/src/routes/auth/signup.tsx +117 -0
- package/templates/react-app/overrides/src/routes/auth/verified.tsx +31 -0
- package/templates/react-app/overrides/src/routes/auth/verify-email.tsx +97 -0
- package/templates/react-app/overrides/src/shared/auth/config.ts +28 -0
- package/templates/react-app/overrides/src/shared/auth/guards.tsx +75 -0
- package/templates/react-app/overrides/src/shared/auth/index.ts +20 -0
- package/templates/react-app/overrides/src/shared/auth/redirect.ts +65 -0
- package/templates/react-app/overrides/src/shared/hooks/index.ts +6 -0
- package/templates/react-app/overrides/src/shared/types/README.md +28 -0
- package/templates/react-app/template.json +222 -0
- package/templates/react-monorepo/files/.dockerignore +19 -0
- package/templates/react-monorepo/files/.editorconfig +12 -0
- package/templates/react-monorepo/files/.forgejo/workflows/build-and-push.yml +98 -0
- package/templates/react-monorepo/files/.forgejo/workflows/ci.yml +35 -0
- package/templates/react-monorepo/files/.husky/pre-commit +1 -0
- package/templates/react-monorepo/files/.nvmrc +1 -0
- package/templates/react-monorepo/files/.prettierignore +6 -0
- package/templates/react-monorepo/files/.prettierrc +9 -0
- package/templates/react-monorepo/files/.yarnrc.yml +2 -0
- package/templates/react-monorepo/files/Dockerfile +90 -0
- package/templates/react-monorepo/files/_gitignore +35 -0
- package/templates/react-monorepo/files/apps/admin/.bin/secrets.js +57 -0
- package/templates/react-monorepo/files/apps/admin/.env.example +16 -0
- package/templates/react-monorepo/files/apps/admin/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/apps/admin/index.html +57 -0
- package/templates/react-monorepo/files/apps/admin/package.json +33 -0
- package/templates/react-monorepo/files/apps/admin/src/App.tsx +3 -0
- package/templates/react-monorepo/files/apps/admin/src/app/nav.tsx +14 -0
- package/templates/react-monorepo/files/apps/admin/src/app/providers.tsx +42 -0
- package/templates/react-monorepo/files/apps/admin/src/app/router.tsx +50 -0
- package/templates/react-monorepo/files/apps/admin/src/app/store.ts +15 -0
- package/templates/react-monorepo/files/apps/admin/src/lib/env.ts +12 -0
- package/templates/react-monorepo/files/apps/admin/src/main.tsx +14 -0
- package/templates/react-monorepo/files/apps/admin/src/routes/home.tsx +17 -0
- package/templates/react-monorepo/files/apps/admin/src/routes/settings.tsx +10 -0
- package/templates/react-monorepo/files/apps/admin/src/vite-env.d.ts +14 -0
- package/templates/react-monorepo/files/apps/admin/tsconfig.json +10 -0
- package/templates/react-monorepo/files/apps/admin/vite.config.ts +13 -0
- package/templates/react-monorepo/files/apps/auth/.bin/secrets.js +57 -0
- package/templates/react-monorepo/files/apps/auth/.env.example +16 -0
- package/templates/react-monorepo/files/apps/auth/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/apps/auth/index.html +57 -0
- package/templates/react-monorepo/files/apps/auth/package.json +32 -0
- package/templates/react-monorepo/files/apps/auth/src/App.tsx +3 -0
- package/templates/react-monorepo/files/apps/auth/src/app/providers.tsx +42 -0
- package/templates/react-monorepo/files/apps/auth/src/app/router.tsx +19 -0
- package/templates/react-monorepo/files/apps/auth/src/app/store.ts +15 -0
- package/templates/react-monorepo/files/apps/auth/src/components/auth-card.tsx +23 -0
- package/templates/react-monorepo/files/apps/auth/src/components/checkbox-field.tsx +32 -0
- package/templates/react-monorepo/files/apps/auth/src/components/google-button.tsx +41 -0
- package/templates/react-monorepo/files/apps/auth/src/components/or-divider.tsx +9 -0
- package/templates/react-monorepo/files/apps/auth/src/components/password-field.tsx +70 -0
- package/templates/react-monorepo/files/apps/auth/src/components/submit-button.tsx +16 -0
- package/templates/react-monorepo/files/apps/auth/src/lib/auth-actions.ts +68 -0
- package/templates/react-monorepo/files/apps/auth/src/lib/env.ts +8 -0
- package/templates/react-monorepo/files/apps/auth/src/lib/password-strength.ts +20 -0
- package/templates/react-monorepo/files/apps/auth/src/lib/redirect.ts +6 -0
- package/templates/react-monorepo/files/apps/auth/src/lib/schemas.ts +37 -0
- package/templates/react-monorepo/files/apps/auth/src/main.tsx +14 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/forgot-password.tsx +91 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/login.tsx +82 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/reset-password.tsx +83 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/signup.tsx +117 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/verified.tsx +30 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/verify-email.tsx +96 -0
- package/templates/react-monorepo/files/apps/auth/src/vite-env.d.ts +14 -0
- package/templates/react-monorepo/files/apps/auth/tsconfig.json +10 -0
- package/templates/react-monorepo/files/apps/auth/vite.config.ts +13 -0
- package/templates/react-monorepo/files/apps/client/.bin/secrets.js +57 -0
- package/templates/react-monorepo/files/apps/client/.env.example +16 -0
- package/templates/react-monorepo/files/apps/client/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/apps/client/index.html +57 -0
- package/templates/react-monorepo/files/apps/client/package.json +35 -0
- package/templates/react-monorepo/files/apps/client/src/App.tsx +3 -0
- package/templates/react-monorepo/files/apps/client/src/app/nav.tsx +14 -0
- package/templates/react-monorepo/files/apps/client/src/app/providers.tsx +42 -0
- package/templates/react-monorepo/files/apps/client/src/app/router.tsx +50 -0
- package/templates/react-monorepo/files/apps/client/src/app/store.ts +15 -0
- package/templates/react-monorepo/files/apps/client/src/lib/env.ts +12 -0
- package/templates/react-monorepo/files/apps/client/src/main.tsx +19 -0
- package/templates/react-monorepo/files/apps/client/src/routes/home.tsx +17 -0
- package/templates/react-monorepo/files/apps/client/src/routes/settings.tsx +10 -0
- package/templates/react-monorepo/files/apps/client/src/vite-env.d.ts +15 -0
- package/templates/react-monorepo/files/apps/client/tsconfig.json +10 -0
- package/templates/react-monorepo/files/apps/client/vite.config.ts +120 -0
- package/templates/react-monorepo/files/apps/landing/.bin/secrets.js +57 -0
- package/templates/react-monorepo/files/apps/landing/.env.example +20 -0
- package/templates/react-monorepo/files/apps/landing/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/apps/landing/index.html +51 -0
- package/templates/react-monorepo/files/apps/landing/package.json +33 -0
- package/templates/react-monorepo/files/apps/landing/src/App.tsx +3 -0
- package/templates/react-monorepo/files/apps/landing/src/app/providers.tsx +42 -0
- package/templates/react-monorepo/files/apps/landing/src/app/router.tsx +21 -0
- package/templates/react-monorepo/files/apps/landing/src/app/store.ts +18 -0
- package/templates/react-monorepo/files/apps/landing/src/features/seo/routes.ts +65 -0
- package/templates/react-monorepo/files/apps/landing/src/lib/env.ts +10 -0
- package/templates/react-monorepo/files/apps/landing/src/main.tsx +14 -0
- package/templates/react-monorepo/files/apps/landing/src/routes/home.tsx +18 -0
- package/templates/react-monorepo/files/apps/landing/src/vite-env.d.ts +15 -0
- package/templates/react-monorepo/files/apps/landing/tsconfig.json +10 -0
- package/templates/react-monorepo/files/apps/landing/vite.config.ts +169 -0
- package/templates/react-monorepo/files/build.sh +61 -0
- package/templates/react-monorepo/files/docker/nginx.conf +136 -0
- package/templates/react-monorepo/files/package.json +37 -0
- package/templates/react-monorepo/files/packages/.gitkeep +0 -0
- package/templates/react-monorepo/files/packages/api/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/packages/api/package.json +30 -0
- package/templates/react-monorepo/files/packages/api/src/base-api.ts +24 -0
- package/templates/react-monorepo/files/packages/api/src/base-query.ts +29 -0
- package/templates/react-monorepo/files/packages/api/src/config.ts +21 -0
- package/templates/react-monorepo/files/packages/api/src/index.ts +15 -0
- package/templates/react-monorepo/files/packages/api/src/realtime-events.ts +34 -0
- package/templates/react-monorepo/files/packages/api/src/socket.ts +41 -0
- package/templates/react-monorepo/files/packages/api/src/store.ts +39 -0
- package/templates/react-monorepo/files/packages/api/src/upload-query.ts +115 -0
- package/templates/react-monorepo/files/packages/api/tsconfig.json +4 -0
- package/templates/react-monorepo/files/packages/auth/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/packages/auth/package.json +33 -0
- package/templates/react-monorepo/files/packages/auth/src/client.ts +27 -0
- package/templates/react-monorepo/files/packages/auth/src/config.ts +22 -0
- package/templates/react-monorepo/files/packages/auth/src/guards.tsx +61 -0
- package/templates/react-monorepo/files/packages/auth/src/hooks.ts +13 -0
- package/templates/react-monorepo/files/packages/auth/src/index.ts +20 -0
- package/templates/react-monorepo/files/packages/auth/src/logout.ts +23 -0
- package/templates/react-monorepo/files/packages/auth/src/provider.tsx +52 -0
- package/templates/react-monorepo/files/packages/auth/src/redirect.ts +37 -0
- package/templates/react-monorepo/files/packages/auth/src/slice.ts +54 -0
- package/templates/react-monorepo/files/packages/auth/tsconfig.json +4 -0
- package/templates/react-monorepo/files/packages/config/README.md +47 -0
- package/templates/react-monorepo/files/packages/config/eslint/base.mjs +83 -0
- package/templates/react-monorepo/files/packages/config/package.json +37 -0
- package/templates/react-monorepo/files/packages/config/tailwind/theme.css +48 -0
- package/templates/react-monorepo/files/packages/config/tsconfig/base.json +22 -0
- package/templates/react-monorepo/files/packages/config/tsconfig/node.json +9 -0
- package/templates/react-monorepo/files/packages/config/tsconfig/react.json +9 -0
- package/templates/react-monorepo/files/packages/config/vite/index.d.ts +18 -0
- package/templates/react-monorepo/files/packages/config/vite/index.mjs +129 -0
- package/templates/react-monorepo/files/packages/hooks/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/packages/hooks/package.json +16 -0
- package/templates/react-monorepo/files/packages/hooks/src/index.ts +3 -0
- package/templates/react-monorepo/files/packages/hooks/tsconfig.json +4 -0
- package/templates/react-monorepo/files/packages/layouts/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/packages/layouts/package.json +30 -0
- package/templates/react-monorepo/files/packages/layouts/src/app-shell/app-shell.tsx +225 -0
- package/templates/react-monorepo/files/packages/layouts/src/app-shell/user-menu.tsx +74 -0
- package/templates/react-monorepo/files/packages/layouts/src/auth-layout.tsx +137 -0
- package/templates/react-monorepo/files/packages/layouts/src/error-boundary.tsx +38 -0
- package/templates/react-monorepo/files/packages/layouts/src/index.ts +23 -0
- package/templates/react-monorepo/files/packages/layouts/src/marketing/marketing-layout.tsx +29 -0
- package/templates/react-monorepo/files/packages/layouts/src/marketing/section-heading.tsx +38 -0
- package/templates/react-monorepo/files/packages/layouts/src/marketing/section.tsx +30 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/app-shell-skeleton.tsx +47 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/empty.tsx +22 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/forbidden.tsx +14 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/loading.tsx +11 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/not-found.tsx +21 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/page-skeleton.tsx +39 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/route-fallback.tsx +26 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/state-screen.tsx +22 -0
- package/templates/react-monorepo/files/packages/layouts/tsconfig.json +4 -0
- package/templates/react-monorepo/files/packages/types/.bin/openapi.js +32 -0
- package/templates/react-monorepo/files/packages/types/.bin/secrets.js +57 -0
- package/templates/react-monorepo/files/packages/types/README.md +28 -0
- package/templates/react-monorepo/files/packages/types/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/packages/types/openapi-ts.config.ts +22 -0
- package/templates/react-monorepo/files/packages/types/package.json +29 -0
- package/templates/react-monorepo/files/packages/types/src/index.ts +4 -0
- package/templates/react-monorepo/files/packages/types/src/types/api/index.ts +9 -0
- package/templates/react-monorepo/files/packages/types/src/types/api/zod.gen.ts +5 -0
- package/templates/react-monorepo/files/packages/types/tsconfig.json +7 -0
- package/templates/react-monorepo/files/packages/ui/components.json +21 -0
- package/templates/react-monorepo/files/packages/ui/eslint.config.mjs +13 -0
- package/templates/react-monorepo/files/packages/ui/package.json +44 -0
- package/templates/react-monorepo/files/packages/ui/src/components/brand/logo.tsx +51 -0
- package/templates/react-monorepo/files/packages/ui/src/components/brand/social-icons.tsx +37 -0
- package/templates/react-monorepo/files/packages/ui/src/components/form/form.tsx +120 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/alert.tsx +25 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/button.tsx +43 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/calendar.tsx +78 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/card.tsx +44 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/checkbox.tsx +16 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/date-picker.tsx +76 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/input.tsx +22 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/label.tsx +19 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/modal.tsx +94 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/popover.tsx +31 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/progress.tsx +33 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/search-input.tsx +69 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/select.tsx +80 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/skeleton.tsx +12 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/sonner.tsx +23 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/spinner.tsx +8 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/textarea.tsx +22 -0
- package/templates/react-monorepo/files/packages/ui/src/index.ts +45 -0
- package/templates/react-monorepo/files/packages/ui/src/lib/utils.ts +7 -0
- package/templates/react-monorepo/files/packages/ui/src/lib/zod-setup.ts +28 -0
- package/templates/react-monorepo/files/packages/ui/src/meta/brand.ts +18 -0
- package/templates/react-monorepo/files/packages/ui/src/meta/meta-context.ts +30 -0
- package/templates/react-monorepo/files/packages/ui/src/meta/meta-provider.tsx +24 -0
- package/templates/react-monorepo/files/packages/ui/src/meta/page-meta.tsx +69 -0
- package/templates/react-monorepo/files/packages/ui/src/meta/use-meta-config.ts +11 -0
- package/templates/react-monorepo/files/packages/ui/src/styles/globals.css +285 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/init-script.ts +23 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/theme-colors.ts +14 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/theme-context.ts +60 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/theme-provider.tsx +101 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/theme-toggle.tsx +40 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/use-theme.ts +11 -0
- package/templates/react-monorepo/files/packages/ui/tsconfig.json +9 -0
- package/templates/react-monorepo/files/turbo.json +24 -0
- package/templates/react-monorepo/template.json +230 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TestBed } from '@suites/unit';
|
|
2
|
+
import { PrismaService } from 'common/services';
|
|
3
|
+
|
|
4
|
+
describe('PrismaService', () => {
|
|
5
|
+
let service: PrismaService;
|
|
6
|
+
|
|
7
|
+
beforeAll(async () => {
|
|
8
|
+
const { unit } = await TestBed.solitary(PrismaService).compile();
|
|
9
|
+
service = unit;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should be defined', () => {
|
|
13
|
+
expect(service).toBeDefined();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { BadRequestException } from '@nestjs/common';
|
|
2
|
+
import type { PrismaService } from 'common/services';
|
|
3
|
+
import { ensureEachExists, ensureExists, ensureUnique } from 'common/utils';
|
|
4
|
+
|
|
5
|
+
describe('record checks', () => {
|
|
6
|
+
const exists = vi.fn();
|
|
7
|
+
const db = { x: { user: { exists } } } as unknown as PrismaService;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => exists.mockReset());
|
|
10
|
+
|
|
11
|
+
describe('ensureExists', () => {
|
|
12
|
+
it('passes when a row has the value, matching case-insensitively', async () => {
|
|
13
|
+
exists.mockResolvedValue(true);
|
|
14
|
+
|
|
15
|
+
await expect(ensureExists(db, 'user', 'role', 'Admin')).resolves.toBe(
|
|
16
|
+
undefined
|
|
17
|
+
);
|
|
18
|
+
expect(exists).toHaveBeenCalledWith({
|
|
19
|
+
role: { equals: 'Admin', mode: 'insensitive' }
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('rejects with a validation error when no row has it', async () => {
|
|
24
|
+
exists.mockResolvedValue(false);
|
|
25
|
+
|
|
26
|
+
await expect(ensureExists(db, 'user', 'role', 'ghost')).rejects.toThrow(
|
|
27
|
+
new BadRequestException("Validation: role 'ghost' does not exist")
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it.each([undefined, null, ''])(
|
|
32
|
+
'skips an empty value (%s)',
|
|
33
|
+
async (value) => {
|
|
34
|
+
await ensureExists(db, 'user', 'role', value);
|
|
35
|
+
expect(exists).not.toHaveBeenCalled();
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('ensureEachExists', () => {
|
|
41
|
+
it('passes when every value exists', async () => {
|
|
42
|
+
exists.mockResolvedValue(true);
|
|
43
|
+
|
|
44
|
+
await ensureEachExists(db, 'user', 'id', ['a', 'b']);
|
|
45
|
+
expect(exists).toHaveBeenCalledTimes(2);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('names the first value that does not exist', async () => {
|
|
49
|
+
exists.mockResolvedValueOnce(true).mockResolvedValueOnce(false);
|
|
50
|
+
|
|
51
|
+
await expect(
|
|
52
|
+
ensureEachExists(db, 'user', 'id', ['a', 'b', 'c'])
|
|
53
|
+
).rejects.toThrow(
|
|
54
|
+
new BadRequestException(
|
|
55
|
+
"Validation: id element with id 'b' does not exist"
|
|
56
|
+
)
|
|
57
|
+
);
|
|
58
|
+
expect(exists).toHaveBeenCalledTimes(2);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('skips a missing list', async () => {
|
|
62
|
+
await ensureEachExists(db, 'user', 'id', undefined);
|
|
63
|
+
expect(exists).not.toHaveBeenCalled();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('ensureUnique', () => {
|
|
68
|
+
it('passes when no row has the value', async () => {
|
|
69
|
+
exists.mockResolvedValue(false);
|
|
70
|
+
await expect(
|
|
71
|
+
ensureUnique(db, 'user', 'email', 'new@example.com')
|
|
72
|
+
).resolves.toBe(undefined);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('rejects with a validation error when the value is taken', async () => {
|
|
76
|
+
exists.mockResolvedValue(true);
|
|
77
|
+
|
|
78
|
+
await expect(
|
|
79
|
+
ensureUnique(db, 'user', 'email', 'taken@example.com')
|
|
80
|
+
).rejects.toThrow(
|
|
81
|
+
new BadRequestException(
|
|
82
|
+
"Validation: email 'taken@example.com' already exists"
|
|
83
|
+
)
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Prisma } from '@db/client';
|
|
3
|
+
import {
|
|
4
|
+
dateOnly,
|
|
5
|
+
dateTime,
|
|
6
|
+
decimal,
|
|
7
|
+
email,
|
|
8
|
+
mustMatch,
|
|
9
|
+
search,
|
|
10
|
+
sortKeys
|
|
11
|
+
} from 'common/schemas';
|
|
12
|
+
import { CommonFilters, DateFilters } from 'common/dto';
|
|
13
|
+
|
|
14
|
+
const messages = (result: { error?: z.ZodError }) =>
|
|
15
|
+
result.error?.issues.map((issue) => issue.message) ?? [];
|
|
16
|
+
|
|
17
|
+
describe('schema fields', () => {
|
|
18
|
+
describe('dateTime', () => {
|
|
19
|
+
it('serializes a Date as an ISO date-time string', () => {
|
|
20
|
+
const at = new Date('2026-01-02T03:04:05.678Z');
|
|
21
|
+
expect(dateTime().parse(at)).toBe('2026-01-02T03:04:05.678Z');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('rejects anything but a Date', () => {
|
|
25
|
+
expect(dateTime().safeParse('2026-01-02').success).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('dateOnly', () => {
|
|
30
|
+
it('serializes a Date as YYYY-MM-DD', () => {
|
|
31
|
+
expect(dateOnly().parse(new Date('2026-03-04T23:00:00.000Z'))).toBe(
|
|
32
|
+
'2026-03-04'
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('decimal', () => {
|
|
38
|
+
it('serializes a Prisma.Decimal as a number, rounded to 4 places', () => {
|
|
39
|
+
expect(decimal().parse(new Prisma.Decimal('12.345678'))).toBe(12.3457);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('accepts a numeric string', () => {
|
|
43
|
+
expect(decimal().parse('3.5')).toBe(3.5);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('email', () => {
|
|
48
|
+
it('lower-cases a valid address', () => {
|
|
49
|
+
expect(email().parse('Ada@Example.COM')).toBe('ada@example.com');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('rejects an invalid address', () => {
|
|
53
|
+
expect(email().safeParse('not-an-email').success).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('search', () => {
|
|
58
|
+
const schema = z.object({ search: search() });
|
|
59
|
+
|
|
60
|
+
it('trims a search of three or more characters', () => {
|
|
61
|
+
expect(schema.parse({ search: ' kamil ' })).toEqual({ search: 'kamil' });
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('treats a blank search as absent', () => {
|
|
65
|
+
expect(schema.parse({ search: '' })).toEqual({ search: undefined });
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('rejects a search shorter than three characters', () => {
|
|
69
|
+
expect(schema.safeParse({ search: 'ab' }).success).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('sortKeys', () => {
|
|
74
|
+
const sort = sortKeys(['name', 'createdAt']);
|
|
75
|
+
|
|
76
|
+
it('accepts allowed keys, with or without a descending prefix', () => {
|
|
77
|
+
expect(sort.parse('name,-createdAt')).toBe('name,-createdAt');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('is optional', () => {
|
|
81
|
+
expect(sort.parse(undefined)).toBeUndefined();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('rejects an unknown key and lists the allowed ones', () => {
|
|
85
|
+
const result = sort.safeParse('name,email');
|
|
86
|
+
expect(messages(result)).toEqual([
|
|
87
|
+
'Sort key must be one of the following: name, createdAt'
|
|
88
|
+
]);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('mustMatch', () => {
|
|
93
|
+
const schema = z
|
|
94
|
+
.object({ password: z.string(), confirmPassword: z.string() })
|
|
95
|
+
.superRefine(mustMatch('password', 'confirmPassword'));
|
|
96
|
+
|
|
97
|
+
it('passes when the fields match', () => {
|
|
98
|
+
expect(
|
|
99
|
+
schema.safeParse({ password: 'a', confirmPassword: 'a' }).success
|
|
100
|
+
).toBe(true);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('reports a mismatch on the confirming field', () => {
|
|
104
|
+
const result = schema.safeParse({ password: 'a', confirmPassword: 'b' });
|
|
105
|
+
expect(result.error?.issues[0].path).toEqual(['confirmPassword']);
|
|
106
|
+
expect(messages(result)).toEqual(['confirmPassword must match password']);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('filter schemas', () => {
|
|
112
|
+
describe('CommonFilters', () => {
|
|
113
|
+
it('coerces page and limit from query-string text', () => {
|
|
114
|
+
expect(CommonFilters.parse({ page: '2', limit: '10' })).toEqual({
|
|
115
|
+
page: 2,
|
|
116
|
+
limit: 10
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it.each(['0', '-1', '1.5', 'abc'])('rejects page=%s', (page) => {
|
|
121
|
+
expect(CommonFilters.safeParse({ page }).success).toBe(false);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('drops unknown query parameters', () => {
|
|
125
|
+
expect(CommonFilters.parse({ page: '1', debug: 'true' })).toEqual({
|
|
126
|
+
page: 1
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('DateFilters', () => {
|
|
132
|
+
it('accepts a date or an ISO date-time', () => {
|
|
133
|
+
expect(
|
|
134
|
+
DateFilters.parse({ from: '2026-01-01', to: '2026-12-31T23:59:59Z' })
|
|
135
|
+
).toEqual({ from: '2026-01-01', to: '2026-12-31T23:59:59Z' });
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('rejects anything else', () => {
|
|
139
|
+
expect(DateFilters.safeParse({ from: 'yesterday' }).success).toBe(false);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { CacheService, RedisThrottlerStorage } from 'common/services';
|
|
2
|
+
|
|
3
|
+
type IncrementResult = [number, number, number, number];
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The Lua script itself is exercised against real Redis by `test/rate-limit.spec.ts`.
|
|
7
|
+
* Here we pin the contract around it: argument marshalling and the ms → s
|
|
8
|
+
* conversion that `ThrottlerGuard` relies on for `Retry-After`.
|
|
9
|
+
*/
|
|
10
|
+
const makeCache = (result: IncrementResult) => {
|
|
11
|
+
const throttlerIncrement = vi.fn().mockResolvedValue(result);
|
|
12
|
+
const defineCommand = vi.fn();
|
|
13
|
+
const cache = {
|
|
14
|
+
db: { defineCommand, throttlerIncrement }
|
|
15
|
+
} as unknown as CacheService;
|
|
16
|
+
|
|
17
|
+
return { cache, throttlerIncrement, defineCommand };
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe('RedisThrottlerStorage', () => {
|
|
21
|
+
it('registers the Lua command once on construction', () => {
|
|
22
|
+
const { cache, defineCommand } = makeCache([1, 60_000, 0, 0]);
|
|
23
|
+
new RedisThrottlerStorage(cache);
|
|
24
|
+
|
|
25
|
+
expect(defineCommand).toHaveBeenCalledWith(
|
|
26
|
+
'throttlerIncrement',
|
|
27
|
+
expect.objectContaining({ numberOfKeys: 2 })
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('passes the hits and block keys, namespaced by throttler name', async () => {
|
|
32
|
+
const { cache, throttlerIncrement } = makeCache([1, 60_000, 0, 0]);
|
|
33
|
+
const storage = new RedisThrottlerStorage(cache);
|
|
34
|
+
|
|
35
|
+
await storage.increment('abc123', 60_000, 30, 60_000, 'default');
|
|
36
|
+
|
|
37
|
+
expect(throttlerIncrement).toHaveBeenCalledWith(
|
|
38
|
+
'throttle:default:abc123',
|
|
39
|
+
'throttle:default:abc123:block',
|
|
40
|
+
60_000,
|
|
41
|
+
30,
|
|
42
|
+
60_000
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('converts millisecond TTLs to the seconds the guard expects', async () => {
|
|
47
|
+
const { cache } = makeCache([1, 59_400, 0, 0]);
|
|
48
|
+
const storage = new RedisThrottlerStorage(cache);
|
|
49
|
+
|
|
50
|
+
const record = await storage.increment('k', 60_000, 30, 60_000, 'default');
|
|
51
|
+
|
|
52
|
+
expect(record).toEqual({
|
|
53
|
+
totalHits: 1,
|
|
54
|
+
timeToExpire: 60, // ceil(59_400 / 1000)
|
|
55
|
+
isBlocked: false,
|
|
56
|
+
timeToBlockExpire: 0
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('reports a block with its remaining time in seconds', async () => {
|
|
61
|
+
const { cache } = makeCache([31, 42_000, 1, 30_500]);
|
|
62
|
+
const storage = new RedisThrottlerStorage(cache);
|
|
63
|
+
|
|
64
|
+
const record = await storage.increment('k', 60_000, 30, 60_000, 'default');
|
|
65
|
+
|
|
66
|
+
expect(record.isBlocked).toBe(true);
|
|
67
|
+
expect(record.totalHits).toBe(31);
|
|
68
|
+
expect(record.timeToBlockExpire).toBe(31); // ceil(30_500 / 1000)
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('clamps negative TTLs (expired or missing key) to zero', async () => {
|
|
72
|
+
const { cache } = makeCache([1, -2, 0, -2]);
|
|
73
|
+
const storage = new RedisThrottlerStorage(cache);
|
|
74
|
+
|
|
75
|
+
const record = await storage.increment('k', 60_000, 30, 60_000, 'default');
|
|
76
|
+
|
|
77
|
+
expect(record.timeToExpire).toBe(0);
|
|
78
|
+
expect(record.timeToBlockExpire).toBe(0);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Global, Module } from '@nestjs/common';
|
|
2
|
+
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
3
|
+
import { TerminusModule } from '@nestjs/terminus'; // @feature observability
|
|
4
|
+
import { LoggerModule } from './modules';
|
|
5
|
+
import { MetricsModule } from './modules'; // @feature observability
|
|
6
|
+
// The queue module itself is generic; here it is only needed to register the
|
|
7
|
+
// `mail` queue, so it rides on the mail feature.
|
|
8
|
+
import { QueueModule } from './modules'; // @feature mail
|
|
9
|
+
import {
|
|
10
|
+
GeneratorService,
|
|
11
|
+
CustomConfigService,
|
|
12
|
+
PrismaService,
|
|
13
|
+
CustomAuthService
|
|
14
|
+
} from './services';
|
|
15
|
+
import { CacheService } from './services'; // @feature cache
|
|
16
|
+
import { MailService } from './services'; // @feature mail
|
|
17
|
+
import { RedisThrottlerStorage } from './services'; // @feature rate-limit
|
|
18
|
+
import { FeatureFlagService } from './services'; // @feature feature-flags
|
|
19
|
+
import { HealthController } from './controllers'; // @feature observability
|
|
20
|
+
import { MailProcessor } from './processors'; // @feature mail
|
|
21
|
+
import { FeatureFlagGuard } from './guards'; // @feature feature-flags
|
|
22
|
+
import { PrismaHealthIndicator } from './misc'; // @feature observability
|
|
23
|
+
import Config from './services/config.service';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Global infrastructure module. Everything listed in `exports` is injectable
|
|
27
|
+
* anywhere without importing this module — extend that array when you add a
|
|
28
|
+
* shared provider, or the rest of the app will not see it.
|
|
29
|
+
*/
|
|
30
|
+
@Global()
|
|
31
|
+
@Module({
|
|
32
|
+
imports: [
|
|
33
|
+
ConfigModule.forRoot({
|
|
34
|
+
load: [Config.getVariables],
|
|
35
|
+
validationSchema: Config.schema
|
|
36
|
+
}),
|
|
37
|
+
LoggerModule,
|
|
38
|
+
// @feature:start observability
|
|
39
|
+
TerminusModule,
|
|
40
|
+
MetricsModule,
|
|
41
|
+
// @feature:end
|
|
42
|
+
QueueModule.register('mail') // @feature mail
|
|
43
|
+
],
|
|
44
|
+
controllers: [
|
|
45
|
+
HealthController // @feature observability
|
|
46
|
+
],
|
|
47
|
+
providers: [
|
|
48
|
+
ConfigService,
|
|
49
|
+
CustomConfigService,
|
|
50
|
+
GeneratorService,
|
|
51
|
+
PrismaService,
|
|
52
|
+
CustomAuthService,
|
|
53
|
+
CacheService, // @feature cache
|
|
54
|
+
MailService, // @feature mail
|
|
55
|
+
MailProcessor, // @feature mail
|
|
56
|
+
RedisThrottlerStorage, // @feature rate-limit
|
|
57
|
+
FeatureFlagService, // @feature feature-flags
|
|
58
|
+
FeatureFlagGuard, // @feature feature-flags
|
|
59
|
+
PrismaHealthIndicator // @feature observability
|
|
60
|
+
],
|
|
61
|
+
exports: [
|
|
62
|
+
CustomConfigService,
|
|
63
|
+
GeneratorService,
|
|
64
|
+
PrismaService,
|
|
65
|
+
CustomAuthService,
|
|
66
|
+
CacheService, // @feature cache
|
|
67
|
+
MailService, // @feature mail
|
|
68
|
+
RedisThrottlerStorage, // @feature rate-limit
|
|
69
|
+
FeatureFlagService // @feature feature-flags
|
|
70
|
+
]
|
|
71
|
+
})
|
|
72
|
+
export class CommonModule {}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import { DocumentBuilder } from '@nestjs/swagger'; // @feature openapi
|
|
3
|
+
import { OriginBuilder } from '../misc';
|
|
4
|
+
|
|
5
|
+
// Read directly from `process.env`, not CustomConfigService: these constants are
|
|
6
|
+
// evaluated at module load, before Nest's DI container exists.
|
|
7
|
+
const { env: E } = process;
|
|
8
|
+
|
|
9
|
+
const port = E.PORT!;
|
|
10
|
+
const host = E.SERVER_HOST!;
|
|
11
|
+
const appHost = E.APP_HOST!;
|
|
12
|
+
const frontendHost = E.FRONTEND_HOST!;
|
|
13
|
+
|
|
14
|
+
const env = E.APP_ENV!;
|
|
15
|
+
const IS_DEV = env === 'development';
|
|
16
|
+
|
|
17
|
+
// Extra origins are a development convenience only — production is pinned to
|
|
18
|
+
// the configured frontend host.
|
|
19
|
+
const CORS_ORIGINS = !IS_DEV
|
|
20
|
+
? [frontendHost]
|
|
21
|
+
: [frontendHost, ...OriginBuilder.build(E.MISC_CORS_ORIGINS)];
|
|
22
|
+
|
|
23
|
+
// @feature:start openapi
|
|
24
|
+
const createDocumentBuilder = () => {
|
|
25
|
+
const builder = new DocumentBuilder()
|
|
26
|
+
.setTitle('Acme Corp API')
|
|
27
|
+
.setDescription('API for the Acme Corp application')
|
|
28
|
+
.setVersion('1.0')
|
|
29
|
+
.addTag('App')
|
|
30
|
+
.addTag('Users', 'User management and authentication')
|
|
31
|
+
.addTag('Current User', 'Current authenticated user information')
|
|
32
|
+
.addBearerAuth();
|
|
33
|
+
|
|
34
|
+
builder.addServer(host);
|
|
35
|
+
if (IS_DEV) {
|
|
36
|
+
builder
|
|
37
|
+
.addServer(`http://localhost:${port}`, 'Local Development')
|
|
38
|
+
.addServer(`http://${appHost}:${port}`, 'Dynamic Development');
|
|
39
|
+
}
|
|
40
|
+
return builder.build();
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const SWAGGER_OPTIONS = createDocumentBuilder();
|
|
44
|
+
// @feature:end
|
|
45
|
+
|
|
46
|
+
export const CORS_OPTIONS = {
|
|
47
|
+
origin: CORS_ORIGINS,
|
|
48
|
+
credentials: true,
|
|
49
|
+
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
|
50
|
+
preflightContinue: false,
|
|
51
|
+
optionsSuccessStatus: 204
|
|
52
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const PINO_CONSOLE_TARGET = {
|
|
2
|
+
target: 'pino-pretty',
|
|
3
|
+
options: {
|
|
4
|
+
ignore: 'pid,hostname',
|
|
5
|
+
translateTime: 'SYS:dd-mm-yyyy HH:MM:ss',
|
|
6
|
+
singleLine: true,
|
|
7
|
+
colorize: true
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const PINO_FILE_TARGET = {
|
|
12
|
+
target: 'pino/file',
|
|
13
|
+
options: {
|
|
14
|
+
destination: 'logs/app.log',
|
|
15
|
+
mkdir: true
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const PINO_CONSOLE_TARGET_PROD = {
|
|
20
|
+
target: 'pino/file',
|
|
21
|
+
options: {
|
|
22
|
+
destination: 1
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Controller, Get, VERSION_NEUTRAL } from '@nestjs/common';
|
|
2
|
+
import { ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
|
|
3
|
+
import {
|
|
4
|
+
HealthCheckService,
|
|
5
|
+
HttpHealthIndicator,
|
|
6
|
+
HealthCheck,
|
|
7
|
+
DiskHealthIndicator,
|
|
8
|
+
MemoryHealthIndicator
|
|
9
|
+
} from '@nestjs/terminus';
|
|
10
|
+
import { SkipThrottle } from '@nestjs/throttler'; // @feature rate-limit
|
|
11
|
+
import { AllowAnonymous } from '@thallesp/nestjs-better-auth';
|
|
12
|
+
import { Op } from 'common/decorators';
|
|
13
|
+
import { CustomConfigService } from '../services';
|
|
14
|
+
import { PrismaHealthIndicator } from '../misc';
|
|
15
|
+
|
|
16
|
+
const MB = 1024 * 1024;
|
|
17
|
+
|
|
18
|
+
@ApiTags('App')
|
|
19
|
+
@Controller({ path: 'health', version: VERSION_NEUTRAL })
|
|
20
|
+
// @feature:start rate-limit
|
|
21
|
+
// Probed on a fixed interval by orchestrators; throttling it would take the
|
|
22
|
+
// service out of rotation under exactly the load it exists to report on.
|
|
23
|
+
@SkipThrottle()
|
|
24
|
+
// @feature:end
|
|
25
|
+
export class HealthController {
|
|
26
|
+
constructor(
|
|
27
|
+
private health: HealthCheckService,
|
|
28
|
+
private http: HttpHealthIndicator,
|
|
29
|
+
private config: CustomConfigService,
|
|
30
|
+
private prisma: PrismaHealthIndicator,
|
|
31
|
+
private disk: DiskHealthIndicator,
|
|
32
|
+
private memory: MemoryHealthIndicator
|
|
33
|
+
) {}
|
|
34
|
+
|
|
35
|
+
@Get()
|
|
36
|
+
@ApiExcludeEndpoint()
|
|
37
|
+
@Op('health', '/health', 'Check the health of the server')
|
|
38
|
+
@HealthCheck()
|
|
39
|
+
@AllowAnonymous()
|
|
40
|
+
async check() {
|
|
41
|
+
const { heapMaxMb, rssMaxMb, diskThreshold, diskPath } = this.config.health;
|
|
42
|
+
return this.health.check([
|
|
43
|
+
() => this.http.pingCheck('http', this.config.app.host),
|
|
44
|
+
() => this.prisma.isHealthy('database'),
|
|
45
|
+
() => this.memory.checkHeap('memory_heap', heapMaxMb * MB),
|
|
46
|
+
() => this.memory.checkRSS('memory_rss', rssMaxMb * MB),
|
|
47
|
+
() =>
|
|
48
|
+
this.disk.checkStorage('disk_storage', {
|
|
49
|
+
thresholdPercent: diskThreshold,
|
|
50
|
+
path: diskPath
|
|
51
|
+
})
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Controller, Get, Res } from '@nestjs/common';
|
|
2
|
+
import { ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
|
|
3
|
+
import { SkipThrottle } from '@nestjs/throttler'; // @feature rate-limit
|
|
4
|
+
import { AllowAnonymous } from '@thallesp/nestjs-better-auth';
|
|
5
|
+
import { PrometheusController } from '@willsoto/nestjs-prometheus';
|
|
6
|
+
import type { Response } from 'express';
|
|
7
|
+
|
|
8
|
+
@ApiTags('App')
|
|
9
|
+
@Controller()
|
|
10
|
+
// @feature:start rate-limit
|
|
11
|
+
// Scraped on a fixed interval by Prometheus; already gated by basic auth.
|
|
12
|
+
@SkipThrottle()
|
|
13
|
+
// @feature:end
|
|
14
|
+
export class MetricsController extends PrometheusController {
|
|
15
|
+
@Get()
|
|
16
|
+
@ApiExcludeEndpoint()
|
|
17
|
+
@AllowAnonymous()
|
|
18
|
+
async index(@Res({ passthrough: true }) response: Response): Promise<string> {
|
|
19
|
+
return super.index(response);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { applyDecorators, SerializeOptions } from '@nestjs/common';
|
|
2
|
+
import {
|
|
3
|
+
ApiOkResponse,
|
|
4
|
+
ApiParam,
|
|
5
|
+
ApiOperation,
|
|
6
|
+
ApiOperationOptions,
|
|
7
|
+
ApiResponseOptions
|
|
8
|
+
} from '@nestjs/swagger';
|
|
9
|
+
import type { z } from 'zod';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Declare what a handler returns: the schema is published as the OpenAPI
|
|
13
|
+
* response and, through the global StandardSchemaSerializerInterceptor, is
|
|
14
|
+
* what the response is serialized with — fields it does not declare are
|
|
15
|
+
* dropped, and a return value that does not match fails loudly.
|
|
16
|
+
*/
|
|
17
|
+
export function Returns(
|
|
18
|
+
schema: z.ZodType,
|
|
19
|
+
options: Omit<ApiResponseOptions, 'type' | 'schema' | 'standardSchema'> = {}
|
|
20
|
+
) {
|
|
21
|
+
return applyDecorators(
|
|
22
|
+
ApiOkResponse({ ...options, standardSchema: schema }),
|
|
23
|
+
SerializeOptions({ schema })
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function IdParam(name = 'id') {
|
|
28
|
+
return applyDecorators(ApiParam({ name, type: String }));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type OperationOptions = Omit<
|
|
32
|
+
ApiOperationOptions,
|
|
33
|
+
'summary' | 'description' | 'operationId'
|
|
34
|
+
>;
|
|
35
|
+
export function Op(
|
|
36
|
+
operationId: string,
|
|
37
|
+
summary: string,
|
|
38
|
+
description: string | undefined = undefined,
|
|
39
|
+
options: OperationOptions = {}
|
|
40
|
+
) {
|
|
41
|
+
return applyDecorators(
|
|
42
|
+
ApiOperation({
|
|
43
|
+
summary,
|
|
44
|
+
operationId,
|
|
45
|
+
description,
|
|
46
|
+
...options
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { search } from '../schemas';
|
|
3
|
+
|
|
4
|
+
// Query strings arrive as text, so numbers are coerced before they are checked.
|
|
5
|
+
const pageNumber = () => z.coerce.number().int().min(1).optional();
|
|
6
|
+
|
|
7
|
+
export const CommonFilters = z.object({
|
|
8
|
+
search: search(),
|
|
9
|
+
limit: pageNumber(),
|
|
10
|
+
page: pageNumber()
|
|
11
|
+
});
|
|
12
|
+
export type CommonFilters = z.output<typeof CommonFilters>;
|
|
13
|
+
|
|
14
|
+
// ISO 8601: a date, or a date-time with an offset.
|
|
15
|
+
const isoDateOrDateTime = () =>
|
|
16
|
+
z
|
|
17
|
+
.union([z.iso.date(), z.iso.datetime({ offset: true })])
|
|
18
|
+
.optional()
|
|
19
|
+
.meta({ example: '2026-01-01T00:00:00.000Z' });
|
|
20
|
+
|
|
21
|
+
export const DateFilters = z.object({
|
|
22
|
+
from: isoDateOrDateTime(),
|
|
23
|
+
to: isoDateOrDateTime()
|
|
24
|
+
});
|
|
25
|
+
export type DateFilters = z.output<typeof DateFilters>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './filters.dto';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const OKEntity = z
|
|
4
|
+
.object({
|
|
5
|
+
status: z.number().meta({ example: 200 }),
|
|
6
|
+
message: z.string().meta({ example: 'ok' })
|
|
7
|
+
})
|
|
8
|
+
.meta({ id: 'OKEntity' });
|
|
9
|
+
export type OKEntity = z.input<typeof OKEntity>;
|
|
10
|
+
|
|
11
|
+
export const ok = (): OKEntity => ({ status: 200, message: 'ok' });
|