Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import type { ListEmailItem } from "$lib/api/emails";
export const deliberiUrl = "https://deliberi.example.test";
export const primaryEmail = "alice@example.com";export const secondaryEmail = "alice@work.example.com";export const unverifiedEmail = "a.liddell@mail.example.com";
export const emails: ListEmailItem[] = [ { address: primaryEmail, verified: true, primary: true, createdAt: "2026-05-12T09:14:00Z" }, { address: secondaryEmail, verified: true, primary: false, createdAt: "2026-07-03T16:40:00Z" }, { address: unverifiedEmail, verified: false, primary: false, createdAt: "2026-09-16T11:02:00Z" }];
export const serviceAuth = (pathname: string): Response => pathname.includes("getServiceAuth") ? Response.json({ token: "service-auth-jwt" }) : new Response(null, { status: 404 });
export type Answer = () => Promise<Response>;
export const ok = (body?: unknown): Answer => () => Promise.resolve( body === undefined ? new Response(null, { status: 200 }) : Response.json(body) );
export const pending: Answer = () => new Promise(() => {});
export const failed = (status: number, message = "deliberi is down"): Answer => () => Promise.resolve(Response.json({ error: "InternalError", message }, { status }));
export const offline: Answer = () => Promise.reject(new TypeError("Failed to fetch"));
export interface EmailAnswers { listEmails?: Answer; addEmail?: Answer; deleteEmail?: Answer; setPrimaryEmail?: Answer; verifyEmail?: Answer;}
export const mockEmailFetch = (answers: EmailAnswers): typeof fetch => { const real = window.fetch; return (input, init) => { const url = String(input instanceof Request ? input.url : input); for (const [name, answer] of Object.entries(answers)) { if (answer && url.includes(`org.tangled.temp.account.${name}`)) return answer(); } return real(input, init); };};
export const installEmailFetch = ({ parameters }: { parameters: Record<string, unknown> }) => { const original = window.fetch; window.fetch = mockEmailFetch((parameters.deliberi as EmailAnswers | undefined) ?? {}); return () => { window.fetch = original; };};