create-guren-app 1.18.4 → 1.19.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-guren-app",
3
- "version": "1.18.4",
3
+ "version": "1.19.1",
4
4
  "description": "Scaffold a Guren app: a Bun-first fullstack TypeScript framework with Laravel-style conventions, Inertia.js + React, Drizzle ORM, and an agent harness for Claude Code and other coding agents.",
5
5
  "keywords": [
6
6
  "guren",
@@ -10,7 +10,10 @@ jobs:
10
10
  checks:
11
11
  runs-on: ubuntu-latest
12
12
  steps:
13
- - uses: actions/checkout@v4
13
+ - uses: actions/checkout@v7
14
+ with:
15
+ # `guren check` judges the migrations not on main yet, which needs main's history.
16
+ fetch-depth: 0
14
17
 
15
18
  - uses: oven-sh/setup-bun@v2
16
19
 
@@ -21,13 +21,13 @@
21
21
  "test": "bun test"
22
22
  },
23
23
  "dependencies": {
24
- "@guren/cli": "^2.31.1",
25
- "@guren/core": "^1.24.0",
26
- "@guren/orm": "^2.14.0",
24
+ "@guren/cli": "^2.32.1",
25
+ "@guren/core": "^1.25.0",
26
+ "@guren/orm": "^2.15.0",
27
27
  "drizzle-orm": "1.0.0-rc.4"
28
28
  },
29
29
  "devDependencies": {
30
- "@guren/testing": "^1.14.1",
30
+ "@guren/testing": "^1.14.2",
31
31
  "bun-types": "^1.3.1",
32
32
  "drizzle-kit": "1.0.0-rc.4",
33
33
  "oxlint": "~1.81.0",
@@ -1,13 +1,19 @@
1
- import { createRateLimitMiddleware, getRequestTranslator, ValidationException } from '@guren/core'
2
- import type { Context, Middleware } from '@guren/core'
1
+ import { AUTH_CONTEXT_KEY, createRateLimitMiddleware, getRequestTranslator, ValidationException } from '@guren/core'
2
+ import type { AuthContext, Context, Middleware } from '@guren/core'
3
3
 
4
4
  interface ThrottleOptions {
5
- /** Requests allowed per client and email address within the window. */
5
+ /** Requests allowed per key within the window. */
6
6
  limit: number
7
7
  windowMs: number
8
8
  /** Translation key; `:seconds` is replaced with the wait. */
9
9
  messageKey: string
10
10
  fallbackMessage: string
11
+ /** Defaults to the client IP and the submitted email. */
12
+ key?: (ctx: Context) => Promise<string>
13
+ /** A request this returns true for is not counted. */
14
+ skip?: (ctx: Context) => Promise<boolean>
15
+ /** The form field an Inertia request shows the message under. */
16
+ errorField?: string
11
17
  }
12
18
 
13
19
  interface BunServerEnv {
@@ -21,18 +27,23 @@ function clientIp(ctx: Context): string | undefined {
21
27
  }
22
28
 
23
29
  // Hono caches the parsed body, so the controller still reads it after this.
24
- async function submittedEmail(ctx: Context): Promise<string | undefined> {
30
+ // `undefined` when the body cannot be read as an object.
31
+ async function submittedBody(ctx: Context): Promise<Record<string, unknown> | undefined> {
25
32
  try {
26
33
  const body: unknown = (ctx.req.header('content-type') ?? '').includes('application/json')
27
34
  ? await ctx.req.json()
28
35
  : await ctx.req.parseBody()
29
- const email = (body as Record<string, unknown> | null)?.email
30
- return typeof email === 'string' ? email.trim().toLowerCase() : undefined
36
+ return typeof body === 'object' && body !== null ? (body as Record<string, unknown>) : undefined
31
37
  } catch {
32
38
  return undefined
33
39
  }
34
40
  }
35
41
 
42
+ async function submittedEmail(ctx: Context): Promise<string | undefined> {
43
+ const email = (await submittedBody(ctx))?.email
44
+ return typeof email === 'string' ? email.trim().toLowerCase() : undefined
45
+ }
46
+
36
47
  function throttleMessage(ctx: Context, options: ThrottleOptions, seconds: number): string {
37
48
  const translated = getRequestTranslator(ctx)?.t(options.messageKey, { seconds })
38
49
  return translated && translated !== options.messageKey
@@ -41,9 +52,9 @@ function throttleMessage(ctx: Context, options: ThrottleOptions, seconds: number
41
52
  }
42
53
 
43
54
  /**
44
- * Counts every request, keyed per client IP and submitted email. The default
45
- * store lives in process memory: pass `store: new RedisRateLimitStore(redis)`
46
- * (from `@guren/core/redis`) to share counts across instances.
55
+ * Counts every request `skip` lets through, per `key`. The default store lives
56
+ * in process memory: pass `store: new RedisRateLimitStore(redis)` (from
57
+ * `@guren/core/redis`) to share counts across instances.
47
58
  */
48
59
  function authThrottle(name: string, options: ThrottleOptions): Middleware {
49
60
  // Built on the first request: the default store starts a sweep timer, which
@@ -54,12 +65,13 @@ function authThrottle(name: string, options: ThrottleOptions): Middleware {
54
65
  limit: options.limit,
55
66
  windowMs: options.windowMs,
56
67
  keyPrefix: `auth:${name}:`,
57
- keyGenerator: async (ctx) => `${clientIp(ctx) ?? 'unknown'}|${(await submittedEmail(ctx)) ?? ''}`,
68
+ keyGenerator: options.key ?? (async (ctx) => `${clientIp(ctx) ?? 'unknown'}|${(await submittedEmail(ctx)) ?? ''}`),
69
+ skip: options.skip,
58
70
  onRateLimited: (ctx, retryAfter) => {
59
71
  const message = throttleMessage(ctx, options, retryAfter)
60
72
  // An Inertia form shows a flashed error; a bare 429 would open its error modal.
61
73
  if (ctx.req.header('x-inertia') === 'true') {
62
- throw ValidationException.withMessages({ message })
74
+ throw ValidationException.withMessages({ [options.errorField ?? 'message']: message })
63
75
  }
64
76
  return ctx.json({ message, retryAfter }, 429)
65
77
  },
@@ -88,3 +100,22 @@ export const throttlePasswordResetRequest = authThrottle('forgot-password', {
88
100
  messageKey: 'auth.too_many_requests',
89
101
  fallbackMessage: 'Too many requests. Please try again in :seconds seconds.',
90
102
  })
103
+
104
+ // Per signed-in user, so a stolen session cannot guess the current password the
105
+ // profile form asks for. Only a request carrying one reaches that check.
106
+ export const throttleProfileUpdate = authThrottle('profile', {
107
+ limit: 5,
108
+ windowMs: 60_000,
109
+ messageKey: 'auth.too_many_requests',
110
+ fallbackMessage: 'Too many requests. Please try again in :seconds seconds.',
111
+ key: async (ctx) => {
112
+ const id = await (ctx.get(AUTH_CONTEXT_KEY) as AuthContext | undefined)?.id()
113
+ return id === undefined || id === null ? `ip:${clientIp(ctx) ?? 'unknown'}` : `user:${String(id)}`
114
+ },
115
+ // Mirrors the controller's `currentPassword === ''`; an unreadable body is counted.
116
+ skip: async (ctx) => {
117
+ const body = await submittedBody(ctx)
118
+ return body !== undefined && (body.currentPassword === undefined || body.currentPassword === '')
119
+ },
120
+ errorField: 'currentPassword',
121
+ })
@@ -1,4 +1,5 @@
1
1
  import { Head, useForm } from '@inertiajs/react'
2
+ import { useId } from 'react'
2
3
  import type { ApiRoutes } from '@/.guren/api-client.gen'
3
4
  import { route } from '@/.guren/routes.gen'
4
5
  import Layout from '../../components/Layout.js'
@@ -19,6 +20,10 @@ export default function EditPost({ post }: Props) {
19
20
  body: post.body,
20
21
  })
21
22
 
23
+ const titleId = useId()
24
+ const excerptId = useId()
25
+ const bodyId = useId()
26
+
22
27
  return (
23
28
  <Layout>
24
29
  <Head title={`Edit ${post.title}`} />
@@ -36,8 +41,11 @@ export default function EditPost({ post }: Props) {
36
41
  }}
37
42
  >
38
43
  <div>
39
- <label className="block text-sm font-bold text-g-heading">Title</label>
44
+ <label htmlFor={titleId} className="block text-sm font-bold text-g-heading">
45
+ Title
46
+ </label>
40
47
  <input
48
+ id={titleId}
41
49
  type="text"
42
50
  value={form.data.title}
43
51
  onChange={(event) => form.setData('title', event.target.value)}
@@ -47,8 +55,11 @@ export default function EditPost({ post }: Props) {
47
55
  </div>
48
56
 
49
57
  <div>
50
- <label className="block text-sm font-bold text-g-heading">Excerpt</label>
58
+ <label htmlFor={excerptId} className="block text-sm font-bold text-g-heading">
59
+ Excerpt
60
+ </label>
51
61
  <input
62
+ id={excerptId}
52
63
  type="text"
53
64
  value={form.data.excerpt}
54
65
  onChange={(event) => form.setData('excerpt', event.target.value)}
@@ -58,8 +69,11 @@ export default function EditPost({ post }: Props) {
58
69
  </div>
59
70
 
60
71
  <div>
61
- <label className="block text-sm font-bold text-g-heading">Body</label>
72
+ <label htmlFor={bodyId} className="block text-sm font-bold text-g-heading">
73
+ Body
74
+ </label>
62
75
  <textarea
76
+ id={bodyId}
63
77
  rows={10}
64
78
  value={form.data.body}
65
79
  onChange={(event) => form.setData('body', event.target.value)}
@@ -1,4 +1,5 @@
1
1
  import { Head, useForm } from '@inertiajs/react'
2
+ import { useId } from 'react'
2
3
  import type { ApiRoutes } from '@/.guren/api-client.gen'
3
4
  import { route } from '@/.guren/routes.gen'
4
5
  import Layout from '../../components/Layout.js'
@@ -11,6 +12,10 @@ const fieldClass =
11
12
  export default function NewPost() {
12
13
  const form = useForm<PostFormData>({ title: '', excerpt: '', body: '' })
13
14
 
15
+ const titleId = useId()
16
+ const excerptId = useId()
17
+ const bodyId = useId()
18
+
14
19
  return (
15
20
  <Layout>
16
21
  <Head title="New post" />
@@ -28,8 +33,11 @@ export default function NewPost() {
28
33
  }}
29
34
  >
30
35
  <div>
31
- <label className="block text-sm font-bold text-g-heading">Title</label>
36
+ <label htmlFor={titleId} className="block text-sm font-bold text-g-heading">
37
+ Title
38
+ </label>
32
39
  <input
40
+ id={titleId}
33
41
  type="text"
34
42
  value={form.data.title}
35
43
  onChange={(event) => form.setData('title', event.target.value)}
@@ -39,8 +47,11 @@ export default function NewPost() {
39
47
  </div>
40
48
 
41
49
  <div>
42
- <label className="block text-sm font-bold text-g-heading">Excerpt</label>
50
+ <label htmlFor={excerptId} className="block text-sm font-bold text-g-heading">
51
+ Excerpt
52
+ </label>
43
53
  <input
54
+ id={excerptId}
44
55
  type="text"
45
56
  value={form.data.excerpt}
46
57
  onChange={(event) => form.setData('excerpt', event.target.value)}
@@ -50,8 +61,11 @@ export default function NewPost() {
50
61
  </div>
51
62
 
52
63
  <div>
53
- <label className="block text-sm font-bold text-g-heading">Body</label>
64
+ <label htmlFor={bodyId} className="block text-sm font-bold text-g-heading">
65
+ Body
66
+ </label>
54
67
  <textarea
68
+ id={bodyId}
55
69
  rows={10}
56
70
  value={form.data.body}
57
71
  onChange={(event) => form.setData('body', event.target.value)}
@@ -1,5 +1,5 @@
1
1
  import { Head, useForm } from '@inertiajs/react'
2
- import type { FormEvent } from 'react'
2
+ import { useId, type FormEvent } from 'react'
3
3
  import Layout from '../../components/Layout.js'
4
4
  import type { ValidationErrors } from '@guren/core'
5
5
 
@@ -22,6 +22,10 @@ export default function ProfileEdit({ profile, status }: Props) {
22
22
  password: '',
23
23
  })
24
24
 
25
+ const nameId = useId()
26
+ const emailId = useId()
27
+ const passwordId = useId()
28
+
25
29
  const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
26
30
  event.preventDefault()
27
31
  form.put('/profile')
@@ -48,8 +52,11 @@ export default function ProfileEdit({ profile, status }: Props) {
48
52
 
49
53
  <form className="space-y-4" onSubmit={handleSubmit}>
50
54
  <div>
51
- <label className="block text-sm font-bold text-g-heading">Name</label>
55
+ <label htmlFor={nameId} className="block text-sm font-bold text-g-heading">
56
+ Name
57
+ </label>
52
58
  <input
59
+ id={nameId}
53
60
  type="text"
54
61
  value={form.data.name}
55
62
  onChange={(event) => form.setData('name', event.target.value)}
@@ -59,8 +66,11 @@ export default function ProfileEdit({ profile, status }: Props) {
59
66
  </div>
60
67
 
61
68
  <div>
62
- <label className="block text-sm font-bold text-g-heading">Email</label>
69
+ <label htmlFor={emailId} className="block text-sm font-bold text-g-heading">
70
+ Email
71
+ </label>
63
72
  <input
73
+ id={emailId}
64
74
  type="email"
65
75
  value={form.data.email}
66
76
  onChange={(event) => form.setData('email', event.target.value)}
@@ -70,8 +80,11 @@ export default function ProfileEdit({ profile, status }: Props) {
70
80
  </div>
71
81
 
72
82
  <div>
73
- <label className="block text-sm font-bold text-g-heading">New password</label>
83
+ <label htmlFor={passwordId} className="block text-sm font-bold text-g-heading">
84
+ New password
85
+ </label>
74
86
  <input
87
+ id={passwordId}
75
88
  type="password"
76
89
  value={form.data.password}
77
90
  onChange={(event) => form.setData('password', event.target.value)}
@@ -3,6 +3,9 @@ import env from './env.js'
3
3
 
4
4
  const database = createMySqlDatabase({
5
5
  migrationsFolder: new URL('../db/migrations', import.meta.url),
6
+ // A pending migration that drops, narrows or renames is refused at boot and by
7
+ // `guren db:migrate` until its first line reads `-- guren:allow-destructive: <reason>`.
8
+ destructiveMigrations: 'refuse',
6
9
  seedersFolder: new URL('../db/seeders', import.meta.url),
7
10
  // `context` is the application's validated environment. `guren db:*` runs this
8
11
  // outside one, where report mode reads the schema without requiring the keys
@@ -3,6 +3,9 @@ import env from './env.js'
3
3
 
4
4
  const database = createPostgresDatabase({
5
5
  migrationsFolder: new URL('../db/migrations', import.meta.url),
6
+ // A pending migration that drops, narrows or renames is refused at boot and by
7
+ // `guren db:migrate` until its first line reads `-- guren:allow-destructive: <reason>`.
8
+ destructiveMigrations: 'refuse',
6
9
  seedersFolder: new URL('../db/seeders', import.meta.url),
7
10
  // `context` is the application's validated environment. `guren db:*` runs this
8
11
  // outside one, where report mode reads the schema without requiring the keys
@@ -3,6 +3,9 @@ import env from './env.js'
3
3
 
4
4
  const database = createSqliteDatabase({
5
5
  migrationsFolder: new URL('../db/migrations', import.meta.url),
6
+ // A pending migration that drops, narrows or renames is refused at boot and by
7
+ // `guren db:migrate` until its first line reads `-- guren:allow-destructive: <reason>`.
8
+ destructiveMigrations: 'refuse',
6
9
  seedersFolder: new URL('../db/seeders', import.meta.url),
7
10
  // `context` is the application's validated environment. `guren db:*` runs this
8
11
  // outside one, where report mode reads the schema without requiring the keys
@@ -10,7 +10,10 @@ jobs:
10
10
  checks:
11
11
  runs-on: ubuntu-latest
12
12
  steps:
13
- - uses: actions/checkout@v4
13
+ - uses: actions/checkout@v7
14
+ with:
15
+ # `guren check` judges the migrations not on main yet, which needs main's history.
16
+ fetch-depth: 0
14
17
 
15
18
  - uses: oven-sh/setup-bun@v2
16
19
 
@@ -22,10 +22,10 @@
22
22
  "db:seed": "bunx guren db:seed"
23
23
  },
24
24
  "dependencies": {
25
- "@guren/cli": "^2.31.1",
26
- "@guren/core": "^1.24.0",
25
+ "@guren/cli": "^2.32.1",
26
+ "@guren/core": "^1.25.0",
27
27
  "@guren/inertia-client": "^1.2.2",
28
- "@guren/orm": "^2.14.0",
28
+ "@guren/orm": "^2.15.0",
29
29
  "@inertiajs/react": "^3.6.1",
30
30
  "drizzle-orm": "1.0.0-rc.4",
31
31
  "react": "^19.0.0",
@@ -33,7 +33,7 @@
33
33
  "zod": "^4.5.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@guren/testing": "^1.14.1",
36
+ "@guren/testing": "^1.14.2",
37
37
  "@tailwindcss/vite": "^4.2.2",
38
38
  "@types/react": "^19.0.0",
39
39
  "@types/react-dom": "^19.0.0",