chris bb6c8a03a7 fix: calendar newlines, admin delivery window setting
CalDAV: joins were using literal '\n' strings which icalEscape then
double-escaped the backslash, so calendar entries showed raw \n. Now
joins use real newline chars which icalEscape converts correctly.

Added deliveryWindowMinutes to HoursConfig (default 60 min). The
checkout route reads this at request time to set both the Square
deliveryWindowDuration and the customer email arrival window. Admin
hours page now has a number input to configure it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 10:57:37 -04:00

29 lines
1.0 KiB
TypeScript

import { readFileSync, existsSync } from 'fs'
import path from 'path'
import { atomicWriteJSON } from './file-utils'
import { DEFAULT_HOURS } from './hours-config'
import type { HoursConfig } from './hours-config'
export type { DayHours, WeekHours, HoursConfig } from './hours-config'
export { DEFAULT_HOURS, minsToTime, timeToMins } from './hours-config'
const HOURS_PATH = path.join(process.cwd(), 'data', 'hours.json')
export function getHoursConfig(): HoursConfig {
if (!existsSync(HOURS_PATH)) return DEFAULT_HOURS
try {
const saved = JSON.parse(readFileSync(HOURS_PATH, 'utf-8')) as Partial<HoursConfig>
return {
delivery: { ...DEFAULT_HOURS.delivery, ...(saved.delivery ?? {}) },
pickup: { ...DEFAULT_HOURS.pickup, ...(saved.pickup ?? {}) },
deliveryWindowMinutes: saved.deliveryWindowMinutes ?? DEFAULT_HOURS.deliveryWindowMinutes,
}
} catch {
return DEFAULT_HOURS
}
}
export function saveHoursConfig(config: HoursConfig): void {
atomicWriteJSON(HOURS_PATH, config)
}