@selfhelp/shared 1.16.0 → 1.17.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 CHANGED
@@ -9,6 +9,27 @@ All notable changes to `@selfhelp/shared` will be documented in this file.
9
9
 
10
10
  This project follows semantic versioning.
11
11
 
12
+ ## v1.17.0
13
+
14
+ **Mobile host-navigation capability** — adds the optional
15
+ `IMobileHostServices.navigate(target, external?)` so a plugin's mobile package can
16
+ honour an in-content redirect (e.g. a survey's "redirect on completion") through
17
+ the host router instead of touching `window.location`. The host owns the router,
18
+ so it routes an internal CMS page keyword / in-app path through its own navigation
19
+ stack and only leaves the app for an explicit external URL — keeping redirects
20
+ correct in BOTH the native app and the CMS web preview iframe (where a raw
21
+ `location` assignment navigates and breaks the embedded frame). Additive only —
22
+ the method is optional, so `^1.x` consumers and older hosts/plugins are unaffected.
23
+
24
+ ### Added (additive, non-breaking)
25
+
26
+ - **`IMobileHostServices.navigate?(target, external?)`** — optional host-owned
27
+ navigation; a plugin MUST feature-detect (`if (host.navigate)`) and degrade
28
+ gracefully on an older host.
29
+ - **`MOBILE_RENDERER_VERSION`** bumped `0.2.0 -> 0.3.0` (additive renderer
30
+ feature). Plugins that need host navigation declare `compatibility.mobile`
31
+ including `0.3.0`; they gate against it through `isMobileRendererCompatible`.
32
+
12
33
  ## v1.16.0
13
34
 
14
35
  **Mobile host-services bridge** — a typed contract so a plugin's mobile package
@@ -35,8 +35,14 @@ declare const PLUGIN_API_VERSION: "0.1.0";
35
35
  * `set/getMobileHostServices`) so a plugin's mobile package routes protected
36
36
  * API calls through the native host (token + 401-refresh owned host-side)
37
37
  * instead of injecting raw tokens — an additive renderer feature.
38
+ *
39
+ * `0.3.0` adds the optional `IMobileHostServices.navigate(target, external)`
40
+ * host-navigation capability so a plugin can honour an in-content redirect
41
+ * through the host router (correct in the native app AND the CMS web preview
42
+ * iframe) instead of touching `window.location` — an additive renderer feature.
43
+ * It is optional, so older plugins/hosts stay compatible.
38
44
  */
39
- declare const MOBILE_RENDERER_VERSION: "0.2.0";
45
+ declare const MOBILE_RENDERER_VERSION: "0.3.0";
40
46
  interface ISemver {
41
47
  major: number;
42
48
  minor: number;
@@ -783,6 +789,27 @@ interface IMobileHostServices {
783
789
  getAccessToken(): string | null;
784
790
  /** Perform an authenticated request with host-managed 401 refresh. */
785
791
  request<TData = unknown>(req: IMobileHostRequest): Promise<IMobileHostResponse<TData>>;
792
+ /**
793
+ * Navigate the host app on the user's behalf to honour an in-content
794
+ * redirect (e.g. a survey's "redirect on completion") WITHOUT the plugin
795
+ * touching `window.location`. The host owns the router, so it routes an
796
+ * internal CMS page keyword / in-app path through its own navigation stack
797
+ * and only leaves the app for an explicit external URL. This keeps redirects
798
+ * correct in EVERY host surface — the native app AND the CMS web preview,
799
+ * where a raw `location` assignment would navigate (and break) the embedded
800
+ * iframe instead of the app.
801
+ *
802
+ * @param target CMS page keyword / in-app path, or an absolute URL when
803
+ * `external` is true.
804
+ * @param external When true the target is a full off-app URL the host opens
805
+ * in the system browser (native) / a new tab (web) instead of
806
+ * routing inside the app. Defaults to false.
807
+ *
808
+ * Optional: a host registered by an older app binary (renderer < 0.3.0) may
809
+ * omit it, so a plugin MUST feature-detect (`if (host.navigate)`) and degrade
810
+ * gracefully rather than assume it exists.
811
+ */
812
+ navigate?(target: string, external?: boolean): void;
786
813
  }
787
814
  /**
788
815
  * Register the host services implementation. Called once by the native
@@ -35,8 +35,14 @@ declare const PLUGIN_API_VERSION: "0.1.0";
35
35
  * `set/getMobileHostServices`) so a plugin's mobile package routes protected
36
36
  * API calls through the native host (token + 401-refresh owned host-side)
37
37
  * instead of injecting raw tokens — an additive renderer feature.
38
+ *
39
+ * `0.3.0` adds the optional `IMobileHostServices.navigate(target, external)`
40
+ * host-navigation capability so a plugin can honour an in-content redirect
41
+ * through the host router (correct in the native app AND the CMS web preview
42
+ * iframe) instead of touching `window.location` — an additive renderer feature.
43
+ * It is optional, so older plugins/hosts stay compatible.
38
44
  */
39
- declare const MOBILE_RENDERER_VERSION: "0.2.0";
45
+ declare const MOBILE_RENDERER_VERSION: "0.3.0";
40
46
  interface ISemver {
41
47
  major: number;
42
48
  minor: number;
@@ -783,6 +789,27 @@ interface IMobileHostServices {
783
789
  getAccessToken(): string | null;
784
790
  /** Perform an authenticated request with host-managed 401 refresh. */
785
791
  request<TData = unknown>(req: IMobileHostRequest): Promise<IMobileHostResponse<TData>>;
792
+ /**
793
+ * Navigate the host app on the user's behalf to honour an in-content
794
+ * redirect (e.g. a survey's "redirect on completion") WITHOUT the plugin
795
+ * touching `window.location`. The host owns the router, so it routes an
796
+ * internal CMS page keyword / in-app path through its own navigation stack
797
+ * and only leaves the app for an explicit external URL. This keeps redirects
798
+ * correct in EVERY host surface — the native app AND the CMS web preview,
799
+ * where a raw `location` assignment would navigate (and break) the embedded
800
+ * iframe instead of the app.
801
+ *
802
+ * @param target CMS page keyword / in-app path, or an absolute URL when
803
+ * `external` is true.
804
+ * @param external When true the target is a full off-app URL the host opens
805
+ * in the system browser (native) / a new tab (web) instead of
806
+ * routing inside the app. Defaults to false.
807
+ *
808
+ * Optional: a host registered by an older app binary (renderer < 0.3.0) may
809
+ * omit it, so a plugin MUST feature-detect (`if (host.navigate)`) and degrade
810
+ * gracefully rather than assume it exists.
811
+ */
812
+ navigate?(target: string, external?: boolean): void;
786
813
  }
787
814
  /**
788
815
  * Register the host services implementation. Called once by the native
@@ -48,7 +48,7 @@ module.exports = __toCommonJS(plugin_sdk_exports);
48
48
 
49
49
  // src/plugin-sdk/version.ts
50
50
  var PLUGIN_API_VERSION = "0.1.0";
51
- var MOBILE_RENDERER_VERSION = "0.2.0";
51
+ var MOBILE_RENDERER_VERSION = "0.3.0";
52
52
  var SEMVER_REGEX = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
53
53
  function parseSemver(version) {
54
54
  const match = SEMVER_REGEX.exec(version);
@@ -1,6 +1,6 @@
1
1
  // src/plugin-sdk/version.ts
2
2
  var PLUGIN_API_VERSION = "0.1.0";
3
- var MOBILE_RENDERER_VERSION = "0.2.0";
3
+ var MOBILE_RENDERER_VERSION = "0.3.0";
4
4
  var SEMVER_REGEX = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
5
5
  function parseSemver(version) {
6
6
  const match = SEMVER_REGEX.exec(version);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@selfhelp/shared",
3
- "version": "1.16.0",
3
+ "version": "1.17.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",
@@ -3,7 +3,7 @@ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
3
  SPDX-License-Identifier: MPL-2.0
4
4
  */
5
5
  /**
6
- * Mobile host-services bridge contract (mobile renderer axis 0.2.0).
6
+ * Mobile host-services bridge contract (mobile renderer axis 0.3.0).
7
7
  *
8
8
  * The shared package only owns the *contract* + the singleton registry; the
9
9
  * real 401-refresh / session-expired logic lives in the native host's
@@ -14,7 +14,9 @@ SPDX-License-Identifier: MPL-2.0
14
14
  * plugin branch on lifecycle + refresh outcomes through a representative
15
15
  * fake host that performs a single 401 -> refresh -> retry, and reports
16
16
  * session-expired when the refresh itself fails,
17
- * - `isMobileRendererCompatible` covers the bumped 0.2.0 host.
17
+ * - `isMobileRendererCompatible` covers the bumped 0.3.0 host,
18
+ * - the host may expose the optional `navigate()` capability a plugin
19
+ * feature-detects to honour an in-content redirect through the host router.
18
20
  */
19
21
 
20
22
  import { afterEach, describe, expect, it, vi } from 'vitest';
@@ -57,6 +59,29 @@ describe('mobile host-services singleton', () => {
57
59
  setMobileHostServices(null);
58
60
  expect(getMobileHostServices()).toBeNull();
59
61
  });
62
+
63
+ it('exposes the optional navigate() a renderer-0.3.0 host registers', () => {
64
+ const navigate = vi.fn();
65
+ setMobileHostServices({
66
+ apiBaseUrl: () => 'https://cms.example.com',
67
+ getAccessToken: () => null,
68
+ request: () => Promise.resolve({ ok: true, status: 200, data: null }),
69
+ navigate,
70
+ });
71
+ const host = getMobileHostServices();
72
+ expect(typeof host?.navigate).toBe('function');
73
+ host?.navigate?.('contact', false);
74
+ expect(navigate).toHaveBeenCalledWith('contact', false);
75
+ });
76
+
77
+ it('omits navigate on an older host so a plugin must feature-detect it', () => {
78
+ setMobileHostServices({
79
+ apiBaseUrl: () => 'https://cms.example.com',
80
+ getAccessToken: () => null,
81
+ request: () => Promise.resolve({ ok: true, status: 200, data: null }),
82
+ });
83
+ expect(getMobileHostServices()?.navigate).toBeUndefined();
84
+ });
60
85
  });
61
86
 
62
87
  describe('host request contract (host owns token + refresh)', () => {
@@ -128,9 +153,10 @@ describe('host request contract (host owns token + refresh)', () => {
128
153
  });
129
154
 
130
155
  describe('mobile renderer compatibility at the bumped version', () => {
131
- it('advertises 0.2.0 and gates plugin compatibility.mobile ranges against it', () => {
132
- expect(MOBILE_RENDERER_VERSION).toBe('0.2.0');
133
- expect(isMobileRendererCompatible('^0.2.0')).toBe(true);
156
+ it('advertises 0.3.0 and gates plugin compatibility.mobile ranges against it', () => {
157
+ expect(MOBILE_RENDERER_VERSION).toBe('0.3.0');
158
+ expect(isMobileRendererCompatible('^0.3.0')).toBe(true);
159
+ expect(isMobileRendererCompatible('>=0.2.0')).toBe(true);
134
160
  expect(isMobileRendererCompatible('^0.1.0')).toBe(false);
135
161
  });
136
162
  });
@@ -92,6 +92,27 @@ export interface IMobileHostServices {
92
92
  getAccessToken(): string | null;
93
93
  /** Perform an authenticated request with host-managed 401 refresh. */
94
94
  request<TData = unknown>(req: IMobileHostRequest): Promise<IMobileHostResponse<TData>>;
95
+ /**
96
+ * Navigate the host app on the user's behalf to honour an in-content
97
+ * redirect (e.g. a survey's "redirect on completion") WITHOUT the plugin
98
+ * touching `window.location`. The host owns the router, so it routes an
99
+ * internal CMS page keyword / in-app path through its own navigation stack
100
+ * and only leaves the app for an explicit external URL. This keeps redirects
101
+ * correct in EVERY host surface — the native app AND the CMS web preview,
102
+ * where a raw `location` assignment would navigate (and break) the embedded
103
+ * iframe instead of the app.
104
+ *
105
+ * @param target CMS page keyword / in-app path, or an absolute URL when
106
+ * `external` is true.
107
+ * @param external When true the target is a full off-app URL the host opens
108
+ * in the system browser (native) / a new tab (web) instead of
109
+ * routing inside the app. Defaults to false.
110
+ *
111
+ * Optional: a host registered by an older app binary (renderer < 0.3.0) may
112
+ * omit it, so a plugin MUST feature-detect (`if (host.navigate)`) and degrade
113
+ * gracefully rather than assume it exists.
114
+ */
115
+ navigate?(target: string, external?: boolean): void;
95
116
  }
96
117
 
97
118
  let registeredHostServices: IMobileHostServices | null = null;
@@ -36,8 +36,14 @@ export const PLUGIN_API_VERSION = '0.1.0' as const;
36
36
  * `set/getMobileHostServices`) so a plugin's mobile package routes protected
37
37
  * API calls through the native host (token + 401-refresh owned host-side)
38
38
  * instead of injecting raw tokens — an additive renderer feature.
39
+ *
40
+ * `0.3.0` adds the optional `IMobileHostServices.navigate(target, external)`
41
+ * host-navigation capability so a plugin can honour an in-content redirect
42
+ * through the host router (correct in the native app AND the CMS web preview
43
+ * iframe) instead of touching `window.location` — an additive renderer feature.
44
+ * It is optional, so older plugins/hosts stay compatible.
39
45
  */
40
- export const MOBILE_RENDERER_VERSION = '0.2.0' as const;
46
+ export const MOBILE_RENDERER_VERSION = '0.3.0' as const;
41
47
 
42
48
  export interface ISemver {
43
49
  major: number;