mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 23:33:29 +00:00
A calendar feed is a standing credential whose contents end up in a
third party's calendar cloud. Putting a record's cycle dates there is
the decision of the person they are about, or of the guardian of
somebody who cannot make it, and no delegate of an adult's record,
MANAGE included.
The subscription routes resolve through requireGuardianAuth instead of
requireRecordAuth("manage", "cycle"): the owner on their own record, or
a MANAGE grant on a record carrying the managed-profile marker. Every
verb follows, the revoke too. The feed re-reads the marker on each fetch
as well as the guardian's grant, so a row minted for somebody else on an
adult's record is a 404 whatever grant stands behind it. The settings
card is offered only where the routes answer.
The routes move from the delegable and MANAGE literals to the guardian
list, and the MANAGE handler inventory is back to 93.
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
/**
|
|
* Pieces the calendar-feed management routes share (#1350).
|
|
*
|
|
* Management is cookie-only. Minting hands out a standing URL credential, so
|
|
* it needs the person at the keyboard (a fresh proof on the session) and is
|
|
* not reachable from a Bearer token at all; the native app shows "set up on
|
|
* the web" instead. The routes resolve through `requireGuardianAuth()`, so
|
|
* the owner and the guardian of a managed profile reach them, and every
|
|
* delegate on an adult's record (MANAGE included) does not.
|
|
*/
|
|
import { apiError } from "@/lib/api-response";
|
|
|
|
import { feedPath } from "./token";
|
|
|
|
/** Mint and rotate, per acting account. */
|
|
export const FEED_MINT_LIMIT_PER_HOUR = 10;
|
|
export const FEED_MINT_WINDOW_MS = 60 * 60 * 1000;
|
|
|
|
/** The refusal a Bearer caller gets: management is a web surface. */
|
|
export function cookieOnlyRefusal(): Response {
|
|
return apiError("Calendar subscriptions are managed on the web", 403, {
|
|
errorCode: "cycle.feed.cookie_only",
|
|
});
|
|
}
|
|
|
|
export function noLiveFeed(): Response {
|
|
return apiError("No calendar subscription is on", 404, {
|
|
errorCode: "cycle.feed.none",
|
|
});
|
|
}
|
|
|
|
export function feedExists(): Response {
|
|
return apiError(
|
|
"A calendar subscription is already on. Rotate it for a new link.",
|
|
409,
|
|
{ errorCode: "cycle.feed.exists" },
|
|
);
|
|
}
|
|
|
|
/** The two forms of the link, built once, at mint. */
|
|
export function feedLinks(
|
|
origin: string,
|
|
raw: string,
|
|
): { url: string; webcalUrl: string } {
|
|
const url = `${origin}${feedPath(raw)}`;
|
|
return { url, webcalUrl: url.replace(/^https?:/, "webcal:") };
|
|
}
|