import { A as ContentHookEvent, Bt as SandboxBuildSpec, C as ContentAfterScheduleHandler, Ct as PluginContext, D as ContentBeforeSaveHandler, E as ContentBeforeDeleteHandler, F as ContentStateChangeEvent, G as EmailBeforeSendHandler, H as EmailAfterSendEvent, K as EmailDeliverEvent, L as CronEvent, M as ContentPublishStateChangeEvent, N as ContentRestoreStateChangeEvent, P as ContentScheduleStateChangeEvent, R as CronHandler, S as ContentAfterSaveHandler, T as ContentAfterUnscheduleHandler, U as EmailAfterSendHandler, W as EmailBeforeSendEvent, Xt as UninstallHandler, Yt as UninstallEvent, Zt as UserInfo, _ as CommentModerateHandler, a as AgentSkillSpec, at as MediaAfterUploadHandler, b as ContentAfterPublishHandler, ct as MediaUploadEvent, d as CommentAfterCreateHandler, dt as PageFragmentEvent, et as LifecycleEvent, f as CommentAfterModerateEvent, ft as PageFragmentHandler, g as CommentModerateEvent, h as CommentBeforeCreateHandler, ht as PageMetadataHandler, i as AgentSessionSpec, it as MediaAfterUploadEvent, k as ContentDeleteEvent, m as CommentBeforeCreateEvent, mt as PageMetadataEvent, n as AgentMcpServerSpec, o as AgentsAccess, ot as MediaBeforeUploadHandler, p as CommentAfterModerateHandler, q as EmailDeliverHandler, r as AgentRunSpec, t as AgentCallbackSpec, tt as LifecycleHandler, u as CommentAfterCreateEvent, w as ContentAfterUnpublishHandler, x as ContentAfterRestoreHandler, y as ContentAfterDeleteHandler, zt as SandboxAccess } from "./types-XJPFqvc1.mjs"; import { Permission } from "@premium-cms/auth"; import { ZodType } from "zod"; //#region src/plugin-types.d.ts /** * Map from hook name to its handler signature. Adding or changing a * hook signature in the runtime means updating this map; the rest of * the type story flows from it. Authors writing * `"content:beforeSave": async (event, ctx) => { ... }` get `event` * typed as `ContentHookEvent` and `ctx` as `PluginContext` for free. */ interface HookHandlers { "plugin:install": LifecycleHandler; "plugin:activate": LifecycleHandler; "plugin:deactivate": LifecycleHandler; "plugin:uninstall": UninstallHandler; "content:beforeSave": ContentBeforeSaveHandler; "content:afterSave": ContentAfterSaveHandler; "content:beforeDelete": ContentBeforeDeleteHandler; "content:afterDelete": ContentAfterDeleteHandler; "content:afterPublish": ContentAfterPublishHandler; "content:afterUnpublish": ContentAfterUnpublishHandler; "content:afterRestore": ContentAfterRestoreHandler; "content:afterSchedule": ContentAfterScheduleHandler; "content:afterUnschedule": ContentAfterUnscheduleHandler; "media:beforeUpload": MediaBeforeUploadHandler; "media:afterUpload": MediaAfterUploadHandler; cron: CronHandler; "email:beforeSend": EmailBeforeSendHandler; "email:deliver": EmailDeliverHandler; "email:afterSend": EmailAfterSendHandler; "comment:beforeCreate": CommentBeforeCreateHandler; "comment:moderate": CommentModerateHandler; "comment:afterCreate": CommentAfterCreateHandler; "comment:afterModerate": CommentAfterModerateHandler; "page:metadata": PageMetadataHandler; "page:fragments": PageFragmentHandler; } /** * Hook-handler config form. The bare-function form is also accepted * (see `HookEntry`) — this is the long form that lets authors override * priority, timeout, exclusivity. `errorPolicy` and `dependencies` are * read by the host but rarely set by authors. */ interface HookConfig { handler: HookHandlers[K]; priority?: number; timeout?: number; dependencies?: string[]; errorPolicy?: "continue" | "abort"; exclusive?: boolean; } /** * Either a bare handler or the config form. The build probe accepts * both shapes and the runtime normalises to the config form before * dispatch. */ type HookEntry = HookHandlers[K] | HookConfig; /** * Request fields a route handler can rely on across both trusted and * sandboxed execution. Trusted handlers receive a real `Request` * (which is structurally compatible — has `url`, `method`, `headers`); * sandboxed handlers receive a serialised `{ url, method, headers }` * record because Worker Loader can't pass `Request` objects across * the boundary. The shared shape is what's actually portable. * * `headers` is intentionally `Record` rather than * `Headers` so the sandboxed serialised form (which is a plain * record) typechecks. Trusted handlers receiving a real `Headers` * object can still call `.get(...)`, but reading via this type's * indexing requires the lookup to be lowercased and exact. Authors * iterating headers in a portable way should use `Object.entries`. */ interface SandboxedRequest { url: string; method: string; headers: Record; } /** * Context passed to a route handler. Routes get an extra `routeCtx` * argument with the call-site input + the originating request, in * addition to the standard `PluginContext`. * * `input` is `unknown` because plugins validate it themselves — no * central schema for route payloads. */ interface SandboxedRouteContext { input: unknown; request: SandboxedRequest; requestMeta?: unknown; /** * Authenticated caller, if the route is private. Resolved and * authorized by the host before dispatch — trust it over any user id * in the request body. `undefined` for public routes and for machine * tokens with no bound user. */ user?: UserInfo; } /** * Route handler. The two-arg shape (`routeCtx`, `pluginCtx`) matches * how the standard-format runtime invokes routes — distinct from * native plugins, where routes take a single context with the input * merged in. * * Return type is `unknown` because routes serialise their return value * to JSON for the caller; authors define their own response shape. */ type RouteHandler = (routeCtx: SandboxedRouteContext, ctx: PluginContext) => Promise; /** * Route entry — either a bare handler or the config form with * `public`, `input` schema, and so on. The build probe accepts both. */ type RouteEntry = RouteHandler | { handler: RouteHandler; public?: boolean; /** * Cache-Control value for successful GET responses. Only honored on * routes that are also `public: true` — authenticated responses * always keep `private, no-store`. */ cacheControl?: string; input?: unknown; permission?: Permission; }; interface SandboxedMcpTool { description: string; route: string; input: ZodType; output?: ZodType; destructive?: boolean; } /** * The shape of a sandboxed plugin's default export. * * Both `hooks` and `routes` are optional — a plugin that only declares * one is valid. Hook keys are constrained to the runtime's hook * vocabulary so a typo (`"content:beforSave"`) is a compile error. * Route keys are open because route names are author-chosen URL path * segments. */ interface SandboxedPlugin { hooks?: { [K in keyof HookHandlers]?: HookEntry }; routes?: Record; mcp?: { tools: Record; }; } //#endregion export { type AgentCallbackSpec, type AgentMcpServerSpec, type AgentRunSpec, type AgentSessionSpec, type AgentSkillSpec, type AgentsAccess, type CommentAfterCreateEvent, type CommentAfterModerateEvent, type CommentBeforeCreateEvent, type CommentModerateEvent, type ContentDeleteEvent, type ContentHookEvent, type ContentPublishStateChangeEvent, type ContentRestoreStateChangeEvent, type ContentScheduleStateChangeEvent, type ContentStateChangeEvent, type CronEvent, type EmailAfterSendEvent, type EmailBeforeSendEvent, type EmailDeliverEvent, HookConfig, HookEntry, HookHandlers, type LifecycleEvent, type MediaAfterUploadEvent, type MediaUploadEvent, type PageFragmentEvent, type PageMetadataEvent, type PluginContext, RouteEntry, RouteHandler, type SandboxAccess, type SandboxBuildSpec, SandboxedMcpTool, SandboxedPlugin, SandboxedRequest, SandboxedRouteContext, type UninstallEvent }; //# sourceMappingURL=plugin-types.d.mts.map