Add web push notifications for new inbox items

This commit is contained in:
Ian Gulliver
2026-10-14 21:25:01 -07:00
parent 01c60d6618
commit 8e4c40eb5f
40 changed files with 1724 additions and 202 deletions
+6 -1
View File
@@ -12,9 +12,10 @@ export type InboxResponseCreate = Schemas["InboxResponseCreate"];
export type Attachment = Schemas["Attachment"];
export type ByreEvent = Schemas["Event"];
export type Status = Schemas["Status"];
export type NotificationPrefs = Schemas["NotificationPrefs"];
export type TurnRef = Schemas["TurnRef"];
type Method = "get" | "post" | "put";
type Method = "get" | "post" | "put" | "delete";
type PathsWith<M extends Method> = {
[P in keyof paths]: paths[P][M] extends { responses: unknown } ? P : never;
@@ -78,6 +79,9 @@ export async function request<M extends Method, P extends PathsWith<M>>(
}
const res = await fetch(url, init);
if (res.status === 204) {
return undefined as Result<Op<P, M>>;
}
const data = await res.json();
if (!res.ok) {
throw new ApiError(res.status, (data as Schemas["Error"]).message);
@@ -88,6 +92,7 @@ export async function request<M extends Method, P extends PathsWith<M>>(
export const get = <P extends PathsWith<"get">>(path: P, opts?: Options<Op<P, "get">>) => request("get", path, opts);
export const post = <P extends PathsWith<"post">>(path: P, opts?: Options<Op<P, "post">>) => request("post", path, opts);
export const put = <P extends PathsWith<"put">>(path: P, opts?: Options<Op<P, "put">>) => request("put", path, opts);
export const del = <P extends PathsWith<"delete">>(path: P, opts?: Options<Op<P, "delete">>) => request("delete", path, opts);
export function subscribe(after: number, onEvent: (ev: ByreEvent) => void, onState: (connected: boolean) => void): EventSource {
const source = new EventSource(`/api/events?after=${after}`);