import "./options-B5K8QEV1.mjs"; import "./types-BCOU_CXE.mjs"; import "./types-XJPFqvc1.mjs"; import "./authz-cKSuylYa.mjs"; import "./index-HRJ8DhHY.mjs"; import "./runner-Bnq68jCZ.mjs"; import "./index-BFUET8yL.mjs"; import "./types-C2avdenh.mjs"; import "./hreflang-BktsQIF_.mjs"; import "./validate-3945fzPI.mjs"; import { EmDashHandlers } from "./astro/types.mjs"; //#region src/plugin-utils.d.ts type PublicPluginApiRouteHandler = EmDashHandlers["handlePublicPluginApiRoute"]; interface PublicPluginRuntimeLocals { emdash?: { handlePublicPluginApiRoute?: PublicPluginApiRouteHandler; }; } /** * Fetch wrapper that adds the `X-EmDash-Request` CSRF protection header. * * All plugin admin API calls should use this instead of raw `fetch()`. * State-changing endpoints reject requests without this header. */ declare function apiFetch(input: string | URL | Request, init?: RequestInit): Promise; /** * Get the public-only plugin route dispatcher exposed to SSR page components. * * This intentionally reads `handlePublicPluginApiRoute`, not the raw * `handlePluginApiRoute` used by core's authenticated plugin API route. */ declare function getPublicPluginApiRouteHandler(locals: PublicPluginRuntimeLocals | null | undefined): PublicPluginApiRouteHandler | undefined; /** * Parse an API response, unwrapping the `{ success, data: T }` envelope. * * All plugin API routes return success responses wrapped in * `{ success: true, data: ... }` by `apiSuccess()`. This helper unwraps that * envelope and handles errors. * * On error responses (non-2xx), throws an Error with the server's message * (from `{ success: false, error: { message } }`) or the fallback message. * * @example * ```ts * const res = await apiFetch("/_emdash/api/plugins/my-plugin/items"); * const { items } = await parseApiResponse<{ items: Item[] }>(res, "Failed to load items"); * ``` */ declare function parseApiResponse(response: Response, fallbackMessage?: string): Promise; /** * Extract the error message from a failed API response. * * Error responses use the shape `{ success: false, error: { code, message } }`. * This helper parses that body and returns the message, falling back to the * provided default. * Swallows JSON parse failures gracefully. * * @example * ```ts * if (!res.ok) { * setError(await getErrorMessage(res, "Failed to save")); * return; * } * ``` */ declare function getErrorMessage(response: Response, fallback: string): Promise; /** * Narrow `unknown` to a plain object record. * * Useful for safely inspecting untyped API responses before accessing properties. */ declare function isRecord(value: unknown): value is Record; //#endregion export { PublicPluginApiRouteHandler, PublicPluginRuntimeLocals, apiFetch, getErrorMessage, getPublicPluginApiRouteHandler, isRecord, parseApiResponse }; //# sourceMappingURL=plugin-utils.d.mts.map