@selfhelp/shared 1.17.1 → 1.19.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.
@@ -0,0 +1,106 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ import { describe, it, expect } from 'vitest';
6
+ import type { IPageItem } from '../../types/pages';
7
+ import {
8
+ DEFAULT_MOBILE_NAV_RENDER,
9
+ DEFAULT_WEB_NAV_RENDER,
10
+ isMobileNavRender,
11
+ isWebNavRender,
12
+ MOBILE_NAV_RENDER_OPTIONS,
13
+ resolveMobileNavRender,
14
+ resolveWebNavRender,
15
+ WEB_NAV_RENDER_OPTIONS,
16
+ } from '../navRender';
17
+ import { DEFAULT_MOBILE_ICON, isMobileIconName, MOBILE_ICON_SET, resolveMobileIcon } from '../mobileIcons';
18
+ import { getMenuVisibleChildren, isMenuVisible, isNavigationPage } from '../menuVisibility';
19
+
20
+ function page(partial: Partial<IPageItem>): IPageItem {
21
+ return {
22
+ id: 0,
23
+ keyword: 'k',
24
+ url: null,
25
+ parent_page_id: null,
26
+ is_headless: false,
27
+ navPosition: null,
28
+ footerPosition: null,
29
+ ...partial,
30
+ };
31
+ }
32
+
33
+ describe('navRender', () => {
34
+ it('validates web/mobile render values', () => {
35
+ expect(isWebNavRender('tabs')).toBe(true);
36
+ expect(isWebNavRender('bottom-tabs')).toBe(false); // mobile-only value
37
+ expect(isMobileNavRender('bottom-tabs')).toBe(true);
38
+ expect(isMobileNavRender('header-dropdown')).toBe(false); // web-only value
39
+ expect(isWebNavRender(null)).toBe(false);
40
+ });
41
+
42
+ it('resolves to the value when valid and falls back otherwise', () => {
43
+ expect(resolveWebNavRender('hero-cards')).toBe('hero-cards');
44
+ expect(resolveWebNavRender('nope')).toBe(DEFAULT_WEB_NAV_RENDER);
45
+ expect(resolveWebNavRender(null, 'header-dropdown')).toBe('header-dropdown');
46
+ expect(resolveMobileNavRender('drawer')).toBe('drawer');
47
+ expect(resolveMobileNavRender(undefined)).toBe(DEFAULT_MOBILE_NAV_RENDER);
48
+ });
49
+
50
+ it('option metadata covers every value with a label + description', () => {
51
+ for (const opt of WEB_NAV_RENDER_OPTIONS) {
52
+ expect(isWebNavRender(opt.value)).toBe(true);
53
+ expect(opt.label.length).toBeGreaterThan(0);
54
+ expect(opt.description.length).toBeGreaterThan(0);
55
+ }
56
+ for (const opt of MOBILE_NAV_RENDER_OPTIONS) {
57
+ expect(isMobileNavRender(opt.value)).toBe(true);
58
+ expect(opt.label.length).toBeGreaterThan(0);
59
+ expect(opt.description.length).toBeGreaterThan(0);
60
+ }
61
+ });
62
+ });
63
+
64
+ describe('mobileIcons', () => {
65
+ it('exposes a non-empty curated set with unique names', () => {
66
+ expect(MOBILE_ICON_SET.length).toBeGreaterThan(10);
67
+ const names = MOBILE_ICON_SET.map((entry) => entry.name);
68
+ expect(new Set(names).size).toBe(names.length);
69
+ });
70
+
71
+ it('validates and resolves icon names with a default fallback', () => {
72
+ expect(isMobileIconName('House')).toBe(true);
73
+ expect(isMobileIconName('NotAnIcon')).toBe(false);
74
+ expect(resolveMobileIcon('Users')).toBe('Users');
75
+ expect(resolveMobileIcon('NotAnIcon')).toBe(DEFAULT_MOBILE_ICON);
76
+ expect(resolveMobileIcon(null)).toBe(DEFAULT_MOBILE_ICON);
77
+ });
78
+ });
79
+
80
+ describe('menuVisibility', () => {
81
+ it('treats a page with a nav position and not headless as a menu page', () => {
82
+ expect(isMenuVisible(page({ navPosition: 1 }))).toBe(true);
83
+ expect(isMenuVisible(page({ navPosition: null }))).toBe(false);
84
+ expect(isMenuVisible(page({ navPosition: 1, is_headless: true }))).toBe(false);
85
+ });
86
+
87
+ it('returns only menu-visible children in nav order', () => {
88
+ const parent = page({
89
+ keyword: 'team',
90
+ navPosition: 1,
91
+ children: [
92
+ page({ keyword: 'b', navPosition: 2 }),
93
+ page({ keyword: 'a', navPosition: 1 }),
94
+ page({ keyword: 'hidden', navPosition: null }),
95
+ page({ keyword: 'headless', navPosition: 3, is_headless: true }),
96
+ ],
97
+ });
98
+ const visible = getMenuVisibleChildren(parent);
99
+ expect(visible.map((child) => child.keyword)).toEqual(['a', 'b']);
100
+ expect(isNavigationPage(parent)).toBe(true);
101
+ });
102
+
103
+ it('a leaf page (no menu-visible children) is not a navigation page', () => {
104
+ expect(isNavigationPage(page({ navPosition: 1, children: [] }))).toBe(false);
105
+ });
106
+ });
@@ -0,0 +1,12 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Navigation contract: render types + option metadata, the curated mobile icon
7
+ * set, and the shared menu-visibility predicate. Imported by the web frontend
8
+ * (admin selects + renderers) and the mobile app (renderers).
9
+ */
10
+ export * from './navRender';
11
+ export * from './mobileIcons';
12
+ export * from './menuVisibility';
@@ -0,0 +1,38 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * The single "is this page on the menu?" predicate, shared by web + mobile menu
7
+ * renderers AND by the automatic virtual-navigation decision. A page is on the
8
+ * menu when the author placed it there (`navPosition != null`) and it is not a
9
+ * headless content-only fragment.
10
+ *
11
+ * Footer-only pages (`footerPosition != null && navPosition == null`), headless
12
+ * pages, and ACL-pruned pages (never in the tree to begin with) are NOT menu
13
+ * pages, so they never appear in a navigation block.
14
+ */
15
+
16
+ import type { IPageItem } from '../types/pages';
17
+
18
+ export function isMenuVisible(page: Pick<IPageItem, 'is_headless' | 'navPosition'>): boolean {
19
+ if (page.is_headless) return false;
20
+ return page.navPosition !== null && page.navPosition !== undefined;
21
+ }
22
+
23
+ /** Children of `page` that should appear in a navigation block, in nav order. */
24
+ export function getMenuVisibleChildren(page: IPageItem): IPageItem[] {
25
+ const children = page.children ?? [];
26
+ return children
27
+ .filter(isMenuVisible)
28
+ .sort((a, b) => (a.navPosition ?? 0) - (b.navPosition ?? 0));
29
+ }
30
+
31
+ /**
32
+ * A "navigation page" is a page whose children act as its menu. The hybrid
33
+ * auto-render rule additionally requires the page to have no visible body
34
+ * sections (decided by the caller, which has the resolved page content).
35
+ */
36
+ export function isNavigationPage(page: IPageItem): boolean {
37
+ return getMenuVisibleChildren(page).length > 0;
38
+ }
@@ -0,0 +1,86 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Curated mobile icon set — the SINGLE source of truth shared by the admin
7
+ * `select-icon-mobile` picker (web frontend, drawn with `lucide-react`) and the
8
+ * mobile menu renderers (drawn with `lucide-react-native`).
9
+ *
10
+ * Storing the lucide PascalCase export name keeps the contract stable: both
11
+ * `lucide-react` and `lucide-react-native` expose identical named exports, so a
12
+ * renderer maps `name -> (LucideIcons as Record<string, Component>)[name]`.
13
+ *
14
+ * Keep this list to icons that read well at small sizes in a tab bar / drawer
15
+ * and that exist in BOTH lucide packages. Add entries here (never per-app) so
16
+ * the picker and the renderer never drift.
17
+ */
18
+
19
+ export interface IMobileIconEntry {
20
+ /** lucide PascalCase export name, e.g. `Home`, `Users`, `LayoutDashboard`. */
21
+ name: string;
22
+ /** Friendly label for the admin picker. */
23
+ label: string;
24
+ }
25
+
26
+ export const MOBILE_ICON_SET: readonly IMobileIconEntry[] = [
27
+ { name: 'House', label: 'Home' },
28
+ { name: 'LayoutDashboard', label: 'Dashboard' },
29
+ { name: 'User', label: 'User' },
30
+ { name: 'Users', label: 'Users / Team' },
31
+ { name: 'Settings', label: 'Settings' },
32
+ { name: 'FileText', label: 'Document' },
33
+ { name: 'Files', label: 'Files' },
34
+ { name: 'Folder', label: 'Folder' },
35
+ { name: 'Info', label: 'Info' },
36
+ { name: 'CircleQuestionMark', label: 'Help' },
37
+ { name: 'Mail', label: 'Mail' },
38
+ { name: 'Phone', label: 'Phone' },
39
+ { name: 'Calendar', label: 'Calendar' },
40
+ { name: 'Bell', label: 'Notifications' },
41
+ { name: 'Search', label: 'Search' },
42
+ { name: 'Star', label: 'Star' },
43
+ { name: 'Heart', label: 'Heart' },
44
+ { name: 'Bookmark', label: 'Bookmark' },
45
+ { name: 'Map', label: 'Map' },
46
+ { name: 'MapPin', label: 'Location' },
47
+ { name: 'Image', label: 'Image' },
48
+ { name: 'Video', label: 'Video' },
49
+ { name: 'Music', label: 'Music' },
50
+ { name: 'ShoppingCart', label: 'Shopping cart' },
51
+ { name: 'CreditCard', label: 'Payment' },
52
+ { name: 'ChartBar', label: 'Bar chart' },
53
+ { name: 'ChartPie', label: 'Pie chart' },
54
+ { name: 'Activity', label: 'Activity' },
55
+ { name: 'Shield', label: 'Shield' },
56
+ { name: 'Lock', label: 'Lock' },
57
+ { name: 'Globe', label: 'Globe' },
58
+ { name: 'Compass', label: 'Compass' },
59
+ { name: 'Flag', label: 'Flag' },
60
+ { name: 'Award', label: 'Award' },
61
+ { name: 'Briefcase', label: 'Work' },
62
+ { name: 'Building', label: 'Building' },
63
+ { name: 'BookOpen', label: 'Book' },
64
+ { name: 'MessageSquare', label: 'Messages' },
65
+ { name: 'ClipboardList', label: 'Tasks' },
66
+ { name: 'CircleCheck', label: 'Check' },
67
+ { name: 'List', label: 'List' },
68
+ { name: 'LayoutGrid', label: 'Grid' },
69
+ { name: 'Menu', label: 'Menu' },
70
+ { name: 'Database', label: 'Data' },
71
+ ] as const;
72
+
73
+ /** All valid mobile icon names (for validation / membership checks). */
74
+ export const MOBILE_ICON_NAMES: readonly string[] = MOBILE_ICON_SET.map((entry) => entry.name);
75
+
76
+ /** Neutral fallback used when a page has no `mobile_icon` or an unknown value. */
77
+ export const DEFAULT_MOBILE_ICON = 'Circle';
78
+
79
+ export function isMobileIconName(value: unknown): value is string {
80
+ return typeof value === 'string' && MOBILE_ICON_NAMES.includes(value);
81
+ }
82
+
83
+ /** Resolve a stored `mobile_icon` to a drawable name, falling back to the default. */
84
+ export function resolveMobileIcon(value: unknown): string {
85
+ return isMobileIconName(value) ? value : DEFAULT_MOBILE_ICON;
86
+ }
@@ -0,0 +1,132 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Navigation rendering contract (shared by web + mobile).
7
+ *
8
+ * The page TREE defines navigation STRUCTURE (parent/child + `nav_position`).
9
+ * A per-page render type controls PRESENTATION only — it never changes the
10
+ * structure or the URLs. Web and mobile each pick their own renderer from the
11
+ * stored value, so the same subtree can render differently per platform.
12
+ *
13
+ * - `web_nav_render` selects the web renderer for a page's children.
14
+ * - `mobile_nav_render` selects the mobile renderer for a page's children.
15
+ *
16
+ * Both fields are OPTIONAL on a page; when unset the platform applies its
17
+ * default (web `tabs`, mobile `segmented-tabs` for a navigation page's
18
+ * children; the GLOBAL app menu defaults to web `header-dropdown` and mobile
19
+ * `bottom-tabs`).
20
+ */
21
+
22
+ export type TWebNavRender = 'header-dropdown' | 'tabs' | 'sidebar-drawer' | 'hero-cards';
23
+
24
+ export type TMobileNavRender = 'segmented-tabs' | 'bottom-tabs' | 'drawer' | 'hero-cards';
25
+
26
+ export const WEB_NAV_RENDER_VALUES: readonly TWebNavRender[] = [
27
+ 'header-dropdown',
28
+ 'tabs',
29
+ 'sidebar-drawer',
30
+ 'hero-cards',
31
+ ] as const;
32
+
33
+ export const MOBILE_NAV_RENDER_VALUES: readonly TMobileNavRender[] = [
34
+ 'segmented-tabs',
35
+ 'bottom-tabs',
36
+ 'drawer',
37
+ 'hero-cards',
38
+ ] as const;
39
+
40
+ /** Default renderer for a navigation page's CHILDREN. */
41
+ export const DEFAULT_WEB_NAV_RENDER: TWebNavRender = 'tabs';
42
+ export const DEFAULT_MOBILE_NAV_RENDER: TMobileNavRender = 'segmented-tabs';
43
+
44
+ /** Default renderer for the GLOBAL app menu (header / shell). */
45
+ export const DEFAULT_WEB_GLOBAL_NAV_RENDER: TWebNavRender = 'header-dropdown';
46
+ export const DEFAULT_MOBILE_GLOBAL_NAV_RENDER: TMobileNavRender = 'bottom-tabs';
47
+
48
+ export interface INavRenderOption<T extends string> {
49
+ value: T;
50
+ /** Friendly label for the admin select. */
51
+ label: string;
52
+ /** Short, plain-language explanation shown under the select. */
53
+ description: string;
54
+ }
55
+
56
+ /** Option metadata for the admin "Web menu style" select. */
57
+ export const WEB_NAV_RENDER_OPTIONS: readonly INavRenderOption<TWebNavRender>[] = [
58
+ {
59
+ value: 'header-dropdown',
60
+ label: 'Header dropdown',
61
+ description: 'Classic top menu; child pages appear in a dropdown. Best for the global website menu.',
62
+ },
63
+ {
64
+ value: 'tabs',
65
+ label: 'Tabs',
66
+ description: 'Show child pages as horizontal tabs. Best for a navigation page with a few children.',
67
+ },
68
+ {
69
+ value: 'sidebar-drawer',
70
+ label: 'Sidebar drawer',
71
+ description: 'Side drawer / hamburger menu. Best for large or deep navigation.',
72
+ },
73
+ {
74
+ value: 'hero-cards',
75
+ label: 'Hero cards',
76
+ description: 'Dashboard-style card grid. Best for landing pages and CMS app dashboards.',
77
+ },
78
+ ] as const;
79
+
80
+ /** Option metadata for the admin "Mobile menu style" select. */
81
+ export const MOBILE_NAV_RENDER_OPTIONS: readonly INavRenderOption<TMobileNavRender>[] = [
82
+ {
83
+ value: 'segmented-tabs',
84
+ label: 'Segmented tabs',
85
+ description: 'Top segmented control for first-level children. Best for a few child pages.',
86
+ },
87
+ {
88
+ value: 'bottom-tabs',
89
+ label: 'Bottom tabs',
90
+ description: 'Bottom tab bar for 3–5 main app-like destinations.',
91
+ },
92
+ {
93
+ value: 'drawer',
94
+ label: 'Drawer',
95
+ description: 'Hamburger / side drawer for larger navigation.',
96
+ },
97
+ {
98
+ value: 'hero-cards',
99
+ label: 'Hero cards',
100
+ description: 'Card grid for dashboards and CMS app pages.',
101
+ },
102
+ ] as const;
103
+
104
+ export function isWebNavRender(value: unknown): value is TWebNavRender {
105
+ return typeof value === 'string' && (WEB_NAV_RENDER_VALUES as readonly string[]).includes(value);
106
+ }
107
+
108
+ export function isMobileNavRender(value: unknown): value is TMobileNavRender {
109
+ return typeof value === 'string' && (MOBILE_NAV_RENDER_VALUES as readonly string[]).includes(value);
110
+ }
111
+
112
+ /**
113
+ * Resolve a stored `web_nav_render` value to a concrete renderer, falling back
114
+ * to the supplied default (page-children default by default).
115
+ */
116
+ export function resolveWebNavRender(
117
+ value: unknown,
118
+ fallback: TWebNavRender = DEFAULT_WEB_NAV_RENDER,
119
+ ): TWebNavRender {
120
+ return isWebNavRender(value) ? value : fallback;
121
+ }
122
+
123
+ /**
124
+ * Resolve a stored `mobile_nav_render` value to a concrete renderer, falling
125
+ * back to the supplied default (page-children default by default).
126
+ */
127
+ export function resolveMobileNavRender(
128
+ value: unknown,
129
+ fallback: TMobileNavRender = DEFAULT_MOBILE_NAV_RENDER,
130
+ ): TMobileNavRender {
131
+ return isMobileNavRender(value) ? value : fallback;
132
+ }
@@ -0,0 +1,110 @@
1
+ /*
2
+ * SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ import { describe, expect, it } from 'vitest';
7
+ import type { IPageContent, IPageRoute } from '../../pages';
8
+ import type { IResolvePageResponse } from '../page';
9
+
10
+ /**
11
+ * Contract coverage for the DB-driven public routing types (issue #30). The web
12
+ * frontend auth styles and the mobile app read `page.route_params.user_id` /
13
+ * `.token` straight off the resolved page, so the route metadata MUST live on
14
+ * `IPageContent` with snake_case param keys. `IPageRoute` is the admin
15
+ * page-routes editor + export/import contract and must keep `path_pattern`
16
+ * placeholders verbatim.
17
+ */
18
+ describe('IPageContent route metadata (resolve responses)', () => {
19
+ it('carries optional snake_case route_params + matched/canonical url', () => {
20
+ const page: IPageContent = {
21
+ id: 7,
22
+ keyword: 'reset-password',
23
+ url: '/reset',
24
+ parent_page_id: null,
25
+ is_headless: true,
26
+ nav_position: null,
27
+ footer_position: null,
28
+ route_params: { user_id: '42', token: 'abc.def~1' },
29
+ matched_url_pattern: '/reset/{user_id}/{token}',
30
+ canonical_url: '/reset',
31
+ sections: [],
32
+ };
33
+
34
+ expect(page.route_params?.user_id).toBe('42');
35
+ expect(page.route_params?.token).toBe('abc.def~1');
36
+ expect(page.matched_url_pattern).toBe('/reset/{user_id}/{token}');
37
+ expect(page.canonical_url).toBe('/reset');
38
+ });
39
+
40
+ it('treats route metadata as optional (a static page omits it)', () => {
41
+ const page: IPageContent = {
42
+ id: 1,
43
+ keyword: 'home',
44
+ url: '/',
45
+ parent_page_id: null,
46
+ is_headless: false,
47
+ nav_position: 1,
48
+ footer_position: null,
49
+ sections: [],
50
+ };
51
+
52
+ expect(page.route_params).toBeUndefined();
53
+ expect(page.matched_url_pattern).toBeUndefined();
54
+ });
55
+
56
+ it('wraps the resolved page in the standard envelope', () => {
57
+ const response: IResolvePageResponse = {
58
+ status: 200,
59
+ message: 'OK',
60
+ error: null,
61
+ logged_in: false,
62
+ meta: { version: 'v1', timestamp: '2026-06-30T00:00:00Z' },
63
+ data: {
64
+ page: {
65
+ id: 9,
66
+ keyword: 'team',
67
+ url: '/team/7',
68
+ parent_page_id: null,
69
+ is_headless: false,
70
+ nav_position: null,
71
+ footer_position: null,
72
+ route_params: { record_id: '7' },
73
+ sections: [],
74
+ },
75
+ },
76
+ };
77
+
78
+ expect(response.data?.page.route_params?.record_id).toBe('7');
79
+ });
80
+ });
81
+
82
+ describe('IPageRoute (admin editor + export/import contract)', () => {
83
+ it('models a parameterized canonical route with regex requirements', () => {
84
+ const route: IPageRoute = {
85
+ id: 12,
86
+ path_pattern: '/team/{record_id}',
87
+ requirements: { record_id: '\\d+' },
88
+ is_canonical: true,
89
+ is_active: true,
90
+ priority: 50,
91
+ };
92
+
93
+ // Param names are NEVER remapped, so the placeholder must survive verbatim.
94
+ expect(route.path_pattern).toContain('{record_id}');
95
+ expect(route.requirements?.record_id).toBe('\\d+');
96
+ expect(route.is_canonical).toBe(true);
97
+ });
98
+
99
+ it('allows a static route with no requirements', () => {
100
+ const route: IPageRoute = {
101
+ path_pattern: '/reset',
102
+ requirements: null,
103
+ is_canonical: true,
104
+ is_active: true,
105
+ priority: 100,
106
+ };
107
+
108
+ expect(route.requirements).toBeNull();
109
+ });
110
+ });
@@ -7,3 +7,10 @@ import type { IPageContent, IPageItem } from '../pages';
7
7
 
8
8
  export type IGetPageResponse = IBaseApiResponse<{ page: IPageContent }>;
9
9
  export type IGetPagesResponse = IBaseApiResponse<IPageItem[]>;
10
+
11
+ /**
12
+ * Response of `GET /cms-api/v1/pages/resolve?path=...` (issue #30). Identical
13
+ * envelope to {@link IGetPageResponse}; the resolved `page` additionally carries
14
+ * `route_params`, `matched_url_pattern`, and `canonical_url`.
15
+ */
16
+ export type IResolvePageResponse = IBaseApiResponse<{ page: IPageContent }>;
@@ -4,6 +4,7 @@ SPDX-License-Identifier: MPL-2.0
4
4
  */
5
5
  import type { IContentField } from './styles/base';
6
6
  import type { TStyleName } from './styles/unknown';
7
+ import type { TWebNavRender, TMobileNavRender } from '../navigation/navRender';
7
8
 
8
9
  /**
9
10
  * Comprehensive page type system, single source of truth for both apps.
@@ -62,6 +63,14 @@ export interface IPageItem extends IBasePageInfo {
62
63
  id_page_access_types?: number;
63
64
  title?: string | null;
64
65
  description?: string | null;
66
+ /** Web menu icon (Tabler component name, e.g. `IconHome`). Page property field `icon`. */
67
+ icon?: string | null;
68
+ /** Mobile menu icon (curated lucide name, e.g. `Home`). Page property field `mobile_icon`. */
69
+ mobile_icon?: string | null;
70
+ /** How this page renders its children as navigation on web. Page property field `web_nav_render`. */
71
+ web_nav_render?: TWebNavRender | null;
72
+ /** How this page renders its children as navigation on mobile. Page property field `mobile_nav_render`. */
73
+ mobile_nav_render?: TMobileNavRender | null;
65
74
  children?: IPageItem[];
66
75
  }
67
76
 
@@ -75,9 +84,44 @@ export interface IPageContent {
75
84
  footer_position: number | null;
76
85
  title?: string | null;
77
86
  description?: string | null;
87
+ /** Web menu icon (Tabler component name). Mirrors the `icon` page property field. */
88
+ icon?: string | null;
89
+ /** Mobile menu icon (curated lucide name). Mirrors the `mobile_icon` page property field. */
90
+ mobile_icon?: string | null;
91
+ /** Web child-navigation render type. Mirrors the `web_nav_render` page property field. */
92
+ web_nav_render?: TWebNavRender | null;
93
+ /** Mobile child-navigation render type. Mirrors the `mobile_nav_render` page property field. */
94
+ mobile_nav_render?: TMobileNavRender | null;
95
+ /**
96
+ * Snake_case route params extracted from the matched public URL pattern
97
+ * (e.g. `{ user_id: '42', token: 'abc' }` or `{ record_id: '7' }`). Present
98
+ * only when the page was resolved via `GET /pages/resolve`. Backend also
99
+ * exposes these to interpolation as `{{route.<name>}}`.
100
+ */
101
+ route_params?: Record<string, string>;
102
+ /** The `page_routes` pattern that matched (e.g. `/reset/{user_id}/{token}`). Resolve responses only. */
103
+ matched_url_pattern?: string | null;
104
+ /** The canonical active route pattern for the page, for canonical-link generation. Resolve responses only. */
105
+ canonical_url?: string | null;
78
106
  sections: IPageSectionWithFields[];
79
107
  }
80
108
 
109
+ /**
110
+ * A public, parameterized route contract for a CMS page (issue #30). Mirrors a
111
+ * backend `page_routes` row. `path_pattern` uses Symfony route syntax
112
+ * (`/team/{record_id}`) and `requirements` maps each placeholder to a regex
113
+ * (`{ record_id: '\\d+' }`). Param names are snake_case and are NEVER remapped
114
+ * on export/import. Used by the admin page-routes editor and page export/import.
115
+ */
116
+ export interface IPageRoute {
117
+ id?: number;
118
+ path_pattern: string;
119
+ requirements?: Record<string, string> | null;
120
+ is_canonical: boolean;
121
+ is_active: boolean;
122
+ priority: number;
123
+ }
124
+
81
125
  export interface IPageFieldTranslation {
82
126
  language_id: number;
83
127
  language_code: string;
@@ -48,6 +48,29 @@ describe('transformPageData', () => {
48
48
  expect(result.children[0].navPosition).toBe(5);
49
49
  });
50
50
 
51
+ it('passes through the navigation icon + render fields', () => {
52
+ const result = transformPageData({
53
+ id: 1,
54
+ keyword: 'team',
55
+ icon: 'IconUsers',
56
+ mobile_icon: 'Users',
57
+ web_nav_render: 'hero-cards',
58
+ mobile_nav_render: 'bottom-tabs',
59
+ });
60
+ expect(result.icon).toBe('IconUsers');
61
+ expect(result.mobile_icon).toBe('Users');
62
+ expect(result.web_nav_render).toBe('hero-cards');
63
+ expect(result.mobile_nav_render).toBe('bottom-tabs');
64
+ });
65
+
66
+ it('defaults the navigation fields to null when absent', () => {
67
+ const result = transformPageData({ id: 1, keyword: 'plain' });
68
+ expect(result.icon).toBeNull();
69
+ expect(result.mobile_icon).toBeNull();
70
+ expect(result.web_nav_render).toBeNull();
71
+ expect(result.mobile_nav_render).toBeNull();
72
+ });
73
+
51
74
  it('defaults missing id/keyword safely', () => {
52
75
  const result = transformPageData({});
53
76
  expect(result.id).toBe(0);
@@ -19,9 +19,18 @@ SPDX-License-Identifier: MPL-2.0
19
19
  * removed all legacy aliases (`parent`, `id_type`,
20
20
  * `id_pageAccessTypes`). The backend is the single source of canonical
21
21
  * keys; the transformer no longer accepts the legacy shapes.
22
+ *
23
+ * ROUTE METADATA (issue #30): this transformer deliberately does NOT carry
24
+ * `route_params` / `matched_url_pattern` / `canonical_url`. Those are
25
+ * resolve-time fields of a single page's full content (`IPageContent`, returned
26
+ * by `GET /pages/resolve`) and are consumed directly off that type. `IPageItem`
27
+ * is the navigation/menu projection of the page tree (keyword, url,
28
+ * nav/footer position, parent/children) and never participates in URL
29
+ * resolution, so adding a route passthrough here would be dead weight.
22
30
  */
23
31
 
24
32
  import type { IPageItem } from '../types/pages';
33
+ import type { TWebNavRender, TMobileNavRender } from '../navigation/navRender';
25
34
 
26
35
  interface IRawPage {
27
36
  id?: number;
@@ -39,6 +48,10 @@ interface IRawPage {
39
48
  is_open_access?: number | boolean | null;
40
49
  title?: string | null;
41
50
  description?: string | null;
51
+ icon?: string | null;
52
+ mobile_icon?: string | null;
53
+ web_nav_render?: TWebNavRender | string | null;
54
+ mobile_nav_render?: TMobileNavRender | string | null;
42
55
  id_users?: number;
43
56
  acl_select?: 0 | 1;
44
57
  acl_insert?: 0 | 1;
@@ -76,6 +89,10 @@ export function transformPageData(apiPage: IRawPage): IPageItem {
76
89
  is_system: apiPage.is_system !== undefined ? toBool(apiPage.is_system) : undefined,
77
90
  title: apiPage.title ?? null,
78
91
  description: apiPage.description ?? null,
92
+ icon: apiPage.icon ?? null,
93
+ mobile_icon: apiPage.mobile_icon ?? null,
94
+ web_nav_render: (apiPage.web_nav_render as TWebNavRender | null) ?? null,
95
+ mobile_nav_render: (apiPage.mobile_nav_render as TMobileNavRender | null) ?? null,
79
96
  children: apiPage.children?.map(transformPageData) ?? [],
80
97
 
81
98
  id_users: apiPage.id_users,