@selfhelp/shared 1.1.0 → 1.2.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 +39 -0
- package/README.md +21 -0
- package/dist/plugin-sdk/index.d.mts +97 -2
- package/dist/plugin-sdk/index.d.ts +97 -2
- package/dist/plugin-sdk/index.js +42 -1
- package/dist/plugin-sdk/index.mjs +36 -1
- package/package.json +1 -1
- package/src/plugin-sdk/index.ts +10 -0
- package/src/plugin-sdk/runtime-shim.ts +140 -0
- package/src/plugin-sdk/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,45 @@ All notable changes to `@selfhelp/shared` will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
This project follows semantic versioning.
|
|
6
6
|
|
|
7
|
+
## [1.2.0] - 2026-05-28
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Canonical plugin runtime-shim contract exported from
|
|
12
|
+
`@selfhelp/shared/plugin-sdk`. This is the single source of truth
|
|
13
|
+
every consumer (host import map, host `globalThis` stash, host
|
|
14
|
+
`/api/plugins/runtime-shim/*` BFF route, plugin Vite build, plugin
|
|
15
|
+
dev-runtime server) now reads from, so the three pieces cannot
|
|
16
|
+
drift apart again:
|
|
17
|
+
- `PLUGIN_RUNTIME_SHIM_SPECIFIERS` — readonly list of every bare
|
|
18
|
+
specifier the host shims to plugins. Includes the previously
|
|
19
|
+
missing `react/jsx-dev-runtime` (needed by Vite's React plugin in
|
|
20
|
+
dev mode) and `@mantine/notifications` (consumed by plugins that
|
|
21
|
+
show toast notifications), so dev-server bundles can resolve them
|
|
22
|
+
instead of bundling a second copy of React or Mantine.
|
|
23
|
+
- `PLUGIN_RUNTIME_SHIM_BASE_PATH` — `/api/plugins/runtime-shim/`
|
|
24
|
+
constant; the host frontend owns this route.
|
|
25
|
+
- `PLUGIN_RUNTIME_GLOBAL_KEY` — `__SELFHELP_RUNTIME__` constant.
|
|
26
|
+
- `PLUGIN_RUNTIME_IMPORT_MAP` — frozen `Record` derived from the
|
|
27
|
+
specifier list, ready to be `JSON.stringify`ed into the host's
|
|
28
|
+
`<script type="importmap">` tag.
|
|
29
|
+
- `buildPluginRuntimeShimPath(specifier)` — string builder for a
|
|
30
|
+
single specifier.
|
|
31
|
+
- `isPluginRuntimeShimSpecifier(value)` — runtime type guard.
|
|
32
|
+
- `TPluginRuntimeShimSpecifier` — string-literal type union of the
|
|
33
|
+
supported specifiers.
|
|
34
|
+
- The plugin SDK contract version bumps from `1.1` to `1.2` to
|
|
35
|
+
reflect the additive surface. Hosts on SDK `1.2+` still accept
|
|
36
|
+
plugins declaring `pluginApiVersion: "1.1"`, so existing plugins
|
|
37
|
+
remain compatible.
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
|
|
41
|
+
- `PLUGIN_API_VERSION` constant: `1.1` → `1.2`. No behavioural
|
|
42
|
+
change for plugins that do not consume the runtime-shim contract
|
|
43
|
+
directly; this only signals which optional SDK surface the host
|
|
44
|
+
exposes.
|
|
45
|
+
|
|
7
46
|
## [1.1.0] - 2026-05-25
|
|
8
47
|
|
|
9
48
|
### Added
|
package/README.md
CHANGED
|
@@ -153,6 +153,27 @@ import { THEME_TOKENS } from '@selfhelp/shared/theme';
|
|
|
153
153
|
import tailwindPreset from '@selfhelp/shared/tailwind';
|
|
154
154
|
```
|
|
155
155
|
|
|
156
|
+
### Consume the plugin runtime-shim contract
|
|
157
|
+
|
|
158
|
+
Plugin builds and the host frontend share a single list of bare
|
|
159
|
+
specifiers that resolve through the host's runtime-shim BFF route.
|
|
160
|
+
Read the contract from `@selfhelp/shared/plugin-sdk` instead of
|
|
161
|
+
duplicating the list in plugin `vite.config.ts` files or in the host
|
|
162
|
+
`runtime-globals.ts`:
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import {
|
|
166
|
+
PLUGIN_RUNTIME_SHIM_SPECIFIERS,
|
|
167
|
+
PLUGIN_RUNTIME_IMPORT_MAP,
|
|
168
|
+
buildPluginRuntimeShimPath,
|
|
169
|
+
} from '@selfhelp/shared/plugin-sdk';
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
The contract is what guarantees `react`, `@mantine/core`,
|
|
173
|
+
`@tanstack/react-query`, and `@selfhelp/shared` (plus their
|
|
174
|
+
documented subpaths) stay single-instance across the host shell and
|
|
175
|
+
every loaded plugin.
|
|
176
|
+
|
|
156
177
|
### Build the package locally
|
|
157
178
|
|
|
158
179
|
```bash
|
|
@@ -13,7 +13,7 @@ import '../common-B96dASgu.mjs';
|
|
|
13
13
|
*
|
|
14
14
|
* Independent from the npm `version` of `@selfhelp/shared`.
|
|
15
15
|
*/
|
|
16
|
-
declare const PLUGIN_API_VERSION: "1.
|
|
16
|
+
declare const PLUGIN_API_VERSION: "1.2";
|
|
17
17
|
interface ISemver {
|
|
18
18
|
major: number;
|
|
19
19
|
minor: number;
|
|
@@ -950,4 +950,99 @@ interface IUsePluginRealtimeResult<TPayload = unknown> {
|
|
|
950
950
|
*/
|
|
951
951
|
declare function usePluginRealtime<TPayload = unknown>(options: IUsePluginRealtimeOptions<TPayload>): IUsePluginRealtimeResult<TPayload>;
|
|
952
952
|
|
|
953
|
-
|
|
953
|
+
/**
|
|
954
|
+
* Plugin runtime-shim contract.
|
|
955
|
+
*
|
|
956
|
+
* Plugins ship as native ESM bundles that import bare specifiers like
|
|
957
|
+
* `react`, `@mantine/core`, `@tanstack/react-query`, and
|
|
958
|
+
* `@selfhelp/shared/plugin-sdk`. The browser cannot resolve those
|
|
959
|
+
* without help, and the host explicitly does NOT want each plugin to
|
|
960
|
+
* bundle its own copy of those packages — a duplicate React breaks
|
|
961
|
+
* hooks, a duplicate `@tanstack/react-query` shadows the host's
|
|
962
|
+
* `QueryClient`, a duplicate `STYLE_REGISTRY` desynchronises the
|
|
963
|
+
* style dispatcher.
|
|
964
|
+
*
|
|
965
|
+
* Resolution strategy is a single contract shared across:
|
|
966
|
+
*
|
|
967
|
+
* 1. The host frontend (`sh-selfhelp_frontend`) which:
|
|
968
|
+
* - renders `<script type="importmap">` with the entries from
|
|
969
|
+
* {@link PLUGIN_RUNTIME_IMPORT_MAP},
|
|
970
|
+
* - serves a tiny per-module shim at
|
|
971
|
+
* {@link PLUGIN_RUNTIME_SHIM_BASE_PATH}`<specifier>`,
|
|
972
|
+
* - populates {@link PLUGIN_RUNTIME_GLOBAL_KEY} on `globalThis`
|
|
973
|
+
* with the singleton module objects the host already loaded.
|
|
974
|
+
* 2. Every plugin's frontend Vite build, which externalises the
|
|
975
|
+
* same specifiers and rewrites them to the matching shim URL so
|
|
976
|
+
* the published bundle's imports resolve through the host.
|
|
977
|
+
* 3. Every plugin's local dev-runtime server (Vite middleware),
|
|
978
|
+
* which inlines the shim payload fetched from the host so
|
|
979
|
+
* on-demand transforms still consume host singletons.
|
|
980
|
+
*
|
|
981
|
+
* Adding or removing a singleton is a single edit to
|
|
982
|
+
* {@link PLUGIN_RUNTIME_SHIM_SPECIFIERS}. The host shell, plugin
|
|
983
|
+
* builds, and plugin dev runtimes all derive their behaviour from
|
|
984
|
+
* that list, so they stay in lockstep automatically.
|
|
985
|
+
*/
|
|
986
|
+
/**
|
|
987
|
+
* Bare ESM specifier the host exposes to plugins as a runtime
|
|
988
|
+
* singleton. The order here is documentation-only; consumers should
|
|
989
|
+
* treat the list as a set.
|
|
990
|
+
*/
|
|
991
|
+
type TPluginRuntimeShimSpecifier = 'react' | 'react/jsx-runtime' | 'react/jsx-dev-runtime' | 'react-dom' | 'react-dom/client' | '@mantine/core' | '@mantine/hooks' | '@mantine/notifications' | '@tanstack/react-query' | '@selfhelp/shared' | '@selfhelp/shared/plugin-sdk' | '@selfhelp/shared/registry';
|
|
992
|
+
/**
|
|
993
|
+
* Canonical list of bare specifiers the host supports for plugin
|
|
994
|
+
* runtimes. Every entry MUST be:
|
|
995
|
+
*
|
|
996
|
+
* 1. Stashed on `globalThis[PLUGIN_RUNTIME_GLOBAL_KEY]` by the host
|
|
997
|
+
* (so the shim has something to re-export);
|
|
998
|
+
* 2. Listed in {@link PLUGIN_RUNTIME_IMPORT_MAP} (so the browser
|
|
999
|
+
* can rewrite the bare specifier to the shim URL); and
|
|
1000
|
+
* 3. Allowed by the host's `/api/plugins/runtime-shim/*` route
|
|
1001
|
+
* handler (so the shim payload is actually generated).
|
|
1002
|
+
*
|
|
1003
|
+
* The host frontend asserts (1)–(3) cover the same set at build
|
|
1004
|
+
* time; drift between them is a contract bug.
|
|
1005
|
+
*/
|
|
1006
|
+
declare const PLUGIN_RUNTIME_SHIM_SPECIFIERS: readonly TPluginRuntimeShimSpecifier[];
|
|
1007
|
+
/**
|
|
1008
|
+
* Host-relative path prefix for the per-module shim endpoint. The
|
|
1009
|
+
* full URL for a given specifier is built by appending the specifier
|
|
1010
|
+
* as-is (it already includes any `@scope/` segment and any
|
|
1011
|
+
* `/subpath`). Use {@link buildPluginRuntimeShimPath} so consumers
|
|
1012
|
+
* never reconstruct the join logic locally.
|
|
1013
|
+
*/
|
|
1014
|
+
declare const PLUGIN_RUNTIME_SHIM_BASE_PATH: "/api/plugins/runtime-shim/";
|
|
1015
|
+
/**
|
|
1016
|
+
* `globalThis` key the host populates with the singleton module
|
|
1017
|
+
* instances. The shim payload reads from this key at module-load
|
|
1018
|
+
* time, so identity is preserved between the host shell and every
|
|
1019
|
+
* plugin without any extra serialization.
|
|
1020
|
+
*/
|
|
1021
|
+
declare const PLUGIN_RUNTIME_GLOBAL_KEY: "__SELFHELP_RUNTIME__";
|
|
1022
|
+
/**
|
|
1023
|
+
* Build the host-relative URL the import map (and the plugin's Vite
|
|
1024
|
+
* config) should point a given specifier at. The returned string is
|
|
1025
|
+
* always same-origin with the host shell — the entire shim contract
|
|
1026
|
+
* relies on browsers loading the bundle from a URL whose imports
|
|
1027
|
+
* resolve to the host's origin.
|
|
1028
|
+
*/
|
|
1029
|
+
declare function buildPluginRuntimeShimPath(specifier: TPluginRuntimeShimSpecifier): string;
|
|
1030
|
+
/**
|
|
1031
|
+
* Type-guarded check that a runtime-supplied string is one of the
|
|
1032
|
+
* specifiers the host knows how to shim. Consumers that take user
|
|
1033
|
+
* input (route segments, manifest values) should always validate
|
|
1034
|
+
* through this helper before falling through to dynamic resolution.
|
|
1035
|
+
*/
|
|
1036
|
+
declare function isPluginRuntimeShimSpecifier(value: unknown): value is TPluginRuntimeShimSpecifier;
|
|
1037
|
+
/**
|
|
1038
|
+
* Bare-specifier → shim URL map. Rendered as the body of the
|
|
1039
|
+
* `<script type="importmap">` tag in the host's root layout. Plugins
|
|
1040
|
+
* also consume the same map at build time to keep externalisation
|
|
1041
|
+
* symmetric with the browser-side import map.
|
|
1042
|
+
*
|
|
1043
|
+
* Frozen so consumers can pass it directly to `JSON.stringify`
|
|
1044
|
+
* without worrying about accidental mutation.
|
|
1045
|
+
*/
|
|
1046
|
+
declare const PLUGIN_RUNTIME_IMPORT_MAP: Readonly<Record<TPluginRuntimeShimSpecifier, string>>;
|
|
1047
|
+
|
|
1048
|
+
export { type IAdminPageDefinition, type IFieldRendererDefinition, type IMenuItemDefinition, type IMobilePluginApi, type IMobilePluginRegistration, type IPluginApi, type IPluginFeatureFlag, type IPluginFieldRendererProps, type IPluginHealthCheck, type IPluginLock, type IPluginLockEntry, type IPluginLockMigration, type IPluginLockMobileEntry, type IPluginManifest, type IPluginManifestAdminPage, type IPluginManifestApiRoute, type IPluginManifestAsset, type IPluginManifestCapability, type IPluginManifestCompatibility, type IPluginManifestConflict, type IPluginManifestDataAccess, type IPluginManifestDependency, type IPluginManifestExternalHost, type IPluginManifestFeatureFlag, type IPluginManifestHealth, type IPluginManifestLookupExtension, type IPluginManifestMobile, type IPluginManifestPermission, type IPluginManifestRealtimeTopic, type IPluginManifestScheduledJob, type IPluginManifestSecurity, type IPluginManifestStyle, type IPluginManifestTrustLevel, type IPluginRealtimePublisher, type IPluginRealtimeTopic, type IPluginRegistration, type IPluginRegistry, type IPluginRegistryEntry, type IPluginRegistryVersionEntry, type IRealtimeTransport, type IRichTextEditorAdapter, type IRichTextEditorAdapterOptions, type IRichTextEditorValue, type IStyleDefinition, type IUsePluginRealtimeOptions, type IUsePluginRealtimeResult, PLUGIN_API_VERSION, PLUGIN_RUNTIME_GLOBAL_KEY, PLUGIN_RUNTIME_IMPORT_MAP, PLUGIN_RUNTIME_SHIM_BASE_PATH, PLUGIN_RUNTIME_SHIM_SPECIFIERS, type TPluginRegistryChannel, type TPluginRuntimeShimSpecifier, type TRealtimeTransportFactory, assertCmsCompatibility, assertPluginApiVersion, assertPluginVersionSemantics, buildPluginRuntimeShimPath, compareSemver, defineMobilePlugin, definePlugin, definePluginRealtimeTopic, isPluginApiCompatible, isPluginRuntimeShimSpecifier, parseSemver, satisfiesSemverRange, usePluginRealtime };
|
|
@@ -13,7 +13,7 @@ import '../common-B96dASgu.js';
|
|
|
13
13
|
*
|
|
14
14
|
* Independent from the npm `version` of `@selfhelp/shared`.
|
|
15
15
|
*/
|
|
16
|
-
declare const PLUGIN_API_VERSION: "1.
|
|
16
|
+
declare const PLUGIN_API_VERSION: "1.2";
|
|
17
17
|
interface ISemver {
|
|
18
18
|
major: number;
|
|
19
19
|
minor: number;
|
|
@@ -950,4 +950,99 @@ interface IUsePluginRealtimeResult<TPayload = unknown> {
|
|
|
950
950
|
*/
|
|
951
951
|
declare function usePluginRealtime<TPayload = unknown>(options: IUsePluginRealtimeOptions<TPayload>): IUsePluginRealtimeResult<TPayload>;
|
|
952
952
|
|
|
953
|
-
|
|
953
|
+
/**
|
|
954
|
+
* Plugin runtime-shim contract.
|
|
955
|
+
*
|
|
956
|
+
* Plugins ship as native ESM bundles that import bare specifiers like
|
|
957
|
+
* `react`, `@mantine/core`, `@tanstack/react-query`, and
|
|
958
|
+
* `@selfhelp/shared/plugin-sdk`. The browser cannot resolve those
|
|
959
|
+
* without help, and the host explicitly does NOT want each plugin to
|
|
960
|
+
* bundle its own copy of those packages — a duplicate React breaks
|
|
961
|
+
* hooks, a duplicate `@tanstack/react-query` shadows the host's
|
|
962
|
+
* `QueryClient`, a duplicate `STYLE_REGISTRY` desynchronises the
|
|
963
|
+
* style dispatcher.
|
|
964
|
+
*
|
|
965
|
+
* Resolution strategy is a single contract shared across:
|
|
966
|
+
*
|
|
967
|
+
* 1. The host frontend (`sh-selfhelp_frontend`) which:
|
|
968
|
+
* - renders `<script type="importmap">` with the entries from
|
|
969
|
+
* {@link PLUGIN_RUNTIME_IMPORT_MAP},
|
|
970
|
+
* - serves a tiny per-module shim at
|
|
971
|
+
* {@link PLUGIN_RUNTIME_SHIM_BASE_PATH}`<specifier>`,
|
|
972
|
+
* - populates {@link PLUGIN_RUNTIME_GLOBAL_KEY} on `globalThis`
|
|
973
|
+
* with the singleton module objects the host already loaded.
|
|
974
|
+
* 2. Every plugin's frontend Vite build, which externalises the
|
|
975
|
+
* same specifiers and rewrites them to the matching shim URL so
|
|
976
|
+
* the published bundle's imports resolve through the host.
|
|
977
|
+
* 3. Every plugin's local dev-runtime server (Vite middleware),
|
|
978
|
+
* which inlines the shim payload fetched from the host so
|
|
979
|
+
* on-demand transforms still consume host singletons.
|
|
980
|
+
*
|
|
981
|
+
* Adding or removing a singleton is a single edit to
|
|
982
|
+
* {@link PLUGIN_RUNTIME_SHIM_SPECIFIERS}. The host shell, plugin
|
|
983
|
+
* builds, and plugin dev runtimes all derive their behaviour from
|
|
984
|
+
* that list, so they stay in lockstep automatically.
|
|
985
|
+
*/
|
|
986
|
+
/**
|
|
987
|
+
* Bare ESM specifier the host exposes to plugins as a runtime
|
|
988
|
+
* singleton. The order here is documentation-only; consumers should
|
|
989
|
+
* treat the list as a set.
|
|
990
|
+
*/
|
|
991
|
+
type TPluginRuntimeShimSpecifier = 'react' | 'react/jsx-runtime' | 'react/jsx-dev-runtime' | 'react-dom' | 'react-dom/client' | '@mantine/core' | '@mantine/hooks' | '@mantine/notifications' | '@tanstack/react-query' | '@selfhelp/shared' | '@selfhelp/shared/plugin-sdk' | '@selfhelp/shared/registry';
|
|
992
|
+
/**
|
|
993
|
+
* Canonical list of bare specifiers the host supports for plugin
|
|
994
|
+
* runtimes. Every entry MUST be:
|
|
995
|
+
*
|
|
996
|
+
* 1. Stashed on `globalThis[PLUGIN_RUNTIME_GLOBAL_KEY]` by the host
|
|
997
|
+
* (so the shim has something to re-export);
|
|
998
|
+
* 2. Listed in {@link PLUGIN_RUNTIME_IMPORT_MAP} (so the browser
|
|
999
|
+
* can rewrite the bare specifier to the shim URL); and
|
|
1000
|
+
* 3. Allowed by the host's `/api/plugins/runtime-shim/*` route
|
|
1001
|
+
* handler (so the shim payload is actually generated).
|
|
1002
|
+
*
|
|
1003
|
+
* The host frontend asserts (1)–(3) cover the same set at build
|
|
1004
|
+
* time; drift between them is a contract bug.
|
|
1005
|
+
*/
|
|
1006
|
+
declare const PLUGIN_RUNTIME_SHIM_SPECIFIERS: readonly TPluginRuntimeShimSpecifier[];
|
|
1007
|
+
/**
|
|
1008
|
+
* Host-relative path prefix for the per-module shim endpoint. The
|
|
1009
|
+
* full URL for a given specifier is built by appending the specifier
|
|
1010
|
+
* as-is (it already includes any `@scope/` segment and any
|
|
1011
|
+
* `/subpath`). Use {@link buildPluginRuntimeShimPath} so consumers
|
|
1012
|
+
* never reconstruct the join logic locally.
|
|
1013
|
+
*/
|
|
1014
|
+
declare const PLUGIN_RUNTIME_SHIM_BASE_PATH: "/api/plugins/runtime-shim/";
|
|
1015
|
+
/**
|
|
1016
|
+
* `globalThis` key the host populates with the singleton module
|
|
1017
|
+
* instances. The shim payload reads from this key at module-load
|
|
1018
|
+
* time, so identity is preserved between the host shell and every
|
|
1019
|
+
* plugin without any extra serialization.
|
|
1020
|
+
*/
|
|
1021
|
+
declare const PLUGIN_RUNTIME_GLOBAL_KEY: "__SELFHELP_RUNTIME__";
|
|
1022
|
+
/**
|
|
1023
|
+
* Build the host-relative URL the import map (and the plugin's Vite
|
|
1024
|
+
* config) should point a given specifier at. The returned string is
|
|
1025
|
+
* always same-origin with the host shell — the entire shim contract
|
|
1026
|
+
* relies on browsers loading the bundle from a URL whose imports
|
|
1027
|
+
* resolve to the host's origin.
|
|
1028
|
+
*/
|
|
1029
|
+
declare function buildPluginRuntimeShimPath(specifier: TPluginRuntimeShimSpecifier): string;
|
|
1030
|
+
/**
|
|
1031
|
+
* Type-guarded check that a runtime-supplied string is one of the
|
|
1032
|
+
* specifiers the host knows how to shim. Consumers that take user
|
|
1033
|
+
* input (route segments, manifest values) should always validate
|
|
1034
|
+
* through this helper before falling through to dynamic resolution.
|
|
1035
|
+
*/
|
|
1036
|
+
declare function isPluginRuntimeShimSpecifier(value: unknown): value is TPluginRuntimeShimSpecifier;
|
|
1037
|
+
/**
|
|
1038
|
+
* Bare-specifier → shim URL map. Rendered as the body of the
|
|
1039
|
+
* `<script type="importmap">` tag in the host's root layout. Plugins
|
|
1040
|
+
* also consume the same map at build time to keep externalisation
|
|
1041
|
+
* symmetric with the browser-side import map.
|
|
1042
|
+
*
|
|
1043
|
+
* Frozen so consumers can pass it directly to `JSON.stringify`
|
|
1044
|
+
* without worrying about accidental mutation.
|
|
1045
|
+
*/
|
|
1046
|
+
declare const PLUGIN_RUNTIME_IMPORT_MAP: Readonly<Record<TPluginRuntimeShimSpecifier, string>>;
|
|
1047
|
+
|
|
1048
|
+
export { type IAdminPageDefinition, type IFieldRendererDefinition, type IMenuItemDefinition, type IMobilePluginApi, type IMobilePluginRegistration, type IPluginApi, type IPluginFeatureFlag, type IPluginFieldRendererProps, type IPluginHealthCheck, type IPluginLock, type IPluginLockEntry, type IPluginLockMigration, type IPluginLockMobileEntry, type IPluginManifest, type IPluginManifestAdminPage, type IPluginManifestApiRoute, type IPluginManifestAsset, type IPluginManifestCapability, type IPluginManifestCompatibility, type IPluginManifestConflict, type IPluginManifestDataAccess, type IPluginManifestDependency, type IPluginManifestExternalHost, type IPluginManifestFeatureFlag, type IPluginManifestHealth, type IPluginManifestLookupExtension, type IPluginManifestMobile, type IPluginManifestPermission, type IPluginManifestRealtimeTopic, type IPluginManifestScheduledJob, type IPluginManifestSecurity, type IPluginManifestStyle, type IPluginManifestTrustLevel, type IPluginRealtimePublisher, type IPluginRealtimeTopic, type IPluginRegistration, type IPluginRegistry, type IPluginRegistryEntry, type IPluginRegistryVersionEntry, type IRealtimeTransport, type IRichTextEditorAdapter, type IRichTextEditorAdapterOptions, type IRichTextEditorValue, type IStyleDefinition, type IUsePluginRealtimeOptions, type IUsePluginRealtimeResult, PLUGIN_API_VERSION, PLUGIN_RUNTIME_GLOBAL_KEY, PLUGIN_RUNTIME_IMPORT_MAP, PLUGIN_RUNTIME_SHIM_BASE_PATH, PLUGIN_RUNTIME_SHIM_SPECIFIERS, type TPluginRegistryChannel, type TPluginRuntimeShimSpecifier, type TRealtimeTransportFactory, assertCmsCompatibility, assertPluginApiVersion, assertPluginVersionSemantics, buildPluginRuntimeShimPath, compareSemver, defineMobilePlugin, definePlugin, definePluginRealtimeTopic, isPluginApiCompatible, isPluginRuntimeShimSpecifier, parseSemver, satisfiesSemverRange, usePluginRealtime };
|
package/dist/plugin-sdk/index.js
CHANGED
|
@@ -21,14 +21,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var plugin_sdk_exports = {};
|
|
22
22
|
__export(plugin_sdk_exports, {
|
|
23
23
|
PLUGIN_API_VERSION: () => PLUGIN_API_VERSION,
|
|
24
|
+
PLUGIN_RUNTIME_GLOBAL_KEY: () => PLUGIN_RUNTIME_GLOBAL_KEY,
|
|
25
|
+
PLUGIN_RUNTIME_IMPORT_MAP: () => PLUGIN_RUNTIME_IMPORT_MAP,
|
|
26
|
+
PLUGIN_RUNTIME_SHIM_BASE_PATH: () => PLUGIN_RUNTIME_SHIM_BASE_PATH,
|
|
27
|
+
PLUGIN_RUNTIME_SHIM_SPECIFIERS: () => PLUGIN_RUNTIME_SHIM_SPECIFIERS,
|
|
24
28
|
assertCmsCompatibility: () => assertCmsCompatibility,
|
|
25
29
|
assertPluginApiVersion: () => assertPluginApiVersion,
|
|
26
30
|
assertPluginVersionSemantics: () => assertPluginVersionSemantics,
|
|
31
|
+
buildPluginRuntimeShimPath: () => buildPluginRuntimeShimPath,
|
|
27
32
|
compareSemver: () => compareSemver,
|
|
28
33
|
defineMobilePlugin: () => defineMobilePlugin,
|
|
29
34
|
definePlugin: () => definePlugin,
|
|
30
35
|
definePluginRealtimeTopic: () => definePluginRealtimeTopic,
|
|
31
36
|
isPluginApiCompatible: () => isPluginApiCompatible,
|
|
37
|
+
isPluginRuntimeShimSpecifier: () => isPluginRuntimeShimSpecifier,
|
|
32
38
|
parseSemver: () => parseSemver,
|
|
33
39
|
satisfiesSemverRange: () => satisfiesSemverRange,
|
|
34
40
|
usePluginRealtime: () => usePluginRealtime
|
|
@@ -36,7 +42,7 @@ __export(plugin_sdk_exports, {
|
|
|
36
42
|
module.exports = __toCommonJS(plugin_sdk_exports);
|
|
37
43
|
|
|
38
44
|
// src/plugin-sdk/version.ts
|
|
39
|
-
var PLUGIN_API_VERSION = "1.
|
|
45
|
+
var PLUGIN_API_VERSION = "1.2";
|
|
40
46
|
var SEMVER_REGEX = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
|
|
41
47
|
function parseSemver(version) {
|
|
42
48
|
const match = SEMVER_REGEX.exec(version);
|
|
@@ -473,17 +479,52 @@ function usePluginRealtime(options) {
|
|
|
473
479
|
}, [enabled, endpoint, pluginId, topic, topicParamsKey, transportFactory]);
|
|
474
480
|
return { data, isOnline, lastEventAt, error };
|
|
475
481
|
}
|
|
482
|
+
|
|
483
|
+
// src/plugin-sdk/runtime-shim.ts
|
|
484
|
+
var PLUGIN_RUNTIME_SHIM_SPECIFIERS = [
|
|
485
|
+
"react",
|
|
486
|
+
"react/jsx-runtime",
|
|
487
|
+
"react/jsx-dev-runtime",
|
|
488
|
+
"react-dom",
|
|
489
|
+
"react-dom/client",
|
|
490
|
+
"@mantine/core",
|
|
491
|
+
"@mantine/hooks",
|
|
492
|
+
"@mantine/notifications",
|
|
493
|
+
"@tanstack/react-query",
|
|
494
|
+
"@selfhelp/shared",
|
|
495
|
+
"@selfhelp/shared/plugin-sdk",
|
|
496
|
+
"@selfhelp/shared/registry"
|
|
497
|
+
];
|
|
498
|
+
var PLUGIN_RUNTIME_SHIM_BASE_PATH = "/api/plugins/runtime-shim/";
|
|
499
|
+
var PLUGIN_RUNTIME_GLOBAL_KEY = "__SELFHELP_RUNTIME__";
|
|
500
|
+
function buildPluginRuntimeShimPath(specifier) {
|
|
501
|
+
return `${PLUGIN_RUNTIME_SHIM_BASE_PATH}${specifier}`;
|
|
502
|
+
}
|
|
503
|
+
function isPluginRuntimeShimSpecifier(value) {
|
|
504
|
+
return typeof value === "string" && PLUGIN_RUNTIME_SHIM_SPECIFIERS.includes(value);
|
|
505
|
+
}
|
|
506
|
+
var PLUGIN_RUNTIME_IMPORT_MAP = Object.freeze(
|
|
507
|
+
Object.fromEntries(
|
|
508
|
+
PLUGIN_RUNTIME_SHIM_SPECIFIERS.map((s) => [s, buildPluginRuntimeShimPath(s)])
|
|
509
|
+
)
|
|
510
|
+
);
|
|
476
511
|
// Annotate the CommonJS export names for ESM import in node:
|
|
477
512
|
0 && (module.exports = {
|
|
478
513
|
PLUGIN_API_VERSION,
|
|
514
|
+
PLUGIN_RUNTIME_GLOBAL_KEY,
|
|
515
|
+
PLUGIN_RUNTIME_IMPORT_MAP,
|
|
516
|
+
PLUGIN_RUNTIME_SHIM_BASE_PATH,
|
|
517
|
+
PLUGIN_RUNTIME_SHIM_SPECIFIERS,
|
|
479
518
|
assertCmsCompatibility,
|
|
480
519
|
assertPluginApiVersion,
|
|
481
520
|
assertPluginVersionSemantics,
|
|
521
|
+
buildPluginRuntimeShimPath,
|
|
482
522
|
compareSemver,
|
|
483
523
|
defineMobilePlugin,
|
|
484
524
|
definePlugin,
|
|
485
525
|
definePluginRealtimeTopic,
|
|
486
526
|
isPluginApiCompatible,
|
|
527
|
+
isPluginRuntimeShimSpecifier,
|
|
487
528
|
parseSemver,
|
|
488
529
|
satisfiesSemverRange,
|
|
489
530
|
usePluginRealtime
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/plugin-sdk/version.ts
|
|
2
|
-
var PLUGIN_API_VERSION = "1.
|
|
2
|
+
var PLUGIN_API_VERSION = "1.2";
|
|
3
3
|
var SEMVER_REGEX = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
|
|
4
4
|
function parseSemver(version) {
|
|
5
5
|
const match = SEMVER_REGEX.exec(version);
|
|
@@ -436,16 +436,51 @@ function usePluginRealtime(options) {
|
|
|
436
436
|
}, [enabled, endpoint, pluginId, topic, topicParamsKey, transportFactory]);
|
|
437
437
|
return { data, isOnline, lastEventAt, error };
|
|
438
438
|
}
|
|
439
|
+
|
|
440
|
+
// src/plugin-sdk/runtime-shim.ts
|
|
441
|
+
var PLUGIN_RUNTIME_SHIM_SPECIFIERS = [
|
|
442
|
+
"react",
|
|
443
|
+
"react/jsx-runtime",
|
|
444
|
+
"react/jsx-dev-runtime",
|
|
445
|
+
"react-dom",
|
|
446
|
+
"react-dom/client",
|
|
447
|
+
"@mantine/core",
|
|
448
|
+
"@mantine/hooks",
|
|
449
|
+
"@mantine/notifications",
|
|
450
|
+
"@tanstack/react-query",
|
|
451
|
+
"@selfhelp/shared",
|
|
452
|
+
"@selfhelp/shared/plugin-sdk",
|
|
453
|
+
"@selfhelp/shared/registry"
|
|
454
|
+
];
|
|
455
|
+
var PLUGIN_RUNTIME_SHIM_BASE_PATH = "/api/plugins/runtime-shim/";
|
|
456
|
+
var PLUGIN_RUNTIME_GLOBAL_KEY = "__SELFHELP_RUNTIME__";
|
|
457
|
+
function buildPluginRuntimeShimPath(specifier) {
|
|
458
|
+
return `${PLUGIN_RUNTIME_SHIM_BASE_PATH}${specifier}`;
|
|
459
|
+
}
|
|
460
|
+
function isPluginRuntimeShimSpecifier(value) {
|
|
461
|
+
return typeof value === "string" && PLUGIN_RUNTIME_SHIM_SPECIFIERS.includes(value);
|
|
462
|
+
}
|
|
463
|
+
var PLUGIN_RUNTIME_IMPORT_MAP = Object.freeze(
|
|
464
|
+
Object.fromEntries(
|
|
465
|
+
PLUGIN_RUNTIME_SHIM_SPECIFIERS.map((s) => [s, buildPluginRuntimeShimPath(s)])
|
|
466
|
+
)
|
|
467
|
+
);
|
|
439
468
|
export {
|
|
440
469
|
PLUGIN_API_VERSION,
|
|
470
|
+
PLUGIN_RUNTIME_GLOBAL_KEY,
|
|
471
|
+
PLUGIN_RUNTIME_IMPORT_MAP,
|
|
472
|
+
PLUGIN_RUNTIME_SHIM_BASE_PATH,
|
|
473
|
+
PLUGIN_RUNTIME_SHIM_SPECIFIERS,
|
|
441
474
|
assertCmsCompatibility,
|
|
442
475
|
assertPluginApiVersion,
|
|
443
476
|
assertPluginVersionSemantics,
|
|
477
|
+
buildPluginRuntimeShimPath,
|
|
444
478
|
compareSemver,
|
|
445
479
|
defineMobilePlugin,
|
|
446
480
|
definePlugin,
|
|
447
481
|
definePluginRealtimeTopic,
|
|
448
482
|
isPluginApiCompatible,
|
|
483
|
+
isPluginRuntimeShimSpecifier,
|
|
449
484
|
parseSemver,
|
|
450
485
|
satisfiesSemverRange,
|
|
451
486
|
usePluginRealtime
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@selfhelp/shared",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Shared TypeScript package for SelfHelp web frontend and mobile app: style registry, types, API contracts, Mantine theme tokens, condition + interpolation engines, CMS class allow-list.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
package/src/plugin-sdk/index.ts
CHANGED
|
@@ -91,3 +91,13 @@ export type {
|
|
|
91
91
|
IUsePluginRealtimeResult,
|
|
92
92
|
} from './realtime';
|
|
93
93
|
export { usePluginRealtime } from './realtime';
|
|
94
|
+
|
|
95
|
+
export type { TPluginRuntimeShimSpecifier } from './runtime-shim';
|
|
96
|
+
export {
|
|
97
|
+
PLUGIN_RUNTIME_SHIM_SPECIFIERS,
|
|
98
|
+
PLUGIN_RUNTIME_SHIM_BASE_PATH,
|
|
99
|
+
PLUGIN_RUNTIME_GLOBAL_KEY,
|
|
100
|
+
PLUGIN_RUNTIME_IMPORT_MAP,
|
|
101
|
+
buildPluginRuntimeShimPath,
|
|
102
|
+
isPluginRuntimeShimSpecifier,
|
|
103
|
+
} from './runtime-shim';
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Plugin runtime-shim contract.
|
|
7
|
+
*
|
|
8
|
+
* Plugins ship as native ESM bundles that import bare specifiers like
|
|
9
|
+
* `react`, `@mantine/core`, `@tanstack/react-query`, and
|
|
10
|
+
* `@selfhelp/shared/plugin-sdk`. The browser cannot resolve those
|
|
11
|
+
* without help, and the host explicitly does NOT want each plugin to
|
|
12
|
+
* bundle its own copy of those packages — a duplicate React breaks
|
|
13
|
+
* hooks, a duplicate `@tanstack/react-query` shadows the host's
|
|
14
|
+
* `QueryClient`, a duplicate `STYLE_REGISTRY` desynchronises the
|
|
15
|
+
* style dispatcher.
|
|
16
|
+
*
|
|
17
|
+
* Resolution strategy is a single contract shared across:
|
|
18
|
+
*
|
|
19
|
+
* 1. The host frontend (`sh-selfhelp_frontend`) which:
|
|
20
|
+
* - renders `<script type="importmap">` with the entries from
|
|
21
|
+
* {@link PLUGIN_RUNTIME_IMPORT_MAP},
|
|
22
|
+
* - serves a tiny per-module shim at
|
|
23
|
+
* {@link PLUGIN_RUNTIME_SHIM_BASE_PATH}`<specifier>`,
|
|
24
|
+
* - populates {@link PLUGIN_RUNTIME_GLOBAL_KEY} on `globalThis`
|
|
25
|
+
* with the singleton module objects the host already loaded.
|
|
26
|
+
* 2. Every plugin's frontend Vite build, which externalises the
|
|
27
|
+
* same specifiers and rewrites them to the matching shim URL so
|
|
28
|
+
* the published bundle's imports resolve through the host.
|
|
29
|
+
* 3. Every plugin's local dev-runtime server (Vite middleware),
|
|
30
|
+
* which inlines the shim payload fetched from the host so
|
|
31
|
+
* on-demand transforms still consume host singletons.
|
|
32
|
+
*
|
|
33
|
+
* Adding or removing a singleton is a single edit to
|
|
34
|
+
* {@link PLUGIN_RUNTIME_SHIM_SPECIFIERS}. The host shell, plugin
|
|
35
|
+
* builds, and plugin dev runtimes all derive their behaviour from
|
|
36
|
+
* that list, so they stay in lockstep automatically.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Bare ESM specifier the host exposes to plugins as a runtime
|
|
41
|
+
* singleton. The order here is documentation-only; consumers should
|
|
42
|
+
* treat the list as a set.
|
|
43
|
+
*/
|
|
44
|
+
export type TPluginRuntimeShimSpecifier =
|
|
45
|
+
| 'react'
|
|
46
|
+
| 'react/jsx-runtime'
|
|
47
|
+
| 'react/jsx-dev-runtime'
|
|
48
|
+
| 'react-dom'
|
|
49
|
+
| 'react-dom/client'
|
|
50
|
+
| '@mantine/core'
|
|
51
|
+
| '@mantine/hooks'
|
|
52
|
+
| '@mantine/notifications'
|
|
53
|
+
| '@tanstack/react-query'
|
|
54
|
+
| '@selfhelp/shared'
|
|
55
|
+
| '@selfhelp/shared/plugin-sdk'
|
|
56
|
+
| '@selfhelp/shared/registry';
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Canonical list of bare specifiers the host supports for plugin
|
|
60
|
+
* runtimes. Every entry MUST be:
|
|
61
|
+
*
|
|
62
|
+
* 1. Stashed on `globalThis[PLUGIN_RUNTIME_GLOBAL_KEY]` by the host
|
|
63
|
+
* (so the shim has something to re-export);
|
|
64
|
+
* 2. Listed in {@link PLUGIN_RUNTIME_IMPORT_MAP} (so the browser
|
|
65
|
+
* can rewrite the bare specifier to the shim URL); and
|
|
66
|
+
* 3. Allowed by the host's `/api/plugins/runtime-shim/*` route
|
|
67
|
+
* handler (so the shim payload is actually generated).
|
|
68
|
+
*
|
|
69
|
+
* The host frontend asserts (1)–(3) cover the same set at build
|
|
70
|
+
* time; drift between them is a contract bug.
|
|
71
|
+
*/
|
|
72
|
+
export const PLUGIN_RUNTIME_SHIM_SPECIFIERS: readonly TPluginRuntimeShimSpecifier[] = [
|
|
73
|
+
'react',
|
|
74
|
+
'react/jsx-runtime',
|
|
75
|
+
'react/jsx-dev-runtime',
|
|
76
|
+
'react-dom',
|
|
77
|
+
'react-dom/client',
|
|
78
|
+
'@mantine/core',
|
|
79
|
+
'@mantine/hooks',
|
|
80
|
+
'@mantine/notifications',
|
|
81
|
+
'@tanstack/react-query',
|
|
82
|
+
'@selfhelp/shared',
|
|
83
|
+
'@selfhelp/shared/plugin-sdk',
|
|
84
|
+
'@selfhelp/shared/registry',
|
|
85
|
+
] as const;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Host-relative path prefix for the per-module shim endpoint. The
|
|
89
|
+
* full URL for a given specifier is built by appending the specifier
|
|
90
|
+
* as-is (it already includes any `@scope/` segment and any
|
|
91
|
+
* `/subpath`). Use {@link buildPluginRuntimeShimPath} so consumers
|
|
92
|
+
* never reconstruct the join logic locally.
|
|
93
|
+
*/
|
|
94
|
+
export const PLUGIN_RUNTIME_SHIM_BASE_PATH = '/api/plugins/runtime-shim/' as const;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* `globalThis` key the host populates with the singleton module
|
|
98
|
+
* instances. The shim payload reads from this key at module-load
|
|
99
|
+
* time, so identity is preserved between the host shell and every
|
|
100
|
+
* plugin without any extra serialization.
|
|
101
|
+
*/
|
|
102
|
+
export const PLUGIN_RUNTIME_GLOBAL_KEY = '__SELFHELP_RUNTIME__' as const;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Build the host-relative URL the import map (and the plugin's Vite
|
|
106
|
+
* config) should point a given specifier at. The returned string is
|
|
107
|
+
* always same-origin with the host shell — the entire shim contract
|
|
108
|
+
* relies on browsers loading the bundle from a URL whose imports
|
|
109
|
+
* resolve to the host's origin.
|
|
110
|
+
*/
|
|
111
|
+
export function buildPluginRuntimeShimPath(specifier: TPluginRuntimeShimSpecifier): string {
|
|
112
|
+
return `${PLUGIN_RUNTIME_SHIM_BASE_PATH}${specifier}`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Type-guarded check that a runtime-supplied string is one of the
|
|
117
|
+
* specifiers the host knows how to shim. Consumers that take user
|
|
118
|
+
* input (route segments, manifest values) should always validate
|
|
119
|
+
* through this helper before falling through to dynamic resolution.
|
|
120
|
+
*/
|
|
121
|
+
export function isPluginRuntimeShimSpecifier(value: unknown): value is TPluginRuntimeShimSpecifier {
|
|
122
|
+
return typeof value === 'string'
|
|
123
|
+
&& (PLUGIN_RUNTIME_SHIM_SPECIFIERS as readonly string[]).includes(value);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Bare-specifier → shim URL map. Rendered as the body of the
|
|
128
|
+
* `<script type="importmap">` tag in the host's root layout. Plugins
|
|
129
|
+
* also consume the same map at build time to keep externalisation
|
|
130
|
+
* symmetric with the browser-side import map.
|
|
131
|
+
*
|
|
132
|
+
* Frozen so consumers can pass it directly to `JSON.stringify`
|
|
133
|
+
* without worrying about accidental mutation.
|
|
134
|
+
*/
|
|
135
|
+
export const PLUGIN_RUNTIME_IMPORT_MAP: Readonly<Record<TPluginRuntimeShimSpecifier, string>>
|
|
136
|
+
= Object.freeze(
|
|
137
|
+
Object.fromEntries(
|
|
138
|
+
PLUGIN_RUNTIME_SHIM_SPECIFIERS.map((s) => [s, buildPluginRuntimeShimPath(s)]),
|
|
139
|
+
) as Record<TPluginRuntimeShimSpecifier, string>,
|
|
140
|
+
);
|
|
@@ -14,7 +14,7 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
14
14
|
*
|
|
15
15
|
* Independent from the npm `version` of `@selfhelp/shared`.
|
|
16
16
|
*/
|
|
17
|
-
export const PLUGIN_API_VERSION = '1.
|
|
17
|
+
export const PLUGIN_API_VERSION = '1.2' as const;
|
|
18
18
|
|
|
19
19
|
export interface ISemver {
|
|
20
20
|
major: number;
|