create-tigra 3.3.0 → 4.0.1
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/CHANGELOG.md +151 -0
- package/README.md +264 -56
- package/bin/create-tigra.js +497 -472
- package/lib/patchers/email-verification.patcher.js +72 -10
- 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 +44 -13
- package/package.json +5 -3
- 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/README.md +79 -0
- 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/README.md +92 -21
- 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 +35 -18
- 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 +13 -2
- package/template/client/src/features/auth/components/RegisterForm.tsx +23 -7
- package/template/client/src/features/auth/hooks/useAuth.ts +11 -1
- 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/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 +1 -1
- 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 +81 -0
- 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/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 -270
- package/template/server/.env.example.production +283 -242
- package/template/server/AGENTS.md +13 -4
- package/template/server/Dockerfile +176 -14
- package/template/server/README.md +108 -0
- package/template/server/docker-compose.yml +4 -2
- package/template/server/docs/deployment.md +63 -0
- package/template/server/docs/logging.md +66 -4
- package/template/server/docs/rate-limits.md +153 -0
- package/template/server/docs/testing.md +81 -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 +0 -3
- 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 -346
- 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 -182
- package/template/server/src/config/rate-limit.config.ts +157 -106
- package/template/server/src/jobs/__tests__/cleanup-deleted-accounts.job.test.ts +60 -8
- 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 +38 -36
- 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 +98 -7
- 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 +53 -2
- 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 +38 -2
- 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 -80
- 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/auth.ts +39 -10
- 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 +53 -14
- 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 -221
- package/template/server/src/libs/logger.ts +41 -12
- package/template/server/src/libs/monitoring.ts +127 -41
- package/template/server/src/libs/observability/sentry.ts +1 -1
- 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 +27 -1
- 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 +59 -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 +94 -84
- package/template/server/src/libs/storage/file-validator.ts +48 -46
- package/template/server/src/libs/storage/image-optimizer.service.ts +16 -5
- 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 +49 -10
- 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 +66 -4
- 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 +197 -37
- 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 +44 -44
- package/template/server/src/modules/auth/auth.schemas.ts +4 -2
- package/template/server/src/modules/auth/auth.service.ts +167 -96
- package/template/server/src/modules/auth/session.repo.ts +12 -0
- 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 +23 -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 +3 -10
- 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
|
@@ -37,6 +37,7 @@ export async function applyEmailVerificationModule(targetDir) {
|
|
|
37
37
|
patchRateLimitConfig(project, targetDir);
|
|
38
38
|
patchAuthService(project, targetDir);
|
|
39
39
|
patchAuthRepo(project, targetDir);
|
|
40
|
+
patchVerificationDefault(targetDir);
|
|
40
41
|
|
|
41
42
|
// C) Patch client files via ts-morph
|
|
42
43
|
patchApiEndpoints(project, targetDir);
|
|
@@ -59,6 +60,12 @@ async function copyModuleFiles(targetDir) {
|
|
|
59
60
|
src: path.join(MODULES_DIR, 'server', 'verification.controller.ts'),
|
|
60
61
|
dest: path.join(targetDir, 'server', 'src', 'modules', 'auth', 'verification.controller.ts'),
|
|
61
62
|
},
|
|
63
|
+
// The module's integration tests ship with it (they need the patched
|
|
64
|
+
// routes, so they live here, not in the template).
|
|
65
|
+
{
|
|
66
|
+
src: path.join(MODULES_DIR, 'server', '__tests__', 'verification.integration.test.ts'),
|
|
67
|
+
dest: path.join(targetDir, 'server', 'src', 'modules', 'auth', '__tests__', 'verification.integration.test.ts'),
|
|
68
|
+
},
|
|
62
69
|
{
|
|
63
70
|
src: path.join(MODULES_DIR, 'client', 'services', 'verification.service.ts'),
|
|
64
71
|
dest: path.join(targetDir, 'client', 'src', 'features', 'auth', 'services', 'verification.service.ts'),
|
|
@@ -180,8 +187,8 @@ export type VerifyAccountInput = z.infer<typeof verifyAccountSchema>;`);
|
|
|
180
187
|
|
|
181
188
|
/**
|
|
182
189
|
* Patch 3: rate-limit.config.ts
|
|
183
|
-
* -
|
|
184
|
-
*
|
|
190
|
+
* - Append AUTH_SEND_VERIFICATION and AUTH_VERIFY_ACCOUNT (10 per 15 minutes each)
|
|
191
|
+
* to the RATE_LIMITS object, built with the routeLimit() helper
|
|
185
192
|
*/
|
|
186
193
|
function patchRateLimitConfig(project, targetDir) {
|
|
187
194
|
const filePath = path.join(targetDir, 'server', 'src', 'config', 'rate-limit.config.ts');
|
|
@@ -212,18 +219,29 @@ function patchRateLimitConfig(project, targetDir) {
|
|
|
212
219
|
// Check if already patched
|
|
213
220
|
if (objectLiteral.getProperty('AUTH_SEND_VERIFICATION')) return;
|
|
214
221
|
|
|
222
|
+
// The entries are built with the routeLimit(name, max, window) helper, which
|
|
223
|
+
// applies RATE_LIMIT_OVERRIDES and the multiplier. A project scaffolded by an
|
|
224
|
+
// older create-tigra has no such helper: stop with a clear message instead of
|
|
225
|
+
// writing code that does not compile.
|
|
226
|
+
if (!sourceFile.getFunction('routeLimit')) {
|
|
227
|
+
throw new Error(
|
|
228
|
+
'rate-limit.config.ts has no routeLimit() helper (project made by an older create-tigra). ' +
|
|
229
|
+
'Add AUTH_SEND_VERIFICATION and AUTH_VERIFY_ACCOUNT (10 per 15 minutes each) to RATE_LIMITS by hand.',
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
215
233
|
// Use text manipulation to insert after AUTH_RESET_PASSWORD block
|
|
216
234
|
// ts-morph's insertPropertyAssignment has quirks with index positioning,
|
|
217
235
|
// so we use the more reliable addPropertyAssignment which appends at end
|
|
218
236
|
// (position within the object doesn't matter for a config map)
|
|
219
237
|
objectLiteral.addPropertyAssignment({
|
|
220
238
|
name: 'AUTH_SEND_VERIFICATION',
|
|
221
|
-
initializer: `
|
|
239
|
+
initializer: `routeLimit('AUTH_SEND_VERIFICATION', 10, '15m')`,
|
|
222
240
|
});
|
|
223
241
|
|
|
224
242
|
objectLiteral.addPropertyAssignment({
|
|
225
243
|
name: 'AUTH_VERIFY_ACCOUNT',
|
|
226
|
-
initializer: `
|
|
244
|
+
initializer: `routeLimit('AUTH_VERIFY_ACCOUNT', 10, '15m')`,
|
|
227
245
|
});
|
|
228
246
|
|
|
229
247
|
sourceFile.saveSync();
|
|
@@ -251,6 +269,45 @@ function replaceAnchor(content, { anchor, replacement, alreadyPatchedMarker, lab
|
|
|
251
269
|
return content.replace(anchorText, replacement.split('\n').join(eol));
|
|
252
270
|
}
|
|
253
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Turn email verification ON by default once this module is installed.
|
|
274
|
+
*
|
|
275
|
+
* Projects without the module default REQUIRE_USER_VERIFICATION to false: they
|
|
276
|
+
* have no verify route, so "on" would lock every new user out. With the module
|
|
277
|
+
* the default becomes true, in the code (env.ts) and in every server env file,
|
|
278
|
+
* so scaffold-time and `create-tigra add` end in the same state. An older
|
|
279
|
+
* project whose env.ts already defaults to true is left as it is.
|
|
280
|
+
*/
|
|
281
|
+
function patchVerificationDefault(targetDir) {
|
|
282
|
+
const envTsPath = path.join(targetDir, 'server', 'src', 'config', 'env.ts');
|
|
283
|
+
const content = fs.readFileSync(envTsPath, 'utf-8');
|
|
284
|
+
const alreadyOn =
|
|
285
|
+
content.includes('REQUIRE_USER_VERIFICATION: envBoolean(true)') ||
|
|
286
|
+
/REQUIRE_USER_VERIFICATION:[^\n]*default\('true'\)/.test(content);
|
|
287
|
+
if (!alreadyOn) {
|
|
288
|
+
const patched = replaceAnchor(content, {
|
|
289
|
+
anchor: 'REQUIRE_USER_VERIFICATION: envBoolean(false),',
|
|
290
|
+
replacement: 'REQUIRE_USER_VERIFICATION: envBoolean(true),',
|
|
291
|
+
alreadyPatchedMarker: 'REQUIRE_USER_VERIFICATION: envBoolean(true)',
|
|
292
|
+
label: 'REQUIRE_USER_VERIFICATION default',
|
|
293
|
+
file: 'server/src/config/env.ts',
|
|
294
|
+
});
|
|
295
|
+
fs.writeFileSync(envTsPath, patched, 'utf-8');
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// `KEY=false` lines only (quoted or not, any letter case); other values are the owner's choice.
|
|
299
|
+
for (const envFile of ['.env.example', '.env', '.env.example.production']) {
|
|
300
|
+
const envPath = path.join(targetDir, 'server', envFile);
|
|
301
|
+
if (!fs.existsSync(envPath)) continue;
|
|
302
|
+
const text = fs.readFileSync(envPath, 'utf-8');
|
|
303
|
+
const updated = text.replace(
|
|
304
|
+
/^REQUIRE_USER_VERIFICATION=(["']?)false\1(?=\s|$)/gim,
|
|
305
|
+
'REQUIRE_USER_VERIFICATION=$1true$1',
|
|
306
|
+
);
|
|
307
|
+
if (updated !== text) fs.writeFileSync(envPath, updated, 'utf-8');
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
254
311
|
/**
|
|
255
312
|
* Patch 4: auth.service.ts
|
|
256
313
|
* - Export sanitizeUser function, SanitizedUser interface, AuthResult interface
|
|
@@ -318,12 +375,15 @@ function patchAuthService(project, targetDir) {
|
|
|
318
375
|
patched = replaceAnchor(patched, {
|
|
319
376
|
file: 'auth.service.ts',
|
|
320
377
|
label: 'register verification branch',
|
|
321
|
-
|
|
378
|
+
// Prefix marker (no closing parenthesis): matches every version of the inserted call.
|
|
379
|
+
alreadyPatchedMarker: 'sendVerification(input.email',
|
|
322
380
|
anchor: ' if (requiresVerification) {\n return {\n user: sanitizeUser(user),\n requiresVerification: true,\n };\n }',
|
|
323
381
|
replacement:
|
|
324
382
|
' if (requiresVerification) {\n' +
|
|
325
|
-
" // Auto-send verification email on registration (best-effort, don't block registration)
|
|
326
|
-
'
|
|
383
|
+
" // Auto-send verification email on registration (best-effort, don't block registration).\n" +
|
|
384
|
+
' // Not charged to the per-address email cap: an address registers only once, so this\n' +
|
|
385
|
+
' // email cannot flood anyone, and strangers using up the cap must not stop it.\n' +
|
|
386
|
+
" sendVerification(input.email, { quota: 'none' }).catch((error) => logger.warn({ code: error?.code }, '[AUTH] Verification email not sent at register'));\n\n" +
|
|
327
387
|
' return {\n user: sanitizeUser(user),\n requiresVerification: true,\n };\n }',
|
|
328
388
|
});
|
|
329
389
|
|
|
@@ -334,7 +394,7 @@ function patchAuthService(project, targetDir) {
|
|
|
334
394
|
patched = replaceAnchor(patched, {
|
|
335
395
|
file: 'auth.service.ts',
|
|
336
396
|
label: 'login account-state check',
|
|
337
|
-
alreadyPatchedMarker: 'sendVerification(user.email
|
|
397
|
+
alreadyPatchedMarker: 'sendVerification(user.email',
|
|
338
398
|
anchor:
|
|
339
399
|
' // Reveal account state only now that the password is proven, so an anonymous\n' +
|
|
340
400
|
' // caller cannot learn whether an email is banned or unverified.\n' +
|
|
@@ -343,8 +403,10 @@ function patchAuthService(project, targetDir) {
|
|
|
343
403
|
' // Reveal account state only now that the password is proven, so an anonymous\n' +
|
|
344
404
|
' // caller cannot learn whether an email is banned or unverified.\n' +
|
|
345
405
|
' // Email-verification module: re-send a fresh link to an unverified (not banned) account.\n' +
|
|
406
|
+
" // Own 'sign-in' email counter: only the password holder gets here, so strangers who use up\n" +
|
|
407
|
+
' // the public counter (forgot-password, resend) can never block this link.\n' +
|
|
346
408
|
' if (user.isActive && env.REQUIRE_USER_VERIFICATION && !user.emailVerifiedAt) {\n' +
|
|
347
|
-
|
|
409
|
+
" sendVerification(user.email, { quota: 'sign-in' }).catch((error) => logger.warn({ code: error?.code }, '[AUTH] Verification email not re-sent at sign-in'));\n" +
|
|
348
410
|
' }\n' +
|
|
349
411
|
' assertAccountCanSignIn(user);',
|
|
350
412
|
});
|
|
@@ -575,7 +637,7 @@ async function patchPostmanCollection(targetDir) {
|
|
|
575
637
|
path: ['auth', 'send-verification'],
|
|
576
638
|
},
|
|
577
639
|
description:
|
|
578
|
-
'Resend the verification email. Public endpoint — no authentication required. Always returns success to prevent email enumeration. A verification email is also sent automatically on registration. Rate limited to
|
|
640
|
+
'Resend the verification email. Public endpoint — no authentication required. Always returns success to prevent email enumeration. A verification email is also sent automatically on registration. Rate limited to 10 requests per 15 minutes per IP, and at most 3 emails per hour to one address (shared with forgot-password).',
|
|
579
641
|
},
|
|
580
642
|
response: [],
|
|
581
643
|
});
|
|
@@ -5,7 +5,7 @@ import { toast } from 'sonner';
|
|
|
5
5
|
|
|
6
6
|
import { useAppDispatch } from '@/store/hooks';
|
|
7
7
|
import { useAppRouter } from '@/hooks/useAppRouter';
|
|
8
|
-
import { getErrorMessage, isErrorCode, ERROR_CODES } from '@/lib/utils/error';
|
|
8
|
+
import { getErrorMessage, isErrorCode, isLimitError, ERROR_CODES } from '@/lib/utils/error';
|
|
9
9
|
import { ROUTES } from '@/lib/constants/routes';
|
|
10
10
|
import { verificationService } from '../services/verification.service';
|
|
11
11
|
import { setUser } from '../store/authSlice';
|
|
@@ -24,6 +24,8 @@ export const useSendVerification = (): UseSendVerificationReturn => {
|
|
|
24
24
|
toast.success('Verification email sent! Please check your inbox.');
|
|
25
25
|
},
|
|
26
26
|
onError: (error: unknown) => {
|
|
27
|
+
// Rate limit or the per-address email cap: the global toast already says how long to wait.
|
|
28
|
+
if (isLimitError(error)) return;
|
|
27
29
|
if (isErrorCode(error, ERROR_CODES.ALREADY_VERIFIED)) {
|
|
28
30
|
toast.info('Your account is already verified');
|
|
29
31
|
router.push(ROUTES.DASHBOARD);
|
|
@@ -56,6 +58,7 @@ export const useVerifyAccount = (): UseVerifyAccountReturn => {
|
|
|
56
58
|
router.push(ROUTES.DASHBOARD);
|
|
57
59
|
},
|
|
58
60
|
onError: (error: unknown) => {
|
|
61
|
+
if (isLimitError(error)) return; // the global toast already says how long to wait
|
|
59
62
|
toast.error(getErrorMessage(error));
|
|
60
63
|
if (isErrorCode(error, ERROR_CODES.INVALID_VERIFICATION_TOKEN)) {
|
|
61
64
|
router.push(ROUTES.LOGIN);
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Email verification (the email-verification module) against a real MySQL
|
|
3
|
+
* and Redis, with verification switched ON for this file. Emails go to an
|
|
4
|
+
* in-process Resend stub; nothing is sent.
|
|
5
|
+
* - Register does not sign in; signing in before verifying is refused
|
|
6
|
+
* (403 EMAIL_NOT_VERIFIED).
|
|
7
|
+
* - The emailed link verifies once and signs in; the same link again, or any
|
|
8
|
+
* other token, is 400 INVALID_VERIFICATION_TOKEN.
|
|
9
|
+
* - Verification tokens are stored by fingerprint only: no Redis key or value
|
|
10
|
+
* holds the raw token.
|
|
11
|
+
* - send-verification answers the same for every address (no account
|
|
12
|
+
* discovery) and emails a fresh link only to an unverified account.
|
|
13
|
+
*
|
|
14
|
+
* The generator copies this file into server/src/modules/auth/__tests__/
|
|
15
|
+
* (lib/patchers/email-verification.patcher.js); it runs with the rest of the
|
|
16
|
+
* integration suite.
|
|
17
|
+
*/
|
|
18
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
19
|
+
import type { FastifyInstance } from 'fastify';
|
|
20
|
+
import {
|
|
21
|
+
PASSWORD,
|
|
22
|
+
buildTestApp,
|
|
23
|
+
call,
|
|
24
|
+
CookieJar,
|
|
25
|
+
redis,
|
|
26
|
+
startEmailStub,
|
|
27
|
+
tokenOf,
|
|
28
|
+
uniqueEmail,
|
|
29
|
+
type EmailStub,
|
|
30
|
+
} from '@/test/integration-helpers.js';
|
|
31
|
+
|
|
32
|
+
let app: FastifyInstance;
|
|
33
|
+
let mail: EmailStub;
|
|
34
|
+
|
|
35
|
+
beforeAll(async () => {
|
|
36
|
+
process.env.REQUIRE_USER_VERIFICATION = 'true';
|
|
37
|
+
mail = await startEmailStub();
|
|
38
|
+
app = await buildTestApp();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
afterAll(async () => {
|
|
42
|
+
await app?.close();
|
|
43
|
+
await mail?.close();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
/** Registers an address and returns the raw token of the verification link it was emailed. */
|
|
47
|
+
async function registerUnverified(tag: string): Promise<{ email: string; token: string; registerJar: CookieJar }> {
|
|
48
|
+
const email = uniqueEmail(tag);
|
|
49
|
+
const registerJar = new CookieJar();
|
|
50
|
+
const r = await call(app, 'POST', '/auth/register', {
|
|
51
|
+
jar: registerJar,
|
|
52
|
+
payload: { email, password: PASSWORD, firstName: 'Veri', lastName: 'Fied' },
|
|
53
|
+
});
|
|
54
|
+
expect(r.status).toBe(201);
|
|
55
|
+
// The verification email goes out after register has answered: wait for it.
|
|
56
|
+
const sent = await mail.waitFor(email, (e) => /verify-account/.test(e.link ?? ''));
|
|
57
|
+
return { email, token: tokenOf(sent.at(-1)?.link ?? null), registerJar };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
describe('before verifying', () => {
|
|
61
|
+
it('register answers 201 without signing in, and sign-in is refused with 403 EMAIL_NOT_VERIFIED', async () => {
|
|
62
|
+
const { email, registerJar } = await registerUnverified('unverified');
|
|
63
|
+
expect(registerJar.get('access_token')).toBeUndefined();
|
|
64
|
+
const login = await call(app, 'POST', '/auth/login', { payload: { email, password: PASSWORD } });
|
|
65
|
+
expect([login.status, login.code]).toEqual([403, 'EMAIL_NOT_VERIFIED']);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('the verification link', () => {
|
|
70
|
+
it('verifies once and signs in; the same link again is 400 INVALID_VERIFICATION_TOKEN', async () => {
|
|
71
|
+
const { token } = await registerUnverified('verify');
|
|
72
|
+
const jar = new CookieJar();
|
|
73
|
+
const ok = await call(app, 'POST', '/auth/verify-account', { jar, payload: { token } });
|
|
74
|
+
expect(ok.status).toBe(200);
|
|
75
|
+
expect((await call(app, 'GET', '/auth/me', { jar })).status).toBe(200);
|
|
76
|
+
const again = await call(app, 'POST', '/auth/verify-account', { payload: { token } });
|
|
77
|
+
expect([again.status, again.code]).toEqual([400, 'INVALID_VERIFICATION_TOKEN']);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('a token nobody was sent → 400 INVALID_VERIFICATION_TOKEN', async () => {
|
|
81
|
+
const r = await call(app, 'POST', '/auth/verify-account', { payload: { token: 'f'.repeat(64) } });
|
|
82
|
+
expect([r.status, r.code]).toEqual([400, 'INVALID_VERIFICATION_TOKEN']);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('no Redis key or value holds the raw token (stored by fingerprint only)', async () => {
|
|
86
|
+
const { token } = await registerUnverified('fingerprint');
|
|
87
|
+
const r = await redis();
|
|
88
|
+
const keys = await r.keys('verify*');
|
|
89
|
+
expect(keys.length).toBeGreaterThan(0);
|
|
90
|
+
expect(keys.join('\n')).not.toContain(token);
|
|
91
|
+
for (const key of keys) {
|
|
92
|
+
if ((await r.type(key)) === 'string') expect((await r.get(key)) ?? '').not.toContain(token);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('send-verification', () => {
|
|
98
|
+
it('answers the same for an unknown address and an unverified account; only the account gets a new link', async () => {
|
|
99
|
+
const { email } = await registerUnverified('resend');
|
|
100
|
+
const before = mail.to(email).length;
|
|
101
|
+
const known = await call(app, 'POST', '/auth/send-verification', { payload: { email } });
|
|
102
|
+
const unknownEmail = uniqueEmail('nobody');
|
|
103
|
+
const unknown = await call(app, 'POST', '/auth/send-verification', { payload: { email: unknownEmail } });
|
|
104
|
+
expect(known.status).toBe(200);
|
|
105
|
+
expect(known.body).toEqual(unknown.body);
|
|
106
|
+
expect(await mail.waitFor(email, () => true, before + 1)).toHaveLength(before + 1);
|
|
107
|
+
expect(mail.to(unknownEmail)).toHaveLength(0);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('wrong input → 422 VALIDATION_FAILED (send-verification and verify-account)', async () => {
|
|
111
|
+
const a = await call(app, 'POST', '/auth/send-verification', { payload: { email: 'x' } });
|
|
112
|
+
const b = await call(app, 'POST', '/auth/verify-account', { payload: {} });
|
|
113
|
+
expect([a.status, a.code, b.status, b.code]).toEqual([422, 'VALIDATION_FAILED', 422, 'VALIDATION_FAILED']);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { FastifyRequest, FastifyReply } from 'fastify';
|
|
2
2
|
import { successResponse } from '@shared/responses/successResponse.js';
|
|
3
3
|
import { setAuthCookies } from '@libs/cookies.js';
|
|
4
|
+
import { getClientIp } from '@libs/client-ip.js';
|
|
4
5
|
import * as verificationService from './verification.service.js';
|
|
5
6
|
|
|
6
7
|
import type { SendVerificationInput, VerifyAccountInput } from './auth.schemas.js';
|
|
@@ -19,7 +20,8 @@ export async function verifyAccount(
|
|
|
19
20
|
reply: FastifyReply,
|
|
20
21
|
): Promise<void> {
|
|
21
22
|
const deviceInfo = request.headers['user-agent'];
|
|
22
|
-
|
|
23
|
+
// Same verified address as login/register sessions (never request.ip or a raw header).
|
|
24
|
+
const ipAddress = getClientIp(request);
|
|
23
25
|
|
|
24
26
|
const result = await verificationService.verifyAccount(request.body.token, deviceInfo, ipAddress);
|
|
25
27
|
|
|
@@ -5,6 +5,9 @@ import { sendEmail } from '@libs/email.js';
|
|
|
5
5
|
import { logger } from '@libs/logger.js';
|
|
6
6
|
import { env } from '@config/env.js';
|
|
7
7
|
import { ACCOUNT_DEACTIVATED } from '@libs/account-status.js';
|
|
8
|
+
import { consumeEmailQuota, type EmailQuotaBucket } from '@libs/email-quota.js';
|
|
9
|
+
import { assertRedisReady } from '@libs/redis-required.js';
|
|
10
|
+
import { hashToken } from '@libs/token-hash.js';
|
|
8
11
|
import {
|
|
9
12
|
BadRequestError,
|
|
10
13
|
ForbiddenError,
|
|
@@ -17,6 +20,8 @@ import { sanitizeUser } from './auth.service.js';
|
|
|
17
20
|
import type { AuthResult } from './auth.service.js';
|
|
18
21
|
|
|
19
22
|
const VERIFICATION_TTL = 3600; // 1 hour in seconds
|
|
23
|
+
// Stored by fingerprint only (libs/token-hash.ts): `verify:<sha256>` -> userId,
|
|
24
|
+
// `verify-user:<userId>` -> that sha256. The raw token exists only in the email.
|
|
20
25
|
const VERIFICATION_PREFIX = 'verify:';
|
|
21
26
|
const VERIFICATION_USER_PREFIX = 'verify-user:';
|
|
22
27
|
|
|
@@ -28,7 +33,28 @@ const VERIFICATION_USER_PREFIX = 'verify-user:';
|
|
|
28
33
|
* Verification proves email ownership and nothing else: it sets
|
|
29
34
|
* `emailVerifiedAt` and never touches `isActive` (the admin ban switch).
|
|
30
35
|
*/
|
|
31
|
-
export async function sendVerification(
|
|
36
|
+
export async function sendVerification(
|
|
37
|
+
email: string,
|
|
38
|
+
{ quota = 'public' }: { quota?: EmailQuotaBucket | 'none' } = {},
|
|
39
|
+
): Promise<void> {
|
|
40
|
+
// Per-address email cap (libs/email-quota.ts), counted BEFORE the lookup so
|
|
41
|
+
// unknown, banned and already-verified addresses count the same and the 429
|
|
42
|
+
// reveals nothing. Which counter:
|
|
43
|
+
// - 'public' (default): the public resend endpoint, shared with forgot-password.
|
|
44
|
+
// Over the cap it answers 429 EMAIL_RATE_LIMITED with the wait.
|
|
45
|
+
// - 'sign-in': the resend after a correct password; its own counter, so
|
|
46
|
+
// strangers typing the address cannot use it up.
|
|
47
|
+
// - 'none': the one email sent at register (an address registers only once).
|
|
48
|
+
// Register and the sign-in resend call this fire-and-forget: over their cap
|
|
49
|
+
// the email is skipped and the caller logs it.
|
|
50
|
+
//
|
|
51
|
+
// Verification tokens live in Redis: without it, answer a clear 503 for every
|
|
52
|
+
// address (checked first, so it reveals nothing about the account).
|
|
53
|
+
assertRedisReady('Email verification');
|
|
54
|
+
if (quota !== 'none') {
|
|
55
|
+
await consumeEmailQuota(email, quota);
|
|
56
|
+
}
|
|
57
|
+
|
|
32
58
|
const user = await authRepo.findUserByEmail(email);
|
|
33
59
|
|
|
34
60
|
// Silent return if user not found — prevents email enumeration (same pattern as forgotPassword)
|
|
@@ -42,18 +68,19 @@ export async function sendVerification(email: string): Promise<void> {
|
|
|
42
68
|
|
|
43
69
|
const redis = getRedis();
|
|
44
70
|
|
|
45
|
-
// Invalidate any existing verification token for this user
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
await redis.del(`${VERIFICATION_PREFIX}${
|
|
71
|
+
// Invalidate any existing verification token for this user (the pointer holds its fingerprint)
|
|
72
|
+
const existingTokenHash = await redis.get(`${VERIFICATION_USER_PREFIX}${user.id}`);
|
|
73
|
+
if (existingTokenHash) {
|
|
74
|
+
await redis.del(`${VERIFICATION_PREFIX}${existingTokenHash}`);
|
|
49
75
|
await redis.del(`${VERIFICATION_USER_PREFIX}${user.id}`);
|
|
50
76
|
}
|
|
51
77
|
|
|
52
|
-
// Generate secure token
|
|
78
|
+
// Generate a secure token; only its fingerprint goes to Redis (1 hour TTL)
|
|
53
79
|
const token = crypto.randomBytes(32).toString('hex');
|
|
80
|
+
const tokenHash = hashToken(token);
|
|
54
81
|
|
|
55
|
-
await redis.set(`${VERIFICATION_PREFIX}${
|
|
56
|
-
await redis.set(`${VERIFICATION_USER_PREFIX}${user.id}`,
|
|
82
|
+
await redis.set(`${VERIFICATION_PREFIX}${tokenHash}`, user.id, 'EX', VERIFICATION_TTL);
|
|
83
|
+
await redis.set(`${VERIFICATION_USER_PREFIX}${user.id}`, tokenHash, 'EX', VERIFICATION_TTL);
|
|
57
84
|
|
|
58
85
|
// Build verification URL and send email
|
|
59
86
|
const verifyUrl = `${env.CLIENT_URL}/verify-account?token=${token}`;
|
|
@@ -112,11 +139,12 @@ export async function verifyAccount(
|
|
|
112
139
|
deviceInfo?: string,
|
|
113
140
|
ipAddress?: string,
|
|
114
141
|
): Promise<AuthResult> {
|
|
142
|
+
assertRedisReady('Email verification'); // the token is stored in Redis
|
|
115
143
|
const redis = getRedis();
|
|
116
144
|
|
|
117
145
|
// Atomic get-and-delete to prevent token reuse via concurrent requests
|
|
118
146
|
// ioredis exposes GETDEL as getdel (all lowercase); getDel does not exist.
|
|
119
|
-
const userId = await redis.getdel(`${VERIFICATION_PREFIX}${token}`);
|
|
147
|
+
const userId = await redis.getdel(`${VERIFICATION_PREFIX}${hashToken(token)}`);
|
|
120
148
|
if (!userId) {
|
|
121
149
|
throw new BadRequestError('Invalid or expired verification token', 'INVALID_VERIFICATION_TOKEN');
|
|
122
150
|
}
|
|
@@ -153,10 +181,7 @@ export async function verifyAccount(
|
|
|
153
181
|
}
|
|
154
182
|
|
|
155
183
|
// Generate tokens and create session (same pattern as login)
|
|
156
|
-
|
|
157
|
-
userId: user.id,
|
|
158
|
-
role: user.role,
|
|
159
|
-
});
|
|
184
|
+
// Session first: the access token carries its id (see authenticate()).
|
|
160
185
|
const refreshToken = generateRefreshToken();
|
|
161
186
|
const refreshTokenExpiresAt = getRefreshTokenExpiresAt();
|
|
162
187
|
|
|
@@ -167,6 +192,12 @@ export async function verifyAccount(
|
|
|
167
192
|
expiresAt: refreshTokenExpiresAt,
|
|
168
193
|
});
|
|
169
194
|
|
|
195
|
+
const accessToken = signAccessToken({
|
|
196
|
+
userId: user.id,
|
|
197
|
+
role: user.role,
|
|
198
|
+
sessionId: session.id,
|
|
199
|
+
});
|
|
200
|
+
|
|
170
201
|
await authRepo.createRefreshToken({
|
|
171
202
|
token: refreshToken,
|
|
172
203
|
userId: user.id,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-tigra",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Create a production-ready full-stack app with Next.js 16 + Fastify 5 + Prisma + Redis",
|
|
6
6
|
"bin": {
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"bin",
|
|
11
11
|
"lib",
|
|
12
12
|
"modules",
|
|
13
|
-
"template"
|
|
13
|
+
"template",
|
|
14
|
+
"CHANGELOG.md"
|
|
14
15
|
],
|
|
15
16
|
"engines": {
|
|
16
17
|
"node": ">=22.12.0"
|
|
@@ -42,7 +43,8 @@
|
|
|
42
43
|
},
|
|
43
44
|
"homepage": "https://github.com/blessandsoul/create-tigra#readme",
|
|
44
45
|
"scripts": {
|
|
45
|
-
"create:test": "node -e \"import('fs').then(f=>f.rmSync('testapp',{recursive:true,force:true}))\" && node bin/create-tigra.js testapp"
|
|
46
|
+
"create:test": "node -e \"import('fs').then(f=>f.rmSync('testapp',{recursive:true,force:true}))\" && node bin/create-tigra.js testapp",
|
|
47
|
+
"check:init-migration": "node scripts/check-init-migration.mjs"
|
|
46
48
|
},
|
|
47
49
|
"dependencies": {
|
|
48
50
|
"chalk": "^5.4.1",
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Dependabot.
|
|
2
|
+
#
|
|
3
|
+
# npm packages and GitHub Actions: security updates only. A pull request when a
|
|
4
|
+
# dependency has a known vulnerability with a fix, and no routine version-bump
|
|
5
|
+
# pull requests (open-pull-requests-limit: 0 turns those off; security updates
|
|
6
|
+
# have their own limit). Turn them on once per repository: Settings → Advanced
|
|
7
|
+
# Security → "Dependabot security updates".
|
|
8
|
+
#
|
|
9
|
+
# Docker base images: monthly version updates (Dependabot has no security
|
|
10
|
+
# updates for Docker). Both Dockerfiles pin node:24-alpine by digest, and a
|
|
11
|
+
# digest pin never changes by itself: without this the images would never
|
|
12
|
+
# get Node or Alpine security fixes. Node major versions (24 -> 25) are left
|
|
13
|
+
# out on purpose: upgrade those deliberately. Both Dockerfiles must keep the
|
|
14
|
+
# same digest, so merge the server and client pull requests together.
|
|
15
|
+
version: 2
|
|
16
|
+
updates:
|
|
17
|
+
- package-ecosystem: npm
|
|
18
|
+
directory: /server
|
|
19
|
+
schedule:
|
|
20
|
+
interval: weekly
|
|
21
|
+
open-pull-requests-limit: 0
|
|
22
|
+
- package-ecosystem: npm
|
|
23
|
+
directory: /client
|
|
24
|
+
schedule:
|
|
25
|
+
interval: weekly
|
|
26
|
+
open-pull-requests-limit: 0
|
|
27
|
+
- package-ecosystem: github-actions
|
|
28
|
+
directory: /
|
|
29
|
+
schedule:
|
|
30
|
+
interval: weekly
|
|
31
|
+
open-pull-requests-limit: 0
|
|
32
|
+
- package-ecosystem: docker
|
|
33
|
+
directory: /server
|
|
34
|
+
schedule:
|
|
35
|
+
interval: monthly
|
|
36
|
+
open-pull-requests-limit: 2
|
|
37
|
+
ignore:
|
|
38
|
+
- dependency-name: node
|
|
39
|
+
update-types: ['version-update:semver-major']
|
|
40
|
+
- package-ecosystem: docker
|
|
41
|
+
directory: /client
|
|
42
|
+
schedule:
|
|
43
|
+
interval: monthly
|
|
44
|
+
open-pull-requests-limit: 2
|
|
45
|
+
ignore:
|
|
46
|
+
- dependency-name: node
|
|
47
|
+
update-types: ['version-update:semver-major']
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: Dependency audit
|
|
2
|
+
|
|
3
|
+
# Once a week: does anything production installs have a known CRITICAL
|
|
4
|
+
# advisory? Not part of CI, so it never blocks a merge; a red run is the
|
|
5
|
+
# signal to update. Critical, not high: some high advisories sit in tooling
|
|
6
|
+
# that only a major upgrade fixes (Prisma's config loader, until Prisma 7),
|
|
7
|
+
# and a check that is red from day one teaches everyone to ignore it. Fixable
|
|
8
|
+
# high advisories reach you as Dependabot security pull requests
|
|
9
|
+
# (.github/dependabot.yml).
|
|
10
|
+
on:
|
|
11
|
+
schedule:
|
|
12
|
+
- cron: '17 6 * * 1' # Mondays 06:17 UTC
|
|
13
|
+
workflow_dispatch:
|
|
14
|
+
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
audit:
|
|
20
|
+
name: npm audit (${{ matrix.app }}, production dependencies)
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
strategy:
|
|
23
|
+
fail-fast: false
|
|
24
|
+
matrix:
|
|
25
|
+
app: [server, client]
|
|
26
|
+
defaults:
|
|
27
|
+
run:
|
|
28
|
+
working-directory: ${{ matrix.app }}
|
|
29
|
+
steps:
|
|
30
|
+
- uses: actions/checkout@v4
|
|
31
|
+
- uses: actions/setup-node@v4
|
|
32
|
+
with:
|
|
33
|
+
node-version: 24
|
|
34
|
+
# Reads package-lock.json; nothing is installed.
|
|
35
|
+
- name: Audit
|
|
36
|
+
run: npm audit --omit=dev --audit-level=critical
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
# Every push and pull request: typecheck, lint, tests and builds for both
|
|
4
|
+
# apps. Checks only — it never deploys. See server/docs/testing.md.
|
|
5
|
+
on:
|
|
6
|
+
push:
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
server:
|
|
14
|
+
name: server (typecheck · lint · unit tests + coverage · build)
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
defaults:
|
|
17
|
+
run:
|
|
18
|
+
working-directory: server
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
- uses: actions/setup-node@v4
|
|
22
|
+
with:
|
|
23
|
+
node-version: 24
|
|
24
|
+
- name: Install dependencies (exactly the lockfile)
|
|
25
|
+
run: npm ci --include=optional
|
|
26
|
+
- name: Generate Prisma client
|
|
27
|
+
run: npx prisma generate
|
|
28
|
+
- name: Typecheck
|
|
29
|
+
run: npm run typecheck
|
|
30
|
+
- name: Lint
|
|
31
|
+
run: npm run lint
|
|
32
|
+
# Unit tests with the coverage ratchet (vitest.config.ts): fails when
|
|
33
|
+
# coverage drops below the recorded numbers.
|
|
34
|
+
- name: Unit tests and coverage
|
|
35
|
+
run: npm run test:coverage
|
|
36
|
+
- name: Build
|
|
37
|
+
run: npm run build
|
|
38
|
+
|
|
39
|
+
server-integration:
|
|
40
|
+
name: server integration tests (real MySQL + Redis)
|
|
41
|
+
runs-on: ubuntu-latest
|
|
42
|
+
defaults:
|
|
43
|
+
run:
|
|
44
|
+
working-directory: server
|
|
45
|
+
steps:
|
|
46
|
+
- uses: actions/checkout@v4
|
|
47
|
+
- uses: actions/setup-node@v4
|
|
48
|
+
with:
|
|
49
|
+
node-version: 24
|
|
50
|
+
- name: Install dependencies (exactly the lockfile)
|
|
51
|
+
run: npm ci --include=optional
|
|
52
|
+
- name: Generate Prisma client
|
|
53
|
+
run: npx prisma generate
|
|
54
|
+
# Testcontainers starts a throwaway MySQL 8.4 and Redis 7 (GitHub's
|
|
55
|
+
# Ubuntu runners have Docker) and applies prisma/migrations.
|
|
56
|
+
- name: Integration tests
|
|
57
|
+
run: npm run test:integration
|
|
58
|
+
|
|
59
|
+
client:
|
|
60
|
+
name: client (typecheck · lint · unit tests + coverage · build)
|
|
61
|
+
runs-on: ubuntu-latest
|
|
62
|
+
defaults:
|
|
63
|
+
run:
|
|
64
|
+
working-directory: client
|
|
65
|
+
steps:
|
|
66
|
+
- uses: actions/checkout@v4
|
|
67
|
+
- uses: actions/setup-node@v4
|
|
68
|
+
with:
|
|
69
|
+
node-version: 24
|
|
70
|
+
- name: Install dependencies (exactly the lockfile)
|
|
71
|
+
run: npm ci --include=optional
|
|
72
|
+
- name: Typecheck
|
|
73
|
+
run: npm run typecheck
|
|
74
|
+
- name: Lint
|
|
75
|
+
run: npm run lint
|
|
76
|
+
- name: Unit tests and coverage
|
|
77
|
+
run: npm run test:coverage
|
|
78
|
+
- name: Build
|
|
79
|
+
run: npm run build
|