import { omitUndefinedKeys } from "./omitUndefinedKeys.ts"; import type { LinkUtmParams, createUtm } from "./utm.ts"; export function withParams(path: string, params?: Record) { if (!params) { return path; } const cleanParams = omitUndefinedKeys(params); if (Object.keys(cleanParams).length === 0) { return path; } return `${path}?${new URLSearchParams(cleanParams)}`; } export type AccountParams = { redirectTo?: string; backTo?: string; }; export type BuyParams = { note?: "continuePurchase" | "loginNeeded"; }; type InputAppHrefs = { login?: (params?: AccountParams) => string; join?: (params?: AccountParams) => string; password?: () => string; dashboard?: () => string; account: () => string; // These are usually external links to the root domain, so we want to be // able to set some tracking params. terms?: (linkUtm?: LinkUtmParams) => string; privacy?: (linkUtm?: LinkUtmParams) => string; cookies?: (linkUtm?: LinkUtmParams) => string; }; export type AppHrefs = Required; export function createHrefs(params: { /** * Hrefs to be used for the given app. At minimum, you need to provide * the core hrefs required by Appkit. */ hrefs: T; /** * The function responsible for generating UTM tags. You should * use the return value of {@link createUtm} unless you are doing something * unusual. */ utm: ReturnType; }) { const { utm, hrefs } = params; return { dashboard: () => `~/`, login: (params?: AccountParams) => withParams(`~/login`, params), join: (params?: AccountParams) => withParams(`~/join`, params), password: () => `~/password`, terms: (linkUtm?: LinkUtmParams) => `https://indietabletop.club/terms?${utm(linkUtm)}`, privacy: (linkUtm?: LinkUtmParams) => `https://indietabletop.club/privacy?${utm(linkUtm)}`, cookies: (linkUtm?: LinkUtmParams) => `https://indietabletop.club/cookies?${utm(linkUtm)}`, itc: (linkUtm?: LinkUtmParams) => `https://indietabletop.club?${utm(linkUtm)}`, fathom: () => `https://usefathom.com`, ...hrefs, }; }