// Guests have no account to list Orders under, so their Order history is // tracked client-side instead: each placed guest Order's id + access token // is remembered here so `/orders` can look them back up without a sign-in. const STORAGE_KEY = 'ghost-kitchen-guest-orders' export type GuestOrderRef = { orderId: number; guestAccessToken: string } const isGuestOrderRef = (value: unknown): value is GuestOrderRef => typeof value === 'object' && value !== null && typeof (value as GuestOrderRef).orderId === 'number' && typeof (value as GuestOrderRef).guestAccessToken === 'string' export const getGuestOrderRefs = (): Array => { try { const raw = window.localStorage.getItem(STORAGE_KEY) if (!raw) return [] const parsed: unknown = JSON.parse(raw) return Array.isArray(parsed) ? parsed.filter(isGuestOrderRef) : [] } catch { return [] } } export const addGuestOrderRef = (ref: GuestOrderRef) => { try { const existing = getGuestOrderRefs().filter( (stored) => stored.orderId !== ref.orderId, ) window.localStorage.setItem( STORAGE_KEY, JSON.stringify([ref, ...existing]), ) } catch { // Unavailable (private mode, quota) — the order still works via its // own link, it just won't show up in the local Orders list. } }