@selfhelp/shared 1.21.5 → 1.21.7

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/dist/index.js CHANGED
@@ -49,6 +49,7 @@ __export(index_exports, {
49
49
  ENDPOINTS: () => ENDPOINTS,
50
50
  FIELDS_MAP_STYLE_CONFIG: () => FIELDS_MAP_STYLE_CONFIG,
51
51
  FONT_SIZE_PX: () => FONT_SIZE_PX,
52
+ FORM_RECORD_PREFILL_SKIP_FIELDS: () => FORM_RECORD_PREFILL_SKIP_FIELDS,
52
53
  FULL_RADIUS_PX: () => FULL_RADIUS_PX,
53
54
  HEADER_CLIENT_TYPE: () => HEADER_CLIENT_TYPE,
54
55
  LINE_HEIGHT: () => LINE_HEIGHT,
@@ -80,6 +81,9 @@ __export(index_exports, {
80
81
  _resetPluginStyleRegistry: () => _resetPluginStyleRegistry,
81
82
  arePreviewPreferencesEqual: () => arePreviewPreferencesEqual,
82
83
  buildConditionContext: () => buildConditionContext,
84
+ buildPagesResolvePath: () => buildPagesResolvePath,
85
+ buildPagesResolveQuery: () => buildPagesResolveQuery,
86
+ buildPagesResolveUrl: () => buildPagesResolveUrl,
83
87
  buildPublicPathFromRoute: () => buildPublicPathFromRoute,
84
88
  clampMenuItemsAtDepth: () => clampMenuItemsAtDepth,
85
89
  classifyClass: () => classifyClass,
@@ -94,6 +98,7 @@ __export(index_exports, {
94
98
  findPageRefInNavigationPayload: () => findPageRefInNavigationPayload,
95
99
  findRemap: () => findRemap,
96
100
  flattenFooterItems: () => flattenFooterItems,
101
+ flattenFormRecordPrefillValues: () => flattenFormRecordPrefillValues,
97
102
  flattenMenuItems: () => flattenMenuItems,
98
103
  flattenNavigationMenuItems: () => flattenNavigationMenuItems,
99
104
  footerColumnItems: () => footerColumnItems,
@@ -148,11 +153,13 @@ __export(index_exports, {
148
153
  matchesMobilePath: () => matchesMobilePath,
149
154
  matchesWebPath: () => matchesWebPath,
150
155
  mergeHeaderLayers: () => mergeHeaderLayers,
156
+ normalizePagesResolvePath: () => normalizePagesResolvePath,
151
157
  pageUrlToMobileRoute: () => pageUrlToMobileRoute,
152
158
  parseDimensionToReactNative: () => parseDimensionToReactNative,
153
159
  parseDimensionToWeb: () => parseDimensionToWeb,
154
160
  parseFieldsMapCatalog: () => parseFieldsMapCatalog,
155
161
  parseFieldsMapLabels: () => parseFieldsMapLabels,
162
+ parseFormRecordPrefill: () => parseFormRecordPrefill,
156
163
  parseInlineRich: () => parseInlineRich,
157
164
  parseOptionCatalog: () => parseOptionCatalog,
158
165
  parseOptionCodes: () => parseOptionCodes,
@@ -350,7 +357,7 @@ function isPreviewBridgeMessage(value) {
350
357
  case PREVIEW_BRIDGE_MESSAGE.READY:
351
358
  return record.source === "web" || record.source === "mobile";
352
359
  case PREVIEW_BRIDGE_MESSAGE.NAVIGATED:
353
- return (record.source === "web" || record.source === "mobile") && (typeof record.keyword === "string" || record.keyword === null) && typeof record.href === "string";
360
+ return (record.source === "web" || record.source === "mobile") && (typeof record.keyword === "string" || record.keyword === null) && typeof record.href === "string" && (record.path === void 0 || record.path === null || typeof record.path === "string");
354
361
  case PREVIEW_BRIDGE_MESSAGE.NAVIGATE:
355
362
  return (typeof record.keyword === "string" || record.keyword === null) && (record.path === void 0 || record.path === null || typeof record.path === "string");
356
363
  case PREVIEW_BRIDGE_MESSAGE.SET_PREFERENCES:
@@ -624,11 +631,12 @@ var ENDPOINTS = {
624
631
  BY_KEYWORD: (keyword) => `${API_VERSION_PREFIX}/pages/by-keyword/${encodeURIComponent(keyword)}`,
625
632
  BY_ID: (pageId) => `${API_VERSION_PREFIX}/pages/${pageId}`,
626
633
  /**
627
- * DB-driven public path resolution (issue #30): maps a full public URL
628
- * path (e.g. `/reset/42/abc`, `/team/7`) to a page payload + route
629
- * params. `path` is sent URL-encoded as a query parameter.
634
+ * Static resolve route (no query). Always pair with
635
+ * {@link buildPagesResolveUrl} / {@link buildPagesResolvePath} so
636
+ * `path`, `language_id`, and `preview` are encoded identically across
637
+ * SSR, browser, and mobile.
630
638
  */
631
- RESOLVE: (path) => `${API_VERSION_PREFIX}/pages/resolve?path=${encodeURIComponent(path)}`
639
+ RESOLVE_ROUTE: `${API_VERSION_PREFIX}/pages/resolve`
632
640
  },
633
641
  NAVIGATION: {
634
642
  GET: `${API_VERSION_PREFIX}/navigation`,
@@ -650,6 +658,37 @@ var CLIENT_TYPE_WEB = "web";
650
658
  var CLIENT_TYPE_MOBILE = "mobile";
651
659
  var CLIENT_TYPE_MOBILE_AND_WEB = "mobile_and_web";
652
660
 
661
+ // src/api/pagesResolve.ts
662
+ function normalizePagesResolvePath(rawPath) {
663
+ const withoutOrigin = rawPath.includes("://") ? (() => {
664
+ try {
665
+ return new URL(rawPath).pathname;
666
+ } catch {
667
+ return rawPath;
668
+ }
669
+ })() : rawPath;
670
+ const pathOnly = withoutOrigin.split("#")[0].split("?")[0];
671
+ const withSlash = pathOnly.startsWith("/") ? pathOnly : `/${pathOnly}`;
672
+ return withSlash.replace(/\/+$/, "") || "/";
673
+ }
674
+ function buildPagesResolveQuery(params) {
675
+ const search = new URLSearchParams();
676
+ search.set("path", normalizePagesResolvePath(params.path));
677
+ if (params.languageId != null && Number.isFinite(params.languageId) && params.languageId > 0) {
678
+ search.set("language_id", String(params.languageId));
679
+ }
680
+ if (params.preview) {
681
+ search.set("preview", "true");
682
+ }
683
+ return search.toString();
684
+ }
685
+ function buildPagesResolvePath(params) {
686
+ return `/pages/resolve?${buildPagesResolveQuery(params)}`;
687
+ }
688
+ function buildPagesResolveUrl(params) {
689
+ return `${API_VERSION_PREFIX}${buildPagesResolvePath(params)}`;
690
+ }
691
+
653
692
  // src/theme/tokens.ts
654
693
  var FONT_SIZE_PX = {
655
694
  xs: 12,
@@ -1813,6 +1852,118 @@ function serializeFieldsMapLabels(labels) {
1813
1852
  return JSON.stringify(clean);
1814
1853
  }
1815
1854
 
1855
+ // src/content/formRecordPrefill.ts
1856
+ var FORM_RECORD_PREFILL_SKIP_FIELDS = /* @__PURE__ */ new Set([
1857
+ "record_id",
1858
+ "entry_date",
1859
+ "id_users",
1860
+ "user_name",
1861
+ "user_code",
1862
+ "id_actionTriggerTypes",
1863
+ "triggerType",
1864
+ "id_languages",
1865
+ "language_locale",
1866
+ "language_name"
1867
+ ]);
1868
+ function isTranslatableChild(children, fieldName) {
1869
+ if (!Array.isArray(children)) {
1870
+ return false;
1871
+ }
1872
+ const child = children.find((item) => item?.name?.content === fieldName);
1873
+ return child?.translatable?.content === "1";
1874
+ }
1875
+ function asScalarString(value) {
1876
+ if (value === null || value === void 0) {
1877
+ return null;
1878
+ }
1879
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1880
+ return String(value);
1881
+ }
1882
+ return null;
1883
+ }
1884
+ function parseFormRecordPrefill(section) {
1885
+ const sectionDataArray = section?.section_data;
1886
+ if (!Array.isArray(sectionDataArray) || sectionDataArray.length === 0) {
1887
+ return { recordId: null, values: {} };
1888
+ }
1889
+ const recordGroups = {};
1890
+ for (const row of sectionDataArray) {
1891
+ if (!row || typeof row !== "object" || Array.isArray(row)) {
1892
+ continue;
1893
+ }
1894
+ const record = row;
1895
+ const rawRecordId = record.record_id;
1896
+ const recordId = typeof rawRecordId === "number" ? rawRecordId : typeof rawRecordId === "string" && rawRecordId.trim() !== "" && Number.isFinite(Number(rawRecordId)) ? Number(rawRecordId) : null;
1897
+ if (recordId === null) {
1898
+ continue;
1899
+ }
1900
+ if (!recordGroups[recordId]) {
1901
+ recordGroups[recordId] = {};
1902
+ }
1903
+ const languageId = typeof record.id_languages === "number" ? record.id_languages : typeof record.id_languages === "string" && Number.isFinite(Number(record.id_languages)) ? Number(record.id_languages) : void 0;
1904
+ for (const [fieldName, fieldValue] of Object.entries(record)) {
1905
+ if (FORM_RECORD_PREFILL_SKIP_FIELDS.has(fieldName)) {
1906
+ continue;
1907
+ }
1908
+ const value = asScalarString(fieldValue);
1909
+ if (value === null) {
1910
+ continue;
1911
+ }
1912
+ const translatable = isTranslatableChild(section.children, fieldName);
1913
+ if (translatable) {
1914
+ if (languageId === 1) {
1915
+ if (!recordGroups[recordId][fieldName]) {
1916
+ recordGroups[recordId][fieldName] = value;
1917
+ }
1918
+ } else if (typeof languageId === "number") {
1919
+ const current = recordGroups[recordId][fieldName];
1920
+ if (typeof current === "string" || !current) {
1921
+ recordGroups[recordId][fieldName] = [{ language_id: languageId, value }];
1922
+ } else {
1923
+ const langValues = current;
1924
+ const existingIndex = langValues.findIndex((v) => v.language_id === languageId);
1925
+ if (existingIndex >= 0) {
1926
+ langValues[existingIndex] = { language_id: languageId, value };
1927
+ } else {
1928
+ langValues.push({ language_id: languageId, value });
1929
+ }
1930
+ }
1931
+ }
1932
+ } else if (languageId === 1 || !recordGroups[recordId][fieldName]) {
1933
+ recordGroups[recordId][fieldName] = value;
1934
+ }
1935
+ }
1936
+ }
1937
+ const firstRecordId = Object.keys(recordGroups)[0];
1938
+ if (!firstRecordId) {
1939
+ return { recordId: null, values: {} };
1940
+ }
1941
+ const id = Number(firstRecordId);
1942
+ return { recordId: id, values: recordGroups[id] ?? {} };
1943
+ }
1944
+ function flattenFormRecordPrefillValues(values, languageId) {
1945
+ const out = {};
1946
+ for (const [key, value] of Object.entries(values)) {
1947
+ if (typeof value === "string") {
1948
+ out[key] = value;
1949
+ continue;
1950
+ }
1951
+ if (!Array.isArray(value) || value.length === 0) {
1952
+ continue;
1953
+ }
1954
+ if (languageId != null) {
1955
+ const match = value.find((entry) => entry.language_id === languageId);
1956
+ if (match) {
1957
+ out[key] = match.value;
1958
+ continue;
1959
+ }
1960
+ }
1961
+ const nonIndependent = value.find((entry) => entry.language_id !== 1);
1962
+ out[key] = (nonIndependent ?? value[0]).value;
1963
+ }
1964
+ return out;
1965
+ }
1966
+
1816
1967
  // src/navigation/headerPreset.ts
1817
1968
  var WEB_HEADER_PRESET_VALUES = [
1818
1969
  "simple",
@@ -2665,6 +2816,7 @@ function transformPagesData(pages) {
2665
2816
  ENDPOINTS,
2666
2817
  FIELDS_MAP_STYLE_CONFIG,
2667
2818
  FONT_SIZE_PX,
2819
+ FORM_RECORD_PREFILL_SKIP_FIELDS,
2668
2820
  FULL_RADIUS_PX,
2669
2821
  HEADER_CLIENT_TYPE,
2670
2822
  LINE_HEIGHT,
@@ -2696,6 +2848,9 @@ function transformPagesData(pages) {
2696
2848
  _resetPluginStyleRegistry,
2697
2849
  arePreviewPreferencesEqual,
2698
2850
  buildConditionContext,
2851
+ buildPagesResolvePath,
2852
+ buildPagesResolveQuery,
2853
+ buildPagesResolveUrl,
2699
2854
  buildPublicPathFromRoute,
2700
2855
  clampMenuItemsAtDepth,
2701
2856
  classifyClass,
@@ -2710,6 +2865,7 @@ function transformPagesData(pages) {
2710
2865
  findPageRefInNavigationPayload,
2711
2866
  findRemap,
2712
2867
  flattenFooterItems,
2868
+ flattenFormRecordPrefillValues,
2713
2869
  flattenMenuItems,
2714
2870
  flattenNavigationMenuItems,
2715
2871
  footerColumnItems,
@@ -2764,11 +2920,13 @@ function transformPagesData(pages) {
2764
2920
  matchesMobilePath,
2765
2921
  matchesWebPath,
2766
2922
  mergeHeaderLayers,
2923
+ normalizePagesResolvePath,
2767
2924
  pageUrlToMobileRoute,
2768
2925
  parseDimensionToReactNative,
2769
2926
  parseDimensionToWeb,
2770
2927
  parseFieldsMapCatalog,
2771
2928
  parseFieldsMapLabels,
2929
+ parseFormRecordPrefill,
2772
2930
  parseInlineRich,
2773
2931
  parseOptionCatalog,
2774
2932
  parseOptionCodes,
package/dist/index.mjs CHANGED
@@ -141,7 +141,7 @@ function isPreviewBridgeMessage(value) {
141
141
  case PREVIEW_BRIDGE_MESSAGE.READY:
142
142
  return record.source === "web" || record.source === "mobile";
143
143
  case PREVIEW_BRIDGE_MESSAGE.NAVIGATED:
144
- return (record.source === "web" || record.source === "mobile") && (typeof record.keyword === "string" || record.keyword === null) && typeof record.href === "string";
144
+ return (record.source === "web" || record.source === "mobile") && (typeof record.keyword === "string" || record.keyword === null) && typeof record.href === "string" && (record.path === void 0 || record.path === null || typeof record.path === "string");
145
145
  case PREVIEW_BRIDGE_MESSAGE.NAVIGATE:
146
146
  return (typeof record.keyword === "string" || record.keyword === null) && (record.path === void 0 || record.path === null || typeof record.path === "string");
147
147
  case PREVIEW_BRIDGE_MESSAGE.SET_PREFERENCES:
@@ -415,11 +415,12 @@ var ENDPOINTS = {
415
415
  BY_KEYWORD: (keyword) => `${API_VERSION_PREFIX}/pages/by-keyword/${encodeURIComponent(keyword)}`,
416
416
  BY_ID: (pageId) => `${API_VERSION_PREFIX}/pages/${pageId}`,
417
417
  /**
418
- * DB-driven public path resolution (issue #30): maps a full public URL
419
- * path (e.g. `/reset/42/abc`, `/team/7`) to a page payload + route
420
- * params. `path` is sent URL-encoded as a query parameter.
418
+ * Static resolve route (no query). Always pair with
419
+ * {@link buildPagesResolveUrl} / {@link buildPagesResolvePath} so
420
+ * `path`, `language_id`, and `preview` are encoded identically across
421
+ * SSR, browser, and mobile.
421
422
  */
422
- RESOLVE: (path) => `${API_VERSION_PREFIX}/pages/resolve?path=${encodeURIComponent(path)}`
423
+ RESOLVE_ROUTE: `${API_VERSION_PREFIX}/pages/resolve`
423
424
  },
424
425
  NAVIGATION: {
425
426
  GET: `${API_VERSION_PREFIX}/navigation`,
@@ -441,6 +442,37 @@ var CLIENT_TYPE_WEB = "web";
441
442
  var CLIENT_TYPE_MOBILE = "mobile";
442
443
  var CLIENT_TYPE_MOBILE_AND_WEB = "mobile_and_web";
443
444
 
445
+ // src/api/pagesResolve.ts
446
+ function normalizePagesResolvePath(rawPath) {
447
+ const withoutOrigin = rawPath.includes("://") ? (() => {
448
+ try {
449
+ return new URL(rawPath).pathname;
450
+ } catch {
451
+ return rawPath;
452
+ }
453
+ })() : rawPath;
454
+ const pathOnly = withoutOrigin.split("#")[0].split("?")[0];
455
+ const withSlash = pathOnly.startsWith("/") ? pathOnly : `/${pathOnly}`;
456
+ return withSlash.replace(/\/+$/, "") || "/";
457
+ }
458
+ function buildPagesResolveQuery(params) {
459
+ const search = new URLSearchParams();
460
+ search.set("path", normalizePagesResolvePath(params.path));
461
+ if (params.languageId != null && Number.isFinite(params.languageId) && params.languageId > 0) {
462
+ search.set("language_id", String(params.languageId));
463
+ }
464
+ if (params.preview) {
465
+ search.set("preview", "true");
466
+ }
467
+ return search.toString();
468
+ }
469
+ function buildPagesResolvePath(params) {
470
+ return `/pages/resolve?${buildPagesResolveQuery(params)}`;
471
+ }
472
+ function buildPagesResolveUrl(params) {
473
+ return `${API_VERSION_PREFIX}${buildPagesResolvePath(params)}`;
474
+ }
475
+
444
476
  // src/theme/tokens.ts
445
477
  var FONT_SIZE_PX = {
446
478
  xs: 12,
@@ -1604,6 +1636,118 @@ function serializeFieldsMapLabels(labels) {
1604
1636
  return JSON.stringify(clean);
1605
1637
  }
1606
1638
 
1639
+ // src/content/formRecordPrefill.ts
1640
+ var FORM_RECORD_PREFILL_SKIP_FIELDS = /* @__PURE__ */ new Set([
1641
+ "record_id",
1642
+ "entry_date",
1643
+ "id_users",
1644
+ "user_name",
1645
+ "user_code",
1646
+ "id_actionTriggerTypes",
1647
+ "triggerType",
1648
+ "id_languages",
1649
+ "language_locale",
1650
+ "language_name"
1651
+ ]);
1652
+ function isTranslatableChild(children, fieldName) {
1653
+ if (!Array.isArray(children)) {
1654
+ return false;
1655
+ }
1656
+ const child = children.find((item) => item?.name?.content === fieldName);
1657
+ return child?.translatable?.content === "1";
1658
+ }
1659
+ function asScalarString(value) {
1660
+ if (value === null || value === void 0) {
1661
+ return null;
1662
+ }
1663
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1664
+ return String(value);
1665
+ }
1666
+ return null;
1667
+ }
1668
+ function parseFormRecordPrefill(section) {
1669
+ const sectionDataArray = section?.section_data;
1670
+ if (!Array.isArray(sectionDataArray) || sectionDataArray.length === 0) {
1671
+ return { recordId: null, values: {} };
1672
+ }
1673
+ const recordGroups = {};
1674
+ for (const row of sectionDataArray) {
1675
+ if (!row || typeof row !== "object" || Array.isArray(row)) {
1676
+ continue;
1677
+ }
1678
+ const record = row;
1679
+ const rawRecordId = record.record_id;
1680
+ const recordId = typeof rawRecordId === "number" ? rawRecordId : typeof rawRecordId === "string" && rawRecordId.trim() !== "" && Number.isFinite(Number(rawRecordId)) ? Number(rawRecordId) : null;
1681
+ if (recordId === null) {
1682
+ continue;
1683
+ }
1684
+ if (!recordGroups[recordId]) {
1685
+ recordGroups[recordId] = {};
1686
+ }
1687
+ const languageId = typeof record.id_languages === "number" ? record.id_languages : typeof record.id_languages === "string" && Number.isFinite(Number(record.id_languages)) ? Number(record.id_languages) : void 0;
1688
+ for (const [fieldName, fieldValue] of Object.entries(record)) {
1689
+ if (FORM_RECORD_PREFILL_SKIP_FIELDS.has(fieldName)) {
1690
+ continue;
1691
+ }
1692
+ const value = asScalarString(fieldValue);
1693
+ if (value === null) {
1694
+ continue;
1695
+ }
1696
+ const translatable = isTranslatableChild(section.children, fieldName);
1697
+ if (translatable) {
1698
+ if (languageId === 1) {
1699
+ if (!recordGroups[recordId][fieldName]) {
1700
+ recordGroups[recordId][fieldName] = value;
1701
+ }
1702
+ } else if (typeof languageId === "number") {
1703
+ const current = recordGroups[recordId][fieldName];
1704
+ if (typeof current === "string" || !current) {
1705
+ recordGroups[recordId][fieldName] = [{ language_id: languageId, value }];
1706
+ } else {
1707
+ const langValues = current;
1708
+ const existingIndex = langValues.findIndex((v) => v.language_id === languageId);
1709
+ if (existingIndex >= 0) {
1710
+ langValues[existingIndex] = { language_id: languageId, value };
1711
+ } else {
1712
+ langValues.push({ language_id: languageId, value });
1713
+ }
1714
+ }
1715
+ }
1716
+ } else if (languageId === 1 || !recordGroups[recordId][fieldName]) {
1717
+ recordGroups[recordId][fieldName] = value;
1718
+ }
1719
+ }
1720
+ }
1721
+ const firstRecordId = Object.keys(recordGroups)[0];
1722
+ if (!firstRecordId) {
1723
+ return { recordId: null, values: {} };
1724
+ }
1725
+ const id = Number(firstRecordId);
1726
+ return { recordId: id, values: recordGroups[id] ?? {} };
1727
+ }
1728
+ function flattenFormRecordPrefillValues(values, languageId) {
1729
+ const out = {};
1730
+ for (const [key, value] of Object.entries(values)) {
1731
+ if (typeof value === "string") {
1732
+ out[key] = value;
1733
+ continue;
1734
+ }
1735
+ if (!Array.isArray(value) || value.length === 0) {
1736
+ continue;
1737
+ }
1738
+ if (languageId != null) {
1739
+ const match = value.find((entry) => entry.language_id === languageId);
1740
+ if (match) {
1741
+ out[key] = match.value;
1742
+ continue;
1743
+ }
1744
+ }
1745
+ const nonIndependent = value.find((entry) => entry.language_id !== 1);
1746
+ out[key] = (nonIndependent ?? value[0]).value;
1747
+ }
1748
+ return out;
1749
+ }
1750
+
1607
1751
  // src/navigation/headerPreset.ts
1608
1752
  var WEB_HEADER_PRESET_VALUES = [
1609
1753
  "simple",
@@ -2455,6 +2599,7 @@ export {
2455
2599
  ENDPOINTS,
2456
2600
  FIELDS_MAP_STYLE_CONFIG,
2457
2601
  FONT_SIZE_PX,
2602
+ FORM_RECORD_PREFILL_SKIP_FIELDS,
2458
2603
  FULL_RADIUS_PX,
2459
2604
  HEADER_CLIENT_TYPE,
2460
2605
  LINE_HEIGHT,
@@ -2486,6 +2631,9 @@ export {
2486
2631
  _resetPluginStyleRegistry,
2487
2632
  arePreviewPreferencesEqual,
2488
2633
  buildConditionContext,
2634
+ buildPagesResolvePath,
2635
+ buildPagesResolveQuery,
2636
+ buildPagesResolveUrl,
2489
2637
  buildPublicPathFromRoute,
2490
2638
  clampMenuItemsAtDepth,
2491
2639
  classifyClass,
@@ -2500,6 +2648,7 @@ export {
2500
2648
  findPageRefInNavigationPayload,
2501
2649
  findRemap,
2502
2650
  flattenFooterItems,
2651
+ flattenFormRecordPrefillValues,
2503
2652
  flattenMenuItems,
2504
2653
  flattenNavigationMenuItems,
2505
2654
  footerColumnItems,
@@ -2554,11 +2703,13 @@ export {
2554
2703
  matchesMobilePath,
2555
2704
  matchesWebPath,
2556
2705
  mergeHeaderLayers,
2706
+ normalizePagesResolvePath,
2557
2707
  pageUrlToMobileRoute,
2558
2708
  parseDimensionToReactNative,
2559
2709
  parseDimensionToWeb,
2560
2710
  parseFieldsMapCatalog,
2561
2711
  parseFieldsMapLabels,
2712
+ parseFormRecordPrefill,
2562
2713
  parseInlineRich,
2563
2714
  parseOptionCatalog,
2564
2715
  parseOptionCodes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@selfhelp/shared",
3
- "version": "1.21.5",
3
+ "version": "1.21.7",
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",
@@ -5,6 +5,12 @@
5
5
 
6
6
  import { describe, expect, it } from 'vitest';
7
7
  import { API_VERSION_PREFIX, ENDPOINTS } from '../endpoints';
8
+ import {
9
+ buildPagesResolvePath,
10
+ buildPagesResolveQuery,
11
+ buildPagesResolveUrl,
12
+ normalizePagesResolvePath,
13
+ } from '../pagesResolve';
8
14
  import type {
9
15
  IForgotPasswordRequest,
10
16
  IResetPasswordRequest,
@@ -45,24 +51,43 @@ describe('ENDPOINTS.AUTH password recovery', () => {
45
51
  });
46
52
 
47
53
  /**
48
- * Contract coverage for the DB-driven public path resolver (issue #30). The web
49
- * frontend SSR layer and the mobile app both build the resolve request from
50
- * `ENDPOINTS.PAGES.RESOLVE`, so a wrong/missing path silently breaks every
51
- * parameterized public URL (`/reset/{user_id}/{token}`, `/team/{record_id}`).
54
+ * Canonical resolve contract: SSR, browser, and mobile must produce the same
55
+ * query encoding for path / language_id / preview.
52
56
  */
53
- describe('ENDPOINTS.PAGES.RESOLVE (DB-driven routing)', () => {
54
- it('builds the resolve endpoint with the path as a URL-encoded query param', () => {
55
- expect(ENDPOINTS.PAGES.RESOLVE('/team/7')).toBe(
57
+ describe('buildPagesResolve* (DB-driven routing)', () => {
58
+ it('exposes the static resolve route constant', () => {
59
+ expect(ENDPOINTS.PAGES.RESOLVE_ROUTE).toBe(`${API_VERSION_PREFIX}/pages/resolve`);
60
+ });
61
+
62
+ it('normalizes paths before encoding', () => {
63
+ expect(normalizePagesResolvePath('/team/7/')).toBe('/team/7');
64
+ expect(normalizePagesResolvePath('team/7')).toBe('/team/7');
65
+ expect(normalizePagesResolvePath('/')).toBe('/');
66
+ expect(normalizePagesResolvePath('/reset/42/abc?x=1#y')).toBe('/reset/42/abc');
67
+ });
68
+
69
+ it('builds identical BFF and full URLs for path-only resolve', () => {
70
+ const params = { path: '/team/7' };
71
+ expect(buildPagesResolveQuery(params)).toBe('path=%2Fteam%2F7');
72
+ expect(buildPagesResolvePath(params)).toBe('/pages/resolve?path=%2Fteam%2F7');
73
+ expect(buildPagesResolveUrl(params)).toBe(
56
74
  `${API_VERSION_PREFIX}/pages/resolve?path=%2Fteam%2F7`,
57
75
  );
58
76
  });
59
77
 
60
- it('encodes reset/validate token paths so slashes survive transport', () => {
61
- expect(ENDPOINTS.PAGES.RESOLVE('/reset/42/abc.def~1')).toBe(
62
- `${API_VERSION_PREFIX}/pages/resolve?path=%2Freset%2F42%2Fabc.def~1`,
78
+ it('includes language_id and preview=true when requested', () => {
79
+ const params = { path: '/reset/42/abc.def~1', languageId: 2, preview: true };
80
+ expect(buildPagesResolveQuery(params)).toBe(
81
+ 'path=%2Freset%2F42%2Fabc.def%7E1&language_id=2&preview=true',
63
82
  );
64
- expect(ENDPOINTS.PAGES.RESOLVE('/')).toBe(
65
- `${API_VERSION_PREFIX}/pages/resolve?path=%2F`,
83
+ expect(buildPagesResolveUrl(params)).toBe(
84
+ `${API_VERSION_PREFIX}/pages/resolve?path=%2Freset%2F42%2Fabc.def%7E1&language_id=2&preview=true`,
66
85
  );
67
86
  });
87
+
88
+ it('omits language_id when absent or non-positive', () => {
89
+ expect(buildPagesResolveQuery({ path: '/', languageId: null })).toBe('path=%2F');
90
+ expect(buildPagesResolveQuery({ path: '/', languageId: 0 })).toBe('path=%2F');
91
+ expect(buildPagesResolveQuery({ path: '/', preview: false })).toBe('path=%2F');
92
+ });
68
93
  });
@@ -41,12 +41,12 @@ export const ENDPOINTS = {
41
41
  `${API_VERSION_PREFIX}/pages/by-keyword/${encodeURIComponent(keyword)}`,
42
42
  BY_ID: (pageId: number): string => `${API_VERSION_PREFIX}/pages/${pageId}`,
43
43
  /**
44
- * DB-driven public path resolution (issue #30): maps a full public URL
45
- * path (e.g. `/reset/42/abc`, `/team/7`) to a page payload + route
46
- * params. `path` is sent URL-encoded as a query parameter.
44
+ * Static resolve route (no query). Always pair with
45
+ * {@link buildPagesResolveUrl} / {@link buildPagesResolvePath} so
46
+ * `path`, `language_id`, and `preview` are encoded identically across
47
+ * SSR, browser, and mobile.
47
48
  */
48
- RESOLVE: (path: string): string =>
49
- `${API_VERSION_PREFIX}/pages/resolve?path=${encodeURIComponent(path)}`,
49
+ RESOLVE_ROUTE: `${API_VERSION_PREFIX}/pages/resolve`,
50
50
  },
51
51
  NAVIGATION: {
52
52
  GET: `${API_VERSION_PREFIX}/navigation`,
package/src/api/index.ts CHANGED
@@ -3,3 +3,4 @@ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
3
  SPDX-License-Identifier: MPL-2.0
4
4
  */
5
5
  export * from './endpoints';
6
+ export * from './pagesResolve';
@@ -0,0 +1,78 @@
1
+ /*
2
+ * SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ /**
7
+ * Canonical public page resolve contract (issue #30).
8
+ *
9
+ * Frontend SSR, frontend browser client, and mobile MUST build resolve
10
+ * requests through these helpers so path / language_id / preview encoding
11
+ * cannot drift between clients.
12
+ */
13
+
14
+ import { API_VERSION_PREFIX } from './endpoints';
15
+
16
+ /** Inputs accepted by `GET /pages/resolve`. */
17
+ export interface IPagesResolveParams {
18
+ /** Public URL path, e.g. `/team/7`, `/reset/42/abc`, `/`. */
19
+ path: string;
20
+ /** Optional language id query param. */
21
+ languageId?: number | null;
22
+ /**
23
+ * When true, request unpublished draft content. Backend requires an
24
+ * authenticated caller (`preview=true`).
25
+ */
26
+ preview?: boolean;
27
+ }
28
+
29
+ /**
30
+ * Normalize a public path for the resolve query: strip origin fragments /
31
+ * search, ensure a leading slash, collapse a trailing slash (except root).
32
+ */
33
+ export function normalizePagesResolvePath(rawPath: string): string {
34
+ const withoutOrigin = rawPath.includes('://')
35
+ ? (() => {
36
+ try {
37
+ return new URL(rawPath).pathname;
38
+ } catch {
39
+ return rawPath;
40
+ }
41
+ })()
42
+ : rawPath;
43
+ const pathOnly = withoutOrigin.split('#')[0].split('?')[0];
44
+ const withSlash = pathOnly.startsWith('/') ? pathOnly : `/${pathOnly}`;
45
+ return withSlash.replace(/\/+$/, '') || '/';
46
+ }
47
+
48
+ /**
49
+ * Build the query string for `/pages/resolve` (no leading `?`).
50
+ * Always includes `path`; optionally `language_id` and `preview=true`.
51
+ */
52
+ export function buildPagesResolveQuery(params: IPagesResolveParams): string {
53
+ const search = new URLSearchParams();
54
+ search.set('path', normalizePagesResolvePath(params.path));
55
+ if (params.languageId != null && Number.isFinite(params.languageId) && params.languageId > 0) {
56
+ search.set('language_id', String(params.languageId));
57
+ }
58
+ if (params.preview) {
59
+ search.set('preview', 'true');
60
+ }
61
+ return search.toString();
62
+ }
63
+
64
+ /**
65
+ * BFF-relative resolve path used by the Next.js frontend
66
+ * (`/pages/resolve?path=…`).
67
+ */
68
+ export function buildPagesResolvePath(params: IPagesResolveParams): string {
69
+ return `/pages/resolve?${buildPagesResolveQuery(params)}`;
70
+ }
71
+
72
+ /**
73
+ * Full Symfony path including `/cms-api/v1` — used by mobile and any
74
+ * direct-to-backend client.
75
+ */
76
+ export function buildPagesResolveUrl(params: IPagesResolveParams): string {
77
+ return `${API_VERSION_PREFIX}${buildPagesResolvePath(params)}`;
78
+ }