@beechcms/api 0.4.0-preview.11 → 0.4.0-preview.13

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 (86) hide show
  1. package/assets/dashboard/BeechLogo.svg +18 -18
  2. package/assets/dashboard/BeechLogoLIght.svg +48 -48
  3. package/assets/dashboard/assets/index-CewtCjom.css +1 -0
  4. package/assets/dashboard/assets/index-FQ6JhvRH.js +554 -0
  5. package/assets/dashboard/beechLogoDark.svg +48 -48
  6. package/assets/dashboard/index.html +18 -18
  7. package/assets/dashboard/sol.svg +3 -3
  8. package/assets/dashboard/undraw_enter_nwx3.svg +36 -36
  9. package/migrations/0000_v040_base.sql +213 -213
  10. package/package.json +2 -2
  11. package/src/auth/constants.ts +10 -10
  12. package/src/auth/login.ts +91 -91
  13. package/src/auth/refresh.ts +127 -127
  14. package/src/factory.ts +347 -325
  15. package/src/features/content/constants.ts +10 -10
  16. package/src/features/content/handlers/create.ts +153 -163
  17. package/src/features/content/handlers/delete.ts +76 -85
  18. package/src/features/content/handlers/facets.ts +45 -45
  19. package/src/features/content/handlers/get.ts +116 -116
  20. package/src/features/content/handlers/list.ts +88 -88
  21. package/src/features/content/handlers/update.ts +207 -216
  22. package/src/features/content/index.ts +20 -20
  23. package/src/features/draft/draft.handler.ts +272 -272
  24. package/src/features/draft/index.ts +1 -1
  25. package/src/features/email/email.provider.ts +38 -38
  26. package/src/features/email/email.service.ts +80 -80
  27. package/src/features/email/email.types.ts +98 -98
  28. package/src/features/email/index.ts +28 -28
  29. package/src/features/email/providers/resend.ts +63 -63
  30. package/src/features/email/templates/password-changed.ts +59 -59
  31. package/src/features/email/templates/password-reset.ts +64 -64
  32. package/src/features/email/templates/shell.ts +92 -93
  33. package/src/features/notifications/index.ts +1 -1
  34. package/src/features/notifications/notifications.handler.ts +130 -88
  35. package/src/features/password-reset/index.ts +15 -15
  36. package/src/features/password-reset/request.ts +106 -88
  37. package/src/features/password-reset/reset.ts +128 -110
  38. package/src/features/rotate-field/index.ts +1 -1
  39. package/src/features/rotate-field/rotate-field.handler.ts +132 -82
  40. package/src/features/rotate-field/rotate-field.schema.ts +13 -9
  41. package/src/features/schema/schema.handler.ts +16 -16
  42. package/src/features/settings/settings.handler.ts +414 -267
  43. package/src/features/setup/index.ts +96 -59
  44. package/src/features/stats/index.ts +1 -1
  45. package/src/features/stats/stats.handler.ts +458 -395
  46. package/src/index.ts +24 -24
  47. package/src/media-utils.ts +78 -78
  48. package/src/middleware/repository.middleware.ts +24 -18
  49. package/src/middleware/storage.middleware.ts +21 -0
  50. package/src/middleware.ts +67 -67
  51. package/src/public/access-policy.ts +23 -23
  52. package/src/public/api-key-middleware.ts +53 -53
  53. package/src/public/index.ts +12 -12
  54. package/src/public/problem-details.ts +48 -42
  55. package/src/public/public-add.ts +166 -166
  56. package/src/public/public-edit.ts +158 -158
  57. package/src/public/public-errors.ts +15 -15
  58. package/src/public/public-read.ts +216 -216
  59. package/src/public/public-routes.ts +84 -31
  60. package/src/public/query-builder.ts +152 -152
  61. package/src/public/rate-limit-middleware.ts +42 -42
  62. package/src/public/response-builder.ts +26 -26
  63. package/src/public/sanitize.ts +65 -65
  64. package/src/public/slug-utils.ts +14 -14
  65. package/src/search-utils.ts +192 -192
  66. package/src/search.ts +72 -72
  67. package/src/shared/activity-logger.ts +79 -79
  68. package/src/shared/apply-policies.ts +63 -63
  69. package/src/shared/base.repository.d1.ts +28 -28
  70. package/src/shared/content-utils.ts +82 -108
  71. package/src/shared/content.repository.d1.ts +382 -382
  72. package/src/shared/fts-sync.ts +4 -4
  73. package/src/shared/idempotency.repository.d1.ts +56 -45
  74. package/src/shared/media.repository.d1.ts +64 -0
  75. package/src/shared/notification-service.ts +56 -56
  76. package/src/shared/query-utils.ts +137 -137
  77. package/src/shared/storage/factory.ts +40 -0
  78. package/src/shared/storage/r2-binding-bucket.ts +81 -0
  79. package/src/shared/storage/s3-bucket.ts +163 -0
  80. package/src/shared/storage-utils.ts +36 -36
  81. package/src/shared/system-stats.repository.d1.ts +44 -0
  82. package/src/types.ts +46 -41
  83. package/src/upload.ts +179 -331
  84. package/src/widget.ts +349 -349
  85. package/assets/dashboard/assets/index-9Ch2xWJr.js +0 -554
  86. package/assets/dashboard/assets/index-ye3325L9.css +0 -1
@@ -1,110 +1,128 @@
1
- /// <reference types="@cloudflare/workers-types" />
2
- import type { Context } from 'hono'
3
- import bcrypt from 'bcryptjs'
4
- import type { Env, Variables } from '../../types'
5
- import { sendPasswordChangedEmail, resolveEmailLocale } from '../email'
6
-
7
- const MIN_PASSWORD_LENGTH = 8
8
- const MAX_PASSWORD_LENGTH = 128
9
-
10
- async function sha256hex(text: string): Promise<string> {
11
- const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(text))
12
- return Array.from(new Uint8Array(buf))
13
- .map(b => b.toString(16).padStart(2, '0'))
14
- .join('')
15
- }
16
-
17
- export async function resetPassword(
18
- c: Context<{ Bindings: Env; Variables: Variables }>
19
- ): Promise<Response> {
20
- if (!c.env.RESEND_API_KEY) {
21
- return c.json({ error: 'Not available' }, 503)
22
- }
23
-
24
- // Rate limiting: 5 tentativi per IP per 60 secondi
25
- if (c.env.RESET_PASSWORD_RATE_LIMITER) {
26
- const ip = c.req.raw.headers.get('cf-connecting-ip') ?? 'unknown'
27
- const { success } = await c.env.RESET_PASSWORD_RATE_LIMITER.limit({ key: ip })
28
- if (!success) {
29
- return c.json({ error: 'Too many requests' }, 429)
30
- }
31
- }
32
-
33
- let body: Record<string, unknown>
34
- try {
35
- body = await c.req.json()
36
- } catch {
37
- return c.json({ error: 'Invalid request body' }, 400)
38
- }
39
-
40
- if (typeof body.token !== 'string' || !body.token) {
41
- return c.json({ error: 'Invalid or expired token' }, 400)
42
- }
43
-
44
- if (
45
- typeof body.password !== 'string' ||
46
- body.password.length < MIN_PASSWORD_LENGTH ||
47
- body.password.length > MAX_PASSWORD_LENGTH
48
- ) {
49
- return c.json({
50
- error: `Password must be between ${MIN_PASSWORD_LENGTH} and ${MAX_PASSWORD_LENGTH} characters`,
51
- }, 400)
52
- }
53
-
54
- const locale = resolveEmailLocale(body.locale)
55
- const tokenHash = await sha256hex(body.token)
56
- const now = Math.floor(Date.now() / 1000)
57
-
58
- // JOIN users per recuperare l'email in un'unica query — serve per la notifica
59
- const record = await c.env.DB
60
- .prepare(
61
- `SELECT prt.id, prt.user_id, u.email
62
- FROM password_reset_tokens prt
63
- JOIN users u ON u.id = prt.user_id
64
- WHERE prt.token_hash = ? AND prt.expires_at > ? AND prt.used_at IS NULL`,
65
- )
66
- .bind(tokenHash, now)
67
- .first<{ id: string; user_id: string; email: string }>()
68
-
69
- if (!record) {
70
- return c.json({ error: 'Invalid or expired token' }, 400)
71
- }
72
-
73
- const newHash = await bcrypt.hash(body.password, 10)
74
-
75
- // Segna token usato, aggiorna password, revoca tutte le sessioni — atomicamente
76
- await c.env.DB.batch([
77
- c.env.DB
78
- .prepare('UPDATE password_reset_tokens SET used_at = unixepoch() WHERE id = ?')
79
- .bind(record.id),
80
- c.env.DB
81
- .prepare('UPDATE users SET password_hash = ? WHERE id = ?')
82
- .bind(newHash, record.user_id),
83
- c.env.DB
84
- .prepare('UPDATE refresh_tokens SET revoked_at = unixepoch() WHERE user_id = ? AND revoked_at IS NULL')
85
- .bind(record.user_id),
86
- ])
87
-
88
- // Notifica "password modificata" — fire-and-forget via waitUntil, non blocca il 200
89
- const notify = () =>
90
- sendPasswordChangedEmail({
91
- to: record.email,
92
- locale,
93
- apiKey: c.env.RESEND_API_KEY!,
94
- from: c.env.EMAIL_FROM,
95
- isDev: c.env.ENV !== 'production',
96
- }).catch((err) => {
97
- if (c.env.ENV !== 'production') {
98
- console.error('[password-reset] notifica email fallita:', err)
99
- }
100
- })
101
-
102
- try {
103
- c.executionCtx.waitUntil(notify())
104
- } catch {
105
- // executionCtx non disponibile in ambiente di test
106
- void notify()
107
- }
108
-
109
- return c.json({ success: true })
110
- }
1
+ /// <reference types="@cloudflare/workers-types" />
2
+ import type { Context } from 'hono'
3
+ import bcrypt from 'bcryptjs'
4
+ import type { Env, Variables } from '../../types'
5
+ import { sendPasswordChangedEmail, resolveEmailLocale } from '../email'
6
+
7
+ const MIN_PASSWORD_LENGTH = 8
8
+ const MAX_PASSWORD_LENGTH = 128
9
+
10
+ /**
11
+ * Computes the SHA-256 hash of a string and returns it as a hex string.
12
+ */
13
+ async function computeSha256Hash(text: string): Promise<string> {
14
+ const encoder = new TextEncoder()
15
+ const data = encoder.encode(text)
16
+ const hashBuffer = await crypto.subtle.digest('SHA-256', data)
17
+
18
+ return Array.from(new Uint8Array(hashBuffer))
19
+ .map(byte => byte.toString(16).padStart(2, '0'))
20
+ .join('')
21
+ }
22
+
23
+ /**
24
+ * Handles the actual password reset process using a valid token.
25
+ */
26
+ export async function resetPassword(
27
+ context: Context<{ Bindings: Env; Variables: Variables }>
28
+ ): Promise<Response> {
29
+ const { env, req, executionCtx } = context
30
+
31
+ if (!env.RESEND_API_KEY) {
32
+ return context.json({ error: 'Service not available' }, 503)
33
+ }
34
+
35
+ // Rate limiting: e.g., 5 attempts per IP per 60 seconds
36
+ if (env.RESET_PASSWORD_RATE_LIMITER) {
37
+ const clientIpAddress = req.raw.headers.get('cf-connecting-ip') ?? 'unknown'
38
+ const { success: isRateLimitAllowed } = await env.RESET_PASSWORD_RATE_LIMITER.limit({ key: clientIpAddress })
39
+
40
+ if (!isRateLimitAllowed) {
41
+ return context.json({ error: 'Too many requests' }, 429)
42
+ }
43
+ }
44
+
45
+ let payload: Record<string, unknown>
46
+ try {
47
+ payload = await req.json()
48
+ } catch {
49
+ return context.json({ error: 'Invalid request body' }, 400)
50
+ }
51
+
52
+ const resetToken = payload.token
53
+ if (typeof resetToken !== 'string' || !resetToken) {
54
+ return context.json({ error: 'Invalid or expired token' }, 400)
55
+ }
56
+
57
+ const newPassword = payload.password
58
+ if (
59
+ typeof newPassword !== 'string' ||
60
+ newPassword.length < MIN_PASSWORD_LENGTH ||
61
+ newPassword.length > MAX_PASSWORD_LENGTH
62
+ ) {
63
+ return context.json({
64
+ error: `Password must be between ${MIN_PASSWORD_LENGTH} and ${MAX_PASSWORD_LENGTH} characters`,
65
+ }, 400)
66
+ }
67
+
68
+ const emailLocale = resolveEmailLocale(payload.locale)
69
+ const hashedResetToken = await computeSha256Hash(resetToken)
70
+ const currentTimestamp = Math.floor(Date.now() / 1000)
71
+
72
+ // JOIN with users table to retrieve the email in a single query - needed for notification.
73
+ const resetTokenRecord = await env.DB
74
+ .prepare(
75
+ `SELECT prt.id, prt.user_id, u.email
76
+ FROM password_reset_tokens prt
77
+ JOIN users u ON u.id = prt.user_id
78
+ WHERE prt.token_hash = ? AND prt.expires_at > ? AND prt.used_at IS NULL`,
79
+ )
80
+ .bind(hashedResetToken, currentTimestamp)
81
+ .first<{ id: string; user_id: string; email: string }>()
82
+
83
+ if (!resetTokenRecord) {
84
+ return context.json({ error: 'Invalid or expired token' }, 400)
85
+ }
86
+
87
+ const hashedNewPassword = await bcrypt.hash(newPassword, 10)
88
+
89
+ // Mark token as used, update user password, and revoke all active sessions - atomically.
90
+ await env.DB.batch([
91
+ env.DB
92
+ .prepare('UPDATE password_reset_tokens SET used_at = unixepoch() WHERE id = ?')
93
+ .bind(resetTokenRecord.id),
94
+ env.DB
95
+ .prepare('UPDATE users SET password_hash = ? WHERE id = ?')
96
+ .bind(hashedNewPassword, resetTokenRecord.user_id),
97
+ env.DB
98
+ .prepare('UPDATE refresh_tokens SET revoked_at = unixepoch() WHERE user_id = ? AND revoked_at IS NULL')
99
+ .bind(resetTokenRecord.user_id),
100
+ ])
101
+
102
+ // Notify user that password was changed - fire-and-forget via waitUntil, doesn't block response.
103
+ const sendNotification = async () => {
104
+ try {
105
+ await sendPasswordChangedEmail({
106
+ to: resetTokenRecord.email,
107
+ locale: emailLocale,
108
+ apiKey: env.RESEND_API_KEY!,
109
+ from: env.EMAIL_FROM,
110
+ isDev: env.ENV !== 'production',
111
+ })
112
+ } catch (error) {
113
+ if (env.ENV !== 'production') {
114
+ console.error('[password-reset] Failed to send password change notification:', error)
115
+ }
116
+ }
117
+ }
118
+
119
+ try {
120
+ executionCtx.waitUntil(sendNotification())
121
+ } catch {
122
+ // executionCtx might not be available in some testing environments
123
+ void sendNotification()
124
+ }
125
+
126
+ return context.json({ success: true })
127
+ }
128
+
@@ -1 +1 @@
1
- export { rotateFieldApp } from './rotate-field.handler'
1
+ export { rotateFieldApp } from './rotate-field.handler'
@@ -1,82 +1,132 @@
1
- /// <reference types="@cloudflare/workers-types" />
2
- import { Hono } from 'hono'
3
- import { resolvePolicies, verifyHashField, sha256hex, validateAndSanitizeSeedPayload, serializeForDb } from '@beechcms/core'
4
- import { publicProblem } from '../../public/problem-details'
5
- import { rotateFieldBodySchema } from './rotate-field.schema'
6
- import type { Env, Variables } from '../../types'
7
-
8
- const rotateFieldApp = new Hono<{ Bindings: Env; Variables: Variables }>()
9
-
10
- rotateFieldApp.post('/:slug/:id/rotate-field', async (c) => {
11
- const slug = c.req.param('slug')
12
- const id = c.req.param('id')
13
-
14
- const seed = c.get('getSeed')(slug)
15
- if (!seed) {
16
- return publicProblem(c, { type: 'content-seed-not-found', title: 'Not Found', status: 404, detail: `Seed '${slug}' not found` })
17
- }
18
-
19
- let rawBody: unknown
20
- try {
21
- rawBody = await c.req.json()
22
- } catch {
23
- return publicProblem(c, { type: 'rotate-field-invalid-json', title: 'Bad Request', status: 400, detail: 'Invalid JSON body' })
24
- }
25
-
26
- const parsed = rotateFieldBodySchema.safeParse(rawBody)
27
- if (!parsed.success) {
28
- return publicProblem(c, { type: 'rotate-field-invalid-body', title: 'Bad Request', status: 400, detail: parsed.error.issues[0]?.message ?? 'Invalid body' })
29
- }
30
-
31
- const { field, current, next } = parsed.data
32
-
33
- const branch = seed.branches.find((b) => b.alias === field)
34
- if (!branch) {
35
- return publicProblem(c, { type: 'rotate-field-unknown-field', title: 'Bad Request', status: 400, detail: `Field '${field}' does not exist in seed '${slug}'` })
36
- }
37
-
38
- const { privacy } = resolvePolicies(branch)
39
- if (privacy !== 'hash') {
40
- return publicProblem(c, { type: 'rotate-field-not-hashable', title: 'Unprocessable Entity', status: 422, detail: `Field '${field}' does not use hash privacy and cannot be rotated with this endpoint` })
41
- }
42
-
43
- const { DB } = c.env
44
- // In v0.4.0 il valore hash è in una colonna reale: row[branch.alias]
45
- const row = await DB.prepare(`SELECT ${branch.alias} FROM content_${slug} WHERE id = ? LIMIT 1`)
46
- .bind(id)
47
- .first<Record<string, unknown>>()
48
-
49
- if (!row) {
50
- return publicProblem(c, { type: 'content-not-found', title: 'Not Found', status: 404, detail: `Entry '${id}' not found` })
51
- }
52
-
53
- const storedHash = row[branch.alias]
54
-
55
- if (typeof storedHash !== 'string' || storedHash.length === 0) {
56
- return publicProblem(c, { type: 'rotate-field-not-set', title: 'Unprocessable Entity', status: 422, detail: `Field '${field}' has no stored value to rotate` })
57
- }
58
-
59
- const matches = await verifyHashField(storedHash, current)
60
- if (!matches) {
61
- return publicProblem(c, { type: 'rotate-field-current-mismatch', title: 'Forbidden', status: 403, detail: 'Current value does not match stored value' })
62
- }
63
-
64
- const validation = validateAndSanitizeSeedPayload(
65
- seed, { [field]: next },
66
- { operation: 'update', allowNull: false, requireAtLeastOneValidField: true, enforceRequiredFields: false }
67
- )
68
- if (validation.details.length > 0) {
69
- return publicProblem(c, { type: 'rotate-field-invalid-next', title: 'Bad Request', status: 400, detail: `Invalid value for field '${field}': ${validation.details[0]?.message ?? 'validation failed'}` })
70
- }
71
-
72
- const nextHash = await sha256hex(next)
73
- const now = Math.floor(Date.now() / 1000)
74
-
75
- await DB.prepare(`UPDATE content_${slug} SET ${branch.alias} = ?, updated_at = ? WHERE id = ?`)
76
- .bind(serializeForDb(branch, nextHash), now, id)
77
- .run()
78
-
79
- return c.json({ success: true })
80
- })
81
-
82
- export { rotateFieldApp }
1
+ /// <reference types="@cloudflare/workers-types" />
2
+ import { Hono } from 'hono'
3
+ import { resolvePolicies, verifyHashField, sha256hex, validateAndSanitizeSeedPayload, serializeForDb } from '@beechcms/core'
4
+ import { publicProblem } from '../../public/problem-details'
5
+ import { rotateFieldRequestSchema } from './rotate-field.schema'
6
+ import type { Env, Variables } from '../../types'
7
+
8
+ const rotateFieldApp = new Hono<{ Bindings: Env; Variables: Variables }>()
9
+
10
+ rotateFieldApp.post('/:slug/:id/rotate-field', async (context) => {
11
+ const seedSlug = context.req.param('slug')
12
+ const entryId = context.req.param('id')
13
+
14
+ const seed = context.get('getSeed')(seedSlug)
15
+ if (!seed) {
16
+ return publicProblem(context, {
17
+ type: 'content-seed-not-found',
18
+ title: 'Not Found',
19
+ status: 404,
20
+ detail: `Seed '${seedSlug}' not found`
21
+ })
22
+ }
23
+
24
+ let requestBody: unknown
25
+ try {
26
+ requestBody = await context.req.json()
27
+ } catch {
28
+ return publicProblem(context, {
29
+ type: 'rotate-field-invalid-json',
30
+ title: 'Bad Request',
31
+ status: 400,
32
+ detail: 'Invalid JSON body'
33
+ })
34
+ }
35
+
36
+ const parsedRequestBody = rotateFieldRequestSchema.safeParse(requestBody)
37
+ if (!parsedRequestBody.success) {
38
+ return publicProblem(context, {
39
+ type: 'rotate-field-invalid-body',
40
+ title: 'Bad Request',
41
+ status: 400,
42
+ detail: parsedRequestBody.error.issues[0]?.message ?? 'Invalid body'
43
+ })
44
+ }
45
+
46
+ const { fieldAlias, currentValue, nextValue } = parsedRequestBody.data
47
+
48
+ const targetFieldBranch = seed.branches.find((branch) => branch.alias === fieldAlias)
49
+ if (!targetFieldBranch) {
50
+ return publicProblem(context, {
51
+ type: 'rotate-field-unknown-field',
52
+ title: 'Bad Request',
53
+ status: 400,
54
+ detail: `Field '${fieldAlias}' does not exist in seed '${seedSlug}'`
55
+ })
56
+ }
57
+
58
+ const { privacy } = resolvePolicies(targetFieldBranch)
59
+ if (privacy !== 'hash') {
60
+ return publicProblem(context, {
61
+ type: 'rotate-field-not-hashable',
62
+ title: 'Unprocessable Entity',
63
+ status: 422,
64
+ detail: `Field '${fieldAlias}' does not use hash privacy and cannot be rotated with this endpoint`
65
+ })
66
+ }
67
+
68
+ const database = context.env.DB
69
+
70
+ // In v0.4.0, the hash value is stored in a dedicated column: contentRecord[targetFieldBranch.alias]
71
+ const contentRecord = await database.prepare(`SELECT ${targetFieldBranch.alias} FROM content_${seedSlug} WHERE id = ? LIMIT 1`)
72
+ .bind(entryId)
73
+ .first<Record<string, unknown>>()
74
+
75
+ if (!contentRecord) {
76
+ return publicProblem(context, {
77
+ type: 'content-not-found',
78
+ title: 'Not Found',
79
+ status: 404,
80
+ detail: `Entry '${entryId}' not found`
81
+ })
82
+ }
83
+
84
+ const storedFieldValueHash = contentRecord[targetFieldBranch.alias]
85
+
86
+ if (typeof storedFieldValueHash !== 'string' || storedFieldValueHash.length === 0) {
87
+ return publicProblem(context, {
88
+ type: 'rotate-field-not-set',
89
+ title: 'Unprocessable Entity',
90
+ status: 422,
91
+ detail: `Field '${fieldAlias}' has no stored value to rotate`
92
+ })
93
+ }
94
+
95
+ const isCurrentValueValid = await verifyHashField(storedFieldValueHash, currentValue)
96
+ if (!isCurrentValueValid) {
97
+ return publicProblem(context, {
98
+ type: 'rotate-field-current-mismatch',
99
+ title: 'Forbidden',
100
+ status: 403,
101
+ detail: 'Current value does not match stored value'
102
+ })
103
+ }
104
+
105
+ const fieldValidationResult = validateAndSanitizeSeedPayload(
106
+ seed,
107
+ { [fieldAlias]: nextValue },
108
+ { operation: 'update', allowNull: false, requireAtLeastOneValidField: true, enforceRequiredFields: false }
109
+ )
110
+
111
+ if (fieldValidationResult.details.length > 0) {
112
+ return publicProblem(context, {
113
+ type: 'rotate-field-invalid-next',
114
+ title: 'Bad Request',
115
+ status: 400,
116
+ detail: `Invalid value for field '${fieldAlias}': ${fieldValidationResult.details[0]?.message ?? 'validation failed'}`
117
+ })
118
+ }
119
+
120
+ const newFieldValueHash = await sha256hex(nextValue)
121
+ const currentTimestamp = Math.floor(Date.now() / 1000)
122
+
123
+ await database.prepare(`UPDATE content_${seedSlug} SET ${targetFieldBranch.alias} = ?, updated_at = ? WHERE id = ?`)
124
+ .bind(serializeForDb(targetFieldBranch, newFieldValueHash), currentTimestamp, entryId)
125
+ .run()
126
+
127
+ return context.json({ success: true })
128
+ })
129
+
130
+
131
+ export { rotateFieldApp }
132
+
@@ -1,9 +1,13 @@
1
- import { z } from 'zod'
2
-
3
- export const rotateFieldBodySchema = z.object({
4
- field: z.string().min(1, "field is required"),
5
- current: z.string().min(1, "current is required"),
6
- next: z.string().min(1, "next is required"),
7
- })
8
-
9
- export type RotateFieldBody = z.infer<typeof rotateFieldBodySchema>
1
+ import { z } from 'zod'
2
+
3
+ /**
4
+ * Schema for rotating a hashed field value.
5
+ * Used to update fields that have 'hash' privacy (e.g., passwords, PINs).
6
+ */
7
+ export const rotateFieldRequestSchema = z.object({
8
+ fieldAlias: z.string().min(1, "The field alias is required"),
9
+ currentValue: z.string().min(1, "The current value is required"),
10
+ nextValue: z.string().min(1, "The new value is required"),
11
+ })
12
+
13
+ export type RotateFieldRequest = z.infer<typeof rotateFieldRequestSchema>
@@ -1,16 +1,16 @@
1
- /// <reference types="@cloudflare/workers-types" />
2
- import { Hono } from 'hono'
3
- import type { Env, Variables } from '../../types'
4
-
5
- const schemaApp = new Hono<{ Bindings: Env; Variables: Variables }>()
6
-
7
- /**
8
- * Ritorna l'intero schema del CMS (la lista dei Seed configurati).
9
- * Usato dalla Dashboard per generare dinamicamente il menu e le form.
10
- */
11
- schemaApp.get('/', async (c) => {
12
- const registry = c.get('seedRegistry')
13
- return c.json(Object.values(registry))
14
- })
15
-
16
- export { schemaApp }
1
+ /// <reference types="@cloudflare/workers-types" />
2
+ import { Hono } from 'hono'
3
+ import type { Env, Variables } from '../../types'
4
+
5
+ const schemaApp = new Hono<{ Bindings: Env; Variables: Variables }>()
6
+
7
+ /**
8
+ * Ritorna l'intero schema del CMS (la lista dei Seed configurati).
9
+ * Usato dalla Dashboard per generare dinamicamente il menu e le form.
10
+ */
11
+ schemaApp.get('/', async (context) => {
12
+ const registry = context.get('seedRegistry')
13
+ return context.json(Object.values(registry))
14
+ })
15
+
16
+ export { schemaApp }