@cervio/plugin-sdk 2.0.0 → 2.0.1
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 +43 -9
- package/dist/index.d.ts +20 -24
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
# @cervio/plugin-sdk
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
client, host theme sync, and a tiny i18n resolver.
|
|
3
|
+
The SDK for Cervio plugins: the `CervioUI` client, the plugin context, the `/api/v1`
|
|
4
|
+
HTTP client, host theme sync, i18n, a PDF viewer and the helpers for write-gate plugins.
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
Start a new plugin with `npm create @cervio/plugin`: the templates come with this
|
|
7
|
+
package wired in.
|
|
9
8
|
|
|
10
9
|
```bash
|
|
11
|
-
|
|
10
|
+
npm install @cervio/plugin-sdk
|
|
12
11
|
```
|
|
13
12
|
|
|
13
|
+
ESM only, no dependencies at runtime for the root entry.
|
|
14
|
+
|
|
15
|
+
| Entry | For | Contents |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| `@cervio/plugin-sdk` | route and task plugins (iframe) | CervioUI, context, HTTP clients, `markReady`, theme, i18n |
|
|
18
|
+
| `@cervio/plugin-sdk/pdf` | route and task plugins with React | `PdfViewer` |
|
|
19
|
+
| `@cervio/plugin-sdk/policy` | write-gate plugins (server isolate) | `definePolicy`, `allow`, `deny`, contract types |
|
|
20
|
+
|
|
14
21
|
## Why not `location.origin`?
|
|
15
22
|
|
|
16
|
-
Route plugins run in a sandboxed iframe (`sandbox="allow-scripts"`,
|
|
23
|
+
Route and task plugins run in a sandboxed iframe (`sandbox="allow-scripts"`,
|
|
17
24
|
no `allow-same-origin`). `window.location.origin` frequently serializes as the
|
|
18
25
|
literal string `"null"` there. Always resolve the API base URL from
|
|
19
26
|
`__CERVIO_PLUGIN_CONTEXT__.parentOrigin` - every helper in this package does
|
|
@@ -117,8 +124,21 @@ i18n.t('toolbar.newEntry')
|
|
|
117
124
|
```
|
|
118
125
|
|
|
119
126
|
Resolve order: host locale (if enabled for this plugin) → `runtimeSettings.fallbackLocale`
|
|
120
|
-
→ plugin default. See [Authoring](https://docs.cervio.app/docs/authoring)
|
|
121
|
-
|
|
127
|
+
→ plugin default. See [Authoring](https://docs.cervio.app/docs/authoring), "Plugin i18n / locale",
|
|
128
|
+
for the full recipe.
|
|
129
|
+
|
|
130
|
+
## PDF viewer
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
import { PdfViewer } from '@cervio/plugin-sdk/pdf'
|
|
134
|
+
|
|
135
|
+
<PdfViewer url={documentUrl} activePage={page} onPageChange={setPage} locale="it" />
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
A separate entry, so plugins that do not show PDFs do not ship it. It needs React and
|
|
139
|
+
bundles the pdf.js worker (it works inside the sandboxed iframe, where a worker file
|
|
140
|
+
cannot be loaded by URL). `renderPageOverlay` draws your own content over the current
|
|
141
|
+
page, at its rendered size.
|
|
122
142
|
|
|
123
143
|
## Write-gate plugins (`plugin_type: policy`)
|
|
124
144
|
|
|
@@ -145,3 +165,17 @@ This package follows semver on its own. `CERVIO_UI_API_VERSION` (currently `1.0.
|
|
|
145
165
|
is the version of the `window.CervioUI` contract offered by the host, and changes
|
|
146
166
|
independently of this package's version. `@cervio/plugin-core` (manifest and ZIP
|
|
147
167
|
validation) and `@cervio/cli` also version independently.
|
|
168
|
+
|
|
169
|
+
## License
|
|
170
|
+
|
|
171
|
+
MIT, see [LICENSE](LICENSE).
|
|
172
|
+
|
|
173
|
+
**Trademark.** "Cervio" and the Cervio logo are trademarks of Cervio S.r.l. This license
|
|
174
|
+
does not grant permission to use them. You may say that a plugin "works with Cervio"; you
|
|
175
|
+
may not imply endorsement or ship a product named Cervio.
|
|
176
|
+
|
|
177
|
+
**Platform.** Using a Cervio organization is governed by your partner or customer
|
|
178
|
+
agreement, not by this license.
|
|
179
|
+
|
|
180
|
+
**Your plugins.** Plugins you write are yours: using this package gives Cervio no rights
|
|
181
|
+
over your plugin, and does not require you to open-source it.
|
package/dist/index.d.ts
CHANGED
|
@@ -465,7 +465,7 @@ declare global {
|
|
|
465
465
|
* outside the Cervio sandbox host, or in a plain browser tab for local dev).
|
|
466
466
|
*/
|
|
467
467
|
declare function getCervioUI(): CervioUI;
|
|
468
|
-
/** True when the host has injected `window.CervioUI` (
|
|
468
|
+
/** True when the host has injected `window.CervioUI` (inside the plugin iframe). */
|
|
469
469
|
declare function isCervioUIAvailable(): boolean;
|
|
470
470
|
type CervioUiFrameMetricsEvent = {
|
|
471
471
|
__cervioUI: 1;
|
|
@@ -501,10 +501,10 @@ type CervioUiHostEvent = CervioUiFrameMetricsEvent | CervioUiFrameClosedEvent |
|
|
|
501
501
|
|
|
502
502
|
/**
|
|
503
503
|
* Typed access to `window.__CERVIO_PLUGIN_CONTEXT__`, the boot payload the
|
|
504
|
-
* Cervio host injects into every route plugin
|
|
504
|
+
* Cervio host injects into every route plugin iframe.
|
|
505
505
|
*
|
|
506
506
|
* Docs: https://docs.cervio.app/docs/authoring ("Auth inside the iframe", "Plugin i18n /
|
|
507
|
-
* locale").
|
|
507
|
+
* locale").
|
|
508
508
|
*/
|
|
509
509
|
interface CervioPluginRuntimeSettings {
|
|
510
510
|
/** Locales this plugin install may use (Admin → Plugins → Impostazioni). */
|
|
@@ -526,7 +526,7 @@ interface CervioPluginContext {
|
|
|
526
526
|
mountedAt?: string;
|
|
527
527
|
/**
|
|
528
528
|
* Real app origin - always set by the host. Use this for API base URLs.
|
|
529
|
-
* Never use `window.location.origin`: in sandboxed
|
|
529
|
+
* Never use `window.location.origin`: in sandboxed iframes it
|
|
530
530
|
* frequently serializes as the literal string `"null"`.
|
|
531
531
|
*/
|
|
532
532
|
parentOrigin?: string;
|
|
@@ -571,11 +571,10 @@ declare function openExternalAuth(url: string): boolean;
|
|
|
571
571
|
declare function markReady(): void;
|
|
572
572
|
|
|
573
573
|
/**
|
|
574
|
-
* Typed access to the task-plugin boot payload
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
* with a different shape — use these helpers rather than `getPluginContext()`.
|
|
574
|
+
* Typed access to the task-plugin boot payload and the submit/draft bridge, which
|
|
575
|
+
* the Cervio host injects when a task layout shows a plugin widget. It shares the
|
|
576
|
+
* `window.__CERVIO_PLUGIN_CONTEXT__` global with route plugins (never both on one
|
|
577
|
+
* page) but has a different shape: use these helpers, not `getPluginContext()`.
|
|
579
578
|
*/
|
|
580
579
|
interface CervioTaskOutcome {
|
|
581
580
|
value: string;
|
|
@@ -586,23 +585,20 @@ interface CervioTaskPluginContextData {
|
|
|
586
585
|
workflowInstanceId: string;
|
|
587
586
|
entityDataId: string | null;
|
|
588
587
|
outcomes: CervioTaskOutcome[];
|
|
589
|
-
/**
|
|
588
|
+
/** The workflow variables the task layout exposes to this widget, never the whole workflow context. */
|
|
590
589
|
instanceVariables: Record<string, unknown>;
|
|
591
590
|
/**
|
|
592
|
-
* The task's last `setTaskDraft()` payload
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
*
|
|
596
|
-
*
|
|
597
|
-
* (rather than from this draft first) silently reverts any edit made just
|
|
598
|
-
* before that remount, once its own re-seed reaches the host. Read this on
|
|
599
|
-
* mount and prefer it over re-deriving initial values from scratch.
|
|
591
|
+
* The task's last `setTaskDraft()` payload, or `null` when none was saved yet.
|
|
592
|
+
* The widget is remounted when the user switches between the compact and the
|
|
593
|
+
* expanded view, which discards its in-memory state: read this on mount and
|
|
594
|
+
* prefer it over deriving initial values from scratch, or the last edits made
|
|
595
|
+
* before the remount are lost.
|
|
600
596
|
*/
|
|
601
597
|
draft: Record<string, unknown> | null;
|
|
602
598
|
}
|
|
603
599
|
interface CervioTaskPluginBoot {
|
|
604
600
|
pluginType: 'task' | 'task_form';
|
|
605
|
-
/** UI hint only: true
|
|
601
|
+
/** UI hint only: true for a task_form plugin on an open task the viewer may complete. The server checks again on every submit. */
|
|
606
602
|
canSubmit: boolean;
|
|
607
603
|
pluginContext: CervioTaskPluginContextData;
|
|
608
604
|
}
|
|
@@ -627,7 +623,7 @@ declare function getTaskPluginContext(): CervioTaskPluginBoot | null;
|
|
|
627
623
|
declare function setTaskDraft(data: Record<string, unknown>): Promise<CervioTaskDraftResult>;
|
|
628
624
|
/**
|
|
629
625
|
* Completes the task with the given outcome. Only works for `task_form`
|
|
630
|
-
* plugins
|
|
626
|
+
* plugins: the host rejects the call for plain `task` plugins.
|
|
631
627
|
*/
|
|
632
628
|
declare function submitTaskOutcome(outcomeKey: string, data?: Record<string, unknown>): Promise<CervioTaskSubmitResult>;
|
|
633
629
|
|
|
@@ -668,7 +664,7 @@ declare function getCurrentTheme(): CervioThemeSnapshot | null;
|
|
|
668
664
|
*
|
|
669
665
|
* Both resolve a missing `baseUrl` from `__CERVIO_PLUGIN_CONTEXT__.parentOrigin`
|
|
670
666
|
* - **never** from `window.location.origin`, which frequently serializes as
|
|
671
|
-
* the literal string `"null"` inside a sandboxed
|
|
667
|
+
* the literal string `"null"` inside a sandboxed iframe.
|
|
672
668
|
*/
|
|
673
669
|
interface Identity {
|
|
674
670
|
user_id: string;
|
|
@@ -728,7 +724,7 @@ declare class CervioApiError extends Error {
|
|
|
728
724
|
/**
|
|
729
725
|
* Resolve an API base URL: explicit value wins, otherwise
|
|
730
726
|
* `__CERVIO_PLUGIN_CONTEXT__.parentOrigin`. Throws rather than silently
|
|
731
|
-
* falling back to `location.origin` (which breaks inside
|
|
727
|
+
* falling back to `location.origin` (which breaks inside sandboxed iframes).
|
|
732
728
|
*/
|
|
733
729
|
declare function resolveApiBaseUrl(explicitBaseUrl?: string): string;
|
|
734
730
|
type CervioClientOptions = {
|
|
@@ -864,8 +860,8 @@ declare function ensureExternalConnection(api: {
|
|
|
864
860
|
declare function findEntityByName(entities: Entity[], technicalName: string): Entity | undefined;
|
|
865
861
|
|
|
866
862
|
/**
|
|
867
|
-
* Minimal i18n helper for
|
|
868
|
-
*
|
|
863
|
+
* Minimal i18n helper for plugins. Plugins run in a sandboxed iframe where
|
|
864
|
+
* the host's translations are not available, so ship
|
|
869
865
|
* your own catalogs in the ZIP and resolve the active locale from the host
|
|
870
866
|
* bootstrap. See https://docs.cervio.app/docs/authoring → "Plugin i18n / locale".
|
|
871
867
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cervio/plugin-sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "SDK for Cervio plugins: CervioUI client, plugin context, /api/v1 client, theme sync, i18n, PDF viewer (./pdf) and write-gate helpers (./policy).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cervio",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"tsup": "^9.0.0",
|
|
64
64
|
"typescript": "^5.8.3",
|
|
65
65
|
"vitest": "^5.0.5",
|
|
66
|
-
"@cervio/plugin-core": "^1.0.
|
|
66
|
+
"@cervio/plugin-core": "^1.0.1"
|
|
67
67
|
},
|
|
68
68
|
"publishConfig": {
|
|
69
69
|
"access": "public"
|