@selfhelp/shared 1.15.0 → 1.15.2
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 +74 -1
- package/dist/index.d.mts +185 -7
- package/dist/index.d.ts +185 -7
- package/dist/index.js +58 -1
- package/dist/index.mjs +53 -1
- package/package.json +1 -1
- package/src/types/__tests__/preview-bridge.test.ts +100 -0
- package/src/types/api/__tests__/system.test.ts +83 -0
- package/src/types/api/system.ts +83 -3
- package/src/types/distribution.ts +17 -4
- package/src/types/index.ts +1 -0
- package/src/types/preview-bridge.ts +139 -0
package/dist/index.js
CHANGED
|
@@ -49,6 +49,9 @@ __export(index_exports, {
|
|
|
49
49
|
LITERAL_CLASSES: () => LITERAL_CLASSES,
|
|
50
50
|
MOBILE_PREVIEW_ENDPOINTS: () => MOBILE_PREVIEW_ENDPOINTS,
|
|
51
51
|
PERMISSIONS: () => PERMISSIONS,
|
|
52
|
+
PREVIEW_BRIDGE_MESSAGE: () => PREVIEW_BRIDGE_MESSAGE,
|
|
53
|
+
PREVIEW_PARENT_ORIGIN_PARAM: () => PREVIEW_PARENT_ORIGIN_PARAM,
|
|
54
|
+
PREVIEW_SHELL_PARAM: () => PREVIEW_SHELL_PARAM,
|
|
52
55
|
RADIUS_PX: () => RADIUS_PX,
|
|
53
56
|
RELEASE_CHANNELS: () => RELEASE_CHANNELS,
|
|
54
57
|
SIZE_VALUES: () => SIZE_VALUES,
|
|
@@ -75,6 +78,7 @@ __export(index_exports, {
|
|
|
75
78
|
gridSpanToReactNativeColumn: () => gridSpanToReactNativeColumn,
|
|
76
79
|
hasInlineFormatting: () => hasInlineFormatting,
|
|
77
80
|
isKnownStyleName: () => isKnownStyleName,
|
|
81
|
+
isPreviewBridgeMessage: () => isPreviewBridgeMessage,
|
|
78
82
|
isRegisteredStyleName: () => isRegisteredStyleName,
|
|
79
83
|
isStyleAllowedOnPage: () => isStyleAllowedOnPage,
|
|
80
84
|
isStylePlacementAllowed: () => isStylePlacementAllowed,
|
|
@@ -94,6 +98,7 @@ __export(index_exports, {
|
|
|
94
98
|
parseDimensionToWeb: () => parseDimensionToWeb,
|
|
95
99
|
parseInlineRich: () => parseInlineRich,
|
|
96
100
|
parseSpacing: () => parseSpacing,
|
|
101
|
+
previewKeywordFromPath: () => previewKeywordFromPath,
|
|
97
102
|
radiusToPx: () => radiusToPx,
|
|
98
103
|
replaceCalcedValues: () => replaceCalcedValues,
|
|
99
104
|
resolveAssetSources: () => resolveAssetSources,
|
|
@@ -189,7 +194,17 @@ var SYSTEM_ENDPOINTS = {
|
|
|
189
194
|
// is stateless — no destructive migration, no backup).
|
|
190
195
|
UPDATE_FRONTEND_RELEASES: `${SYSTEM_PREFIX}/update/frontend/releases`,
|
|
191
196
|
UPDATE_FRONTEND_PREFLIGHT: `${SYSTEM_PREFIX}/update/frontend/preflight`,
|
|
192
|
-
UPDATE_FRONTEND_REQUEST: `${SYSTEM_PREFIX}/update/frontend/request
|
|
197
|
+
UPDATE_FRONTEND_REQUEST: `${SYSTEM_PREFIX}/update/frontend/request`,
|
|
198
|
+
// Mobile-preview update flow. The `selfhelp-mobile-preview` web image is
|
|
199
|
+
// provisioned with every install and ships independently of the core (like
|
|
200
|
+
// the frontend), so an instance can move it to a newer compatible version on
|
|
201
|
+
// its own. These reuse the core preflight/releases response shapes; the
|
|
202
|
+
// request body omits `accepted_migration_risk` (a preview swap is stateless).
|
|
203
|
+
// Requesting one onto an instance that never had it doubles as the
|
|
204
|
+
// enable/bootstrap path (the SelfHelp Manager provisions it).
|
|
205
|
+
UPDATE_MOBILE_PREVIEW_RELEASES: `${SYSTEM_PREFIX}/update/mobile-preview/releases`,
|
|
206
|
+
UPDATE_MOBILE_PREVIEW_PREFLIGHT: `${SYSTEM_PREFIX}/update/mobile-preview/preflight`,
|
|
207
|
+
UPDATE_MOBILE_PREVIEW_REQUEST: `${SYSTEM_PREFIX}/update/mobile-preview/request`
|
|
193
208
|
};
|
|
194
209
|
|
|
195
210
|
// src/types/api/mobile-preview.ts
|
|
@@ -201,6 +216,43 @@ var MOBILE_PREVIEW_ENDPOINTS = {
|
|
|
201
216
|
EXCHANGE: `${MOBILE_PREVIEW_PREFIX}/mobile-preview/session/exchange`
|
|
202
217
|
};
|
|
203
218
|
|
|
219
|
+
// src/types/preview-bridge.ts
|
|
220
|
+
var PREVIEW_SHELL_PARAM = "previewShell";
|
|
221
|
+
var PREVIEW_PARENT_ORIGIN_PARAM = "parentOrigin";
|
|
222
|
+
var PREVIEW_BRIDGE_MESSAGE = {
|
|
223
|
+
/** frame → shell: the bridge mounted and is ready to sync. */
|
|
224
|
+
READY: "selfhelp-preview:ready",
|
|
225
|
+
/** frame → shell: the frame navigated to a new in-app location. */
|
|
226
|
+
NAVIGATED: "selfhelp-preview:navigated",
|
|
227
|
+
/** shell → frame: navigate the frame to a CMS keyword (soft, no reload). */
|
|
228
|
+
NAVIGATE: "selfhelp-preview:navigate"
|
|
229
|
+
};
|
|
230
|
+
function isPreviewBridgeMessage(value) {
|
|
231
|
+
if (typeof value !== "object" || value === null) return false;
|
|
232
|
+
const record = value;
|
|
233
|
+
switch (record.type) {
|
|
234
|
+
case PREVIEW_BRIDGE_MESSAGE.READY:
|
|
235
|
+
return record.source === "web" || record.source === "mobile";
|
|
236
|
+
case PREVIEW_BRIDGE_MESSAGE.NAVIGATED:
|
|
237
|
+
return (record.source === "web" || record.source === "mobile") && (typeof record.keyword === "string" || record.keyword === null) && typeof record.href === "string";
|
|
238
|
+
case PREVIEW_BRIDGE_MESSAGE.NAVIGATE:
|
|
239
|
+
return typeof record.keyword === "string" || record.keyword === null;
|
|
240
|
+
default:
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function previewKeywordFromPath(path) {
|
|
245
|
+
if (!path) return null;
|
|
246
|
+
const withoutQuery = path.split(/[?#]/, 1)[0] ?? "";
|
|
247
|
+
const trimmed = withoutQuery.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
248
|
+
if (trimmed === "") return null;
|
|
249
|
+
try {
|
|
250
|
+
return decodeURIComponent(trimmed);
|
|
251
|
+
} catch {
|
|
252
|
+
return trimmed;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
204
256
|
// src/types/distribution.ts
|
|
205
257
|
var RELEASE_CHANNELS = ["stable", "beta", "nightly", "test"];
|
|
206
258
|
|
|
@@ -1533,6 +1585,9 @@ function transformPagesData(pages) {
|
|
|
1533
1585
|
LITERAL_CLASSES,
|
|
1534
1586
|
MOBILE_PREVIEW_ENDPOINTS,
|
|
1535
1587
|
PERMISSIONS,
|
|
1588
|
+
PREVIEW_BRIDGE_MESSAGE,
|
|
1589
|
+
PREVIEW_PARENT_ORIGIN_PARAM,
|
|
1590
|
+
PREVIEW_SHELL_PARAM,
|
|
1536
1591
|
RADIUS_PX,
|
|
1537
1592
|
RELEASE_CHANNELS,
|
|
1538
1593
|
SIZE_VALUES,
|
|
@@ -1559,6 +1614,7 @@ function transformPagesData(pages) {
|
|
|
1559
1614
|
gridSpanToReactNativeColumn,
|
|
1560
1615
|
hasInlineFormatting,
|
|
1561
1616
|
isKnownStyleName,
|
|
1617
|
+
isPreviewBridgeMessage,
|
|
1562
1618
|
isRegisteredStyleName,
|
|
1563
1619
|
isStyleAllowedOnPage,
|
|
1564
1620
|
isStylePlacementAllowed,
|
|
@@ -1578,6 +1634,7 @@ function transformPagesData(pages) {
|
|
|
1578
1634
|
parseDimensionToWeb,
|
|
1579
1635
|
parseInlineRich,
|
|
1580
1636
|
parseSpacing,
|
|
1637
|
+
previewKeywordFromPath,
|
|
1581
1638
|
radiusToPx,
|
|
1582
1639
|
replaceCalcedValues,
|
|
1583
1640
|
resolveAssetSources,
|
package/dist/index.mjs
CHANGED
|
@@ -68,7 +68,17 @@ var SYSTEM_ENDPOINTS = {
|
|
|
68
68
|
// is stateless — no destructive migration, no backup).
|
|
69
69
|
UPDATE_FRONTEND_RELEASES: `${SYSTEM_PREFIX}/update/frontend/releases`,
|
|
70
70
|
UPDATE_FRONTEND_PREFLIGHT: `${SYSTEM_PREFIX}/update/frontend/preflight`,
|
|
71
|
-
UPDATE_FRONTEND_REQUEST: `${SYSTEM_PREFIX}/update/frontend/request
|
|
71
|
+
UPDATE_FRONTEND_REQUEST: `${SYSTEM_PREFIX}/update/frontend/request`,
|
|
72
|
+
// Mobile-preview update flow. The `selfhelp-mobile-preview` web image is
|
|
73
|
+
// provisioned with every install and ships independently of the core (like
|
|
74
|
+
// the frontend), so an instance can move it to a newer compatible version on
|
|
75
|
+
// its own. These reuse the core preflight/releases response shapes; the
|
|
76
|
+
// request body omits `accepted_migration_risk` (a preview swap is stateless).
|
|
77
|
+
// Requesting one onto an instance that never had it doubles as the
|
|
78
|
+
// enable/bootstrap path (the SelfHelp Manager provisions it).
|
|
79
|
+
UPDATE_MOBILE_PREVIEW_RELEASES: `${SYSTEM_PREFIX}/update/mobile-preview/releases`,
|
|
80
|
+
UPDATE_MOBILE_PREVIEW_PREFLIGHT: `${SYSTEM_PREFIX}/update/mobile-preview/preflight`,
|
|
81
|
+
UPDATE_MOBILE_PREVIEW_REQUEST: `${SYSTEM_PREFIX}/update/mobile-preview/request`
|
|
72
82
|
};
|
|
73
83
|
|
|
74
84
|
// src/types/api/mobile-preview.ts
|
|
@@ -80,6 +90,43 @@ var MOBILE_PREVIEW_ENDPOINTS = {
|
|
|
80
90
|
EXCHANGE: `${MOBILE_PREVIEW_PREFIX}/mobile-preview/session/exchange`
|
|
81
91
|
};
|
|
82
92
|
|
|
93
|
+
// src/types/preview-bridge.ts
|
|
94
|
+
var PREVIEW_SHELL_PARAM = "previewShell";
|
|
95
|
+
var PREVIEW_PARENT_ORIGIN_PARAM = "parentOrigin";
|
|
96
|
+
var PREVIEW_BRIDGE_MESSAGE = {
|
|
97
|
+
/** frame → shell: the bridge mounted and is ready to sync. */
|
|
98
|
+
READY: "selfhelp-preview:ready",
|
|
99
|
+
/** frame → shell: the frame navigated to a new in-app location. */
|
|
100
|
+
NAVIGATED: "selfhelp-preview:navigated",
|
|
101
|
+
/** shell → frame: navigate the frame to a CMS keyword (soft, no reload). */
|
|
102
|
+
NAVIGATE: "selfhelp-preview:navigate"
|
|
103
|
+
};
|
|
104
|
+
function isPreviewBridgeMessage(value) {
|
|
105
|
+
if (typeof value !== "object" || value === null) return false;
|
|
106
|
+
const record = value;
|
|
107
|
+
switch (record.type) {
|
|
108
|
+
case PREVIEW_BRIDGE_MESSAGE.READY:
|
|
109
|
+
return record.source === "web" || record.source === "mobile";
|
|
110
|
+
case PREVIEW_BRIDGE_MESSAGE.NAVIGATED:
|
|
111
|
+
return (record.source === "web" || record.source === "mobile") && (typeof record.keyword === "string" || record.keyword === null) && typeof record.href === "string";
|
|
112
|
+
case PREVIEW_BRIDGE_MESSAGE.NAVIGATE:
|
|
113
|
+
return typeof record.keyword === "string" || record.keyword === null;
|
|
114
|
+
default:
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function previewKeywordFromPath(path) {
|
|
119
|
+
if (!path) return null;
|
|
120
|
+
const withoutQuery = path.split(/[?#]/, 1)[0] ?? "";
|
|
121
|
+
const trimmed = withoutQuery.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
122
|
+
if (trimmed === "") return null;
|
|
123
|
+
try {
|
|
124
|
+
return decodeURIComponent(trimmed);
|
|
125
|
+
} catch {
|
|
126
|
+
return trimmed;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
83
130
|
// src/types/distribution.ts
|
|
84
131
|
var RELEASE_CHANNELS = ["stable", "beta", "nightly", "test"];
|
|
85
132
|
|
|
@@ -1411,6 +1458,9 @@ export {
|
|
|
1411
1458
|
LITERAL_CLASSES,
|
|
1412
1459
|
MOBILE_PREVIEW_ENDPOINTS,
|
|
1413
1460
|
PERMISSIONS,
|
|
1461
|
+
PREVIEW_BRIDGE_MESSAGE,
|
|
1462
|
+
PREVIEW_PARENT_ORIGIN_PARAM,
|
|
1463
|
+
PREVIEW_SHELL_PARAM,
|
|
1414
1464
|
RADIUS_PX,
|
|
1415
1465
|
RELEASE_CHANNELS,
|
|
1416
1466
|
SIZE_VALUES,
|
|
@@ -1437,6 +1487,7 @@ export {
|
|
|
1437
1487
|
gridSpanToReactNativeColumn,
|
|
1438
1488
|
hasInlineFormatting,
|
|
1439
1489
|
isKnownStyleName,
|
|
1490
|
+
isPreviewBridgeMessage,
|
|
1440
1491
|
isRegisteredStyleName,
|
|
1441
1492
|
isStyleAllowedOnPage,
|
|
1442
1493
|
isStylePlacementAllowed,
|
|
@@ -1456,6 +1507,7 @@ export {
|
|
|
1456
1507
|
parseDimensionToWeb,
|
|
1457
1508
|
parseInlineRich,
|
|
1458
1509
|
parseSpacing,
|
|
1510
|
+
previewKeywordFromPath,
|
|
1459
1511
|
radiusToPx,
|
|
1460
1512
|
replaceCalcedValues,
|
|
1461
1513
|
resolveAssetSources,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@selfhelp/shared",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.2",
|
|
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",
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Live Preview bridge contract tests.
|
|
7
|
+
*
|
|
8
|
+
* The shell and both frame bridges trust `isPreviewBridgeMessage` to narrow
|
|
9
|
+
* arbitrary cross-frame `postMessage` data, and derive the cross-platform sync
|
|
10
|
+
* unit with `previewKeywordFromPath`. These lock both: a malformed/foreign
|
|
11
|
+
* message must be rejected, a well-formed one in either direction accepted, and
|
|
12
|
+
* web/mobile paths must reduce to the same keyword (so sync can't drift).
|
|
13
|
+
*/
|
|
14
|
+
import { describe, expect, it } from 'vitest';
|
|
15
|
+
import {
|
|
16
|
+
PREVIEW_BRIDGE_MESSAGE,
|
|
17
|
+
isPreviewBridgeMessage,
|
|
18
|
+
previewKeywordFromPath,
|
|
19
|
+
type TPreviewBridgeMessage,
|
|
20
|
+
} from '../preview-bridge';
|
|
21
|
+
|
|
22
|
+
describe('isPreviewBridgeMessage', () => {
|
|
23
|
+
it('accepts a frame->shell navigated message (the user clicked a link)', () => {
|
|
24
|
+
const msg: TPreviewBridgeMessage = {
|
|
25
|
+
type: PREVIEW_BRIDGE_MESSAGE.NAVIGATED,
|
|
26
|
+
source: 'web',
|
|
27
|
+
keyword: 'impressum',
|
|
28
|
+
href: '/impressum?previewShell=1',
|
|
29
|
+
locale: 'de-CH',
|
|
30
|
+
};
|
|
31
|
+
expect(isPreviewBridgeMessage(msg)).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('accepts a navigated message for home (keyword null) and a ready message', () => {
|
|
35
|
+
expect(
|
|
36
|
+
isPreviewBridgeMessage({
|
|
37
|
+
type: PREVIEW_BRIDGE_MESSAGE.NAVIGATED,
|
|
38
|
+
source: 'mobile',
|
|
39
|
+
keyword: null,
|
|
40
|
+
href: '/',
|
|
41
|
+
}),
|
|
42
|
+
).toBe(true);
|
|
43
|
+
expect(
|
|
44
|
+
isPreviewBridgeMessage({ type: PREVIEW_BRIDGE_MESSAGE.READY, source: 'mobile' }),
|
|
45
|
+
).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('accepts a shell->frame navigate command (keyword or null)', () => {
|
|
49
|
+
expect(
|
|
50
|
+
isPreviewBridgeMessage({ type: PREVIEW_BRIDGE_MESSAGE.NAVIGATE, keyword: 'team' }),
|
|
51
|
+
).toBe(true);
|
|
52
|
+
expect(
|
|
53
|
+
isPreviewBridgeMessage({ type: PREVIEW_BRIDGE_MESSAGE.NAVIGATE, keyword: null }),
|
|
54
|
+
).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('rejects foreign / malformed messages so cross-frame noise is ignored', () => {
|
|
58
|
+
expect(isPreviewBridgeMessage(null)).toBe(false);
|
|
59
|
+
expect(isPreviewBridgeMessage('selfhelp-preview:navigate')).toBe(false);
|
|
60
|
+
expect(isPreviewBridgeMessage({ type: 'webpack:hot-update' })).toBe(false);
|
|
61
|
+
// wrong source
|
|
62
|
+
expect(
|
|
63
|
+
isPreviewBridgeMessage({ type: PREVIEW_BRIDGE_MESSAGE.READY, source: 'desktop' }),
|
|
64
|
+
).toBe(false);
|
|
65
|
+
// navigated without href
|
|
66
|
+
expect(
|
|
67
|
+
isPreviewBridgeMessage({
|
|
68
|
+
type: PREVIEW_BRIDGE_MESSAGE.NAVIGATED,
|
|
69
|
+
source: 'web',
|
|
70
|
+
keyword: 'x',
|
|
71
|
+
}),
|
|
72
|
+
).toBe(false);
|
|
73
|
+
// navigate with a non-string keyword
|
|
74
|
+
expect(
|
|
75
|
+
isPreviewBridgeMessage({ type: PREVIEW_BRIDGE_MESSAGE.NAVIGATE, keyword: 5 }),
|
|
76
|
+
).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('previewKeywordFromPath', () => {
|
|
81
|
+
it('reduces web and mobile paths to the same keyword (no drift)', () => {
|
|
82
|
+
expect(previewKeywordFromPath('/impressum')).toBe('impressum');
|
|
83
|
+
expect(previewKeywordFromPath('impressum')).toBe('impressum');
|
|
84
|
+
expect(previewKeywordFromPath('/impressum/')).toBe('impressum');
|
|
85
|
+
expect(previewKeywordFromPath('/impressum?previewShell=1')).toBe('impressum');
|
|
86
|
+
expect(previewKeywordFromPath('/impressum#section')).toBe('impressum');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('treats home / empty as null (the shared "home" sentinel)', () => {
|
|
90
|
+
expect(previewKeywordFromPath('/')).toBeNull();
|
|
91
|
+
expect(previewKeywordFromPath('')).toBeNull();
|
|
92
|
+
expect(previewKeywordFromPath(null)).toBeNull();
|
|
93
|
+
expect(previewKeywordFromPath(undefined)).toBeNull();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('keeps multi-segment keywords and decodes percent-encoding', () => {
|
|
97
|
+
expect(previewKeywordFromPath('/projects/alpha')).toBe('projects/alpha');
|
|
98
|
+
expect(previewKeywordFromPath('/caf%C3%A9')).toBe('café');
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -11,6 +11,10 @@ import {
|
|
|
11
11
|
type IFrontendUpdateRequest,
|
|
12
12
|
type IFrontendUpdateRequestResponse,
|
|
13
13
|
type IMaintenanceSetRequest,
|
|
14
|
+
type IMobilePreviewUpdatePreflight,
|
|
15
|
+
type IMobilePreviewUpdateReleases,
|
|
16
|
+
type IMobilePreviewUpdateRequest,
|
|
17
|
+
type IMobilePreviewUpdateRequestResponse,
|
|
14
18
|
type ISystemAdvisories,
|
|
15
19
|
type ISystemAdvisoriesResponse,
|
|
16
20
|
type ISystemAdvisory,
|
|
@@ -159,6 +163,7 @@ describe('system maintenance contracts', () => {
|
|
|
159
163
|
selfhelp_version: '1.4.0',
|
|
160
164
|
backend_version: '1.4.0',
|
|
161
165
|
frontend_version: '1.4.0',
|
|
166
|
+
mobile_preview_version: '0.2.0',
|
|
162
167
|
plugin_api_version: '2.1',
|
|
163
168
|
database_migration_version: 'Version20260605081254',
|
|
164
169
|
safe_mode: false,
|
|
@@ -183,6 +188,7 @@ describe('system maintenance contracts', () => {
|
|
|
183
188
|
kind: 'core',
|
|
184
189
|
target_version: '1.5.0',
|
|
185
190
|
target_frontend_version: null,
|
|
191
|
+
target_mobile_preview_version: null,
|
|
186
192
|
progress_percent: 42,
|
|
187
193
|
steps: [{ name: 'backup', status: 'succeeded' }],
|
|
188
194
|
requested_at: '2026-06-08T00:00:00Z',
|
|
@@ -248,6 +254,7 @@ describe('system maintenance contracts', () => {
|
|
|
248
254
|
kind: 'core',
|
|
249
255
|
target_version: '8.0.1',
|
|
250
256
|
target_frontend_version: null,
|
|
257
|
+
target_mobile_preview_version: null,
|
|
251
258
|
progress_percent: 100,
|
|
252
259
|
steps: [],
|
|
253
260
|
requested_at: '2026-06-08T00:00:00Z',
|
|
@@ -290,6 +297,7 @@ describe('system maintenance contracts', () => {
|
|
|
290
297
|
kind: 'core',
|
|
291
298
|
target_version: '8.0.1',
|
|
292
299
|
target_frontend_version: null,
|
|
300
|
+
target_mobile_preview_version: null,
|
|
293
301
|
progress_percent: 100,
|
|
294
302
|
steps: [{ name: 'migrate', status: 'succeeded' }],
|
|
295
303
|
requested_at: '2026-06-08T00:00:00Z',
|
|
@@ -380,4 +388,79 @@ describe('system maintenance contracts', () => {
|
|
|
380
388
|
expect(accepted.data.kind).toBe('frontend');
|
|
381
389
|
expect(accepted.data.target_frontend_version).toBe('0.1.7');
|
|
382
390
|
});
|
|
391
|
+
|
|
392
|
+
it('exposes the mobile-preview update endpoints under the system prefix', () => {
|
|
393
|
+
expect(SYSTEM_ENDPOINTS.UPDATE_MOBILE_PREVIEW_RELEASES).toBe(
|
|
394
|
+
'/cms-api/v1/admin/system/update/mobile-preview/releases',
|
|
395
|
+
);
|
|
396
|
+
expect(SYSTEM_ENDPOINTS.UPDATE_MOBILE_PREVIEW_PREFLIGHT).toBe(
|
|
397
|
+
'/cms-api/v1/admin/system/update/mobile-preview/preflight',
|
|
398
|
+
);
|
|
399
|
+
expect(SYSTEM_ENDPOINTS.UPDATE_MOBILE_PREVIEW_REQUEST).toBe(
|
|
400
|
+
'/cms-api/v1/admin/system/update/mobile-preview/request',
|
|
401
|
+
);
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
it('models the mobile-preview update flow (stateless swap + core-compat verdict)', () => {
|
|
405
|
+
// mobile-preview is a first-class update kind alongside core/frontend.
|
|
406
|
+
const kinds: TUpdateKind[] = ['core', 'frontend', 'mobile-preview'];
|
|
407
|
+
expect(kinds).toContain('mobile-preview');
|
|
408
|
+
|
|
409
|
+
const releases: IMobilePreviewUpdateReleases = {
|
|
410
|
+
available: true,
|
|
411
|
+
current_version: 'not_installed',
|
|
412
|
+
releases: [
|
|
413
|
+
{ version: '0.2.1', channel: 'stable', blocked: false },
|
|
414
|
+
{ version: '0.2.0', channel: 'stable', blocked: false },
|
|
415
|
+
],
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
const preflight: IMobilePreviewUpdatePreflight = {
|
|
419
|
+
preflight_id: 'mp-pf-001',
|
|
420
|
+
status: 'ok',
|
|
421
|
+
instance_id: 'inst-a',
|
|
422
|
+
current_version: 'not_installed',
|
|
423
|
+
target_version: '0.2.1',
|
|
424
|
+
// The preview ⇄ core rule is evaluated server-side against signed
|
|
425
|
+
// registry metadata, so the CMS verdict matches the manager's.
|
|
426
|
+
checks: [
|
|
427
|
+
{
|
|
428
|
+
code: 'mobile_preview_compatibility',
|
|
429
|
+
severity: 'info',
|
|
430
|
+
message: 'Core 0.1.19 satisfies the target preview required core range.',
|
|
431
|
+
component: 'mobile-preview',
|
|
432
|
+
},
|
|
433
|
+
],
|
|
434
|
+
options: [{ type: 'mobile-preview', version: '0.2.1', label: 'SelfHelp mobile preview 0.2.1' }],
|
|
435
|
+
// The preview image is stateless: a swap is never destructive.
|
|
436
|
+
database: { destructive: false, requires_backup: false, manual_confirmation_required: false },
|
|
437
|
+
rollback: { automatic_before_migrations: true, automatic_after_destructive_migrations: true },
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
// No accepted_migration_risk: a preview swap is stateless. Requesting it
|
|
441
|
+
// onto a not_installed instance doubles as the enable/bootstrap path.
|
|
442
|
+
const request: IMobilePreviewUpdateRequest = { target_version: '0.2.1', preflight_id: 'mp-pf-001' };
|
|
443
|
+
|
|
444
|
+
const accepted: IMobilePreviewUpdateRequestResponse = {
|
|
445
|
+
status: 202,
|
|
446
|
+
message: 'Accepted',
|
|
447
|
+
error: null,
|
|
448
|
+
logged_in: true,
|
|
449
|
+
meta: { version: 'v1', timestamp: '2026-06-23T00:00:00Z' },
|
|
450
|
+
data: {
|
|
451
|
+
operation_id: 'op-mp-1',
|
|
452
|
+
instance_id: 'inst-a',
|
|
453
|
+
status: 'requested',
|
|
454
|
+
kind: 'mobile-preview',
|
|
455
|
+
target_mobile_preview_version: '0.2.1',
|
|
456
|
+
},
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
expect(releases.current_version).toBe('not_installed');
|
|
460
|
+
expect(preflight.checks[0]?.component).toBe('mobile-preview');
|
|
461
|
+
expect(preflight.database.requires_backup).toBe(false);
|
|
462
|
+
expect(request.target_version).toBe('0.2.1');
|
|
463
|
+
expect(accepted.data.kind).toBe('mobile-preview');
|
|
464
|
+
expect(accepted.data.target_mobile_preview_version).toBe('0.2.1');
|
|
465
|
+
});
|
|
383
466
|
});
|
package/src/types/api/system.ts
CHANGED
|
@@ -35,10 +35,25 @@ export const SYSTEM_ENDPOINTS = {
|
|
|
35
35
|
UPDATE_FRONTEND_RELEASES: `${SYSTEM_PREFIX}/update/frontend/releases`,
|
|
36
36
|
UPDATE_FRONTEND_PREFLIGHT: `${SYSTEM_PREFIX}/update/frontend/preflight`,
|
|
37
37
|
UPDATE_FRONTEND_REQUEST: `${SYSTEM_PREFIX}/update/frontend/request`,
|
|
38
|
+
// Mobile-preview update flow. The `selfhelp-mobile-preview` web image is
|
|
39
|
+
// provisioned with every install and ships independently of the core (like
|
|
40
|
+
// the frontend), so an instance can move it to a newer compatible version on
|
|
41
|
+
// its own. These reuse the core preflight/releases response shapes; the
|
|
42
|
+
// request body omits `accepted_migration_risk` (a preview swap is stateless).
|
|
43
|
+
// Requesting one onto an instance that never had it doubles as the
|
|
44
|
+
// enable/bootstrap path (the SelfHelp Manager provisions it).
|
|
45
|
+
UPDATE_MOBILE_PREVIEW_RELEASES: `${SYSTEM_PREFIX}/update/mobile-preview/releases`,
|
|
46
|
+
UPDATE_MOBILE_PREVIEW_PREFLIGHT: `${SYSTEM_PREFIX}/update/mobile-preview/preflight`,
|
|
47
|
+
UPDATE_MOBILE_PREVIEW_REQUEST: `${SYSTEM_PREFIX}/update/mobile-preview/request`,
|
|
38
48
|
} as const;
|
|
39
49
|
|
|
40
|
-
/**
|
|
41
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Discriminates a core (full-stack) update from the stateless component-only
|
|
52
|
+
* swaps. `frontend` swaps the Next.js image; `mobile-preview` swaps the
|
|
53
|
+
* `selfhelp-mobile-preview` web image. Both are lightweight (no DB migration,
|
|
54
|
+
* no backup) and performed by the SelfHelp Manager.
|
|
55
|
+
*/
|
|
56
|
+
export type TUpdateKind = 'core' | 'frontend' | 'mobile-preview';
|
|
42
57
|
|
|
43
58
|
export interface ISystemInstalledPlugin {
|
|
44
59
|
id: string;
|
|
@@ -59,6 +74,16 @@ export interface ISystemVersion {
|
|
|
59
74
|
selfhelp_version: string;
|
|
60
75
|
backend_version: string;
|
|
61
76
|
frontend_version: string;
|
|
77
|
+
/**
|
|
78
|
+
* The provisioned `selfhelp-mobile-preview` web image version reported by the
|
|
79
|
+
* backend (set by the SelfHelp Manager via `SELFHELP_MOBILE_PREVIEW_VERSION`
|
|
80
|
+
* when it provisions/updates the service). `unknown` until the manager stamps
|
|
81
|
+
* it; `not_installed` when no preview service is provisioned for this
|
|
82
|
+
* instance (e.g. an instance that predates default provisioning, or a dev
|
|
83
|
+
* source checkout). The page-editor preview panel additionally probes the
|
|
84
|
+
* running image's `version.json` for the live value.
|
|
85
|
+
*/
|
|
86
|
+
mobile_preview_version: string;
|
|
62
87
|
plugin_api_version: string;
|
|
63
88
|
database_migration_version: string;
|
|
64
89
|
deployment: TSystemDeployment;
|
|
@@ -214,7 +239,7 @@ export interface IUpdatePreflightCheck {
|
|
|
214
239
|
* and the plugin-specific `pinned` affordance). Snake_case is the wire contract.
|
|
215
240
|
*/
|
|
216
241
|
export interface ICompatibilityError {
|
|
217
|
-
component: 'core' | 'frontend' | 'plugin';
|
|
242
|
+
component: 'core' | 'frontend' | 'mobile-preview' | 'plugin';
|
|
218
243
|
component_id: string;
|
|
219
244
|
current_version: string | null;
|
|
220
245
|
target_version: string | null;
|
|
@@ -347,6 +372,11 @@ export interface IUpdateStatus {
|
|
|
347
372
|
* for the synthetic `idle` status.
|
|
348
373
|
*/
|
|
349
374
|
target_frontend_version: string | null;
|
|
375
|
+
/**
|
|
376
|
+
* The mobile-preview image version a `mobile-preview`-kind operation targets;
|
|
377
|
+
* `null` for core/frontend operations and the synthetic `idle` status.
|
|
378
|
+
*/
|
|
379
|
+
target_mobile_preview_version: string | null;
|
|
350
380
|
progress_percent: number;
|
|
351
381
|
steps: IUpdateStep[];
|
|
352
382
|
requested_at: string;
|
|
@@ -409,3 +439,53 @@ export type IFrontendUpdateRequestResponse = IBaseApiResponse<{
|
|
|
409
439
|
kind: 'frontend';
|
|
410
440
|
target_frontend_version: string;
|
|
411
441
|
}>;
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* POST /admin/system/update/mobile-preview/request — request a MOBILE-PREVIEW
|
|
445
|
+
* update for THIS instance. Like {@link IFrontendUpdateRequest} it carries no
|
|
446
|
+
* `instance_id` (the backend derives + verifies it) and no
|
|
447
|
+
* `accepted_migration_risk` (a preview swap is stateless). Requesting it onto an
|
|
448
|
+
* instance that has no preview yet is also the enable/bootstrap path: the
|
|
449
|
+
* SelfHelp Manager provisions the `selfhelp-mobile-preview` service. The manager
|
|
450
|
+
* re-resolves the signed release and is the final authority on compatibility +
|
|
451
|
+
* signatures + image digests before it swaps the container.
|
|
452
|
+
*/
|
|
453
|
+
export interface IMobilePreviewUpdateRequest {
|
|
454
|
+
target_version: string;
|
|
455
|
+
preflight_id: string;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* GET /admin/system/update/mobile-preview/releases — mobile-preview image
|
|
460
|
+
* versions published in the official registry (newest first). Reuses
|
|
461
|
+
* {@link IUpdateReleases}: `current_version` is the instance's provisioned
|
|
462
|
+
* preview version (or `not_installed`) and `available: false` means the registry
|
|
463
|
+
* was unreachable (fall back to manual entry). Aliased for call-site clarity.
|
|
464
|
+
*/
|
|
465
|
+
export type IMobilePreviewUpdateReleases = IUpdateReleases;
|
|
466
|
+
export type IMobilePreviewUpdateReleasesResponse = IUpdateReleasesResponse;
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* GET /admin/system/update/mobile-preview/preflight — compatibility verdict for
|
|
470
|
+
* a mobile-preview target. Reuses {@link IUpdatePreflight}; the preview is
|
|
471
|
+
* stateless so `database.destructive`/`requires_backup` are always false. The
|
|
472
|
+
* preview ⇄ core compatibility rule IS evaluated here (as a
|
|
473
|
+
* `mobile_preview_compatibility` check) against the same signed registry
|
|
474
|
+
* metadata the SelfHelp Manager resolves — the running core must satisfy the
|
|
475
|
+
* target preview's `backendCompatibility.requiredCoreRange` — so the CMS verdict
|
|
476
|
+
* matches the manager's instead of always reporting "OK". The manager still
|
|
477
|
+
* re-verifies signatures + image digests and re-runs the per-plugin RN/Expo
|
|
478
|
+
* twin-axis gate at execution and remains the final authority. Aliased for
|
|
479
|
+
* call-site clarity.
|
|
480
|
+
*/
|
|
481
|
+
export type IMobilePreviewUpdatePreflight = IUpdatePreflight;
|
|
482
|
+
export type IMobilePreviewUpdatePreflightResponse = IUpdatePreflightResponse;
|
|
483
|
+
|
|
484
|
+
/** POST /admin/system/update/mobile-preview/request — accepted record. */
|
|
485
|
+
export type IMobilePreviewUpdateRequestResponse = IBaseApiResponse<{
|
|
486
|
+
operation_id: string;
|
|
487
|
+
instance_id: string;
|
|
488
|
+
status: TUpdateOperationStatus;
|
|
489
|
+
kind: 'mobile-preview';
|
|
490
|
+
target_mobile_preview_version: string;
|
|
491
|
+
}>;
|
|
@@ -390,6 +390,17 @@ export interface MobilePreviewRelease {
|
|
|
390
390
|
backendCompatibility: ServiceBackendCompatibility;
|
|
391
391
|
/** Mobile renderer contract version advertised by this image (semver). */
|
|
392
392
|
mobileRendererVersion: string;
|
|
393
|
+
/**
|
|
394
|
+
* React Native version the preview image was built with. Top-level canonical
|
|
395
|
+
* value the SelfHelp Manager gates a plugin's `compatibility.reactNative`
|
|
396
|
+
* range against (the `builtFrom.reactNative` provenance field mirrors it).
|
|
397
|
+
*/
|
|
398
|
+
reactNativeVersion?: string;
|
|
399
|
+
/**
|
|
400
|
+
* Expo SDK version the preview image was built with. Gated against a plugin's
|
|
401
|
+
* `compatibility.expoSdk` range (mirrors `builtFrom.expoSdk`).
|
|
402
|
+
*/
|
|
403
|
+
expoSdkVersion?: string;
|
|
393
404
|
/** Curated plugin mobile packages baked into the image. */
|
|
394
405
|
bundledPlugins: BundledPluginRef[];
|
|
395
406
|
security: SignatureBlock;
|
|
@@ -404,11 +415,13 @@ export interface PluginRelease {
|
|
|
404
415
|
official: boolean;
|
|
405
416
|
/**
|
|
406
417
|
* Compatibility ranges the host must satisfy. `mobile` (additive) is the
|
|
407
|
-
*
|
|
408
|
-
* plugin's mobile package supports (parallel to `pluginApi`).
|
|
409
|
-
*
|
|
418
|
+
* mobile-renderer axis: the range of host `mobileRendererVersion` the
|
|
419
|
+
* plugin's mobile package supports (parallel to `pluginApi`). `reactNative`
|
|
420
|
+
* and `expoSdk` (additive) are gated against the resolved
|
|
421
|
+
* `selfhelp-mobile-preview` image's `reactNativeVersion` / `expoSdkVersion`.
|
|
422
|
+
* All three are absent for web-only plugins.
|
|
410
423
|
*/
|
|
411
|
-
compatibility: { core: string; pluginApi: string; mobile?: string };
|
|
424
|
+
compatibility: { core: string; pluginApi: string; mobile?: string; reactNative?: string; expoSdk?: string };
|
|
412
425
|
dependencies?: { plugins: { id: string; range: string }[] };
|
|
413
426
|
artifacts: { manifestUrl: string; archiveUrl: string; sha256: string };
|
|
414
427
|
security: SignatureBlock;
|
package/src/types/index.ts
CHANGED