Skip to content

feat(calendar): subscribe to a class's feed from every menu row #393

Description

@sydevs-bot

Summary

"Add to calendar" cannot subscribe anyone to anything. Apple Calendar gets a downloaded file, Google gets a one-off action=TEMPLATE link, and Outlook, Office 365 and Yahoo get only the single session the viewer registered for. SahajCloud will serve a token-addressed .ics feed per class, so this rebuilds the menu over that address: Apple, Google and both Outlooks subscribe, Yahoo keeps its one session, and the download becomes its own last row. It also admits webcal: at the href gate, selects the new field on the event read, and updates the host contract.

Goal context

Consumer child of #368 ("People can add a class to their calendar in one click, whichever calendar they use"). sydevs/SahajCloud#1131 produces the feed, its address and the menu copy; this child builds the menu over all three and merges after it.

Interfaces

Consumed from sydevs/SahajCloud#1131, three things:

  • The feed — GET https://<cloud host>/api/events/calendar/<token>.ics, text/calendar; charset=utf-8, unauthenticated, carrying the full recurrence and no joining link. 404 for an unknown or tampered token and for a finished class; STATUS:CANCELLED for 90 days after a takedown.
  • events.calendarFeedUrl — a virtual, read-only https:// string on the single-event read, null on list reads, the geojson feed, relationship hydration and an unpublished class. It is defaultPopulate: false upstream, so an explicit select is required. It reaches this repo as a generated type through pnpm types:cms, which the dispatcher's contract sync runs on this PR once the producer merges.
  • Two event.actions keys — calendar_next_session_only ("Adds the next session only") and calendar_keeps_updated ("Keeps itself up to date"), reaching this repo through pnpm sync:translations --write once the producer is deployed.

This provides nothing back to the producer. No other repo consumes anything added here.

Approach

A. The addresses (src/lib/ics.ts)

Read the whole file docblock (:7-53) before editing. Its two arguments — why the ICS is hand-rolled (#105, #52) and why schedule.icalRule is unusable — still hold for the download row, which keeps buildEventIcs (:322) unchanged. Keep both, and add which rows now subscribe instead of building a file.

  • IcsEventInput (:55) gains the feed address as an optional nullish field. The address no longer follows from input.id, so it is read off the event document, never composed here.
  • One builder for the webcal:// form of that address (scheme swap on the https:// string), and the provider wrappers over it. Each returns undefined when the event carries no address:
    • Apple — the webcal:// form itself.
    • Google — https://calendar.google.com/calendar/r?cid=<the webcal address, percent-encoded>. This replaces today's buildGoogleCalendarUrl (:379), whose action=TEMPLATE + recur=RRULE: + ctz params go, per the goal's decision that Google subscribes. ⚠ One source reports the webcal URL landing in Google's Calendar-Name field rather than its address field, so verify what the dialog actually shows (§ Verification), not merely that it opens.
    • Outlook.com / Office 365 — two candidate shapes over OUTLOOK_HOSTS (:408), tried in order, documented by nobody: …/calendar/0/addfromweb?url=… first, then …/calendar/0/deeplink/compose?path=/calendar/action/compose&rru=addsubscription&url=…. Try each with both the webcal:// and the https:// form of url=.
    • Yahoo — buildYahooCalendarUrl (:451) unchanged.
  • Keep buildOutlookCalendarUrl (:425) as the fallback. Its rru=addevent shape is the sibling of rru=addsubscription and it works today. If no candidate opens a subscribe dialog listing more than one session, the two Outlook rows keep that link and take the calendar_next_session_only sub-label — the treatment the goal's decisions already give a service with no subscribe route, so it needs no new answer. It does cost the goal's Outlook success line, so the PR must say which outcome happened.
  • Correct the docblock's Apple claim (:14-18). It says Apple resolves IANA TZIDs without a VTIMEZONE, which SahajCloud's own builder docblock contradicts. Apple no longer reads anything this file emits — it subscribes to the feed, which ships VTIMEZONE — so state which rows each builder serves and drop the Apple-specific claim rather than leave two repos' docblocks disagreeing.
  • Pin every built URL in src/lib/ics.test.ts against a parsed URL — url.origin + url.pathname plus url.searchParams.get(…), as :328-334 and :393-404 already do. Never a string compare: a percent-encoding difference that a calendar accepts would read as a failure, and one it rejects would not.
  • ⚠ The host comes from VITE_SAHAJCLOUD_URL (src/config/api/client.ts:72), by way of the field. Google and Microsoft fetch the feed server-side, so a localhost or dev host is unreachable to them and no local run can verify those two rows. Verification is on a deployed preview pointed at production SahajCloud.

B. The scheme gate (src/lib/shape/href.ts)

webcal: is refused today, silently: it is not in ALLOWED_SCHEME (:15), so Link reports and degrades the row to a <span> (src/components/atoms/Link/Link.tsx:105) — a row that looks normal and does nothing.

  • Add webcal to ALLOWED_SCHEME, and extend src/lib/shape/href.test.ts (which also asserts the JSX-anchor inventory at :131-191, and asserts the allowed set at :111).
  • ⚠ The docblock's case-insensitivity argument needs the new distinction. It ties the list to two upstream guards over CMS-authored URLs — SafeUrlSchema (src/types/event.ts:124) and validateWebUrl — both /^https?:/i. webcal: is an address we build from a field we select, and it reaches neither guard, so say that rather than let the docblock imply a guard that does not cover it.
  • Check the same two sentences elsewhere: isSafeHref's own docblock and docs/rules/data-layer.md:171 § "isSafeHref is the sink-level gate" both say "three allowed schemes" and name them. Correct both.
  • No new JSX anchor: the rows render through the Link atom, so the inventory stays at three.

C. The event read

  • getEventDoc (src/config/api/fetch.ts:668) adds the new field to its select. SahajCloud requires an explicit select on every client read, and the field is defaultPopulate: false upstream, so an unlisted field comes back absent.
  • EventDocSchema (src/types/event.ts:197) carries it, shaped like webUrl (:227) on SafeUrlSchema (:124): https?: only, .nullish().catch(null), so a class with no address parses rather than failing the whole event read.
  • Thread it to the menu through calendarExport (src/views/RegistrationView/RegistrationView.tsx:82-99), which is where the form's calendar prop is built (RegistrationForm.tsx:454). The view holds the full doc; AddToCalendar takes export primitives, never an Event.
  • ⚠ src/types/payload/ is generated and is a contractSync path. Do not run pnpm types:cms while the producer is unmerged — it reads SahajCloud's main and would silently pull the old shape. Copy the producer branch's generated file by hand during the set build; the dispatcher re-syncs it on this PR once the producer merges.

D. The menu (src/components/molecules/AddToCalendar/)

AddToCalendar.tsx, plus AddToCalendar.test.tsx and AddToCalendar.stories.tsx.

  • Final order and labels: Apple Calendar, Google Calendar, Outlook.com, Office 365 (each subscribing, each with the calendar_keeps_updated sub-label), Yahoo (one session, calendar_next_session_only), then "Download .ics file" last.
  • The download row carries event.actions.download_ics as its own label, not a sub-label. The Apple row uses that key as a sub-label today (:92) and no longer downloads anything.
  • calendarLinkTargets (:32-39) gains the sub-label on its target type and returns the five rows in that order; with no feed address it returns none.
  • The download row stays a <button> (:90, downloadEventIcs at :41-54) because it synthesises a file. The other five are anchors through Link with target="_blank", as :95-101 already renders.
  • No address on the event → render the download row alone. Never render a subscribe row that cannot work.

E. The host contract

Per AGENTS.md, anything a host can observe lands in docs/embedding.md and CHANGELOG.md in the same PR.

  • allow-popups now covers the whole calendar menu, not just the compact card and four link-outs. Extend the notes at docs/embedding.md:86-87 and :602-604 and the troubleshooting row at :1360, and add that a sandboxed frame can refuse a protocol handler (webcal:) even with allow-popups.
  • allow-downloads now matters for the last row alone. docs/embedding.md:604 and :1361 and CHANGELOG.md:70-74 all tie it to the Apple row. Correct all three.
  • The CSP and Permissions-Policy tables need nothing, and the PR says so explicitly: every row is a navigation, not a fetch. A reviewer should not have to go looking.

F. The copy

Copy is CMS-owned. This repo may not hand-edit a string, and never src/config/translations.en.json (pnpm sync:translations --write generates it; add_calendar and download_ics sit at :90,93). Once sydevs/SahajCloud#1131 is deployed, run that sync in the build session, then wire the t() calls. src/config/translations.test.ts pins the snapshot against every call site in both directions, so a t() with no key fails the unit lane — the honest consequence is that the rows needing the two new keys cannot ship until the sync lands.

Acceptance criteria

A — the addresses

  • A builder reads the feed address off the event document and never composes one from the event id
  • The Apple address is the webcal:// form of that address, unchanged otherwise
  • The Google address is https://calendar.google.com/calendar/r with cid carrying the webcal:// address
  • No built URL carries action=TEMPLATE, recur= or ctz= any more
  • Each Outlook row carries whichever subscribe shape verification settled, or buildOutlookCalendarUrl's rru=addevent link if neither subscribed
  • The Yahoo address is byte-identical to today's
  • Every built URL is asserted in src/lib/ics.test.ts through a parsed URL, never a string compare
  • The file docblock keeps its hand-rolled and icalRule arguments, says which rows each builder serves, and no longer claims Apple reads a TZID without VTIMEZONE

B — the scheme gate

  • isSafeHref and hasAllowedScheme both accept webcal: and WEBCAL:, and src/lib/shape/href.test.ts pins both
  • A webcal: href renders as a real <a>, not a <span>, and reports nothing
  • The JSX-anchor inventory is still exactly three components
  • ALLOWED_SCHEME's docblock says webcal: is built here and reaches neither SafeUrlSchema nor validateWebUrl
  • isSafeHref's docblock and docs/rules/data-layer.md § "isSafeHref is the sink-level gate" both name four schemes

C — the event read

  • getEventDoc's select names the feed field, and EventDocSchema parses it as a nullish http(s) URL
  • An event document with the field absent, null, or a non-http string still parses, with the address falling to null
  • The address reaches AddToCalendar through calendarExport, not through a second read

D — the menu

  • The rows render in order: Apple Calendar, Google Calendar, Outlook.com, Office 365, Yahoo, Download .ics file
  • The four subscribing rows carry event.actions.calendar_keeps_updated; Yahoo carries event.actions.calendar_next_session_only
  • The last row's own label is event.actions.download_ics, and no row carries that key as a sub-label
  • The last row is a <button>; the other five are anchors with target="_blank"
  • An event with no feed address renders the download row and nothing else

E — the host contract

  • docs/embedding.md ties allow-popups to the whole calendar menu and says a sandbox may refuse a webcal: protocol handler even with it
  • docs/embedding.md and CHANGELOG.md tie allow-downloads to the download row only, in all three places that name the Apple row today
  • CHANGELOG.md has an entry describing the menu change in host-facing terms
  • The PR body states that the CSP and Permissions-Policy tables need no change, and why

F — the copy and the order

  • No string is hand-edited, and src/config/translations.en.json changes only as pnpm sync:translations --write wrote it
  • The two new keys are present in that snapshot before any t() call referencing them is pushed
  • The PR reports which Outlook outcome happened — a subscribe dialog on both hosts, or the single-session fallback

Verification checklist

  • .claude/skills/pr-prep/check.sh — the lean gate (lint, typecheck, test:run)
  • pnpm test:run src/lib/ics.test.ts src/lib/shape/href.test.ts src/types/event.test.ts src/config/api/fetch.test.ts src/components/molecules/AddToCalendar/AddToCalendar.test.tsx src/config/translations.test.ts
  • pnpm build && pnpm size — the eager-payload budget
  • pnpm build && pnpm review:embed, then open the sandboxed host page: every subscribe row opens something or says why, and the download row is the only one that needs allow-downloads. Repeat with allow-popups removed and confirm the failure matches what docs/embedding.md:1360 now says
  • On a deployed preview pointed at production SahajCloud (⚠ not a local server — Google and Microsoft fetch the feed server-side and cannot reach localhost), register for a weekly class and click each row signed in:
    • Apple Calendar (macOS or iOS): a subscribe prompt naming the class, no file in Downloads; after accepting, at least three future sessions appear
    • Google Calendar: a subscribe dialog, the class lands under "Other calendars" with all its sessions, and the dialog shows the feed as the address, not as the calendar's name
    • Outlook.com (personal account) and Office 365 (work account): a subscribe dialog, not an add-event form, listing more than one session. Try addfromweb first, then rru=addsubscription, each with the webcal:// and the https:// form of url=, and record which combination worked on which host
    • Yahoo: one session, and the row says so
  • DST, against the subscribed feed in Apple Calendar and Google Calendar: a 6pm Europe/London class still reads 6pm for a session after the next clock change
  • curl -sI "<the address from the event read>" → 200 and text/calendar, confirming the field the menu is building from actually answers

Notes

That line orders the merge, not the build: the set is built together, in one session, against the producer's branch. The generated types are provisional until the producer merges and the dispatcher's contract sync refreshes them on this PR.

This PR triggers a security review. .claude/workflow.json's securityReview.triggerPattern covers both src/lib/shape/href and src/config/api/, and this change widens the href allowlist and adds a field to a client read.

The feed is unauthenticated by construction and its token is the whole access control — sydevs/SahajCloud#1131 owns that, and this repo only puts the address it is handed into an href.

The menu redesign this builds on: #366 (merged).

Activity

  1. added
    proposal
    on Nov 11, 2026
  2. moved this from Awaiting to Blocked in SYDevelopers Technical Roadmapon Nov 11, 2026
  3. removed
    proposal
    on Nov 11, 2026
  4. sydevs-bot commented on Nov 11, 2026

    @sydevs-bot
    ContributorAuthor

    🤖 no session running
    approved by Ardnived

    Written by the sydevs dispatcher. Sessions never edit this comment.

  5. moved this from Blocked to Pending in SYDevelopers Technical Roadmapon Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Fields

    Priority

    Medium

    Hold Until

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions