UNPKG

@persona/layout-editor-remote-module

Version:

Shared manifest format, Vite plugin, and host/iframe bridge for remotely-defined dashboard layout modules in Persona dashboard apps.

101 lines (99 loc) • 4.64 kB
import { a as JsonSchemaObject, c as ModuleCategory, d as RemoteModuleRegistrationManifestV1Schema, f as remoteModuleRegistrationManifestV1Schema, i as Json, l as RemoteModuleDelivery, n as LayoutModuleEntry, o as LayoutType, r as defineLayoutModule, s as ModuleBadge, t as LayoutModuleDefinitionInput, u as RemoteModuleRegistrationManifestV1 } from "./define-BnDRhao0.mjs"; import { z } from "zod"; //#region src/manifest-path.d.ts /** * Default path (site-root-relative) the manifest document is served from and * written to, when `PersonaLayoutModulesOptions.manifestPath` isn't * overridden. A standalone module (rather than living in vite-plugin.ts, the * one place that actually uses it) so it can also be re-exported from the * runtime-safe `.` entry — a consumer wiring up something like CORS for the * manifest route in its own server, outside of vite.config.ts, needs this * default without pulling in Vite. */ declare const DEFAULT_MANIFEST_PATH = "/_layout_modules_manifest.json"; //#endregion //#region src/parse.d.ts /** * The document the Vite plugin emits at `manifestPath` (and serves from the * dev server): every module the app declares, under a single `modules` key. */ interface RemoteModuleManifestDocument { modules: RemoteModuleRegistrationManifestV1[]; } /** * Module keys must be unique within one document — a consumer identifies a * module as `${sourceId}/${key}`, so a duplicate would collide. The plugin * already refuses to build such an app; re-checked here so a hand-written or * tampered manifest can't slip one through. */ declare const remoteModuleManifestDocumentSchema: z.ZodObject<{ modules: z.ZodArray<z.ZodObject<{ allowAddingToLayout: z.ZodBoolean; allowDynamicHeight: z.ZodOptional<z.ZodBoolean>; badge: z.ZodOptional<z.ZodEnum<{ beta: "beta"; deprecated: "deprecated"; improved: "improved"; new: "new"; }>>; category: z.ZodOptional<z.ZodEnum<{ build_your_own: "build_your_own"; components: "components"; management: "management"; related_records: "related_records"; }>>; categoryCustom: z.ZodOptional<z.ZodString>; configSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; defaultConfig: z.ZodOptional<z.ZodRecord<z.ZodEnum<{ account: "account"; case: "case"; transaction: "transaction"; }> & z.core.$partial, z.ZodRecord<z.ZodString, z.ZodUnknown>>>; defaultSize: z.ZodRecord<z.ZodEnum<{ account: "account"; case: "case"; transaction: "transaction"; }> & z.core.$partial, z.ZodObject<{ height: z.ZodNumber; width: z.ZodNumber; }, z.core.$strip>>; descriptionShort: z.ZodString; displayName: z.ZodString; icon: z.ZodOptional<z.ZodString>; internalUsersOnly: z.ZodOptional<z.ZodBoolean>; key: z.ZodString; layouts: z.ZodDefault<z.ZodArray<z.ZodEnum<{ account: "account"; case: "case"; transaction: "transaction"; }>>>; manifestVersion: z.ZodLiteral<"v1">; remote: z.ZodObject<{ render: z.ZodObject<{ document: z.ZodString; }, z.core.$strip>; }, z.core.$strip>; uiConfigSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; }, z.core.$strip>>; }, z.core.$strip>; type RemoteModuleManifestParseResult = { data: RemoteModuleManifestDocument; success: true; } | { error: RemoteModuleManifestParseError; success: false; }; declare class RemoteModuleManifestParseError extends Error { readonly issues: z.core.$ZodIssue[]; constructor(error: z.ZodError); } /** * Validate the raw JSON of a manifest document (e.g. `await response.json()`) * and return it typed. Throws `RemoteModuleManifestParseError` if the document * is malformed; use `safeParseRemoteModuleManifest` to get a result instead. */ declare function parseRemoteModuleManifest(json: unknown): RemoteModuleManifestDocument; /** Non-throwing variant of `parseRemoteModuleManifest`. */ declare function safeParseRemoteModuleManifest(json: unknown): RemoteModuleManifestParseResult; //#endregion export { DEFAULT_MANIFEST_PATH, type Json, type JsonSchemaObject, type LayoutModuleDefinitionInput, type LayoutModuleEntry, type LayoutType, type ModuleBadge, type ModuleCategory, type RemoteModuleDelivery, type RemoteModuleManifestDocument, RemoteModuleManifestParseError, type RemoteModuleManifestParseResult, type RemoteModuleRegistrationManifestV1, type RemoteModuleRegistrationManifestV1Schema, defineLayoutModule, parseRemoteModuleManifest, remoteModuleManifestDocumentSchema, remoteModuleRegistrationManifestV1Schema, safeParseRemoteModuleManifest };