/** * Workspace resolver — maps a storefront deployment's own hostname to its * FavCRM workspace (`companyId`), so a deployment can identify its workspace * at request time instead of hard-coding a `companyId` env var. * * Framework-agnostic: a SvelteKit `hooks.server.ts`, a Next.js middleware, or * any server runtime calls `resolve(hostname, fetch)` and stashes the result. * * Backs the public `GET /v6/customer-portal/storefront/resolve-domain` * endpoint. Registered hostnames are managed via `/v6/dev/verify` (auto on * signup) or `/v6/merchant/storefront-domains`. * * @example * ```ts * // one module-level instance, reused across requests * const resolver = createWorkspaceResolver({ apiUrl: "https://api.favcrm.io" }); * * // in a per-request server hook * const companyId = * (await resolver.resolve(url.hostname, fetch)) ?? ENV_COMPANY_ID; * ``` */ export interface WorkspaceResolverOptions { /** FavCRM API base URL, e.g. `https://api.favcrm.io`. Trailing slash optional. */ apiUrl: string; /** * How long a resolution — hit *or* miss — is cached. Default 5 minutes. * A miss is cached too, so an unregistered host is not re-fetched per request. */ ttlMs?: number; /** * Abort the resolve request after this many ms. Default 3000. * * The resolver runs inside a server hook before the page renders, so a hung * API would otherwise stall every cold request. On timeout the resolution is * treated as a miss and the caller falls back to its env var / demo mode. */ timeoutMs?: number; } export interface WorkspaceResolver { /** * Resolve a deployment hostname to its workspace `companyId`. * * Returns `null` for a local host, an unregistered hostname, or any * network/parse error — never throws, so callers can fall back cleanly. * * @param hostname - The request hostname (a port suffix is stripped). * @param fetchFn - Fetch implementation; defaults to `globalThis.fetch`. * Pass the framework's request-scoped `fetch` when available. */ resolve(hostname: string, fetchFn?: typeof globalThis.fetch): Promise; /** Drop all cached resolutions. Mainly for tests. */ clear(): void; } /** * Create a workspace resolver with its own in-memory cache. Construct one per * process (module scope) and reuse it — the cache is what keeps resolution off * the network on most requests. */ export declare function createWorkspaceResolver(options: WorkspaceResolverOptions): WorkspaceResolver; //# sourceMappingURL=storefront-resolver.d.ts.map