tinyzoo 0.2.2 → 0.4.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.
Files changed (72) hide show
  1. package/app/components/CmsDayPicker.vue +5 -1
  2. package/app/components/CmsFieldColor.vue +3 -3
  3. package/app/components/CmsFieldDate.vue +5 -3
  4. package/app/components/CmsFieldGallery.vue +1 -1
  5. package/app/components/CmsFieldRelationOne.vue +1 -1
  6. package/app/components/CmsFieldText.vue +1 -1
  7. package/app/components/CmsListFilters.vue +1 -1
  8. package/app/components/CmsMoment.vue +1 -1
  9. package/app/components/CmsPasswordInput.vue +1 -1
  10. package/app/components/CmsPreviewPanel.vue +4 -4
  11. package/app/components/CmsPublishReview.vue +1 -1
  12. package/app/components/CmsRevisions.vue +1 -1
  13. package/app/components/CmsRichTextEditor.vue +3 -3
  14. package/app/components/CmsSingletonForm.vue +1 -1
  15. package/app/components/CmsTreeList.vue +3 -3
  16. package/app/i18n/cs.ts +43 -0
  17. package/app/i18n/de.ts +43 -0
  18. package/app/i18n/en.ts +43 -0
  19. package/app/middleware/cms-auth.global.ts +1 -1
  20. package/app/pages/admin/[entity]/[id].vue +9 -9
  21. package/app/pages/admin/[entity]/index.vue +7 -7
  22. package/app/pages/admin/account.vue +96 -4
  23. package/app/pages/admin/email/[token].vue +70 -0
  24. package/app/pages/admin/email/revert/[token].vue +70 -0
  25. package/app/pages/admin/media.vue +1 -1
  26. package/app/pages/admin/privacy.vue +6 -2
  27. package/app/pages/admin/styleguide.vue +1 -1
  28. package/app/pages/admin/team.vue +75 -2
  29. package/app/utils/cmsIssues.ts +2 -0
  30. package/cli/generate.ts +2 -1
  31. package/cli/index.ts +1 -1
  32. package/cli/upgrade.ts +24 -6
  33. package/cli/versions.ts +2 -2
  34. package/forms/index.ts +0 -3
  35. package/module.ts +33 -9
  36. package/nuxt.config.ts +4 -3
  37. package/package.json +11 -12
  38. package/server/api/cms/_auth/email/[token].get.ts +16 -0
  39. package/server/api/cms/_auth/email/confirm.post.ts +73 -0
  40. package/server/api/cms/_auth/email/index.delete.ts +11 -0
  41. package/server/api/cms/_auth/email/index.get.ts +10 -0
  42. package/server/api/cms/_auth/email/index.post.ts +86 -0
  43. package/server/api/cms/_auth/email/revert/[token].get.ts +15 -0
  44. package/server/api/cms/_auth/email/revert.post.ts +68 -0
  45. package/server/api/cms/_auth/me.patch.ts +1 -1
  46. package/server/api/cms/_auth/password.post.ts +1 -1
  47. package/server/api/cms/_collab/socket.ts +68 -20
  48. package/server/api/cms/_live.ts +1 -1
  49. package/server/api/cms/_privacy/export.post.ts +5 -1
  50. package/server/api/cms/_privacy/lookup.post.ts +5 -2
  51. package/server/api/cms/_users/[id].delete.ts +3 -0
  52. package/server/api/cms/_users/[id].patch.ts +114 -13
  53. package/server/api/cms/_users/index.post.ts +2 -1
  54. package/server/middleware/cms-session.ts +2 -0
  55. package/server/plugins/cms-0-config-check.ts +32 -7
  56. package/server/store/redis.ts +9 -1
  57. package/server/utils/cmsAudit.ts +10 -2
  58. package/server/utils/cmsAuth.ts +42 -6
  59. package/server/utils/cmsCollabServer.ts +27 -12
  60. package/server/utils/cmsEmailChange.ts +193 -0
  61. package/server/utils/cmsEmailChangeRules.ts +108 -0
  62. package/server/utils/cmsEmails.ts +155 -9
  63. package/server/utils/cmsLive.ts +7 -4
  64. package/server/utils/cmsPrivacy.ts +60 -11
  65. package/server/utils/cmsRetention.ts +4 -0
  66. package/server/utils/cmsSession.ts +42 -9
  67. package/src/appSecret.ts +88 -0
  68. package/src/index.ts +1 -1
  69. package/src/presets.ts +1 -33
  70. package/src/system.ts +1 -1
  71. package/starter/.env.example +3 -2
  72. package/starter/package.json +4 -4
@@ -1,4 +1,4 @@
1
- import { and, eq, or, propOf, sql } from 'tinyzoo'
1
+ import { and, eq, inArray, or, propOf, sql } from 'tinyzoo'
2
2
  import type { CmsEntity, CmsRegistry } from 'tinyzoo'
3
3
  import { z } from 'zod'
4
4
  import { formEntities, purgeSubmissions } from '../../forms/retention'
@@ -13,8 +13,11 @@ import { formEntities, purgeSubmissions } from '../../forms/retention'
13
13
  * fields equal the address (case-insensitive, whitespace trimmed) — and their saved
14
14
  * versions and search rows, which hold the same text;
15
15
  * - the account: email, name, role, status, language, sign-in times;
16
- * - audit entries: those the account made, those about it (invitation, role change)
17
- * and failed sign-ins that tried the address.
16
+ * - audit entries: those the account made, those about it (invitation, role change,
17
+ * a change of its address) and failed sign-ins that tried the address. A change of
18
+ * address names the new one as `email` and the old one as `previousEmail`; either finds it;
19
+ * - a change of sign-in address waiting for confirmation, or the way back from one
20
+ * (cms_state `email-change:*` / `email-revert:*`), that names the address.
18
21
  * Not covered: what an editor wrote under their own name in entries or media (that is
19
22
  * the site's content, not personal data about a visitor), and copies in backups.
20
23
  */
@@ -58,7 +61,7 @@ export async function findSubmissions(db: any, reg: CmsRegistry, email: string):
58
61
  /** The condition that picks the audit entries touching a person: theirs, about them, or naming their address. */
59
62
  export function auditCondition(reg: CmsRegistry, email: string, accountId: string | null) {
60
63
  const a = reg.cmsAudit
61
- const parts = [sql`lower(${a.meta}->>'email') = ${email}`]
64
+ const parts = [sql`lower(${a.meta}->>'email') = ${email}`, sql`lower(${a.meta}->>'previousEmail') = ${email}`]
62
65
  if (accountId) parts.push(eq(a.userId, accountId), and(eq(a.recordId, accountId), sql`${a.action} like 'user.%'`)!)
63
66
  return or(...parts)!
64
67
  }
@@ -77,6 +80,31 @@ export function submissionView(e: CmsEntity, row: Record<string, any>) {
77
80
  return { form: e.name, id: row.id as string, createdAt: row.createdAt as Date, status: (row.status as string | null) ?? null, data }
78
81
  }
79
82
 
83
+ /** The audit actions of a change of sign-in address: they name two addresses, `email` (new) and `previousEmail` (old). */
84
+ const ADDRESS_CHANGES = new Set(['account.email_request', 'account.email', 'account.email_cancel', 'account.email_revert', 'user.email'])
85
+
86
+ /**
87
+ * An audit entry as exported to the person with `email`: a change of sign-in address
88
+ * names two addresses, and the other one is not always theirs. It is when the entry is
89
+ * about their own account (they made the change, or it was made to their account) —
90
+ * except the address of another account they asked for (`inUse`). Found only through
91
+ * the address (it is the old address of somebody else's account now, or that other
92
+ * account's own), the other address is left out.
93
+ */
94
+ export function auditExportMeta(entry: { action: string; userId: string | null; recordId: string | null; meta: unknown }, email: string, accountId: string | null): unknown {
95
+ const meta = entry.meta as Record<string, unknown> | null
96
+ if (!meta || typeof meta !== 'object' || Array.isArray(meta) || !ADDRESS_CHANGES.has(entry.action)) return entry.meta
97
+ const own = !!accountId && (entry.action.startsWith('user.') ? entry.recordId === accountId : entry.userId === accountId)
98
+ const out: Record<string, unknown> = { ...meta }
99
+ for (const key of ['email', 'previousEmail'] as const) {
100
+ const value = typeof out[key] === 'string' ? (out[key] as string).trim().toLowerCase() : null
101
+ if (value === null || value === email) continue
102
+ const theirs = own && !(key === 'email' && out.inUse === true)
103
+ if (!theirs) out[key] = '(another person’s address)'
104
+ }
105
+ return out
106
+ }
107
+
80
108
  /** The account without secrets (no password hash, no session counter). */
81
109
  export function accountView(u: any) {
82
110
  return { id: u.id as string, email: u.email as string, name: u.name as string, role: u.role as string, status: u.status as string, language: (u.locale as string | null) ?? null, lastLoginAt: u.lastLoginAt as Date | null, createdAt: u.createdAt as Date }
@@ -125,16 +153,26 @@ export async function erasePerson(db: any, reg: CmsRegistry, email: string, acto
125
153
  sessionVersion: sql`${u.sessionVersion} + 1`, updatedAt: new Date(),
126
154
  }).where(eq(u.id, account.id))
127
155
  await tx.delete(reg.cmsTokens).where(eq(reg.cmsTokens.userId, account.id))
156
+ await tx.delete(reg.cmsState).where(eq(reg.cmsState.key, emailChangeStateKey(account.id)))
157
+ await tx.delete(reg.cmsState).where(sql`${reg.cmsState.key} like ${emailRevertStatePattern(account.id)}`)
128
158
  }
159
+ // A change waiting for this address, or a way back to it, of whichever account: the link goes with it.
160
+ const states = await findEmailStates(tx, reg, email)
161
+ if (states.length) await tx.delete(reg.cmsState).where(inArray(reg.cmsState.key, states.map((r) => r.key)))
129
162
  return { submissions, account: !!account, auditEntries }
130
163
  })
131
164
  }
132
165
 
133
166
  /**
134
167
  * Take the erased person's own details out of the audit log, and nobody else's:
135
- * - entries that name their address (`meta.email`, any case, whitespace trimmed: a failed
136
- * sign-in with it, their invitation, their deletion) and entries about their account
137
- * (`user.*` on their id) lose email, IP address and name;
168
+ * - entries that name their address (`meta.email` or `meta.previousEmail`, any case,
169
+ * whitespace trimmed: a failed sign-in with it, their invitation, their deletion, a
170
+ * change of their address) lose that address — only that one: a change of address
171
+ * names another, which may be somebody else's now (the account that moved away from
172
+ * the address this person has today) — and sign-in attempts their IP address too;
173
+ * - entries about their account (`user.*` on their id) lose addresses, IP address and name;
174
+ * - their own changes of address (`account.email*`) lose both addresses (but not the
175
+ * address of another account they asked for, `inUse`);
138
176
  * - entries they made themselves lose their IP address and their name — but not an
139
177
  * `email` that is someone else's: the `user.invite` entries of an administrator hold
140
178
  * the invitees' addresses, which belong to the invitees.
@@ -148,12 +186,23 @@ async function scrubAudit(tx: any, reg: CmsRegistry, email: string, account: { i
148
186
  const res: any = await tx.execute(sql`update ${a} set meta = nullif(${set}, '{}'::jsonb) where ${isObject} and (${where}) returning ${a.id}`)
149
187
  for (const row of res?.rows ?? []) touched.add(String(row.id))
150
188
  }
151
- const strip = sql`${a.meta} - 'email' - 'ip' - 'name'`
189
+ const strip = sql`${a.meta} - 'email' - 'previousEmail' - 'ip' - 'name'`
190
+ const names = (key: string) => sql`lower(btrim(${a.meta}->>${key})) = ${email}`
152
191
  // Naming the address: a sign-in attempt (its IP address went with the attempt) or an entry by somebody
153
- // else about this person (the actor's own details are not ours to take).
154
- await run(sql`case when ${a.action} like 'auth.%' then ${strip} else ${a.meta} - 'email' end`, sql`lower(btrim(${a.meta}->>'email')) = ${email}`)
192
+ // else about this person (the actor's own details are not ours to take). Only the keys that hold this
193
+ // address go: the other address of a change belongs to whoever has it (their own changes: below).
194
+ const matching = sql`${a.meta} - (case when ${names('email')} then 'email' else '' end) - (case when ${names('previousEmail')} then 'previousEmail' else '' end)`
195
+ await run(
196
+ sql`case when ${a.action} like 'auth.%' then ${strip} else ${matching} end`,
197
+ sql`(${names('email')} or ${names('previousEmail')})`,
198
+ )
155
199
  if (account) {
156
- await run(strip, sql`${a.recordId} = ${account.id} and ${a.action} like 'user.%' and ${a.meta} ?| array['email', 'ip', 'name']`)
200
+ await run(strip, sql`${a.recordId} = ${account.id} and ${a.action} like 'user.%' and ${a.meta} ?| array['email', 'previousEmail', 'ip', 'name']`)
201
+ // Their own changes of address: both addresses are theirs (but not another account's address they asked for).
202
+ await run(
203
+ sql`case when ${a.meta} ? 'inUse' then ${a.meta} - 'previousEmail' else ${a.meta} - 'email' - 'previousEmail' end`,
204
+ sql`${a.userId} = ${account.id} and ${a.action} like 'account.email%' and ${a.meta} ?| array['email', 'previousEmail']`,
205
+ )
157
206
  // Their own entries: their client address, and their name if it is the one on the entry.
158
207
  const name = (account.name ?? '').trim().toLowerCase()
159
208
  await run(
@@ -7,6 +7,8 @@ import { inArray, lt, sql } from 'tinyzoo'
7
7
  * past their form's `retentionDays`; none = kept).
8
8
  * - The audit log: `cms.retention.auditDays` (default 365; 0 = kept) — it holds who
9
9
  * did what and, for failed sign-ins, the email and address tried.
10
+ * - Changes of sign-in address: one nobody confirmed, or a way back nobody took, is
11
+ * deleted once its link has expired (cms_state `email-change:*`, `email-revert:*`).
10
12
  *
11
13
  * A daily task (`cms:retention`) deletes what is past its time, in batches, one
12
14
  * instance at a time (an advisory lock), and writes one audit entry with the counts
@@ -47,6 +49,8 @@ export async function runRetention(): Promise<RetentionResult | null> {
47
49
  if (old.length < BATCH * 2) break
48
50
  }
49
51
  }
52
+ // Changes of sign-in address nobody confirmed, and ways back nobody took, once expired.
53
+ await sweepEmailStates(tx, reg)
50
54
  return true
51
55
  })
52
56
  if (!ran) return null
@@ -15,9 +15,14 @@ export interface CmsUser {
15
15
  * middleware (server/middleware/cms-session.ts) sets it from the session after
16
16
  * checking the account in the database; with `cms.auth.mode: 'external'` the host does.
17
17
  */
18
- /** The name of the session cookie (nuxt-auth-utils: `nuxt-session`, or `runtimeConfig.session.name`). */
18
+ /**
19
+ * The name of the session cookie: nuxt-auth-utils' `nuxt-auth-session`, or
20
+ * `runtimeConfig.session.name` (NUXT_SESSION_NAME). nuxt-auth-utils refuses
21
+ * `nuxt-session` (the cookie of Nuxt's own `useSession()`) and uses its default instead.
22
+ */
19
23
  export function sessionCookieName(): string {
20
- return String((useRuntimeConfig().session as any)?.name || 'nuxt-session')
24
+ const name = String((useRuntimeConfig().session as any)?.name || 'nuxt-auth-session')
25
+ return name === 'nuxt-session' ? 'nuxt-auth-session' : name
21
26
  }
22
27
 
23
28
  /**
@@ -45,33 +50,61 @@ export function requireCmsUser(event: any): CmsUser {
45
50
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
46
51
 
47
52
  /**
48
- * The account a sealed session belongs to, if it may still be used: it exists, is
49
- * active, and the session was issued for its current session version (a password
50
- * change or "sign out everywhere" bumps it). Null otherwise.
53
+ * Was the session signed in less than `runtimeConfig.session.maxAge` ago (NUXT_SESSION_MAX_AGE,
54
+ * seconds; 14 days by default)? From `cms.iat`, the time of the sign-in that a session written
55
+ * again keeps (cmsAuth.ts, startCmsSession). A session without it was not made by this version:
56
+ * not in time. Without a maxAge only that is checked.
57
+ */
58
+ export function signedInRecently(session: any, now = Date.now()): boolean {
59
+ const iat = session?.cms?.iat
60
+ if (typeof iat !== 'number' || !Number.isFinite(iat) || iat > now + 60_000) return false
61
+ const maxAge = Number((useRuntimeConfig().session as any)?.maxAge)
62
+ return !(maxAge > 0) || now - iat < maxAge * 1000
63
+ }
64
+
65
+ /**
66
+ * The account a sealed session belongs to, if it may still be used: signed in less than
67
+ * `maxAge` ago (signedInRecently), and the account exists, is active, and the session was
68
+ * issued for its current session version (a password change or "sign out everywhere"
69
+ * bumps it). Null otherwise.
51
70
  */
52
71
  export async function activeAccountOf(session: any): Promise<any | null> {
53
- const id = session?.cms?.uid
72
+ return activeAccount(session?.cms?.uid, session?.cms?.sv, session?.cms?.iat)
73
+ }
74
+
75
+ /**
76
+ * The account, if the session it was admitted with was signed in at `iat` less than
77
+ * `maxAge` ago, and the account is active and still at session version `sv`: for a socket
78
+ * admitted earlier with a session (activeAccountOf), checked again while it stays open, so
79
+ * an open socket ends with its session too instead of outliving the 14 days.
80
+ */
81
+ export async function activeAccount(id: unknown, sv: unknown, iat: unknown): Promise<any | null> {
82
+ if (!signedInRecently({ cms: { iat } })) return null
54
83
  if (typeof id !== 'string' || !UUID.test(id)) return null
55
84
  const { db, reg } = useCms()
56
85
  const [u] = await db.select().from(reg.cmsUsers).where(eq(reg.cmsUsers.id, id))
57
- if (!u || u.status !== 'active' || u.sessionVersion !== session?.cms?.sv) return null
86
+ if (!u || u.status !== 'active' || u.sessionVersion !== sv) return null
58
87
  return u
59
88
  }
60
89
 
61
90
  /**
62
91
  * Admit a WebSocket upgrade for the admin (realtime, shared editing): it must come
63
92
  * from this site's own pages and carry a valid built-in session for an active
64
- * account. Puts the account on `request.context` (cmsUser, cmsSessionVersion), which
65
- * the socket's peer then carries. Throws a Response to refuse.
93
+ * account. Puts the account on `request.context` (cmsUser, cmsSessionVersion and
94
+ * cmsSignedInAt, the session's sign-in time), which the socket's peer then carries.
95
+ * Throws a Response to refuse.
66
96
  */
67
97
  export async function admitAdminSocket(request: any): Promise<void> {
68
98
  if (cmsAuthMode() !== 'builtin') throw new Response('Needs the built-in sign-in', { status: 404 })
69
99
  if (!sameOrigin(request)) throw new Response('Forbidden', { status: 403 })
100
+ // Only read: in a WebSocket handler nuxt-auth-utils cannot write the session (there is no
101
+ // response to carry the cookie), so a stale cookie is refused here, not cleared.
70
102
  const session: any = hasSessionCookie(request) ? await getUserSession(request).catch(() => null) : null
71
103
  const u = await activeAccountOf(session)
72
104
  if (!u) throw new Response('Unauthorized', { status: 401 })
73
105
  request.context.cmsUser = { id: u.id, email: u.email, name: u.name || u.email, role: u.role, locale: u.locale }
74
106
  request.context.cmsSessionVersion = u.sessionVersion
107
+ request.context.cmsSignedInAt = session.cms.iat
75
108
  }
76
109
 
77
110
  /**
@@ -0,0 +1,88 @@
1
+ /**
2
+ * NUXT_SESSION_PASSWORD standing in for NUXT_APP_SECRET (deprecated, removed in 0.5).
3
+ *
4
+ * nuxt-auth-utils 0.6 seals the sign-in cookie with a key Nuxt derives from its app secret
5
+ * (`NUXT_APP_SECRET`) and no longer reads `NUXT_SESSION_PASSWORD`. So that a site deployed
6
+ * with only the old variable keeps starting (and signing people in) after the update, the
7
+ * server takes the session password as the app secret when no app secret is set at all.
8
+ * A set app secret always wins, whatever else uses it (signed image URLs…).
9
+ *
10
+ * Nitro reads the environment into its runtime config once, when its config module is
11
+ * evaluated, and freezes it; a Nitro plugin runs too late to change it. So the copy is put
12
+ * at the top of that module in the server bundle (module.ts), before the environment is
13
+ * read. The start-up check (server/plugins/cms-0-config-check.ts) then warns that the old
14
+ * name is deprecated, or refuses to start when there is no secret at all.
15
+ *
16
+ * Build-time only; kept apart from module.ts so it can be tested on its own.
17
+ */
18
+
19
+ /** Where the start-up check finds the name of what stood in for the app secret (the same string there). */
20
+ export const APP_SECRET_FROM = 'tinyzoo.appSecretFrom'
21
+
22
+ /** The runtime config path a 0.3 site may have set the password at in nuxt.config (the same string in the start-up check). */
23
+ export const CONFIG_SESSION_PASSWORD = 'runtimeConfig.session.password'
24
+
25
+ /** Nitro's runtime config module, the one the fallback is put at the top of. */
26
+ export const NITRO_CONFIG_MODULE = /[\\/]nitropack[\\/]dist[\\/]runtime[\\/]internal[\\/]config\.mjs$/
27
+
28
+ export interface AppSecretPlan {
29
+ /** Put the fallback into the server bundle. */
30
+ install: boolean
31
+ /** `runtimeConfig.session.password` (nuxt.config) was taken as the build's app secret. */
32
+ fromConfig: boolean
33
+ envPrefix: string
34
+ }
35
+
36
+ /**
37
+ * What to do for a build, from Nitro's runtime config. Mutates `runtimeConfig`: when a site
38
+ * set `runtimeConfig.session.password` in its nuxt.config (tinyzoo 0.3 accepted it) and no
39
+ * app secret, that value becomes the build's `appSecret`. It is in the built runtime config
40
+ * already (as `session.password`), so nothing new is written into the bundle, and a
41
+ * NUXT_APP_SECRET set at runtime still wins over it.
42
+ */
43
+ export function planAppSecretFallback(runtimeConfig: Record<string, any>): AppSecretPlan {
44
+ const envPrefix = String(runtimeConfig.nitro?.envPrefix || 'NUXT_')
45
+ // Set in nuxt.config, or generated for `nuxt dev`: nothing to stand in for.
46
+ if (runtimeConfig.appSecret) return { install: false, fromConfig: false, envPrefix }
47
+ const password = runtimeConfig.session?.password
48
+ const fromConfig = typeof password === 'string' && password.length > 0
49
+ if (fromConfig) runtimeConfig.appSecret = password
50
+ return { install: true, fromConfig, envPrefix }
51
+ }
52
+
53
+ /**
54
+ * The lines put at the top of Nitro's config module. When neither `<prefix>APP_SECRET` nor
55
+ * `NITRO_APP_SECRET` is set, `<prefix>SESSION_PASSWORD` (or `NITRO_SESSION_PASSWORD`) is
56
+ * copied to the app secret variable Nitro reads first, and the name of what stood in is
57
+ * left for the start-up check. Carries no secret.
58
+ */
59
+ export function appSecretFallbackCode(envPrefix: string, fromConfig: boolean): string {
60
+ const prefix = JSON.stringify(envPrefix)
61
+ return `;(() => {
62
+ const env = globalThis.process?.env
63
+ if (!env || env[${prefix} + 'APP_SECRET'] || env.NITRO_APP_SECRET) return
64
+ const from = [${prefix} + 'SESSION_PASSWORD', 'NITRO_SESSION_PASSWORD'].find((name) => env[name])
65
+ const mark = (name) => { globalThis[Symbol.for(${JSON.stringify(APP_SECRET_FROM)})] = name }
66
+ if (!from) {
67
+ ${fromConfig ? `mark(${JSON.stringify(CONFIG_SESSION_PASSWORD)})` : ''}
68
+ return
69
+ }
70
+ // Nitro reads NITRO_APP_SECRET first, even when it is empty.
71
+ env[env.NITRO_APP_SECRET !== undefined ? 'NITRO_APP_SECRET' : ${prefix} + 'APP_SECRET'] = env[from]
72
+ mark(from)
73
+ })();
74
+ `
75
+ }
76
+
77
+ /**
78
+ * The source map of `code + source` when `code` is whole lines put in front: the added lines
79
+ * map to nothing, every line of `source` to itself (line by line, which is all a stack trace
80
+ * needs). Saves a dependency for one prepend.
81
+ */
82
+ export function prependedLinesMap(code: string, source: string, file: string) {
83
+ const added = code.split('\n').length - 1
84
+ const lines = source.split('\n').length
85
+ // Per line: generated column 0, source 0, the next source line (+1, "C"; the first is +0, "A"), column 0.
86
+ const mappings = ';'.repeat(added) + Array.from({ length: lines }, (_, i) => (i ? 'AACA' : 'AAAA')).join(';')
87
+ return { version: 3, file, sources: [file], sourcesContent: [source], names: [], mappings }
88
+ }
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  export { defineEntity, defineSingleton, buildRegistry, propOf, editorLayout, listLayout } from './entity'
3
3
  export type { CmsEntity, CmsRegistry, ContentConfig, PublishConfig, EntityDef, Entity, Junction, Row, Insert, Update, CmsEditorLayout, CmsListLayout, CmsFormSection } from './entity'
4
4
  export { f, snake, camel, pascal, buildColumn, serializeColumn, type CmsGalleryValue, type CmsListValue } from './fields'
5
- export { seo, linkBlock, definePages, defineNavigation, defineRedirects, defineForm, defineFormSettings, FORM_FIELD_TYPES, type FormOptions } from './presets'
5
+ export { seo, linkBlock, definePages, defineNavigation, defineRedirects, FORM_FIELD_TYPES, type FormOptions } from './presets'
6
6
  export { defineBlock, blocksSchema, mediaIdsInBlocks, mediaIdsInFields, blockMediaKeys, BLOCK_FIELD_TYPES, blockVersion, storedBlockVersion, upgradeBlock, upgradeBlocks, upgradeListItems, upgradeStoredRow, logUpgradeFailure, UPGRADE_FAILED_KEY, UNKNOWN_BLOCK_TYPE, type UpgradeIssue, type UpgradeOptions, type BlockDef, type BlockValue, type BlocksValue, type GroupValue, type CmsBlock } from './blocks'
7
7
  export { resolveText, type LocalizedText } from './i18n'
8
8
  export { defineLocales, type LocalesDef } from './locales'
package/src/presets.ts CHANGED
@@ -5,7 +5,6 @@ import { f } from './fields'
5
5
  import type { LocalizedText } from './i18n'
6
6
  import type { PathTemplate } from './paths'
7
7
  import { cmsDeprecated } from './deprecate'
8
- import { defineForm as formsDefineForm, defineFormSettings as formsDefineFormSettings, IMPLICIT_FORMS_REQUIREMENT } from '../forms'
9
8
  import { TREE_DEFAULT_MAX_DEPTH } from './tree'
10
9
 
11
10
  const SEO_GROUP = { en: 'Search & sharing', cs: 'Vyhledávače a sdílení', de: 'Suche & Teilen' }
@@ -195,36 +194,5 @@ export function defineRedirects(opts: { name?: string } = {}) {
195
194
  return e
196
195
  }
197
196
 
198
- // ── forms: moved to the forms plugin (`tinyzoo/forms`); these keep old sites working ──
197
+ // ── forms: in the forms plugin (`tinyzoo/forms`); the field types and options stay importable from here ──
199
198
  export { FORM_FIELD_TYPES, type FormOptions } from '../forms'
200
-
201
- /**
202
- * @deprecated Import `defineForm` from `tinyzoo/forms` and register `formsPlugin()` in
203
- * `export const plugins = [...]`. Still works (it registers the plugin by itself), same
204
- * tables and endpoints. Removed in 0.4.
205
- */
206
- export function defineForm<F extends Record<string, any>>(name: string, opts: import('../forms').FormOptions<F>) {
207
- cmsDeprecated(
208
- 'defineForm',
209
- '`defineForm()` from "tinyzoo" is replaced by `defineForm()` from "tinyzoo/forms" with `export const plugins = [formsPlugin()]` in cms.config.ts.',
210
- { removeIn: '0.4.0' },
211
- )
212
- const e = formsDefineForm(name, opts)
213
- ;(e as any).requiresPlugin = IMPLICIT_FORMS_REQUIREMENT
214
- return e
215
- }
216
-
217
- /**
218
- * @deprecated Import `defineFormSettings` from `tinyzoo/forms` and register `formsPlugin()`.
219
- * Still works (it registers the plugin by itself). Removed in 0.4.
220
- */
221
- export function defineFormSettings(opts: Parameters<typeof formsDefineFormSettings>[0] = {}) {
222
- cmsDeprecated(
223
- 'defineFormSettings',
224
- '`defineFormSettings()` from "tinyzoo" is replaced by `defineFormSettings()` from "tinyzoo/forms" with `export const plugins = [formsPlugin()]` in cms.config.ts.',
225
- { removeIn: '0.4.0' },
226
- )
227
- const e = formsDefineFormSettings(opts)
228
- ;(e as any).requiresPlugin = IMPLICIT_FORMS_REQUIREMENT
229
- return e
230
- }
package/src/system.ts CHANGED
@@ -38,7 +38,7 @@ export const cmsUsers = pgTable('cms_users', {
38
38
  export const cmsTokens = pgTable('cms_tokens', {
39
39
  id: uuid('id').primaryKey().defaultRandom(),
40
40
  userId: uuid('user_id').notNull().references(() => cmsUsers.id, { onDelete: 'cascade' }),
41
- // invite | reset
41
+ // invite | reset | email (a change of address; the address waits in cms_state)
42
42
  kind: text('kind').notNull(),
43
43
  // SHA-256 of the secret sent in the link; the secret itself is never stored.
44
44
  tokenHash: text('token_hash').notNull(),
@@ -1,7 +1,8 @@
1
1
  # Copy to .env for development.
2
2
  DATABASE_URL=postgres://site:site@localhost:5433/site
3
- # At least 32 characters; signs the admin's sessions.
4
- NUXT_SESSION_PASSWORD=change-me-to-a-long-random-string-32-chars-min
3
+ # At least 32 characters (openssl rand -base64 32); the admin's sign-in cookie is sealed with a key derived from it.
4
+ # Production needs one; in development Nuxt makes one when it is not set.
5
+ NUXT_APP_SECRET=change-me-to-a-long-random-string-32-chars-min
5
6
  # The website's address (emails, sitemap). In development it comes from the request.
6
7
  # NUXT_CMS_PUBLIC_URL=https://www.example.cz
7
8
  # Who hears about new form messages when nobody is set in the admin.
@@ -17,9 +17,9 @@
17
17
  "@internationalized/date": "^3.12.2",
18
18
  "@nuxt/ui": "^4.0.0",
19
19
  "@tinyzoo/client": "workspace:*",
20
- "drizzle-orm": "^0.44.0",
21
- "nuxt": "^4.0.0",
22
- "nuxt-auth-utils": "^0.5.29",
20
+ "drizzle-orm": "^0.45.4",
21
+ "nuxt": "^4.6.4",
22
+ "nuxt-auth-utils": "^0.6.2",
23
23
  "pg": "^8.16.3",
24
24
  "tailwindcss": "^4.3.1",
25
25
  "tinyzoo": "workspace:*",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "devDependencies": {
29
29
  "@iconify-json/lucide": "^1.2.114",
30
- "drizzle-kit": "^0.31.0",
30
+ "drizzle-kit": "^0.31.11",
31
31
  "tsx": "^4.19.0",
32
32
  "typescript": "^5.7.0",
33
33
  "vue-tsc": "^3.3.14"