/** * Server-side remote data source loading for Puck template resolution (`{{ source.path }}`). * Site-specific fetchers are provided via `builtinFetchers` by the consuming app. * * NOTE: This file imports from the DAL (user-remote-datasource-store) and must * NOT be re-exported through the client barrel. Client-safe exports live in * `fetch-http-json.ts`. */ import type { HostResolver } from "./egress-guard"; export type RemoteDatasourceContext = Record; export declare function extractReferencedDatasourceIds(data: unknown): Set; export type RemoteDatasourceFetcherParams = { /** Query params from the URL. */ searchParams: Record; /** Params captured from route template matching (e.g. { id: "5" } from /jedi/:id). */ urlParams: Record; /** Saved preview params from the editor. */ savedPreviewParams: Record; /** Fetch implementation to use for HTTP requests. */ fetchImpl: typeof fetch; }; export type RemoteDatasourceFetcher = { /** The key under which the fetched data appears in the datasource context. */ id: string; /** Fetch function that returns the data for this datasource. */ fetch: (params: RemoteDatasourceFetcherParams) => Promise>; }; /** A single remote datasource that failed to load under {@link LoadRemoteDatasourceContextOpts.isolateFailures}. */ export type RemoteDatasourceFailure = { /** The id of the datasource that failed. */ id: string; /** Whether the datasource timed out or failed for another reason. */ reason: "timeout" | "failed"; }; export type LoadRemoteDatasourceContextOpts = { /** * Omit for a page rendered ahead of its request. Published pages are cached, * so they never read the query string; route template params come from the * path either way. */ searchParams?: URLSearchParams | Record; fetchImpl?: typeof fetch; pagePath?: string; routeTemplateKeys?: string[]; savedPreviewParams?: Record; builtinFetchers?: RemoteDatasourceFetcher[]; /** When set, only fetchers whose id appears in this set will run. */ referencedDatasourceIds?: Set; /** * Resolves the hosts of user-defined HTTP JSON datasources so every address * can be checked before a request is sent. Defaults to the platform DNS * resolver when `fetchImpl` is omitted or is the global `fetch`; a custom * `fetchImpl` without a resolver gets URL-only checks. */ resolveHost?: HostResolver; /** * Opt into per-datasource fault isolation: a slow or failing datasource * resolves to an empty object and is reported via `onFailure` instead of * rejecting the whole load. Omit this to let a rejection propagate, which * is required wherever a failure must not be cached as empty data. */ isolateFailures?: { /** Milliseconds to wait for a single datasource before treating it as timed out. */ timeoutMs: number; /** Called once for each datasource that times out or fails. */ onFailure: (failure: RemoteDatasourceFailure) => void; }; }; /** * Load all named remote datasource values for the current request. * * Resolves URL params from route template matching, saved preview params, and query params, * then calls each builtin fetcher and each user-defined HTTP JSON datasource in parallel. */ export declare function loadRemoteDatasourceContext(opts: LoadRemoteDatasourceContextOpts): Promise;