@selfhelp/shared 1.30.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/index.d.mts +14 -82
  3. package/dist/index.d.ts +14 -82
  4. package/dist/index.js +1 -1
  5. package/dist/index.mjs +1 -1
  6. package/dist/inlineFormat-Duu5VLMU.d.mts +73 -0
  7. package/dist/inlineFormat-Duu5VLMU.d.ts +73 -0
  8. package/dist/{manifest-DRlcSvvy.d.mts → manifest-DWHD0PQA.d.mts} +124 -1
  9. package/dist/{manifest-DRlcSvvy.d.ts → manifest-DWHD0PQA.d.ts} +124 -1
  10. package/dist/plugin-sdk/index.d.mts +210 -10
  11. package/dist/plugin-sdk/index.d.ts +210 -10
  12. package/dist/plugin-sdk/index.js +174 -2
  13. package/dist/plugin-sdk/index.mjs +171 -2
  14. package/dist/plugin-sdk/sync-map.d.mts +22 -0
  15. package/dist/plugin-sdk/sync-map.d.ts +22 -0
  16. package/dist/plugin-sdk/sync-map.js +58 -0
  17. package/dist/plugin-sdk/sync-map.mjs +33 -0
  18. package/dist/registry/index.d.mts +2 -2
  19. package/dist/registry/index.d.ts +2 -2
  20. package/dist/{styles.registry-DnIJqEzM.d.mts → styles.registry-B2cyNdo3.d.mts} +26 -1
  21. package/dist/{styles.registry-C2ACy7H0.d.ts → styles.registry-G_KUYGPv.d.ts} +26 -1
  22. package/dist/testing/index.d.mts +1 -1
  23. package/dist/testing/index.d.ts +1 -1
  24. package/package.json +3 -3
  25. package/src/plugin-sdk/__tests__/define-sync.test.ts +106 -0
  26. package/src/plugin-sdk/__tests__/exports.test.ts +29 -0
  27. package/src/plugin-sdk/__tests__/host-services.test.ts +96 -6
  28. package/src/plugin-sdk/__tests__/sync-map.test.ts +48 -0
  29. package/src/plugin-sdk/__tests__/version.test.ts +9 -0
  30. package/src/plugin-sdk/host-services.ts +106 -0
  31. package/src/plugin-sdk/index.ts +24 -0
  32. package/src/plugin-sdk/manifest.ts +142 -0
  33. package/src/plugin-sdk/sync-map.ts +61 -0
  34. package/src/plugin-sdk/types.ts +89 -5
  35. package/src/plugin-sdk/version.ts +19 -2
  36. package/src/sync/__tests__/sync.test.ts +19 -0
  37. package/src/sync/sync.ts +3 -2
  38. package/src/sync/types.ts +9 -6
  39. package/src/types/api/form-lists.ts +16 -1
  40. package/src/types/api/forms.ts +10 -0
@@ -1,5 +1,8 @@
1
- export { I as IPluginManifest, a as IPluginManifestAdminPage, b as IPluginManifestApiRoute, c as IPluginManifestAsset, d as IPluginManifestCapability, e as IPluginManifestCompatibility, f as IPluginManifestConflict, g as IPluginManifestDataAccess, h as IPluginManifestDependency, i as IPluginManifestExternalHost, j as IPluginManifestFeatureFlag, k as IPluginManifestField, l as IPluginManifestFieldType, m as IPluginManifestHealth, n as IPluginManifestLookupExtension, o as IPluginManifestMobile, p as IPluginManifestPermission, q as IPluginManifestRealtimeTopic, r as IPluginManifestScheduledJob, s as IPluginManifestSecurity, t as IPluginManifestStyle, u as IPluginManifestStyleField, v as IPluginManifestStyleGroup, w as IPluginManifestTrustLevel } from '../manifest-DRlcSvvy.mjs';
2
- import { I as IStyleRegistryEntry } from '../styles.registry-DnIJqEzM.mjs';
1
+ export { I as IPluginManifest, a as IPluginManifestAdminPage, b as IPluginManifestApiRoute, c as IPluginManifestAsset, d as IPluginManifestCacheCategory, e as IPluginManifestCapability, f as IPluginManifestCompatibility, g as IPluginManifestConflict, h as IPluginManifestDataAccess, i as IPluginManifestDependency, j as IPluginManifestExternalHost, k as IPluginManifestFeatureFlag, l as IPluginManifestField, m as IPluginManifestFieldType, n as IPluginManifestHealth, o as IPluginManifestJobConfigProperty, p as IPluginManifestJobConfigSchema, q as IPluginManifestJsonLogicOperation, r as IPluginManifestLookupExtension, s as IPluginManifestMobile, t as IPluginManifestPermission, u as IPluginManifestRateLimit, v as IPluginManifestRealtimeTopic, w as IPluginManifestRecurringJob, x as IPluginManifestScheduledJob, y as IPluginManifestSecurity, z as IPluginManifestSetting, A as IPluginManifestStyle, B as IPluginManifestStyleField, C as IPluginManifestStyleGroup, D as IPluginManifestTrustLevel, T as TPluginDomainEventName } from '../manifest-DWHD0PQA.mjs';
2
+ import { I as IStyleRegistryEntry } from '../styles.registry-B2cyNdo3.mjs';
3
+ import { IPluginSyncEntry } from './sync-map.mjs';
4
+ export { matchPluginSyncEntries } from './sync-map.mjs';
5
+ export { I as IInlineNode, p as parseInlineRich, s as stripHtmlToText } from '../inlineFormat-Duu5VLMU.mjs';
3
6
  import '../common-qaDIAYS3.mjs';
4
7
 
5
8
  /**
@@ -13,8 +16,16 @@ import '../common-qaDIAYS3.mjs';
13
16
  * - major (1.x -> 2.0) — breaking SDK change.
14
17
  *
15
18
  * Independent from the npm `version` of `@selfhelp/shared`.
19
+ *
20
+ * `0.2.0` adds resource tags, the plugin sync map, manifest keys for settings /
21
+ * rate limits / JSON Logic / cache categories / action-plannable jobs, and the
22
+ * web SDK `resources` / `settings` / `sectionAnchor` surface (task
23
+ * `2026-11-25-plugin-resource-hooks`). It also covers the optional mobile host
24
+ * services `upload`, `requestPermission` / `openAppSettings` and
25
+ * `getPluginStorage`, and the `parseInlineRich` / `stripHtmlToText` /
26
+ * `IInlineNode` exports (the mobile renderer axis is `0.4.0`).
16
27
  */
17
- declare const PLUGIN_API_VERSION: "0.1.0";
28
+ declare const PLUGIN_API_VERSION: "0.2.0";
18
29
  /**
19
30
  * Mobile renderer contract version. This is the SECOND, mobile-only
20
31
  * compatibility axis (independent of `PLUGIN_API_VERSION`): it versions the
@@ -41,8 +52,17 @@ declare const PLUGIN_API_VERSION: "0.1.0";
41
52
  * through the host router (correct in the native app AND the CMS web preview
42
53
  * iframe) instead of touching `window.location` — an additive renderer feature.
43
54
  * It is optional, so older plugins/hosts stay compatible.
55
+ *
56
+ * `0.4.0` adds three optional host services and one text-helper export (task
57
+ * `2026-11-25-plugin-resource-hooks`, C27 to C30): `upload` (multipart through
58
+ * the host with the host's token), `requestPermission` / `openAppSettings`
59
+ * (microphone and camera, asked by the app), `getPluginStorage` (a small device
60
+ * key-value store per server, user and plugin), and `parseInlineRich` /
61
+ * `stripHtmlToText` / `IInlineNode` exported from `plugin-sdk`. All members are
62
+ * optional, so a plugin feature-detects them; plugins declare `>=` ranges in
63
+ * `compatibility.mobile`.
44
64
  */
45
- declare const MOBILE_RENDERER_VERSION: "0.3.0";
65
+ declare const MOBILE_RENDERER_VERSION: "0.4.0";
46
66
  interface ISemver {
47
67
  major: number;
48
68
  minor: number;
@@ -389,6 +409,42 @@ interface IPluginLock {
389
409
  * component type at registration time.
390
410
  */
391
411
  type TPluginComponent<TProps = unknown> = (props: TProps) => unknown;
412
+ /**
413
+ * Where a plugin item is used (C7). Pages the caller may not read are counted
414
+ * only in `hidden_count`.
415
+ */
416
+ interface IResourceUsage {
417
+ pages: Array<{
418
+ id: number;
419
+ keyword: string;
420
+ title: string | null;
421
+ draft_uses: boolean;
422
+ published_uses: boolean;
423
+ }>;
424
+ actions: Array<{
425
+ id: number;
426
+ name: string;
427
+ }>;
428
+ hidden_count: number;
429
+ }
430
+ /**
431
+ * One item of `GET /admin/plugins/{pluginId}/settings` (C14). Secrets never
432
+ * carry a clear `value`; `hint` is the last 4 characters when the secret is
433
+ * long enough, otherwise null.
434
+ */
435
+ interface IPluginSettingViewItem {
436
+ key: string;
437
+ label: string;
438
+ type: 'string' | 'number' | 'boolean' | 'url';
439
+ secret: boolean;
440
+ required: boolean;
441
+ has_value: boolean;
442
+ value: string | number | boolean | null;
443
+ hint: string | null;
444
+ overridden_by_env: boolean;
445
+ }
446
+ /** The C14 GET settings list for one plugin. */
447
+ type IPluginSettingsView = IPluginSettingViewItem[];
392
448
  /**
393
449
  * Definition of a CMS style contributed by a plugin.
394
450
  */
@@ -655,6 +711,33 @@ interface IPluginApi {
655
711
  * inline markup only, `block` also keeps headings, lists and paragraphs.
656
712
  */
657
713
  sanitizeHtml(html: string, mode: 'inline' | 'block'): string;
714
+ /**
715
+ * CSS selector for a rendered section element (C23). Returns
716
+ * `.section-<id>`. Web only.
717
+ */
718
+ sectionAnchor(sectionId: number): string;
719
+ /** Where-used for a plugin item the caller may view (C7, C11). */
720
+ resources: {
721
+ usage(type: string, id: number): Promise<IResourceUsage>;
722
+ };
723
+ /**
724
+ * Optional host UI parts. `ResourceUsageList` is offered when the host
725
+ * ships a shared where-used list for delete warnings.
726
+ */
727
+ ui?: {
728
+ ResourceUsageList: TPluginComponent<{
729
+ type: string;
730
+ id: number;
731
+ warnBeforeDelete?: boolean;
732
+ }>;
733
+ };
734
+ /**
735
+ * This plugin's settings as the host stores them (C14). Secrets show
736
+ * `has_value` only; clear values are never returned for secrets.
737
+ */
738
+ settings: {
739
+ get(): Promise<IPluginSettingsView>;
740
+ };
658
741
  /**
659
742
  * Logger that respects the host's debug config. Avoid `console.log`
660
743
  * in plugin code; route everything through this.
@@ -668,12 +751,18 @@ interface IPluginApi {
668
751
  }
669
752
  /**
670
753
  * Same shape on mobile, minus the rich-text editor adapter when the
671
- * plugin only supports read-only mobile rendering. React Native does not
672
- * render HTML, so there is no `sanitizeHtml`: mobile plugins show CMS text
673
- * with `parseInlineRich` / `stripHtmlToText`. A plugin that renders HTML in
674
- * a WebView sanitizes it there itself.
754
+ * plugin only supports read-only mobile rendering. Web-only C11 / C23 members
755
+ * are omitted. React Native does not render HTML, so there is no
756
+ * `sanitizeHtml` on mobile. HTML rule for mobile plugins:
757
+ * - Native React Native text: `parseInlineRich` (inline formatting and
758
+ * links) and `stripHtmlToText` (plain text), both exported from
759
+ * `@selfhelp/shared/plugin-sdk`.
760
+ * - HTML inside the plugin's own WebView: the plugin bundles a sanitizer into
761
+ * the WebView runtime and keeps a strict CSP. The host offers no sanitizer
762
+ * on mobile.
763
+ * - Web part: `api.sanitizeHtml`; never bundle a sanitizer there.
675
764
  */
676
- interface IMobilePluginApi extends Omit<IPluginApi, 'richTextEditor' | 'sanitizeHtml'> {
765
+ interface IMobilePluginApi extends Omit<IPluginApi, 'richTextEditor' | 'sanitizeHtml' | 'sectionAnchor' | 'resources' | 'ui' | 'settings'> {
677
766
  /** Mobile builds without rich-text support set this to `null`. */
678
767
  richTextEditor: IRichTextEditorAdapter | null;
679
768
  }
@@ -707,6 +796,11 @@ interface IPluginRegistration {
707
796
  * `field_types`) without the host having to hardcode the renderer.
708
797
  */
709
798
  fieldRenderers?: IFieldRendererDefinition[];
799
+ /**
800
+ * Declarative sync map (C10). The host invalidates each matching
801
+ * `queryKey` as a prefix when a change notice carries a listed tag.
802
+ */
803
+ sync?: IPluginSyncEntry[];
710
804
  }
711
805
  /**
712
806
  * Returned by `defineMobilePlugin()` for the mobile side of a plugin.
@@ -721,6 +815,11 @@ interface IMobilePluginRegistration {
721
815
  realtimeTopics?: IPluginRealtimeTopic[];
722
816
  /** Mobile feature flags (mirror of the manifest flags). */
723
817
  featureFlags?: IPluginFeatureFlag[];
818
+ /**
819
+ * Declarative sync map (C10). Same shape as the web registration; the
820
+ * mobile host invalidates matching query keys from `applySyncTags`.
821
+ */
822
+ sync?: IPluginSyncEntry[];
724
823
  }
725
824
 
726
825
  /**
@@ -826,6 +925,67 @@ interface IMobileHostResponse<TData = unknown> {
826
925
  */
827
926
  sessionExpired?: boolean;
828
927
  }
928
+ /**
929
+ * One file part of a multipart upload the plugin asks the host to send
930
+ * (renderer 0.4.0, C27). Give exactly one of {@link uri} or {@link base64}.
931
+ */
932
+ interface IMobileHostUploadFile {
933
+ /** Multipart part name (the field name the plugin's route reads). */
934
+ field: string;
935
+ /** File name sent to the server. */
936
+ name: string;
937
+ /** MIME type, e.g. `audio/m4a`. */
938
+ type: string;
939
+ /**
940
+ * `file://` or `content://` (native), `blob:` or `data:` (web preview).
941
+ * Exclusive with {@link base64}.
942
+ */
943
+ uri?: string;
944
+ /** Raw base64 without a `data:` prefix. Exclusive with {@link uri}. */
945
+ base64?: string;
946
+ }
947
+ /**
948
+ * A protected multipart upload (renderer 0.4.0, C27). Same path rules as
949
+ * {@link IMobileHostRequest}: relative to the host API base, absolute URLs are
950
+ * refused.
951
+ */
952
+ interface IMobileHostUploadRequest {
953
+ /** Path relative to the host API base, like {@link IMobileHostRequest.path}. */
954
+ path: string;
955
+ /** HTTP method. Defaults to `POST`. */
956
+ method?: 'POST' | 'PUT';
957
+ /** Text parts of the multipart body. */
958
+ fields?: Record<string, string>;
959
+ /** File parts. At least one is required. */
960
+ files: IMobileHostUploadFile[];
961
+ /** Extra request headers. */
962
+ headers?: Record<string, string>;
963
+ /** Query parameters appended to the path. */
964
+ query?: Record<string, string | number | boolean>;
965
+ }
966
+ /** What a plugin may ask the host to request from the system (C28). */
967
+ type TMobileHostPermission = 'microphone' | 'camera';
968
+ /**
969
+ * Answer to {@link IMobileHostServices.requestPermission}: `granted`, `denied`
970
+ * (the user said no and the app may ask again) or `blocked` (the system will
971
+ * not show the prompt again; send the user to {@link IMobileHostServices.openAppSettings}).
972
+ */
973
+ type TMobileHostPermissionState = 'granted' | 'denied' | 'blocked';
974
+ /**
975
+ * Small device key-value store for one plugin, one user and one server (C29).
976
+ * Meant for drafts and view state. It is not encrypted: never keep secrets or
977
+ * tokens in it. The server still decides everything on submit.
978
+ */
979
+ interface IMobilePluginStorage {
980
+ /** The stored value, or `null` when the key is not set. */
981
+ getItem(key: string): Promise<string | null>;
982
+ /** Stores a value; rejects with `Error('plugin_storage_full')` over the size cap and changes nothing. */
983
+ setItem(key: string, value: string): Promise<void>;
984
+ /** Removes one key. */
985
+ removeItem(key: string): Promise<void>;
986
+ /** Removes everything of this plugin, this user and this server only. */
987
+ clear(): Promise<void>;
988
+ }
829
989
  /**
830
990
  * Authenticated host services exposed to a plugin's mobile package. The
831
991
  * host owns the token + refresh; the plugin only describes the request.
@@ -863,6 +1023,46 @@ interface IMobileHostServices {
863
1023
  * gracefully rather than assume it exists.
864
1024
  */
865
1025
  navigate?(target: string, external?: boolean): void;
1026
+ /**
1027
+ * Send a `multipart/form-data` request through the host (renderer 0.4.0).
1028
+ * The host attaches the token and client headers, makes one 401 refresh
1029
+ * retry and answers in the {@link IMobileHostResponse} shape, like
1030
+ * {@link request}. An absolute path is refused. Nothing is sent, and the
1031
+ * answer is `{ ok: false, status: 0, reason }`, when `reason` is
1032
+ * `invalid_upload` (no file, or a file with both or neither of `uri` and
1033
+ * `base64`) or `file_too_large` (one total size limit per request). The
1034
+ * host removes any temporary file it wrote for a `base64` input.
1035
+ *
1036
+ * Optional: an older host omits it, so a plugin MUST feature-detect
1037
+ * (`if (host.upload)`) and degrade gracefully.
1038
+ */
1039
+ upload?<TData = unknown>(req: IMobileHostUploadRequest): Promise<IMobileHostResponse<TData>>;
1040
+ /**
1041
+ * Ask the system for microphone or camera access (renderer 0.4.0). Only the
1042
+ * app asks; a plugin in a WebView cannot. Resolves to `granted`, `denied`
1043
+ * or `blocked` ({@link TMobileHostPermissionState}); on `blocked` the plugin
1044
+ * should explain why it needs the permission and offer
1045
+ * {@link openAppSettings}.
1046
+ *
1047
+ * Optional: feature-detect (`if (host.requestPermission)`).
1048
+ */
1049
+ requestPermission?(kind: TMobileHostPermission): Promise<TMobileHostPermissionState>;
1050
+ /**
1051
+ * Open the app's system settings page so the user can change a `blocked`
1052
+ * permission (renderer 0.4.0). Does nothing in the web preview.
1053
+ *
1054
+ * Optional: feature-detect (`if (host.openAppSettings)`).
1055
+ */
1056
+ openAppSettings?(): void;
1057
+ /**
1058
+ * Device storage for the given plugin id, scoped to the current server and
1059
+ * user (guest = 0), emptied on logout, server switch and a rejected token
1060
+ * refresh (renderer 0.4.0, C29). Throws when `pluginId` does not match the
1061
+ * manifest id pattern. Not for secrets.
1062
+ *
1063
+ * Optional: feature-detect (`if (host.getPluginStorage)`).
1064
+ */
1065
+ getPluginStorage?(pluginId: string): IMobilePluginStorage;
866
1066
  }
867
1067
  /**
868
1068
  * Register the host services implementation. Called once by the native
@@ -1059,4 +1259,4 @@ declare function isPluginRuntimeShimSpecifier(value: unknown): value is TPluginR
1059
1259
  */
1060
1260
  declare const PLUGIN_RUNTIME_IMPORT_MAP: Readonly<Record<TPluginRuntimeShimSpecifier, string>>;
1061
1261
 
1062
- export { type IAdminPageDefinition, type IFieldRendererDefinition, type IMenuItemDefinition, type IMobileHostRequest, type IMobileHostResponse, type IMobileHostServices, type IMobilePluginApi, type IMobilePluginRegistration, type IPluginApi, type IPluginFeatureFlag, type IPluginFieldRendererProps, type IPluginHealthCheck, type IPluginLock, type IPluginLockEntry, type IPluginLockMigration, type IPluginLockMobileEntry, type IPluginPageModal, type IPluginRealtimePublisher, type IPluginRealtimeTopic, type IPluginRegistration, type IPluginRegistry, type IPluginRelease, type IPluginStylePage, type IPluginStyleProps, type IRealtimeTransport, type IRegistryReleaseRef, type IRegistrySignatureBlock, type IRichTextEditorAdapter, type IRichTextEditorAdapterOptions, type IRichTextEditorValue, type IStyleDefinition, type IUsePluginRealtimeOptions, type IUsePluginRealtimeResult, MOBILE_RENDERER_VERSION, PLUGIN_API_VERSION, PLUGIN_REGISTRY_CHANNELS, PLUGIN_RUNTIME_GLOBAL_KEY, PLUGIN_RUNTIME_IMPORT_MAP, PLUGIN_RUNTIME_SHIM_BASE_PATH, PLUGIN_RUNTIME_SHIM_SPECIFIERS, type TMobileHostMethod, type TPluginRegistryChannel, type TPluginRuntimeShimSpecifier, type TRealtimeTransportFactory, assertCmsCompatibility, assertPluginApiVersion, assertPluginVersionSemantics, buildPluginRuntimeShimPath, compareSemver, defineMobilePlugin, definePlugin, definePluginRealtimeTopic, getMobileHostServices, isMobileRendererCompatible, isPluginApiCompatible, isPluginRuntimeShimSpecifier, parseSemver, satisfiesSemverRange, setMobileHostServices, usePluginRealtime };
1262
+ export { type IAdminPageDefinition, type IFieldRendererDefinition, type IMenuItemDefinition, type IMobileHostRequest, type IMobileHostResponse, type IMobileHostServices, type IMobileHostUploadFile, type IMobileHostUploadRequest, type IMobilePluginApi, type IMobilePluginRegistration, type IMobilePluginStorage, type IPluginApi, type IPluginFeatureFlag, type IPluginFieldRendererProps, type IPluginHealthCheck, type IPluginLock, type IPluginLockEntry, type IPluginLockMigration, type IPluginLockMobileEntry, type IPluginPageModal, type IPluginRealtimePublisher, type IPluginRealtimeTopic, type IPluginRegistration, type IPluginRegistry, type IPluginRelease, type IPluginSettingViewItem, type IPluginSettingsView, type IPluginStylePage, type IPluginStyleProps, IPluginSyncEntry, type IRealtimeTransport, type IRegistryReleaseRef, type IRegistrySignatureBlock, type IResourceUsage, type IRichTextEditorAdapter, type IRichTextEditorAdapterOptions, type IRichTextEditorValue, type IStyleDefinition, type IUsePluginRealtimeOptions, type IUsePluginRealtimeResult, MOBILE_RENDERER_VERSION, PLUGIN_API_VERSION, PLUGIN_REGISTRY_CHANNELS, PLUGIN_RUNTIME_GLOBAL_KEY, PLUGIN_RUNTIME_IMPORT_MAP, PLUGIN_RUNTIME_SHIM_BASE_PATH, PLUGIN_RUNTIME_SHIM_SPECIFIERS, type TMobileHostMethod, type TMobileHostPermission, type TMobileHostPermissionState, type TPluginRegistryChannel, type TPluginRuntimeShimSpecifier, type TRealtimeTransportFactory, assertCmsCompatibility, assertPluginApiVersion, assertPluginVersionSemantics, buildPluginRuntimeShimPath, compareSemver, defineMobilePlugin, definePlugin, definePluginRealtimeTopic, getMobileHostServices, isMobileRendererCompatible, isPluginApiCompatible, isPluginRuntimeShimSpecifier, parseSemver, satisfiesSemverRange, setMobileHostServices, usePluginRealtime };
@@ -1,5 +1,8 @@
1
- export { I as IPluginManifest, a as IPluginManifestAdminPage, b as IPluginManifestApiRoute, c as IPluginManifestAsset, d as IPluginManifestCapability, e as IPluginManifestCompatibility, f as IPluginManifestConflict, g as IPluginManifestDataAccess, h as IPluginManifestDependency, i as IPluginManifestExternalHost, j as IPluginManifestFeatureFlag, k as IPluginManifestField, l as IPluginManifestFieldType, m as IPluginManifestHealth, n as IPluginManifestLookupExtension, o as IPluginManifestMobile, p as IPluginManifestPermission, q as IPluginManifestRealtimeTopic, r as IPluginManifestScheduledJob, s as IPluginManifestSecurity, t as IPluginManifestStyle, u as IPluginManifestStyleField, v as IPluginManifestStyleGroup, w as IPluginManifestTrustLevel } from '../manifest-DRlcSvvy.js';
2
- import { I as IStyleRegistryEntry } from '../styles.registry-C2ACy7H0.js';
1
+ export { I as IPluginManifest, a as IPluginManifestAdminPage, b as IPluginManifestApiRoute, c as IPluginManifestAsset, d as IPluginManifestCacheCategory, e as IPluginManifestCapability, f as IPluginManifestCompatibility, g as IPluginManifestConflict, h as IPluginManifestDataAccess, i as IPluginManifestDependency, j as IPluginManifestExternalHost, k as IPluginManifestFeatureFlag, l as IPluginManifestField, m as IPluginManifestFieldType, n as IPluginManifestHealth, o as IPluginManifestJobConfigProperty, p as IPluginManifestJobConfigSchema, q as IPluginManifestJsonLogicOperation, r as IPluginManifestLookupExtension, s as IPluginManifestMobile, t as IPluginManifestPermission, u as IPluginManifestRateLimit, v as IPluginManifestRealtimeTopic, w as IPluginManifestRecurringJob, x as IPluginManifestScheduledJob, y as IPluginManifestSecurity, z as IPluginManifestSetting, A as IPluginManifestStyle, B as IPluginManifestStyleField, C as IPluginManifestStyleGroup, D as IPluginManifestTrustLevel, T as TPluginDomainEventName } from '../manifest-DWHD0PQA.js';
2
+ import { I as IStyleRegistryEntry } from '../styles.registry-G_KUYGPv.js';
3
+ import { IPluginSyncEntry } from './sync-map.js';
4
+ export { matchPluginSyncEntries } from './sync-map.js';
5
+ export { I as IInlineNode, p as parseInlineRich, s as stripHtmlToText } from '../inlineFormat-Duu5VLMU.js';
3
6
  import '../common-qaDIAYS3.js';
4
7
 
5
8
  /**
@@ -13,8 +16,16 @@ import '../common-qaDIAYS3.js';
13
16
  * - major (1.x -> 2.0) — breaking SDK change.
14
17
  *
15
18
  * Independent from the npm `version` of `@selfhelp/shared`.
19
+ *
20
+ * `0.2.0` adds resource tags, the plugin sync map, manifest keys for settings /
21
+ * rate limits / JSON Logic / cache categories / action-plannable jobs, and the
22
+ * web SDK `resources` / `settings` / `sectionAnchor` surface (task
23
+ * `2026-11-25-plugin-resource-hooks`). It also covers the optional mobile host
24
+ * services `upload`, `requestPermission` / `openAppSettings` and
25
+ * `getPluginStorage`, and the `parseInlineRich` / `stripHtmlToText` /
26
+ * `IInlineNode` exports (the mobile renderer axis is `0.4.0`).
16
27
  */
17
- declare const PLUGIN_API_VERSION: "0.1.0";
28
+ declare const PLUGIN_API_VERSION: "0.2.0";
18
29
  /**
19
30
  * Mobile renderer contract version. This is the SECOND, mobile-only
20
31
  * compatibility axis (independent of `PLUGIN_API_VERSION`): it versions the
@@ -41,8 +52,17 @@ declare const PLUGIN_API_VERSION: "0.1.0";
41
52
  * through the host router (correct in the native app AND the CMS web preview
42
53
  * iframe) instead of touching `window.location` — an additive renderer feature.
43
54
  * It is optional, so older plugins/hosts stay compatible.
55
+ *
56
+ * `0.4.0` adds three optional host services and one text-helper export (task
57
+ * `2026-11-25-plugin-resource-hooks`, C27 to C30): `upload` (multipart through
58
+ * the host with the host's token), `requestPermission` / `openAppSettings`
59
+ * (microphone and camera, asked by the app), `getPluginStorage` (a small device
60
+ * key-value store per server, user and plugin), and `parseInlineRich` /
61
+ * `stripHtmlToText` / `IInlineNode` exported from `plugin-sdk`. All members are
62
+ * optional, so a plugin feature-detects them; plugins declare `>=` ranges in
63
+ * `compatibility.mobile`.
44
64
  */
45
- declare const MOBILE_RENDERER_VERSION: "0.3.0";
65
+ declare const MOBILE_RENDERER_VERSION: "0.4.0";
46
66
  interface ISemver {
47
67
  major: number;
48
68
  minor: number;
@@ -389,6 +409,42 @@ interface IPluginLock {
389
409
  * component type at registration time.
390
410
  */
391
411
  type TPluginComponent<TProps = unknown> = (props: TProps) => unknown;
412
+ /**
413
+ * Where a plugin item is used (C7). Pages the caller may not read are counted
414
+ * only in `hidden_count`.
415
+ */
416
+ interface IResourceUsage {
417
+ pages: Array<{
418
+ id: number;
419
+ keyword: string;
420
+ title: string | null;
421
+ draft_uses: boolean;
422
+ published_uses: boolean;
423
+ }>;
424
+ actions: Array<{
425
+ id: number;
426
+ name: string;
427
+ }>;
428
+ hidden_count: number;
429
+ }
430
+ /**
431
+ * One item of `GET /admin/plugins/{pluginId}/settings` (C14). Secrets never
432
+ * carry a clear `value`; `hint` is the last 4 characters when the secret is
433
+ * long enough, otherwise null.
434
+ */
435
+ interface IPluginSettingViewItem {
436
+ key: string;
437
+ label: string;
438
+ type: 'string' | 'number' | 'boolean' | 'url';
439
+ secret: boolean;
440
+ required: boolean;
441
+ has_value: boolean;
442
+ value: string | number | boolean | null;
443
+ hint: string | null;
444
+ overridden_by_env: boolean;
445
+ }
446
+ /** The C14 GET settings list for one plugin. */
447
+ type IPluginSettingsView = IPluginSettingViewItem[];
392
448
  /**
393
449
  * Definition of a CMS style contributed by a plugin.
394
450
  */
@@ -655,6 +711,33 @@ interface IPluginApi {
655
711
  * inline markup only, `block` also keeps headings, lists and paragraphs.
656
712
  */
657
713
  sanitizeHtml(html: string, mode: 'inline' | 'block'): string;
714
+ /**
715
+ * CSS selector for a rendered section element (C23). Returns
716
+ * `.section-<id>`. Web only.
717
+ */
718
+ sectionAnchor(sectionId: number): string;
719
+ /** Where-used for a plugin item the caller may view (C7, C11). */
720
+ resources: {
721
+ usage(type: string, id: number): Promise<IResourceUsage>;
722
+ };
723
+ /**
724
+ * Optional host UI parts. `ResourceUsageList` is offered when the host
725
+ * ships a shared where-used list for delete warnings.
726
+ */
727
+ ui?: {
728
+ ResourceUsageList: TPluginComponent<{
729
+ type: string;
730
+ id: number;
731
+ warnBeforeDelete?: boolean;
732
+ }>;
733
+ };
734
+ /**
735
+ * This plugin's settings as the host stores them (C14). Secrets show
736
+ * `has_value` only; clear values are never returned for secrets.
737
+ */
738
+ settings: {
739
+ get(): Promise<IPluginSettingsView>;
740
+ };
658
741
  /**
659
742
  * Logger that respects the host's debug config. Avoid `console.log`
660
743
  * in plugin code; route everything through this.
@@ -668,12 +751,18 @@ interface IPluginApi {
668
751
  }
669
752
  /**
670
753
  * Same shape on mobile, minus the rich-text editor adapter when the
671
- * plugin only supports read-only mobile rendering. React Native does not
672
- * render HTML, so there is no `sanitizeHtml`: mobile plugins show CMS text
673
- * with `parseInlineRich` / `stripHtmlToText`. A plugin that renders HTML in
674
- * a WebView sanitizes it there itself.
754
+ * plugin only supports read-only mobile rendering. Web-only C11 / C23 members
755
+ * are omitted. React Native does not render HTML, so there is no
756
+ * `sanitizeHtml` on mobile. HTML rule for mobile plugins:
757
+ * - Native React Native text: `parseInlineRich` (inline formatting and
758
+ * links) and `stripHtmlToText` (plain text), both exported from
759
+ * `@selfhelp/shared/plugin-sdk`.
760
+ * - HTML inside the plugin's own WebView: the plugin bundles a sanitizer into
761
+ * the WebView runtime and keeps a strict CSP. The host offers no sanitizer
762
+ * on mobile.
763
+ * - Web part: `api.sanitizeHtml`; never bundle a sanitizer there.
675
764
  */
676
- interface IMobilePluginApi extends Omit<IPluginApi, 'richTextEditor' | 'sanitizeHtml'> {
765
+ interface IMobilePluginApi extends Omit<IPluginApi, 'richTextEditor' | 'sanitizeHtml' | 'sectionAnchor' | 'resources' | 'ui' | 'settings'> {
677
766
  /** Mobile builds without rich-text support set this to `null`. */
678
767
  richTextEditor: IRichTextEditorAdapter | null;
679
768
  }
@@ -707,6 +796,11 @@ interface IPluginRegistration {
707
796
  * `field_types`) without the host having to hardcode the renderer.
708
797
  */
709
798
  fieldRenderers?: IFieldRendererDefinition[];
799
+ /**
800
+ * Declarative sync map (C10). The host invalidates each matching
801
+ * `queryKey` as a prefix when a change notice carries a listed tag.
802
+ */
803
+ sync?: IPluginSyncEntry[];
710
804
  }
711
805
  /**
712
806
  * Returned by `defineMobilePlugin()` for the mobile side of a plugin.
@@ -721,6 +815,11 @@ interface IMobilePluginRegistration {
721
815
  realtimeTopics?: IPluginRealtimeTopic[];
722
816
  /** Mobile feature flags (mirror of the manifest flags). */
723
817
  featureFlags?: IPluginFeatureFlag[];
818
+ /**
819
+ * Declarative sync map (C10). Same shape as the web registration; the
820
+ * mobile host invalidates matching query keys from `applySyncTags`.
821
+ */
822
+ sync?: IPluginSyncEntry[];
724
823
  }
725
824
 
726
825
  /**
@@ -826,6 +925,67 @@ interface IMobileHostResponse<TData = unknown> {
826
925
  */
827
926
  sessionExpired?: boolean;
828
927
  }
928
+ /**
929
+ * One file part of a multipart upload the plugin asks the host to send
930
+ * (renderer 0.4.0, C27). Give exactly one of {@link uri} or {@link base64}.
931
+ */
932
+ interface IMobileHostUploadFile {
933
+ /** Multipart part name (the field name the plugin's route reads). */
934
+ field: string;
935
+ /** File name sent to the server. */
936
+ name: string;
937
+ /** MIME type, e.g. `audio/m4a`. */
938
+ type: string;
939
+ /**
940
+ * `file://` or `content://` (native), `blob:` or `data:` (web preview).
941
+ * Exclusive with {@link base64}.
942
+ */
943
+ uri?: string;
944
+ /** Raw base64 without a `data:` prefix. Exclusive with {@link uri}. */
945
+ base64?: string;
946
+ }
947
+ /**
948
+ * A protected multipart upload (renderer 0.4.0, C27). Same path rules as
949
+ * {@link IMobileHostRequest}: relative to the host API base, absolute URLs are
950
+ * refused.
951
+ */
952
+ interface IMobileHostUploadRequest {
953
+ /** Path relative to the host API base, like {@link IMobileHostRequest.path}. */
954
+ path: string;
955
+ /** HTTP method. Defaults to `POST`. */
956
+ method?: 'POST' | 'PUT';
957
+ /** Text parts of the multipart body. */
958
+ fields?: Record<string, string>;
959
+ /** File parts. At least one is required. */
960
+ files: IMobileHostUploadFile[];
961
+ /** Extra request headers. */
962
+ headers?: Record<string, string>;
963
+ /** Query parameters appended to the path. */
964
+ query?: Record<string, string | number | boolean>;
965
+ }
966
+ /** What a plugin may ask the host to request from the system (C28). */
967
+ type TMobileHostPermission = 'microphone' | 'camera';
968
+ /**
969
+ * Answer to {@link IMobileHostServices.requestPermission}: `granted`, `denied`
970
+ * (the user said no and the app may ask again) or `blocked` (the system will
971
+ * not show the prompt again; send the user to {@link IMobileHostServices.openAppSettings}).
972
+ */
973
+ type TMobileHostPermissionState = 'granted' | 'denied' | 'blocked';
974
+ /**
975
+ * Small device key-value store for one plugin, one user and one server (C29).
976
+ * Meant for drafts and view state. It is not encrypted: never keep secrets or
977
+ * tokens in it. The server still decides everything on submit.
978
+ */
979
+ interface IMobilePluginStorage {
980
+ /** The stored value, or `null` when the key is not set. */
981
+ getItem(key: string): Promise<string | null>;
982
+ /** Stores a value; rejects with `Error('plugin_storage_full')` over the size cap and changes nothing. */
983
+ setItem(key: string, value: string): Promise<void>;
984
+ /** Removes one key. */
985
+ removeItem(key: string): Promise<void>;
986
+ /** Removes everything of this plugin, this user and this server only. */
987
+ clear(): Promise<void>;
988
+ }
829
989
  /**
830
990
  * Authenticated host services exposed to a plugin's mobile package. The
831
991
  * host owns the token + refresh; the plugin only describes the request.
@@ -863,6 +1023,46 @@ interface IMobileHostServices {
863
1023
  * gracefully rather than assume it exists.
864
1024
  */
865
1025
  navigate?(target: string, external?: boolean): void;
1026
+ /**
1027
+ * Send a `multipart/form-data` request through the host (renderer 0.4.0).
1028
+ * The host attaches the token and client headers, makes one 401 refresh
1029
+ * retry and answers in the {@link IMobileHostResponse} shape, like
1030
+ * {@link request}. An absolute path is refused. Nothing is sent, and the
1031
+ * answer is `{ ok: false, status: 0, reason }`, when `reason` is
1032
+ * `invalid_upload` (no file, or a file with both or neither of `uri` and
1033
+ * `base64`) or `file_too_large` (one total size limit per request). The
1034
+ * host removes any temporary file it wrote for a `base64` input.
1035
+ *
1036
+ * Optional: an older host omits it, so a plugin MUST feature-detect
1037
+ * (`if (host.upload)`) and degrade gracefully.
1038
+ */
1039
+ upload?<TData = unknown>(req: IMobileHostUploadRequest): Promise<IMobileHostResponse<TData>>;
1040
+ /**
1041
+ * Ask the system for microphone or camera access (renderer 0.4.0). Only the
1042
+ * app asks; a plugin in a WebView cannot. Resolves to `granted`, `denied`
1043
+ * or `blocked` ({@link TMobileHostPermissionState}); on `blocked` the plugin
1044
+ * should explain why it needs the permission and offer
1045
+ * {@link openAppSettings}.
1046
+ *
1047
+ * Optional: feature-detect (`if (host.requestPermission)`).
1048
+ */
1049
+ requestPermission?(kind: TMobileHostPermission): Promise<TMobileHostPermissionState>;
1050
+ /**
1051
+ * Open the app's system settings page so the user can change a `blocked`
1052
+ * permission (renderer 0.4.0). Does nothing in the web preview.
1053
+ *
1054
+ * Optional: feature-detect (`if (host.openAppSettings)`).
1055
+ */
1056
+ openAppSettings?(): void;
1057
+ /**
1058
+ * Device storage for the given plugin id, scoped to the current server and
1059
+ * user (guest = 0), emptied on logout, server switch and a rejected token
1060
+ * refresh (renderer 0.4.0, C29). Throws when `pluginId` does not match the
1061
+ * manifest id pattern. Not for secrets.
1062
+ *
1063
+ * Optional: feature-detect (`if (host.getPluginStorage)`).
1064
+ */
1065
+ getPluginStorage?(pluginId: string): IMobilePluginStorage;
866
1066
  }
867
1067
  /**
868
1068
  * Register the host services implementation. Called once by the native
@@ -1059,4 +1259,4 @@ declare function isPluginRuntimeShimSpecifier(value: unknown): value is TPluginR
1059
1259
  */
1060
1260
  declare const PLUGIN_RUNTIME_IMPORT_MAP: Readonly<Record<TPluginRuntimeShimSpecifier, string>>;
1061
1261
 
1062
- export { type IAdminPageDefinition, type IFieldRendererDefinition, type IMenuItemDefinition, type IMobileHostRequest, type IMobileHostResponse, type IMobileHostServices, type IMobilePluginApi, type IMobilePluginRegistration, type IPluginApi, type IPluginFeatureFlag, type IPluginFieldRendererProps, type IPluginHealthCheck, type IPluginLock, type IPluginLockEntry, type IPluginLockMigration, type IPluginLockMobileEntry, type IPluginPageModal, type IPluginRealtimePublisher, type IPluginRealtimeTopic, type IPluginRegistration, type IPluginRegistry, type IPluginRelease, type IPluginStylePage, type IPluginStyleProps, type IRealtimeTransport, type IRegistryReleaseRef, type IRegistrySignatureBlock, type IRichTextEditorAdapter, type IRichTextEditorAdapterOptions, type IRichTextEditorValue, type IStyleDefinition, type IUsePluginRealtimeOptions, type IUsePluginRealtimeResult, MOBILE_RENDERER_VERSION, PLUGIN_API_VERSION, PLUGIN_REGISTRY_CHANNELS, PLUGIN_RUNTIME_GLOBAL_KEY, PLUGIN_RUNTIME_IMPORT_MAP, PLUGIN_RUNTIME_SHIM_BASE_PATH, PLUGIN_RUNTIME_SHIM_SPECIFIERS, type TMobileHostMethod, type TPluginRegistryChannel, type TPluginRuntimeShimSpecifier, type TRealtimeTransportFactory, assertCmsCompatibility, assertPluginApiVersion, assertPluginVersionSemantics, buildPluginRuntimeShimPath, compareSemver, defineMobilePlugin, definePlugin, definePluginRealtimeTopic, getMobileHostServices, isMobileRendererCompatible, isPluginApiCompatible, isPluginRuntimeShimSpecifier, parseSemver, satisfiesSemverRange, setMobileHostServices, usePluginRealtime };
1262
+ export { type IAdminPageDefinition, type IFieldRendererDefinition, type IMenuItemDefinition, type IMobileHostRequest, type IMobileHostResponse, type IMobileHostServices, type IMobileHostUploadFile, type IMobileHostUploadRequest, type IMobilePluginApi, type IMobilePluginRegistration, type IMobilePluginStorage, type IPluginApi, type IPluginFeatureFlag, type IPluginFieldRendererProps, type IPluginHealthCheck, type IPluginLock, type IPluginLockEntry, type IPluginLockMigration, type IPluginLockMobileEntry, type IPluginPageModal, type IPluginRealtimePublisher, type IPluginRealtimeTopic, type IPluginRegistration, type IPluginRegistry, type IPluginRelease, type IPluginSettingViewItem, type IPluginSettingsView, type IPluginStylePage, type IPluginStyleProps, IPluginSyncEntry, type IRealtimeTransport, type IRegistryReleaseRef, type IRegistrySignatureBlock, type IResourceUsage, type IRichTextEditorAdapter, type IRichTextEditorAdapterOptions, type IRichTextEditorValue, type IStyleDefinition, type IUsePluginRealtimeOptions, type IUsePluginRealtimeResult, MOBILE_RENDERER_VERSION, PLUGIN_API_VERSION, PLUGIN_REGISTRY_CHANNELS, PLUGIN_RUNTIME_GLOBAL_KEY, PLUGIN_RUNTIME_IMPORT_MAP, PLUGIN_RUNTIME_SHIM_BASE_PATH, PLUGIN_RUNTIME_SHIM_SPECIFIERS, type TMobileHostMethod, type TMobileHostPermission, type TMobileHostPermissionState, type TPluginRegistryChannel, type TPluginRuntimeShimSpecifier, type TRealtimeTransportFactory, assertCmsCompatibility, assertPluginApiVersion, assertPluginVersionSemantics, buildPluginRuntimeShimPath, compareSemver, defineMobilePlugin, definePlugin, definePluginRealtimeTopic, getMobileHostServices, isMobileRendererCompatible, isPluginApiCompatible, isPluginRuntimeShimSpecifier, parseSemver, satisfiesSemverRange, setMobileHostServices, usePluginRealtime };