@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.js
CHANGED
|
@@ -26,6 +26,35 @@ 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
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/task-context.ts
|
|
40
|
+
function getTaskPluginContext() {
|
|
41
|
+
if (typeof window === "undefined") return null;
|
|
42
|
+
const raw = window.__CERVIO_PLUGIN_CONTEXT__;
|
|
43
|
+
if (!raw || typeof raw !== "object" || typeof raw.pluginType !== "string") return null;
|
|
44
|
+
return raw;
|
|
45
|
+
}
|
|
46
|
+
async function setTaskDraft(data) {
|
|
47
|
+
if (typeof window === "undefined" || typeof window.__cervioTaskSetDraft !== "function") {
|
|
48
|
+
return { ok: false, error: "not_available" };
|
|
49
|
+
}
|
|
50
|
+
return window.__cervioTaskSetDraft(data);
|
|
51
|
+
}
|
|
52
|
+
async function submitTaskOutcome(outcomeKey, data) {
|
|
53
|
+
if (typeof window === "undefined" || typeof window.__cervioTaskSubmit !== "function") {
|
|
54
|
+
return { ok: false, error: "not_available" };
|
|
55
|
+
}
|
|
56
|
+
return window.__cervioTaskSubmit(outcomeKey, data);
|
|
57
|
+
}
|
|
29
58
|
|
|
30
59
|
// src/theme.ts
|
|
31
60
|
function isHostThemeMessage(data) {
|
|
@@ -88,6 +117,16 @@ function throwIfNotOk(res, body) {
|
|
|
88
117
|
const message = typeof body.message === "string" ? body.message : res.statusText;
|
|
89
118
|
throw new CervioApiError(res.status, code, message);
|
|
90
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
|
+
}
|
|
91
130
|
function buildRecordsQuery(opts) {
|
|
92
131
|
const params = new URLSearchParams();
|
|
93
132
|
if (opts?.limit != null) params.set("limit", String(opts.limit));
|
|
@@ -95,6 +134,35 @@ function buildRecordsQuery(opts) {
|
|
|
95
134
|
const qs = params.toString();
|
|
96
135
|
return qs ? `?${qs}` : "";
|
|
97
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
|
+
}
|
|
98
166
|
function createCervioClient(opts) {
|
|
99
167
|
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
100
168
|
const baseUrl = resolveApiBaseUrl(opts.baseUrl);
|
|
@@ -110,15 +178,7 @@ function createCervioClient(opts) {
|
|
|
110
178
|
return body;
|
|
111
179
|
}
|
|
112
180
|
return {
|
|
113
|
-
|
|
114
|
-
listEntities: () => request("/api/v1/entities"),
|
|
115
|
-
getEntity: (entityId) => request(`/api/v1/entities/${entityId}`),
|
|
116
|
-
getCapabilities: (entityId) => request(
|
|
117
|
-
`/api/v1/entities/${entityId}/capabilities`
|
|
118
|
-
),
|
|
119
|
-
listRecords: (entityId, opts2) => request(
|
|
120
|
-
`/api/v1/entities/${entityId}/records${buildRecordsQuery(opts2)}`
|
|
121
|
-
)
|
|
181
|
+
...readEndpoints(request)
|
|
122
182
|
};
|
|
123
183
|
}
|
|
124
184
|
function createCervioSessionClient(opts = {}) {
|
|
@@ -134,16 +194,8 @@ function createCervioSessionClient(opts = {}) {
|
|
|
134
194
|
return body;
|
|
135
195
|
}
|
|
136
196
|
return {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
getEntity: (entityId) => request(`/api/v1/entities/${entityId}`),
|
|
140
|
-
getCapabilities: (entityId) => request(
|
|
141
|
-
`/api/v1/entities/${entityId}/capabilities`
|
|
142
|
-
),
|
|
143
|
-
listRecords: (entityId, opts2) => request(
|
|
144
|
-
`/api/v1/entities/${entityId}/records${buildRecordsQuery(opts2)}`
|
|
145
|
-
),
|
|
146
|
-
/** External Connections — requires admin bind + `X-Cervio-Plugin-Key` (host injects on relay). */
|
|
197
|
+
...readEndpoints(request),
|
|
198
|
+
/** External Connections - requires admin bind + `X-Cervio-Plugin-Key` (host injects on relay). */
|
|
147
199
|
connectionStatus: (connectionId) => request(
|
|
148
200
|
`/api/v1/plugins/connections/${encodeURIComponent(connectionId)}/status`
|
|
149
201
|
),
|
|
@@ -183,20 +235,6 @@ async function ensureExternalConnection(api, connectionId, returnTo) {
|
|
|
183
235
|
}
|
|
184
236
|
return null;
|
|
185
237
|
}
|
|
186
|
-
var DEFAULT_PAGE = 500;
|
|
187
|
-
async function countVisibleRecords(api, entityId, pageSize = DEFAULT_PAGE) {
|
|
188
|
-
let total = 0;
|
|
189
|
-
let offset = 0;
|
|
190
|
-
const maxRows = 2e5;
|
|
191
|
-
for (; ; ) {
|
|
192
|
-
const { records } = await api.listRecords(entityId, { limit: pageSize, offset });
|
|
193
|
-
total += records.length;
|
|
194
|
-
if (records.length < pageSize) break;
|
|
195
|
-
offset += pageSize;
|
|
196
|
-
if (offset >= maxRows) break;
|
|
197
|
-
}
|
|
198
|
-
return total;
|
|
199
|
-
}
|
|
200
238
|
function findEntityByName(entities, technicalName) {
|
|
201
239
|
const n = technicalName.toLowerCase();
|
|
202
240
|
return entities.find((e) => e.name.toLowerCase() === n);
|
|
@@ -251,6 +289,4 @@ function createI18n(opts) {
|
|
|
251
289
|
return { locale, availableLocales, t, localeTag };
|
|
252
290
|
}
|
|
253
291
|
|
|
254
|
-
export { CERVIO_UI_API_VERSION, CervioApiError,
|
|
255
|
-
//# sourceMappingURL=index.js.map
|
|
256
|
-
//# 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 };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `PdfViewer`'s own chrome can't use next-intl - a plugin bundle has no
|
|
6
|
+
* `public/locales`. Small built-in catalog instead; pass `locale` to pick one
|
|
7
|
+
* (default `it`, matching the rest of this codebase's default).
|
|
8
|
+
*/
|
|
9
|
+
type PdfViewerLocale = 'it' | 'en';
|
|
10
|
+
|
|
11
|
+
interface PdfPageOverlayInfo {
|
|
12
|
+
/** 1-based page number currently rendered. */
|
|
13
|
+
page: number;
|
|
14
|
+
/** Rendered page size in CSS pixels (matches the canvas exactly). */
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
}
|
|
18
|
+
interface PdfViewerProps {
|
|
19
|
+
/** Absolute (or origin-relative) URL to the PDF - fetched directly, cross-origin, no relay. */
|
|
20
|
+
url: string;
|
|
21
|
+
/** 1-based page to jump to; only acts on change (doesn't fight manual page nav). */
|
|
22
|
+
activePage?: number | null;
|
|
23
|
+
/** Fires whenever the rendered page changes (nav buttons or `activePage`). */
|
|
24
|
+
onPageChange?: (page: number) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Renders extra content positioned over the current page, at its exact
|
|
27
|
+
* rendered size - e.g. citation/field bounding-box overlays. Sits above the
|
|
28
|
+
* text layer (`z-index`), so give interactive parts their own
|
|
29
|
+
* `pointer-events: auto` (the container itself has `pointer-events: none`
|
|
30
|
+
* so it doesn't block text selection where there's no overlay content).
|
|
31
|
+
*/
|
|
32
|
+
renderPageOverlay?: (info: PdfPageOverlayInfo) => ReactNode;
|
|
33
|
+
/** `it` (default) or `en` - see `./i18n`. */
|
|
34
|
+
locale?: PdfViewerLocale;
|
|
35
|
+
}
|
|
36
|
+
declare function PdfViewer({ url, activePage, onPageChange, renderPageOverlay, locale }: PdfViewerProps): react.JSX.Element;
|
|
37
|
+
|
|
38
|
+
export { PdfViewer };
|
|
39
|
+
export type { PdfPageOverlayInfo, PdfViewerLocale, PdfViewerProps };
|