create-knit 0.10.0 → 0.11.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 +1 -1
- package/template/base/AGENTS.md +4 -0
- package/template/base/apps/web/.env.example +16 -0
- package/template/base/llms.txt +3 -2
- package/template/examples/layers/example-dashboard/app/pages/dashboard.vue +19 -0
- package/template/examples/layers/example-dashboard/i18n/locales/de.json +3 -1
- package/template/examples/layers/example-dashboard/i18n/locales/en.json +3 -1
- package/template/examples/layers/example-dashboard/i18n/locales/es.json +3 -1
- package/template/versions.json +1 -1
package/package.json
CHANGED
package/template/base/AGENTS.md
CHANGED
|
@@ -97,6 +97,10 @@ pnpm manage test --unit # fast; pnpm test runs e2e too (builds
|
|
|
97
97
|
- **Resources** must be *exported*. `_choices` for a foreign key goes through the target table's resource (no resource, no choices).
|
|
98
98
|
- **Realtime channels are default-deny:** a channel without `authorize` needs a signed-in user. `broadcastModel` fires after commit, for `useModel` writes only.
|
|
99
99
|
- **CSRF:** cookie-carrying cross-site `POST`/`PUT`/`PATCH`/`DELETE` to `/api/**` get 403. With curl, send no `Origin` or the server's own origin. Webhooks go in `NUXT_KNIT_SECURITY_CSRF_EXEMPT`.
|
|
100
|
+
- **Writes are rate limited:** 120 a minute per caller on resources and endpoints, 30 uploads; over it is a 429 with `Retry-After`. A route's own `rateLimit` replaces the default; a test suite that hammers writes sets `NUXT_KNIT_RATE_LIMIT_ENABLED=false`.
|
|
101
|
+
- **API tokens** (`Authorization: Bearer knit_…`, off until `NUXT_KNIT_AUTH_API_TOKENS_ENABLED=true`) act as a user, ignore cookies, and are refused on `/api/_admin`, `/api/auth` and realtime. Your handlers need no changes: `requireAuth`, permissions and policies see the token's user.
|
|
102
|
+
- **`queueMail()` in requests, `sendMail()` in scripts:** `sendMail()` throws when the mailer fails; `queueMail()` and `template.queue()` never do.
|
|
103
|
+
- **Cursor pages have no `total`:** `?cursor=`, `paginateCursor()` and `useResource().infinite()` return `next` instead. Keep `list()` / `paginate()` where you show page numbers.
|
|
100
104
|
- **Vue's `useModel` shadows Knit's** in typechecking. In server files, import it explicitly from `@knit-framework/core/models`.
|
|
101
105
|
- **Two dev servers on `localhost`** share cookies across ports. Use `http://<name>.localhost:<port>`.
|
|
102
106
|
- **Drizzle renders columns unqualified inside `` sql`…` ``.** In correlated subqueries, write table-qualified names.
|
|
@@ -44,6 +44,22 @@ NUXT_BETTER_AUTH_URL=
|
|
|
44
44
|
# Behind a reverse proxy, read the client IP from X-Forwarded-For: false (default) | true
|
|
45
45
|
# NUXT_BETTER_AUTH_TRUST_PROXY=false
|
|
46
46
|
|
|
47
|
+
# Rate limits for resources, endpoints and uploads, per caller (docs/security.md#rate-limiting).
|
|
48
|
+
# NUXT_KNIT_RATE_LIMIT_ENABLED=true
|
|
49
|
+
# Where counts are kept: database (default, shared by every instance) | memory (per process)
|
|
50
|
+
# NUXT_KNIT_RATE_LIMIT_STORE=database
|
|
51
|
+
# Requests per minute and caller; 0 is no limit. A route's own `rateLimit` replaces these.
|
|
52
|
+
# NUXT_KNIT_RATE_LIMIT_WRITES=120
|
|
53
|
+
# NUXT_KNIT_RATE_LIMIT_UPLOADS=30
|
|
54
|
+
# NUXT_KNIT_RATE_LIMIT_READS=0
|
|
55
|
+
|
|
56
|
+
# API tokens for scripts, apps and other servers (docs/api-tokens.md): false (default) | true
|
|
57
|
+
# NUXT_KNIT_AUTH_API_TOKENS_ENABLED=false
|
|
58
|
+
# Who may create tokens on the account page: authenticated (default) | staff
|
|
59
|
+
# NUXT_KNIT_AUTH_API_TOKENS_CREATE=authenticated
|
|
60
|
+
# Longest lifetime of a token in days; 0 (default) is no limit
|
|
61
|
+
# NUXT_KNIT_AUTH_API_TOKENS_MAX_LIFETIME=0
|
|
62
|
+
|
|
47
63
|
# Sign-in options (docs/auth.md#sign-in-options). A provider is on when both its id and secret are
|
|
48
64
|
# set; register the callback URL <site>/api/auth/callback/<provider> at the provider.
|
|
49
65
|
# NUXT_KNIT_AUTH_PROVIDERS_GITHUB_CLIENT_ID=
|
package/template/base/llms.txt
CHANGED
|
@@ -22,8 +22,9 @@ Agents working in a Knit project: read AGENTS.md, and use the `knit` MCP server
|
|
|
22
22
|
- [Auth & permissions](node_modules/@knit-framework/core/docs/auth.md): Users, staff, superusers, groups, permissions, `/accounts/*` pages, sign-in options, the session cache
|
|
23
23
|
- [Row-level permissions](node_modules/@knit-framework/core/docs/permissions.md): which permission goes where (model permissions, admin switches, resource rules, policies), `defineModelMeta(table, { policy })`, `useModel(table).as(actor)`, what the admin, resources and realtime apply
|
|
24
24
|
- [Organizations](node_modules/@knit-framework/core/docs/organizations.md): `NUXT_KNIT_AUTH_ORGANIZATIONS_ENABLED`, invitations, roles, `inActiveOrganization` / `hasOrganizationRole` / `assignOrganization`, `useOrganization()`, `switchOrganization()` in tests
|
|
25
|
+
- [API tokens](node_modules/@knit-framework/core/docs/api-tokens.md): `NUXT_KNIT_AUTH_API_TOKENS_ENABLED`, `Authorization: Bearer knit_…`, tokens act as a user with optional narrower permissions, `pnpm manage createtoken`, `createTestClient(url, { token })`
|
|
25
26
|
- [Internationalization](node_modules/@knit-framework/core/docs/i18n.md): Translations, locales per layer, translating models, the language switcher
|
|
26
|
-
- [Email](node_modules/@knit-framework/core/docs/email.md): `sendMail()`, mailers, templates, auth emails
|
|
27
|
+
- [Email](node_modules/@knit-framework/core/docs/email.md): `sendMail()`, `queueMail()` (does not fail the request, retries on the database task backend), mailers, templates, auth emails
|
|
27
28
|
- [Background tasks](node_modules/@knit-framework/core/docs/tasks.md): `defineTask`, `enqueue`, the worker, cron schedules
|
|
28
29
|
- [Realtime](node_modules/@knit-framework/core/docs/realtime.md): Channels over SSE and WebSocket, `publish`, `broadcastModel`, `useRealtime`, scaling with Postgres
|
|
29
30
|
- [Files & uploads](node_modules/@knit-framework/core/docs/files.md): `fileColumn`, uploads, disk/S3 storage
|
|
@@ -31,7 +32,7 @@ Agents working in a Knit project: read AGENTS.md, and use the `knit` MCP server
|
|
|
31
32
|
- [Sitemaps & feeds](node_modules/@knit-framework/core/docs/sitemaps-and-feeds.md): `/sitemap.xml`, RSS and Atom
|
|
32
33
|
- [Observability](node_modules/@knit-framework/core/docs/observability.md): OpenTelemetry traces (NUXT_KNIT_TELEMETRY_ENABLED), what each span contains, `withSpan`
|
|
33
34
|
- [Logging](node_modules/@knit-framework/core/docs/logging.md): LogLayer: pretty dev output, JSON in production, request logs, redaction
|
|
34
|
-
- [Security](node_modules/@knit-framework/core/docs/security.md): CSRF, security headers, CSP
|
|
35
|
+
- [Security](node_modules/@knit-framework/core/docs/security.md): CSRF, security headers, CSP, rate limiting (`rateLimit` on resources and endpoints, `assertRateLimit`, `NUXT_KNIT_RATE_LIMIT_*`, 429 with `Retry-After`)
|
|
35
36
|
- [Testing](node_modules/@knit-framework/core/docs/testing.md): Test databases (PGlite, or Postgres with `KNIT_TEST_DATABASE_URL`), factories, the HTTP client, `pnpm test`
|
|
36
37
|
- [Knit in Nuxt DevTools](node_modules/@knit-framework/core/docs/devtools.md): the dev-only Knit tab (models, routes, tasks, mail, realtime, errors, migrations), its actions and who may read it
|
|
37
38
|
- [`manage` CLI](node_modules/@knit-framework/core/docs/cli.md): Every command, `startapp` and `generate`, JSON output for scripts and agents, seeds, custom commands
|
|
@@ -11,6 +11,9 @@ useHead({ title: () => t('dashboard.title') })
|
|
|
11
11
|
|
|
12
12
|
const posts = useResource<typeof post>('posts').list({ perPage: 100, key: 'dashboard-posts' })
|
|
13
13
|
|
|
14
|
+
// A list that grows: five posts now, five more per click. It pages by cursor, so the server counts nothing.
|
|
15
|
+
const recent = useResource<typeof post>('posts').infinite({ perPage: 5, key: 'dashboard-recent' })
|
|
16
|
+
|
|
14
17
|
const browser = reactive({
|
|
15
18
|
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
16
19
|
online: navigator.onLine,
|
|
@@ -63,5 +66,21 @@ const latest = computed(() => posts.items.value[0])
|
|
|
63
66
|
</p>
|
|
64
67
|
</UCard>
|
|
65
68
|
</div>
|
|
69
|
+
|
|
70
|
+
<UCard data-testid="recent-posts">
|
|
71
|
+
<template #header>
|
|
72
|
+
<h2 class="font-semibold text-highlighted">{{ t('dashboard.recent') }}</h2>
|
|
73
|
+
</template>
|
|
74
|
+
<ul class="divide-y divide-default">
|
|
75
|
+
<li v-for="item in recent.items.value" :key="item.id" class="flex items-center justify-between gap-3 py-2">
|
|
76
|
+
<ULink :to="`/blog/${item.slug}`" class="min-w-0 truncate font-medium">{{ item.title }}</ULink>
|
|
77
|
+
<NuxtTime v-if="item.publishedAt" :datetime="item.publishedAt" :locale="locale" date-style="medium" class="shrink-0 text-sm text-muted" />
|
|
78
|
+
</li>
|
|
79
|
+
</ul>
|
|
80
|
+
<p v-if="!recent.items.value.length" class="text-sm text-muted">—</p>
|
|
81
|
+
<template v-if="recent.hasMore.value" #footer>
|
|
82
|
+
<UButton :label="t('dashboard.loadMore')" icon="i-lucide-chevrons-down" color="neutral" variant="subtle" :loading="recent.loadingMore.value" data-testid="load-more" @click="recent.loadMore()" />
|
|
83
|
+
</template>
|
|
84
|
+
</UCard>
|
|
66
85
|
</UContainer>
|
|
67
86
|
</template>
|
package/template/versions.json
CHANGED