@cervio/create-plugin 1.0.0 → 1.1.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 CHANGED
@@ -3,6 +3,7 @@
3
3
  Scaffold a new [Cervio](https://cervio.app) plugin in one command:
4
4
 
5
5
  - **Route plugin** (default): a full page in Cervio. Vite + React + TypeScript, wired to `@cervio/plugin-sdk`.
6
+ - **Task plugin** (`--type task`): a widget inside a workflow task that can complete it (`task_form`).
6
7
  - **Write-gate plugin** (`--type policy`): allow or deny a record save (`before_create` / `before_update`), bundled for the server isolate.
7
8
 
8
9
  ```bash
@@ -10,14 +11,15 @@ npm create @cervio/plugin@latest my-plugin
10
11
  # or
11
12
  npx @cervio/create-plugin my-plugin --host https://your-org.cervio.app
12
13
 
13
- # write-gate plugin
14
+ # task plugin, write-gate plugin
15
+ npm create @cervio/plugin@latest my-task -- --type task
14
16
  npm create @cervio/plugin@latest my-guard -- --type policy
15
17
  ```
16
18
 
17
- `cervio init` (from `@cervio/cli`) runs the same scaffolder.
19
+ `cervio init` (from `@cervio/cli`) runs the same scaffolder. Requires Node.js 26 or later.
18
20
 
19
21
  Options: `--host <url>`, `--route-slug <slug>` (route plugins; defaults to the
20
- kebab-cased plugin name), `--type route|policy` (`server` is a legacy alias for
22
+ kebab-cased plugin name), `--type route|task|policy` (`server` is a legacy alias for
21
23
  `policy`), `--yes` (skip the host prompt).
22
24
 
23
25
  ## What you get (route)
@@ -40,6 +42,23 @@ my-plugin/
40
42
  .cursor/rules/cervio-plugin.mdc
41
43
  ```
42
44
 
45
+ ## What you get (task)
46
+
47
+ ```text
48
+ my-task/
49
+ AGENTS.md # rules for coding agents
50
+ README.md # task vs task_form, drafts, box size
51
+ cervio.json # host, plugin_key
52
+ manifest.json # plugin_type: task_form, task_widget.preferred_size
53
+ package.json # build / validate / push scripts
54
+ vite.config.ts
55
+ index.html
56
+ src/
57
+ main.tsx, App.tsx # variables, draft, outcome buttons
58
+ i18n/ # it/en catalogs
59
+ index.css # fills the task box, host CSS tokens only
60
+ ```
61
+
43
62
  ## What you get (write-gate plugin)
44
63
 
45
64
  ```text
@@ -67,3 +86,17 @@ await createPlugin(['my-plugin', '--type', 'route', '--yes'])
67
86
  [docs.cervio.app](https://docs.cervio.app): Authoring, Route plugins, Policy plugins.
68
87
 
69
88
  `create-cervio-plugin` is the previous name of this package and is deprecated.
89
+
90
+ ## License
91
+
92
+ MIT, see [LICENSE](LICENSE).
93
+
94
+ **Trademark.** "Cervio" and the Cervio logo are trademarks of Cervio S.r.l. This license
95
+ does not grant permission to use them. You may say that a plugin "works with Cervio"; you
96
+ may not imply endorsement or ship a product named Cervio.
97
+
98
+ **Platform.** Using a Cervio organization is governed by your partner or customer
99
+ agreement, not by this license.
100
+
101
+ **Your plugins.** Plugins you write are yours: using this package gives Cervio no rights
102
+ over your plugin, and does not require you to open-source it.
@@ -4,8 +4,46 @@ import path from "path";
4
4
  import { fileURLToPath } from "url";
5
5
  import prompts from "prompts";
6
6
  var __dirname = path.dirname(fileURLToPath(import.meta.url));
7
- var TEMPLATE_DIR = path.join(__dirname, "..", "template");
8
- var TEMPLATE_POLICY_DIR = path.join(__dirname, "..", "template-policy");
7
+ var TEMPLATES = {
8
+ route: {
9
+ dir: path.join(__dirname, "..", "template"),
10
+ label: "route plugin",
11
+ next: [
12
+ "npm install",
13
+ "npm run dev # local Vite preview (CervioUI is unavailable outside Cervio)",
14
+ "npm run build # dist/index.html + dist/surface.html + dist/assets",
15
+ "npm run validate # same checks as the Cervio upload",
16
+ "npm run push:dev # dev channel while iterating; npm run push for a release"
17
+ ]
18
+ },
19
+ task: {
20
+ dir: path.join(__dirname, "..", "template-task"),
21
+ label: "task plugin",
22
+ next: [
23
+ "npm install",
24
+ "npm run build # dist/index.html + dist/assets",
25
+ "npm run validate # same checks as the Cervio upload",
26
+ "npm run push:dev # then add a plugin widget to a task layout in Admin"
27
+ ]
28
+ },
29
+ policy: {
30
+ dir: path.join(__dirname, "..", "template-policy"),
31
+ label: "write-gate plugin",
32
+ next: [
33
+ "npm install",
34
+ "# edit src/index.js (uses @cervio/plugin-sdk/policy)",
35
+ "npm run build # REQUIRED: bundles into server/index.js",
36
+ "npm run validate # build + cervio validate",
37
+ "npm run push # build + cervio push, then bind the hook in Admin \u2192 Plugins"
38
+ ]
39
+ }
40
+ };
41
+ var TYPE_ALIASES = {
42
+ route: "route",
43
+ task: "task",
44
+ policy: "policy",
45
+ server: "policy"
46
+ };
9
47
  var RESERVED_NAMES = /* @__PURE__ */ new Set([".", "..", "node_modules", ".git"]);
10
48
  var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".gif", ".ico", ".woff", ".woff2"]);
11
49
  var DOTFILE_RENAMES = {
@@ -120,15 +158,16 @@ async function createPlugin(argv) {
120
158
  }
121
159
  const routeSlug = flags.get("route-slug") || pluginKey;
122
160
  const rawType = (flags.get("type") || "route").toLowerCase();
123
- const isPolicy = rawType === "policy" || rawType === "server";
124
- const templateDir = isPolicy ? TEMPLATE_POLICY_DIR : TEMPLATE_DIR;
125
- if (isPolicy && !await pathExists(templateDir)) {
126
- console.error("The policy template is missing (template-policy/).");
161
+ const kind = TYPE_ALIASES[rawType];
162
+ if (!kind) {
163
+ console.error(`Unknown --type "${rawType}". Use one of: route, task, policy.`);
127
164
  process.exit(1);
128
165
  return;
129
166
  }
167
+ const template = TEMPLATES[kind];
168
+ const isPolicy = kind === "policy";
130
169
  await fs.mkdir(targetDir, { recursive: true });
131
- await copyTemplate(templateDir, targetDir, {
170
+ await copyTemplate(template.dir, targetDir, {
132
171
  PLUGIN_NAME: targetName,
133
172
  PLUGIN_KEY: pluginKey,
134
173
  ROUTE_SLUG: routeSlug,
@@ -148,26 +187,11 @@ async function createPlugin(argv) {
148
187
  }
149
188
  }
150
189
  console.log("");
151
- console.log(
152
- `\u2714 Created ${targetName} at ${targetDir}${isPolicy ? " (write-gate plugin)" : ""}`
153
- );
190
+ console.log(`\u2714 Created ${targetName} at ${targetDir} (${template.label})`);
154
191
  console.log("");
155
192
  console.log("Next steps:");
156
193
  console.log(` cd ${targetName}`);
157
- if (isPolicy) {
158
- console.log(" npm install # installs @cervio/plugin-sdk + esbuild");
159
- console.log(" # edit src/index.js # plugin source (@cervio/plugin-sdk/policy)");
160
- console.log(" npm run build # REQUIRED: bundles into server/index.js");
161
- console.log(" npm run validate # build + cervio validate");
162
- console.log(" npm run push # build + cervio push");
163
- console.log(" # then bind the hook in Admin \u2192 Plugins (plugin_hook_bindings)");
164
- } else {
165
- console.log(" npm install # or pnpm install / yarn");
166
- console.log(" npm run dev # local Vite preview (CervioUI stubs unavailable outside the sandbox)");
167
- console.log(" npm run build # produces dist/index.html + dist/surface.html + dist/assets");
168
- console.log(" npm run validate # cervio validate - matches host upload checks");
169
- console.log(' npm run push # cervio push - prefer "cervio push --dev" while iterating');
170
- }
194
+ for (const line of template.next) console.log(` ${line}`);
171
195
  console.log("");
172
196
  if (!isPolicy) {
173
197
  console.log("Read AGENTS.md before iterating with an LLM coding agent.");
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  createPlugin
4
- } from "./chunk-NNLHAM7U.js";
4
+ } from "./chunk-AGG3S6VV.js";
5
5
 
6
6
  // src/cli.ts
7
7
  createPlugin(process.argv.slice(2)).catch((err) => {
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createPlugin
3
- } from "./chunk-NNLHAM7U.js";
3
+ } from "./chunk-AGG3S6VV.js";
4
4
  export {
5
5
  createPlugin
6
6
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cervio/create-plugin",
3
- "version": "1.0.0",
4
- "description": "Scaffold a Cervio plugin (route, task or write-gate policy) wired to the Cervio toolchain. Run with: npm create @cervio/plugin",
3
+ "version": "1.1.1",
4
+ "description": "Scaffold a Cervio plugin (route, task or write-gate) wired to the Cervio toolchain. Run with: npm create @cervio/plugin",
5
5
  "keywords": [
6
6
  "cervio",
7
7
  "plugin",
@@ -31,6 +31,7 @@
31
31
  "files": [
32
32
  "dist",
33
33
  "template",
34
+ "template-task",
34
35
  "template-policy",
35
36
  "README.md",
36
37
  "LICENSE"
@@ -93,6 +93,11 @@ npm run validate # cervio validate - same checks the host runs on upload
93
93
  npm run push # cervio push - uploads + creates/updates the plugin version
94
94
  ```
95
95
 
96
+ **First time on a host**, in this order: `cervio push` (no `--dev`: it creates the
97
+ plugin, a dev push before it fails), then `cervio route set` (without a route config
98
+ `/r/<route_slug>` answers "plugin not available"), then
99
+ `cervio route set --dev-channel on` if you will use `push:dev`.
100
+
96
101
  While iterating on a shared/dev org, **prefer**:
97
102
 
98
103
  ```bash
@@ -13,11 +13,26 @@ npm install
13
13
  npm run dev # local Vite dev server (CervioUI / __CERVIO_PLUGIN_CONTEXT__ are not injected here)
14
14
  npm run build # dist/index.html + dist/surface.html + dist/assets/*
15
15
  npm run validate # cervio validate - matches host upload checks
16
- npm run push # cervio push - prefer "cervio push --dev" while iterating
17
16
  ```
18
17
 
19
- `npm run validate` / `npm run push` require the [`cervio` CLI](https://github.com/cervio-app) -
20
- already a devDependency here. Log in once per host: `npx cervio login --host <host>`.
18
+ ## First publish
19
+
20
+ ```bash
21
+ npx cervio login --host https://your-org.cervio.app # once per host; fills "host" in cervio.json
22
+ npm run push # first push: creates the plugin on the host
23
+ npx cervio route set # makes it reachable at /r/<route_slug>
24
+ ```
25
+
26
+ Until `cervio route set` runs (or an admin sets the route in Admin → Plugins), the page
27
+ shows "plugin not available". Then iterate on the dev channel:
28
+
29
+ ```bash
30
+ npx cervio route set --dev-channel on # once
31
+ npm run push:dev # test at /r/<route_slug>?channel=dev
32
+ npm run push # release when it works
33
+ ```
34
+
35
+ The `cervio` CLI is already a devDependency here.
21
36
 
22
37
  ## Project layout
23
38
 
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Route plugins run in a sandboxed `srcDoc` iframe: next-intl / `public/locales`
3
- * are not available, so catalogs ship inside the ZIP. Keep identical key sets
2
+ * Route plugins run in a sandboxed iframe: the host's translations are not
3
+ * available, so catalogs ship inside the ZIP. Keep identical key sets
4
4
  * across every locale - see AGENTS.md and the host's
5
5
  * https://docs.cervio.app/docs/authoring/performance-safety → "Plugin i18n / locale" for the resolve order.
6
6
  */
@@ -18,8 +18,12 @@ npm run pack # build + cervio pack
18
18
  npm run push # build + cervio push
19
19
  ```
20
20
 
21
- Then bind the hook in Admin → Plugins. Disabling the binding works as a kill switch
22
- without uploading a new version.
21
+ The push binds each entry of `hooks` to its entities: there is nothing to configure in
22
+ the admin. Entities are matched by name when you push, so **create them first**: an
23
+ entity that does not exist yet is skipped, and you push again once it does.
24
+
25
+ To stop the hook, deactivate the plugin in Admin → Plugins (no new upload needed), or
26
+ remove the hook from `manifest.json` and push.
23
27
 
24
28
  ## Why build?
25
29
 
@@ -0,0 +1,17 @@
1
+ ---
2
+ description: Cervio task plugin rules - task context, drafts, submit, build/validate/push loop
3
+ globs:
4
+ - "**/*"
5
+ alwaysApply: true
6
+ ---
7
+
8
+ # Cervio task plugin - agent rules
9
+
10
+ Read `AGENTS.md` in full before editing anything: this rule only points to it.
11
+
12
+ 1. Host access only through `@cervio/plugin-sdk` (`getTaskPluginContext`,
13
+ `setTaskDraft`, `submitTaskOutcome`, `markReady`).
14
+ 2. Seed state from the saved draft on mount; debounce draft saves.
15
+ 3. Fill the box (`height: 100%`, internal scroll).
16
+ 4. No `version` in `manifest.json`; declare every `/api/v1` call in `cervio_apis`.
17
+ 5. Loop: `npm run build`, `npm run validate`, `npm run push:dev`.
@@ -0,0 +1,34 @@
1
+ # Agent rules: Cervio task plugin
2
+
3
+ This project is a Cervio **task plugin** (`plugin_type: task_form`), scaffolded with
4
+ `@cervio/create-plugin`. It runs in a sandboxed iframe inside a workflow task.
5
+
6
+ ## Must
7
+
8
+ - Use `@cervio/plugin-sdk` for everything host-related: `getTaskPluginContext`,
9
+ `setTaskDraft`, `submitTaskOutcome`, `markReady`, `createCervioSessionClient`.
10
+ Never post raw `postMessage` payloads to the host.
11
+ - Read the saved draft (`pluginContext.draft`) on mount before deriving initial values:
12
+ the widget remounts when the user switches between compact and expanded view.
13
+ - Save drafts after a pause (debounce), not on every keystroke.
14
+ - Call `markReady()` once, when the first useful content is on screen (also on error).
15
+ - Treat `canSubmit` as a hint: the server re-checks the assignee and the task status.
16
+ - Fill the box: `height: 100%`, internal scroll, usable from about 352px high.
17
+ - Every `/api/v1` call needs its method and path prefix in `manifest.json`
18
+ `cervio_apis`. Read records through views (`listViewRecords`, `countViewRecords`):
19
+ the entity records endpoint is for organization administrators only.
20
+ - All user-visible strings in `src/i18n` (`it` and `en`, same keys).
21
+ - Use host CSS variables (`var(--background)`, `var(--foreground)`...); never define
22
+ `:root`.
23
+
24
+ ## Must not
25
+
26
+ - No `window.alert` / `window.confirm`, no `window.location.origin` (it is `"null"`
27
+ in the sandbox): use the SDK, which resolves the host origin.
28
+ - No secrets, tokens or API keys in the code or the ZIP.
29
+ - No `version` in `manifest.json`: Cervio assigns release versions on upload.
30
+ - No polling loops or a request per render.
31
+
32
+ ## Commands
33
+
34
+ `npm run build`, `npm run validate`, `npm run push:dev`, `npm run push`.
@@ -0,0 +1,46 @@
1
+ # {{PLUGIN_NAME}}
2
+
3
+ A Cervio task plugin, scaffolded with `@cervio/create-plugin`. It renders inside a
4
+ workflow task (Admin → Workflow → task layouts → plugin widget), not as a page.
5
+
6
+ ## Develop
7
+
8
+ ```bash
9
+ npm install
10
+ npm run build # dist/index.html + dist/assets
11
+ npm run validate # same checks as the Cervio upload
12
+ npm run push:dev # dev channel; npm run push for a release
13
+ ```
14
+
15
+ `npm run dev` previews the UI locally, but the task context and submit only exist
16
+ inside Cervio.
17
+
18
+ ## task or task_form
19
+
20
+ The manifest declares `"plugin_type": "task_form"`: the widget can complete the task
21
+ with `submitTaskOutcome()`. For a read-only helper (checklist, calculator) use `"task"`
22
+ and let an `actions` widget of the layout complete the task.
23
+
24
+ ## How it works
25
+
26
+ - `getTaskPluginContext()`: the task, its outcomes, the workflow variables the layout
27
+ exposes, and the last saved draft. The binding is frozen when the task is created.
28
+ - `setTaskDraft()`: saves work in progress (the template saves after a short pause).
29
+ Read the draft on mount: the widget remounts when the user expands it.
30
+ - `submitTaskOutcome(outcome, data)`: completes the task. The server checks the
31
+ assignee and the task status again.
32
+ - `markReady()`: tells Cervio the widget is ready, to time how long it takes to open.
33
+
34
+ ## Size
35
+
36
+ The layout chooses the box height; `task_widget.preferred_size` in the manifest is only
37
+ the default (`compact`, `standard`, `tall`, `fill`). The UI fills its box, scrolls
38
+ inside, and works from about 352px high.
39
+
40
+ ## API calls
41
+
42
+ `cervio_apis` is empty: the widget calls no `/api/v1` endpoint. Declare every method and
43
+ path prefix you add (for example `{ "method": "GET", "path_prefix": "/api/v1/me" }`),
44
+ otherwise the call fails with `Path not declared for this plugin`.
45
+
46
+ Documentation: [docs.cervio.app](https://docs.cervio.app), Authoring → Task plugins.
@@ -0,0 +1,4 @@
1
+ {
2
+ "host": "{{HOST}}",
3
+ "plugin_key": "{{PLUGIN_KEY}}"
4
+ }
@@ -0,0 +1,4 @@
1
+ node_modules
2
+ dist
3
+ *.zip
4
+ .DS_Store
@@ -0,0 +1,12 @@
1
+ <!doctype html>
2
+ <html lang="it">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>{{PLUGIN_NAME}}</title>
7
+ </head>
8
+ <body>
9
+ <div id="root"></div>
10
+ <script type="module" src="/src/main.tsx"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "./node_modules/@cervio/plugin-core/manifest.schema.json",
3
+ "plugin_key": "{{PLUGIN_KEY}}",
4
+ "name": "{{PLUGIN_NAME}}",
5
+ "plugin_type": "task_form",
6
+ "description": "Describe what the assignee does in this task.",
7
+ "requiredApiVersion": "1.0.0",
8
+ "entry": "src/main.tsx",
9
+ "task_widget": { "preferred_size": "standard" },
10
+ "cervio_apis": []
11
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "{{PLUGIN_KEY}}",
3
+ "private": true,
4
+ "version": "0.1.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build",
9
+ "preview": "vite preview",
10
+ "validate": "cervio validate",
11
+ "push": "cervio push",
12
+ "push:dev": "cervio push --dev"
13
+ },
14
+ "dependencies": {
15
+ "@cervio/plugin-sdk": "^2.0.0",
16
+ "react": "^19.0.0",
17
+ "react-dom": "^19.0.0"
18
+ },
19
+ "devDependencies": {
20
+ "@cervio/cli": "^1.0.0",
21
+ "@cervio/plugin-core": "^1.0.0",
22
+ "@types/react": "^19.0.0",
23
+ "@types/react-dom": "^19.0.0",
24
+ "@vitejs/plugin-react": "^6.2.0",
25
+ "typescript": "~5.9.0",
26
+ "vite": "^8.3.5"
27
+ }
28
+ }
@@ -0,0 +1,117 @@
1
+ import { useEffect, useRef, useState } from 'react'
2
+ import {
3
+ getTaskPluginContext,
4
+ markReady,
5
+ setTaskDraft,
6
+ submitTaskOutcome,
7
+ type CervioTaskOutcome,
8
+ } from '@cervio/plugin-sdk'
9
+ import { createAppI18n } from './i18n'
10
+
11
+ type Draft = { notes: string }
12
+
13
+ const DRAFT_DELAY_MS = 600
14
+
15
+ export function App() {
16
+ const i18n = createAppI18n()
17
+ const task = getTaskPluginContext()
18
+ const ctx = task?.pluginContext
19
+
20
+ // Start from the saved draft: the widget remounts (compact/expanded view), and
21
+ // re-deriving values from scratch would drop the assignee's last edits.
22
+ const [notes, setNotes] = useState(() => String((ctx?.draft as Draft | null)?.notes ?? ''))
23
+ const [saving, setSaving] = useState<'idle' | 'saving' | 'saved' | 'error'>('idle')
24
+ const [submitting, setSubmitting] = useState<string | null>(null)
25
+ const [error, setError] = useState<string | null>(null)
26
+ const [done, setDone] = useState(false)
27
+ const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
28
+
29
+ useEffect(() => {
30
+ // Everything the first screen shows comes from the boot payload: it is ready now.
31
+ markReady()
32
+ }, [])
33
+
34
+ function onNotesChange(value: string) {
35
+ setNotes(value)
36
+ if (!task) return
37
+ // Coalesce keystrokes into one draft save.
38
+ clearTimeout(timer.current)
39
+ timer.current = setTimeout(async () => {
40
+ setSaving('saving')
41
+ const res = await setTaskDraft({ notes: value })
42
+ setSaving(res.ok ? 'saved' : 'error')
43
+ }, DRAFT_DELAY_MS)
44
+ }
45
+
46
+ async function complete(outcome: CervioTaskOutcome) {
47
+ clearTimeout(timer.current)
48
+ setSubmitting(outcome.value)
49
+ setError(null)
50
+ // The server checks the assignee and the task status again: canSubmit is a hint.
51
+ const res = await submitTaskOutcome(outcome.value, { notes })
52
+ setSubmitting(null)
53
+ if (res.ok) setDone(true)
54
+ else setError(i18n.t('task.submitError', { message: res.error ?? 'unknown' }))
55
+ }
56
+
57
+ if (!task || !ctx) {
58
+ return (
59
+ <main className="task">
60
+ <p className="task-muted">{i18n.t('task.outsideCervio')}</p>
61
+ </main>
62
+ )
63
+ }
64
+
65
+ const variables = Object.entries(ctx.instanceVariables)
66
+
67
+ return (
68
+ <main className="task">
69
+ <section className="task-body">
70
+ <h2 className="task-title">{i18n.t('task.title')}</h2>
71
+
72
+ <dl className="task-vars">
73
+ {variables.length === 0 && <p className="task-muted">{i18n.t('task.noVariables')}</p>}
74
+ {variables.map(([name, value]) => (
75
+ <div key={name} className="task-var">
76
+ <dt>{name}</dt>
77
+ <dd>{typeof value === 'object' ? JSON.stringify(value) : String(value)}</dd>
78
+ </div>
79
+ ))}
80
+ </dl>
81
+
82
+ <label className="task-label" htmlFor="notes">
83
+ {i18n.t('task.notes')}
84
+ </label>
85
+ <textarea
86
+ id="notes"
87
+ className="task-notes"
88
+ value={notes}
89
+ disabled={done}
90
+ onChange={(e) => onNotesChange(e.target.value)}
91
+ />
92
+ <p className="task-muted" aria-live="polite">
93
+ {saving === 'saving' && i18n.t('task.saving')}
94
+ {saving === 'saved' && i18n.t('task.saved')}
95
+ {saving === 'error' && i18n.t('task.saveError')}
96
+ </p>
97
+ </section>
98
+
99
+ <footer className="task-actions">
100
+ {error && <p className="task-error">{error}</p>}
101
+ {done && <p className="task-muted">{i18n.t('task.completed')}</p>}
102
+ {task.canSubmit && !done
103
+ ? ctx.outcomes.map((outcome) => (
104
+ <button
105
+ key={outcome.value}
106
+ type="button"
107
+ disabled={submitting !== null}
108
+ onClick={() => complete(outcome)}
109
+ >
110
+ {submitting === outcome.value ? i18n.t('task.submitting') : outcome.label}
111
+ </button>
112
+ ))
113
+ : null}
114
+ </footer>
115
+ </main>
116
+ )
117
+ }
@@ -0,0 +1,14 @@
1
+ export const en = {
2
+ task: {
3
+ title: '{{PLUGIN_NAME}}',
4
+ noVariables: 'No workflow variables are exposed to this widget.',
5
+ notes: 'Notes',
6
+ saving: 'Saving draft…',
7
+ saved: 'Draft saved',
8
+ saveError: 'The draft could not be saved.',
9
+ submitting: 'Completing…',
10
+ submitError: 'The task could not be completed: {message}',
11
+ completed: 'Task completed.',
12
+ outsideCervio: 'This widget runs inside a Cervio task. Open it from My tasks.',
13
+ },
14
+ } as const
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The plugin runs in a sandboxed iframe: catalogs ship inside the ZIP. Keep the
3
+ * same keys in every locale. Resolve order: host locale (when enabled for this
4
+ * plugin), then the fallback locale, then the default below.
5
+ */
6
+ import { createI18n, type CervioI18nCatalog } from '@cervio/plugin-sdk'
7
+ import { en } from './en'
8
+ import { it } from './it'
9
+
10
+ export const messages: CervioI18nCatalog = { it, en }
11
+
12
+ export function createAppI18n() {
13
+ return createI18n({ defaultLocale: 'it', messages })
14
+ }
@@ -0,0 +1,14 @@
1
+ export const it = {
2
+ task: {
3
+ title: '{{PLUGIN_NAME}}',
4
+ noVariables: 'Nessuna variabile del processo è esposta a questo riquadro.',
5
+ notes: 'Note',
6
+ saving: 'Salvataggio della bozza…',
7
+ saved: 'Bozza salvata',
8
+ saveError: 'Non è stato possibile salvare la bozza.',
9
+ submitting: 'Completamento…',
10
+ submitError: 'Non è stato possibile completare l’attività: {message}',
11
+ completed: 'Attività completata.',
12
+ outsideCervio: 'Questo riquadro funziona dentro un’attività di Cervio. Aprilo da Le mie attività.',
13
+ },
14
+ } as const
@@ -0,0 +1,117 @@
1
+ /* Design tokens come only from the host theme bridge: do not define :root here.
2
+ Use var(--background), var(--foreground), var(--border), var(--primary)... */
3
+
4
+ * {
5
+ box-sizing: border-box;
6
+ }
7
+
8
+ html,
9
+ body,
10
+ #root {
11
+ height: 100%;
12
+ margin: 0;
13
+ }
14
+
15
+ body {
16
+ font-family: var(--font-sans, system-ui, sans-serif);
17
+ color: var(--foreground);
18
+ background: var(--background);
19
+ }
20
+
21
+ /* The widget fills the box the layout gives it (from about 352px high) and
22
+ scrolls inside: the actions stay visible at the bottom. */
23
+ .task {
24
+ height: 100%;
25
+ display: flex;
26
+ flex-direction: column;
27
+ }
28
+
29
+ .task-body {
30
+ flex: 1;
31
+ min-height: 0;
32
+ overflow: auto;
33
+ padding: 1rem 1.25rem;
34
+ display: flex;
35
+ flex-direction: column;
36
+ gap: 0.75rem;
37
+ }
38
+
39
+ .task-title {
40
+ margin: 0;
41
+ font-size: 1rem;
42
+ font-weight: 600;
43
+ }
44
+
45
+ .task-vars {
46
+ margin: 0;
47
+ display: grid;
48
+ gap: 0.25rem;
49
+ }
50
+
51
+ .task-var {
52
+ display: flex;
53
+ gap: 0.5rem;
54
+ font-size: 0.875rem;
55
+ }
56
+
57
+ .task-var dt {
58
+ color: var(--muted-foreground);
59
+ }
60
+
61
+ .task-var dd {
62
+ margin: 0;
63
+ }
64
+
65
+ .task-label {
66
+ font-size: 0.875rem;
67
+ font-weight: 500;
68
+ }
69
+
70
+ .task-notes {
71
+ min-height: 6rem;
72
+ resize: vertical;
73
+ padding: 0.5rem;
74
+ font: inherit;
75
+ color: var(--foreground);
76
+ background: var(--background);
77
+ border: 1px solid var(--border);
78
+ border-radius: var(--radius, 0.375rem);
79
+ }
80
+
81
+ .task-muted {
82
+ margin: 0;
83
+ font-size: 0.8125rem;
84
+ color: var(--muted-foreground);
85
+ }
86
+
87
+ .task-error {
88
+ margin: 0 auto 0 0;
89
+ font-size: 0.8125rem;
90
+ color: var(--destructive);
91
+ }
92
+
93
+ .task-actions {
94
+ display: flex;
95
+ flex-wrap: wrap;
96
+ justify-content: flex-end;
97
+ align-items: center;
98
+ gap: 0.5rem;
99
+ padding: 0.75rem 1.25rem;
100
+ border-top: 1px solid var(--border);
101
+ }
102
+
103
+ .task-actions button {
104
+ padding: 0.5rem 0.875rem;
105
+ font: inherit;
106
+ font-size: 0.875rem;
107
+ color: var(--primary-foreground);
108
+ background: var(--primary);
109
+ border: 0;
110
+ border-radius: var(--radius, 0.375rem);
111
+ cursor: pointer;
112
+ }
113
+
114
+ .task-actions button:disabled {
115
+ opacity: 0.6;
116
+ cursor: default;
117
+ }
@@ -0,0 +1,10 @@
1
+ import { StrictMode } from 'react'
2
+ import { createRoot } from 'react-dom/client'
3
+ import { App } from './App'
4
+ import './index.css'
5
+
6
+ createRoot(document.getElementById('root')!).render(
7
+ <StrictMode>
8
+ <App />
9
+ </StrictMode>,
10
+ )
@@ -0,0 +1,5 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ // Global `window.__CERVIO_PLUGIN_CONTEXT__` and `window.CervioUI` typings come
4
+ // from `@cervio/plugin-sdk` (imported throughout `src/`) - no need to redeclare
5
+ // them here.
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
6
+ "module": "ESNext",
7
+ "skipLibCheck": true,
8
+ "moduleResolution": "bundler",
9
+ "isolatedModules": true,
10
+ "moduleDetection": "force",
11
+ "strict": true,
12
+ "noEmit": true,
13
+ "jsx": "react-jsx",
14
+ "noUnusedLocals": true,
15
+ "noUnusedParameters": true
16
+ },
17
+ "include": ["src"]
18
+ }
@@ -0,0 +1,31 @@
1
+ import { fileURLToPath } from 'node:url'
2
+ import { defineConfig } from 'vite'
3
+ import react from '@vitejs/plugin-react'
4
+
5
+ /**
6
+ * Task widget build: one entry JS + one CSS. Cervio serves `dist/` as a cached
7
+ * document per uploaded version and inlines the entry JS (up to ~384 KB) and
8
+ * CSS into it, so the widget opens without extra requests. Keep everything the
9
+ * first screen needs in the entry; use dynamic `import()` only for rare, heavy
10
+ * features (a sandboxed iframe does not cache its own requests).
11
+ */
12
+ export default defineConfig({
13
+ plugins: [react()],
14
+ base: './',
15
+ build: {
16
+ target: 'es2022',
17
+ outDir: 'dist',
18
+ assetsDir: 'assets',
19
+ emptyOutDir: true,
20
+ cssCodeSplit: false,
21
+ modulePreload: false,
22
+ rolldownOptions: {
23
+ input: fileURLToPath(new URL('./index.html', import.meta.url)),
24
+ output: {
25
+ chunkFileNames: 'assets/[name]-[hash].js',
26
+ entryFileNames: 'assets/[name]-[hash].js',
27
+ assetFileNames: 'assets/[name]-[hash][extname]',
28
+ },
29
+ },
30
+ },
31
+ })