@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,106 @@
|
|
|
1
|
+
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
|
2
|
+
import { PrismaPg } from '@prisma/adapter-pg';
|
|
3
|
+
import { PaginationOptions } from 'common/types';
|
|
4
|
+
import { Prisma, PrismaClient } from '@db/client';
|
|
5
|
+
import { getPaginationInfo } from '../utils';
|
|
6
|
+
import type { PaginationMeta } from '../entity';
|
|
7
|
+
import { CustomConfigService } from './config.service';
|
|
8
|
+
|
|
9
|
+
type TableNames = Array<{ tablename: string }>;
|
|
10
|
+
|
|
11
|
+
const setupExtensions = (db: PrismaClient) =>
|
|
12
|
+
db.$extends({
|
|
13
|
+
model: {
|
|
14
|
+
$allModels: {
|
|
15
|
+
async exists<
|
|
16
|
+
Type,
|
|
17
|
+
Arguments,
|
|
18
|
+
Result extends Prisma.Result<Type, Arguments, 'count'>
|
|
19
|
+
>(this: Type, where: Prisma.Args<Type, 'count'>['where']) {
|
|
20
|
+
const ctx = Prisma.getExtensionContext(this) as any;
|
|
21
|
+
const counts: Result = await ctx.count({ where });
|
|
22
|
+
return Boolean(counts);
|
|
23
|
+
},
|
|
24
|
+
async paginate<
|
|
25
|
+
Type,
|
|
26
|
+
Args extends Omit<
|
|
27
|
+
Prisma.Args<Type, 'findMany'>,
|
|
28
|
+
'skip' | 'take' | 'cursor'
|
|
29
|
+
>,
|
|
30
|
+
Result extends Prisma.Result<Type, Args, 'findMany'>
|
|
31
|
+
>(this: Type, args: Args & PaginationOptions) {
|
|
32
|
+
const { limit, page, where, ...rest } = args;
|
|
33
|
+
const {
|
|
34
|
+
skip,
|
|
35
|
+
take,
|
|
36
|
+
page: currentPage
|
|
37
|
+
} = getPaginationInfo({
|
|
38
|
+
limit,
|
|
39
|
+
page
|
|
40
|
+
});
|
|
41
|
+
const ctx = Prisma.getExtensionContext(this) as any;
|
|
42
|
+
const [list, total]: [Result, number] = await Promise.all([
|
|
43
|
+
ctx.findMany({ ...rest, skip, take, where }),
|
|
44
|
+
ctx.count({ where })
|
|
45
|
+
]);
|
|
46
|
+
const meta: PaginationMeta = {
|
|
47
|
+
total,
|
|
48
|
+
currentPage,
|
|
49
|
+
pageSize: list.length,
|
|
50
|
+
lastPage: Math.ceil(total / take) || 1
|
|
51
|
+
};
|
|
52
|
+
const result: [Result, PaginationMeta] = [list, meta];
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
@Injectable()
|
|
60
|
+
export class PrismaService
|
|
61
|
+
extends PrismaClient
|
|
62
|
+
implements OnModuleInit, OnModuleDestroy
|
|
63
|
+
{
|
|
64
|
+
constructor(private readonly c: CustomConfigService) {
|
|
65
|
+
const adapter = new PrismaPg({
|
|
66
|
+
connectionString: c.database.url
|
|
67
|
+
});
|
|
68
|
+
super({
|
|
69
|
+
adapter,
|
|
70
|
+
transactionOptions: {
|
|
71
|
+
isolationLevel: Prisma.TransactionIsolationLevel.Serializable,
|
|
72
|
+
maxWait: 6000,
|
|
73
|
+
timeout: 150000
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get x() {
|
|
79
|
+
return setupExtensions(this);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async onModuleInit() {
|
|
83
|
+
await this.$connect();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async onModuleDestroy() {
|
|
87
|
+
await this.$disconnect();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async truncate() {
|
|
91
|
+
const tableNames = await this
|
|
92
|
+
.$queryRaw<TableNames>`SELECT tablename from pg_tables where schemaname='public'`;
|
|
93
|
+
|
|
94
|
+
const tables = tableNames
|
|
95
|
+
.map(({ tablename }) => tablename)
|
|
96
|
+
.filter((name) => name !== '_prisma_migrations')
|
|
97
|
+
.map((name) => `"public"."${name}"`)
|
|
98
|
+
.join(', ');
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
await this.$executeRawUnsafe(`TRUNCATE TABLE ${tables} CASCADE;`);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.log({ error });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { ThrottlerStorage } from '@nestjs/throttler';
|
|
3
|
+
import { ThrottlerStorageRecord } from '@nestjs/throttler/dist/throttler-storage-record.interface';
|
|
4
|
+
import type IoRedis from 'ioredis';
|
|
5
|
+
import { CacheService } from './cache.service';
|
|
6
|
+
|
|
7
|
+
const HITS_PREFIX = 'throttle';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Increment the hit counter and decide whether the tracker is blocked, in a
|
|
11
|
+
* single round-trip. Splitting this into INCR + PTTL + SET would let two
|
|
12
|
+
* concurrent requests both observe a below-limit count.
|
|
13
|
+
*
|
|
14
|
+
* KEYS: hits, block. ARGV: ttl(ms), limit, blockDuration(ms).
|
|
15
|
+
* Returns: { totalHits, hitsPttl(ms), isBlocked(0|1), blockPttl(ms) }.
|
|
16
|
+
*/
|
|
17
|
+
const INCREMENT_SCRIPT = `
|
|
18
|
+
local hitsKey = KEYS[1]
|
|
19
|
+
local blockKey = KEYS[2]
|
|
20
|
+
local ttl = tonumber(ARGV[1])
|
|
21
|
+
local limit = tonumber(ARGV[2])
|
|
22
|
+
local blockDuration = tonumber(ARGV[3])
|
|
23
|
+
|
|
24
|
+
-- Already serving a block: report it without consuming another hit.
|
|
25
|
+
local blockPttl = redis.call('PTTL', blockKey)
|
|
26
|
+
if blockPttl > 0 then
|
|
27
|
+
local hits = tonumber(redis.call('GET', hitsKey)) or (limit + 1)
|
|
28
|
+
local hitsPttl = redis.call('PTTL', hitsKey)
|
|
29
|
+
if hitsPttl < 0 then hitsPttl = 0 end
|
|
30
|
+
return { hits, hitsPttl, 1, blockPttl }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
local hits = redis.call('INCR', hitsKey)
|
|
34
|
+
if hits == 1 then
|
|
35
|
+
redis.call('PEXPIRE', hitsKey, ttl)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
local hitsPttl = redis.call('PTTL', hitsKey)
|
|
39
|
+
if hitsPttl < 0 then
|
|
40
|
+
-- Key exists without a TTL (or raced with expiry); re-arm the window.
|
|
41
|
+
redis.call('PEXPIRE', hitsKey, ttl)
|
|
42
|
+
hitsPttl = ttl
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
if hits > limit then
|
|
46
|
+
redis.call('SET', blockKey, '1', 'PX', blockDuration)
|
|
47
|
+
return { hits, hitsPttl, 1, blockDuration }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
return { hits, hitsPttl, 0, 0 }
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
type IncrementResult = [number, number, number, number];
|
|
54
|
+
|
|
55
|
+
type ThrottlerRedis = IoRedis & {
|
|
56
|
+
throttlerIncrement(
|
|
57
|
+
hitsKey: string,
|
|
58
|
+
blockKey: string,
|
|
59
|
+
ttl: number,
|
|
60
|
+
limit: number,
|
|
61
|
+
blockDuration: number
|
|
62
|
+
): Promise<IncrementResult>;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Redis-backed {@link ThrottlerStorage}, sharing the ioredis connection already
|
|
67
|
+
* opened by {@link CacheService}. In-memory storage would give each process its
|
|
68
|
+
* own buckets, which is wrong as soon as more than one instance runs.
|
|
69
|
+
*
|
|
70
|
+
* `ttl` and `blockDuration` arrive in milliseconds; `timeToExpire` and
|
|
71
|
+
* `timeToBlockExpire` are returned in seconds, matching `ThrottlerStorageService`.
|
|
72
|
+
*/
|
|
73
|
+
@Injectable()
|
|
74
|
+
export class RedisThrottlerStorage implements ThrottlerStorage {
|
|
75
|
+
private readonly redis: ThrottlerRedis;
|
|
76
|
+
|
|
77
|
+
constructor(private readonly cache: CacheService) {
|
|
78
|
+
this.redis = this.cache.db as ThrottlerRedis;
|
|
79
|
+
this.redis.defineCommand('throttlerIncrement', {
|
|
80
|
+
numberOfKeys: 2,
|
|
81
|
+
lua: INCREMENT_SCRIPT
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async increment(
|
|
86
|
+
key: string,
|
|
87
|
+
ttl: number,
|
|
88
|
+
limit: number,
|
|
89
|
+
blockDuration: number,
|
|
90
|
+
throttlerName: string
|
|
91
|
+
): Promise<ThrottlerStorageRecord> {
|
|
92
|
+
const hitsKey = `${HITS_PREFIX}:${throttlerName}:${key}`;
|
|
93
|
+
const [totalHits, hitsPttl, isBlocked, blockPttl] =
|
|
94
|
+
await this.redis.throttlerIncrement(
|
|
95
|
+
hitsKey,
|
|
96
|
+
`${hitsKey}:block`,
|
|
97
|
+
ttl,
|
|
98
|
+
limit,
|
|
99
|
+
blockDuration
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
totalHits,
|
|
104
|
+
timeToExpire: toSeconds(hitsPttl),
|
|
105
|
+
isBlocked: isBlocked === 1,
|
|
106
|
+
timeToBlockExpire: toSeconds(blockPttl)
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const toSeconds = (milliseconds: number) =>
|
|
112
|
+
Math.ceil(Math.max(milliseconds, 0) / 1000);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export enum MailJob {
|
|
2
|
+
Activation = 'activation',
|
|
3
|
+
ActivationTwofa = 'activation-twofa',
|
|
4
|
+
ForgotPassword = 'forgot-password',
|
|
5
|
+
PasswordChanged = 'password-changed',
|
|
6
|
+
ResetPassword = 'reset-password',
|
|
7
|
+
SetPassword = 'set-password',
|
|
8
|
+
Welcome = 'welcome'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface EmailGlobalProps {
|
|
12
|
+
host: string;
|
|
13
|
+
appName: string;
|
|
14
|
+
footerText: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface EmailBaseProps extends EmailGlobalProps {
|
|
18
|
+
subject: string;
|
|
19
|
+
preview?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type EmailProps<T extends { to: string }> = Omit<T, 'to'> &
|
|
23
|
+
EmailBaseProps;
|
|
24
|
+
|
|
25
|
+
export interface ActivationData {
|
|
26
|
+
to: string;
|
|
27
|
+
firstName: string;
|
|
28
|
+
token: string;
|
|
29
|
+
url: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ActivationTwoFaData {
|
|
33
|
+
to: string;
|
|
34
|
+
firstName: string;
|
|
35
|
+
qrcode: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ForgotPasswordData {
|
|
39
|
+
to: string;
|
|
40
|
+
token: string;
|
|
41
|
+
url: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface SetPasswordData {
|
|
45
|
+
to: string;
|
|
46
|
+
firstName: string;
|
|
47
|
+
token: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface WelcomeData {
|
|
51
|
+
to: string;
|
|
52
|
+
firstName: string;
|
|
53
|
+
clientLoginPage: string;
|
|
54
|
+
supportEmail: string;
|
|
55
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface PaginationOptions {
|
|
2
|
+
page?: number;
|
|
3
|
+
limit?: number;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface PaginationInfo {
|
|
7
|
+
skip: number;
|
|
8
|
+
take: number;
|
|
9
|
+
page: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SortNesting {
|
|
13
|
+
key: string;
|
|
14
|
+
values: string[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface SortObjectArg {
|
|
18
|
+
sort?: string;
|
|
19
|
+
nesting?: SortNesting[];
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PrismaClient } from '@db/client';
|
|
2
|
+
|
|
3
|
+
export type PrismaModelName = keyof Omit<
|
|
4
|
+
PrismaClient,
|
|
5
|
+
| '$on'
|
|
6
|
+
| '$connect'
|
|
7
|
+
| '$disconnect'
|
|
8
|
+
| '$extends'
|
|
9
|
+
| '$use'
|
|
10
|
+
| '$queryRaw'
|
|
11
|
+
| '$executeRaw'
|
|
12
|
+
| '$executeRawUnsafe'
|
|
13
|
+
| '$queryRawUnsafe'
|
|
14
|
+
| '$transaction'
|
|
15
|
+
| symbol
|
|
16
|
+
>;
|
|
17
|
+
|
|
18
|
+
export type PrismaModel<Name extends PrismaModelName> = PrismaClient[Name];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Gender as G } from '@db/enums';
|
|
2
|
+
namespace Enum {
|
|
3
|
+
/**
|
|
4
|
+
* S3 key prefixes. Add a folder here rather than passing a raw string, and
|
|
5
|
+
* list it in `PrivateUploadFolders` if its objects must not be publicly
|
|
6
|
+
* readable — that set is what decides the object ACL on upload, so an
|
|
7
|
+
* omission silently makes private files world-readable.
|
|
8
|
+
*/
|
|
9
|
+
export enum UploadFolder {
|
|
10
|
+
AVATARS = 'avatars',
|
|
11
|
+
UPLOAD = 'upload',
|
|
12
|
+
PRIVATE = 'private'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const PrivateUploadFolders: ReadonlySet<UploadFolder> = new Set([
|
|
16
|
+
UploadFolder.PRIVATE
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
export const isPrivateUploadFolder = (folder: UploadFolder) =>
|
|
20
|
+
PrivateUploadFolders.has(folder);
|
|
21
|
+
|
|
22
|
+
export enum Gender {
|
|
23
|
+
MALE = 'male',
|
|
24
|
+
FEMALE = 'female'
|
|
25
|
+
}
|
|
26
|
+
export type UserGender = G | Gender;
|
|
27
|
+
export const Genders = Object.values(Gender);
|
|
28
|
+
export const gendersErrorMessage = () => {
|
|
29
|
+
const GENDER: Record<Gender, string> = {
|
|
30
|
+
[Gender.MALE]: 'male',
|
|
31
|
+
[Gender.FEMALE]: 'female'
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const genders = Genders.map((g) => `${g} (${GENDER[g]})`).join(', ');
|
|
35
|
+
return `genderId must be one of [${genders}]`;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default Enum;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PaginationInfo,
|
|
3
|
+
PaginationOptions,
|
|
4
|
+
SortNesting,
|
|
5
|
+
SortObjectArg
|
|
6
|
+
} from 'common/types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Check if an enum includes specified value
|
|
10
|
+
* @param type - Type of the enum to check
|
|
11
|
+
* @param value - Value to check
|
|
12
|
+
*/
|
|
13
|
+
export const isInEnum = <T extends ArrayLike<unknown>, U extends keyof T>(
|
|
14
|
+
type: T,
|
|
15
|
+
value: U
|
|
16
|
+
) => Object.values(type).includes(value);
|
|
17
|
+
|
|
18
|
+
export const getPaginationInfo = (
|
|
19
|
+
options: PaginationOptions
|
|
20
|
+
): PaginationInfo => {
|
|
21
|
+
const page = options.page && options.page > 0 ? options.page : 1;
|
|
22
|
+
const take = options.limit && options.limit > 0 ? options.limit : 10;
|
|
23
|
+
return {
|
|
24
|
+
skip: (page - 1) * take,
|
|
25
|
+
take,
|
|
26
|
+
page
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Parse a value as boolean
|
|
32
|
+
* @param value - value to check
|
|
33
|
+
* @param defaultValue - default value to return for an invalid `value`
|
|
34
|
+
*/
|
|
35
|
+
export const parseBoolean = (
|
|
36
|
+
value: string | number | null | undefined,
|
|
37
|
+
defaultValue = false
|
|
38
|
+
): boolean => {
|
|
39
|
+
if (value === '' || value === null || value === undefined) {
|
|
40
|
+
return defaultValue;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (typeof value === 'string') {
|
|
44
|
+
if (value.trim() === '') {
|
|
45
|
+
return defaultValue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const toCheck = value.trim().toLowerCase();
|
|
49
|
+
if (toCheck === '1' || toCheck === 'true' || toCheck === 'yes') {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (typeof value === 'number') {
|
|
55
|
+
if (value >= 1) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* It takes an array of any type and returns a random item from that array
|
|
65
|
+
* @param arr - The array to get a random item from.
|
|
66
|
+
*/
|
|
67
|
+
export const getRandomArrayItem = <T>(arr: T[]) =>
|
|
68
|
+
arr[Math.floor(Math.random() * arr.length)];
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* "Convert a string to lowercase, optionally capitalizing the first letter."
|
|
72
|
+
*
|
|
73
|
+
* @param str - The string to be converted to lowercase.
|
|
74
|
+
* @param capitalizeFirstLetter - If true, the first letter of the string will
|
|
75
|
+
* be capitalized.
|
|
76
|
+
*/
|
|
77
|
+
export const lowercase = (str: string, capitalizeFirstLetter = false) => {
|
|
78
|
+
const result = str.trim().toLocaleLowerCase();
|
|
79
|
+
|
|
80
|
+
return capitalizeFirstLetter
|
|
81
|
+
? result.replace(/^[a-z]/, (letter) => letter.toUpperCase())
|
|
82
|
+
: result;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const isValidUUID = (value: string) => {
|
|
86
|
+
const uuidPattern =
|
|
87
|
+
/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
|
|
88
|
+
|
|
89
|
+
return uuidPattern.test(value);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Create sort objects from a string
|
|
94
|
+
* @param sort - the string to convert to a sort object
|
|
95
|
+
* @returns the sort object
|
|
96
|
+
*/
|
|
97
|
+
export function createSortObject<T = any>(
|
|
98
|
+
options: SortObjectArg | undefined
|
|
99
|
+
): T[];
|
|
100
|
+
export function createSortObject<T = any>(sort?: string): T[];
|
|
101
|
+
export function createSortObject<T = any>(
|
|
102
|
+
param: SortObjectArg | string | undefined
|
|
103
|
+
): T[] {
|
|
104
|
+
const list: T[] = [];
|
|
105
|
+
|
|
106
|
+
let sort: string | undefined;
|
|
107
|
+
let nesting: SortNesting[] | undefined;
|
|
108
|
+
|
|
109
|
+
if (!param) return list;
|
|
110
|
+
|
|
111
|
+
if (typeof param === 'string') {
|
|
112
|
+
sort = param;
|
|
113
|
+
} else {
|
|
114
|
+
sort = param.sort;
|
|
115
|
+
nesting = param.nesting;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (!sort) return list;
|
|
119
|
+
|
|
120
|
+
const keys = sort.split(',');
|
|
121
|
+
keys.forEach((key) => {
|
|
122
|
+
const name = key.replace(/^-/, '');
|
|
123
|
+
const value = key.startsWith('-') ? 'desc' : 'asc';
|
|
124
|
+
const obj: T = { [name]: value } as T;
|
|
125
|
+
|
|
126
|
+
if (!nesting || !nesting.length) {
|
|
127
|
+
list.push(obj);
|
|
128
|
+
} else {
|
|
129
|
+
const nest = nesting.find((n) => n.values.includes(name));
|
|
130
|
+
if (!nest) {
|
|
131
|
+
list.push(obj);
|
|
132
|
+
} else {
|
|
133
|
+
list.push({ [nest.key]: obj } as T);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
return list;
|
|
139
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the client IP from proxy headers, falling back to the socket address.
|
|
3
|
+
*
|
|
4
|
+
* Behind a reverse proxy every request carries the proxy's socket address, so
|
|
5
|
+
* rate-limit buckets keyed on it would be shared by all clients. `x-forwarded-for`
|
|
6
|
+
* is a comma-separated chain (`client, proxy1, proxy2`) — the client is first.
|
|
7
|
+
*/
|
|
8
|
+
export const getClientIp = (
|
|
9
|
+
req: Record<string, any>,
|
|
10
|
+
headerNames: string[]
|
|
11
|
+
): string => {
|
|
12
|
+
const headers = (req.headers ?? {}) as Record<string, string | string[]>;
|
|
13
|
+
|
|
14
|
+
for (const name of headerNames) {
|
|
15
|
+
const raw = headers[name];
|
|
16
|
+
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
17
|
+
const first = value?.split(',')[0]?.trim();
|
|
18
|
+
if (first) return first;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return req.ip ?? req.socket?.remoteAddress ?? 'unknown';
|
|
22
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { BadRequestException } from '@nestjs/common';
|
|
2
|
+
import type { PrismaService } from '../services';
|
|
3
|
+
import type { PrismaModelName } from '../types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Database-backed checks for request values. A schema validates shape without
|
|
7
|
+
* a database handle, so these run in the service that uses the value. Matching
|
|
8
|
+
* is case-insensitive, and failures are 400s in the same `Validation: …` form
|
|
9
|
+
* the validation pipe produces.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const matches = (
|
|
13
|
+
db: PrismaService,
|
|
14
|
+
model: PrismaModelName,
|
|
15
|
+
field: string,
|
|
16
|
+
value: string
|
|
17
|
+
): Promise<boolean> =>
|
|
18
|
+
(db.x[model] as any).exists({
|
|
19
|
+
[field]: { equals: value, mode: 'insensitive' }
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/** Reject `value` unless some `model` row has it in `field`. Skips empties. */
|
|
23
|
+
export async function ensureExists(
|
|
24
|
+
db: PrismaService,
|
|
25
|
+
model: PrismaModelName,
|
|
26
|
+
field: string,
|
|
27
|
+
value: string | null | undefined
|
|
28
|
+
) {
|
|
29
|
+
if (!value) return;
|
|
30
|
+
if (!(await matches(db, model, field, value))) {
|
|
31
|
+
throw new BadRequestException(
|
|
32
|
+
`Validation: ${field} '${value}' does not exist`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Reject `values` unless every one exists in `model`.`field`. */
|
|
38
|
+
export async function ensureEachExists(
|
|
39
|
+
db: PrismaService,
|
|
40
|
+
model: PrismaModelName,
|
|
41
|
+
field: string,
|
|
42
|
+
values: readonly string[] | null | undefined
|
|
43
|
+
) {
|
|
44
|
+
for (const value of values ?? []) {
|
|
45
|
+
if (!(await matches(db, model, field, value))) {
|
|
46
|
+
throw new BadRequestException(
|
|
47
|
+
`Validation: ${field} element with id '${value}' does not exist`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Reject `value` if a `model` row already has it in `field`. */
|
|
54
|
+
export async function ensureUnique(
|
|
55
|
+
db: PrismaService,
|
|
56
|
+
model: PrismaModelName,
|
|
57
|
+
field: string,
|
|
58
|
+
value: string | null | undefined
|
|
59
|
+
) {
|
|
60
|
+
if (!value) return;
|
|
61
|
+
if (await matches(db, model, field, value)) {
|
|
62
|
+
throw new BadRequestException(
|
|
63
|
+
`Validation: ${field} '${value}' already exists`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { User } from '@db/client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Namespaced Redis keys for hash-cached entities.
|
|
5
|
+
*
|
|
6
|
+
* Adding a cached entity means three matching edits: a `Type` member (the hash
|
|
7
|
+
* key), a `TypeEntityMap` entry (what a member deserializes to), and an `ID`
|
|
8
|
+
* builder (the field key). They are kept in one file precisely so a mismatch
|
|
9
|
+
* shows up here rather than as a runtime cache miss.
|
|
10
|
+
*/
|
|
11
|
+
export namespace Key {
|
|
12
|
+
type IdType = number | string;
|
|
13
|
+
|
|
14
|
+
export enum Type {
|
|
15
|
+
Users = 'users'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type TypeKey = keyof typeof Type;
|
|
19
|
+
|
|
20
|
+
type TypeEntityMap = {
|
|
21
|
+
Users: User;
|
|
22
|
+
};
|
|
23
|
+
export type EntityMap<T extends TypeKey> = TypeEntityMap[T];
|
|
24
|
+
|
|
25
|
+
const ID: Record<Type, <T = IdType>(id: T) => string> = {
|
|
26
|
+
[Type.Users]: (id) => `uid:${id}`
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const id = <T = IdType>(typeKey: TypeKey, key: T) =>
|
|
30
|
+
ID[Type[typeKey]](key);
|
|
31
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { hasPermission } from 'lib/access';
|
|
2
|
+
|
|
3
|
+
describe('hasPermission', () => {
|
|
4
|
+
it('grants a permission the role holds', () => {
|
|
5
|
+
expect(hasPermission('user', { session: ['list'] })).toBe(true);
|
|
6
|
+
expect(hasPermission('user', { session: ['list', 'revoke'] })).toBe(true);
|
|
7
|
+
expect(hasPermission('admin', { user: ['ban'] })).toBe(true);
|
|
8
|
+
expect(hasPermission('superuser', { user: ['delete'] })).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('denies a permission the role lacks', () => {
|
|
12
|
+
expect(hasPermission('user', { user: ['list'] })).toBe(false);
|
|
13
|
+
expect(hasPermission('user', { user: ['delete'] })).toBe(false);
|
|
14
|
+
expect(hasPermission('admin', { user: ['delete'] })).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("treats a missing role as the admin plugin's defaultRole", () => {
|
|
18
|
+
expect(hasPermission(null, { session: ['list'] })).toBe(true);
|
|
19
|
+
expect(hasPermission(undefined, { session: ['list'] })).toBe(true);
|
|
20
|
+
expect(hasPermission('', { session: ['list'] })).toBe(true);
|
|
21
|
+
// ...but the default role is still only a `user`.
|
|
22
|
+
expect(hasPermission(null, { user: ['delete'] })).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('fails closed on an unrecognized role', () => {
|
|
26
|
+
expect(hasPermission('bogus', { session: ['list'] })).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('unions comma-separated roles, ignoring unknown ones', () => {
|
|
30
|
+
expect(hasPermission('bogus,user', { session: ['list'] })).toBe(true);
|
|
31
|
+
expect(hasPermission('user, admin', { user: ['ban'] })).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
});
|