@selfhelp/shared 1.29.0 → 1.31.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/CHANGELOG.md +83 -0
- package/dist/index.d.mts +35 -85
- package/dist/index.d.ts +35 -85
- package/dist/index.js +18 -5
- package/dist/index.mjs +15 -5
- package/dist/inlineFormat-Duu5VLMU.d.mts +73 -0
- package/dist/inlineFormat-Duu5VLMU.d.ts +73 -0
- package/dist/{manifest-BNnCN1Qo.d.mts → manifest-DWHD0PQA.d.mts} +168 -1
- package/dist/{manifest-BNnCN1Qo.d.ts → manifest-DWHD0PQA.d.ts} +168 -1
- package/dist/plugin-sdk/index.d.mts +260 -7
- package/dist/plugin-sdk/index.d.ts +260 -7
- package/dist/plugin-sdk/index.js +174 -2
- package/dist/plugin-sdk/index.mjs +171 -2
- package/dist/plugin-sdk/sync-map.d.mts +22 -0
- package/dist/plugin-sdk/sync-map.d.ts +22 -0
- package/dist/plugin-sdk/sync-map.js +58 -0
- package/dist/plugin-sdk/sync-map.mjs +33 -0
- package/dist/registry/index.d.mts +2 -2
- package/dist/registry/index.d.ts +2 -2
- package/dist/{styles.registry-DnIJqEzM.d.mts → styles.registry-B2cyNdo3.d.mts} +26 -1
- package/dist/{styles.registry-C2ACy7H0.d.ts → styles.registry-G_KUYGPv.d.ts} +26 -1
- package/dist/testing/index.d.mts +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/package.json +3 -3
- package/src/content/__tests__/languageIndependent.test.ts +26 -0
- package/src/content/__tests__/languageIndependentLiteral.test.ts +62 -0
- package/src/content/formRecordPrefill.ts +9 -7
- package/src/content/index.ts +1 -0
- package/src/content/languageIndependent.ts +28 -0
- package/src/plugin-sdk/__tests__/define-sync.test.ts +106 -0
- package/src/plugin-sdk/__tests__/exports.test.ts +29 -0
- package/src/plugin-sdk/__tests__/host-services.test.ts +96 -6
- package/src/plugin-sdk/__tests__/sync-map.test.ts +48 -0
- package/src/plugin-sdk/__tests__/version.test.ts +9 -0
- package/src/plugin-sdk/host-services.ts +106 -0
- package/src/plugin-sdk/index.ts +31 -0
- package/src/plugin-sdk/manifest.ts +193 -0
- package/src/plugin-sdk/sync-map.ts +61 -0
- package/src/plugin-sdk/types.ts +142 -2
- package/src/plugin-sdk/version.ts +19 -2
- package/src/sync/__tests__/sync.test.ts +19 -0
- package/src/sync/sync.ts +3 -2
- package/src/sync/types.ts +9 -6
- package/src/types/api/form-lists.ts +16 -1
- package/src/types/api/forms.ts +10 -0
|
@@ -163,6 +163,17 @@ export interface IPluginManifestPermission {
|
|
|
163
163
|
defaultRoles?: string[];
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
/** A field linked to a plugin style, with its editor metadata. */
|
|
167
|
+
export interface IPluginManifestStyleField {
|
|
168
|
+
/** A field of the plugin (`fields`) or a core field such as `own_entries_only`. */
|
|
169
|
+
name: string;
|
|
170
|
+
title?: string;
|
|
171
|
+
help?: string;
|
|
172
|
+
default?: string | null;
|
|
173
|
+
hidden?: boolean;
|
|
174
|
+
disabled?: boolean;
|
|
175
|
+
}
|
|
176
|
+
|
|
166
177
|
export interface IPluginManifestStyle {
|
|
167
178
|
/** Style name (used as `style_name` discriminator). */
|
|
168
179
|
name: string;
|
|
@@ -170,6 +181,43 @@ export interface IPluginManifestStyle {
|
|
|
170
181
|
canHaveChildren: boolean;
|
|
171
182
|
/** Optional capability requirement (e.g. `frontendStyles`). */
|
|
172
183
|
capability?: IPluginManifestCapability;
|
|
184
|
+
/** Style group name; required when the installer creates the style. */
|
|
185
|
+
group?: string;
|
|
186
|
+
/** Earlier names of this style; the installer renames the row in place. */
|
|
187
|
+
renamedFrom?: string[];
|
|
188
|
+
/** When present, the installer makes the style's field links match this list. */
|
|
189
|
+
fields?: IPluginManifestStyleField[];
|
|
190
|
+
/**
|
|
191
|
+
* Field name → registered resource type of this plugin (`resourceTypes`
|
|
192
|
+
* lookup). The field must be declared for the style. Needs `pluginApiVersion`
|
|
193
|
+
* >= 0.2.0.
|
|
194
|
+
*/
|
|
195
|
+
resourceFields?: Record<string, string>;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Style group written into `style_groups` by the host installer (rule 7.8). */
|
|
199
|
+
export interface IPluginManifestStyleGroup {
|
|
200
|
+
name: string;
|
|
201
|
+
description?: string;
|
|
202
|
+
position?: number;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Field type (editor control) written into `field_types`; kebab-case name. */
|
|
206
|
+
export interface IPluginManifestFieldType {
|
|
207
|
+
name: string;
|
|
208
|
+
position?: number;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Plugin-owned field written into `fields`; snake_case name. */
|
|
212
|
+
export interface IPluginManifestField {
|
|
213
|
+
name: string;
|
|
214
|
+
/** A core field type or one declared under `fieldTypes`. */
|
|
215
|
+
type: string;
|
|
216
|
+
/** True for participant-facing content stored per language. */
|
|
217
|
+
translatable?: boolean;
|
|
218
|
+
config?: Record<string, unknown> | null;
|
|
219
|
+
/** Earlier names of this field; the installer renames the row in place. */
|
|
220
|
+
renamedFrom?: string[];
|
|
173
221
|
}
|
|
174
222
|
|
|
175
223
|
export interface IPluginManifestAdminPage {
|
|
@@ -200,12 +248,112 @@ export interface IPluginManifestApiRoute {
|
|
|
200
248
|
public?: boolean;
|
|
201
249
|
}
|
|
202
250
|
|
|
251
|
+
/**
|
|
252
|
+
* Inline JSON Schema for an action-plannable plugin job config. Allowed property
|
|
253
|
+
* types are `string`, `integer`, `number` and `boolean`; nesting is not allowed.
|
|
254
|
+
* `format: "variable-text"` marks a string that accepts `{{variables}}`.
|
|
255
|
+
*/
|
|
256
|
+
export interface IPluginManifestJobConfigSchema {
|
|
257
|
+
type: 'object';
|
|
258
|
+
properties?: Record<string, IPluginManifestJobConfigProperty>;
|
|
259
|
+
required?: string[];
|
|
260
|
+
additionalProperties?: boolean;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export interface IPluginManifestJobConfigProperty {
|
|
264
|
+
type: 'string' | 'integer' | 'number' | 'boolean';
|
|
265
|
+
enum?: Array<string | number | boolean>;
|
|
266
|
+
minimum?: number;
|
|
267
|
+
maximum?: number;
|
|
268
|
+
maxLength?: number;
|
|
269
|
+
title?: string;
|
|
270
|
+
description?: string;
|
|
271
|
+
default?: string | number | boolean;
|
|
272
|
+
/** Marks a string that accepts `{{variables}}` when the action plans the job. */
|
|
273
|
+
format?: 'variable-text';
|
|
274
|
+
}
|
|
275
|
+
|
|
203
276
|
export interface IPluginManifestScheduledJob {
|
|
204
277
|
/** Job type key. */
|
|
205
278
|
type: string;
|
|
206
279
|
description: string;
|
|
207
280
|
/** Capability gate (always requires `scheduledJobs`). */
|
|
208
281
|
capability: 'scheduledJobs';
|
|
282
|
+
/** Required when `actionPlannable` is true. Shown in the action builder. */
|
|
283
|
+
label?: string;
|
|
284
|
+
/** When true, editors may plan this job type in an action. Default false. */
|
|
285
|
+
actionPlannable?: boolean;
|
|
286
|
+
/** Inline JSON Schema for `plugin_config` when the job is planned from an action. */
|
|
287
|
+
configSchema?: IPluginManifestJobConfigSchema;
|
|
288
|
+
/** Config property → registered resource type of this plugin. */
|
|
289
|
+
resourceFields?: Record<string, string>;
|
|
290
|
+
/** Child-process timeout in seconds (10 to 900). Default 120. */
|
|
291
|
+
timeoutSeconds?: number;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Cache category declared by a plugin; stored as `<plugin id>.<name>`. */
|
|
295
|
+
export interface IPluginManifestCacheCategory {
|
|
296
|
+
/** `^[a-z][a-z0-9_]{0,40}$`. */
|
|
297
|
+
name: string;
|
|
298
|
+
/** Lifetime in seconds (60 to 86400). */
|
|
299
|
+
ttlSeconds: number;
|
|
300
|
+
description?: string;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** Instance setting declared by a plugin; stored by the host (C14). */
|
|
304
|
+
export interface IPluginManifestSetting {
|
|
305
|
+
/** `^[a-z][a-z0-9_]{0,63}$`. */
|
|
306
|
+
key: string;
|
|
307
|
+
label: string;
|
|
308
|
+
type: 'string' | 'number' | 'boolean' | 'url';
|
|
309
|
+
/** Default false. Secrets are encrypted at rest and never returned clear. */
|
|
310
|
+
secret?: boolean;
|
|
311
|
+
/** Default false. */
|
|
312
|
+
required?: boolean;
|
|
313
|
+
/** Not allowed when `secret` is true. */
|
|
314
|
+
default?: string | number | boolean;
|
|
315
|
+
/** `^[A-Z][A-Z0-9_]{2,63}$`, unique across enabled plugins. */
|
|
316
|
+
envOverride?: string;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/** Rate limit declared by a plugin (C15). */
|
|
320
|
+
export interface IPluginManifestRateLimit {
|
|
321
|
+
/** `^[a-z][a-z0-9_]{0,40}$`. */
|
|
322
|
+
name: string;
|
|
323
|
+
policy: 'sliding_window' | 'fixed_window';
|
|
324
|
+
/** 1 to 100000. */
|
|
325
|
+
limit: number;
|
|
326
|
+
/** Symfony rate-limiter interval string (e.g. `1 minute`). */
|
|
327
|
+
interval: string;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** JSON Logic operation declared by a plugin (C16). */
|
|
331
|
+
export interface IPluginManifestJsonLogicOperation {
|
|
332
|
+
/** `^[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*$`; the namespace belongs to one plugin. */
|
|
333
|
+
name: string;
|
|
334
|
+
description: string;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* After-commit domain events a plugin may listen to (C24). Must match the host
|
|
339
|
+
* event names exactly.
|
|
340
|
+
*/
|
|
341
|
+
export type TPluginDomainEventName =
|
|
342
|
+
| 'record.saved'
|
|
343
|
+
| 'record.deleted'
|
|
344
|
+
| 'user.created'
|
|
345
|
+
| 'user.deleted'
|
|
346
|
+
| 'page.published';
|
|
347
|
+
|
|
348
|
+
/** Recurring plugin job (C25). `type` must be one of the plugin's `scheduledJobs`. */
|
|
349
|
+
export interface IPluginManifestRecurringJob {
|
|
350
|
+
/** `^[a-z][a-z0-9_]{0,40}$`. */
|
|
351
|
+
name: string;
|
|
352
|
+
/** One of this plugin's `scheduledJobs[].type`. */
|
|
353
|
+
type: string;
|
|
354
|
+
/** Five-field cron, UTC, at least 5 minutes apart. */
|
|
355
|
+
cron: string;
|
|
356
|
+
description: string;
|
|
209
357
|
}
|
|
210
358
|
|
|
211
359
|
export interface IPluginManifestAsset {
|
|
@@ -302,6 +450,15 @@ export interface IPluginManifest {
|
|
|
302
450
|
/** Styles contributed to the registry. */
|
|
303
451
|
styles?: IPluginManifestStyle[];
|
|
304
452
|
|
|
453
|
+
/** Style groups the host installer writes (rule 7.8). */
|
|
454
|
+
styleGroups?: IPluginManifestStyleGroup[];
|
|
455
|
+
|
|
456
|
+
/** Field types the host installer writes (rule 7.8). */
|
|
457
|
+
fieldTypes?: IPluginManifestFieldType[];
|
|
458
|
+
|
|
459
|
+
/** Plugin-owned fields the host installer writes (rule 7.8). */
|
|
460
|
+
fields?: IPluginManifestField[];
|
|
461
|
+
|
|
305
462
|
/** Admin pages mounted under `/admin/plugins-host/{pluginId}/`. */
|
|
306
463
|
adminPages?: IPluginManifestAdminPage[];
|
|
307
464
|
|
|
@@ -311,6 +468,42 @@ export interface IPluginManifest {
|
|
|
311
468
|
/** Scheduled jobs. */
|
|
312
469
|
scheduledJobs?: IPluginManifestScheduledJob[];
|
|
313
470
|
|
|
471
|
+
/**
|
|
472
|
+
* Cache categories the host registers for this plugin (C4). Needs
|
|
473
|
+
* `pluginApiVersion` >= 0.2.0.
|
|
474
|
+
*/
|
|
475
|
+
cacheCategories?: IPluginManifestCacheCategory[];
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Instance settings and secrets stored by the host (C14). Needs
|
|
479
|
+
* `pluginApiVersion` >= 0.2.0.
|
|
480
|
+
*/
|
|
481
|
+
settings?: IPluginManifestSetting[];
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Rate limits the host builds for this plugin (C15). Needs
|
|
485
|
+
* `pluginApiVersion` >= 0.2.0.
|
|
486
|
+
*/
|
|
487
|
+
rateLimits?: IPluginManifestRateLimit[];
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* JSON Logic operations the host registers for conditions (C16). Needs
|
|
491
|
+
* `pluginApiVersion` >= 0.2.0.
|
|
492
|
+
*/
|
|
493
|
+
jsonLogicOperations?: IPluginManifestJsonLogicOperation[];
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* After-commit domain events this plugin's listeners receive (C24). Needs
|
|
497
|
+
* `pluginApiVersion` >= 0.2.0.
|
|
498
|
+
*/
|
|
499
|
+
listens?: TPluginDomainEventName[];
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Recurring jobs the host keeps queued while the plugin is enabled (C25).
|
|
503
|
+
* Needs `pluginApiVersion` >= 0.2.0.
|
|
504
|
+
*/
|
|
505
|
+
recurringJobs?: IPluginManifestRecurringJob[];
|
|
506
|
+
|
|
314
507
|
/** Vendored assets. */
|
|
315
508
|
assets?: IPluginManifestAsset[];
|
|
316
509
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Declarative plugin sync map (contract C10).
|
|
7
|
+
*
|
|
8
|
+
* A plugin lists tags (exact, or a prefix ending in `*`) and the React Query
|
|
9
|
+
* key each tag should invalidate. Hosts call {@link matchPluginSyncEntries}
|
|
10
|
+
* from `applySyncTags` and invalidate each returned key as a prefix.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** One entry of a plugin's optional `sync` map. */
|
|
14
|
+
export interface IPluginSyncEntry {
|
|
15
|
+
/** Exact tags, or a prefix ending in `*` (`res:surveyjs_survey:*`, `table:*`). */
|
|
16
|
+
tags: string[];
|
|
17
|
+
/** React Query key the host invalidates as a prefix when a listed tag matches. */
|
|
18
|
+
queryKey: readonly unknown[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns the unique `queryKey` values whose `tags` match any of the message
|
|
23
|
+
* tags. A pattern ending in `*` matches by prefix; every other tag must equal.
|
|
24
|
+
* Uniqueness is by `JSON.stringify(queryKey)`.
|
|
25
|
+
*/
|
|
26
|
+
export function matchPluginSyncEntries(
|
|
27
|
+
entries: readonly IPluginSyncEntry[] | null | undefined,
|
|
28
|
+
tags: readonly string[],
|
|
29
|
+
): readonly unknown[][] {
|
|
30
|
+
if (!entries?.length || tags.length === 0) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const seen = new Set<string>();
|
|
35
|
+
const keys: unknown[][] = [];
|
|
36
|
+
|
|
37
|
+
for (const entry of entries) {
|
|
38
|
+
if (!entry.tags?.length || !Array.isArray(entry.queryKey)) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const matched = tags.some((tag) => entry.tags.some((pattern) => tagMatchesPattern(tag, pattern)));
|
|
42
|
+
if (!matched) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const serialized = JSON.stringify(entry.queryKey);
|
|
46
|
+
if (seen.has(serialized)) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
seen.add(serialized);
|
|
50
|
+
keys.push(entry.queryKey.slice());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return keys;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function tagMatchesPattern(tag: string, pattern: string): boolean {
|
|
57
|
+
if (pattern.endsWith('*')) {
|
|
58
|
+
return tag.startsWith(pattern.slice(0, -1));
|
|
59
|
+
}
|
|
60
|
+
return tag === pattern;
|
|
61
|
+
}
|
package/src/plugin-sdk/types.ts
CHANGED
|
@@ -17,6 +17,8 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
17
17
|
|
|
18
18
|
import type { IStyleRegistryEntry } from '../registry/styles.registry';
|
|
19
19
|
|
|
20
|
+
import type { IPluginSyncEntry } from './sync-map';
|
|
21
|
+
|
|
20
22
|
/**
|
|
21
23
|
* Generic component renderer. We avoid pulling in React types here to
|
|
22
24
|
* keep the SDK framework-agnostic; the runtime casts to the appropriate
|
|
@@ -24,6 +26,42 @@ import type { IStyleRegistryEntry } from '../registry/styles.registry';
|
|
|
24
26
|
*/
|
|
25
27
|
export type TPluginComponent<TProps = unknown> = (props: TProps) => unknown;
|
|
26
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Where a plugin item is used (C7). Pages the caller may not read are counted
|
|
31
|
+
* only in `hidden_count`.
|
|
32
|
+
*/
|
|
33
|
+
export interface IResourceUsage {
|
|
34
|
+
pages: Array<{
|
|
35
|
+
id: number;
|
|
36
|
+
keyword: string;
|
|
37
|
+
title: string | null;
|
|
38
|
+
draft_uses: boolean;
|
|
39
|
+
published_uses: boolean;
|
|
40
|
+
}>;
|
|
41
|
+
actions: Array<{ id: number; name: string }>;
|
|
42
|
+
hidden_count: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* One item of `GET /admin/plugins/{pluginId}/settings` (C14). Secrets never
|
|
47
|
+
* carry a clear `value`; `hint` is the last 4 characters when the secret is
|
|
48
|
+
* long enough, otherwise null.
|
|
49
|
+
*/
|
|
50
|
+
export interface IPluginSettingViewItem {
|
|
51
|
+
key: string;
|
|
52
|
+
label: string;
|
|
53
|
+
type: 'string' | 'number' | 'boolean' | 'url';
|
|
54
|
+
secret: boolean;
|
|
55
|
+
required: boolean;
|
|
56
|
+
has_value: boolean;
|
|
57
|
+
value: string | number | boolean | null;
|
|
58
|
+
hint: string | null;
|
|
59
|
+
overridden_by_env: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The C14 GET settings list for one plugin. */
|
|
63
|
+
export type IPluginSettingsView = IPluginSettingViewItem[];
|
|
64
|
+
|
|
27
65
|
/**
|
|
28
66
|
* Definition of a CMS style contributed by a plugin.
|
|
29
67
|
*/
|
|
@@ -40,6 +78,52 @@ export interface IStyleDefinition extends Omit<IStyleRegistryEntry, 'category'>
|
|
|
40
78
|
component: TPluginComponent;
|
|
41
79
|
}
|
|
42
80
|
|
|
81
|
+
/**
|
|
82
|
+
* The popup a page is shown in, as the host sees it. Outside a popup
|
|
83
|
+
* `inModal` is false and `closeModal()` does nothing, so a plugin can call
|
|
84
|
+
* it unconditionally (for example after a save, like the core form's
|
|
85
|
+
* `close_modal_on_save`).
|
|
86
|
+
*/
|
|
87
|
+
export interface IPluginPageModal {
|
|
88
|
+
inModal: boolean;
|
|
89
|
+
closeModal: () => void;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The page a plugin section is drawn on. A plugin endpoint that serves or
|
|
94
|
+
* accepts data for the section names the page and the section in every call
|
|
95
|
+
* (with this language, preview state and route), so the server can check
|
|
96
|
+
* access and read the section's settings itself (rule 7.7), like the core
|
|
97
|
+
* form and form list do.
|
|
98
|
+
*/
|
|
99
|
+
export interface IPluginStylePage {
|
|
100
|
+
/** Page id; null while the page content is not known yet. */
|
|
101
|
+
id: number | null;
|
|
102
|
+
languageId: number | null;
|
|
103
|
+
/** Whether the page is shown as the editor's draft (preview mode). */
|
|
104
|
+
preview: boolean;
|
|
105
|
+
/** The page's declared route parameters (`page.route_params`). */
|
|
106
|
+
routeParams: Record<string, string>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Props the host passes to a plugin style component (the `component` of an
|
|
111
|
+
* {@link IStyleDefinition}). `style` is the section as the page payload
|
|
112
|
+
* carries it (fields keyed by name).
|
|
113
|
+
*/
|
|
114
|
+
export interface IPluginStyleProps {
|
|
115
|
+
style: Record<string, unknown>;
|
|
116
|
+
styleProps: Record<string, string>;
|
|
117
|
+
cssClass: string;
|
|
118
|
+
parentActive?: number;
|
|
119
|
+
childIndex?: number;
|
|
120
|
+
parentColor?: string;
|
|
121
|
+
/** The popup the page is shown in; a no-op outside one. */
|
|
122
|
+
pageModal: IPluginPageModal;
|
|
123
|
+
/** The page the section is on, to name in plugin calls. */
|
|
124
|
+
page: IPluginStylePage;
|
|
125
|
+
}
|
|
126
|
+
|
|
43
127
|
/**
|
|
44
128
|
* Props passed by the host's section-field editor to a plugin-supplied
|
|
45
129
|
* field renderer. The host owns the surrounding label / help tooltip /
|
|
@@ -246,6 +330,40 @@ export interface IPluginApi {
|
|
|
246
330
|
realtime?: IPluginRealtimePublisher;
|
|
247
331
|
/** Host rich-text editor adapter. */
|
|
248
332
|
richTextEditor: IRichTextEditorAdapter;
|
|
333
|
+
/**
|
|
334
|
+
* The host's HTML sanitizer, with the same rules core pages use (web:
|
|
335
|
+
* DOMPurify, plus the host's link rewrites). Call it before rendering any
|
|
336
|
+
* CMS or user HTML; never bundle a sanitizer of your own. `inline` keeps
|
|
337
|
+
* inline markup only, `block` also keeps headings, lists and paragraphs.
|
|
338
|
+
*/
|
|
339
|
+
sanitizeHtml(html: string, mode: 'inline' | 'block'): string;
|
|
340
|
+
/**
|
|
341
|
+
* CSS selector for a rendered section element (C23). Returns
|
|
342
|
+
* `.section-<id>`. Web only.
|
|
343
|
+
*/
|
|
344
|
+
sectionAnchor(sectionId: number): string;
|
|
345
|
+
/** Where-used for a plugin item the caller may view (C7, C11). */
|
|
346
|
+
resources: {
|
|
347
|
+
usage(type: string, id: number): Promise<IResourceUsage>;
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* Optional host UI parts. `ResourceUsageList` is offered when the host
|
|
351
|
+
* ships a shared where-used list for delete warnings.
|
|
352
|
+
*/
|
|
353
|
+
ui?: {
|
|
354
|
+
ResourceUsageList: TPluginComponent<{
|
|
355
|
+
type: string;
|
|
356
|
+
id: number;
|
|
357
|
+
warnBeforeDelete?: boolean;
|
|
358
|
+
}>;
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* This plugin's settings as the host stores them (C14). Secrets show
|
|
362
|
+
* `has_value` only; clear values are never returned for secrets.
|
|
363
|
+
*/
|
|
364
|
+
settings: {
|
|
365
|
+
get(): Promise<IPluginSettingsView>;
|
|
366
|
+
};
|
|
249
367
|
/**
|
|
250
368
|
* Logger that respects the host's debug config. Avoid `console.log`
|
|
251
369
|
* in plugin code; route everything through this.
|
|
@@ -260,9 +378,21 @@ export interface IPluginApi {
|
|
|
260
378
|
|
|
261
379
|
/**
|
|
262
380
|
* Same shape on mobile, minus the rich-text editor adapter when the
|
|
263
|
-
* plugin only supports read-only mobile rendering.
|
|
381
|
+
* plugin only supports read-only mobile rendering. Web-only C11 / C23 members
|
|
382
|
+
* are omitted. React Native does not render HTML, so there is no
|
|
383
|
+
* `sanitizeHtml` on mobile. HTML rule for mobile plugins:
|
|
384
|
+
* - Native React Native text: `parseInlineRich` (inline formatting and
|
|
385
|
+
* links) and `stripHtmlToText` (plain text), both exported from
|
|
386
|
+
* `@selfhelp/shared/plugin-sdk`.
|
|
387
|
+
* - HTML inside the plugin's own WebView: the plugin bundles a sanitizer into
|
|
388
|
+
* the WebView runtime and keeps a strict CSP. The host offers no sanitizer
|
|
389
|
+
* on mobile.
|
|
390
|
+
* - Web part: `api.sanitizeHtml`; never bundle a sanitizer there.
|
|
264
391
|
*/
|
|
265
|
-
export interface IMobilePluginApi extends Omit<
|
|
392
|
+
export interface IMobilePluginApi extends Omit<
|
|
393
|
+
IPluginApi,
|
|
394
|
+
'richTextEditor' | 'sanitizeHtml' | 'sectionAnchor' | 'resources' | 'ui' | 'settings'
|
|
395
|
+
> {
|
|
266
396
|
/** Mobile builds without rich-text support set this to `null`. */
|
|
267
397
|
richTextEditor: IRichTextEditorAdapter | null;
|
|
268
398
|
}
|
|
@@ -297,6 +427,11 @@ export interface IPluginRegistration {
|
|
|
297
427
|
* `field_types`) without the host having to hardcode the renderer.
|
|
298
428
|
*/
|
|
299
429
|
fieldRenderers?: IFieldRendererDefinition[];
|
|
430
|
+
/**
|
|
431
|
+
* Declarative sync map (C10). The host invalidates each matching
|
|
432
|
+
* `queryKey` as a prefix when a change notice carries a listed tag.
|
|
433
|
+
*/
|
|
434
|
+
sync?: IPluginSyncEntry[];
|
|
300
435
|
}
|
|
301
436
|
|
|
302
437
|
/**
|
|
@@ -312,4 +447,9 @@ export interface IMobilePluginRegistration {
|
|
|
312
447
|
realtimeTopics?: IPluginRealtimeTopic[];
|
|
313
448
|
/** Mobile feature flags (mirror of the manifest flags). */
|
|
314
449
|
featureFlags?: IPluginFeatureFlag[];
|
|
450
|
+
/**
|
|
451
|
+
* Declarative sync map (C10). Same shape as the web registration; the
|
|
452
|
+
* mobile host invalidates matching query keys from `applySyncTags`.
|
|
453
|
+
*/
|
|
454
|
+
sync?: IPluginSyncEntry[];
|
|
315
455
|
}
|
|
@@ -13,8 +13,16 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
13
13
|
* - major (1.x -> 2.0) — breaking SDK change.
|
|
14
14
|
*
|
|
15
15
|
* Independent from the npm `version` of `@selfhelp/shared`.
|
|
16
|
+
*
|
|
17
|
+
* `0.2.0` adds resource tags, the plugin sync map, manifest keys for settings /
|
|
18
|
+
* rate limits / JSON Logic / cache categories / action-plannable jobs, and the
|
|
19
|
+
* web SDK `resources` / `settings` / `sectionAnchor` surface (task
|
|
20
|
+
* `2026-11-25-plugin-resource-hooks`). It also covers the optional mobile host
|
|
21
|
+
* services `upload`, `requestPermission` / `openAppSettings` and
|
|
22
|
+
* `getPluginStorage`, and the `parseInlineRich` / `stripHtmlToText` /
|
|
23
|
+
* `IInlineNode` exports (the mobile renderer axis is `0.4.0`).
|
|
16
24
|
*/
|
|
17
|
-
export const PLUGIN_API_VERSION = '0.
|
|
25
|
+
export const PLUGIN_API_VERSION = '0.2.0' as const;
|
|
18
26
|
|
|
19
27
|
/**
|
|
20
28
|
* Mobile renderer contract version. This is the SECOND, mobile-only
|
|
@@ -42,8 +50,17 @@ export const PLUGIN_API_VERSION = '0.1.0' as const;
|
|
|
42
50
|
* through the host router (correct in the native app AND the CMS web preview
|
|
43
51
|
* iframe) instead of touching `window.location` — an additive renderer feature.
|
|
44
52
|
* It is optional, so older plugins/hosts stay compatible.
|
|
53
|
+
*
|
|
54
|
+
* `0.4.0` adds three optional host services and one text-helper export (task
|
|
55
|
+
* `2026-11-25-plugin-resource-hooks`, C27 to C30): `upload` (multipart through
|
|
56
|
+
* the host with the host's token), `requestPermission` / `openAppSettings`
|
|
57
|
+
* (microphone and camera, asked by the app), `getPluginStorage` (a small device
|
|
58
|
+
* key-value store per server, user and plugin), and `parseInlineRich` /
|
|
59
|
+
* `stripHtmlToText` / `IInlineNode` exported from `plugin-sdk`. All members are
|
|
60
|
+
* optional, so a plugin feature-detects them; plugins declare `>=` ranges in
|
|
61
|
+
* `compatibility.mobile`.
|
|
45
62
|
*/
|
|
46
|
-
export const MOBILE_RENDERER_VERSION = '0.
|
|
63
|
+
export const MOBILE_RENDERER_VERSION = '0.4.0' as const;
|
|
47
64
|
|
|
48
65
|
export interface ISemver {
|
|
49
66
|
major: number;
|
|
@@ -38,10 +38,20 @@ describe('parseSyncMessage (C1)', () => {
|
|
|
38
38
|
'table:4',
|
|
39
39
|
'section:5',
|
|
40
40
|
'asset:6',
|
|
41
|
+
'res:surveyjs_survey:12',
|
|
41
42
|
];
|
|
42
43
|
expect(parseSyncMessage({ v: 1, tags })?.tags).toEqual(tags);
|
|
43
44
|
});
|
|
44
45
|
|
|
46
|
+
it('keeps only well-formed res: tags (C1)', () => {
|
|
47
|
+
expect(
|
|
48
|
+
parseSyncMessage({
|
|
49
|
+
v: 1,
|
|
50
|
+
tags: ['res:surveyjs_survey:12', 'res:Bad:1', 'res:x:1'],
|
|
51
|
+
}),
|
|
52
|
+
).toEqual({ v: 1, tags: ['res:surveyjs_survey:12'] });
|
|
53
|
+
});
|
|
54
|
+
|
|
45
55
|
it('ignores a message of a higher version', () => {
|
|
46
56
|
expect(parseSyncMessage({ v: 2, tags: ['page:12'] })).toBeNull();
|
|
47
57
|
expect(parseSyncMessage({ v: 0, tags: ['page:12'] })).toBeNull();
|
|
@@ -124,6 +134,15 @@ describe('pageDependsOn (C6)', () => {
|
|
|
124
134
|
expect(pageDependsOn(draft, ['page:12'])).toBe(false);
|
|
125
135
|
});
|
|
126
136
|
|
|
137
|
+
it('matches a listed res: tag', () => {
|
|
138
|
+
const withRes: ISyncBlock = {
|
|
139
|
+
depends_on: ['page:12', 'res:surveyjs_survey:12', 'global_values'],
|
|
140
|
+
valid_until: null,
|
|
141
|
+
};
|
|
142
|
+
expect(pageDependsOn(withRes, ['res:surveyjs_survey:12'])).toBe(true);
|
|
143
|
+
expect(pageDependsOn(withRes, ['res:surveyjs_survey:99'])).toBe(false);
|
|
144
|
+
});
|
|
145
|
+
|
|
127
146
|
it('is false without a sync block or an empty list', () => {
|
|
128
147
|
expect(pageDependsOn(undefined, ['page:12'])).toBe(false);
|
|
129
148
|
expect(pageDependsOn(null, ['page:12'])).toBe(false);
|
package/src/sync/sync.ts
CHANGED
|
@@ -70,8 +70,9 @@ export function parseSyncMessageJson(raw: string): ISyncChangeMessage | null {
|
|
|
70
70
|
* True when a page payload's `sync.depends_on` names any of the message's tags (C6).
|
|
71
71
|
*
|
|
72
72
|
* Only tags that a page payload can list match here: `page:<id>`,
|
|
73
|
-
* `page_draft:<id>`, `table:<id>` and `global_values`. The
|
|
74
|
-
* page dependencies and are handled by the client on their
|
|
73
|
+
* `page_draft:<id>`, `table:<id>`, `res:<type>:<id>` and `global_values`. The
|
|
74
|
+
* other tags are not page dependencies and are handled by the client on their
|
|
75
|
+
* own:
|
|
75
76
|
*
|
|
76
77
|
* - `acl` and `navigation` affect every page the caller may see, so the client
|
|
77
78
|
* invalidates all page queries and the navigation (it does not ask each page).
|
package/src/sync/types.ts
CHANGED
|
@@ -32,6 +32,7 @@ export const SYNC_MESSAGE_VERSION = 1 as const;
|
|
|
32
32
|
* | `table:<id>` | A record of the data table changed |
|
|
33
33
|
* | `section:<id>` | A section was saved in the admin |
|
|
34
34
|
* | `asset:<id>` | An asset changed |
|
|
35
|
+
* | `res:<type>:<id>` | A plugin item of a registered resource type changed |
|
|
35
36
|
*/
|
|
36
37
|
export type TSyncTag =
|
|
37
38
|
| 'acl'
|
|
@@ -42,11 +43,12 @@ export type TSyncTag =
|
|
|
42
43
|
| `page_lock:${number}`
|
|
43
44
|
| `table:${number}`
|
|
44
45
|
| `section:${number}`
|
|
45
|
-
| `asset:${number}
|
|
46
|
+
| `asset:${number}`
|
|
47
|
+
| `res:${string}:${number}`;
|
|
46
48
|
|
|
47
49
|
/** Mirror of the backend tag pattern (C1). Anchored, so the whole tag must match. */
|
|
48
50
|
export const SYNC_TAG_PATTERN =
|
|
49
|
-
/^(acl|navigation|global_values|page:\d+|page_draft:\d+|page_lock:\d+|table:\d+|section:\d+|asset:\d+)$/;
|
|
51
|
+
/^(acl|navigation|global_values|page:\d+|page_draft:\d+|page_lock:\d+|table:\d+|section:\d+|asset:\d+|res:[a-z][a-z0-9_]{1,63}:\d+)$/;
|
|
50
52
|
|
|
51
53
|
/** Data of one `changed` event (C1). */
|
|
52
54
|
export interface ISyncChangeMessage {
|
|
@@ -60,10 +62,11 @@ export interface ISyncChangeMessage {
|
|
|
60
62
|
* The `sync` block of every page payload, published and draft (C6).
|
|
61
63
|
*
|
|
62
64
|
* `depends_on` lists `page:<id>` (`page_draft:<id>` for a draft), `table:<id>`
|
|
63
|
-
* for every data table the page reads,
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
65
|
+
* for every data table the page reads, `res:<type>:<id>` for plugin items the
|
|
66
|
+
* page references or a style resolver depends on, and `global_values`.
|
|
67
|
+
* `valid_until` is the earliest moment (UTC, ISO 8601) the result can change
|
|
68
|
+
* because time passes, or `null`. The client refetches once at `valid_until`
|
|
69
|
+
* plus a random delay while the page is open.
|
|
67
70
|
*/
|
|
68
71
|
export interface ISyncBlock {
|
|
69
72
|
depends_on: string[];
|
|
@@ -165,6 +165,11 @@ export interface IFormListRow extends IFormListRecordAccess {
|
|
|
165
165
|
entry_date: string;
|
|
166
166
|
/** Send back as `expected_version` when changing the record. */
|
|
167
167
|
version: number;
|
|
168
|
+
/**
|
|
169
|
+
* Content the write was based on (`page:<id>@v<n>|draft` or
|
|
170
|
+
* `res:<type>:<id>@v<n>`). Null when unknown (older rows).
|
|
171
|
+
*/
|
|
172
|
+
content_ref?: string | null;
|
|
168
173
|
/** Exactly the configured columns, by field. */
|
|
169
174
|
values: Record<string, TFormListCellValue>;
|
|
170
175
|
/**
|
|
@@ -182,6 +187,11 @@ export interface IFormListSelected extends IFormListRecordAccess {
|
|
|
182
187
|
entry_date: string;
|
|
183
188
|
/** Send back as `expected_version` when saving, deleting, running an action or restoring. */
|
|
184
189
|
version: number;
|
|
190
|
+
/**
|
|
191
|
+
* Content the write was based on (`page:<id>@v<n>|draft` or
|
|
192
|
+
* `res:<type>:<id>@v<n>`). Null when unknown (older rows).
|
|
193
|
+
*/
|
|
194
|
+
content_ref?: string | null;
|
|
185
195
|
values: Record<string, TFormListCellValue>;
|
|
186
196
|
/** The prefill the inline form receives on a page load; null when the caller cannot edit the record. */
|
|
187
197
|
form_values: Record<string, unknown> | unknown[] | null;
|
|
@@ -269,7 +279,7 @@ export type IFormListQuickActionResponse = IBaseApiResponse<IFormListQuickAction
|
|
|
269
279
|
// -- history -------------------------------------------------------------------------
|
|
270
280
|
|
|
271
281
|
export type TDataRevisionOperation = 'create' | 'update' | 'delete' | 'restore' | 'baseline';
|
|
272
|
-
export type TDataRevisionSource = 'form' | 'admin' | 'quick_action' | 'job' | 'import' | 'system';
|
|
282
|
+
export type TDataRevisionSource = 'form' | 'admin' | 'quick_action' | 'job' | 'import' | 'system' | 'plugin';
|
|
273
283
|
|
|
274
284
|
export interface IFormListActor {
|
|
275
285
|
id: number;
|
|
@@ -289,6 +299,11 @@ export interface IFormListRevision {
|
|
|
289
299
|
/** The number of fields the revision changed. */
|
|
290
300
|
changed_fields: number;
|
|
291
301
|
is_checkpoint: boolean;
|
|
302
|
+
/**
|
|
303
|
+
* Content that revision was based on (`page:<id>@v<n>|draft` or
|
|
304
|
+
* `res:<type>:<id>@v<n>`). Null when unknown (older revisions).
|
|
305
|
+
*/
|
|
306
|
+
content_ref?: string | null;
|
|
292
307
|
}
|
|
293
308
|
|
|
294
309
|
/** A file a revision held; `available` is false once the file was erased. */
|
package/src/types/api/forms.ts
CHANGED
|
@@ -187,6 +187,11 @@ export interface IFormSubmitData extends IFormResultLegacyFields {
|
|
|
187
187
|
user_authenticated: boolean;
|
|
188
188
|
/** The record's version after the submit (1 for a new record). */
|
|
189
189
|
version: number;
|
|
190
|
+
/**
|
|
191
|
+
* Content the write was based on (`page:<id>@v<n>|draft` or
|
|
192
|
+
* `res:<type>:<id>@v<n>`). Null when unknown.
|
|
193
|
+
*/
|
|
194
|
+
content_ref?: string | null;
|
|
190
195
|
}
|
|
191
196
|
|
|
192
197
|
/**
|
|
@@ -201,6 +206,11 @@ export interface IFormUpdateData extends IFormResultLegacyFields {
|
|
|
201
206
|
updated_at: string;
|
|
202
207
|
/** The record's version after the update. */
|
|
203
208
|
version: number;
|
|
209
|
+
/**
|
|
210
|
+
* Content the write was based on (`page:<id>@v<n>|draft` or
|
|
211
|
+
* `res:<type>:<id>@v<n>`). Null when unknown.
|
|
212
|
+
*/
|
|
213
|
+
content_ref?: string | null;
|
|
204
214
|
}
|
|
205
215
|
|
|
206
216
|
/**
|