feat(timetable): types + zod schemas + idempotency-key helper (Session 4 step 1)
- Extract generateIdempotencyKey() from useFormDraft into reusable lib/ - New types/timetable.ts mirrors PerformanceResource, ArtistEngagementResource, StageResource, GenreResource and the four enums verbatim - New schemas/timetable.ts adds zod parsers for runtime validation of API responses + form payloads (createPerformance, createStage, moveTimetable) RFC v0.2 §10 contract surface for the upcoming timetable canvas. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
useSaveFormDraft,
|
||||
useSubmitForm,
|
||||
} from '@/composables/api/usePublicForm'
|
||||
import { generateIdempotencyKey } from '@/lib/idempotencyKey'
|
||||
import type { FormValues, PublicFormSubmission, SaveDraftBody } from '@/types/forms/formBuilder'
|
||||
|
||||
/** sessionStorage key for reusing an idempotency key across reloads. */
|
||||
@@ -19,25 +20,6 @@ export function draftSubmitterStorageKey(token: string): string {
|
||||
return `draft_submitter:${token}`
|
||||
}
|
||||
|
||||
function generateIdempotencyKey(): string {
|
||||
const c = (globalThis as { crypto?: { randomUUID?: () => string; getRandomValues?: (arr: Uint8Array) => Uint8Array } }).crypto
|
||||
if (c?.randomUUID) {
|
||||
// UUID v4 (36 chars) exceeds backend max:30. Backend expects 6..30
|
||||
// chars so compress to 24 hex chars (still collision-resistant).
|
||||
return c.randomUUID().replace(/-/g, '').slice(0, 24)
|
||||
}
|
||||
if (c?.getRandomValues) {
|
||||
const buf = new Uint8Array(12)
|
||||
|
||||
c.getRandomValues(buf)
|
||||
|
||||
return Array.from(buf, b => b.toString(16).padStart(2, '0')).join('')
|
||||
}
|
||||
|
||||
// Last-resort fallback — still within 6..30.
|
||||
return `idem-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`.slice(0, 30)
|
||||
}
|
||||
|
||||
interface UseFormDraftOptions {
|
||||
|
||||
/** Preferred locale string for `submitted_in_locale` (e.g. `"nl"`). */
|
||||
|
||||
Reference in New Issue
Block a user