@cervio/plugin-sdk 1.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present Cervio S.r.l.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -4,8 +4,8 @@ Typed client + runtime helpers for **Cervio route plugins**: `window.CervioUI`,
4
4
  the plugin boot context (`__CERVIO_PLUGIN_CONTEXT__`), the `/api/v1` HTTP
5
5
  client, host theme sync, and a tiny i18n resolver.
6
6
 
7
- Scaffold a new plugin with `create-cervio-plugin` (see
8
- `packages/create-cervio-plugin`) - it ships with this package pre-wired.
7
+ Scaffold a new plugin with `npm create @cervio/plugin` (package
8
+ [`@cervio/create-plugin`](../create-plugin)): it ships with this package pre-wired.
9
9
 
10
10
  ```bash
11
11
  pnpm add @cervio/plugin-sdk
@@ -13,7 +13,7 @@ pnpm add @cervio/plugin-sdk
13
13
 
14
14
  ## Why not `location.origin`?
15
15
 
16
- Route plugins run in a sandboxed `srcDoc` iframe (`sandbox="allow-scripts"`,
16
+ Route plugins run in a sandboxed iframe (`sandbox="allow-scripts"`,
17
17
  no `allow-same-origin`). `window.location.origin` frequently serializes as the
18
18
  literal string `"null"` there. Always resolve the API base URL from
19
19
  `__CERVIO_PLUGIN_CONTEXT__.parentOrigin` - every helper in this package does
@@ -47,11 +47,47 @@ console.log(ctx?.routeSlug, ctx?.parentOrigin, ctx?.runtimeSettings)
47
47
  ## HTTP client
48
48
 
49
49
  ```ts
50
- import { createCervioSessionClient } from '@cervio/plugin-sdk'
50
+ import { createCervioSessionClient, getPluginContext } from '@cervio/plugin-sdk'
51
51
 
52
52
  // baseUrl defaults to __CERVIO_PLUGIN_CONTEXT__.parentOrigin
53
53
  const client = createCervioSessionClient()
54
- const { entities } = await client.listEntities()
54
+
55
+ // Records through a view assigned to the user: its filters and permissions apply.
56
+ // Take the view id from the plugin settings, never hard-code it.
57
+ const viewId = String(getPluginContext()?.runtimeSettings?.view_id ?? '')
58
+ const { records, page } = await client.listViewRecords(viewId, { limit: 50 })
59
+ const next = page.next_cursor
60
+ ? await client.listViewRecords(viewId, { limit: 50, cursor: page.next_cursor })
61
+ : null
62
+ const { count } = await client.countViewRecords(viewId) // one call, counted by the server
63
+
64
+ // Entities by technical name: one round trip, no listEntities() first.
65
+ const { capabilities } = await client.getCapabilities('clienti')
66
+ ```
67
+
68
+ `getEntity`, `getCapabilities` and `listRecords` take the entity id **or** its
69
+ technical name. Never hard-code org-specific UUIDs.
70
+
71
+ `listRecords` (records of an entity without a view) works for organization
72
+ administrators only: for other users the API answers `view_required`. A plugin used
73
+ by everyone reads records with `listViewRecords` and counts them with
74
+ `countViewRecords`.
75
+
76
+ ### Fast start-up
77
+
78
+ - `me()` and `listEntities()` are answered from the boot payload when the manifest
79
+ declares `GET /api/v1/me` / `GET /api/v1/entities` in `cervio_apis`: no round trip.
80
+ - Declare the calls your plugin makes at start in the manifest `boot_requests`
81
+ (same path + query as the code, e.g. `/api/v1/views/<view id>/records?limit=50`):
82
+ Cervio starts them while the plugin loads and your call gets the response at once.
83
+ - Call `markReady()` once the first data is on screen:
84
+
85
+ ```ts
86
+ import { markReady } from '@cervio/plugin-sdk'
87
+
88
+ const { records } = await client.listViewRecords(viewId, { limit: 50 })
89
+ setRows(records)
90
+ markReady() // Cervio times the plugin open up to here; no-op outside Cervio
55
91
  ```
56
92
 
57
93
  `createCervioClient({ token })` is the Bearer-token equivalent (PAT / OAuth2
@@ -84,9 +120,28 @@ Resolve order: host locale (if enabled for this plugin) → `runtimeSettings.fal
84
120
  → plugin default. See [Authoring](https://docs.cervio.app/docs/authoring) → "Plugin i18n / locale" in
85
121
  the host repo for the full recipe.
86
122
 
123
+ ## Write-gate plugins (`plugin_type: policy`)
124
+
125
+ A write-gate plugin runs in a server-side isolate before a record is created or
126
+ updated and answers allow or deny. It is not a record visibility policy (those are
127
+ configured in Admin, without code). Its helpers live in a separate entry with no
128
+ browser, React or PDF code:
129
+
130
+ ```js
131
+ import { definePolicy, allow, deny } from '@cervio/plugin-sdk/policy'
132
+
133
+ export default definePolicy(async (input, host) => {
134
+ if (input.record.data.blocked) return deny('Blocked by policy', 'BLOCKED')
135
+ return allow()
136
+ })
137
+ ```
138
+
139
+ The isolate loads a single self-contained module: bundle your entry (the scaffolder's
140
+ policy template does it with esbuild) instead of shipping bare imports.
141
+
87
142
  ## Versioning
88
143
 
89
- This package version tracks `CERVIO_UI_API_VERSION` (currently `1.0.0`), the
90
- `window.CervioUI.apiVersion` contract - not semver-independent feature
91
- releases. `@cervio/plugin-core` (manifest/ZIP validation) and `@cervio/cli`
92
- version independently.
144
+ This package follows semver on its own. `CERVIO_UI_API_VERSION` (currently `1.0.0`)
145
+ is the version of the `window.CervioUI` contract offered by the host, and changes
146
+ independently of this package's version. `@cervio/plugin-core` (manifest and ZIP
147
+ validation) and `@cervio/cli` also version independently.
package/dist/index.d.ts CHANGED
@@ -156,6 +156,11 @@ interface CervioUiDateOpenOptions {
156
156
  mode?: 'date' | 'datetime';
157
157
  min?: string;
158
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[];
159
164
  /** Default true. */
160
165
  clearable?: boolean;
161
166
  }
@@ -534,8 +539,6 @@ interface CervioPluginContext {
534
539
  pluginVersion?: string | null;
535
540
  pluginArtifactSha256?: string | null;
536
541
  pluginKey?: string | null;
537
- /** Whether the host is caching this route's `srcDoc` across soft navigations. */
538
- artifactCacheEnabled?: boolean;
539
542
  runtimeSettings?: CervioPluginRuntimeSettings;
540
543
  /** Present only inside `dist/surface.html` (dialog.surface body iframe). */
541
544
  cervioSurface?: boolean;
@@ -546,6 +549,7 @@ declare global {
546
549
  __CERVIO_PLUGIN_CONTEXT__?: CervioPluginContext;
547
550
  /** Host-mediated top-level navigation (OAuth consent, cross-plugin deep links). */
548
551
  __cervioOpenExternalAuth?: (url: string) => boolean;
552
+ __cervioPluginReadySent?: boolean;
549
553
  /** Same-route query/path sync without reloading the iframe (shareable deep links). */
550
554
  __cervioSyncParentUrl?: (url: string, replace?: boolean) => boolean;
551
555
  }
@@ -559,6 +563,12 @@ declare function isInsideCervioSandbox(): boolean;
559
563
  * cross-plugin deep links: the sandboxed iframe cannot navigate `window.top`.
560
564
  */
561
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;
562
572
 
563
573
  /**
564
574
  * Typed access to the task-plugin boot payload + submit/draft bridge, injected
@@ -684,6 +694,32 @@ interface EntityRecord {
684
694
  entity_id: string;
685
695
  data: Record<string, unknown>;
686
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
+ };
687
723
  declare class CervioApiError extends Error {
688
724
  readonly status: number;
689
725
  readonly code: string;
@@ -734,47 +770,83 @@ declare function createCervioClient(opts: CervioClientOptions): {
734
770
  listEntities: () => Promise<{
735
771
  entities: Entity[];
736
772
  }>;
737
- getEntity: (entityId: string) => Promise<{
773
+ /** `entity`: id or technical name (e.g. `'clienti'`). */
774
+ getEntity: (entity: string) => Promise<{
738
775
  entity: Entity;
739
776
  }>;
740
- getCapabilities: (entityId: string) => Promise<{
777
+ /** `entity`: id or technical name. */
778
+ getCapabilities: (entity: string) => Promise<{
741
779
  entity_id: string;
742
780
  capabilities: EntityCapabilities;
743
781
  }>;
744
- listRecords: (entityId: string, opts?: {
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?: {
745
788
  limit?: number;
746
789
  offset?: number;
747
790
  }) => Promise<{
748
791
  records: EntityRecord[];
749
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
+ }>;
750
804
  };
751
805
  type CervioClient = ReturnType<typeof createCervioClient>;
752
806
  /** Same-origin session cookie auth (typical inside the Cervio shell iframe). */
753
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>;
754
815
  me: () => Promise<Identity>;
755
816
  listEntities: () => Promise<{
756
817
  entities: Entity[];
757
818
  }>;
758
- getEntity: (entityId: string) => Promise<{
819
+ /** `entity`: id or technical name (e.g. `'clienti'`). */
820
+ getEntity: (entity: string) => Promise<{
759
821
  entity: Entity;
760
822
  }>;
761
- getCapabilities: (entityId: string) => Promise<{
823
+ /** `entity`: id or technical name. */
824
+ getCapabilities: (entity: string) => Promise<{
762
825
  entity_id: string;
763
826
  capabilities: EntityCapabilities;
764
827
  }>;
765
- listRecords: (entityId: string, opts?: {
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?: {
766
834
  limit?: number;
767
835
  offset?: number;
768
836
  }) => Promise<{
769
837
  records: EntityRecord[];
770
838
  }>;
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;
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;
776
849
  }>;
777
- connectionProxy: <T = unknown>(connectionId: string, input: ExternalProxyInput) => Promise<T>;
778
850
  };
779
851
  type CervioSessionClient = ReturnType<typeof createCervioSessionClient>;
780
852
  /** Ensure user OAuth for an External Connection; opens top-level consent when needed. */
@@ -785,17 +857,10 @@ declare function ensureExternalConnection(api: {
785
857
  message?: string;
786
858
  }>;
787
859
  }, 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. */
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
+ */
799
864
  declare function findEntityByName(entities: Entity[], technicalName: string): Entity | undefined;
800
865
 
801
866
  /**
@@ -838,4 +903,5 @@ interface CervioI18n {
838
903
  /** Build a small `t()` + locale resolver from bundled catalogs. */
839
904
  declare function createI18n(opts: CreateI18nOptions): CervioI18n;
840
905
 
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 };
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 };
package/dist/index.js CHANGED
@@ -26,6 +26,15 @@ function openExternalAuth(url) {
26
26
  }
27
27
  return window.__cervioOpenExternalAuth(url);
28
28
  }
29
+ function markReady() {
30
+ if (typeof window === "undefined" || window.parent === window) return;
31
+ if (window.__cervioPluginReadySent) return;
32
+ window.__cervioPluginReadySent = true;
33
+ try {
34
+ window.parent.postMessage({ __cervioPluginReady: 1 }, "*");
35
+ } catch {
36
+ }
37
+ }
29
38
 
30
39
  // src/task-context.ts
31
40
  function getTaskPluginContext() {
@@ -108,6 +117,16 @@ function throwIfNotOk(res, body) {
108
117
  const message = typeof body.message === "string" ? body.message : res.statusText;
109
118
  throw new CervioApiError(res.status, code, message);
110
119
  }
120
+ function buildViewRecordsQuery(opts) {
121
+ const params = new URLSearchParams();
122
+ if (opts?.limit != null) params.set("limit", String(opts.limit));
123
+ if (opts?.cursor) params.set("cursor", opts.cursor);
124
+ if (opts?.options) params.set("options", opts.options);
125
+ if (opts?.relations) params.set("relations", opts.relations);
126
+ if (opts?.locale) params.set("locale", opts.locale);
127
+ const qs = params.toString();
128
+ return qs ? `?${qs}` : "";
129
+ }
111
130
  function buildRecordsQuery(opts) {
112
131
  const params = new URLSearchParams();
113
132
  if (opts?.limit != null) params.set("limit", String(opts.limit));
@@ -115,6 +134,35 @@ function buildRecordsQuery(opts) {
115
134
  const qs = params.toString();
116
135
  return qs ? `?${qs}` : "";
117
136
  }
137
+ function readEndpoints(request) {
138
+ const entityPath = (entity) => `/api/v1/entities/${encodeURIComponent(entity)}`;
139
+ const viewPath = (viewId) => `/api/v1/views/${encodeURIComponent(viewId)}`;
140
+ return {
141
+ me: () => request("/api/v1/me"),
142
+ listEntities: () => request("/api/v1/entities"),
143
+ /** `entity`: id or technical name (e.g. `'clienti'`). */
144
+ getEntity: (entity) => request(entityPath(entity)),
145
+ /** `entity`: id or technical name. */
146
+ getCapabilities: (entity) => request(
147
+ `${entityPath(entity)}/capabilities`
148
+ ),
149
+ /**
150
+ * Records of an entity, without a view. **Organization administrators only**: for
151
+ * other users the API answers `view_required`, so a plugin used by everyone reads
152
+ * records through {@link listViewRecords}. `entity`: id or technical name.
153
+ */
154
+ listRecords: (entity, opts) => request(`${entityPath(entity)}/records${buildRecordsQuery(opts)}`),
155
+ /**
156
+ * One page of records through a view assigned to the user: the view's filters,
157
+ * owner scope and field permissions apply. Pass `page.next_cursor` as `cursor`
158
+ * for the next page. Declared in the manifest `boot_requests` with the same path
159
+ * and query, the first page is answered at boot.
160
+ */
161
+ listViewRecords: (viewId, opts) => request(`${viewPath(viewId)}/records${buildViewRecordsQuery(opts)}`),
162
+ /** Number of records visible through a view, computed by the server in one call. */
163
+ countViewRecords: (viewId) => request(`${viewPath(viewId)}/records/count`)
164
+ };
165
+ }
118
166
  function createCervioClient(opts) {
119
167
  const fetchImpl = opts.fetchImpl ?? fetch;
120
168
  const baseUrl = resolveApiBaseUrl(opts.baseUrl);
@@ -130,15 +178,7 @@ function createCervioClient(opts) {
130
178
  return body;
131
179
  }
132
180
  return {
133
- me: () => request("/api/v1/me"),
134
- listEntities: () => request("/api/v1/entities"),
135
- getEntity: (entityId) => request(`/api/v1/entities/${entityId}`),
136
- getCapabilities: (entityId) => request(
137
- `/api/v1/entities/${entityId}/capabilities`
138
- ),
139
- listRecords: (entityId, opts2) => request(
140
- `/api/v1/entities/${entityId}/records${buildRecordsQuery(opts2)}`
141
- )
181
+ ...readEndpoints(request)
142
182
  };
143
183
  }
144
184
  function createCervioSessionClient(opts = {}) {
@@ -154,15 +194,7 @@ function createCervioSessionClient(opts = {}) {
154
194
  return body;
155
195
  }
156
196
  return {
157
- me: () => request("/api/v1/me"),
158
- listEntities: () => request("/api/v1/entities"),
159
- getEntity: (entityId) => request(`/api/v1/entities/${entityId}`),
160
- getCapabilities: (entityId) => request(
161
- `/api/v1/entities/${entityId}/capabilities`
162
- ),
163
- listRecords: (entityId, opts2) => request(
164
- `/api/v1/entities/${entityId}/records${buildRecordsQuery(opts2)}`
165
- ),
197
+ ...readEndpoints(request),
166
198
  /** External Connections - requires admin bind + `X-Cervio-Plugin-Key` (host injects on relay). */
167
199
  connectionStatus: (connectionId) => request(
168
200
  `/api/v1/plugins/connections/${encodeURIComponent(connectionId)}/status`
@@ -203,20 +235,6 @@ async function ensureExternalConnection(api, connectionId, returnTo) {
203
235
  }
204
236
  return null;
205
237
  }
206
- var DEFAULT_PAGE = 500;
207
- async function countVisibleRecords(api, entityId, pageSize = DEFAULT_PAGE) {
208
- let total = 0;
209
- let offset = 0;
210
- const maxRows = 2e5;
211
- for (; ; ) {
212
- const { records } = await api.listRecords(entityId, { limit: pageSize, offset });
213
- total += records.length;
214
- if (records.length < pageSize) break;
215
- offset += pageSize;
216
- if (offset >= maxRows) break;
217
- }
218
- return total;
219
- }
220
238
  function findEntityByName(entities, technicalName) {
221
239
  const n = technicalName.toLowerCase();
222
240
  return entities.find((e) => e.name.toLowerCase() === n);
@@ -271,6 +289,4 @@ function createI18n(opts) {
271
289
  return { locale, availableLocales, t, localeTag };
272
290
  }
273
291
 
274
- export { CERVIO_UI_API_VERSION, CervioApiError, countVisibleRecords, createCervioClient, createCervioSessionClient, createI18n, ensureExternalConnection, findEntityByName, getCervioUI, getCurrentTheme, getPluginContext, getTaskPluginContext, isCervioUIAvailable, isInsideCervioSandbox, onThemeChange, openExternalAuth, resolveApiBaseUrl, resolvePluginLocale, setTaskDraft, submitTaskOutcome };
275
- //# sourceMappingURL=index.js.map
276
- //# sourceMappingURL=index.js.map
292
+ export { CERVIO_UI_API_VERSION, CervioApiError, createCervioClient, createCervioSessionClient, createI18n, ensureExternalConnection, findEntityByName, getCervioUI, getCurrentTheme, getPluginContext, getTaskPluginContext, isCervioUIAvailable, isInsideCervioSandbox, markReady, onThemeChange, openExternalAuth, resolveApiBaseUrl, resolvePluginLocale, setTaskDraft, submitTaskOutcome };
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
1
+ import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
 
4
4
  /**
@@ -33,6 +33,7 @@ interface PdfViewerProps {
33
33
  /** `it` (default) or `en` - see `./i18n`. */
34
34
  locale?: PdfViewerLocale;
35
35
  }
36
- declare function PdfViewer({ url, activePage, onPageChange, renderPageOverlay, locale }: PdfViewerProps): react_jsx_runtime.JSX.Element;
36
+ declare function PdfViewer({ url, activePage, onPageChange, renderPageOverlay, locale }: PdfViewerProps): react.JSX.Element;
37
37
 
38
- export { type PdfPageOverlayInfo, PdfViewer, type PdfViewerLocale, type PdfViewerProps };
38
+ export { PdfViewer };
39
+ export type { PdfPageOverlayInfo, PdfViewerLocale, PdfViewerProps };