@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,88 @@
|
|
|
1
|
+
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
2
|
+
import { UserSession } from '@thallesp/nestjs-better-auth';
|
|
3
|
+
import { Prisma } from '@db/client';
|
|
4
|
+
import { PrismaService } from 'common/services';
|
|
5
|
+
import { ensureExists } from 'common/utils';
|
|
6
|
+
import { hasRole, type RoleInput } from 'lib/access';
|
|
7
|
+
import { PaginatedUserEntity, UserEntity } from '../entity';
|
|
8
|
+
import { UserFilters } from '../dto';
|
|
9
|
+
import { ok } from 'common/entity';
|
|
10
|
+
|
|
11
|
+
const SU = 'superuser';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Roles a viewer may see. Superusers are visible only to their own tier —
|
|
15
|
+
* everyone below sees user / moderator / admin.
|
|
16
|
+
*/
|
|
17
|
+
const visibleRolesFor = (role: RoleInput): string[] =>
|
|
18
|
+
hasRole(role, SU)
|
|
19
|
+
? ['user', 'moderator', 'admin', SU]
|
|
20
|
+
: ['user', 'moderator', 'admin'];
|
|
21
|
+
|
|
22
|
+
@Injectable()
|
|
23
|
+
export class UsersService {
|
|
24
|
+
constructor(private db: PrismaService) {}
|
|
25
|
+
|
|
26
|
+
async paginate(
|
|
27
|
+
user: UserSession['user'],
|
|
28
|
+
filters: UserFilters
|
|
29
|
+
): Promise<PaginatedUserEntity> {
|
|
30
|
+
await ensureExists(this.db, 'user', 'role', filters.role);
|
|
31
|
+
|
|
32
|
+
const where: Prisma.UserWhereInput = {
|
|
33
|
+
id: { not: user.id }
|
|
34
|
+
};
|
|
35
|
+
if (filters.search && filters.search.trim() !== '') {
|
|
36
|
+
const search = filters.search.trim();
|
|
37
|
+
where.OR = [
|
|
38
|
+
{ email: { contains: search, mode: 'insensitive' } },
|
|
39
|
+
{ name: { contains: search, mode: 'insensitive' } }
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// `hasRole`, not `user.role === SU`: better-auth stores role as a
|
|
44
|
+
// comma-separated string, so a user holding "admin,superuser" fails a
|
|
45
|
+
// straight equality. See `lib/access.ts`.
|
|
46
|
+
const visibleRoles = visibleRolesFor(user.role);
|
|
47
|
+
|
|
48
|
+
// An out-of-range role (a non-superuser asking for superusers) narrows to
|
|
49
|
+
// the whole visible set rather than leaking — never to an unfiltered list.
|
|
50
|
+
where.role =
|
|
51
|
+
filters.role && visibleRoles.includes(filters.role)
|
|
52
|
+
? filters.role
|
|
53
|
+
: { in: visibleRoles };
|
|
54
|
+
|
|
55
|
+
const [list, meta] = await this.db.x.user.paginate({
|
|
56
|
+
where,
|
|
57
|
+
page: filters.page,
|
|
58
|
+
limit: filters.limit
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return { list, ...meta };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Takes the whole session user, not just an id, because visibility depends on
|
|
66
|
+
* the viewer's role — it has to agree with {@link paginate}. Before, a
|
|
67
|
+
* superuser could see other superusers in the listing and then 404 opening
|
|
68
|
+
* one, which is what the admin drawer does on row click.
|
|
69
|
+
*/
|
|
70
|
+
async getUserById(
|
|
71
|
+
viewer: UserSession['user'],
|
|
72
|
+
id: string
|
|
73
|
+
): Promise<UserEntity> {
|
|
74
|
+
if (viewer.id === id) throw new NotFoundException();
|
|
75
|
+
const user = await this.db.user.findFirst({ where: { id } });
|
|
76
|
+
if (!user) throw new NotFoundException();
|
|
77
|
+
// 404 rather than 403 — a hidden user shouldn't be confirmed to exist.
|
|
78
|
+
if (!visibleRolesFor(viewer.role).includes(user.role ?? 'user')) {
|
|
79
|
+
throw new NotFoundException();
|
|
80
|
+
}
|
|
81
|
+
return user;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async remove(id: string) {
|
|
85
|
+
await this.db.user.delete({ where: { id } });
|
|
86
|
+
return ok();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { CurrentUserController, UsersController } from './controllers';
|
|
3
|
+
import { CurrentUserService, UsersService } from './services';
|
|
4
|
+
|
|
5
|
+
@Module({
|
|
6
|
+
imports: [],
|
|
7
|
+
controllers: [CurrentUserController, UsersController],
|
|
8
|
+
providers: [CurrentUserService, UsersService]
|
|
9
|
+
})
|
|
10
|
+
export class UsersModule {}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { AppFactory } from '@test/factory/app';
|
|
2
|
+
import { SWAGGER_OPTIONS } from 'common/constants';
|
|
3
|
+
|
|
4
|
+
describe('App', () => {
|
|
5
|
+
let app: AppFactory;
|
|
6
|
+
|
|
7
|
+
beforeAll(async () => {
|
|
8
|
+
app = await AppFactory.init();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
afterAll(async () => {
|
|
12
|
+
await app.close();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('GET: /', () => {
|
|
16
|
+
let status: number;
|
|
17
|
+
let body: any;
|
|
18
|
+
let headers: Record<string, string>;
|
|
19
|
+
|
|
20
|
+
beforeAll(async () => {
|
|
21
|
+
const response = await app.request.get('/');
|
|
22
|
+
status = response.status;
|
|
23
|
+
body = response.body;
|
|
24
|
+
headers = response.headers as Record<string, string>;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should have 200 status', () => {
|
|
28
|
+
expect(status).toBe(200);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should return object with app title and description', () => {
|
|
32
|
+
const {
|
|
33
|
+
info: { title, description }
|
|
34
|
+
} = SWAGGER_OPTIONS;
|
|
35
|
+
expect(body).toStrictEqual({ title, description });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should apply basic security headers via helmet', () => {
|
|
39
|
+
// A small subset of headers that helmet sets by default
|
|
40
|
+
expect(headers['x-dns-prefetch-control']).toBeDefined();
|
|
41
|
+
expect(headers['x-content-type-options']).toBe('nosniff');
|
|
42
|
+
expect(headers['x-frame-options']).toBeDefined();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('GET: /non-existent', () => {
|
|
47
|
+
it('should return 404 for unknown route', async () => {
|
|
48
|
+
const response = await app.request.get('/non-existent');
|
|
49
|
+
expect(response.status).toBe(404);
|
|
50
|
+
expect(response.body).toMatchObject({
|
|
51
|
+
statusCode: 404
|
|
52
|
+
});
|
|
53
|
+
expect(typeof response.body.message).toBe('string');
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('GET: /openapi-json', () => {
|
|
58
|
+
it('should expose OpenAPI document', async () => {
|
|
59
|
+
const response = await app.request.get('/openapi-json');
|
|
60
|
+
expect(response.status).toBe(200);
|
|
61
|
+
expect(response.headers['content-type']).toContain('application/json');
|
|
62
|
+
const body = response.body as any;
|
|
63
|
+
expect(body).toHaveProperty('openapi');
|
|
64
|
+
const {
|
|
65
|
+
info: { title }
|
|
66
|
+
} = SWAGGER_OPTIONS;
|
|
67
|
+
expect(body.info.title).toBe(title);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('GET: /docs', () => {
|
|
72
|
+
it('should serve API documentation UI', async () => {
|
|
73
|
+
const response = await app.request.get('/docs');
|
|
74
|
+
expect(response.status).toBe(200);
|
|
75
|
+
expect(response.headers['content-type']).toContain('text/html');
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// @feature:start graphql
|
|
80
|
+
describe('POST: /graphql', () => {
|
|
81
|
+
it('should answer the root info query', async () => {
|
|
82
|
+
const response = await app.request
|
|
83
|
+
.post('/graphql')
|
|
84
|
+
.send({ query: '{ info { title description } }' });
|
|
85
|
+
expect(response.status).toBe(200);
|
|
86
|
+
const { info } = SWAGGER_OPTIONS;
|
|
87
|
+
expect(response.body.data.info).toEqual({
|
|
88
|
+
title: info.title,
|
|
89
|
+
description: info.description
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
// @feature:end
|
|
94
|
+
|
|
95
|
+
describe('OPTIONS: / (CORS preflight)', () => {
|
|
96
|
+
it('should respond with CORS headers for allowed origin', async () => {
|
|
97
|
+
const response = await app.request.get('/');
|
|
98
|
+
expect(response.headers['vary']).toContain('Origin');
|
|
99
|
+
expect(response.headers['access-control-allow-credentials']).toBe('true');
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Response } from 'supertest';
|
|
2
|
+
import { AppFactory } from '@test/factory/app';
|
|
3
|
+
import { SUPER_USER } from '@test/factory/constants';
|
|
4
|
+
|
|
5
|
+
describe('Auth', () => {
|
|
6
|
+
let app: AppFactory;
|
|
7
|
+
|
|
8
|
+
beforeAll(async () => {
|
|
9
|
+
app = await AppFactory.init();
|
|
10
|
+
await app.refresh();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
afterAll(async () => {
|
|
14
|
+
await app.close();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('Sign in with email [ /auth/sign-in/email ]', () => {
|
|
18
|
+
describe('with valid credentials', () => {
|
|
19
|
+
let response: Response;
|
|
20
|
+
let cookie: string | undefined;
|
|
21
|
+
|
|
22
|
+
beforeAll(async () => {
|
|
23
|
+
const result = await app.signIn(SUPER_USER.email, SUPER_USER.password);
|
|
24
|
+
response = result.response;
|
|
25
|
+
cookie = result.cookie;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should succeed with logged in user', () => {
|
|
29
|
+
expect(response.status).toBe(200);
|
|
30
|
+
expect(response.body).toHaveProperty('user');
|
|
31
|
+
expect(response.body.user).toHaveProperty('email', SUPER_USER.email);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should establish a session (cookie)', () => {
|
|
35
|
+
expect(cookie).toBeDefined();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('Protected route: /auth/get-session', () => {
|
|
39
|
+
let res: Response;
|
|
40
|
+
|
|
41
|
+
beforeAll(async () => {
|
|
42
|
+
res = await app.request
|
|
43
|
+
.get('/auth/get-session')
|
|
44
|
+
.set('Cookie', cookie!);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should allow access with valid session cookie', () => {
|
|
48
|
+
expect(res.status).toBe(200);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should return the session information', async () => {
|
|
52
|
+
expect(res.body).toHaveProperty('session');
|
|
53
|
+
expect(res.body.session).toMatchObject({
|
|
54
|
+
id: expect.any(String),
|
|
55
|
+
expiresAt: expect.any(String),
|
|
56
|
+
token: expect.any(String),
|
|
57
|
+
createdAt: expect.any(String),
|
|
58
|
+
updatedAt: expect.any(String),
|
|
59
|
+
ipAddress: expect.any(String),
|
|
60
|
+
userAgent: expect.any(String),
|
|
61
|
+
userId: expect.any(String),
|
|
62
|
+
impersonatedBy: null
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should return the user information', async () => {
|
|
67
|
+
expect(res.body).toHaveProperty('user');
|
|
68
|
+
expect(res.body.user).toHaveProperty('name', SUPER_USER.name);
|
|
69
|
+
expect(res.body.user).toHaveProperty('email', SUPER_USER.email);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('otherwise', () => {
|
|
75
|
+
let response: Response;
|
|
76
|
+
let cookie: string | undefined;
|
|
77
|
+
|
|
78
|
+
beforeAll(async () => {
|
|
79
|
+
const result = await app.signIn('wrong@example.com', 'invalid');
|
|
80
|
+
response = result.response;
|
|
81
|
+
cookie = result.cookie;
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should return error for wrong credentials', async () => {
|
|
85
|
+
expect([400, 401]).toContain(response.status);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should NOT set a session cookie', () => {
|
|
89
|
+
expect(cookie).toBeUndefined();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('Protected route: /auth/get-session', () => {
|
|
93
|
+
let res: Response;
|
|
94
|
+
|
|
95
|
+
beforeAll(async () => {
|
|
96
|
+
res = await app.request
|
|
97
|
+
.get('/auth/get-session')
|
|
98
|
+
.set('Cookie', cookie || '');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should NOT allow access', () => {
|
|
102
|
+
expect(res.status).toBe(200);
|
|
103
|
+
expect(res.body).toBeNull();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Response } from 'supertest';
|
|
2
|
+
import { AppFactory } from '@test/factory/app';
|
|
3
|
+
import { SUPER_USER, TEST_ADMIN, TEST_USER } from '@test/factory/constants';
|
|
4
|
+
|
|
5
|
+
describe('Current User', () => {
|
|
6
|
+
let app: AppFactory;
|
|
7
|
+
let superuserCookie: string;
|
|
8
|
+
let adminCookie: string;
|
|
9
|
+
let userCookie: string;
|
|
10
|
+
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
app = await AppFactory.init();
|
|
13
|
+
await app.refresh();
|
|
14
|
+
|
|
15
|
+
const superuserResult = await app.signIn(
|
|
16
|
+
SUPER_USER.email,
|
|
17
|
+
SUPER_USER.password
|
|
18
|
+
);
|
|
19
|
+
superuserCookie = superuserResult.cookie!;
|
|
20
|
+
|
|
21
|
+
const adminResult = await app.signIn(TEST_ADMIN.email, TEST_ADMIN.password);
|
|
22
|
+
adminCookie = adminResult.cookie!;
|
|
23
|
+
|
|
24
|
+
const userResult = await app.signIn(TEST_USER.email, TEST_USER.password);
|
|
25
|
+
userCookie = userResult.cookie!;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterAll(async () => {
|
|
29
|
+
await app.close();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('v1', () => {
|
|
33
|
+
describe('GET: /v1/user', () => {
|
|
34
|
+
describe('as superuser', () => {
|
|
35
|
+
let response: Response;
|
|
36
|
+
|
|
37
|
+
beforeAll(async () => {
|
|
38
|
+
response = await app.request
|
|
39
|
+
.get('/v1/user')
|
|
40
|
+
.set('Cookie', superuserCookie);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should return 200', () => {
|
|
44
|
+
expect(response.status).toBe(200);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should return current user data', () => {
|
|
48
|
+
expect(response.body).toHaveProperty('id');
|
|
49
|
+
expect(response.body).toHaveProperty('name');
|
|
50
|
+
expect(response.body).toHaveProperty('email', SUPER_USER.email);
|
|
51
|
+
expect(response.body).toHaveProperty('emailVerified');
|
|
52
|
+
expect(response.body).toHaveProperty('createdAt');
|
|
53
|
+
expect(response.body).toHaveProperty('updatedAt');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should include role', () => {
|
|
57
|
+
expect(response.body).toHaveProperty('role');
|
|
58
|
+
expect(response.body.role).toBe('superuser');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('as admin', () => {
|
|
63
|
+
let response: Response;
|
|
64
|
+
|
|
65
|
+
beforeAll(async () => {
|
|
66
|
+
response = await app.request
|
|
67
|
+
.get('/v1/user')
|
|
68
|
+
.set('Cookie', adminCookie);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should return 200', () => {
|
|
72
|
+
expect(response.status).toBe(200);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should return admin user data', () => {
|
|
76
|
+
expect(response.body.email).toBe(TEST_ADMIN.email);
|
|
77
|
+
expect(response.body.name).toBe(TEST_ADMIN.name);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should have admin role', () => {
|
|
81
|
+
expect(response.body.role).toBe('admin');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('as regular user', () => {
|
|
86
|
+
let response: Response;
|
|
87
|
+
|
|
88
|
+
beforeAll(async () => {
|
|
89
|
+
response = await app.request
|
|
90
|
+
.get('/v1/user')
|
|
91
|
+
.set('Cookie', userCookie);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should return 200', () => {
|
|
95
|
+
expect(response.status).toBe(200);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should return regular user data', () => {
|
|
99
|
+
expect(response.body.email).toBe(TEST_USER.email);
|
|
100
|
+
expect(response.body.name).toBe(TEST_USER.name);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should have user role', () => {
|
|
104
|
+
expect(response.body.role).toBe('user');
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('without authentication', () => {
|
|
109
|
+
let response: Response;
|
|
110
|
+
|
|
111
|
+
beforeAll(async () => {
|
|
112
|
+
response = await app.request.get('/v1/user');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should return 401', () => {
|
|
116
|
+
expect(response.status).toBe(401);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe('response shape', () => {
|
|
121
|
+
let response: Response;
|
|
122
|
+
|
|
123
|
+
beforeAll(async () => {
|
|
124
|
+
response = await app.request
|
|
125
|
+
.get('/v1/user')
|
|
126
|
+
.set('Cookie', userCookie);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('should not expose banned fields', () => {
|
|
130
|
+
expect(response.body).not.toHaveProperty('banned');
|
|
131
|
+
expect(response.body).not.toHaveProperty('banReason');
|
|
132
|
+
expect(response.body).not.toHaveProperty('banExpires');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should have image field (nullable)', () => {
|
|
136
|
+
expect(response.body).toHaveProperty('image');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should have emailVerified as boolean', () => {
|
|
140
|
+
expect(typeof response.body.emailVerified).toBe('boolean');
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe('GET: /user (without version)', () => {
|
|
146
|
+
it('should return 404 when version prefix is missing', async () => {
|
|
147
|
+
const response = await app.request
|
|
148
|
+
.get('/user')
|
|
149
|
+
.set('Cookie', userCookie);
|
|
150
|
+
expect(response.status).toBe(404);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { INestApplication } from '@nestjs/common';
|
|
2
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
3
|
+
import supertest from 'supertest';
|
|
4
|
+
import { vi } from 'vitest';
|
|
5
|
+
import { AppModule } from 'app.module';
|
|
6
|
+
import { CustomConfigService, PrismaService } from 'common/services';
|
|
7
|
+
import { CacheService } from 'common/services'; // @feature cache
|
|
8
|
+
import { MailService } from 'common/services'; // @feature mail
|
|
9
|
+
import { FeatureFlagService } from 'common/services'; // @feature feature-flags
|
|
10
|
+
import { MediaService } from 'media/services'; // @feature media
|
|
11
|
+
import Seeder from '@seeders/util';
|
|
12
|
+
import * as setup from 'app.setup';
|
|
13
|
+
|
|
14
|
+
type Cookie = string[] | undefined;
|
|
15
|
+
|
|
16
|
+
// @feature:start feature-flags
|
|
17
|
+
/** Per-spec overrides for the integrations AppFactory replaces. */
|
|
18
|
+
type AppFactoryOverrides = {
|
|
19
|
+
flags?: Partial<FeatureFlagService>;
|
|
20
|
+
};
|
|
21
|
+
// @feature:end
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Boots the *real* Nest application against the real test Postgres and Redis —
|
|
25
|
+
* only the outbound integrations are replaced. Mirrors `app.setup.ts`, so a
|
|
26
|
+
* global pipe or filter added there has to be added here too or e2e will pass
|
|
27
|
+
* on behaviour production does not have.
|
|
28
|
+
*
|
|
29
|
+
* Always `await app.close()` in `afterAll`: it triggers `refresh()`, and a spec
|
|
30
|
+
* that skips it leaves rows behind for the next one.
|
|
31
|
+
*/
|
|
32
|
+
export class AppFactory {
|
|
33
|
+
private constructor(private readonly app: INestApplication) {}
|
|
34
|
+
|
|
35
|
+
get instance() {
|
|
36
|
+
return this.app;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get server() {
|
|
40
|
+
return this.app.getHttpServer();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
get request() {
|
|
44
|
+
return supertest(this.server);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get db() {
|
|
48
|
+
return this.app.get(PrismaService);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// @feature:start cache
|
|
52
|
+
get cache() {
|
|
53
|
+
return this.app.get(CacheService);
|
|
54
|
+
}
|
|
55
|
+
// @feature:end
|
|
56
|
+
|
|
57
|
+
get config() {
|
|
58
|
+
return this.app.get(CustomConfigService);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async refresh() {
|
|
62
|
+
await this.db.truncate();
|
|
63
|
+
await this.cache.truncate(); // @feature cache
|
|
64
|
+
await this.seed();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async seed() {
|
|
68
|
+
await Seeder.setup(this.db).seed(this.config.superuser, true);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async signIn(email: string, password: string) {
|
|
72
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
73
|
+
const response = await this.request.post('/auth/sign-in/email').send({
|
|
74
|
+
email,
|
|
75
|
+
password
|
|
76
|
+
});
|
|
77
|
+
errorSpy.mockRestore();
|
|
78
|
+
|
|
79
|
+
const setCookie = response.headers['set-cookie'] as unknown as Cookie;
|
|
80
|
+
const cookie = setCookie?.[0];
|
|
81
|
+
return { cookie, response };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async close() {
|
|
85
|
+
await this.refresh();
|
|
86
|
+
await this.app.close();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static async init(
|
|
90
|
+
overrides: AppFactoryOverrides = {} // @feature feature-flags
|
|
91
|
+
) {
|
|
92
|
+
// @feature:start mail
|
|
93
|
+
// No-op MailService so nothing is enqueued to the BullMQ `mail` queue.
|
|
94
|
+
// cache.truncate() (Redis flushall) runs between specs and would wipe
|
|
95
|
+
// in-flight job keys, making the worker throw "Missing key for job N".
|
|
96
|
+
// (Listed explicitly — a Proxy that answers every prop, incl. `then`,
|
|
97
|
+
// makes this look thenable and Nest DI hangs awaiting it.)
|
|
98
|
+
const mailMock: Record<keyof MailService, ReturnType<typeof vi.fn>> = {
|
|
99
|
+
activation: vi.fn(),
|
|
100
|
+
activationTwofa: vi.fn(),
|
|
101
|
+
welcome: vi.fn(),
|
|
102
|
+
forgotPassword: vi.fn(),
|
|
103
|
+
resetPassword: vi.fn(),
|
|
104
|
+
passwordChanged: vi.fn(),
|
|
105
|
+
setPassword: vi.fn()
|
|
106
|
+
};
|
|
107
|
+
// @feature:end
|
|
108
|
+
|
|
109
|
+
// @feature:start feature-flags
|
|
110
|
+
// Treat every feature flag as ON in tests by default, so flag-gated
|
|
111
|
+
// routes behave deterministically without reaching the real GrowthBook
|
|
112
|
+
// API at boot. Specs can override per-flag behaviour via `overrides.flags`.
|
|
113
|
+
const flagsMock: Partial<FeatureFlagService> = {
|
|
114
|
+
isOn: () => true,
|
|
115
|
+
isOff: () => false,
|
|
116
|
+
getValue: (_key, defaultValue) => defaultValue as never,
|
|
117
|
+
refresh: vi.fn(),
|
|
118
|
+
...overrides.flags
|
|
119
|
+
};
|
|
120
|
+
// @feature:end
|
|
121
|
+
|
|
122
|
+
// @feature:start media
|
|
123
|
+
// In-memory MediaService so uploads never touch real S3. Buffers are kept
|
|
124
|
+
// keyed by their fake URL so an async worker can re-read what was uploaded.
|
|
125
|
+
const mediaFiles = new Map<string, Buffer>();
|
|
126
|
+
const mediaMock: Partial<Record<keyof MediaService, unknown>> = {
|
|
127
|
+
uploadAvatar: vi.fn(async () => 'https://test.local/avatars/mock.png'),
|
|
128
|
+
uploadFile: vi.fn(async (file: Express.Multer.File) => {
|
|
129
|
+
const url = `https://test.local/uploads/${Math.random()
|
|
130
|
+
.toString(36)
|
|
131
|
+
.slice(2)}`;
|
|
132
|
+
mediaFiles.set(url, file.buffer);
|
|
133
|
+
return url;
|
|
134
|
+
}),
|
|
135
|
+
getFileBuffer: vi.fn(
|
|
136
|
+
async (url: string) => mediaFiles.get(url) ?? Buffer.alloc(0)
|
|
137
|
+
),
|
|
138
|
+
deleteFile: vi.fn(async () => {})
|
|
139
|
+
};
|
|
140
|
+
// @feature:end
|
|
141
|
+
|
|
142
|
+
const module: TestingModule = await Test.createTestingModule({
|
|
143
|
+
imports: [AppModule]
|
|
144
|
+
})
|
|
145
|
+
.overrideProvider(MailService) // @feature mail
|
|
146
|
+
.useValue(mailMock) // @feature mail
|
|
147
|
+
.overrideProvider(MediaService) // @feature media
|
|
148
|
+
.useValue(mediaMock) // @feature media
|
|
149
|
+
.overrideProvider(FeatureFlagService) // @feature feature-flags
|
|
150
|
+
.useValue(flagsMock) // @feature feature-flags
|
|
151
|
+
.compile();
|
|
152
|
+
|
|
153
|
+
const app = module.createNestApplication({
|
|
154
|
+
bodyParser: false,
|
|
155
|
+
bufferLogs: true
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
setup.usePinoLogger(app);
|
|
159
|
+
setup.enableVersioning(app);
|
|
160
|
+
setup.setStatic(app);
|
|
161
|
+
setup.enableJsonBodyParser(app);
|
|
162
|
+
setup.useGlobalPipes(app);
|
|
163
|
+
setup.useGlobalInterceptors(app);
|
|
164
|
+
setup.useGlobalFilters(app);
|
|
165
|
+
await setup.enableOpenAPI(app); // @feature openapi
|
|
166
|
+
setup.enableCors(app);
|
|
167
|
+
setup.enableHelmet(app);
|
|
168
|
+
|
|
169
|
+
await app.init();
|
|
170
|
+
return new AppFactory(app);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
|
|
3
|
+
export const SUPER_USER = {
|
|
4
|
+
name: 'Super User',
|
|
5
|
+
email: process.env.SUPERUSER_EMAIL || 'superuser@example.com',
|
|
6
|
+
password: process.env.SUPERUSER_PASSWORD || 'Secret@1',
|
|
7
|
+
role: 'superuser'
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const TEST_ADMIN = {
|
|
11
|
+
name: 'Test Admin',
|
|
12
|
+
email: 'test.admin@example.com',
|
|
13
|
+
password: 'secret',
|
|
14
|
+
role: 'admin'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const TEST_USER = {
|
|
18
|
+
name: 'Test User',
|
|
19
|
+
email: 'test.user@example.com',
|
|
20
|
+
password: 'secret',
|
|
21
|
+
role: 'user'
|
|
22
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Factory } from 'fishery';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import { CommonFilters } from 'common/dto';
|
|
4
|
+
import { UserFilters } from 'users/dto'; // @feature users
|
|
5
|
+
|
|
6
|
+
export class Dto {
|
|
7
|
+
/**
|
|
8
|
+
* Run a request schema over `plain` the way the validation pipe does, and
|
|
9
|
+
* return the Zod result (`success`, then `data` or `error`).
|
|
10
|
+
*/
|
|
11
|
+
static parse<T extends z.ZodType>(schema: T, plain: unknown) {
|
|
12
|
+
return schema.safeParse(plain);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static get commonFilters() {
|
|
16
|
+
return Factory.define<CommonFilters>(() => ({}));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// @feature:start users
|
|
20
|
+
static get userFilters() {
|
|
21
|
+
return Factory.define<UserFilters>(() => ({
|
|
22
|
+
page: 1,
|
|
23
|
+
limit: 10
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
// @feature:end
|
|
27
|
+
}
|