@cervio/plugin-sdk 1.1.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/dist/index.d.cts DELETED
@@ -1,841 +0,0 @@
1
- /**
2
- * Publishable typed client mirroring `window.CervioUI` injected by the Cervio host.
3
- * Docs: https://docs.cervio.app/docs/plugins/ui (Admin Components = catalog + try-it only).
4
- *
5
- * `CERVIO_UI_API_VERSION` tracks the host `window.CervioUI.apiVersion` wire
6
- * contract (additive namespaces may ship in a package minor without bumping it).
7
- */
8
- declare const CERVIO_UI_API_VERSION: "1.0.0";
9
- type CervioUiToastType = 'success' | 'error' | 'warning' | 'info';
10
- type CervioUiDialogVariant = 'default' | 'destructive';
11
- type CervioUiFrameSize = 'sm' | 'md' | 'lg' | 'full';
12
- interface CervioUiSelectOption {
13
- value: string;
14
- label: string;
15
- }
16
- interface CervioUiToastOptions {
17
- type?: CervioUiToastType;
18
- message: string;
19
- }
20
- interface CervioUiConfirmOptions {
21
- title: string;
22
- description: string;
23
- confirmLabel?: string;
24
- cancelLabel?: string;
25
- variant?: CervioUiDialogVariant;
26
- }
27
- interface CervioUiAlertOptions {
28
- title: string;
29
- description: string;
30
- okLabel?: string;
31
- }
32
- interface CervioUiFrameOpenOptions {
33
- title?: string;
34
- size?: CervioUiFrameSize;
35
- showClose?: boolean;
36
- /**
37
- * Optional body height in px (120–900) for `dialog.surface`.
38
- * Host sizes the dialog to content; omit to let the surface report via `update`.
39
- */
40
- height?: number;
41
- }
42
- interface CervioUiSurfaceOpenOptions extends CervioUiFrameOpenOptions {
43
- /** Plain JSON forwarded to `dist/surface.html` on open (max ~64KB). */
44
- params?: unknown;
45
- }
46
- interface CervioUiSelectOpenOptions {
47
- options: CervioUiSelectOption[];
48
- value?: string;
49
- searchable?: boolean;
50
- placeholder?: string;
51
- emptyText?: string;
52
- }
53
- interface CervioUiFrameSlot {
54
- left: number;
55
- top: number;
56
- width: number;
57
- height: number;
58
- headerHeight: number;
59
- }
60
- interface CervioUiThemeSnapshot {
61
- tokens: Record<string, string>;
62
- colorScheme: 'dark' | 'light';
63
- }
64
- /** Host locale/date/number preferences pushed via `__cervioPluginFormat`; see `CervioUI.format.*`. */
65
- interface CervioUiFormatSnapshot {
66
- /** BCP47 tag (e.g. `it-IT`). */
67
- locale: string;
68
- dateFormat: 'dd/MM/yyyy' | 'MM/dd/yyyy' | 'yyyy-MM-dd';
69
- decimalSeparator: ',' | '.';
70
- thousandsSeparator: string;
71
- /** IANA timezone (e.g. `Europe/Rome`). */
72
- timeZone: string;
73
- /** System UI locale (`NEXT_LOCALE`). */
74
- uiLocale: 'it' | 'en';
75
- }
76
- /** Opaque file metadata: the `File`/blob never crosses postMessage. */
77
- interface CervioUiFileMeta {
78
- id: string;
79
- name: string;
80
- mime: string;
81
- size: number;
82
- }
83
- /** `{ id, label }` action used by `actionSheet.open`. */
84
- interface CervioUiActionSheetAction {
85
- id: string;
86
- label: string;
87
- variant?: CervioUiDialogVariant;
88
- }
89
- /** Wider variant set accepted by `sheet.open` (mirrors button variants). */
90
- interface CervioUiSheetAction {
91
- id: string;
92
- label: string;
93
- variant?: 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost';
94
- }
95
- /** `{ value, label, subtitle? }` option resolved by domain pickers. */
96
- interface CervioUiDomainPickOption {
97
- value: string;
98
- label: string;
99
- subtitle?: string;
100
- }
101
- interface CervioUiActionSheetOpenOptions {
102
- title?: string;
103
- actions: CervioUiActionSheetAction[];
104
- cancelLabel?: string;
105
- }
106
- interface CervioUiFilesPickOptions {
107
- /** MIME types / extensions, e.g. `['image/*', '.pdf']`. Omit to allow the default document types. */
108
- accept?: string[];
109
- multiple?: boolean;
110
- /** Default 20. */
111
- maxFiles?: number;
112
- /** Default: host document upload limit (50 MB). */
113
- maxBytes?: number;
114
- title?: string;
115
- dropHint?: string;
116
- pickLabel?: string;
117
- }
118
- interface CervioUiFilesCaptureOptions {
119
- facing?: 'environment' | 'user';
120
- title?: string;
121
- }
122
- interface CervioUiFilesPickResult {
123
- files: CervioUiFileMeta[];
124
- }
125
- interface CervioUiFilesUploadOptions {
126
- entityId: string;
127
- recordId: string;
128
- /** Ids returned by `files.pick` / `files.capture` - consumed on upload (removed from the host's in-memory store). */
129
- fileIds: string[];
130
- title?: string;
131
- fileName?: string;
132
- }
133
- type CervioUiFilesUploadResult = {
134
- ok: true;
135
- documents: unknown[];
136
- } | {
137
- ok: false;
138
- error: string;
139
- };
140
- interface CervioUiProgressShowOptions {
141
- /** Plugin-chosen id; reuse it with `update` / `hide`. */
142
- id: string;
143
- label?: string;
144
- /** 0-100; omit for an indeterminate bar. */
145
- value?: number;
146
- }
147
- interface CervioUiProgressUpdateOptions {
148
- id: string;
149
- label?: string;
150
- value?: number;
151
- }
152
- interface CervioUiDateOpenOptions {
153
- title?: string;
154
- /** ISO date (`yyyy-MM-dd`) or datetime string. */
155
- value?: string;
156
- mode?: 'date' | 'datetime';
157
- min?: string;
158
- max?: string;
159
- /** Default true. */
160
- clearable?: boolean;
161
- }
162
- interface CervioUiRecordPickOptions {
163
- title?: string;
164
- entityId?: string;
165
- /** Resolved by exact match against entity name/label when `entityId` is omitted. */
166
- entityName?: string;
167
- value?: string;
168
- /** Default true. */
169
- searchable?: boolean;
170
- }
171
- interface CervioUiEntityPickOptions {
172
- title?: string;
173
- value?: string;
174
- }
175
- interface CervioUiUserPickOptions {
176
- title?: string;
177
- value?: string;
178
- }
179
- interface CervioUiGroupPickOptions {
180
- title?: string;
181
- value?: string;
182
- }
183
- interface CervioUiSheetOpenOptions {
184
- title?: string;
185
- description?: string;
186
- actions: CervioUiSheetAction[];
187
- }
188
- /** At least one of `title`, `text`, `url` is required. */
189
- interface CervioUiShareOpenOptions {
190
- title?: string;
191
- text?: string;
192
- /** Same-origin path starting with `/` (resolved to an absolute URL by the host). */
193
- url?: string;
194
- }
195
- type CervioUiShareResult = {
196
- ok: boolean;
197
- fallback?: 'clipboard';
198
- };
199
- /** Exactly one of `fileId` / `url` is required. */
200
- interface CervioUiPrintOpenOptions {
201
- fileId?: string;
202
- /** Same-origin path starting with `/`. */
203
- url?: string;
204
- }
205
- /** Exactly one of `fileId` / `url` is required. */
206
- interface CervioUiExportDownloadOptions {
207
- fileId?: string;
208
- /** Same-origin path starting with `/`. */
209
- url?: string;
210
- fileName?: string;
211
- }
212
- interface CervioUiNavConfirmLeaveOptions {
213
- enabled: boolean;
214
- message?: string;
215
- }
216
- interface CervioUiCameraOpenOptions {
217
- title?: string;
218
- facing?: 'environment' | 'user';
219
- }
220
- interface CervioUiBarcodeScanOptions {
221
- title?: string;
222
- }
223
- type CervioUiBarcodeScanResult = {
224
- value: string;
225
- format?: string;
226
- } | null;
227
- interface CervioUiLocationPickOptions {
228
- title?: string;
229
- }
230
- interface CervioUiTaskOutcome {
231
- value: string;
232
- label: string;
233
- }
234
- interface CervioUiTaskSummary {
235
- id: string;
236
- status: string;
237
- title: string;
238
- outcomes: CervioUiTaskOutcome[];
239
- entityDataId: string | null;
240
- canComplete: boolean;
241
- blockReason: string | null;
242
- requiresFullView: boolean;
243
- }
244
- interface CervioUiTaskListItem {
245
- id: string;
246
- title: string;
247
- outcomes: CervioUiTaskOutcome[];
248
- status: string;
249
- }
250
- interface CervioUiTaskCompleteOptions {
251
- taskId: string;
252
- outcomeKey: string;
253
- response?: Record<string, unknown>;
254
- }
255
- interface CervioUiTaskCompleteResult {
256
- taskCompleted: boolean;
257
- }
258
- interface CervioUiTaskOpenResult {
259
- completed: boolean;
260
- outcomeKey?: string;
261
- }
262
- type CervioUiLocationResult = {
263
- lat: number;
264
- lng: number;
265
- accuracy?: number;
266
- } | null;
267
- interface CervioUI {
268
- apiVersion: typeof CERVIO_UI_API_VERSION;
269
- capabilities(): Promise<string[]>;
270
- toast(opts: CervioUiToastOptions): Promise<{
271
- ok: true;
272
- }>;
273
- dialog: {
274
- confirm(opts: CervioUiConfirmOptions): Promise<boolean>;
275
- alert(opts: CervioUiAlertOptions): Promise<true>;
276
- frame: {
277
- /** Sync cached slot (null if host has not pushed dialog.frame.slots yet). */
278
- slot?(size?: 'sm' | 'md' | 'lg' | 'full'): CervioUiFrameSlot | null;
279
- open(opts?: CervioUiFrameOpenOptions): Promise<{
280
- open: true;
281
- slot: CervioUiFrameSlot;
282
- }>;
283
- update(opts: {
284
- title?: string;
285
- }): Promise<{
286
- ok: true;
287
- }>;
288
- close(): Promise<{
289
- ok: true;
290
- }>;
291
- };
292
- /** Recommended for custom modals: host Dialog + body from dist/surface.html. */
293
- surface: {
294
- open(opts?: CervioUiSurfaceOpenOptions): Promise<{
295
- open: true;
296
- }>;
297
- update(opts: {
298
- title?: string;
299
- height?: number;
300
- }): Promise<{
301
- ok: true;
302
- }>;
303
- close(): Promise<{
304
- ok: true;
305
- }>;
306
- /** Relay plain JSON to the other iframe (page ↔ surface). */
307
- post(data: unknown): Promise<{
308
- ok: true;
309
- }>;
310
- };
311
- };
312
- backdrop: {
313
- set(open: boolean): Promise<{
314
- open: boolean;
315
- }>;
316
- };
317
- select: {
318
- open(opts: CervioUiSelectOpenOptions): Promise<string | null>;
319
- };
320
- combobox: {
321
- open(opts: CervioUiSelectOpenOptions): Promise<string | null>;
322
- };
323
- /** Last host theme push (null until first `__cervioPluginTheme` message). Applied automatically by inject script. */
324
- theme: {
325
- get(): CervioUiThemeSnapshot | null;
326
- };
327
- /** Host locale/date/number prefs (`__cervioPluginFormat`). `date`/`dateTime`/`number`/`currency` format client-side, no RPC. */
328
- format: {
329
- /** Last host format push (seeded from `__CERVIO_PLUGIN_CONTEXT__.format`). */
330
- get(): CervioUiFormatSnapshot;
331
- date(value: unknown): string;
332
- dateTime(value: unknown): string;
333
- number(value: unknown, opts?: {
334
- maxDecimals?: number;
335
- }): string;
336
- currency(value: unknown, currency?: string): string;
337
- };
338
- /** Host bottom sheet with a short list of tappable actions. */
339
- actionSheet: {
340
- open(opts: CervioUiActionSheetOpenOptions): Promise<string | null>;
341
- };
342
- /** Host file picker (pick/capture) and upload to an entity record; blobs never cross postMessage. */
343
- files: {
344
- pick(opts?: CervioUiFilesPickOptions): Promise<CervioUiFilesPickResult | null>;
345
- capture(opts?: CervioUiFilesCaptureOptions): Promise<CervioUiFilesPickResult | null>;
346
- upload(opts: CervioUiFilesUploadOptions): Promise<CervioUiFilesUploadResult>;
347
- /** Experimental: image/PDF preview dialog for a previously picked/uploaded file. */
348
- preview(opts: {
349
- fileId: string;
350
- }): Promise<{
351
- ok: true;
352
- }>;
353
- /** Experimental: v1 pass-through - resolves the same fileId, no pixel manipulation yet. */
354
- crop(opts: {
355
- fileId: string;
356
- }): Promise<string | null>;
357
- };
358
- /** Host top overlay stack of determinate/indeterminate progress bars keyed by plugin-chosen id. */
359
- progress: {
360
- show(opts: CervioUiProgressShowOptions): Promise<{
361
- ok: true;
362
- }>;
363
- update(opts: CervioUiProgressUpdateOptions): Promise<{
364
- ok: true;
365
- }>;
366
- hide(id: string): Promise<{
367
- ok: true;
368
- }>;
369
- };
370
- date: {
371
- /** Host date / datetime picker; ISO in, ISO out. */
372
- open(opts?: CervioUiDateOpenOptions): Promise<string | null>;
373
- };
374
- record: {
375
- /** Host searchable picker over records of a given entity. */
376
- pick(opts?: CervioUiRecordPickOptions): Promise<string | null>;
377
- };
378
- entity: {
379
- /** Host searchable picker over entity types visible to the caller. */
380
- pick(opts?: CervioUiEntityPickOptions): Promise<string | null>;
381
- };
382
- user: {
383
- /** Host searchable picker over organization users. */
384
- pick(opts?: CervioUiUserPickOptions): Promise<string | null>;
385
- };
386
- group: {
387
- /** Host searchable picker over organization groups. */
388
- pick(opts?: CervioUiGroupPickOptions): Promise<string | null>;
389
- };
390
- /** Host bottom sheet with title, description and a richer action variant set than `actionSheet`. */
391
- sheet: {
392
- open(opts: CervioUiSheetOpenOptions): Promise<string | null>;
393
- };
394
- /** Host-mediated clipboard write (sandboxed iframes cannot access the Clipboard API directly). */
395
- clipboard: {
396
- write(text: string): Promise<{
397
- ok: boolean;
398
- }>;
399
- };
400
- /** Host Web Share (falls back to clipboard copy when unsupported). */
401
- share: {
402
- open(opts: CervioUiShareOpenOptions): Promise<CervioUiShareResult>;
403
- };
404
- /** Host-driven print (fileId or same-origin url). */
405
- print: {
406
- open(opts: CervioUiPrintOpenOptions): Promise<{
407
- ok: true;
408
- }>;
409
- };
410
- /** Host-driven file download (fileId or same-origin url). */
411
- export: {
412
- download(opts: CervioUiExportDownloadOptions): Promise<{
413
- ok: true;
414
- }>;
415
- };
416
- /** Plugin-controlled "leave without saving?" confirmation on shell navigation / tab close. */
417
- nav: {
418
- confirmLeave(opts: CervioUiNavConfirmLeaveOptions): Promise<{
419
- ok: true;
420
- }>;
421
- };
422
- /** Experimental: host camera capture (getUserMedia), resolves a single photo file. */
423
- camera: {
424
- open(opts?: CervioUiCameraOpenOptions): Promise<CervioUiFileMeta | null>;
425
- };
426
- /** Experimental: host barcode/QR scan; rejects with `code: 'barcode_error'` on scan failure. */
427
- barcode: {
428
- scan(opts?: CervioUiBarcodeScanOptions): Promise<CervioUiBarcodeScanResult>;
429
- };
430
- /** Experimental: host geolocation lookup on explicit user action. */
431
- location: {
432
- pick(opts?: CervioUiLocationPickOptions): Promise<CervioUiLocationResult>;
433
- };
434
- /**
435
- * Contextual workflow tasks for route plugins (assignee-gated complete).
436
- * Rejects with `{ code, message }` for Unauthorized | Forbidden | task_not_open |
437
- * already_responded | reassigned | workflow_not_active | invalid_outcome |
438
- * variable_required | document_upload_required | record_link_required | in_flight.
439
- */
440
- task: {
441
- get(opts: {
442
- taskId: string;
443
- }): Promise<CervioUiTaskSummary>;
444
- complete(opts: CervioUiTaskCompleteOptions): Promise<CervioUiTaskCompleteResult>;
445
- open(opts: {
446
- taskId: string;
447
- }): Promise<CervioUiTaskOpenResult>;
448
- listForRecord(opts: {
449
- entityDataId: string;
450
- }): Promise<CervioUiTaskListItem[]>;
451
- };
452
- }
453
- declare global {
454
- interface Window {
455
- CervioUI?: CervioUI;
456
- }
457
- }
458
- /**
459
- * Returns `window.CervioUI`, throwing when it is not present (e.g. running
460
- * outside the Cervio sandbox host, or in a plain browser tab for local dev).
461
- */
462
- declare function getCervioUI(): CervioUI;
463
- /** True when the host has injected `window.CervioUI` (srcDoc sandbox). */
464
- declare function isCervioUIAvailable(): boolean;
465
- type CervioUiFrameMetricsEvent = {
466
- __cervioUI: 1;
467
- event: 'dialog.frame.metrics';
468
- open: boolean;
469
- title?: string;
470
- size?: CervioUiFrameSize;
471
- showClose?: boolean;
472
- slot?: CervioUiFrameSlot;
473
- };
474
- type CervioUiFrameClosedEvent = {
475
- __cervioUI: 1;
476
- event: 'dialog.frame.closed';
477
- reason: 'host' | 'plugin' | 'escape';
478
- };
479
- type CervioUiSurfaceOpenedEvent = {
480
- __cervioUI: 1;
481
- event: 'dialog.surface.opened';
482
- params?: unknown;
483
- };
484
- type CervioUiSurfaceMessageEvent = {
485
- __cervioUI: 1;
486
- event: 'dialog.surface.message';
487
- data: unknown;
488
- from: 'page' | 'surface';
489
- };
490
- type CervioUiSurfaceClosedEvent = {
491
- __cervioUI: 1;
492
- event: 'dialog.surface.closed';
493
- reason: 'host' | 'plugin' | 'escape';
494
- };
495
- type CervioUiHostEvent = CervioUiFrameMetricsEvent | CervioUiFrameClosedEvent | CervioUiSurfaceOpenedEvent | CervioUiSurfaceMessageEvent | CervioUiSurfaceClosedEvent;
496
-
497
- /**
498
- * Typed access to `window.__CERVIO_PLUGIN_CONTEXT__`, the boot payload the
499
- * Cervio host injects into every route plugin `srcDoc` iframe.
500
- *
501
- * Docs: https://docs.cervio.app/docs/authoring ("Auth inside the iframe", "Plugin i18n /
502
- * locale"). Field shape is set by `components/plugins/plugin-route-sandbox-host.tsx`.
503
- */
504
- interface CervioPluginRuntimeSettings {
505
- /** Locales this plugin install may use (Admin → Plugins → Impostazioni). */
506
- availableLocales?: string[];
507
- /** Used when the host locale is not in `availableLocales`. */
508
- fallbackLocale?: string;
509
- [key: string]: unknown;
510
- }
511
- interface CervioPluginContext {
512
- /** Route slug the plugin was mounted under. */
513
- routeSlug?: string;
514
- /** Per-menu-item config attached via `menu_items.plugin_context`. */
515
- pluginContext?: Record<string, unknown> | null;
516
- previewMode?: boolean;
517
- /** Logged-in Cervio UI locale (`NEXT_LOCALE`): `'it' | 'en'`. */
518
- locale?: string;
519
- /** Alias of `locale` kept for backward compatibility with early bootstraps. */
520
- userLocale?: string;
521
- mountedAt?: string;
522
- /**
523
- * Real app origin - always set by the host. Use this for API base URLs.
524
- * Never use `window.location.origin`: in sandboxed `srcDoc` iframes it
525
- * frequently serializes as the literal string `"null"`.
526
- */
527
- parentOrigin?: string;
528
- /** Parent page pathname (the iframe's own `location` is opaque). */
529
- parentPath?: string;
530
- /** Parent page search string, including leading `?` when present. */
531
- parentSearch?: string;
532
- /** Full parent `href`, for deep-linking. */
533
- parentHref?: string;
534
- pluginVersion?: string | null;
535
- pluginArtifactSha256?: string | null;
536
- pluginKey?: string | null;
537
- /** Whether the host is caching this route's `srcDoc` across soft navigations. */
538
- artifactCacheEnabled?: boolean;
539
- runtimeSettings?: CervioPluginRuntimeSettings;
540
- /** Present only inside `dist/surface.html` (dialog.surface body iframe). */
541
- cervioSurface?: boolean;
542
- [key: string]: unknown;
543
- }
544
- declare global {
545
- interface Window {
546
- __CERVIO_PLUGIN_CONTEXT__?: CervioPluginContext;
547
- /** Host-mediated top-level navigation (OAuth consent, cross-plugin deep links). */
548
- __cervioOpenExternalAuth?: (url: string) => boolean;
549
- /** Same-route query/path sync without reloading the iframe (shareable deep links). */
550
- __cervioSyncParentUrl?: (url: string, replace?: boolean) => boolean;
551
- }
552
- }
553
- /** Returns the host boot payload, or `null` outside the Cervio sandbox. */
554
- declare function getPluginContext(): CervioPluginContext | null;
555
- /** True when running inside a Cervio route plugin sandbox iframe. */
556
- declare function isInsideCervioSandbox(): boolean;
557
- /**
558
- * Navigate the real app window (top-level). Required for OAuth consent and
559
- * cross-plugin deep links: the sandboxed iframe cannot navigate `window.top`.
560
- */
561
- declare function openExternalAuth(url: string): boolean;
562
-
563
- /**
564
- * Typed access to the task-plugin boot payload + submit/draft bridge, injected
565
- * by `components/plugins/task-plugin-sandbox-host.tsx` when a human-task node
566
- * uses `taskUiMode: 'plugin'`. Shares the `window.__CERVIO_PLUGIN_CONTEXT__`
567
- * global with route plugins (never both on one page, so no collision), but
568
- * with a different shape — use these helpers rather than `getPluginContext()`.
569
- */
570
- interface CervioTaskOutcome {
571
- value: string;
572
- label: string;
573
- }
574
- interface CervioTaskPluginContextData {
575
- taskId: string;
576
- workflowInstanceId: string;
577
- entityDataId: string | null;
578
- outcomes: CervioTaskOutcome[];
579
- /** Allowlisted subset of workflow instance variables declared by the node's exposedVariables config — never the full workflow_instances.context. */
580
- instanceVariables: Record<string, unknown>;
581
- /**
582
- * The task's last `setTaskDraft()` payload (`workflow_tasks.draft_response_payload`),
583
- * or `null` when none was saved yet. Only one `TaskPluginSandboxHost` is ever
584
- * mounted at a time (compact XOR expanded modal) — switching between them
585
- * unmounts/remounts the plugin's iframe, discarding its in-memory state. A
586
- * plugin that seeds its editable fields from extraction data on every mount
587
- * (rather than from this draft first) silently reverts any edit made just
588
- * before that remount, once its own re-seed reaches the host. Read this on
589
- * mount and prefer it over re-deriving initial values from scratch.
590
- */
591
- draft: Record<string, unknown> | null;
592
- }
593
- interface CervioTaskPluginBoot {
594
- pluginType: 'task' | 'task_form';
595
- /** UI hint only: true when this is a task_form plugin on an open task the viewer may complete. Server re-checks independently on every submit. */
596
- canSubmit: boolean;
597
- pluginContext: CervioTaskPluginContextData;
598
- }
599
- interface CervioTaskSubmitResult {
600
- ok: boolean;
601
- taskCompleted?: boolean;
602
- error?: string;
603
- }
604
- interface CervioTaskDraftResult {
605
- ok: boolean;
606
- error?: string;
607
- }
608
- declare global {
609
- interface Window {
610
- __cervioTaskSetDraft?: (data: unknown) => Promise<CervioTaskDraftResult>;
611
- __cervioTaskSubmit?: (outcomeKey: string, data?: unknown) => Promise<CervioTaskSubmitResult>;
612
- }
613
- }
614
- /** Returns the task boot payload, or `null` outside a task-plugin sandbox. */
615
- declare function getTaskPluginContext(): CervioTaskPluginBoot | null;
616
- /** Incremental autosave (no completion). No-op outside a task-plugin sandbox. */
617
- declare function setTaskDraft(data: Record<string, unknown>): Promise<CervioTaskDraftResult>;
618
- /**
619
- * Completes the task with the given outcome. Only works for `task_form`
620
- * plugins — the host rejects the call server-side for plain `task` plugins.
621
- */
622
- declare function submitTaskOutcome(outcomeKey: string, data?: Record<string, unknown>): Promise<CervioTaskSubmitResult>;
623
-
624
- /**
625
- * Typed wrapper around the host's `__cervioPluginTheme` postMessage push.
626
- * The CervioUI inject script already applies host tokens to `document`
627
- * automatically (`var(--background)`, etc.) - use this only when your plugin
628
- * needs to *react* to a theme change in JS (e.g. re-render a canvas/chart).
629
- */
630
- type CervioColorScheme = 'dark' | 'light';
631
- interface CervioHostThemeMessage {
632
- __cervioPluginTheme: 1;
633
- tokens: Record<string, string>;
634
- colorScheme: CervioColorScheme;
635
- }
636
- interface CervioThemeSnapshot {
637
- tokens: Record<string, string>;
638
- colorScheme: CervioColorScheme;
639
- }
640
- type CervioThemeChangeHandler = (theme: CervioThemeSnapshot) => void;
641
- /**
642
- * Subscribe to host theme pushes. Returns an unsubscribe function.
643
- * Fires immediately with the last known theme (from `CervioUI.theme.get()`)
644
- * when available, then on every subsequent host theme change.
645
- */
646
- declare function onThemeChange(handler: CervioThemeChangeHandler): () => void;
647
- /** Last theme snapshot applied by the CervioUI inject script, if any. */
648
- declare function getCurrentTheme(): CervioThemeSnapshot | null;
649
-
650
- /**
651
- * Typed fetch wrapper around the Cervio v1 REST API (`/api/v1/*`) for route
652
- * plugins and external scripts.
653
- *
654
- * Two flavors:
655
- * - `createCervioClient` - Bearer token (PAT / OAuth2 access token).
656
- * - `createCervioSessionClient` - same-origin session cookies (typical when
657
- * running inside the Cervio app shell iframe).
658
- *
659
- * Both resolve a missing `baseUrl` from `__CERVIO_PLUGIN_CONTEXT__.parentOrigin`
660
- * - **never** from `window.location.origin`, which frequently serializes as
661
- * the literal string `"null"` inside a sandboxed `srcDoc` iframe.
662
- */
663
- interface Identity {
664
- user_id: string;
665
- organization_id: string;
666
- auth_method: 'pat' | 'oauth2' | 'supabase_jwt' | 'session';
667
- }
668
- interface Entity {
669
- id: string;
670
- name: string;
671
- label: string;
672
- description: string | null;
673
- document_management_enabled: boolean;
674
- }
675
- interface EntityCapabilities {
676
- can_read: boolean;
677
- can_create: boolean;
678
- can_update: boolean;
679
- can_delete: boolean;
680
- can_export: boolean;
681
- }
682
- interface EntityRecord {
683
- id: string;
684
- entity_id: string;
685
- data: Record<string, unknown>;
686
- }
687
- declare class CervioApiError extends Error {
688
- readonly status: number;
689
- readonly code: string;
690
- constructor(status: number, code: string, message: string);
691
- }
692
- /**
693
- * Resolve an API base URL: explicit value wins, otherwise
694
- * `__CERVIO_PLUGIN_CONTEXT__.parentOrigin`. Throws rather than silently
695
- * falling back to `location.origin` (which breaks inside `srcDoc` sandboxes).
696
- */
697
- declare function resolveApiBaseUrl(explicitBaseUrl?: string): string;
698
- type CervioClientOptions = {
699
- /** Defaults to `__CERVIO_PLUGIN_CONTEXT__.parentOrigin` when omitted. */
700
- baseUrl?: string;
701
- /** PAT (`cpat_…`) or OAuth2 access token. Read-only on writes for PAT. */
702
- token: string;
703
- fetchImpl?: typeof fetch;
704
- };
705
- type CervioSessionClientOptions = {
706
- /** Defaults to `__CERVIO_PLUGIN_CONTEXT__.parentOrigin` when omitted. */
707
- baseUrl?: string;
708
- fetchImpl?: typeof fetch;
709
- };
710
- type ExternalConnectionStatus = {
711
- connection_id: string;
712
- provider: string;
713
- connector_key: string;
714
- configured: boolean;
715
- connected: boolean;
716
- account_email: string | null;
717
- scopes: string[];
718
- allowed_apis: unknown;
719
- /** True when user has separate "product" (Profilo) connection for same builtin provider, but not this plugin's own. UX hint only, not auto-usable. */
720
- has_product_connection?: boolean;
721
- };
722
- type ExternalProxyInput = {
723
- /** Required when the manifest requirement allows more than one API host. */
724
- host?: string;
725
- method: string;
726
- path: string;
727
- query?: Record<string, string>;
728
- headers?: Record<string, string>;
729
- body?: unknown;
730
- };
731
- /** Bearer-authenticated client (PAT / OAuth2 access token). */
732
- declare function createCervioClient(opts: CervioClientOptions): {
733
- me: () => Promise<Identity>;
734
- listEntities: () => Promise<{
735
- entities: Entity[];
736
- }>;
737
- getEntity: (entityId: string) => Promise<{
738
- entity: Entity;
739
- }>;
740
- getCapabilities: (entityId: string) => Promise<{
741
- entity_id: string;
742
- capabilities: EntityCapabilities;
743
- }>;
744
- listRecords: (entityId: string, opts?: {
745
- limit?: number;
746
- offset?: number;
747
- }) => Promise<{
748
- records: EntityRecord[];
749
- }>;
750
- };
751
- type CervioClient = ReturnType<typeof createCervioClient>;
752
- /** Same-origin session cookie auth (typical inside the Cervio shell iframe). */
753
- declare function createCervioSessionClient(opts?: CervioSessionClientOptions): {
754
- me: () => Promise<Identity>;
755
- listEntities: () => Promise<{
756
- entities: Entity[];
757
- }>;
758
- getEntity: (entityId: string) => Promise<{
759
- entity: Entity;
760
- }>;
761
- getCapabilities: (entityId: string) => Promise<{
762
- entity_id: string;
763
- capabilities: EntityCapabilities;
764
- }>;
765
- listRecords: (entityId: string, opts?: {
766
- limit?: number;
767
- offset?: number;
768
- }) => Promise<{
769
- records: EntityRecord[];
770
- }>;
771
- /** External Connections - requires admin bind + `X-Cervio-Plugin-Key` (host injects on relay). */
772
- connectionStatus: (connectionId: string) => Promise<ExternalConnectionStatus>;
773
- connectionStart: (connectionId: string, returnTo?: string) => Promise<{
774
- authorizeUrl?: string;
775
- message?: string;
776
- }>;
777
- connectionProxy: <T = unknown>(connectionId: string, input: ExternalProxyInput) => Promise<T>;
778
- };
779
- type CervioSessionClient = ReturnType<typeof createCervioSessionClient>;
780
- /** Ensure user OAuth for an External Connection; opens top-level consent when needed. */
781
- declare function ensureExternalConnection(api: {
782
- connectionStatus: (id: string) => Promise<ExternalConnectionStatus>;
783
- connectionStart: (id: string, returnTo?: string) => Promise<{
784
- authorizeUrl?: string;
785
- message?: string;
786
- }>;
787
- }, connectionId: string, returnTo?: string): Promise<ExternalConnectionStatus | null>;
788
- type CervioListRecordsClient = {
789
- listRecords: (entityId: string, opts?: {
790
- limit?: number;
791
- offset?: number;
792
- }) => Promise<{
793
- records: EntityRecord[];
794
- }>;
795
- };
796
- /** Total visible records for the caller (paginates until exhausted; cap 200k). */
797
- declare function countVisibleRecords(api: CervioListRecordsClient, entityId: string, pageSize?: number): Promise<number>;
798
- /** Find an entity by technical name (case-insensitive) - prefer names over hard-coded UUIDs. */
799
- declare function findEntityByName(entities: Entity[], technicalName: string): Entity | undefined;
800
-
801
- /**
802
- * Minimal i18n helper for route plugins. Route plugins run in a sandboxed
803
- * `srcDoc` iframe: next-intl / `public/locales` are not available, so ship
804
- * your own catalogs in the ZIP and resolve the active locale from the host
805
- * bootstrap. See https://docs.cervio.app/docs/authoring → "Plugin i18n / locale".
806
- *
807
- * Resolve order (mandatory):
808
- * 1. host locale (`__CERVIO_PLUGIN_CONTEXT__.locale`), if enabled for this plugin
809
- * 2. `runtimeSettings.fallbackLocale`
810
- * 3. plugin default locale
811
- */
812
- type CervioI18nMessages = Record<string, unknown>;
813
- type CervioI18nCatalog = Record<string, CervioI18nMessages>;
814
- interface ResolvePluginLocaleOptions {
815
- /** Locales this plugin ships (message keys must exist for each). */
816
- availableLocales: string[];
817
- defaultLocale: string;
818
- }
819
- /** Resolve order only - does not read message catalogs. */
820
- declare function resolvePluginLocale(opts: ResolvePluginLocaleOptions): string;
821
- interface CreateI18nOptions {
822
- /** `{ it: { toolbar: { newEntry: '...' } }, en: { ... } }` - identical key sets. */
823
- messages: CervioI18nCatalog;
824
- defaultLocale: string;
825
- /** Defaults to `Object.keys(messages)`. */
826
- availableLocales?: string[];
827
- /** Override `Intl` locale tags (e.g. `{ it: 'it-IT' }`). */
828
- localeTags?: Record<string, string>;
829
- }
830
- interface CervioI18n {
831
- locale: string;
832
- availableLocales: string[];
833
- /** Dot-path lookup (`'toolbar.newEntry'`) with `{placeholder}` interpolation. */
834
- t: (key: string, vars?: Record<string, string | number>) => string;
835
- /** `Intl`-ready BCP 47 tag for `Intl.DateTimeFormat` / `Intl.NumberFormat`. */
836
- localeTag: (locale?: string) => string;
837
- }
838
- /** Build a small `t()` + locale resolver from bundled catalogs. */
839
- declare function createI18n(opts: CreateI18nOptions): CervioI18n;
840
-
841
- export { CERVIO_UI_API_VERSION, CervioApiError, type CervioClient, type CervioClientOptions, type CervioColorScheme, type CervioHostThemeMessage, type CervioI18n, type CervioI18nCatalog, type CervioI18nMessages, type CervioListRecordsClient, type CervioPluginContext, type CervioPluginRuntimeSettings, type CervioSessionClient, type CervioSessionClientOptions, type CervioTaskDraftResult, type CervioTaskOutcome, type CervioTaskPluginBoot, type CervioTaskPluginContextData, type CervioTaskSubmitResult, type CervioThemeChangeHandler, type CervioThemeSnapshot, type CervioUI, type CervioUiActionSheetAction, type CervioUiActionSheetOpenOptions, type CervioUiAlertOptions, type CervioUiBarcodeScanOptions, type CervioUiBarcodeScanResult, type CervioUiCameraOpenOptions, type CervioUiConfirmOptions, type CervioUiDateOpenOptions, type CervioUiDialogVariant, type CervioUiDomainPickOption, type CervioUiEntityPickOptions, type CervioUiExportDownloadOptions, type CervioUiFileMeta, type CervioUiFilesCaptureOptions, type CervioUiFilesPickOptions, type CervioUiFilesPickResult, type CervioUiFilesUploadOptions, type CervioUiFilesUploadResult, type CervioUiFormatSnapshot, type CervioUiFrameClosedEvent, type CervioUiFrameMetricsEvent, type CervioUiFrameOpenOptions, type CervioUiFrameSize, type CervioUiFrameSlot, type CervioUiGroupPickOptions, type CervioUiHostEvent, type CervioUiLocationPickOptions, type CervioUiLocationResult, type CervioUiNavConfirmLeaveOptions, type CervioUiPrintOpenOptions, type CervioUiProgressShowOptions, type CervioUiProgressUpdateOptions, type CervioUiRecordPickOptions, type CervioUiSelectOpenOptions, type CervioUiSelectOption, type CervioUiShareOpenOptions, type CervioUiShareResult, type CervioUiSheetAction, type CervioUiSheetOpenOptions, type CervioUiSurfaceClosedEvent, type CervioUiSurfaceMessageEvent, type CervioUiSurfaceOpenOptions, type CervioUiSurfaceOpenedEvent, type CervioUiTaskCompleteOptions, type CervioUiTaskCompleteResult, type CervioUiTaskListItem, type CervioUiTaskOpenResult, type CervioUiTaskOutcome, type CervioUiTaskSummary, type CervioUiThemeSnapshot, type CervioUiToastOptions, type CervioUiToastType, type CervioUiUserPickOptions, type CreateI18nOptions, type Entity, type EntityCapabilities, type EntityRecord, type ExternalConnectionStatus, type ExternalProxyInput, type Identity, type ResolvePluginLocaleOptions, countVisibleRecords, createCervioClient, createCervioSessionClient, createI18n, ensureExternalConnection, findEntityByName, getCervioUI, getCurrentTheme, getPluginContext, getTaskPluginContext, isCervioUIAvailable, isInsideCervioSandbox, onThemeChange, openExternalAuth, resolveApiBaseUrl, resolvePluginLocale, setTaskDraft, submitTaskOutcome };