@cervio/plugin-sdk 1.0.0 → 2.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/LICENSE +21 -0
- package/README.md +71 -15
- package/dist/index.d.ts +503 -38
- package/dist/index.js +72 -36
- package/dist/pdf/index.d.ts +39 -0
- package/dist/pdf/index.js +355 -0
- package/dist/policy/index.d.ts +82 -0
- package/dist/policy/index.js +25 -0
- package/package.json +54 -18
- package/dist/index.cjs +0 -274
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -442
- package/dist/index.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Publishable typed client mirroring `window.CervioUI` injected by the Cervio host.
|
|
3
|
-
* Docs: Admin
|
|
3
|
+
* Docs: https://docs.cervio.app/docs/plugins/ui (Admin Components = catalog + try-it only).
|
|
4
4
|
*
|
|
5
|
-
* `CERVIO_UI_API_VERSION` tracks the host `window.CervioUI.apiVersion`
|
|
6
|
-
*
|
|
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
7
|
*/
|
|
8
8
|
declare const CERVIO_UI_API_VERSION: "1.0.0";
|
|
9
9
|
type CervioUiToastType = 'success' | 'error' | 'warning' | 'info';
|
|
@@ -33,6 +33,11 @@ interface CervioUiFrameOpenOptions {
|
|
|
33
33
|
title?: string;
|
|
34
34
|
size?: CervioUiFrameSize;
|
|
35
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;
|
|
36
41
|
}
|
|
37
42
|
interface CervioUiSurfaceOpenOptions extends CervioUiFrameOpenOptions {
|
|
38
43
|
/** Plain JSON forwarded to `dist/surface.html` on open (max ~64KB). */
|
|
@@ -56,6 +61,214 @@ interface CervioUiThemeSnapshot {
|
|
|
56
61
|
tokens: Record<string, string>;
|
|
57
62
|
colorScheme: 'dark' | 'light';
|
|
58
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
|
+
/**
|
|
160
|
+
* ISO `yyyy-MM-dd` days greyed / unselectable in the calendar even when inside
|
|
161
|
+
* `[min, max]` (weekends, holidays, already taken, …). Max 400 entries.
|
|
162
|
+
*/
|
|
163
|
+
disabledDates?: string[];
|
|
164
|
+
/** Default true. */
|
|
165
|
+
clearable?: boolean;
|
|
166
|
+
}
|
|
167
|
+
interface CervioUiRecordPickOptions {
|
|
168
|
+
title?: string;
|
|
169
|
+
entityId?: string;
|
|
170
|
+
/** Resolved by exact match against entity name/label when `entityId` is omitted. */
|
|
171
|
+
entityName?: string;
|
|
172
|
+
value?: string;
|
|
173
|
+
/** Default true. */
|
|
174
|
+
searchable?: boolean;
|
|
175
|
+
}
|
|
176
|
+
interface CervioUiEntityPickOptions {
|
|
177
|
+
title?: string;
|
|
178
|
+
value?: string;
|
|
179
|
+
}
|
|
180
|
+
interface CervioUiUserPickOptions {
|
|
181
|
+
title?: string;
|
|
182
|
+
value?: string;
|
|
183
|
+
}
|
|
184
|
+
interface CervioUiGroupPickOptions {
|
|
185
|
+
title?: string;
|
|
186
|
+
value?: string;
|
|
187
|
+
}
|
|
188
|
+
interface CervioUiSheetOpenOptions {
|
|
189
|
+
title?: string;
|
|
190
|
+
description?: string;
|
|
191
|
+
actions: CervioUiSheetAction[];
|
|
192
|
+
}
|
|
193
|
+
/** At least one of `title`, `text`, `url` is required. */
|
|
194
|
+
interface CervioUiShareOpenOptions {
|
|
195
|
+
title?: string;
|
|
196
|
+
text?: string;
|
|
197
|
+
/** Same-origin path starting with `/` (resolved to an absolute URL by the host). */
|
|
198
|
+
url?: string;
|
|
199
|
+
}
|
|
200
|
+
type CervioUiShareResult = {
|
|
201
|
+
ok: boolean;
|
|
202
|
+
fallback?: 'clipboard';
|
|
203
|
+
};
|
|
204
|
+
/** Exactly one of `fileId` / `url` is required. */
|
|
205
|
+
interface CervioUiPrintOpenOptions {
|
|
206
|
+
fileId?: string;
|
|
207
|
+
/** Same-origin path starting with `/`. */
|
|
208
|
+
url?: string;
|
|
209
|
+
}
|
|
210
|
+
/** Exactly one of `fileId` / `url` is required. */
|
|
211
|
+
interface CervioUiExportDownloadOptions {
|
|
212
|
+
fileId?: string;
|
|
213
|
+
/** Same-origin path starting with `/`. */
|
|
214
|
+
url?: string;
|
|
215
|
+
fileName?: string;
|
|
216
|
+
}
|
|
217
|
+
interface CervioUiNavConfirmLeaveOptions {
|
|
218
|
+
enabled: boolean;
|
|
219
|
+
message?: string;
|
|
220
|
+
}
|
|
221
|
+
interface CervioUiCameraOpenOptions {
|
|
222
|
+
title?: string;
|
|
223
|
+
facing?: 'environment' | 'user';
|
|
224
|
+
}
|
|
225
|
+
interface CervioUiBarcodeScanOptions {
|
|
226
|
+
title?: string;
|
|
227
|
+
}
|
|
228
|
+
type CervioUiBarcodeScanResult = {
|
|
229
|
+
value: string;
|
|
230
|
+
format?: string;
|
|
231
|
+
} | null;
|
|
232
|
+
interface CervioUiLocationPickOptions {
|
|
233
|
+
title?: string;
|
|
234
|
+
}
|
|
235
|
+
interface CervioUiTaskOutcome {
|
|
236
|
+
value: string;
|
|
237
|
+
label: string;
|
|
238
|
+
}
|
|
239
|
+
interface CervioUiTaskSummary {
|
|
240
|
+
id: string;
|
|
241
|
+
status: string;
|
|
242
|
+
title: string;
|
|
243
|
+
outcomes: CervioUiTaskOutcome[];
|
|
244
|
+
entityDataId: string | null;
|
|
245
|
+
canComplete: boolean;
|
|
246
|
+
blockReason: string | null;
|
|
247
|
+
requiresFullView: boolean;
|
|
248
|
+
}
|
|
249
|
+
interface CervioUiTaskListItem {
|
|
250
|
+
id: string;
|
|
251
|
+
title: string;
|
|
252
|
+
outcomes: CervioUiTaskOutcome[];
|
|
253
|
+
status: string;
|
|
254
|
+
}
|
|
255
|
+
interface CervioUiTaskCompleteOptions {
|
|
256
|
+
taskId: string;
|
|
257
|
+
outcomeKey: string;
|
|
258
|
+
response?: Record<string, unknown>;
|
|
259
|
+
}
|
|
260
|
+
interface CervioUiTaskCompleteResult {
|
|
261
|
+
taskCompleted: boolean;
|
|
262
|
+
}
|
|
263
|
+
interface CervioUiTaskOpenResult {
|
|
264
|
+
completed: boolean;
|
|
265
|
+
outcomeKey?: string;
|
|
266
|
+
}
|
|
267
|
+
type CervioUiLocationResult = {
|
|
268
|
+
lat: number;
|
|
269
|
+
lng: number;
|
|
270
|
+
accuracy?: number;
|
|
271
|
+
} | null;
|
|
59
272
|
interface CervioUI {
|
|
60
273
|
apiVersion: typeof CERVIO_UI_API_VERSION;
|
|
61
274
|
capabilities(): Promise<string[]>;
|
|
@@ -88,6 +301,7 @@ interface CervioUI {
|
|
|
88
301
|
}>;
|
|
89
302
|
update(opts: {
|
|
90
303
|
title?: string;
|
|
304
|
+
height?: number;
|
|
91
305
|
}): Promise<{
|
|
92
306
|
ok: true;
|
|
93
307
|
}>;
|
|
@@ -115,6 +329,131 @@ interface CervioUI {
|
|
|
115
329
|
theme: {
|
|
116
330
|
get(): CervioUiThemeSnapshot | null;
|
|
117
331
|
};
|
|
332
|
+
/** Host locale/date/number prefs (`__cervioPluginFormat`). `date`/`dateTime`/`number`/`currency` format client-side, no RPC. */
|
|
333
|
+
format: {
|
|
334
|
+
/** Last host format push (seeded from `__CERVIO_PLUGIN_CONTEXT__.format`). */
|
|
335
|
+
get(): CervioUiFormatSnapshot;
|
|
336
|
+
date(value: unknown): string;
|
|
337
|
+
dateTime(value: unknown): string;
|
|
338
|
+
number(value: unknown, opts?: {
|
|
339
|
+
maxDecimals?: number;
|
|
340
|
+
}): string;
|
|
341
|
+
currency(value: unknown, currency?: string): string;
|
|
342
|
+
};
|
|
343
|
+
/** Host bottom sheet with a short list of tappable actions. */
|
|
344
|
+
actionSheet: {
|
|
345
|
+
open(opts: CervioUiActionSheetOpenOptions): Promise<string | null>;
|
|
346
|
+
};
|
|
347
|
+
/** Host file picker (pick/capture) and upload to an entity record; blobs never cross postMessage. */
|
|
348
|
+
files: {
|
|
349
|
+
pick(opts?: CervioUiFilesPickOptions): Promise<CervioUiFilesPickResult | null>;
|
|
350
|
+
capture(opts?: CervioUiFilesCaptureOptions): Promise<CervioUiFilesPickResult | null>;
|
|
351
|
+
upload(opts: CervioUiFilesUploadOptions): Promise<CervioUiFilesUploadResult>;
|
|
352
|
+
/** Experimental: image/PDF preview dialog for a previously picked/uploaded file. */
|
|
353
|
+
preview(opts: {
|
|
354
|
+
fileId: string;
|
|
355
|
+
}): Promise<{
|
|
356
|
+
ok: true;
|
|
357
|
+
}>;
|
|
358
|
+
/** Experimental: v1 pass-through - resolves the same fileId, no pixel manipulation yet. */
|
|
359
|
+
crop(opts: {
|
|
360
|
+
fileId: string;
|
|
361
|
+
}): Promise<string | null>;
|
|
362
|
+
};
|
|
363
|
+
/** Host top overlay stack of determinate/indeterminate progress bars keyed by plugin-chosen id. */
|
|
364
|
+
progress: {
|
|
365
|
+
show(opts: CervioUiProgressShowOptions): Promise<{
|
|
366
|
+
ok: true;
|
|
367
|
+
}>;
|
|
368
|
+
update(opts: CervioUiProgressUpdateOptions): Promise<{
|
|
369
|
+
ok: true;
|
|
370
|
+
}>;
|
|
371
|
+
hide(id: string): Promise<{
|
|
372
|
+
ok: true;
|
|
373
|
+
}>;
|
|
374
|
+
};
|
|
375
|
+
date: {
|
|
376
|
+
/** Host date / datetime picker; ISO in, ISO out. */
|
|
377
|
+
open(opts?: CervioUiDateOpenOptions): Promise<string | null>;
|
|
378
|
+
};
|
|
379
|
+
record: {
|
|
380
|
+
/** Host searchable picker over records of a given entity. */
|
|
381
|
+
pick(opts?: CervioUiRecordPickOptions): Promise<string | null>;
|
|
382
|
+
};
|
|
383
|
+
entity: {
|
|
384
|
+
/** Host searchable picker over entity types visible to the caller. */
|
|
385
|
+
pick(opts?: CervioUiEntityPickOptions): Promise<string | null>;
|
|
386
|
+
};
|
|
387
|
+
user: {
|
|
388
|
+
/** Host searchable picker over organization users. */
|
|
389
|
+
pick(opts?: CervioUiUserPickOptions): Promise<string | null>;
|
|
390
|
+
};
|
|
391
|
+
group: {
|
|
392
|
+
/** Host searchable picker over organization groups. */
|
|
393
|
+
pick(opts?: CervioUiGroupPickOptions): Promise<string | null>;
|
|
394
|
+
};
|
|
395
|
+
/** Host bottom sheet with title, description and a richer action variant set than `actionSheet`. */
|
|
396
|
+
sheet: {
|
|
397
|
+
open(opts: CervioUiSheetOpenOptions): Promise<string | null>;
|
|
398
|
+
};
|
|
399
|
+
/** Host-mediated clipboard write (sandboxed iframes cannot access the Clipboard API directly). */
|
|
400
|
+
clipboard: {
|
|
401
|
+
write(text: string): Promise<{
|
|
402
|
+
ok: boolean;
|
|
403
|
+
}>;
|
|
404
|
+
};
|
|
405
|
+
/** Host Web Share (falls back to clipboard copy when unsupported). */
|
|
406
|
+
share: {
|
|
407
|
+
open(opts: CervioUiShareOpenOptions): Promise<CervioUiShareResult>;
|
|
408
|
+
};
|
|
409
|
+
/** Host-driven print (fileId or same-origin url). */
|
|
410
|
+
print: {
|
|
411
|
+
open(opts: CervioUiPrintOpenOptions): Promise<{
|
|
412
|
+
ok: true;
|
|
413
|
+
}>;
|
|
414
|
+
};
|
|
415
|
+
/** Host-driven file download (fileId or same-origin url). */
|
|
416
|
+
export: {
|
|
417
|
+
download(opts: CervioUiExportDownloadOptions): Promise<{
|
|
418
|
+
ok: true;
|
|
419
|
+
}>;
|
|
420
|
+
};
|
|
421
|
+
/** Plugin-controlled "leave without saving?" confirmation on shell navigation / tab close. */
|
|
422
|
+
nav: {
|
|
423
|
+
confirmLeave(opts: CervioUiNavConfirmLeaveOptions): Promise<{
|
|
424
|
+
ok: true;
|
|
425
|
+
}>;
|
|
426
|
+
};
|
|
427
|
+
/** Experimental: host camera capture (getUserMedia), resolves a single photo file. */
|
|
428
|
+
camera: {
|
|
429
|
+
open(opts?: CervioUiCameraOpenOptions): Promise<CervioUiFileMeta | null>;
|
|
430
|
+
};
|
|
431
|
+
/** Experimental: host barcode/QR scan; rejects with `code: 'barcode_error'` on scan failure. */
|
|
432
|
+
barcode: {
|
|
433
|
+
scan(opts?: CervioUiBarcodeScanOptions): Promise<CervioUiBarcodeScanResult>;
|
|
434
|
+
};
|
|
435
|
+
/** Experimental: host geolocation lookup on explicit user action. */
|
|
436
|
+
location: {
|
|
437
|
+
pick(opts?: CervioUiLocationPickOptions): Promise<CervioUiLocationResult>;
|
|
438
|
+
};
|
|
439
|
+
/**
|
|
440
|
+
* Contextual workflow tasks for route plugins (assignee-gated complete).
|
|
441
|
+
* Rejects with `{ code, message }` for Unauthorized | Forbidden | task_not_open |
|
|
442
|
+
* already_responded | reassigned | workflow_not_active | invalid_outcome |
|
|
443
|
+
* variable_required | document_upload_required | record_link_required | in_flight.
|
|
444
|
+
*/
|
|
445
|
+
task: {
|
|
446
|
+
get(opts: {
|
|
447
|
+
taskId: string;
|
|
448
|
+
}): Promise<CervioUiTaskSummary>;
|
|
449
|
+
complete(opts: CervioUiTaskCompleteOptions): Promise<CervioUiTaskCompleteResult>;
|
|
450
|
+
open(opts: {
|
|
451
|
+
taskId: string;
|
|
452
|
+
}): Promise<CervioUiTaskOpenResult>;
|
|
453
|
+
listForRecord(opts: {
|
|
454
|
+
entityDataId: string;
|
|
455
|
+
}): Promise<CervioUiTaskListItem[]>;
|
|
456
|
+
};
|
|
118
457
|
}
|
|
119
458
|
declare global {
|
|
120
459
|
interface Window {
|
|
@@ -164,7 +503,7 @@ type CervioUiHostEvent = CervioUiFrameMetricsEvent | CervioUiFrameClosedEvent |
|
|
|
164
503
|
* Typed access to `window.__CERVIO_PLUGIN_CONTEXT__`, the boot payload the
|
|
165
504
|
* Cervio host injects into every route plugin `srcDoc` iframe.
|
|
166
505
|
*
|
|
167
|
-
* Docs:
|
|
506
|
+
* Docs: https://docs.cervio.app/docs/authoring ("Auth inside the iframe", "Plugin i18n /
|
|
168
507
|
* locale"). Field shape is set by `components/plugins/plugin-route-sandbox-host.tsx`.
|
|
169
508
|
*/
|
|
170
509
|
interface CervioPluginRuntimeSettings {
|
|
@@ -186,7 +525,7 @@ interface CervioPluginContext {
|
|
|
186
525
|
userLocale?: string;
|
|
187
526
|
mountedAt?: string;
|
|
188
527
|
/**
|
|
189
|
-
* Real app origin
|
|
528
|
+
* Real app origin - always set by the host. Use this for API base URLs.
|
|
190
529
|
* Never use `window.location.origin`: in sandboxed `srcDoc` iframes it
|
|
191
530
|
* frequently serializes as the literal string `"null"`.
|
|
192
531
|
*/
|
|
@@ -200,8 +539,6 @@ interface CervioPluginContext {
|
|
|
200
539
|
pluginVersion?: string | null;
|
|
201
540
|
pluginArtifactSha256?: string | null;
|
|
202
541
|
pluginKey?: string | null;
|
|
203
|
-
/** Whether the host is caching this route's `srcDoc` across soft navigations. */
|
|
204
|
-
artifactCacheEnabled?: boolean;
|
|
205
542
|
runtimeSettings?: CervioPluginRuntimeSettings;
|
|
206
543
|
/** Present only inside `dist/surface.html` (dialog.surface body iframe). */
|
|
207
544
|
cervioSurface?: boolean;
|
|
@@ -212,6 +549,9 @@ declare global {
|
|
|
212
549
|
__CERVIO_PLUGIN_CONTEXT__?: CervioPluginContext;
|
|
213
550
|
/** Host-mediated top-level navigation (OAuth consent, cross-plugin deep links). */
|
|
214
551
|
__cervioOpenExternalAuth?: (url: string) => boolean;
|
|
552
|
+
__cervioPluginReadySent?: boolean;
|
|
553
|
+
/** Same-route query/path sync without reloading the iframe (shareable deep links). */
|
|
554
|
+
__cervioSyncParentUrl?: (url: string, replace?: boolean) => boolean;
|
|
215
555
|
}
|
|
216
556
|
}
|
|
217
557
|
/** Returns the host boot payload, or `null` outside the Cervio sandbox. */
|
|
@@ -223,11 +563,78 @@ declare function isInsideCervioSandbox(): boolean;
|
|
|
223
563
|
* cross-plugin deep links: the sandboxed iframe cannot navigate `window.top`.
|
|
224
564
|
*/
|
|
225
565
|
declare function openExternalAuth(url: string): boolean;
|
|
566
|
+
/**
|
|
567
|
+
* Tell the host that the first useful content is on screen (data loaded, not
|
|
568
|
+
* just the skeleton). The host uses it to time the plugin open; calling it is
|
|
569
|
+
* optional, safe outside Cervio, and only the first call counts.
|
|
570
|
+
*/
|
|
571
|
+
declare function markReady(): void;
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Typed access to the task-plugin boot payload + submit/draft bridge, injected
|
|
575
|
+
* by `components/plugins/task-plugin-sandbox-host.tsx` when a human-task node
|
|
576
|
+
* uses `taskUiMode: 'plugin'`. Shares the `window.__CERVIO_PLUGIN_CONTEXT__`
|
|
577
|
+
* global with route plugins (never both on one page, so no collision), but
|
|
578
|
+
* with a different shape — use these helpers rather than `getPluginContext()`.
|
|
579
|
+
*/
|
|
580
|
+
interface CervioTaskOutcome {
|
|
581
|
+
value: string;
|
|
582
|
+
label: string;
|
|
583
|
+
}
|
|
584
|
+
interface CervioTaskPluginContextData {
|
|
585
|
+
taskId: string;
|
|
586
|
+
workflowInstanceId: string;
|
|
587
|
+
entityDataId: string | null;
|
|
588
|
+
outcomes: CervioTaskOutcome[];
|
|
589
|
+
/** Allowlisted subset of workflow instance variables declared by the node's exposedVariables config — never the full workflow_instances.context. */
|
|
590
|
+
instanceVariables: Record<string, unknown>;
|
|
591
|
+
/**
|
|
592
|
+
* The task's last `setTaskDraft()` payload (`workflow_tasks.draft_response_payload`),
|
|
593
|
+
* or `null` when none was saved yet. Only one `TaskPluginSandboxHost` is ever
|
|
594
|
+
* mounted at a time (compact XOR expanded modal) — switching between them
|
|
595
|
+
* unmounts/remounts the plugin's iframe, discarding its in-memory state. A
|
|
596
|
+
* plugin that seeds its editable fields from extraction data on every mount
|
|
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.
|
|
600
|
+
*/
|
|
601
|
+
draft: Record<string, unknown> | null;
|
|
602
|
+
}
|
|
603
|
+
interface CervioTaskPluginBoot {
|
|
604
|
+
pluginType: 'task' | 'task_form';
|
|
605
|
+
/** 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. */
|
|
606
|
+
canSubmit: boolean;
|
|
607
|
+
pluginContext: CervioTaskPluginContextData;
|
|
608
|
+
}
|
|
609
|
+
interface CervioTaskSubmitResult {
|
|
610
|
+
ok: boolean;
|
|
611
|
+
taskCompleted?: boolean;
|
|
612
|
+
error?: string;
|
|
613
|
+
}
|
|
614
|
+
interface CervioTaskDraftResult {
|
|
615
|
+
ok: boolean;
|
|
616
|
+
error?: string;
|
|
617
|
+
}
|
|
618
|
+
declare global {
|
|
619
|
+
interface Window {
|
|
620
|
+
__cervioTaskSetDraft?: (data: unknown) => Promise<CervioTaskDraftResult>;
|
|
621
|
+
__cervioTaskSubmit?: (outcomeKey: string, data?: unknown) => Promise<CervioTaskSubmitResult>;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
/** Returns the task boot payload, or `null` outside a task-plugin sandbox. */
|
|
625
|
+
declare function getTaskPluginContext(): CervioTaskPluginBoot | null;
|
|
626
|
+
/** Incremental autosave (no completion). No-op outside a task-plugin sandbox. */
|
|
627
|
+
declare function setTaskDraft(data: Record<string, unknown>): Promise<CervioTaskDraftResult>;
|
|
628
|
+
/**
|
|
629
|
+
* Completes the task with the given outcome. Only works for `task_form`
|
|
630
|
+
* plugins — the host rejects the call server-side for plain `task` plugins.
|
|
631
|
+
*/
|
|
632
|
+
declare function submitTaskOutcome(outcomeKey: string, data?: Record<string, unknown>): Promise<CervioTaskSubmitResult>;
|
|
226
633
|
|
|
227
634
|
/**
|
|
228
635
|
* Typed wrapper around the host's `__cervioPluginTheme` postMessage push.
|
|
229
636
|
* The CervioUI inject script already applies host tokens to `document`
|
|
230
|
-
* automatically (`var(--background)`, etc.)
|
|
637
|
+
* automatically (`var(--background)`, etc.) - use this only when your plugin
|
|
231
638
|
* needs to *react* to a theme change in JS (e.g. re-render a canvas/chart).
|
|
232
639
|
*/
|
|
233
640
|
type CervioColorScheme = 'dark' | 'light';
|
|
@@ -255,12 +662,12 @@ declare function getCurrentTheme(): CervioThemeSnapshot | null;
|
|
|
255
662
|
* plugins and external scripts.
|
|
256
663
|
*
|
|
257
664
|
* Two flavors:
|
|
258
|
-
* - `createCervioClient`
|
|
259
|
-
* - `createCervioSessionClient`
|
|
665
|
+
* - `createCervioClient` - Bearer token (PAT / OAuth2 access token).
|
|
666
|
+
* - `createCervioSessionClient` - same-origin session cookies (typical when
|
|
260
667
|
* running inside the Cervio app shell iframe).
|
|
261
668
|
*
|
|
262
669
|
* Both resolve a missing `baseUrl` from `__CERVIO_PLUGIN_CONTEXT__.parentOrigin`
|
|
263
|
-
*
|
|
670
|
+
* - **never** from `window.location.origin`, which frequently serializes as
|
|
264
671
|
* the literal string `"null"` inside a sandboxed `srcDoc` iframe.
|
|
265
672
|
*/
|
|
266
673
|
interface Identity {
|
|
@@ -287,6 +694,32 @@ interface EntityRecord {
|
|
|
287
694
|
entity_id: string;
|
|
288
695
|
data: Record<string, unknown>;
|
|
289
696
|
}
|
|
697
|
+
/** One page of `GET /api/v1/views/{viewId}/records`. */
|
|
698
|
+
interface ViewRecordsPage {
|
|
699
|
+
records: Array<{
|
|
700
|
+
id: string;
|
|
701
|
+
data: Record<string, unknown>;
|
|
702
|
+
}>;
|
|
703
|
+
page: {
|
|
704
|
+
limit: number;
|
|
705
|
+
has_more: boolean;
|
|
706
|
+
next_cursor?: string;
|
|
707
|
+
};
|
|
708
|
+
/** Content locale used for option labels. */
|
|
709
|
+
locale: string;
|
|
710
|
+
}
|
|
711
|
+
type ListViewRecordsOptions = {
|
|
712
|
+
/** Page size, 1 to 500 (default: the view's own page size). */
|
|
713
|
+
limit?: number;
|
|
714
|
+
/** `page.next_cursor` of the previous page. */
|
|
715
|
+
cursor?: string;
|
|
716
|
+
/** Option fields: `labels`, `slugs` or `both`. */
|
|
717
|
+
options?: 'labels' | 'slugs' | 'both';
|
|
718
|
+
/** Relation fields: `labels`, `uuids` or `both`. */
|
|
719
|
+
relations?: 'labels' | 'uuids' | 'both';
|
|
720
|
+
/** Content locale for option labels; must be enabled on the organization. */
|
|
721
|
+
locale?: string;
|
|
722
|
+
};
|
|
290
723
|
declare class CervioApiError extends Error {
|
|
291
724
|
readonly status: number;
|
|
292
725
|
readonly code: string;
|
|
@@ -319,6 +752,8 @@ type ExternalConnectionStatus = {
|
|
|
319
752
|
account_email: string | null;
|
|
320
753
|
scopes: string[];
|
|
321
754
|
allowed_apis: unknown;
|
|
755
|
+
/** True when user has separate "product" (Profilo) connection for same builtin provider, but not this plugin's own. UX hint only, not auto-usable. */
|
|
756
|
+
has_product_connection?: boolean;
|
|
322
757
|
};
|
|
323
758
|
type ExternalProxyInput = {
|
|
324
759
|
/** Required when the manifest requirement allows more than one API host. */
|
|
@@ -335,47 +770,83 @@ declare function createCervioClient(opts: CervioClientOptions): {
|
|
|
335
770
|
listEntities: () => Promise<{
|
|
336
771
|
entities: Entity[];
|
|
337
772
|
}>;
|
|
338
|
-
|
|
773
|
+
/** `entity`: id or technical name (e.g. `'clienti'`). */
|
|
774
|
+
getEntity: (entity: string) => Promise<{
|
|
339
775
|
entity: Entity;
|
|
340
776
|
}>;
|
|
341
|
-
|
|
777
|
+
/** `entity`: id or technical name. */
|
|
778
|
+
getCapabilities: (entity: string) => Promise<{
|
|
342
779
|
entity_id: string;
|
|
343
780
|
capabilities: EntityCapabilities;
|
|
344
781
|
}>;
|
|
345
|
-
|
|
782
|
+
/**
|
|
783
|
+
* Records of an entity, without a view. **Organization administrators only**: for
|
|
784
|
+
* other users the API answers `view_required`, so a plugin used by everyone reads
|
|
785
|
+
* records through {@link listViewRecords}. `entity`: id or technical name.
|
|
786
|
+
*/
|
|
787
|
+
listRecords: (entity: string, opts?: {
|
|
346
788
|
limit?: number;
|
|
347
789
|
offset?: number;
|
|
348
790
|
}) => Promise<{
|
|
349
791
|
records: EntityRecord[];
|
|
350
792
|
}>;
|
|
793
|
+
/**
|
|
794
|
+
* One page of records through a view assigned to the user: the view's filters,
|
|
795
|
+
* owner scope and field permissions apply. Pass `page.next_cursor` as `cursor`
|
|
796
|
+
* for the next page. Declared in the manifest `boot_requests` with the same path
|
|
797
|
+
* and query, the first page is answered at boot.
|
|
798
|
+
*/
|
|
799
|
+
listViewRecords: (viewId: string, opts?: ListViewRecordsOptions) => Promise<ViewRecordsPage>;
|
|
800
|
+
/** Number of records visible through a view, computed by the server in one call. */
|
|
801
|
+
countViewRecords: (viewId: string) => Promise<{
|
|
802
|
+
count: number;
|
|
803
|
+
}>;
|
|
351
804
|
};
|
|
352
805
|
type CervioClient = ReturnType<typeof createCervioClient>;
|
|
353
806
|
/** Same-origin session cookie auth (typical inside the Cervio shell iframe). */
|
|
354
807
|
declare function createCervioSessionClient(opts?: CervioSessionClientOptions): {
|
|
808
|
+
/** External Connections - requires admin bind + `X-Cervio-Plugin-Key` (host injects on relay). */
|
|
809
|
+
connectionStatus: (connectionId: string) => Promise<ExternalConnectionStatus>;
|
|
810
|
+
connectionStart: (connectionId: string, returnTo?: string) => Promise<{
|
|
811
|
+
authorizeUrl?: string;
|
|
812
|
+
message?: string;
|
|
813
|
+
}>;
|
|
814
|
+
connectionProxy: <T = unknown>(connectionId: string, input: ExternalProxyInput) => Promise<T>;
|
|
355
815
|
me: () => Promise<Identity>;
|
|
356
816
|
listEntities: () => Promise<{
|
|
357
817
|
entities: Entity[];
|
|
358
818
|
}>;
|
|
359
|
-
|
|
819
|
+
/** `entity`: id or technical name (e.g. `'clienti'`). */
|
|
820
|
+
getEntity: (entity: string) => Promise<{
|
|
360
821
|
entity: Entity;
|
|
361
822
|
}>;
|
|
362
|
-
|
|
823
|
+
/** `entity`: id or technical name. */
|
|
824
|
+
getCapabilities: (entity: string) => Promise<{
|
|
363
825
|
entity_id: string;
|
|
364
826
|
capabilities: EntityCapabilities;
|
|
365
827
|
}>;
|
|
366
|
-
|
|
828
|
+
/**
|
|
829
|
+
* Records of an entity, without a view. **Organization administrators only**: for
|
|
830
|
+
* other users the API answers `view_required`, so a plugin used by everyone reads
|
|
831
|
+
* records through {@link listViewRecords}. `entity`: id or technical name.
|
|
832
|
+
*/
|
|
833
|
+
listRecords: (entity: string, opts?: {
|
|
367
834
|
limit?: number;
|
|
368
835
|
offset?: number;
|
|
369
836
|
}) => Promise<{
|
|
370
837
|
records: EntityRecord[];
|
|
371
838
|
}>;
|
|
372
|
-
/**
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
839
|
+
/**
|
|
840
|
+
* One page of records through a view assigned to the user: the view's filters,
|
|
841
|
+
* owner scope and field permissions apply. Pass `page.next_cursor` as `cursor`
|
|
842
|
+
* for the next page. Declared in the manifest `boot_requests` with the same path
|
|
843
|
+
* and query, the first page is answered at boot.
|
|
844
|
+
*/
|
|
845
|
+
listViewRecords: (viewId: string, opts?: ListViewRecordsOptions) => Promise<ViewRecordsPage>;
|
|
846
|
+
/** Number of records visible through a view, computed by the server in one call. */
|
|
847
|
+
countViewRecords: (viewId: string) => Promise<{
|
|
848
|
+
count: number;
|
|
377
849
|
}>;
|
|
378
|
-
connectionProxy: <T = unknown>(connectionId: string, input: ExternalProxyInput) => Promise<T>;
|
|
379
850
|
};
|
|
380
851
|
type CervioSessionClient = ReturnType<typeof createCervioSessionClient>;
|
|
381
852
|
/** Ensure user OAuth for an External Connection; opens top-level consent when needed. */
|
|
@@ -386,24 +857,17 @@ declare function ensureExternalConnection(api: {
|
|
|
386
857
|
message?: string;
|
|
387
858
|
}>;
|
|
388
859
|
}, connectionId: string, returnTo?: string): Promise<ExternalConnectionStatus | null>;
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}) => Promise<{
|
|
394
|
-
records: EntityRecord[];
|
|
395
|
-
}>;
|
|
396
|
-
};
|
|
397
|
-
/** Total visible records for the caller (paginates until exhausted; cap 200k). */
|
|
398
|
-
declare function countVisibleRecords(api: CervioListRecordsClient, entityId: string, pageSize?: number): Promise<number>;
|
|
399
|
-
/** Find an entity by technical name (case-insensitive) — prefer names over hard-coded UUIDs. */
|
|
860
|
+
/**
|
|
861
|
+
* Find an entity by technical name (case-insensitive) - prefer names over hard-coded UUIDs.
|
|
862
|
+
* Often not needed: records / capabilities / entity calls accept the name directly.
|
|
863
|
+
*/
|
|
400
864
|
declare function findEntityByName(entities: Entity[], technicalName: string): Entity | undefined;
|
|
401
865
|
|
|
402
866
|
/**
|
|
403
867
|
* Minimal i18n helper for route plugins. Route plugins run in a sandboxed
|
|
404
868
|
* `srcDoc` iframe: next-intl / `public/locales` are not available, so ship
|
|
405
869
|
* your own catalogs in the ZIP and resolve the active locale from the host
|
|
406
|
-
* bootstrap. See
|
|
870
|
+
* bootstrap. See https://docs.cervio.app/docs/authoring → "Plugin i18n / locale".
|
|
407
871
|
*
|
|
408
872
|
* Resolve order (mandatory):
|
|
409
873
|
* 1. host locale (`__CERVIO_PLUGIN_CONTEXT__.locale`), if enabled for this plugin
|
|
@@ -417,10 +881,10 @@ interface ResolvePluginLocaleOptions {
|
|
|
417
881
|
availableLocales: string[];
|
|
418
882
|
defaultLocale: string;
|
|
419
883
|
}
|
|
420
|
-
/** Resolve order only
|
|
884
|
+
/** Resolve order only - does not read message catalogs. */
|
|
421
885
|
declare function resolvePluginLocale(opts: ResolvePluginLocaleOptions): string;
|
|
422
886
|
interface CreateI18nOptions {
|
|
423
|
-
/** `{ it: { toolbar: { newEntry: '...' } }, en: { ... } }`
|
|
887
|
+
/** `{ it: { toolbar: { newEntry: '...' } }, en: { ... } }` - identical key sets. */
|
|
424
888
|
messages: CervioI18nCatalog;
|
|
425
889
|
defaultLocale: string;
|
|
426
890
|
/** Defaults to `Object.keys(messages)`. */
|
|
@@ -439,4 +903,5 @@ interface CervioI18n {
|
|
|
439
903
|
/** Build a small `t()` + locale resolver from bundled catalogs. */
|
|
440
904
|
declare function createI18n(opts: CreateI18nOptions): CervioI18n;
|
|
441
905
|
|
|
442
|
-
export { CERVIO_UI_API_VERSION, CervioApiError,
|
|
906
|
+
export { CERVIO_UI_API_VERSION, CervioApiError, createCervioClient, createCervioSessionClient, createI18n, ensureExternalConnection, findEntityByName, getCervioUI, getCurrentTheme, getPluginContext, getTaskPluginContext, isCervioUIAvailable, isInsideCervioSandbox, markReady, onThemeChange, openExternalAuth, resolveApiBaseUrl, resolvePluginLocale, setTaskDraft, submitTaskOutcome };
|
|
907
|
+
export type { CervioClient, CervioClientOptions, CervioColorScheme, CervioHostThemeMessage, CervioI18n, CervioI18nCatalog, CervioI18nMessages, CervioPluginContext, CervioPluginRuntimeSettings, CervioSessionClient, CervioSessionClientOptions, CervioTaskDraftResult, CervioTaskOutcome, CervioTaskPluginBoot, CervioTaskPluginContextData, CervioTaskSubmitResult, CervioThemeChangeHandler, CervioThemeSnapshot, CervioUI, CervioUiActionSheetAction, CervioUiActionSheetOpenOptions, CervioUiAlertOptions, CervioUiBarcodeScanOptions, CervioUiBarcodeScanResult, CervioUiCameraOpenOptions, CervioUiConfirmOptions, CervioUiDateOpenOptions, CervioUiDialogVariant, CervioUiDomainPickOption, CervioUiEntityPickOptions, CervioUiExportDownloadOptions, CervioUiFileMeta, CervioUiFilesCaptureOptions, CervioUiFilesPickOptions, CervioUiFilesPickResult, CervioUiFilesUploadOptions, CervioUiFilesUploadResult, CervioUiFormatSnapshot, CervioUiFrameClosedEvent, CervioUiFrameMetricsEvent, CervioUiFrameOpenOptions, CervioUiFrameSize, CervioUiFrameSlot, CervioUiGroupPickOptions, CervioUiHostEvent, CervioUiLocationPickOptions, CervioUiLocationResult, CervioUiNavConfirmLeaveOptions, CervioUiPrintOpenOptions, CervioUiProgressShowOptions, CervioUiProgressUpdateOptions, CervioUiRecordPickOptions, CervioUiSelectOpenOptions, CervioUiSelectOption, CervioUiShareOpenOptions, CervioUiShareResult, CervioUiSheetAction, CervioUiSheetOpenOptions, CervioUiSurfaceClosedEvent, CervioUiSurfaceMessageEvent, CervioUiSurfaceOpenOptions, CervioUiSurfaceOpenedEvent, CervioUiTaskCompleteOptions, CervioUiTaskCompleteResult, CervioUiTaskListItem, CervioUiTaskOpenResult, CervioUiTaskOutcome, CervioUiTaskSummary, CervioUiThemeSnapshot, CervioUiToastOptions, CervioUiToastType, CervioUiUserPickOptions, CreateI18nOptions, Entity, EntityCapabilities, EntityRecord, ExternalConnectionStatus, ExternalProxyInput, Identity, ListViewRecordsOptions, ResolvePluginLocaleOptions, ViewRecordsPage };
|