@selfhelp/shared 1.27.0 → 1.29.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/dist/index.d.ts CHANGED
@@ -7,6 +7,119 @@ export { COLOR_PALETTE, COLOR_SCALES, CONTAINER_SIZE_PX, FONT_SIZE_PX, FULL_RADI
7
7
  export { TAnyStyleName, TPluginStyleImplMap, TStyleImplMap, getRegistryEntry, getRegistryEntryAny, getStylePlacement, getStylePlatforms, getStylePluginId, isKnownStyleName, isRegisteredStyleName, isStyleAllowedOnPage, isStylePlacementAllowed, isStyleSupportedOnPlatform, setToStylePlatform, stylePlatformToSet } from './registry/index.js';
8
8
  export { sharedTailwindExtend, sharedTailwindPreset } from './theme/tailwind.js';
9
9
 
10
+ /**
11
+ * Live-sync contract (task `2026-11-20-live-sync-and-edit-lock`, contracts C1 to C9).
12
+ *
13
+ * The backend publishes a `changed` Mercure event that carries names and ids
14
+ * only, never content. Clients match the tags against the `sync.depends_on`
15
+ * list the server put into each page payload and refetch what matches. The
16
+ * server decides who gets a message; a client never decides who may see a
17
+ * change.
18
+ */
19
+ /** Mercure event name of a change message (C1). */
20
+ declare const SYNC_EVENT_NAME: "changed";
21
+ /** Highest change-message version this package understands (C1). Clients ignore a higher `v`. */
22
+ declare const SYNC_MESSAGE_VERSION: 1;
23
+ /**
24
+ * Tags a change message may carry (C1). A client ignores tags it does not know.
25
+ *
26
+ * | Tag | Meaning |
27
+ * | --- | --- |
28
+ * | `acl` | Access of this audience changed (re-bootstrap the stream, refetch user data) |
29
+ * | `navigation` | A menu or the visible page set changed |
30
+ * | `global_values` | Global values changed |
31
+ * | `page:<id>` | The published page changed |
32
+ * | `page_draft:<id>` | The draft of the page changed (editors) |
33
+ * | `page_lock:<id>` | The edit lock of the page changed (editors) |
34
+ * | `table:<id>` | A record of the data table changed |
35
+ * | `section:<id>` | A section was saved in the admin |
36
+ * | `asset:<id>` | An asset changed |
37
+ */
38
+ type TSyncTag = 'acl' | 'navigation' | 'global_values' | `page:${number}` | `page_draft:${number}` | `page_lock:${number}` | `table:${number}` | `section:${number}` | `asset:${number}`;
39
+ /** Mirror of the backend tag pattern (C1). Anchored, so the whole tag must match. */
40
+ declare const SYNC_TAG_PATTERN: RegExp;
41
+ /** Data of one `changed` event (C1). */
42
+ interface ISyncChangeMessage {
43
+ /** Message version. Always 1 for this package. */
44
+ v: typeof SYNC_MESSAGE_VERSION;
45
+ /** Unique, non-empty list of known tags. */
46
+ tags: TSyncTag[];
47
+ }
48
+ /**
49
+ * The `sync` block of every page payload, published and draft (C6).
50
+ *
51
+ * `depends_on` lists `page:<id>` (`page_draft:<id>` for a draft), `table:<id>`
52
+ * for every data table the page reads, and `global_values`. `valid_until` is
53
+ * the earliest moment (UTC, ISO 8601) the result can change because time
54
+ * passes, or `null`. The client refetches once at `valid_until` plus a random
55
+ * delay while the page is open.
56
+ */
57
+ interface ISyncBlock {
58
+ depends_on: string[];
59
+ valid_until: string | null;
60
+ }
61
+ /**
62
+ * Data of `GET /auth/events` (C4). For a guest `topic`, `impersonationTopic`
63
+ * and `systemUpdateTopic` are `null` and `syncTopics` is the public topic only.
64
+ * The token covers exactly the listed topics (plus plugin topics).
65
+ */
66
+ interface IAuthEventsBootstrap {
67
+ hubUrl: string;
68
+ topic: string | null;
69
+ impersonationTopic: string | null;
70
+ systemUpdateTopic: string | null;
71
+ /** Sync topics to subscribe to: `[user, each group, each role, public]`, or `[public]` for a guest. */
72
+ syncTopics: string[];
73
+ pluginTopics: string[];
74
+ /** `null` when `transport=cookie` was requested. */
75
+ token: string | null;
76
+ expiresIn: number;
77
+ }
78
+ /** Error codes of the page draft version and lock checks (C8, C9). */
79
+ declare const PAGE_VERSION_REQUIRED_ERROR: "page_version_required";
80
+ declare const STALE_PAGE_VERSION_ERROR: "stale_page_version";
81
+ declare const PAGE_LOCKED_ERROR: "page_locked";
82
+ /**
83
+ * `409` when the caller's own page edit lock ended by idle expiry and they try
84
+ * to renew (`POST .../lock`). Data is {@link IPageLockStatus}. Resume through
85
+ * take-over (`POST .../lock/take-over`), not a plain acquire.
86
+ */
87
+ declare const LOCK_IDLE_ENDED_ERROR: "lock_idle_ended";
88
+ /**
89
+ * Draft version of a page (C8). `GET /admin/pages/{page_id}` returns it in its
90
+ * data (and in the `X-Page-Version` header); admin page types extend this so
91
+ * the editor can send it back with every draft write.
92
+ */
93
+ interface IPageDraftVersioned {
94
+ /** Integer from 1; raised by one on every successful draft write. */
95
+ draft_version: number;
96
+ }
97
+ /** Data of `409 stale_page_version` (C8). */
98
+ interface IStalePageVersionData {
99
+ page_id: number;
100
+ current_version: number;
101
+ }
102
+ /** Holder of a page edit lock (C9). */
103
+ interface IPageLockHolder {
104
+ id: number;
105
+ name: string;
106
+ }
107
+ /**
108
+ * Status of a page edit lock (C9). Per caller (`mine`) and never cached.
109
+ * `holder`, `expires_at` and `idle_expires_at` are `null` when `held` is false.
110
+ * The data of `409 page_locked` is this object.
111
+ */
112
+ interface IPageLockStatus {
113
+ page_id: number;
114
+ held: boolean;
115
+ mine: boolean;
116
+ holder: IPageLockHolder | null;
117
+ /** The lease ends here unless renewed (120 s after the last renewal). */
118
+ expires_at: string | null;
119
+ /** The lock ends here unless the holder writes (15 minutes after the last draft write). */
120
+ idle_expires_at: string | null;
121
+ }
122
+
10
123
  /**
11
124
  * Comprehensive page type system, single source of truth for both apps.
12
125
  */
@@ -124,6 +237,13 @@ interface IPageContent {
124
237
  matched_url_pattern?: string | null;
125
238
  /** The canonical active route pattern for the page, for canonical-link generation. Resolve responses only. */
126
239
  canonical_url?: string | null;
240
+ /**
241
+ * Live-sync block (C6): the tags this payload depends on and the moment it
242
+ * can change because time passes. Emitted by the backend on published and
243
+ * draft page payloads; optional here because the type is also used for
244
+ * payloads built elsewhere (preview, admin).
245
+ */
246
+ sync?: ISyncBlock;
127
247
  sections: IPageSectionWithFields[];
128
248
  }
129
249
  /**
@@ -195,6 +315,12 @@ interface IUserData {
195
315
  roles?: string[];
196
316
  groups?: string[];
197
317
  acl_version?: string | number | null;
318
+ /**
319
+ * Access stamp (live sync, C5): the same value the backend sends in the
320
+ * `X-Acl-Stamp` header of every response to this user. A client that sees
321
+ * a header value different from this one invalidates its user data.
322
+ */
323
+ acl_stamp?: string;
198
324
  }
199
325
  interface IJwtPayload {
200
326
  sub: number;
@@ -386,6 +512,8 @@ type ILanguagesResponse = IBaseApiResponse<ILanguageItem[]>;
386
512
 
387
513
  type IGetPageResponse = IBaseApiResponse<{
388
514
  page: IPageContent;
515
+ /** Live-sync block next to the page (contract C6); optional on older servers. */
516
+ sync?: ISyncBlock | null;
389
517
  }>;
390
518
  type IGetPagesResponse = IBaseApiResponse<IPageItem[]>;
391
519
  /**
@@ -395,6 +523,8 @@ type IGetPagesResponse = IBaseApiResponse<IPageItem[]>;
395
523
  */
396
524
  type IResolvePageResponse = IBaseApiResponse<{
397
525
  page: IPageContent;
526
+ /** Live-sync block next to the page (contract C6); optional on older servers. */
527
+ sync?: ISyncBlock | null;
398
528
  }>;
399
529
 
400
530
  /**
@@ -1803,7 +1933,23 @@ declare const ENDPOINTS: {
1803
1933
  readonly RESTORE: (tableName: string, recordId: number) => string;
1804
1934
  readonly VERSION_FILE: (tableName: string, recordId: number, version: number, fieldKey: string) => string;
1805
1935
  };
1936
+ /**
1937
+ * Page edit lock (live sync, C9). Route permission `admin.page.update` plus
1938
+ * the update grant on the page. `LOCK` serves three methods: GET (status),
1939
+ * POST (acquire or renew) and DELETE (release); `TAKE_OVER` is POST only.
1940
+ * Every route answers an `IPageLockStatus`.
1941
+ */
1942
+ readonly ADMIN_PAGE_LOCK: {
1943
+ readonly LOCK: (pageId: number) => string;
1944
+ readonly TAKE_OVER: (pageId: number) => string;
1945
+ };
1806
1946
  };
1947
+ /** Header on every response to a signed-in caller: the access stamp (live sync, C5). */
1948
+ declare const HEADER_ACL_STAMP = "X-Acl-Stamp";
1949
+ /** Request header `X-Page-View: 1`: the only page fetch per visit that counts as a view (C7, F135). */
1950
+ declare const HEADER_PAGE_VIEW = "X-Page-View";
1951
+ /** Draft-version header: sent with every page draft write, returned on page reads and writes (C8). */
1952
+ declare const HEADER_PAGE_VERSION = "X-Page-Version";
1807
1953
  /** Header set the backend reads to switch page-access mode + condition platform var. */
1808
1954
  declare const HEADER_CLIENT_TYPE = "X-Client-Type";
1809
1955
  declare const CLIENT_TYPE_WEB = "web";
@@ -2973,6 +3119,78 @@ declare function isMenuItemActiveOnMobile(item: INavigationMenuItem, pathname: s
2973
3119
  */
2974
3120
  declare function expandedIdsForActiveTrail(items: INavigationMenuItem[], pathname: string, platform: 'web' | 'mobile'): Set<number>;
2975
3121
 
3122
+ /**
3123
+ * Small, pure helpers both clients use to read a change message and match it
3124
+ * to what is on screen (contracts C1 and C6). They hold no state, touch no
3125
+ * network and never decide access: they only compare tags the server sent
3126
+ * with tags the server put into the page payload.
3127
+ */
3128
+
3129
+ /** Largest random delay before a refetch caused by a `changed` message (decision "instant"). */
3130
+ declare const SYNC_CHANGED_MAX_DELAY_MS = 300;
3131
+ /** Largest random delay before the one refetch at a page's `valid_until`. */
3132
+ declare const SYNC_VALID_UNTIL_MAX_DELAY_MS = 2000;
3133
+ /** Why a refetch is scheduled: a pushed change, or the page's own `valid_until`. */
3134
+ type TSyncRefetchKind = 'changed' | 'valid_until';
3135
+ /**
3136
+ * Validates the data of a `changed` event (C1).
3137
+ *
3138
+ * Returns `null` when the data is not an object, `v` is not
3139
+ * {@link SYNC_MESSAGE_VERSION} (a higher version is ignored by design), `tags`
3140
+ * is not a list, or no known tag is left. Unknown tags are dropped and
3141
+ * duplicates are removed, so `{ v: 1, tags: ['page:12', 'foo:1'] }` gives
3142
+ * `{ v: 1, tags: ['page:12'] }`. A message that carries only unknown tags
3143
+ * returns `null` because there is nothing a client could act on.
3144
+ */
3145
+ declare function parseSyncMessage(data: unknown): ISyncChangeMessage | null;
3146
+ /**
3147
+ * Same as {@link parseSyncMessage} for the raw `data` string of a server-sent
3148
+ * event. Invalid JSON returns `null`.
3149
+ */
3150
+ declare function parseSyncMessageJson(raw: string): ISyncChangeMessage | null;
3151
+ /**
3152
+ * True when a page payload's `sync.depends_on` names any of the message's tags (C6).
3153
+ *
3154
+ * Only tags that a page payload can list match here: `page:<id>`,
3155
+ * `page_draft:<id>`, `table:<id>` and `global_values`. The other tags are not
3156
+ * page dependencies and are handled by the client on their own:
3157
+ *
3158
+ * - `acl` and `navigation` affect every page the caller may see, so the client
3159
+ * invalidates all page queries and the navigation (it does not ask each page).
3160
+ * - `page_lock:<id>`, `section:<id>` and `asset:<id>` are editor-side tags;
3161
+ * the admin screens that show them refetch their own queries.
3162
+ *
3163
+ * A page without a `sync` block (older server, error payload) never matches.
3164
+ */
3165
+ declare function pageDependsOn(sync: ISyncBlock | null | undefined, tags: readonly string[]): boolean;
3166
+ /**
3167
+ * Random delay in milliseconds before a refetch: 0 to 300 for a `changed`
3168
+ * message, 0 to 2000 for `valid_until`. It spreads many clients over a short
3169
+ * time without making a change feel slow. `random` is injectable for tests.
3170
+ */
3171
+ declare function syncRefetchDelayMs(kind: TSyncRefetchKind, random?: () => number): number;
3172
+
3173
+ /**
3174
+ * Unwrap a page API response so the live-sync block travels with the page.
3175
+ *
3176
+ * The backend answers `{ data: { page, sync } }`: the sync block (contract C6)
3177
+ * sits next to the page, not inside it. Clients that cache the page read
3178
+ * `page.sync` for tag matching and `valid_until`, so every unwrap goes through
3179
+ * {@link pageFromPayload}.
3180
+ */
3181
+
3182
+ /** The `data` of a page response (`/pages/by-keyword`, `/pages/resolve`). */
3183
+ interface IPagePayload {
3184
+ page?: IPageContent | null;
3185
+ sync?: ISyncBlock | null;
3186
+ }
3187
+ /**
3188
+ * The page of a response's `data`, carrying the response's `sync` block.
3189
+ * Prefers `payload.sync`, falls back to `page.sync`. Returns `null` when there
3190
+ * is no page. With no sync at all, returns the page unchanged.
3191
+ */
3192
+ declare function pageFromPayload(payload: IPagePayload | null | undefined): IPageContent | null;
3193
+
2976
3194
  /**
2977
3195
  * Parse the unified `spacing` field. The CMS
2978
3196
  * stores this as a JSON string with optional keys for each side:
@@ -3034,4 +3252,4 @@ declare function transformPageData(apiPage: IRawPage): IPageItem;
3034
3252
  */
3035
3253
  declare function transformPagesData(pages: IRawPage[] | null | undefined): IPageItem[];
3036
3254
 
3037
- export { API_VERSION_PREFIX, type AdvisoryAffected, type AdvisoryFeed, type AdvisorySeverity, type BackupManifest, type BackupRetentionPolicy, type BackupSchedulePolicy, type BundledPluginRef, CLASS_PATTERNS, CLASS_REMAP, CLIENT_TYPE_MOBILE, CLIENT_TYPE_MOBILE_AND_WEB, CLIENT_TYPE_WEB, CMS_APP_PRIMARY_ROLES, CMS_APP_ROLES, COLOR_NAMES, type CheckSeverity, type CompatibilityRules, type CoreRelease, DEFAULT_MOBILE_ICON, DEFAULT_RATE_LIMIT_MESSAGE, DEFAULT_WEB_FOOTER_PRESET, DEFAULT_WEB_HEADER_PRESET, type DatabaseMigrationMetadata, ENDPOINTS, FIELDS_MAP_STYLE_CONFIG, FORM_LIST_MAX_PAGE, FORM_LIST_MAX_ROUTE_PARAMS, FORM_LIST_MAX_ROUTE_VALUE_LENGTH, FORM_LIST_MAX_SORTS, FORM_LIST_MAX_VALUE_BYTES, FORM_LIST_MODES, FORM_LIST_SEARCH_MAX_LENGTH, FORM_LIST_SEARCH_MIN_LENGTH, FORM_RECORD_PREFILL_SKIP_FIELDS, type FrontendRelease, HEADER_CLIENT_TYPE, IAboutItem, type IAssetSource, IBaseApiResponse, type IBasePageInfo, type IBasePageSection, type IBranchNavContext, type IBranchNavSegment, type IBreadcrumbEntry, type IClassPattern, type IClassRemap, type ICmsApp, type ICmsAppAssignedPage, type ICmsAppDetail, type ICmsAppPage, type ICmsAppSummary, type ICompatibilityError, type IConditionContext, IContentField, type IEvaluatedCondition, type IFieldsMapStyleConfig, type IForgotPasswordRequest, type IForgotPasswordResponse, IFormInvalidData, type IFormListCacheScope, type IFormListFailure, IFormListFilesCell, IFormListRestoreBlockedData, IFormListSort, type IFormListUrlError, type IFormListUrlRules, type IFormListUrlState, type IFormRecordPrefill, type IFormRecordPrefillChild, type IFormRecordPrefillSection, type IFormRecordPrefillTranslatedValue, IFormStaleVersionData, type IFrontendUpdatePreflight, type IFrontendUpdatePreflightResponse, type IFrontendUpdateReleases, type IFrontendUpdateReleasesResponse, type IFrontendUpdateRequest, type IFrontendUpdateRequestResponse, type IGetPageResponse, type IGetPagesResponse, type IHeaderLayerSplit, type IInlineNode, type IJwtPayload, type ILanguage, type ILanguageItem, type ILanguagePreference, type ILanguagePreferenceUpdateResponse, type ILanguagesResponse, type ILoginRequest, type ILoginSuccessData, type ILoginSuccessResponse, type ILogoutSuccessResponse, type IMaintenanceSetRequest, type IMenuSearchHit, type IMobileAdapterBaseProps, type IMobileButtonProps, type IMobileCardProps, type IMobileCheckboxProps, type IMobileContainerProps, type IMobileIconEntry, type IMobileInputProps, type IMobileModalProps, type IMobilePreviewExchangeData, type IMobilePreviewExchangeRequest, type IMobilePreviewExchangeResponse, type IMobilePreviewSessionData, type IMobilePreviewSessionRequest, type IMobilePreviewSessionResponse, type IMobilePreviewUpdatePreflight, type IMobilePreviewUpdatePreflightResponse, type IMobilePreviewUpdateReleases, type IMobilePreviewUpdateReleasesResponse, type IMobilePreviewUpdateRequest, type IMobilePreviewUpdateRequestResponse, type IMobileSelectOption, type IMobileSelectProps, type IMobileSwitchProps, type IMobileTextProps, type IMobileTextareaProps, type IMobileUiAdapters, type INavigationBranding, type INavigationBundle, type INavigationBundleImportHints, type INavigationBundleItem, type INavigationBundleItemTranslation, type INavigationBundleMenu, type INavigationMenu, type INavigationMenuItem, type INavigationPayload, type INavigationResolvedPageRef, type INavigationSearchConfig, type INavigationStartupConfig, type IOptionCatalogEntry, type IOptionLabelMap, type IOptionStyleConfig, type IPageAccessTypeInfo, type IPageContent, type IPageField, type IPageFieldTranslation, type IPageFieldsData, type IPageItem, type IPageRoute, type IPageSectionWithFields, type IPageSectionsData, type IPagesResolveParams, type IPreviewNavigateCommand, type IPreviewNavigatedMessage, type IPreviewPreferences, type IPreviewPreferencesChangedMessage, type IPreviewReadyMessage, type IPreviewSetPreferencesCommand, type IRefreshRequest, type IRefreshSuccessResponse, type IResetPasswordRequest, type IResetPasswordResponse, type IResolvePageResponse, type IResolvedOption, type ISpacingValue, type ISystemAdvisories, type ISystemAdvisoriesResponse, type ISystemAdvisory, type ISystemAdvisoryAffected, type ISystemHealth, type ISystemHealthComponent, type ISystemHealthResponse, type ISystemInstalledPlugin, type ISystemMaintenance, type ISystemMaintenanceResponse, type ISystemVersion, type ISystemVersionResponse, type ITwoFactorRequiredData, type ITwoFactorRequiredResponse, type ITwoFactorVerifyRequest, type ITwoFactorVerifySuccessResponse, type IUpdatePreflight, type IUpdatePreflightCheck, type IUpdatePreflightOption, type IUpdatePreflightResponse, type IUpdateRelease, type IUpdateReleases, type IUpdateReleasesResponse, type IUpdateRequest, type IUpdateRequestResponse, type IUpdateStatus, type IUpdateStatusManager, type IUpdateStatusResponse, type IUpdateStep, type IUserData, type IUserDataResponse, type IWebFooterPresetOption, type IWebHeaderPresetOption, type ImageRef, type InstalledPlugin, type InstanceImages, type InstanceLock, type InstanceManifest, type InstanceMode, type InstanceResourceConfig, type InstanceRouting, type InstanceStatus, type InstanceVersions, type InventoryInstanceEntry, LITERAL_CLASSES, type LockPluginEntry, type LockServiceEntry, MOBILE_ICON_NAMES, MOBILE_ICON_SET, MOBILE_PREVIEW_ENDPOINTS, type MobilePreviewRelease, NAVIGATION_BRANDING_LOGO_HEIGHTS, NAVIGATION_BUNDLE_FORMAT, NAVIGATION_BUNDLE_VERSION, NAVIGATION_HEADER_LAYER_TOP, OPTION_STYLE_CONFIGS, PERMISSIONS, PREVIEW_BRIDGE_MESSAGE, PREVIEW_PARENT_ORIGIN_PARAM, PREVIEW_SHELL_PARAM, type PluginRelease, type PreflightCheck, type PreflightOption, type PreflightStatus, RELEASE_CHANNELS, type RegistryIndex, type RegistryReleaseRef, type ReleaseChannel, type RuntimeServicePolicy, type RuntimeServiceRange, SIZE_VALUES, SPACING_VALUES, SYSTEM_ENDPOINTS, type SchedulerRelease, type SecurityAdvisory, type ServerInventory, type ServiceBackendCompatibility, type SignatureBlock, type SupportBundleMeta, type TCalcedValues, type TClassDecision, type TClientType, type TCmsAppRole, TFormListMode, type TFormListUrlChange, type TFormListUrlErrorReason, type TFormListUrlParse, type TFormRecordPrefillFieldValue, type TFormRecordPrefillFileValue, THeroUiButtonVariant, THeroUiSize, TMobileButtonFeedback, TMobileFieldVariant, type TMobilePagePresentation, TMobileSelectPresentation, type TNavigationBrandingSize, type TNavigationBrandingVariant, type TNavigationBundleExportMode, type TNavigationChildrenNavMode, type TNavigationHeaderLayer, type TNavigationMenuItemType, type TNavigationMenuKey, type TNavigationMobileStartSource, type TNavigationSearchMode, type TNavigationStartMode, type TOptionStyleName, type TPermission, type TPlatform, type TPreviewBridgeMessage, type TPreviewBridgeMessageType, type TPreviewColorScheme, type TPreviewFrameSource, TStyleName, type TSystemAdvisorySeverity, type TSystemComponentStatus, type TSystemDeployment, type TSystemHealthOverall, type TUpdateCheckSeverity, type TUpdateKind, type TUpdateOperationStatus, type TUpdatePreflightStatus, type TWebFooterPreset, type TWebHeaderPreset, type TrustLevel, type TrustedKey, type TrustedKeysFile, type UpdatePreflightResult, WEB_FOOTER_PRESET_OPTIONS, WEB_FOOTER_PRESET_VALUES, WEB_HEADER_PRESET_OPTIONS, WEB_HEADER_PRESET_VALUES, type WorkerRelease, applyFormListUrlChange, arePreviewPreferencesEqual, asFilesCell, asRecordVersion, buildConditionContext, buildPagesResolvePath, buildPagesResolveQuery, buildPagesResolveUrl, buildPublicPathFromRoute, clampMenuItemsAtDepth, classifyClass, classifyClassString, collectPageIdsFromMenuItems, emptyFormListUrlState, encodeFormListQuery, evaluateCondition, expandedIdsForActiveTrail, findMenuItemByPageId, findNearestBottomTabMenuItemForPage, findPageRefInNavigationPayload, findRemap, flattenFooterItems, flattenFormRecordPrefillValues, flattenMenuItems, flattenNavigationMenuItems, footerColumnItems, footerGroupLinks, footerStandaloneItems, formListCacheKey, formListQueryString, formListRouteQuery, formatRateLimitMessage, getFormInvalidData, getFormListFailure, getFormListRestoreBlocked, getFormStaleVersion, getNavigationItemAriaLabel, getNavigationItemHref, getNavigationItemKeyword, getNavigationItemLabel, getNavigationItemMobileHref, getRateLimitRetryAfter, hasInlineFormatting, isBottomTabMenuItemActive, isDoubleWebHeaderPreset, isFormListParam, isMenuItemActiveOnMobile, isMenuItemActiveOnWeb, isMobileIconName, isNavigationBundleVersionSupported, isOnAnyMobileMenu, isOnAnyMobileMenuFromPayload, isPageInMenuTree, isPageInResolvedMenus, isPageOnAnyMenu, isPageOnMobileMenu, isPageOnWebMenu, isPreviewBridgeMessage, isWebFooterPreset, isWebHeaderPreset, matchesMobilePath, matchesWebPath, mergeHeaderLayers, nextSortOnHeaderClick, normalizePagesResolvePath, pageUrlToMobileRoute, parseFieldsMapCatalog, parseFieldsMapLabels, parseFormListQuery, parseFormRecordPrefill, parseInlineRich, parseOptionCatalog, parseOptionCodes, parseOptionLabels, parseSpacing, pickFormListQuery, previewKeywordFromPath, replaceCalcedValues, resolveAssetSources, resolveAssetUrl, resolveBranchNavGroup, resolveBrandingPresentation, resolveFieldsMapLabel, resolveHolderRedirectPath, resolveMenuMaxDepth, resolveMobileIcon, resolveMobilePagePresentation, resolveMobileSegmentGroup, resolveMobileStartupKeyword, resolveMobileStartupRoute, resolveOptionCodesLabels, resolveOptionLabel, resolveOptionValueLabels, resolveOptions, resolveWebBranchNavContext, resolveWebBranchNavGroup, resolveWebFooterPreset, resolveWebHeaderPreset, resolveWebStartupPath, searchMenuPagesInPayload, serializeFieldsMapCatalog, serializeFieldsMapLabels, spacingToClasses, splitHeaderLayers, stripHtmlToText, transformPageData, transformPagesData };
3255
+ export { API_VERSION_PREFIX, type AdvisoryAffected, type AdvisoryFeed, type AdvisorySeverity, type BackupManifest, type BackupRetentionPolicy, type BackupSchedulePolicy, type BundledPluginRef, CLASS_PATTERNS, CLASS_REMAP, CLIENT_TYPE_MOBILE, CLIENT_TYPE_MOBILE_AND_WEB, CLIENT_TYPE_WEB, CMS_APP_PRIMARY_ROLES, CMS_APP_ROLES, COLOR_NAMES, type CheckSeverity, type CompatibilityRules, type CoreRelease, DEFAULT_MOBILE_ICON, DEFAULT_RATE_LIMIT_MESSAGE, DEFAULT_WEB_FOOTER_PRESET, DEFAULT_WEB_HEADER_PRESET, type DatabaseMigrationMetadata, ENDPOINTS, FIELDS_MAP_STYLE_CONFIG, FORM_LIST_MAX_PAGE, FORM_LIST_MAX_ROUTE_PARAMS, FORM_LIST_MAX_ROUTE_VALUE_LENGTH, FORM_LIST_MAX_SORTS, FORM_LIST_MAX_VALUE_BYTES, FORM_LIST_MODES, FORM_LIST_SEARCH_MAX_LENGTH, FORM_LIST_SEARCH_MIN_LENGTH, FORM_RECORD_PREFILL_SKIP_FIELDS, type FrontendRelease, HEADER_ACL_STAMP, HEADER_CLIENT_TYPE, HEADER_PAGE_VERSION, HEADER_PAGE_VIEW, IAboutItem, type IAssetSource, type IAuthEventsBootstrap, IBaseApiResponse, type IBasePageInfo, type IBasePageSection, type IBranchNavContext, type IBranchNavSegment, type IBreadcrumbEntry, type IClassPattern, type IClassRemap, type ICmsApp, type ICmsAppAssignedPage, type ICmsAppDetail, type ICmsAppPage, type ICmsAppSummary, type ICompatibilityError, type IConditionContext, IContentField, type IEvaluatedCondition, type IFieldsMapStyleConfig, type IForgotPasswordRequest, type IForgotPasswordResponse, IFormInvalidData, type IFormListCacheScope, type IFormListFailure, IFormListFilesCell, IFormListRestoreBlockedData, IFormListSort, type IFormListUrlError, type IFormListUrlRules, type IFormListUrlState, type IFormRecordPrefill, type IFormRecordPrefillChild, type IFormRecordPrefillSection, type IFormRecordPrefillTranslatedValue, IFormStaleVersionData, type IFrontendUpdatePreflight, type IFrontendUpdatePreflightResponse, type IFrontendUpdateReleases, type IFrontendUpdateReleasesResponse, type IFrontendUpdateRequest, type IFrontendUpdateRequestResponse, type IGetPageResponse, type IGetPagesResponse, type IHeaderLayerSplit, type IInlineNode, type IJwtPayload, type ILanguage, type ILanguageItem, type ILanguagePreference, type ILanguagePreferenceUpdateResponse, type ILanguagesResponse, type ILoginRequest, type ILoginSuccessData, type ILoginSuccessResponse, type ILogoutSuccessResponse, type IMaintenanceSetRequest, type IMenuSearchHit, type IMobileAdapterBaseProps, type IMobileButtonProps, type IMobileCardProps, type IMobileCheckboxProps, type IMobileContainerProps, type IMobileIconEntry, type IMobileInputProps, type IMobileModalProps, type IMobilePreviewExchangeData, type IMobilePreviewExchangeRequest, type IMobilePreviewExchangeResponse, type IMobilePreviewSessionData, type IMobilePreviewSessionRequest, type IMobilePreviewSessionResponse, type IMobilePreviewUpdatePreflight, type IMobilePreviewUpdatePreflightResponse, type IMobilePreviewUpdateReleases, type IMobilePreviewUpdateReleasesResponse, type IMobilePreviewUpdateRequest, type IMobilePreviewUpdateRequestResponse, type IMobileSelectOption, type IMobileSelectProps, type IMobileSwitchProps, type IMobileTextProps, type IMobileTextareaProps, type IMobileUiAdapters, type INavigationBranding, type INavigationBundle, type INavigationBundleImportHints, type INavigationBundleItem, type INavigationBundleItemTranslation, type INavigationBundleMenu, type INavigationMenu, type INavigationMenuItem, type INavigationPayload, type INavigationResolvedPageRef, type INavigationSearchConfig, type INavigationStartupConfig, type IOptionCatalogEntry, type IOptionLabelMap, type IOptionStyleConfig, type IPageAccessTypeInfo, type IPageContent, type IPageDraftVersioned, type IPageField, type IPageFieldTranslation, type IPageFieldsData, type IPageItem, type IPageLockHolder, type IPageLockStatus, type IPagePayload, type IPageRoute, type IPageSectionWithFields, type IPageSectionsData, type IPagesResolveParams, type IPreviewNavigateCommand, type IPreviewNavigatedMessage, type IPreviewPreferences, type IPreviewPreferencesChangedMessage, type IPreviewReadyMessage, type IPreviewSetPreferencesCommand, type IRefreshRequest, type IRefreshSuccessResponse, type IResetPasswordRequest, type IResetPasswordResponse, type IResolvePageResponse, type IResolvedOption, type ISpacingValue, type IStalePageVersionData, type ISyncBlock, type ISyncChangeMessage, type ISystemAdvisories, type ISystemAdvisoriesResponse, type ISystemAdvisory, type ISystemAdvisoryAffected, type ISystemHealth, type ISystemHealthComponent, type ISystemHealthResponse, type ISystemInstalledPlugin, type ISystemMaintenance, type ISystemMaintenanceResponse, type ISystemVersion, type ISystemVersionResponse, type ITwoFactorRequiredData, type ITwoFactorRequiredResponse, type ITwoFactorVerifyRequest, type ITwoFactorVerifySuccessResponse, type IUpdatePreflight, type IUpdatePreflightCheck, type IUpdatePreflightOption, type IUpdatePreflightResponse, type IUpdateRelease, type IUpdateReleases, type IUpdateReleasesResponse, type IUpdateRequest, type IUpdateRequestResponse, type IUpdateStatus, type IUpdateStatusManager, type IUpdateStatusResponse, type IUpdateStep, type IUserData, type IUserDataResponse, type IWebFooterPresetOption, type IWebHeaderPresetOption, type ImageRef, type InstalledPlugin, type InstanceImages, type InstanceLock, type InstanceManifest, type InstanceMode, type InstanceResourceConfig, type InstanceRouting, type InstanceStatus, type InstanceVersions, type InventoryInstanceEntry, LITERAL_CLASSES, LOCK_IDLE_ENDED_ERROR, type LockPluginEntry, type LockServiceEntry, MOBILE_ICON_NAMES, MOBILE_ICON_SET, MOBILE_PREVIEW_ENDPOINTS, type MobilePreviewRelease, NAVIGATION_BRANDING_LOGO_HEIGHTS, NAVIGATION_BUNDLE_FORMAT, NAVIGATION_BUNDLE_VERSION, NAVIGATION_HEADER_LAYER_TOP, OPTION_STYLE_CONFIGS, PAGE_LOCKED_ERROR, PAGE_VERSION_REQUIRED_ERROR, PERMISSIONS, PREVIEW_BRIDGE_MESSAGE, PREVIEW_PARENT_ORIGIN_PARAM, PREVIEW_SHELL_PARAM, type PluginRelease, type PreflightCheck, type PreflightOption, type PreflightStatus, RELEASE_CHANNELS, type RegistryIndex, type RegistryReleaseRef, type ReleaseChannel, type RuntimeServicePolicy, type RuntimeServiceRange, SIZE_VALUES, SPACING_VALUES, STALE_PAGE_VERSION_ERROR, SYNC_CHANGED_MAX_DELAY_MS, SYNC_EVENT_NAME, SYNC_MESSAGE_VERSION, SYNC_TAG_PATTERN, SYNC_VALID_UNTIL_MAX_DELAY_MS, SYSTEM_ENDPOINTS, type SchedulerRelease, type SecurityAdvisory, type ServerInventory, type ServiceBackendCompatibility, type SignatureBlock, type SupportBundleMeta, type TCalcedValues, type TClassDecision, type TClientType, type TCmsAppRole, TFormListMode, type TFormListUrlChange, type TFormListUrlErrorReason, type TFormListUrlParse, type TFormRecordPrefillFieldValue, type TFormRecordPrefillFileValue, THeroUiButtonVariant, THeroUiSize, TMobileButtonFeedback, TMobileFieldVariant, type TMobilePagePresentation, TMobileSelectPresentation, type TNavigationBrandingSize, type TNavigationBrandingVariant, type TNavigationBundleExportMode, type TNavigationChildrenNavMode, type TNavigationHeaderLayer, type TNavigationMenuItemType, type TNavigationMenuKey, type TNavigationMobileStartSource, type TNavigationSearchMode, type TNavigationStartMode, type TOptionStyleName, type TPermission, type TPlatform, type TPreviewBridgeMessage, type TPreviewBridgeMessageType, type TPreviewColorScheme, type TPreviewFrameSource, TStyleName, type TSyncRefetchKind, type TSyncTag, type TSystemAdvisorySeverity, type TSystemComponentStatus, type TSystemDeployment, type TSystemHealthOverall, type TUpdateCheckSeverity, type TUpdateKind, type TUpdateOperationStatus, type TUpdatePreflightStatus, type TWebFooterPreset, type TWebHeaderPreset, type TrustLevel, type TrustedKey, type TrustedKeysFile, type UpdatePreflightResult, WEB_FOOTER_PRESET_OPTIONS, WEB_FOOTER_PRESET_VALUES, WEB_HEADER_PRESET_OPTIONS, WEB_HEADER_PRESET_VALUES, type WorkerRelease, applyFormListUrlChange, arePreviewPreferencesEqual, asFilesCell, asRecordVersion, buildConditionContext, buildPagesResolvePath, buildPagesResolveQuery, buildPagesResolveUrl, buildPublicPathFromRoute, clampMenuItemsAtDepth, classifyClass, classifyClassString, collectPageIdsFromMenuItems, emptyFormListUrlState, encodeFormListQuery, evaluateCondition, expandedIdsForActiveTrail, findMenuItemByPageId, findNearestBottomTabMenuItemForPage, findPageRefInNavigationPayload, findRemap, flattenFooterItems, flattenFormRecordPrefillValues, flattenMenuItems, flattenNavigationMenuItems, footerColumnItems, footerGroupLinks, footerStandaloneItems, formListCacheKey, formListQueryString, formListRouteQuery, formatRateLimitMessage, getFormInvalidData, getFormListFailure, getFormListRestoreBlocked, getFormStaleVersion, getNavigationItemAriaLabel, getNavigationItemHref, getNavigationItemKeyword, getNavigationItemLabel, getNavigationItemMobileHref, getRateLimitRetryAfter, hasInlineFormatting, isBottomTabMenuItemActive, isDoubleWebHeaderPreset, isFormListParam, isMenuItemActiveOnMobile, isMenuItemActiveOnWeb, isMobileIconName, isNavigationBundleVersionSupported, isOnAnyMobileMenu, isOnAnyMobileMenuFromPayload, isPageInMenuTree, isPageInResolvedMenus, isPageOnAnyMenu, isPageOnMobileMenu, isPageOnWebMenu, isPreviewBridgeMessage, isWebFooterPreset, isWebHeaderPreset, matchesMobilePath, matchesWebPath, mergeHeaderLayers, nextSortOnHeaderClick, normalizePagesResolvePath, pageDependsOn, pageFromPayload, pageUrlToMobileRoute, parseFieldsMapCatalog, parseFieldsMapLabels, parseFormListQuery, parseFormRecordPrefill, parseInlineRich, parseOptionCatalog, parseOptionCodes, parseOptionLabels, parseSpacing, parseSyncMessage, parseSyncMessageJson, pickFormListQuery, previewKeywordFromPath, replaceCalcedValues, resolveAssetSources, resolveAssetUrl, resolveBranchNavGroup, resolveBrandingPresentation, resolveFieldsMapLabel, resolveHolderRedirectPath, resolveMenuMaxDepth, resolveMobileIcon, resolveMobilePagePresentation, resolveMobileSegmentGroup, resolveMobileStartupKeyword, resolveMobileStartupRoute, resolveOptionCodesLabels, resolveOptionLabel, resolveOptionValueLabels, resolveOptions, resolveWebBranchNavContext, resolveWebBranchNavGroup, resolveWebFooterPreset, resolveWebHeaderPreset, resolveWebStartupPath, searchMenuPagesInPayload, serializeFieldsMapCatalog, serializeFieldsMapLabels, spacingToClasses, splitHeaderLayers, stripHtmlToText, syncRefetchDelayMs, transformPageData, transformPagesData };
package/dist/index.js CHANGED
@@ -61,9 +61,13 @@ __export(index_exports, {
61
61
  FORM_RECORD_PREFILL_SKIP_FIELDS: () => FORM_RECORD_PREFILL_SKIP_FIELDS,
62
62
  FORM_SECTION_STYLE_NAMES: () => FORM_SECTION_STYLE_NAMES,
63
63
  FULL_RADIUS_PX: () => FULL_RADIUS_PX,
64
+ HEADER_ACL_STAMP: () => HEADER_ACL_STAMP,
64
65
  HEADER_CLIENT_TYPE: () => HEADER_CLIENT_TYPE,
66
+ HEADER_PAGE_VERSION: () => HEADER_PAGE_VERSION,
67
+ HEADER_PAGE_VIEW: () => HEADER_PAGE_VIEW,
65
68
  LINE_HEIGHT: () => LINE_HEIGHT,
66
69
  LITERAL_CLASSES: () => LITERAL_CLASSES,
70
+ LOCK_IDLE_ENDED_ERROR: () => LOCK_IDLE_ENDED_ERROR,
67
71
  MOBILE_ICON_NAMES: () => MOBILE_ICON_NAMES,
68
72
  MOBILE_ICON_SET: () => MOBILE_ICON_SET,
69
73
  MOBILE_PREVIEW_ENDPOINTS: () => MOBILE_PREVIEW_ENDPOINTS,
@@ -72,6 +76,8 @@ __export(index_exports, {
72
76
  NAVIGATION_BUNDLE_VERSION: () => NAVIGATION_BUNDLE_VERSION,
73
77
  NAVIGATION_HEADER_LAYER_TOP: () => NAVIGATION_HEADER_LAYER_TOP,
74
78
  OPTION_STYLE_CONFIGS: () => OPTION_STYLE_CONFIGS,
79
+ PAGE_LOCKED_ERROR: () => PAGE_LOCKED_ERROR,
80
+ PAGE_VERSION_REQUIRED_ERROR: () => PAGE_VERSION_REQUIRED_ERROR,
75
81
  PERMISSIONS: () => PERMISSIONS,
76
82
  PREVIEW_BRIDGE_MESSAGE: () => PREVIEW_BRIDGE_MESSAGE,
77
83
  PREVIEW_PARENT_ORIGIN_PARAM: () => PREVIEW_PARENT_ORIGIN_PARAM,
@@ -82,7 +88,13 @@ __export(index_exports, {
82
88
  SPACING_PX: () => SPACING_PX,
83
89
  SPACING_TO_TAILWIND: () => SPACING_TO_TAILWIND,
84
90
  SPACING_VALUES: () => SPACING_VALUES,
91
+ STALE_PAGE_VERSION_ERROR: () => STALE_PAGE_VERSION_ERROR,
85
92
  STYLE_REGISTRY: () => STYLE_REGISTRY,
93
+ SYNC_CHANGED_MAX_DELAY_MS: () => SYNC_CHANGED_MAX_DELAY_MS,
94
+ SYNC_EVENT_NAME: () => SYNC_EVENT_NAME,
95
+ SYNC_MESSAGE_VERSION: () => SYNC_MESSAGE_VERSION,
96
+ SYNC_TAG_PATTERN: () => SYNC_TAG_PATTERN,
97
+ SYNC_VALID_UNTIL_MAX_DELAY_MS: () => SYNC_VALID_UNTIL_MAX_DELAY_MS,
86
98
  SYSTEM_ENDPOINTS: () => SYSTEM_ENDPOINTS,
87
99
  WEB_FOOTER_PRESET_OPTIONS: () => WEB_FOOTER_PRESET_OPTIONS,
88
100
  WEB_FOOTER_PRESET_VALUES: () => WEB_FOOTER_PRESET_VALUES,
@@ -180,6 +192,8 @@ __export(index_exports, {
180
192
  mergeHeaderLayers: () => mergeHeaderLayers,
181
193
  nextSortOnHeaderClick: () => nextSortOnHeaderClick,
182
194
  normalizePagesResolvePath: () => normalizePagesResolvePath,
195
+ pageDependsOn: () => pageDependsOn,
196
+ pageFromPayload: () => pageFromPayload,
183
197
  pageUrlToMobileRoute: () => pageUrlToMobileRoute,
184
198
  parseDimensionToReactNative: () => parseDimensionToReactNative,
185
199
  parseDimensionToWeb: () => parseDimensionToWeb,
@@ -192,6 +206,8 @@ __export(index_exports, {
192
206
  parseOptionCodes: () => parseOptionCodes,
193
207
  parseOptionLabels: () => parseOptionLabels,
194
208
  parseSpacing: () => parseSpacing,
209
+ parseSyncMessage: () => parseSyncMessage,
210
+ parseSyncMessageJson: () => parseSyncMessageJson,
195
211
  pickFormListQuery: () => pickFormListQuery,
196
212
  previewKeywordFromPath: () => previewKeywordFromPath,
197
213
  radiusToPx: () => radiusToPx,
@@ -234,6 +250,7 @@ __export(index_exports, {
234
250
  splitHeaderLayers: () => splitHeaderLayers,
235
251
  stripHtmlToText: () => stripHtmlToText,
236
252
  stylePlatformToSet: () => stylePlatformToSet,
253
+ syncRefetchDelayMs: () => syncRefetchDelayMs,
237
254
  toHeroUiSemanticProps: () => toHeroUiSemanticProps,
238
255
  toMantineSemanticProps: () => toMantineSemanticProps,
239
256
  toReactNativeSemanticStyle: () => toReactNativeSemanticStyle,
@@ -721,8 +738,21 @@ var ENDPOINTS = {
721
738
  COMPARE: (tableName, recordId) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/compare`,
722
739
  RESTORE: (tableName, recordId) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/restore`,
723
740
  VERSION_FILE: (tableName, recordId, version, fieldKey) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/versions/${version}/files/${encodeURIComponent(fieldKey)}`
741
+ },
742
+ /**
743
+ * Page edit lock (live sync, C9). Route permission `admin.page.update` plus
744
+ * the update grant on the page. `LOCK` serves three methods: GET (status),
745
+ * POST (acquire or renew) and DELETE (release); `TAKE_OVER` is POST only.
746
+ * Every route answers an `IPageLockStatus`.
747
+ */
748
+ ADMIN_PAGE_LOCK: {
749
+ LOCK: (pageId) => `${API_VERSION_PREFIX}/admin/pages/${pageId}/lock`,
750
+ TAKE_OVER: (pageId) => `${API_VERSION_PREFIX}/admin/pages/${pageId}/lock/take-over`
724
751
  }
725
752
  };
753
+ var HEADER_ACL_STAMP = "X-Acl-Stamp";
754
+ var HEADER_PAGE_VIEW = "X-Page-View";
755
+ var HEADER_PAGE_VERSION = "X-Page-Version";
726
756
  var HEADER_CLIENT_TYPE = "X-Client-Type";
727
757
  var CLIENT_TYPE_WEB = "web";
728
758
  var CLIENT_TYPE_MOBILE = "mobile";
@@ -3255,6 +3285,63 @@ function expandedIdsForActiveTrail(items, pathname, platform) {
3255
3285
  return expanded;
3256
3286
  }
3257
3287
 
3288
+ // src/sync/types.ts
3289
+ var SYNC_EVENT_NAME = "changed";
3290
+ var SYNC_MESSAGE_VERSION = 1;
3291
+ var SYNC_TAG_PATTERN = /^(acl|navigation|global_values|page:\d+|page_draft:\d+|page_lock:\d+|table:\d+|section:\d+|asset:\d+)$/;
3292
+ var PAGE_VERSION_REQUIRED_ERROR = "page_version_required";
3293
+ var STALE_PAGE_VERSION_ERROR = "stale_page_version";
3294
+ var PAGE_LOCKED_ERROR = "page_locked";
3295
+ var LOCK_IDLE_ENDED_ERROR = "lock_idle_ended";
3296
+
3297
+ // src/sync/sync.ts
3298
+ var SYNC_CHANGED_MAX_DELAY_MS = 300;
3299
+ var SYNC_VALID_UNTIL_MAX_DELAY_MS = 2e3;
3300
+ function isRecord(value) {
3301
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3302
+ }
3303
+ function parseSyncMessage(data) {
3304
+ if (!isRecord(data) || data.v !== SYNC_MESSAGE_VERSION || !Array.isArray(data.tags)) {
3305
+ return null;
3306
+ }
3307
+ const tags = [];
3308
+ for (const tag of data.tags) {
3309
+ if (typeof tag === "string" && SYNC_TAG_PATTERN.test(tag) && !tags.includes(tag)) {
3310
+ tags.push(tag);
3311
+ }
3312
+ }
3313
+ return tags.length === 0 ? null : { v: SYNC_MESSAGE_VERSION, tags };
3314
+ }
3315
+ function parseSyncMessageJson(raw) {
3316
+ try {
3317
+ return parseSyncMessage(JSON.parse(raw));
3318
+ } catch {
3319
+ return null;
3320
+ }
3321
+ }
3322
+ function pageDependsOn(sync, tags) {
3323
+ if (!sync || !Array.isArray(sync.depends_on) || sync.depends_on.length === 0) {
3324
+ return false;
3325
+ }
3326
+ return tags.some((tag) => sync.depends_on.includes(tag));
3327
+ }
3328
+ function syncRefetchDelayMs(kind, random = Math.random) {
3329
+ const max = kind === "changed" ? SYNC_CHANGED_MAX_DELAY_MS : SYNC_VALID_UNTIL_MAX_DELAY_MS;
3330
+ const r = random();
3331
+ const unit = Number.isFinite(r) ? Math.min(Math.max(r, 0), 1) : 0;
3332
+ return Math.min(max, Math.floor(unit * (max + 1)));
3333
+ }
3334
+
3335
+ // src/sync/page-payload.ts
3336
+ function pageFromPayload(payload) {
3337
+ const page = payload?.page;
3338
+ if (!page) {
3339
+ return null;
3340
+ }
3341
+ const sync = payload.sync ?? page.sync;
3342
+ return sync ? { ...page, sync } : page;
3343
+ }
3344
+
3258
3345
  // src/utils/spacing.ts
3259
3346
  var ALLOWED_KEYS = ["mt", "mb", "ms", "me", "pt", "pb", "ps", "pe"];
3260
3347
  function parseSpacing(raw) {
@@ -3352,9 +3439,13 @@ function transformPagesData(pages) {
3352
3439
  FORM_RECORD_PREFILL_SKIP_FIELDS,
3353
3440
  FORM_SECTION_STYLE_NAMES,
3354
3441
  FULL_RADIUS_PX,
3442
+ HEADER_ACL_STAMP,
3355
3443
  HEADER_CLIENT_TYPE,
3444
+ HEADER_PAGE_VERSION,
3445
+ HEADER_PAGE_VIEW,
3356
3446
  LINE_HEIGHT,
3357
3447
  LITERAL_CLASSES,
3448
+ LOCK_IDLE_ENDED_ERROR,
3358
3449
  MOBILE_ICON_NAMES,
3359
3450
  MOBILE_ICON_SET,
3360
3451
  MOBILE_PREVIEW_ENDPOINTS,
@@ -3363,6 +3454,8 @@ function transformPagesData(pages) {
3363
3454
  NAVIGATION_BUNDLE_VERSION,
3364
3455
  NAVIGATION_HEADER_LAYER_TOP,
3365
3456
  OPTION_STYLE_CONFIGS,
3457
+ PAGE_LOCKED_ERROR,
3458
+ PAGE_VERSION_REQUIRED_ERROR,
3366
3459
  PERMISSIONS,
3367
3460
  PREVIEW_BRIDGE_MESSAGE,
3368
3461
  PREVIEW_PARENT_ORIGIN_PARAM,
@@ -3373,7 +3466,13 @@ function transformPagesData(pages) {
3373
3466
  SPACING_PX,
3374
3467
  SPACING_TO_TAILWIND,
3375
3468
  SPACING_VALUES,
3469
+ STALE_PAGE_VERSION_ERROR,
3376
3470
  STYLE_REGISTRY,
3471
+ SYNC_CHANGED_MAX_DELAY_MS,
3472
+ SYNC_EVENT_NAME,
3473
+ SYNC_MESSAGE_VERSION,
3474
+ SYNC_TAG_PATTERN,
3475
+ SYNC_VALID_UNTIL_MAX_DELAY_MS,
3377
3476
  SYSTEM_ENDPOINTS,
3378
3477
  WEB_FOOTER_PRESET_OPTIONS,
3379
3478
  WEB_FOOTER_PRESET_VALUES,
@@ -3471,6 +3570,8 @@ function transformPagesData(pages) {
3471
3570
  mergeHeaderLayers,
3472
3571
  nextSortOnHeaderClick,
3473
3572
  normalizePagesResolvePath,
3573
+ pageDependsOn,
3574
+ pageFromPayload,
3474
3575
  pageUrlToMobileRoute,
3475
3576
  parseDimensionToReactNative,
3476
3577
  parseDimensionToWeb,
@@ -3483,6 +3584,8 @@ function transformPagesData(pages) {
3483
3584
  parseOptionCodes,
3484
3585
  parseOptionLabels,
3485
3586
  parseSpacing,
3587
+ parseSyncMessage,
3588
+ parseSyncMessageJson,
3486
3589
  pickFormListQuery,
3487
3590
  previewKeywordFromPath,
3488
3591
  radiusToPx,
@@ -3525,6 +3628,7 @@ function transformPagesData(pages) {
3525
3628
  splitHeaderLayers,
3526
3629
  stripHtmlToText,
3527
3630
  stylePlatformToSet,
3631
+ syncRefetchDelayMs,
3528
3632
  toHeroUiSemanticProps,
3529
3633
  toMantineSemanticProps,
3530
3634
  toReactNativeSemanticStyle,
package/dist/index.mjs CHANGED
@@ -477,8 +477,21 @@ var ENDPOINTS = {
477
477
  COMPARE: (tableName, recordId) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/compare`,
478
478
  RESTORE: (tableName, recordId) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/restore`,
479
479
  VERSION_FILE: (tableName, recordId, version, fieldKey) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/versions/${version}/files/${encodeURIComponent(fieldKey)}`
480
+ },
481
+ /**
482
+ * Page edit lock (live sync, C9). Route permission `admin.page.update` plus
483
+ * the update grant on the page. `LOCK` serves three methods: GET (status),
484
+ * POST (acquire or renew) and DELETE (release); `TAKE_OVER` is POST only.
485
+ * Every route answers an `IPageLockStatus`.
486
+ */
487
+ ADMIN_PAGE_LOCK: {
488
+ LOCK: (pageId) => `${API_VERSION_PREFIX}/admin/pages/${pageId}/lock`,
489
+ TAKE_OVER: (pageId) => `${API_VERSION_PREFIX}/admin/pages/${pageId}/lock/take-over`
480
490
  }
481
491
  };
492
+ var HEADER_ACL_STAMP = "X-Acl-Stamp";
493
+ var HEADER_PAGE_VIEW = "X-Page-View";
494
+ var HEADER_PAGE_VERSION = "X-Page-Version";
482
495
  var HEADER_CLIENT_TYPE = "X-Client-Type";
483
496
  var CLIENT_TYPE_WEB = "web";
484
497
  var CLIENT_TYPE_MOBILE = "mobile";
@@ -3011,6 +3024,63 @@ function expandedIdsForActiveTrail(items, pathname, platform) {
3011
3024
  return expanded;
3012
3025
  }
3013
3026
 
3027
+ // src/sync/types.ts
3028
+ var SYNC_EVENT_NAME = "changed";
3029
+ var SYNC_MESSAGE_VERSION = 1;
3030
+ var SYNC_TAG_PATTERN = /^(acl|navigation|global_values|page:\d+|page_draft:\d+|page_lock:\d+|table:\d+|section:\d+|asset:\d+)$/;
3031
+ var PAGE_VERSION_REQUIRED_ERROR = "page_version_required";
3032
+ var STALE_PAGE_VERSION_ERROR = "stale_page_version";
3033
+ var PAGE_LOCKED_ERROR = "page_locked";
3034
+ var LOCK_IDLE_ENDED_ERROR = "lock_idle_ended";
3035
+
3036
+ // src/sync/sync.ts
3037
+ var SYNC_CHANGED_MAX_DELAY_MS = 300;
3038
+ var SYNC_VALID_UNTIL_MAX_DELAY_MS = 2e3;
3039
+ function isRecord(value) {
3040
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3041
+ }
3042
+ function parseSyncMessage(data) {
3043
+ if (!isRecord(data) || data.v !== SYNC_MESSAGE_VERSION || !Array.isArray(data.tags)) {
3044
+ return null;
3045
+ }
3046
+ const tags = [];
3047
+ for (const tag of data.tags) {
3048
+ if (typeof tag === "string" && SYNC_TAG_PATTERN.test(tag) && !tags.includes(tag)) {
3049
+ tags.push(tag);
3050
+ }
3051
+ }
3052
+ return tags.length === 0 ? null : { v: SYNC_MESSAGE_VERSION, tags };
3053
+ }
3054
+ function parseSyncMessageJson(raw) {
3055
+ try {
3056
+ return parseSyncMessage(JSON.parse(raw));
3057
+ } catch {
3058
+ return null;
3059
+ }
3060
+ }
3061
+ function pageDependsOn(sync, tags) {
3062
+ if (!sync || !Array.isArray(sync.depends_on) || sync.depends_on.length === 0) {
3063
+ return false;
3064
+ }
3065
+ return tags.some((tag) => sync.depends_on.includes(tag));
3066
+ }
3067
+ function syncRefetchDelayMs(kind, random = Math.random) {
3068
+ const max = kind === "changed" ? SYNC_CHANGED_MAX_DELAY_MS : SYNC_VALID_UNTIL_MAX_DELAY_MS;
3069
+ const r = random();
3070
+ const unit = Number.isFinite(r) ? Math.min(Math.max(r, 0), 1) : 0;
3071
+ return Math.min(max, Math.floor(unit * (max + 1)));
3072
+ }
3073
+
3074
+ // src/sync/page-payload.ts
3075
+ function pageFromPayload(payload) {
3076
+ const page = payload?.page;
3077
+ if (!page) {
3078
+ return null;
3079
+ }
3080
+ const sync = payload.sync ?? page.sync;
3081
+ return sync ? { ...page, sync } : page;
3082
+ }
3083
+
3014
3084
  // src/utils/spacing.ts
3015
3085
  var ALLOWED_KEYS = ["mt", "mb", "ms", "me", "pt", "pb", "ps", "pe"];
3016
3086
  function parseSpacing(raw) {
@@ -3107,9 +3177,13 @@ export {
3107
3177
  FORM_RECORD_PREFILL_SKIP_FIELDS,
3108
3178
  FORM_SECTION_STYLE_NAMES,
3109
3179
  FULL_RADIUS_PX,
3180
+ HEADER_ACL_STAMP,
3110
3181
  HEADER_CLIENT_TYPE,
3182
+ HEADER_PAGE_VERSION,
3183
+ HEADER_PAGE_VIEW,
3111
3184
  LINE_HEIGHT,
3112
3185
  LITERAL_CLASSES,
3186
+ LOCK_IDLE_ENDED_ERROR,
3113
3187
  MOBILE_ICON_NAMES,
3114
3188
  MOBILE_ICON_SET,
3115
3189
  MOBILE_PREVIEW_ENDPOINTS,
@@ -3118,6 +3192,8 @@ export {
3118
3192
  NAVIGATION_BUNDLE_VERSION,
3119
3193
  NAVIGATION_HEADER_LAYER_TOP,
3120
3194
  OPTION_STYLE_CONFIGS,
3195
+ PAGE_LOCKED_ERROR,
3196
+ PAGE_VERSION_REQUIRED_ERROR,
3121
3197
  PERMISSIONS,
3122
3198
  PREVIEW_BRIDGE_MESSAGE,
3123
3199
  PREVIEW_PARENT_ORIGIN_PARAM,
@@ -3128,7 +3204,13 @@ export {
3128
3204
  SPACING_PX,
3129
3205
  SPACING_TO_TAILWIND,
3130
3206
  SPACING_VALUES,
3207
+ STALE_PAGE_VERSION_ERROR,
3131
3208
  STYLE_REGISTRY,
3209
+ SYNC_CHANGED_MAX_DELAY_MS,
3210
+ SYNC_EVENT_NAME,
3211
+ SYNC_MESSAGE_VERSION,
3212
+ SYNC_TAG_PATTERN,
3213
+ SYNC_VALID_UNTIL_MAX_DELAY_MS,
3132
3214
  SYSTEM_ENDPOINTS,
3133
3215
  WEB_FOOTER_PRESET_OPTIONS,
3134
3216
  WEB_FOOTER_PRESET_VALUES,
@@ -3226,6 +3308,8 @@ export {
3226
3308
  mergeHeaderLayers,
3227
3309
  nextSortOnHeaderClick,
3228
3310
  normalizePagesResolvePath,
3311
+ pageDependsOn,
3312
+ pageFromPayload,
3229
3313
  pageUrlToMobileRoute,
3230
3314
  parseDimensionToReactNative,
3231
3315
  parseDimensionToWeb,
@@ -3238,6 +3322,8 @@ export {
3238
3322
  parseOptionCodes,
3239
3323
  parseOptionLabels,
3240
3324
  parseSpacing,
3325
+ parseSyncMessage,
3326
+ parseSyncMessageJson,
3241
3327
  pickFormListQuery,
3242
3328
  previewKeywordFromPath,
3243
3329
  radiusToPx,
@@ -3280,6 +3366,7 @@ export {
3280
3366
  splitHeaderLayers,
3281
3367
  stripHtmlToText,
3282
3368
  stylePlatformToSet,
3369
+ syncRefetchDelayMs,
3283
3370
  toHeroUiSemanticProps,
3284
3371
  toMantineSemanticProps,
3285
3372
  toReactNativeSemanticStyle,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@selfhelp/shared",
3
- "version": "1.27.0",
3
+ "version": "1.29.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",