/** * P1-backed PageStore — per-operation API calls. * * Each read/write/delete makes a real API call to the P1 backend. * No data is cached in memory — the backend is the source of truth. */ import type { PageLocalization, SeoMetadata, SiteLocales } from "@pantheon-systems/css-client"; import type { PageStore, RouteSummary } from "./types"; /** * Minimal subset of P1Client used by the store. * Declared here so consumers don't require a hard dependency on * @pantheon-systems/css-client — they pass in their own client instance. */ export interface P1StoreClient { documents: { list(siteId: string, branchId: string, options?: { include?: "routeSummary"[]; }): Promise<{ id: string; path: string; templateId?: string | null; routeSummary?: RouteSummary | null; }[]>; getByPath(siteId: string, path: string, branchId?: string): Promise<{ id: string; path: string; }>; create(params: { siteId: string; branchId: string; path: string; templateId?: string; templateVersion?: number; }): Promise<{ id: string; path: string; }>; delete(siteId: string, branchId: string, documentId: string): Promise; }; versions: { getLatest(siteId: string, branchId: string, documentId: string): Promise<{ snapshot: Record; }>; create(siteId: string, params: { documentId: string; branchId: string; snapshot: Record; }): Promise; }; queries?: { list(siteId: string, branchId: string): Promise<{ name: string; datasource: string; sort: unknown[]; defaultLimit: number; maxLimit: number; includeMetadata: boolean; includeSnapshot: boolean; autoGenerated: boolean; version: number; }[]>; getResults(siteId: string, branchId: string, queryName: string, params?: { limit?: number; offset?: number; includeMetadata?: boolean; includeSnapshot?: boolean; }): Promise<{ items: unknown[]; returnedCount: number; totalCount?: number; query: unknown; }>; }; } /** Minimal subset of P1ContentClient used for published-only reads. */ export interface P1ContentClientInterface { getPage(path: string): Promise<{ data: Record; metadata?: SeoMetadata; localization?: PageLocalization; siteLocales?: SiteLocales; } | null>; } export interface P1StoreConfig { client: P1StoreClient; /** * When provided, public reads (no auth token in context) use this client * which hits the content delivery endpoint and returns only published versions. * Editor reads (auth token present) always use the versions API. */ contentClient?: P1ContentClientInterface; siteId: string; /** * The workstream (branch) to read and write. When omitted, resolved lazily on * the first editor request via resolveBranchId. Public reads use the * workstream set on contentClient, and main when contentClient names none. * Reading a workstream other than main returns its latest saved version of * each page, or main's published version for a page not edited there, and * needs a site token with `read:draft` or `read:all`. */ branchId?: string; /** * Called on the first editor operation when branchId is not pre-configured. * Receives the bearer token from the active request context so branch * detection runs under the user's credentials, not the sat_ API key. */ resolveBranchId?: (bearerToken: string) => Promise; /** Factory to create a client with a specific bearer token (for user-auth writes). */ createAuthClient?: (bearerToken: string) => P1StoreClient; /** When true, read operations also use the per-request auth client instead of the shared API-key client. */ authenticatedReads?: boolean; } export declare function createP1PageStore(config: P1StoreConfig): PageStore;