fix(03): WR-01 preserve existing RRULE on edit instead of resetting to none

This commit is contained in:
Lucas Berger
2026-06-09 10:39:06 -04:00
parent f645644853
commit 02aa407764
4 changed files with 80 additions and 17 deletions
+23
View File
@@ -43,6 +43,29 @@ export const RRULE_PRESETS: Record<string, string> = {
yearly: 'FREQ=YEARLY',
}
/**
* WR-01: Extract the existing RRULE string from a stored VCALENDAR/VEVENT, so the
* outbox worker can preserve recurrence on an edit whose payload omits it (the PWA
* occurrence contract does not expose recurrence, D-03). Returns the RRULE value as a
* 'FREQ=…' string (e.g. 'FREQ=WEEKLY'), or undefined when the event has no RRULE or
* the input cannot be parsed.
*/
export function extractRruleString(rawVevent: string): string | undefined {
let parsed: ReturnType<typeof ICAL.parse>
try {
parsed = ICAL.parse(rawVevent)
} catch {
return undefined
}
const comp = new ICAL.Component(parsed)
const vevent = comp.getFirstSubcomponent('vevent')
if (!vevent) return undefined
const rrule = vevent.getFirstPropertyValue('rrule')
if (!rrule) return undefined
// ICAL.Recur#toString() yields the RECUR value, e.g. 'FREQ=WEEKLY'.
return typeof rrule === 'string' ? rrule : (rrule as ICAL.Recur).toString()
}
/**
* Builds a VCALENDAR/VEVENT iCalendar string from form parameters.
*