@cervio/plugin-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -0
- package/dist/index.cjs +274 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +442 -0
- package/dist/index.d.ts +442 -0
- package/dist/index.js +256 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cervio-ui.ts","../src/context.ts","../src/theme.ts","../src/client.ts","../src/i18n.ts"],"names":["opts"],"mappings":";AAQO,IAAM,qBAAA,GAAwB;AA8G9B,SAAS,WAAA,GAAwB;AACtC,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,CAAC,OAAO,QAAA,EAAU;AACrD,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,MAAA,CAAO,QAAA;AAChB;AAGO,SAAS,mBAAA,GAA+B;AAC7C,EAAA,OAAO,OAAO,MAAA,KAAW,WAAA,IAAe,CAAC,CAAC,MAAA,CAAO,QAAA;AACnD;;;ACvEO,SAAS,gBAAA,GAA+C;AAC7D,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,EAAa,OAAO,IAAA;AAC1C,EAAA,OAAO,OAAO,yBAAA,IAA6B,IAAA;AAC7C;AAGO,SAAS,qBAAA,GAAiC;AAC/C,EAAA,OAAO,kBAAiB,IAAK,IAAA;AAC/B;AAMO,SAAS,iBAAiB,GAAA,EAAsB;AACrD,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,OAAO,MAAA,CAAO,6BAA6B,UAAA,EAAY;AAC1F,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,MAAA,CAAO,yBAAyB,GAAG,CAAA;AAC5C;;;ACtDA,SAAS,mBAAmB,IAAA,EAA+C;AACzE,EAAA,OACE,CAAC,CAAC,IAAA,IACF,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mBAAA,CAAoB,EAAE,kBAAkB,aAAA,EAAe,IAAA,CAAK,eAAe,CAAA;AAC1F,EAAA,MAAM,IAAA,GAAO,IAAA,CAAK,QAAA,CAAS,MAAM,CAAA,IAAK,KAAK,QAAA,CAAS,IAAA,CAAK,aAAa,CAAA,IAAK,EAAC;AAC5E,EAAA,MAAM,aAAa,EAAE,GAAG,mBAAA,EAAqB,GAAG,KAAK,UAAA,EAAW;AAEhE,EAAA,SAAS,CAAA,CAAE,KAAa,IAAA,EAAgD;AACtE,IAAA,MAAM,GAAA,GAAM,cAAA,CAAe,IAAA,EAAM,GAAG,CAAA;AACpC,IAAA,IAAI,GAAA,GAAM,OAAO,GAAA,KAAQ,QAAA,GAAW,GAAA,GAAM,GAAA;AAC1C,IAAA,IAAI,IAAA,EAAM;AACR,MAAA,KAAA,MAAW,CAAC,CAAA,EAAG,CAAC,KAAK,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,EAAG;AACzC,QAAA,GAAA,GAAM,IAAI,UAAA,CAAW,CAAA,CAAA,EAAI,CAAC,CAAA,CAAA,CAAA,EAAK,MAAA,CAAO,CAAC,CAAC,CAAA;AAAA,MAC1C;AAAA,IACF;AACA,IAAA,OAAO,GAAA;AAAA,EACT;AAEA,EAAA,SAAS,SAAA,CAAU,IAAY,MAAA,EAAgB;AAC7C,IAAA,OAAO,UAAA,CAAW,CAAC,CAAA,IAAK,CAAA;AAAA,EAC1B;AAEA,EAAA,OAAO,EAAE,MAAA,EAAQ,gBAAA,EAAkB,CAAA,EAAG,SAAA,EAAU;AAClD","file":"index.js","sourcesContent":["/**\n * Publishable typed client mirroring `window.CervioUI` injected by the Cervio host.\n * Docs: Admin → Plugins → UI components (`/admin/plugins/components`) and `docs/plugins/ui/`.\n *\n * `CERVIO_UI_API_VERSION` tracks the host `window.CervioUI.apiVersion` contract —\n * this package's own version is kept in lockstep with it (see package.json).\n */\n\nexport const CERVIO_UI_API_VERSION = '1.0.0' as const\n\nexport type CervioUiToastType = 'success' | 'error' | 'warning' | 'info'\nexport type CervioUiDialogVariant = 'default' | 'destructive'\nexport type CervioUiFrameSize = 'sm' | 'md' | 'lg' | 'full'\n\nexport interface CervioUiSelectOption {\n value: string\n label: string\n}\n\nexport interface CervioUiToastOptions {\n type?: CervioUiToastType\n message: string\n}\n\nexport interface CervioUiConfirmOptions {\n title: string\n description: string\n confirmLabel?: string\n cancelLabel?: string\n variant?: CervioUiDialogVariant\n}\n\nexport interface CervioUiAlertOptions {\n title: string\n description: string\n okLabel?: string\n}\n\nexport interface CervioUiFrameOpenOptions {\n title?: string\n size?: CervioUiFrameSize\n showClose?: boolean\n}\n\nexport interface CervioUiSurfaceOpenOptions extends CervioUiFrameOpenOptions {\n /** Plain JSON forwarded to `dist/surface.html` on open (max ~64KB). */\n params?: unknown\n}\n\nexport interface CervioUiSelectOpenOptions {\n options: CervioUiSelectOption[]\n value?: string\n searchable?: boolean\n placeholder?: string\n emptyText?: string\n}\n\nexport interface CervioUiFrameSlot {\n left: number\n top: number\n width: number\n height: number\n headerHeight: number\n}\n\nexport interface CervioUiThemeSnapshot {\n tokens: Record<string, string>\n colorScheme: 'dark' | 'light'\n}\n\nexport interface CervioUI {\n apiVersion: typeof CERVIO_UI_API_VERSION\n capabilities(): Promise<string[]>\n toast(opts: CervioUiToastOptions): Promise<{ ok: true }>\n dialog: {\n confirm(opts: CervioUiConfirmOptions): Promise<boolean>\n alert(opts: CervioUiAlertOptions): Promise<true>\n frame: {\n /** Sync cached slot (null if host has not pushed dialog.frame.slots yet). */\n slot?(size?: 'sm' | 'md' | 'lg' | 'full'): CervioUiFrameSlot | null\n open(opts?: CervioUiFrameOpenOptions): Promise<{ open: true; slot: CervioUiFrameSlot }>\n update(opts: { title?: string }): Promise<{ ok: true }>\n close(): Promise<{ ok: true }>\n }\n /** Recommended for custom modals: host Dialog + body from dist/surface.html. */\n surface: {\n open(opts?: CervioUiSurfaceOpenOptions): Promise<{ open: true }>\n update(opts: { title?: string }): Promise<{ ok: true }>\n close(): Promise<{ ok: true }>\n /** Relay plain JSON to the other iframe (page ↔ surface). */\n post(data: unknown): Promise<{ ok: true }>\n }\n }\n backdrop: {\n set(open: boolean): Promise<{ open: boolean }>\n }\n select: {\n open(opts: CervioUiSelectOpenOptions): Promise<string | null>\n }\n combobox: {\n open(opts: CervioUiSelectOpenOptions): Promise<string | null>\n }\n /** Last host theme push (null until first `__cervioPluginTheme` message). Applied automatically by inject script. */\n theme: {\n get(): CervioUiThemeSnapshot | null\n }\n}\n\ndeclare global {\n interface Window {\n CervioUI?: CervioUI\n }\n}\n\n/**\n * Returns `window.CervioUI`, throwing when it is not present (e.g. running\n * outside the Cervio sandbox host, or in a plain browser tab for local dev).\n */\nexport function getCervioUI(): CervioUI {\n if (typeof window === 'undefined' || !window.CervioUI) {\n throw new Error(\n 'CervioUI is not available. Route plugins must run inside the Cervio sandbox host.',\n )\n }\n return window.CervioUI\n}\n\n/** True when the host has injected `window.CervioUI` (srcDoc sandbox). */\nexport function isCervioUIAvailable(): boolean {\n return typeof window !== 'undefined' && !!window.CervioUI\n}\n\nexport type CervioUiFrameMetricsEvent = {\n __cervioUI: 1\n event: 'dialog.frame.metrics'\n open: boolean\n title?: string\n size?: CervioUiFrameSize\n showClose?: boolean\n slot?: CervioUiFrameSlot\n}\n\nexport type CervioUiFrameClosedEvent = {\n __cervioUI: 1\n event: 'dialog.frame.closed'\n reason: 'host' | 'plugin' | 'escape'\n}\n\nexport type CervioUiSurfaceOpenedEvent = {\n __cervioUI: 1\n event: 'dialog.surface.opened'\n params?: unknown\n}\n\nexport type CervioUiSurfaceMessageEvent = {\n __cervioUI: 1\n event: 'dialog.surface.message'\n data: unknown\n from: 'page' | 'surface'\n}\n\nexport type CervioUiSurfaceClosedEvent = {\n __cervioUI: 1\n event: 'dialog.surface.closed'\n reason: 'host' | 'plugin' | 'escape'\n}\n\nexport type CervioUiHostEvent =\n | CervioUiFrameMetricsEvent\n | CervioUiFrameClosedEvent\n | CervioUiSurfaceOpenedEvent\n | CervioUiSurfaceMessageEvent\n | CervioUiSurfaceClosedEvent\n","/**\n * Typed access to `window.__CERVIO_PLUGIN_CONTEXT__`, the boot payload the\n * Cervio host injects into every route plugin `srcDoc` iframe.\n *\n * Docs: `docs/plugins/AUTHORING.md` (\"Auth inside the iframe\", \"Plugin i18n /\n * locale\"). Field shape is set by `components/plugins/plugin-route-sandbox-host.tsx`.\n */\n\nexport interface CervioPluginRuntimeSettings {\n /** Locales this plugin install may use (Admin → Plugins → Impostazioni). */\n availableLocales?: string[]\n /** Used when the host locale is not in `availableLocales`. */\n fallbackLocale?: string\n [key: string]: unknown\n}\n\nexport interface CervioPluginContext {\n /** Route slug the plugin was mounted under. */\n routeSlug?: string\n /** Per-menu-item config attached via `menu_items.plugin_context`. */\n pluginContext?: Record<string, unknown> | null\n previewMode?: boolean\n /** Logged-in Cervio UI locale (`NEXT_LOCALE`): `'it' | 'en'`. */\n locale?: string\n /** Alias of `locale` kept for backward compatibility with early bootstraps. */\n userLocale?: string\n mountedAt?: string\n /**\n * Real app origin — always set by the host. Use this for API base URLs.\n * Never use `window.location.origin`: in sandboxed `srcDoc` iframes it\n * frequently serializes as the literal string `\"null\"`.\n */\n parentOrigin?: string\n /** Parent page pathname (the iframe's own `location` is opaque). */\n parentPath?: string\n /** Parent page search string, including leading `?` when present. */\n parentSearch?: string\n /** Full parent `href`, for deep-linking. */\n parentHref?: string\n pluginVersion?: string | null\n pluginArtifactSha256?: string | null\n pluginKey?: string | null\n /** Whether the host is caching this route's `srcDoc` across soft navigations. */\n artifactCacheEnabled?: boolean\n runtimeSettings?: CervioPluginRuntimeSettings\n /** Present only inside `dist/surface.html` (dialog.surface body iframe). */\n cervioSurface?: boolean\n [key: string]: unknown\n}\n\ndeclare global {\n interface Window {\n __CERVIO_PLUGIN_CONTEXT__?: CervioPluginContext\n /** Host-mediated top-level navigation (OAuth consent, cross-plugin deep links). */\n __cervioOpenExternalAuth?: (url: string) => boolean\n }\n}\n\n/** Returns the host boot payload, or `null` outside the Cervio sandbox. */\nexport function getPluginContext(): CervioPluginContext | null {\n if (typeof window === 'undefined') return null\n return window.__CERVIO_PLUGIN_CONTEXT__ ?? null\n}\n\n/** True when running inside a Cervio route plugin sandbox iframe. */\nexport function isInsideCervioSandbox(): boolean {\n return getPluginContext() != null\n}\n\n/**\n * Navigate the real app window (top-level). Required for OAuth consent and\n * cross-plugin deep links: the sandboxed iframe cannot navigate `window.top`.\n */\nexport function openExternalAuth(url: string): boolean {\n if (typeof window === 'undefined' || typeof window.__cervioOpenExternalAuth !== 'function') {\n return false\n }\n return window.__cervioOpenExternalAuth(url)\n}\n","/**\n * Typed wrapper around the host's `__cervioPluginTheme` postMessage push.\n * The CervioUI inject script already applies host tokens to `document`\n * automatically (`var(--background)`, etc.) — use this only when your plugin\n * needs to *react* to a theme change in JS (e.g. re-render a canvas/chart).\n */\n\nimport { getCervioUI } from './cervio-ui'\n\nexport type CervioColorScheme = 'dark' | 'light'\n\nexport interface CervioHostThemeMessage {\n __cervioPluginTheme: 1\n tokens: Record<string, string>\n colorScheme: CervioColorScheme\n}\n\nexport interface CervioThemeSnapshot {\n tokens: Record<string, string>\n colorScheme: CervioColorScheme\n}\n\nexport type CervioThemeChangeHandler = (theme: CervioThemeSnapshot) => void\n\nfunction isHostThemeMessage(data: unknown): data is CervioHostThemeMessage {\n return (\n !!data &&\n typeof data === 'object' &&\n (data as { __cervioPluginTheme?: unknown }).__cervioPluginTheme === 1\n )\n}\n\n/**\n * Subscribe to host theme pushes. Returns an unsubscribe function.\n * Fires immediately with the last known theme (from `CervioUI.theme.get()`)\n * when available, then on every subsequent host theme change.\n */\nexport function onThemeChange(handler: CervioThemeChangeHandler): () => void {\n if (typeof window === 'undefined') return () => {}\n\n const current = getCurrentTheme()\n if (current) handler(current)\n\n const listener = (event: MessageEvent) => {\n if (!isHostThemeMessage(event.data)) return\n handler({\n tokens: event.data.tokens ?? {},\n colorScheme: event.data.colorScheme === 'dark' ? 'dark' : 'light',\n })\n }\n window.addEventListener('message', listener)\n return () => window.removeEventListener('message', listener)\n}\n\n/** Last theme snapshot applied by the CervioUI inject script, if any. */\nexport function getCurrentTheme(): CervioThemeSnapshot | null {\n if (typeof window === 'undefined' || !window.CervioUI) return null\n try {\n return getCervioUI().theme.get()\n } catch {\n return null\n }\n}\n","/**\n * Typed fetch wrapper around the Cervio v1 REST API (`/api/v1/*`) for route\n * plugins and external scripts.\n *\n * Two flavors:\n * - `createCervioClient` — Bearer token (PAT / OAuth2 access token).\n * - `createCervioSessionClient` — same-origin session cookies (typical when\n * running inside the Cervio app shell iframe).\n *\n * Both resolve a missing `baseUrl` from `__CERVIO_PLUGIN_CONTEXT__.parentOrigin`\n * — **never** from `window.location.origin`, which frequently serializes as\n * the literal string `\"null\"` inside a sandboxed `srcDoc` iframe.\n */\n\nimport { getPluginContext } from './context'\n\nexport interface Identity {\n user_id: string\n organization_id: string\n auth_method: 'pat' | 'oauth2' | 'supabase_jwt' | 'session'\n}\n\nexport interface Entity {\n id: string\n name: string\n label: string\n description: string | null\n document_management_enabled: boolean\n}\n\nexport interface EntityCapabilities {\n can_read: boolean\n can_create: boolean\n can_update: boolean\n can_delete: boolean\n can_export: boolean\n}\n\nexport interface EntityRecord {\n id: string\n entity_id: string\n data: Record<string, unknown>\n}\n\nexport class CervioApiError extends Error {\n constructor(\n public readonly status: number,\n public readonly code: string,\n message: string,\n ) {\n super(message)\n this.name = 'CervioApiError'\n }\n}\n\n/**\n * Resolve an API base URL: explicit value wins, otherwise\n * `__CERVIO_PLUGIN_CONTEXT__.parentOrigin`. Throws rather than silently\n * falling back to `location.origin` (which breaks inside `srcDoc` sandboxes).\n */\nexport function resolveApiBaseUrl(explicitBaseUrl?: string): string {\n const explicit = explicitBaseUrl?.trim()\n if (explicit) return explicit.replace(/\\/$/, '')\n\n const parentOrigin = getPluginContext()?.parentOrigin?.trim()\n if (parentOrigin && parentOrigin !== 'null') {\n return parentOrigin.replace(/\\/$/, '')\n }\n\n throw new Error(\n 'Unable to resolve the Cervio API base URL. Pass { baseUrl } explicitly, or run ' +\n 'inside the Cervio plugin sandbox so window.__CERVIO_PLUGIN_CONTEXT__.parentOrigin ' +\n 'is set. Do not fall back to window.location.origin.',\n )\n}\n\nasync function parseJsonSafe(res: Response): Promise<Record<string, unknown>> {\n try {\n return (await res.json()) as Record<string, unknown>\n } catch {\n return {}\n }\n}\n\nfunction throwIfNotOk(res: Response, body: Record<string, unknown>): void {\n if (res.ok) return\n const code = typeof body.error === 'string' ? body.error : 'http_error'\n const message = typeof body.message === 'string' ? body.message : res.statusText\n throw new CervioApiError(res.status, code, message)\n}\n\nexport type CervioClientOptions = {\n /** Defaults to `__CERVIO_PLUGIN_CONTEXT__.parentOrigin` when omitted. */\n baseUrl?: string\n /** PAT (`cpat_…`) or OAuth2 access token. Read-only on writes for PAT. */\n token: string\n fetchImpl?: typeof fetch\n}\n\nexport type CervioSessionClientOptions = {\n /** Defaults to `__CERVIO_PLUGIN_CONTEXT__.parentOrigin` when omitted. */\n baseUrl?: string\n fetchImpl?: typeof fetch\n}\n\nexport type ExternalConnectionStatus = {\n connection_id: string\n provider: string\n connector_key: string\n configured: boolean\n connected: boolean\n account_email: string | null\n scopes: string[]\n allowed_apis: unknown\n}\n\nexport type ExternalProxyInput = {\n /** Required when the manifest requirement allows more than one API host. */\n host?: string\n method: string\n path: string\n query?: Record<string, string>\n headers?: Record<string, string>\n body?: unknown\n}\n\nfunction buildRecordsQuery(opts?: { limit?: number; offset?: number }): string {\n const params = new URLSearchParams()\n if (opts?.limit != null) params.set('limit', String(opts.limit))\n if (opts?.offset != null) params.set('offset', String(opts.offset))\n const qs = params.toString()\n return qs ? `?${qs}` : ''\n}\n\n/** Bearer-authenticated client (PAT / OAuth2 access token). */\nexport function createCervioClient(opts: CervioClientOptions) {\n const fetchImpl = opts.fetchImpl ?? fetch\n const baseUrl = resolveApiBaseUrl(opts.baseUrl)\n\n async function request<T>(path: string): Promise<T> {\n const res = await fetchImpl(`${baseUrl}${path}`, {\n headers: {\n Authorization: `Bearer ${opts.token}`,\n Accept: 'application/json',\n },\n })\n const body = await parseJsonSafe(res)\n throwIfNotOk(res, body)\n return body as T\n }\n\n return {\n me: () => request<Identity>('/api/v1/me'),\n listEntities: () => request<{ entities: Entity[] }>('/api/v1/entities'),\n getEntity: (entityId: string) => request<{ entity: Entity }>(`/api/v1/entities/${entityId}`),\n getCapabilities: (entityId: string) =>\n request<{ entity_id: string; capabilities: EntityCapabilities }>(\n `/api/v1/entities/${entityId}/capabilities`,\n ),\n listRecords: (entityId: string, opts?: { limit?: number; offset?: number }) =>\n request<{ records: EntityRecord[] }>(\n `/api/v1/entities/${entityId}/records${buildRecordsQuery(opts)}`,\n ),\n }\n}\n\nexport type CervioClient = ReturnType<typeof createCervioClient>\n\n/** Same-origin session cookie auth (typical inside the Cervio shell iframe). */\nexport function createCervioSessionClient(opts: CervioSessionClientOptions = {}) {\n const fetchImpl = opts.fetchImpl ?? fetch\n const baseUrl = resolveApiBaseUrl(opts.baseUrl)\n\n async function request<T>(path: string): Promise<T> {\n const res = await fetchImpl(`${baseUrl}${path}`, {\n credentials: 'include',\n headers: { Accept: 'application/json' },\n })\n const body = await parseJsonSafe(res)\n throwIfNotOk(res, body)\n return body as T\n }\n\n return {\n me: () => request<Identity>('/api/v1/me'),\n listEntities: () => request<{ entities: Entity[] }>('/api/v1/entities'),\n getEntity: (entityId: string) => request<{ entity: Entity }>(`/api/v1/entities/${entityId}`),\n getCapabilities: (entityId: string) =>\n request<{ entity_id: string; capabilities: EntityCapabilities }>(\n `/api/v1/entities/${entityId}/capabilities`,\n ),\n listRecords: (entityId: string, opts?: { limit?: number; offset?: number }) =>\n request<{ records: EntityRecord[] }>(\n `/api/v1/entities/${entityId}/records${buildRecordsQuery(opts)}`,\n ),\n /** External Connections — requires admin bind + `X-Cervio-Plugin-Key` (host injects on relay). */\n connectionStatus: (connectionId: string) =>\n request<ExternalConnectionStatus>(\n `/api/v1/plugins/connections/${encodeURIComponent(connectionId)}/status`,\n ),\n connectionStart: (connectionId: string, returnTo?: string) => {\n const qs = returnTo ? `?return_to=${encodeURIComponent(returnTo)}` : ''\n return request<{ authorizeUrl?: string; message?: string }>(\n `/api/v1/plugins/connections/${encodeURIComponent(connectionId)}/start${qs}`,\n )\n },\n connectionProxy: async <T = unknown>(\n connectionId: string,\n input: ExternalProxyInput,\n ): Promise<T> => {\n const res = await fetchImpl(\n `${baseUrl}/api/v1/plugins/connections/${encodeURIComponent(connectionId)}/proxy`,\n {\n method: 'POST',\n credentials: 'include',\n headers: { Accept: 'application/json', 'Content-Type': 'application/json' },\n body: JSON.stringify(input),\n },\n )\n const body = await parseJsonSafe(res)\n throwIfNotOk(res, body)\n return body as T\n },\n }\n}\n\nexport type CervioSessionClient = ReturnType<typeof createCervioSessionClient>\n\n/** Ensure user OAuth for an External Connection; opens top-level consent when needed. */\nexport async function ensureExternalConnection(\n api: {\n connectionStatus: (id: string) => Promise<ExternalConnectionStatus>\n connectionStart: (id: string, returnTo?: string) => Promise<{ authorizeUrl?: string; message?: string }>\n },\n connectionId: string,\n returnTo?: string,\n): Promise<ExternalConnectionStatus | null> {\n const st = await api.connectionStatus(connectionId)\n if (st.connected) return st\n const start = await api.connectionStart(connectionId, returnTo)\n if (!start.authorizeUrl) {\n throw new CervioApiError(501, 'start_failed', start.message || 'OAuth start failed')\n }\n if (typeof window !== 'undefined' && typeof window.__cervioOpenExternalAuth === 'function') {\n window.__cervioOpenExternalAuth(start.authorizeUrl)\n } else if (typeof window !== 'undefined') {\n window.top!.location.href = start.authorizeUrl\n }\n return null\n}\n\nconst DEFAULT_PAGE = 500\n\nexport type CervioListRecordsClient = {\n listRecords: (entityId: string, opts?: { limit?: number; offset?: number }) => Promise<{ records: EntityRecord[] }>\n}\n\n/** Total visible records for the caller (paginates until exhausted; cap 200k). */\nexport async function countVisibleRecords(\n api: CervioListRecordsClient,\n entityId: string,\n pageSize: number = DEFAULT_PAGE,\n): Promise<number> {\n let total = 0\n let offset = 0\n const maxRows = 200_000\n for (;;) {\n const { records } = await api.listRecords(entityId, { limit: pageSize, offset })\n total += records.length\n if (records.length < pageSize) break\n offset += pageSize\n if (offset >= maxRows) break\n }\n return total\n}\n\n/** Find an entity by technical name (case-insensitive) — prefer names over hard-coded UUIDs. */\nexport function findEntityByName(entities: Entity[], technicalName: string): Entity | undefined {\n const n = technicalName.toLowerCase()\n return entities.find((e) => e.name.toLowerCase() === n)\n}\n","/**\n * Minimal i18n helper for route plugins. Route plugins run in a sandboxed\n * `srcDoc` iframe: next-intl / `public/locales` are not available, so ship\n * your own catalogs in the ZIP and resolve the active locale from the host\n * bootstrap. See `docs/plugins/AUTHORING.md` → \"Plugin i18n / locale\".\n *\n * Resolve order (mandatory):\n * 1. host locale (`__CERVIO_PLUGIN_CONTEXT__.locale`), if enabled for this plugin\n * 2. `runtimeSettings.fallbackLocale`\n * 3. plugin default locale\n */\n\nimport { getPluginContext } from './context'\n\nexport type CervioI18nMessages = Record<string, unknown>\nexport type CervioI18nCatalog = Record<string, CervioI18nMessages>\n\nconst DEFAULT_LOCALE_TAGS: Record<string, string> = {\n it: 'it-IT',\n en: 'en-GB',\n es: 'es-ES',\n fr: 'fr-FR',\n de: 'de-DE',\n}\n\nexport interface ResolvePluginLocaleOptions {\n /** Locales this plugin ships (message keys must exist for each). */\n availableLocales: string[]\n defaultLocale: string\n}\n\n/** Resolve order only — does not read message catalogs. */\nexport function resolvePluginLocale(opts: ResolvePluginLocaleOptions): string {\n const ctx = getPluginContext()\n const hostLocale = ctx?.locale ?? ctx?.userLocale\n const runtimeAvailable = ctx?.runtimeSettings?.availableLocales\n const runtimeAllowed =\n Array.isArray(runtimeAvailable) && runtimeAvailable.length > 0 ? runtimeAvailable : null\n\n if (\n hostLocale &&\n opts.availableLocales.includes(hostLocale) &&\n (!runtimeAllowed || runtimeAllowed.includes(hostLocale))\n ) {\n return hostLocale\n }\n\n const fallback = ctx?.runtimeSettings?.fallbackLocale\n if (fallback && opts.availableLocales.includes(fallback)) return fallback\n\n return opts.defaultLocale\n}\n\nfunction getNestedValue(obj: unknown, path: string): unknown {\n return path.split('.').reduce<unknown>((acc, key) => {\n if (acc && typeof acc === 'object' && key in (acc as Record<string, unknown>)) {\n return (acc as Record<string, unknown>)[key]\n }\n return undefined\n }, obj)\n}\n\nexport interface CreateI18nOptions {\n /** `{ it: { toolbar: { newEntry: '...' } }, en: { ... } }` — identical key sets. */\n messages: CervioI18nCatalog\n defaultLocale: string\n /** Defaults to `Object.keys(messages)`. */\n availableLocales?: string[]\n /** Override `Intl` locale tags (e.g. `{ it: 'it-IT' }`). */\n localeTags?: Record<string, string>\n}\n\nexport interface CervioI18n {\n locale: string\n availableLocales: string[]\n /** Dot-path lookup (`'toolbar.newEntry'`) with `{placeholder}` interpolation. */\n t: (key: string, vars?: Record<string, string | number>) => string\n /** `Intl`-ready BCP 47 tag for `Intl.DateTimeFormat` / `Intl.NumberFormat`. */\n localeTag: (locale?: string) => string\n}\n\n/** Build a small `t()` + locale resolver from bundled catalogs. */\nexport function createI18n(opts: CreateI18nOptions): CervioI18n {\n const availableLocales = opts.availableLocales ?? Object.keys(opts.messages)\n const locale = resolvePluginLocale({ availableLocales, defaultLocale: opts.defaultLocale })\n const dict = opts.messages[locale] ?? opts.messages[opts.defaultLocale] ?? {}\n const localeTags = { ...DEFAULT_LOCALE_TAGS, ...opts.localeTags }\n\n function t(key: string, vars?: Record<string, string | number>): string {\n const raw = getNestedValue(dict, key)\n let out = typeof raw === 'string' ? raw : key\n if (vars) {\n for (const [k, v] of Object.entries(vars)) {\n out = out.replaceAll(`{${k}}`, String(v))\n }\n }\n return out\n }\n\n function localeTag(l: string = locale): string {\n return localeTags[l] ?? l\n }\n\n return { locale, availableLocales, t, localeTag }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cervio/plugin-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Typed client + runtime helpers for Cervio route plugins: CervioUI, plugin context, theme sync, and i18n. Tracks CERVIO_UI_API_VERSION.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^22.15.0",
|
|
22
|
+
"jsdom": "^29.1.1",
|
|
23
|
+
"tsup": "^8.5.0",
|
|
24
|
+
"typescript": "^5.8.3",
|
|
25
|
+
"vitest": "^3.2.4"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"license": "UNLICENSED",
|
|
31
|
+
"keywords": [
|
|
32
|
+
"cervio",
|
|
33
|
+
"plugin",
|
|
34
|
+
"sdk"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup --config tsup.config.ts",
|
|
38
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
39
|
+
"test": "vitest run"
|
|
40
|
+
}
|
|
41
|
+
}
|