create-tigra 3.2.0 → 4.0.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/README.md +81 -12
- package/bin/create-tigra.js +495 -472
- package/lib/patchers/email-verification.patcher.js +160 -44
- package/modules/email-verification/client/hooks/useVerification.ts +4 -1
- package/modules/email-verification/server/__tests__/verification.integration.test.ts +115 -0
- package/modules/email-verification/server/verification.controller.ts +3 -1
- package/modules/email-verification/server/verification.service.ts +81 -21
- package/package.json +3 -2
- package/template/.github/dependabot.yml +47 -0
- package/template/.github/workflows/audit.yml +36 -0
- package/template/.github/workflows/ci.yml +79 -0
- package/template/AGENTS.md +18 -9
- package/template/client/.dockerignore +1 -0
- package/template/client/.env.example.production +13 -2
- package/template/client/AGENTS.md +13 -5
- package/template/client/Dockerfile +186 -14
- package/template/client/next.config.ts +1 -1
- package/template/client/package-lock.json +15983 -14181
- package/template/client/package.json +56 -48
- package/template/client/scripts/check-sharp.mjs +53 -0
- package/template/client/scripts/next-dev.cjs +5 -1
- package/template/client/src/__tests__/proxy.test.ts +92 -0
- package/template/client/src/app/healthz/route.ts +16 -0
- package/template/client/src/app/layout.tsx +9 -3
- package/template/client/src/app/page.tsx +2 -2
- package/template/client/src/app/providers.tsx +23 -4
- package/template/client/src/components/layout/Header.tsx +7 -3
- package/template/client/src/features/admin/hooks/useAdminSessions.ts +2 -1
- package/template/client/src/features/admin/hooks/useAdminUsers.ts +3 -1
- package/template/client/src/features/admin/types/admin.types.ts +2 -3
- package/template/client/src/features/auth/components/AuthInitializer.tsx +38 -19
- package/template/client/src/features/auth/components/ForgotPasswordForm.tsx +107 -0
- package/template/client/src/features/auth/components/LimitNotice.tsx +28 -0
- package/template/client/src/features/auth/components/LoginForm.tsx +18 -4
- package/template/client/src/features/auth/components/RegisterForm.tsx +23 -7
- package/template/client/src/features/auth/hooks/useAuth.ts +27 -7
- package/template/client/src/features/auth/hooks/usePasswordReset.ts +7 -1
- package/template/client/src/features/auth/services/auth.service.ts +8 -3
- package/template/client/src/features/auth/store/authSlice.ts +7 -2
- package/template/client/src/features/auth/types/auth.types.ts +3 -0
- package/template/client/src/instrumentation-client.ts +9 -1
- package/template/client/src/instrumentation.ts +6 -0
- package/template/client/src/lib/api/__tests__/axios.config.test.ts +183 -0
- package/template/client/src/lib/api/api.types.ts +14 -0
- package/template/client/src/lib/api/axios.config.ts +101 -15
- package/template/client/src/lib/api/hard-redirect.ts +8 -0
- package/template/client/src/lib/api/session-events.ts +29 -0
- package/template/client/src/lib/constants/routes.ts +12 -0
- package/template/client/src/lib/observability/sentry-scrub.ts +71 -0
- package/template/client/src/lib/utils/__tests__/error.test.ts +119 -0
- package/template/client/src/lib/utils/__tests__/form.test.ts +42 -0
- package/template/client/src/lib/utils/__tests__/paths.test.ts +43 -0
- package/template/client/src/lib/utils/__tests__/security.test.ts +40 -0
- package/template/client/src/lib/utils/__tests__/session-marker.test.ts +27 -0
- package/template/client/src/lib/utils/error.ts +86 -1
- package/template/client/src/lib/utils/form.ts +31 -0
- package/template/client/src/lib/utils/paths.ts +18 -0
- package/template/client/src/lib/utils/security.ts +37 -0
- package/template/client/src/lib/utils/session-marker.ts +24 -0
- package/template/client/src/{middleware.ts → proxy.ts} +25 -11
- package/template/client/src/store/__tests__/store.test.ts +44 -0
- package/template/client/src/store/index.ts +26 -8
- package/template/client/vitest.config.mts +48 -0
- package/template/server/.env.example +280 -269
- package/template/server/.env.example.production +283 -236
- package/template/server/AGENTS.md +13 -4
- package/template/server/Dockerfile +181 -14
- package/template/server/docker-compose.yml +4 -2
- package/template/server/docs/deployment.md +63 -0
- package/template/server/docs/logging.md +52 -4
- package/template/server/docs/rate-limits.md +153 -0
- package/template/server/docs/testing.md +63 -0
- package/template/server/eslint.config.mjs +19 -0
- package/template/server/package-lock.json +8784 -8743
- package/template/server/package.json +79 -75
- package/template/server/prisma/migrations/0_init/migration.sql +82 -0
- package/template/server/prisma/migrations/migration_lock.toml +3 -0
- package/template/server/prisma/schema.prisma +19 -6
- package/template/server/prisma/seed.ts +13 -5
- package/template/server/scripts/check-heic.mjs +40 -0
- package/template/server/scripts/check-sharp.mjs +53 -0
- package/template/server/src/__tests__/routes.integration.test.ts +280 -0
- package/template/server/src/app.ts +248 -335
- package/template/server/src/config/__tests__/env.test.ts +219 -0
- package/template/server/src/config/__tests__/rate-limit.config.test.ts +158 -0
- package/template/server/src/config/env.ts +326 -171
- package/template/server/src/config/rate-limit.config.ts +157 -106
- package/template/server/src/jobs/__tests__/cleanup-deleted-accounts.job.test.ts +110 -0
- package/template/server/src/jobs/__tests__/cleanup-expired-auth.job.test.ts +44 -0
- package/template/server/src/jobs/__tests__/jobs.integration.test.ts +88 -0
- package/template/server/src/jobs/__tests__/schedule.test.ts +92 -0
- package/template/server/src/jobs/cleanup-deleted-accounts.job.ts +81 -65
- package/template/server/src/jobs/cleanup-expired-auth.job.ts +32 -24
- package/template/server/src/jobs/index.ts +12 -2
- package/template/server/src/jobs/refresh-cloudflare-ranges.job.ts +28 -0
- package/template/server/src/jobs/schedule.ts +50 -0
- package/template/server/src/libs/__tests__/auth.test.ts +168 -0
- package/template/server/src/libs/__tests__/client-ip.test.ts +257 -121
- package/template/server/src/libs/__tests__/cloudflare-ranges.test.ts +79 -0
- package/template/server/src/libs/__tests__/cookies.test.ts +113 -0
- package/template/server/src/libs/__tests__/email-quota.test.ts +81 -0
- package/template/server/src/libs/__tests__/email.test.ts +68 -0
- package/template/server/src/libs/__tests__/error-handler.test.ts +162 -0
- package/template/server/src/libs/__tests__/health-db-down.integration.test.ts +37 -0
- package/template/server/src/libs/__tests__/health-redis-down.integration.test.ts +45 -0
- package/template/server/src/libs/__tests__/health-routes.test.ts +83 -0
- package/template/server/src/libs/__tests__/health.integration.test.ts +118 -0
- package/template/server/src/libs/__tests__/http.test.ts +74 -2
- package/template/server/src/libs/__tests__/ip-block.test.ts +179 -62
- package/template/server/src/libs/__tests__/logger.test.ts +50 -0
- package/template/server/src/libs/__tests__/monitoring.test.ts +185 -0
- package/template/server/src/libs/__tests__/outbound.integration.test.ts +48 -0
- package/template/server/src/libs/__tests__/prisma-client.test.ts +28 -0
- package/template/server/src/libs/__tests__/query-counter.integration.test.ts +53 -0
- package/template/server/src/libs/__tests__/rate-limiting.test.ts +146 -0
- package/template/server/src/libs/__tests__/rate-limits.integration.test.ts +53 -0
- package/template/server/src/libs/__tests__/redis-required.test.ts +30 -0
- package/template/server/src/libs/__tests__/redis.test.ts +59 -0
- package/template/server/src/libs/__tests__/request-id.test.ts +25 -0
- package/template/server/src/libs/__tests__/requestLogger.test.ts +126 -0
- package/template/server/src/libs/__tests__/safe-http.test.ts +138 -0
- package/template/server/src/libs/__tests__/sentry-scrub.test.ts +82 -0
- package/template/server/src/libs/__tests__/shutdown.test.ts +89 -0
- package/template/server/src/libs/__tests__/url-safety.test.ts +130 -80
- package/template/server/src/libs/account-status.ts +52 -0
- package/template/server/src/libs/auth.ts +51 -12
- package/template/server/src/libs/client-ip.ts +158 -77
- package/template/server/src/libs/cloudflare-ranges.ts +132 -0
- package/template/server/src/libs/cookies.ts +91 -24
- package/template/server/src/libs/email-quota.ts +74 -0
- package/template/server/src/libs/email.ts +46 -9
- package/template/server/src/libs/error-handler.ts +111 -0
- package/template/server/src/libs/health-routes.ts +53 -0
- package/template/server/src/libs/http.ts +139 -47
- package/template/server/src/libs/ip-address.ts +37 -0
- package/template/server/src/libs/ip-block.ts +284 -220
- package/template/server/src/libs/logger.ts +41 -12
- package/template/server/src/libs/monitoring.ts +131 -42
- package/template/server/src/libs/observability/sentry.ts +80 -0
- package/template/server/src/libs/origin-check.ts +9 -7
- package/template/server/src/libs/prisma.ts +47 -4
- package/template/server/src/libs/query-counter.ts +71 -59
- package/template/server/src/libs/rate-limiting.ts +110 -0
- package/template/server/src/libs/redis-required.ts +28 -0
- package/template/server/src/libs/redis.ts +108 -18
- package/template/server/src/libs/request-id.ts +18 -0
- package/template/server/src/libs/requestLogger.ts +112 -17
- package/template/server/src/libs/safe-http.ts +101 -0
- package/template/server/src/libs/shutdown.ts +87 -0
- package/template/server/src/libs/storage/__tests__/fixtures/tiny-heic.ts +13 -0
- package/template/server/src/libs/storage/__tests__/image-optimizer.test.ts +143 -0
- package/template/server/src/libs/storage/__tests__/multipart-limits.test.ts +91 -0
- package/template/server/src/libs/storage/__tests__/upload-persistence.test.ts +52 -0
- package/template/server/src/libs/storage/file-storage.service.ts +104 -83
- package/template/server/src/libs/storage/file-validator.ts +48 -46
- package/template/server/src/libs/storage/image-optimizer.service.ts +78 -72
- package/template/server/src/libs/token-hash.ts +18 -0
- package/template/server/src/libs/url-safety.ts +127 -121
- package/template/server/src/libs/validation-errors.ts +86 -0
- package/template/server/src/modules/admin/__tests__/admin-actions.integration.test.ts +255 -0
- package/template/server/src/modules/admin/__tests__/admin.health.test.ts +82 -0
- package/template/server/src/modules/admin/__tests__/admin.repo.test.ts +55 -0
- package/template/server/src/modules/admin/__tests__/admin.schemas.test.ts +38 -0
- package/template/server/src/modules/admin/__tests__/admin.service.test.ts +162 -0
- package/template/server/src/modules/admin/admin.controller.ts +66 -49
- package/template/server/src/modules/admin/admin.repo.ts +56 -13
- package/template/server/src/modules/admin/admin.routes.ts +48 -2
- package/template/server/src/modules/admin/admin.schemas.ts +18 -6
- package/template/server/src/modules/admin/admin.service.ts +73 -7
- package/template/server/src/modules/auth/__tests__/auth.controller.test.ts +39 -0
- package/template/server/src/modules/auth/__tests__/auth.integration.test.ts +9 -3
- package/template/server/src/modules/auth/__tests__/auth.service.dummy-hash.test.ts +34 -0
- package/template/server/src/modules/auth/__tests__/auth.service.test.ts +332 -49
- package/template/server/src/modules/auth/__tests__/session-cleanup.test.ts +39 -0
- package/template/server/src/modules/auth/__tests__/sessions.integration.test.ts +246 -0
- package/template/server/src/modules/auth/__tests__/token-fingerprints.test.ts +119 -0
- package/template/server/src/modules/auth/auth.controller.ts +133 -128
- package/template/server/src/modules/auth/auth.repo.ts +60 -42
- package/template/server/src/modules/auth/auth.schemas.ts +5 -2
- package/template/server/src/modules/auth/auth.service.ts +197 -109
- package/template/server/src/modules/auth/session.repo.ts +12 -12
- package/template/server/src/modules/files/__tests__/files.integration.test.ts +5 -5
- package/template/server/src/modules/users/__tests__/avatar-upload.test.ts +120 -0
- package/template/server/src/modules/users/__tests__/name-rules.test.ts +46 -0
- package/template/server/src/modules/users/__tests__/users.integration.test.ts +295 -0
- package/template/server/src/modules/users/__tests__/users.repo.test.ts +37 -0
- package/template/server/src/modules/users/__tests__/users.service.test.ts +129 -0
- package/template/server/src/modules/users/users.controller.ts +9 -38
- package/template/server/src/modules/users/users.repo.ts +25 -7
- package/template/server/src/modules/users/users.routes.ts +3 -22
- package/template/server/src/modules/users/users.schemas.ts +15 -9
- package/template/server/src/modules/users/users.service.ts +105 -93
- package/template/server/src/scripts/make-admin.ts +48 -0
- package/template/server/src/server.ts +48 -26
- package/template/server/src/shared/errors/AppError.ts +27 -1
- package/template/server/src/shared/errors/errors.ts +42 -5
- package/template/server/src/shared/responses/successResponse.ts +22 -3
- package/template/server/src/shared/types/index.ts +7 -0
- package/template/server/src/test/__tests__/integration-services.test.ts +66 -0
- package/template/server/src/test/integration-helpers.ts +343 -0
- package/template/server/src/test/integration-services.ts +74 -0
- package/template/server/src/test/integration.global-setup.ts +144 -0
- package/template/server/src/test/integration.setup.ts +35 -158
- package/template/server/src/test/setup.ts +23 -8
- package/template/server/tsconfig.build.json +1 -1
- package/template/server/tsconfig.json +1 -0
- package/template/server/vitest.config.ts +17 -4
- package/template/server/vitest.integration.config.ts +18 -13
- package/template/server/src/libs/storage/filename-sanitizer.ts +0 -71
|
@@ -1,82 +1,86 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "{{PROJECT_NAME}}-server",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"test
|
|
15
|
-
"test:
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"prisma:
|
|
20
|
-
"prisma:
|
|
21
|
-
"prisma:
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"docker:
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
},
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"@fastify/
|
|
41
|
-
"@fastify/
|
|
1
|
+
{
|
|
2
|
+
"name": "{{PROJECT_NAME}}-server",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=24"
|
|
6
|
+
},
|
|
7
|
+
"type": "module",
|
|
8
|
+
"description": "",
|
|
9
|
+
"main": "dist/server.js",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"dev": "tsx watch src/server.ts",
|
|
12
|
+
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
13
|
+
"start": "node dist/server.js",
|
|
14
|
+
"test": "vitest run",
|
|
15
|
+
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
16
|
+
"test:watch": "vitest",
|
|
17
|
+
"test:ui": "vitest --ui",
|
|
18
|
+
"test:coverage": "vitest run --coverage",
|
|
19
|
+
"prisma:generate": "prisma generate",
|
|
20
|
+
"prisma:migrate:dev": "prisma migrate dev",
|
|
21
|
+
"prisma:migrate:deploy": "prisma migrate deploy",
|
|
22
|
+
"prisma:reset": "prisma migrate reset",
|
|
23
|
+
"prisma:seed": "prisma db seed",
|
|
24
|
+
"prisma:studio": "prisma studio",
|
|
25
|
+
"lint": "eslint src/",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"audit": "npm audit --audit-level=high",
|
|
28
|
+
"redis:flush": "tsx scripts/flush-redis.ts",
|
|
29
|
+
"docker:up": "docker compose up -d",
|
|
30
|
+
"docker:tools": "docker compose --profile tools up -d",
|
|
31
|
+
"docker:down": "docker compose --profile tools down",
|
|
32
|
+
"docker:logs": "docker compose logs -f",
|
|
33
|
+
"generate:env": "node -e \"import('fs').then(f=>{if(f.existsSync('.env'))console.log('.env already exists, skipping');else{f.copyFileSync('.env.example','.env');console.log('.env created from .env.example')}})\""
|
|
34
|
+
},
|
|
35
|
+
"prisma": {
|
|
36
|
+
"seed": "tsx prisma/seed.ts",
|
|
37
|
+
"make-admin": "tsx src/scripts/make-admin.ts"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@fastify/cookie": "^11.0.2",
|
|
41
|
+
"@fastify/cors": "^11.2.0",
|
|
42
|
+
"@fastify/helmet": "^13.0.2",
|
|
43
|
+
"@fastify/jwt": "^10.1.0",
|
|
44
|
+
"@fastify/multipart": "^9.0.2",
|
|
45
|
+
"@fastify/rate-limit": "^10.3.0",
|
|
42
46
|
"@fastify/static": "^10.1.4",
|
|
43
|
-
"@prisma/client": "^6.19.3",
|
|
44
|
-
"@sentry/node": "^10.62.0",
|
|
45
|
-
"argon2": "^0.44.0",
|
|
47
|
+
"@prisma/client": "^6.19.3",
|
|
48
|
+
"@sentry/node": "^10.62.0",
|
|
49
|
+
"argon2": "^0.44.0",
|
|
46
50
|
"axios": "^1.20.0",
|
|
47
|
-
"dotenv": "^16.4.7",
|
|
51
|
+
"dotenv": "^16.4.7",
|
|
48
52
|
"fastify": "^5.12.5",
|
|
49
|
-
"fastify-type-provider-zod": "^6.1.0",
|
|
50
|
-
"ioredis": "^5.9.2",
|
|
51
|
-
"pino": "^10.3.1",
|
|
52
|
-
"pino-pretty": "^13.1.3",
|
|
53
|
-
"resend": "^6.9.4",
|
|
54
|
-
"sharp": "^0.35.
|
|
53
|
+
"fastify-type-provider-zod": "^6.1.0",
|
|
54
|
+
"ioredis": "^5.9.2",
|
|
55
|
+
"pino": "^10.3.1",
|
|
56
|
+
"pino-pretty": "^13.1.3",
|
|
57
|
+
"resend": "^6.9.4",
|
|
58
|
+
"sharp": "^0.35.5",
|
|
55
59
|
"uuid": "^14.0.2",
|
|
56
|
-
"zod": "^4.3.6"
|
|
57
|
-
},
|
|
58
|
-
"overrides": {
|
|
59
|
-
"bn.js": ">=5.2.3",
|
|
60
|
-
"flatted": ">=3.4.2",
|
|
61
|
-
"@typescript-eslint/typescript-estree": {
|
|
62
|
-
"minimatch": ">=10.2.1"
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
"devDependencies": {
|
|
66
|
-
"@eslint/js": "^10.0.1",
|
|
67
|
-
"@testcontainers/mysql": "^12.0.3",
|
|
68
|
-
"@testcontainers/redis": "^12.0.3",
|
|
69
|
-
"@types/node": "^
|
|
70
|
-
"@types/uuid": "^10.0.0",
|
|
60
|
+
"zod": "^4.3.6"
|
|
61
|
+
},
|
|
62
|
+
"overrides": {
|
|
63
|
+
"bn.js": ">=5.2.3",
|
|
64
|
+
"flatted": ">=3.4.2",
|
|
65
|
+
"@typescript-eslint/typescript-estree": {
|
|
66
|
+
"minimatch": ">=10.2.1"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@eslint/js": "^10.0.1",
|
|
71
|
+
"@testcontainers/mysql": "^12.0.3",
|
|
72
|
+
"@testcontainers/redis": "^12.0.3",
|
|
73
|
+
"@types/node": "^24",
|
|
74
|
+
"@types/uuid": "^10.0.0",
|
|
71
75
|
"@vitest/coverage-v8": "^4.1.11",
|
|
72
76
|
"@vitest/ui": "^4.1.11",
|
|
73
|
-
"eslint": "^10.0.1",
|
|
74
|
-
"prisma": "^6.19.3",
|
|
75
|
-
"testcontainers": "^12.0.3",
|
|
76
|
-
"tsc-alias": "^1.8.16",
|
|
77
|
-
"tsx": "^4.21.0",
|
|
78
|
-
"typescript": "^5.9.3",
|
|
79
|
-
"typescript-eslint": "^8.55.0",
|
|
77
|
+
"eslint": "^10.0.1",
|
|
78
|
+
"prisma": "^6.19.3",
|
|
79
|
+
"testcontainers": "^12.0.3",
|
|
80
|
+
"tsc-alias": "^1.8.16",
|
|
81
|
+
"tsx": "^4.21.0",
|
|
82
|
+
"typescript": "^5.9.3",
|
|
83
|
+
"typescript-eslint": "^8.55.0",
|
|
80
84
|
"vitest": "^4.1.11"
|
|
81
|
-
}
|
|
82
|
-
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
-- CreateTable
|
|
2
|
+
CREATE TABLE `users` (
|
|
3
|
+
`id` VARCHAR(191) NOT NULL,
|
|
4
|
+
`email` VARCHAR(191) NOT NULL,
|
|
5
|
+
`password` VARCHAR(191) NOT NULL,
|
|
6
|
+
`firstName` VARCHAR(191) NOT NULL,
|
|
7
|
+
`lastName` VARCHAR(191) NOT NULL,
|
|
8
|
+
`avatarUrl` VARCHAR(191) NULL,
|
|
9
|
+
`role` ENUM('USER', 'ADMIN') NOT NULL DEFAULT 'USER',
|
|
10
|
+
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
|
11
|
+
`emailVerifiedAt` DATETIME(3) NULL,
|
|
12
|
+
`deletedAt` DATETIME(3) NULL,
|
|
13
|
+
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
14
|
+
`updatedAt` DATETIME(3) NOT NULL,
|
|
15
|
+
|
|
16
|
+
UNIQUE INDEX `users_email_key`(`email`),
|
|
17
|
+
INDEX `users_role_idx`(`role`),
|
|
18
|
+
INDEX `users_isActive_idx`(`isActive`),
|
|
19
|
+
INDEX `users_deletedAt_idx`(`deletedAt`),
|
|
20
|
+
INDEX `users_email_isActive_idx`(`email`, `isActive`),
|
|
21
|
+
PRIMARY KEY (`id`)
|
|
22
|
+
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
23
|
+
|
|
24
|
+
-- CreateTable
|
|
25
|
+
CREATE TABLE `refresh_tokens` (
|
|
26
|
+
`id` VARCHAR(191) NOT NULL,
|
|
27
|
+
`token` VARCHAR(500) NOT NULL,
|
|
28
|
+
`userId` VARCHAR(191) NOT NULL,
|
|
29
|
+
`sessionId` VARCHAR(191) NULL,
|
|
30
|
+
`expiresAt` DATETIME(3) NOT NULL,
|
|
31
|
+
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
32
|
+
|
|
33
|
+
UNIQUE INDEX `refresh_tokens_token_key`(`token`),
|
|
34
|
+
INDEX `refresh_tokens_userId_idx`(`userId`),
|
|
35
|
+
INDEX `refresh_tokens_token_idx`(`token`),
|
|
36
|
+
INDEX `refresh_tokens_userId_expiresAt_idx`(`userId`, `expiresAt`),
|
|
37
|
+
INDEX `refresh_tokens_expiresAt_idx`(`expiresAt`),
|
|
38
|
+
INDEX `refresh_tokens_sessionId_idx`(`sessionId`),
|
|
39
|
+
PRIMARY KEY (`id`)
|
|
40
|
+
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
41
|
+
|
|
42
|
+
-- CreateTable
|
|
43
|
+
CREATE TABLE `sessions` (
|
|
44
|
+
`id` VARCHAR(191) NOT NULL,
|
|
45
|
+
`userId` VARCHAR(191) NOT NULL,
|
|
46
|
+
`deviceInfo` VARCHAR(500) NULL,
|
|
47
|
+
`ipAddress` VARCHAR(45) NULL,
|
|
48
|
+
`lastActiveAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
49
|
+
`expiresAt` DATETIME(3) NOT NULL,
|
|
50
|
+
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
51
|
+
|
|
52
|
+
INDEX `sessions_userId_idx`(`userId`),
|
|
53
|
+
INDEX `sessions_userId_expiresAt_idx`(`userId`, `expiresAt`),
|
|
54
|
+
INDEX `sessions_expiresAt_idx`(`expiresAt`),
|
|
55
|
+
PRIMARY KEY (`id`)
|
|
56
|
+
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
57
|
+
|
|
58
|
+
-- CreateTable
|
|
59
|
+
CREATE TABLE `blocked_ips` (
|
|
60
|
+
`id` VARCHAR(191) NOT NULL,
|
|
61
|
+
`ip` VARCHAR(45) NOT NULL,
|
|
62
|
+
`reason` VARCHAR(500) NULL,
|
|
63
|
+
`blockedBy` VARCHAR(191) NULL,
|
|
64
|
+
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
65
|
+
`updatedAt` DATETIME(3) NOT NULL,
|
|
66
|
+
|
|
67
|
+
UNIQUE INDEX `blocked_ips_ip_key`(`ip`),
|
|
68
|
+
PRIMARY KEY (`id`)
|
|
69
|
+
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
70
|
+
|
|
71
|
+
-- AddForeignKey
|
|
72
|
+
ALTER TABLE `refresh_tokens` ADD CONSTRAINT `refresh_tokens_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
73
|
+
|
|
74
|
+
-- AddForeignKey
|
|
75
|
+
ALTER TABLE `refresh_tokens` ADD CONSTRAINT `refresh_tokens_sessionId_fkey` FOREIGN KEY (`sessionId`) REFERENCES `sessions`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
76
|
+
|
|
77
|
+
-- AddForeignKey
|
|
78
|
+
ALTER TABLE `sessions` ADD CONSTRAINT `sessions_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
79
|
+
|
|
80
|
+
-- AddForeignKey
|
|
81
|
+
ALTER TABLE `blocked_ips` ADD CONSTRAINT `blocked_ips_blockedBy_fkey` FOREIGN KEY (`blockedBy`) REFERENCES `users`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
82
|
+
|
|
@@ -20,12 +20,16 @@ model User {
|
|
|
20
20
|
lastName String
|
|
21
21
|
avatarUrl String? // SEO-friendly path: /uploads/users/{userId}/avatar/{firstName-lastName}-avatar.webp
|
|
22
22
|
role UserRole @default(USER)
|
|
23
|
+
// Admin ban switch ONLY: false = deactivated by an admin (or soft-deleted).
|
|
24
|
+
// Never use it to mean "email not verified" — that is emailVerifiedAt. Mixing
|
|
25
|
+
// the two let a banned user re-activate themselves through the verify link.
|
|
23
26
|
isActive Boolean @default(true)
|
|
27
|
+
// Set when the user proves ownership of their email (or an admin approves
|
|
28
|
+
// them). Null = not verified; login requires it only while
|
|
29
|
+
// REQUIRE_USER_VERIFICATION is on.
|
|
30
|
+
emailVerifiedAt DateTime?
|
|
24
31
|
deletedAt DateTime?
|
|
25
32
|
|
|
26
|
-
// Account lockout
|
|
27
|
-
failedLoginAttempts Int @default(0)
|
|
28
|
-
lockedUntil DateTime?
|
|
29
33
|
|
|
30
34
|
createdAt DateTime @default(now())
|
|
31
35
|
updatedAt DateTime @updatedAt
|
|
@@ -51,6 +55,10 @@ model RefreshToken {
|
|
|
51
55
|
createdAt DateTime @default(now())
|
|
52
56
|
|
|
53
57
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
58
|
+
// A refresh token lives only as long as its session: deleting the session
|
|
59
|
+
// (logout, admin force-expire, the expiry cleanup job) deletes its tokens, so
|
|
60
|
+
// a login can never outlive the session record users and admins see.
|
|
61
|
+
session Session? @relation(fields: [sessionId], references: [id], onDelete: Cascade)
|
|
54
62
|
|
|
55
63
|
// Performance indexes for token operations and cleanup
|
|
56
64
|
@@index([userId])
|
|
@@ -70,7 +78,8 @@ model Session {
|
|
|
70
78
|
expiresAt DateTime
|
|
71
79
|
createdAt DateTime @default(now())
|
|
72
80
|
|
|
73
|
-
user
|
|
81
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
82
|
+
refreshTokens RefreshToken[]
|
|
74
83
|
|
|
75
84
|
// Performance indexes for session queries
|
|
76
85
|
@@index([userId])
|
|
@@ -83,12 +92,16 @@ model BlockedIp {
|
|
|
83
92
|
id String @id @default(uuid())
|
|
84
93
|
ip String @unique @db.VarChar(45)
|
|
85
94
|
reason String? @db.VarChar(500)
|
|
86
|
-
|
|
95
|
+
// Admin who created the block. Nullable + SetNull: deleting that admin (the
|
|
96
|
+
// 30-day account purge) must neither fail nor remove the block — the block
|
|
97
|
+
// stays in force, only "who blocked it" is lost. With a required relation the
|
|
98
|
+
// database refused the delete and the purge got stuck on that admin forever.
|
|
99
|
+
blockedBy String?
|
|
87
100
|
|
|
88
101
|
createdAt DateTime @default(now())
|
|
89
102
|
updatedAt DateTime @updatedAt
|
|
90
103
|
|
|
91
|
-
user User @relation(fields: [blockedBy], references: [id])
|
|
104
|
+
user User? @relation(fields: [blockedBy], references: [id], onDelete: SetNull)
|
|
92
105
|
|
|
93
106
|
@@map("blocked_ips")
|
|
94
107
|
}
|
|
@@ -4,18 +4,23 @@ import argon2 from 'argon2';
|
|
|
4
4
|
const prisma = new PrismaClient();
|
|
5
5
|
|
|
6
6
|
// Well-known dev-only fallbacks. NEVER used in production — the guard in
|
|
7
|
-
// main()
|
|
8
|
-
// you can override via SEED_ADMIN_PASSWORD / SEED_USER_PASSWORD.
|
|
7
|
+
// main() seeds only when NODE_ENV is explicitly development or test, and even
|
|
8
|
+
// then you can override via SEED_ADMIN_PASSWORD / SEED_USER_PASSWORD.
|
|
9
9
|
const DEV_ADMIN_PASSWORD = 'Admin123!';
|
|
10
10
|
const DEV_USER_PASSWORD = 'User123!';
|
|
11
11
|
|
|
12
|
+
// Environments where demo accounts are acceptable. Anything else, including an
|
|
13
|
+
// unset NODE_ENV, is treated as production (matching src/config/env.ts).
|
|
14
|
+
const SEEDABLE_ENVS = new Set(['development', 'test']);
|
|
15
|
+
|
|
12
16
|
async function main(): Promise<void> {
|
|
13
17
|
// Refuse to seed production: this script creates a well-known admin account
|
|
14
18
|
// (admin@example.com). On a production database that is a backdoor, not a
|
|
15
|
-
// convenience. Seed data belongs to dev/test environments only
|
|
16
|
-
|
|
19
|
+
// convenience. Seed data belongs to dev/test environments only, so the guard
|
|
20
|
+
// is an allowlist: a missing NODE_ENV must not slip through.
|
|
21
|
+
if (!SEEDABLE_ENVS.has(process.env.NODE_ENV ?? '')) {
|
|
17
22
|
console.error(
|
|
18
|
-
|
|
23
|
+
`Refusing to seed: NODE_ENV is "${process.env.NODE_ENV ?? '(unset)'}" (seeding needs development or test).\n` +
|
|
19
24
|
'The seed script creates well-known demo accounts (admin@example.com) and must never run against a production database.\n' +
|
|
20
25
|
'If you really need initial data in production, create it manually or write a dedicated, audited provisioning script.',
|
|
21
26
|
);
|
|
@@ -34,6 +39,8 @@ async function main(): Promise<void> {
|
|
|
34
39
|
firstName: 'Admin',
|
|
35
40
|
lastName: 'User',
|
|
36
41
|
role: 'ADMIN',
|
|
42
|
+
// Demo accounts are pre-verified so they can log in with email verification on.
|
|
43
|
+
emailVerifiedAt: new Date(),
|
|
37
44
|
},
|
|
38
45
|
});
|
|
39
46
|
|
|
@@ -46,6 +53,7 @@ async function main(): Promise<void> {
|
|
|
46
53
|
firstName: 'Test',
|
|
47
54
|
lastName: 'User',
|
|
48
55
|
role: 'USER',
|
|
56
|
+
emailVerifiedAt: new Date(),
|
|
49
57
|
},
|
|
50
58
|
});
|
|
51
59
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build-time proof that the server image decodes real HEIC (iPhone) photos.
|
|
3
|
+
* The Dockerfile runs it right after check-sharp.mjs, as the runtime user; any
|
|
4
|
+
* failure fails the image build.
|
|
5
|
+
*
|
|
6
|
+
* Why a separate check: sharp.format.heif.input is also true for a build that
|
|
7
|
+
* only reads AVIF (sharp's own prebuilt binaries report it too), so it proves
|
|
8
|
+
* nothing about HEIC. HEIC needs libheif's libde265 plugin (Dockerfile:
|
|
9
|
+
* libheif-libde265), and only decoding a real HEVC file shows it loads.
|
|
10
|
+
* The avatar upload accepts HEIC (src/libs/storage/image-optimizer.service.ts).
|
|
11
|
+
*
|
|
12
|
+
* Server only: the client image does not take HEIC uploads, and check-sharp.mjs
|
|
13
|
+
* must stay identical in both apps.
|
|
14
|
+
*/
|
|
15
|
+
import assert from 'node:assert/strict';
|
|
16
|
+
|
|
17
|
+
const { default: sharp } = await import('sharp');
|
|
18
|
+
|
|
19
|
+
// 16x16 solid-colour HEIC, 467 bytes, no metadata, generated (not a photo).
|
|
20
|
+
// Same bytes as src/libs/storage/__tests__/fixtures/tiny-heic.ts.
|
|
21
|
+
const TINY_HEIC_BASE64 =
|
|
22
|
+
'AAAAHGZ0eXBoZWljAAAAAG1pZjFoZWljbWlhZgAAAXxtZXRhAAAAAAAAACFoZGxyAAAAAAAAAABwaWN0AAAAAAAAAAAAAAAAAAAA' +
|
|
23
|
+
'ACJpbG9jAAAAAERAAAEAAQAAAAABoAABAAAAAAAAADMAAAAjaWluZgAAAAAAAQAAABVpbmZlAgAAAAABAABodmMxAAAAAA5waXRt' +
|
|
24
|
+
'AAAAAAABAAAA/GlwcnAAAADcaXBjbwAAAHVodmNDAQNwAAAAkAAAAAAAHvAA/P34+AAADwNgAAEAGEABDAH//wNwAAADAJAAAAMA' +
|
|
25
|
+
'AAMAHroCQGEAAQApQgEBA3AAAAMAkAAAAwAAAwAeoCCBBZbqrprm4CGgwIAAAAyAAAADAIRiAAEABkQBwXPBiQAAABNjb2xybmNs' +
|
|
26
|
+
'eAABAA0ABoAAAAAUaXNwZQAAAAAAAABAAAAAQAAAAChjbGFwAAAAEAAAAAEAAAAQAAAAAf///9AAAAAC////0AAAAAIAAAAQcGl4' +
|
|
27
|
+
'aQAAAAADCAgIAAAAGGlwbWEAAAAAAAAAAQABBYECAwWEAAAAO21kYXQAAAAvKAGvEyFkY0D4EPdn/9RdjB6iuj/gbsenOyEdwNIg' +
|
|
28
|
+
'gJtASJNdUAsWEICHdqVW3Pg=';
|
|
29
|
+
|
|
30
|
+
const heic = Buffer.from(TINY_HEIC_BASE64, 'base64');
|
|
31
|
+
const meta = await sharp(heic).metadata();
|
|
32
|
+
assert.equal(meta.format, 'heif', 'HEIC fixture: container format');
|
|
33
|
+
assert.equal(meta.compression, 'hevc', 'HEIC fixture: must be HEVC-coded (a real iPhone-style HEIC)');
|
|
34
|
+
|
|
35
|
+
const { data, info } = await sharp(heic, { autoOrient: true }).resize(8, 8).webp().toBuffer({ resolveWithObject: true });
|
|
36
|
+
assert.equal(info.format, 'webp', 'HEIC: output format');
|
|
37
|
+
assert.equal(info.width, 8, 'HEIC: resize width');
|
|
38
|
+
assert.equal((await sharp(data).metadata()).exif, undefined, 'HEIC: metadata must be stripped');
|
|
39
|
+
|
|
40
|
+
console.log('check-heic: HEIC (HEVC) photos decode in this image');
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build-time proof that sharp works in the final Docker image. The Dockerfile
|
|
3
|
+
* runs it as the runtime user after everything is copied in; any failure
|
|
4
|
+
* fails the image build, so an image whose sharp cannot load never ships.
|
|
5
|
+
* It needs no env, network, database or application code.
|
|
6
|
+
*
|
|
7
|
+
* Why the addon file is loaded directly first: when our source-built addon
|
|
8
|
+
* fails to load, sharp silently falls back to its prebuilt addon. On a build
|
|
9
|
+
* host with a newer (x86-64-v2) CPU that fallback works, hides the broken
|
|
10
|
+
* build, and the image then crashes on an older production CPU. Requiring our
|
|
11
|
+
* own file first turns a missing library into a build error here.
|
|
12
|
+
*
|
|
13
|
+
* Keep this file identical in server/scripts and client/scripts.
|
|
14
|
+
*/
|
|
15
|
+
import assert from 'node:assert/strict';
|
|
16
|
+
import { execFileSync } from 'node:child_process';
|
|
17
|
+
import { readFileSync } from 'node:fs';
|
|
18
|
+
import { createRequire } from 'node:module';
|
|
19
|
+
|
|
20
|
+
const require = createRequire(import.meta.url);
|
|
21
|
+
const { version } = require('../node_modules/sharp/package.json');
|
|
22
|
+
require(`../node_modules/sharp/src/build/Release/sharp-linuxmusl-${process.arch}-${version}.node`);
|
|
23
|
+
|
|
24
|
+
// The libvips the Dockerfile compiled. sharp must report this one, not the
|
|
25
|
+
// libvips bundled with its prebuilt addon.
|
|
26
|
+
const pc = readFileSync('/opt/vips/lib/pkgconfig/vips-cpp.pc', 'utf8');
|
|
27
|
+
const shipped = /^Version:\s*(\S+)/m.exec(pc)?.[1];
|
|
28
|
+
|
|
29
|
+
const { default: sharp } = await import('sharp');
|
|
30
|
+
assert.equal(sharp.versions.vips, shipped, 'sharp is not using the libvips built into this image');
|
|
31
|
+
|
|
32
|
+
// The work the apps do: decode, auto-orient, resize, encode WebP and drop
|
|
33
|
+
// metadata (avatars on the server, /_next/image on the client).
|
|
34
|
+
const jpeg = await sharp({ create: { width: 16, height: 16, channels: 3, background: '#3366cc' } })
|
|
35
|
+
.jpeg()
|
|
36
|
+
.withExif({ IFD0: { Copyright: 'check-sharp' } })
|
|
37
|
+
.toBuffer();
|
|
38
|
+
assert.ok((await sharp(jpeg).metadata()).exif, 'the test JPEG should carry EXIF');
|
|
39
|
+
const png = await sharp({ create: { width: 16, height: 16, channels: 4, background: '#00000000' } }).png().toBuffer();
|
|
40
|
+
|
|
41
|
+
for (const [name, input] of [['jpeg', jpeg], ['png', png]]) {
|
|
42
|
+
const { data, info } = await sharp(input).autoOrient().resize(8, 8).webp().toBuffer({ resolveWithObject: true });
|
|
43
|
+
assert.equal(info.format, 'webp', `${name}: output format`);
|
|
44
|
+
assert.equal(info.width, 8, `${name}: resize width`);
|
|
45
|
+
assert.equal((await sharp(data).metadata()).exif, undefined, `${name}: metadata must be stripped`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// HEIC/HEIF input (phone photos) is accepted by the server's avatar upload.
|
|
49
|
+
assert.equal(sharp.format.heif.input.buffer, true, 'HEIF input support missing');
|
|
50
|
+
|
|
51
|
+
// Also prove which runtime the image ships (the deploy log shows this line).
|
|
52
|
+
const npmVersion = execFileSync('npm', ['-v'], { encoding: 'utf8' }).trim();
|
|
53
|
+
console.log(`check-sharp: sharp ${version} works with libvips ${sharp.versions.vips} on Node ${process.version}, npm ${npmVersion}`);
|