@aglyn/aglyn 1.10.0 → 1.12.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.
Files changed (55) hide show
  1. package/package.json +11 -11
  2. package/src/lib/app-utils/account-preferences.d.ts +15 -13
  3. package/src/lib/app-utils/account-preferences.js +20 -20
  4. package/src/lib/app-utils/account-preferences.js.map +1 -1
  5. package/src/lib/app-utils/crm.d.ts +3 -1
  6. package/src/lib/app-utils/crm.js +6 -3
  7. package/src/lib/app-utils/crm.js.map +1 -1
  8. package/src/lib/app-utils/docs-help-sections.generated.js +3 -3
  9. package/src/lib/app-utils/docs-help-sections.generated.js.map +1 -1
  10. package/src/lib/app-utils/docs-help.generated.d.ts +2 -2
  11. package/src/lib/app-utils/docs-help.generated.js +2 -0
  12. package/src/lib/app-utils/docs-help.generated.js.map +1 -1
  13. package/src/lib/app-utils/docs-index.generated.js +76 -69
  14. package/src/lib/app-utils/docs-index.generated.js.map +1 -1
  15. package/src/lib/app-utils/full-use-cost.d.ts +28 -11
  16. package/src/lib/app-utils/full-use-cost.js +31 -15
  17. package/src/lib/app-utils/full-use-cost.js.map +1 -1
  18. package/src/lib/app-utils/markdown-lite.js +8 -1
  19. package/src/lib/app-utils/markdown-lite.js.map +1 -1
  20. package/src/lib/app-utils/org-role-grants.d.ts +6 -0
  21. package/src/lib/app-utils/org-role-grants.js +3 -1
  22. package/src/lib/app-utils/org-role-grants.js.map +1 -1
  23. package/src/lib/app-utils/person-erasure.d.ts +8 -0
  24. package/src/lib/app-utils/person-erasure.js +6 -0
  25. package/src/lib/app-utils/person-erasure.js.map +1 -1
  26. package/src/lib/app-utils/plan-entitlements.d.ts +27 -1
  27. package/src/lib/app-utils/plan-entitlements.js +44 -3
  28. package/src/lib/app-utils/plan-entitlements.js.map +1 -1
  29. package/src/lib/app-utils/site-preview.d.ts +6 -2
  30. package/src/lib/app-utils/site-preview.js +5 -3
  31. package/src/lib/app-utils/site-preview.js.map +1 -1
  32. package/src/lib/app-utils/site-unavailable.d.ts +4 -7
  33. package/src/lib/app-utils/site-unavailable.js +4 -8
  34. package/src/lib/app-utils/site-unavailable.js.map +1 -1
  35. package/src/lib/app-utils/upgrade-proposal.d.ts +17 -3
  36. package/src/lib/app-utils/upgrade-proposal.js +28 -6
  37. package/src/lib/app-utils/upgrade-proposal.js.map +1 -1
  38. package/src/lib/foundation/definitions/org-billing.types.d.ts +22 -0
  39. package/src/lib/foundation/definitions/org-billing.types.js +2 -2
  40. package/src/lib/foundation/definitions/org-billing.types.js.map +1 -1
  41. package/src/lib/foundation/definitions/platform.types.d.ts +1 -1
  42. package/src/lib/foundation/definitions/platform.types.js.map +1 -1
  43. package/src/lib/foundation/definitions/write-deny-coverage.util.d.ts +1 -1
  44. package/src/lib/foundation/definitions/write-deny-coverage.util.js +1 -1
  45. package/src/lib/foundation/definitions/write-deny-coverage.util.js.map +1 -1
  46. package/src/lib/plugin-manager/first-party-plugins.generated.js +1 -1
  47. package/src/lib/plugin-manager/first-party-plugins.generated.js.map +1 -1
  48. package/src/lib/plugin-manager/plugin-contact-capture.d.ts +18 -0
  49. package/src/lib/plugin-manager/plugin-contact-capture.js +26 -0
  50. package/src/lib/plugin-manager/plugin-contact-capture.js.map +1 -1
  51. package/src/lib/plugin-manager/plugin-person-erasure-notes.d.ts +61 -0
  52. package/src/lib/plugin-manager/plugin-person-erasure-notes.js +114 -0
  53. package/src/lib/plugin-manager/plugin-person-erasure-notes.js.map +1 -0
  54. package/src/lib/plugin-manager/plugin-site-starters.d.ts +7 -0
  55. package/src/lib/plugin-manager/plugin-site-starters.js.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/aglyn",
3
- "version": "1.10.0",
3
+ "version": "1.12.0",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -37,16 +37,16 @@
37
37
  "./package.json": "./package.json"
38
38
  },
39
39
  "dependencies": {
40
- "@aglyn/shared-data-enums": "1.10.0",
41
- "@aglyn/shared-data-mdi": "1.10.0",
42
- "@aglyn/shared-data-types": "1.10.0",
43
- "@aglyn/shared-util-email": "1.10.0",
44
- "@aglyn/shared-util-first-touch": "1.10.0",
45
- "@aglyn/shared-util-http": "1.10.0",
46
- "@aglyn/shared-util-logger": "1.10.0",
47
- "@aglyn/shared-util-timestamp": "1.10.0",
48
- "@aglyn/shared-util-tools": "1.10.0",
49
- "@aglyn/shared-util-vendor": "1.10.0",
40
+ "@aglyn/shared-data-enums": "1.12.0",
41
+ "@aglyn/shared-data-mdi": "1.12.0",
42
+ "@aglyn/shared-data-types": "1.12.0",
43
+ "@aglyn/shared-util-email": "1.12.0",
44
+ "@aglyn/shared-util-first-touch": "1.12.0",
45
+ "@aglyn/shared-util-http": "1.12.0",
46
+ "@aglyn/shared-util-logger": "1.12.0",
47
+ "@aglyn/shared-util-timestamp": "1.12.0",
48
+ "@aglyn/shared-util-tools": "1.12.0",
49
+ "@aglyn/shared-util-vendor": "1.12.0",
50
50
  "@data-driven-forms/react-form-renderer": "^4.2.0",
51
51
  "@msgpack/msgpack": "^3.1.3",
52
52
  "@types/unist": "^3.0.3",
@@ -23,7 +23,7 @@
23
23
  * | field | shape | cap |
24
24
  * | -- | -- | -- |
25
25
  * | `pinnedOrgs` | workspace ids, in the order the person keeps them | 5 |
26
- * | `pinnedHosts` | {@link PinnedHost}s, in the order they were pinned | 5 a workspace, 100 in all |
26
+ * | `pinnedHosts` | {@link PinnedHost}s, in the order they were pinned | 500 in all, no cap a workspace |
27
27
  * | `recentOrgs` | workspace ids, most recently opened first | 8 |
28
28
  * | `starred` | {@link StarredItem}s, in the order they were starred | 50 |
29
29
  * | `recents` | {@link RecentItem}s, most recently opened first | 30 |
@@ -188,15 +188,16 @@ export declare function keepPinnedOrgs(stored: readonly string[], keep: readonly
188
188
  export declare function movePinnedOrg(pinned: readonly string[], orgId: string, offset: number): string[];
189
189
  /** `users/{uid}` field holding the sites the person pinned, each with its workspace (AGL-4005). */
190
190
  export declare const PINNED_HOSTS_FIELD = "pinnedHosts";
191
- /** The most sites a person may pin in one workspace: five, as for workspaces. */
192
- export declare const PINNED_HOSTS_PER_WORKSPACE = 5;
193
191
  /**
194
192
  * The most site pins the account keeps across every workspace, the bound the
195
- * Firestore rules hold. Nobody meets it by pinning: it takes twenty
196
- * workspaces with five each. Past it, the oldest pins of OTHER workspaces
197
- * give way (see {@link pinHost}).
193
+ * Firestore rules hold so `users/{uid}` (read on every launch) cannot grow
194
+ * without end. A workspace has no cap of its own: a person pins as many of
195
+ * its sites as they like (AGL-4165, Zach 2026-11-04), where workspace pins
196
+ * stay at five. Past the bound, the oldest pins of OTHER workspaces give way
197
+ * (see {@link pinHost}); only a workspace holding every one of the 500 is
198
+ * ever full.
198
199
  */
199
- export declare const PINNED_HOSTS_MAX = 100;
200
+ export declare const PINNED_HOSTS_MAX = 500;
200
201
  /**
201
202
  * One pinned site and the workspace it belongs to. The workspace rides with
202
203
  * the pin so a surface that holds only one workspace's sites (the site
@@ -212,7 +213,7 @@ export interface PinnedHost {
212
213
  * value can never take the sites list down.
213
214
  */
214
215
  export declare function readPinnedHosts(profile: unknown): PinnedHost[];
215
- /** One workspace's pinned site ids, in the order pinned, at most five. */
216
+ /** One workspace's pinned site ids, in the order pinned. */
216
217
  export declare function workspacePinnedHosts(stored: readonly PinnedHost[], orgId: string): string[];
217
218
  export interface PinHostResult {
218
219
  /** Every stored pin after the request: unchanged unless `outcome` is `pinned`. */
@@ -220,11 +221,12 @@ export interface PinHostResult {
220
221
  outcome: PinOrgOutcome;
221
222
  }
222
223
  /**
223
- * Pins a site at the end of its workspace's pins, or says that workspace
224
- * already has five. As with workspaces, a full list is never made room in
225
- * quietly: the caller asks "Pinned is full. Replace one?" and calls
226
- * {@link replacePinnedHost} with the answer. Only the account-wide bound
227
- * ({@link PINNED_HOSTS_MAX}) makes room, and only from other workspaces.
224
+ * Pins a site at the end of its workspace's pins. A workspace takes as many
225
+ * as the person likes; only the account-wide bound ({@link PINNED_HOSTS_MAX})
226
+ * makes room, and only from other workspaces. A workspace that already holds
227
+ * every pin the account keeps answers `full`, never a pin dropped quietly:
228
+ * the caller asks "Pinned is full. Replace one?" and calls
229
+ * {@link replacePinnedHost} with the answer.
228
230
  */
229
231
  export declare function pinHost(stored: readonly PinnedHost[], pin: PinnedHost): PinHostResult;
230
232
  /** The stored pins without one site. */
@@ -23,7 +23,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
23
23
  * | field | shape | cap |
24
24
  * | -- | -- | -- |
25
25
  * | `pinnedOrgs` | workspace ids, in the order the person keeps them | 5 |
26
- * | `pinnedHosts` | {@link PinnedHost}s, in the order they were pinned | 5 a workspace, 100 in all |
26
+ * | `pinnedHosts` | {@link PinnedHost}s, in the order they were pinned | 500 in all, no cap a workspace |
27
27
  * | `recentOrgs` | workspace ids, most recently opened first | 8 |
28
28
  * | `starred` | {@link StarredItem}s, in the order they were starred | 50 |
29
29
  * | `recents` | {@link RecentItem}s, most recently opened first | 30 |
@@ -195,13 +195,15 @@ function idList(value) {
195
195
  }
196
196
  // ── Site pins ───────────────────────────────────────────────────────────────
197
197
  /** `users/{uid}` field holding the sites the person pinned, each with its workspace (AGL-4005). */ export const PINNED_HOSTS_FIELD = 'pinnedHosts';
198
- /** The most sites a person may pin in one workspace: five, as for workspaces. */ export const PINNED_HOSTS_PER_WORKSPACE = 5;
199
198
  /**
200
199
  * The most site pins the account keeps across every workspace, the bound the
201
- * Firestore rules hold. Nobody meets it by pinning: it takes twenty
202
- * workspaces with five each. Past it, the oldest pins of OTHER workspaces
203
- * give way (see {@link pinHost}).
204
- */ export const PINNED_HOSTS_MAX = 100;
200
+ * Firestore rules hold so `users/{uid}` (read on every launch) cannot grow
201
+ * without end. A workspace has no cap of its own: a person pins as many of
202
+ * its sites as they like (AGL-4165, Zach 2026-11-04), where workspace pins
203
+ * stay at five. Past the bound, the oldest pins of OTHER workspaces give way
204
+ * (see {@link pinHost}); only a workspace holding every one of the 500 is
205
+ * ever full.
206
+ */ export const PINNED_HOSTS_MAX = 500;
205
207
  function pinnedHostList(value) {
206
208
  if (!Array.isArray(value)) return [];
207
209
  const seen = new Set();
@@ -226,15 +228,16 @@ function pinnedHostList(value) {
226
228
  */ export function readPinnedHosts(profile) {
227
229
  return pinnedHostList(field(profile, PINNED_HOSTS_FIELD));
228
230
  }
229
- /** One workspace's pinned site ids, in the order pinned, at most five. */ export function workspacePinnedHosts(stored, orgId) {
230
- return pinnedHostList(stored).filter((pin)=>pin.orgId === orgId).map((pin)=>pin.hostId).slice(0, PINNED_HOSTS_PER_WORKSPACE);
231
+ /** One workspace's pinned site ids, in the order pinned. */ export function workspacePinnedHosts(stored, orgId) {
232
+ return pinnedHostList(stored).filter((pin)=>pin.orgId === orgId).map((pin)=>pin.hostId).slice(0, PINNED_HOSTS_MAX);
231
233
  }
232
234
  /**
233
- * Pins a site at the end of its workspace's pins, or says that workspace
234
- * already has five. As with workspaces, a full list is never made room in
235
- * quietly: the caller asks "Pinned is full. Replace one?" and calls
236
- * {@link replacePinnedHost} with the answer. Only the account-wide bound
237
- * ({@link PINNED_HOSTS_MAX}) makes room, and only from other workspaces.
235
+ * Pins a site at the end of its workspace's pins. A workspace takes as many
236
+ * as the person likes; only the account-wide bound ({@link PINNED_HOSTS_MAX})
237
+ * makes room, and only from other workspaces. A workspace that already holds
238
+ * every pin the account keeps answers `full`, never a pin dropped quietly:
239
+ * the caller asks "Pinned is full. Replace one?" and calls
240
+ * {@link replacePinnedHost} with the answer.
238
241
  */ export function pinHost(stored, pin) {
239
242
  const current = pinnedHostList(stored);
240
243
  if (!pin.orgId || !pin.hostId) return {
@@ -246,12 +249,6 @@ function pinnedHostList(value) {
246
249
  pinnedHosts: current,
247
250
  outcome: 'alreadyPinned'
248
251
  };
249
- if (inWorkspace.length >= PINNED_HOSTS_PER_WORKSPACE) {
250
- return {
251
- pinnedHosts: current,
252
- outcome: 'full'
253
- };
254
- }
255
252
  // A site pinned under the workspace it has since moved out of moves with it.
256
253
  const next = [
257
254
  ...current.filter((entry)=>entry.hostId !== pin.hostId),
@@ -262,7 +259,10 @@ function pinnedHostList(value) {
262
259
  ];
263
260
  while(next.length > PINNED_HOSTS_MAX){
264
261
  const oldest = next.findIndex((entry)=>entry.orgId !== pin.orgId);
265
- if (oldest === -1) break;
262
+ if (oldest === -1) return {
263
+ pinnedHosts: current,
264
+ outcome: 'full'
265
+ };
266
266
  next.splice(oldest, 1);
267
267
  }
268
268
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/account-preferences.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * THE PREFERENCES A PERSON KEEPS ON THEIR ACCOUNT (AGL-3943).\n *\n * One documented shape on `users/{uid}`, read and written the same way by\n * the console and both native apps (docs/mobile/native-navigation.md):\n *\n * | field | shape | cap |\n * | -- | -- | -- |\n * | `pinnedOrgs` | workspace ids, in the order the person keeps them | 5 |\n * | `pinnedHosts` | {@link PinnedHost}s, in the order they were pinned | 5 a workspace, 100 in all |\n * | `recentOrgs` | workspace ids, most recently opened first | 8 |\n * | `starred` | {@link StarredItem}s, in the order they were starred | 50 |\n * | `recents` | {@link RecentItem}s, most recently opened first | 30 |\n * | `workspaceColors` | workspace id → `#RRGGBB` the person picked | 100 |\n * | `appTheme` | {@link AppThemePrefs}, the apps' look, synced | — |\n * | `tabBars` | {@link TabBarPins}, the phone's tab bar per site and per workspace | 4 areas each, 100 in all |\n *\n * The caps are held twice: here, by every writer, and by the Firestore rules,\n * which refuse a write that grows a list past its cap. A list that is ALREADY\n * past it (pins made before the cap, Zach 2026-10-18) may only shrink, so a\n * person with seven pins can still unpin one; the console asks them once\n * which five to keep, and until they answer the first five are the pins.\n *\n * A per-device override of the theme (\"this device only\") is the device's\n * own, kept in local storage on each platform, and never written here.\n *\n * NO IMPORTS, on purpose: the native apps read these constants, types and\n * the answers of these functions through the generated contracts, so it must\n * stay a plain module.\n */\n\n/** `users/{uid}` field holding the ids of the workspaces the person pinned. */\nexport const PINNED_ORGS_FIELD = 'pinnedOrgs'\n\n/** The most workspaces a person may pin, everywhere, the console included. */\nexport const PINNED_ORGS_MAX = 5\n\n/** `users/{uid}` field holding the workspaces opened most recently, newest first. */\nexport const RECENT_ORGS_FIELD = 'recentOrgs'\n\n/** How many recently opened workspaces are kept. */\nexport const RECENT_ORGS_MAX = 8\n\n/** How many recent workspaces the rail shows below the pins. */\nexport const RAIL_RECENT_ORGS = 3\n\n/** `users/{uid}` field holding the person's starred screens and records. */\nexport const STARRED_FIELD = 'starred'\n\n/** The most items a person may star. */\nexport const STARRED_MAX = 50\n\n/** `users/{uid}` field holding the screens and records opened most recently. */\nexport const RECENTS_FIELD = 'recents'\n\n/** How many recently opened screens and records are kept. */\nexport const RECENTS_MAX = 30\n\n/** `users/{uid}` field holding the color the person picked for each workspace. */\nexport const WORKSPACE_COLORS_FIELD = 'workspaceColors'\n\n/** The most workspaces a person may pick a color for. */\nexport const WORKSPACE_COLORS_MAX = 100\n\n/** `users/{uid}` field holding the apps' theme, synced across devices. */\nexport const APP_THEME_FIELD = 'appTheme'\n\n/** The longest label a starred or recent item keeps. */\nexport const ACCOUNT_ITEM_LABEL_MAX = 120\n\n/** A picked color: `#` and six hex digits. */\nexport const ACCOUNT_COLOR_PATTERN = '^#[0-9A-Fa-f]{6}$'\n\n/** The color dot a starred item may carry, named so each platform draws it from its theme. */\nexport type StarColor =\n | 'blue'\n | 'purple'\n | 'pink'\n | 'red'\n | 'orange'\n | 'yellow'\n | 'green'\n | 'grey'\n\n/** Every star color, in the order the picker lists them. */\nexport const STAR_COLORS: readonly StarColor[] = [\n 'blue',\n 'purple',\n 'pink',\n 'red',\n 'orange',\n 'yellow',\n 'green',\n 'grey',\n]\n\n/**\n * A screen or a record the person can come back to: what it is, where it\n * belongs, what it was called, and the native screen that opens it.\n */\nexport interface AccountItemRef {\n /**\n * `screen` for a place in the app (a nav manifest row), otherwise the\n * one-box search kind of the record (`page`, `order`, `contact`, …).\n */\n kind: string\n /** The nav row id for a `screen`, otherwise the record's document id. */\n id: string\n /** The workspace it belongs to. */\n orgId: string\n /** The site, for an item that belongs to one. */\n hostId?: string\n /** What it was called when it was starred or opened. */\n label: string\n /** The native screen that opens it. */\n screen: string\n /** That screen's params. */\n params?: Record<string, string>\n}\n\n/** One starred item. */\nexport interface StarredItem extends AccountItemRef {\n color?: StarColor\n starredAtMs: number\n}\n\n/** One recently opened item. */\nexport interface RecentItem extends AccountItemRef {\n openedAtMs: number\n}\n\nexport type AppAppearance = 'system' | 'light' | 'dark'\n\nexport type AppThemeName = 'aglyn' | 'quiet' | 'night' | 'ocean' | 'warm' | 'highContrast'\n\nexport type AppDensity = 'comfortable' | 'compact'\n\nexport type AppTextSize = 'system' | 'small' | 'medium' | 'large' | 'extraLarge'\n\nexport type AppSidebarStyle = 'tinted' | 'plain'\n\n/** The apps' look, saved on the account so it follows the person to every device. */\nexport interface AppThemePrefs {\n /** Light, dark or the system's. */\n appearance: AppAppearance\n /** The theme: rail, sidebar tint, surfaces and accent for light and dark together. */\n theme: AppThemeName\n /** `theme` for the theme's own accent, or a `#RRGGBB` the person picked. */\n accent: string\n density: AppDensity\n /** `system` follows Dynamic Type or the font scale; the rest are the Mac and Windows sizes. */\n textSize: AppTextSize\n /**\n * `plain` keeps the sidebar on the theme's surface; `tinted` lays the THEME's accent over it at 5%, on a theme other\n * than Aglyn only (Aglyn's sidebar is always neutral). A workspace's color never tints it: that is its rail tile's.\n */\n sidebarStyle: AppSidebarStyle\n /** The app icon's id: `aglyn`, or one of the alternates the apps ship. */\n appIcon: string\n /** A workspace's own brand color tints the app while you are in it. */\n useWorkspaceBrand: boolean\n}\n\n/** What a person who never changed anything sees. */\nexport const DEFAULT_APP_THEME: AppThemePrefs = {\n appearance: 'system',\n theme: 'aglyn',\n accent: 'theme',\n density: 'comfortable',\n textSize: 'system',\n // Plain: a sidebar keeps the theme's neutral ground unless the person picks Tinted (AGL-3990).\n sidebarStyle: 'plain',\n appIcon: 'aglyn',\n useWorkspaceBrand: true,\n}\n\n/** Every value each closed theme field accepts, in the order a picker lists them. */\nexport const APP_APPEARANCES: readonly AppAppearance[] = ['system', 'light', 'dark']\nexport const APP_THEME_NAMES: readonly AppThemeName[] = [\n 'aglyn',\n 'quiet',\n 'night',\n 'ocean',\n 'warm',\n 'highContrast',\n]\nexport const APP_DENSITIES: readonly AppDensity[] = ['comfortable', 'compact']\nexport const APP_TEXT_SIZES: readonly AppTextSize[] = [\n 'system',\n 'small',\n 'medium',\n 'large',\n 'extraLarge',\n]\nexport const APP_SIDEBAR_STYLES: readonly AppSidebarStyle[] = ['tinted', 'plain']\n\n/** The longest app icon id. */\nexport const APP_ICON_ID_MAX = 40\n\nfunction field(profile: unknown, name: string): unknown {\n return profile && typeof profile === 'object'\n ? (profile as Record<string, unknown>)[name]\n : undefined\n}\n\nfunction idList(value: unknown): string[] {\n if (!Array.isArray(value)) return []\n return [\n ...new Set(\n value.filter((entry): entry is string => typeof entry === 'string' && entry !== ''),\n ),\n ]\n}\n\n/** Whether a value is a picked color, `#` and six hex digits. */\nexport function isAccountColor(value: unknown): value is string {\n return typeof value === 'string' && new RegExp(ACCOUNT_COLOR_PATTERN).test(value)\n}\n\n// ── Pins ────────────────────────────────────────────────────────────────────\n\n/**\n * Every id the person stored as pinned, in their order, without repeats.\n *\n * Anything that is not a list of non-empty strings reads as no pins, so a\n * stray value can never take a switcher down. May hold more than\n * {@link PINNED_ORGS_MAX} for an account that pinned before the cap; read\n * {@link effectivePinnedOrgs} for the pins to show.\n */\nexport function readPinnedOrgs(profile: unknown): string[] {\n return idList(field(profile, PINNED_ORGS_FIELD))\n}\n\n/** The pins in force: the first {@link PINNED_ORGS_MAX} stored, until the person picks. */\nexport function effectivePinnedOrgs(stored: readonly string[]): string[] {\n return idList(stored).slice(0, PINNED_ORGS_MAX)\n}\n\n/** The account pinned more than the cap before there was one, and has to pick which to keep. */\nexport function pinnedOrgsOverCap(stored: readonly string[]): boolean {\n return idList(stored).length > PINNED_ORGS_MAX\n}\n\nexport type PinOrgOutcome = 'pinned' | 'alreadyPinned' | 'full'\n\nexport interface PinOrgResult {\n /** The pins after the request: unchanged unless `outcome` is `pinned`. */\n pinned: string[]\n outcome: PinOrgOutcome\n}\n\n/**\n * Pins a workspace at the end of the list, or says the list is full. A full\n * list is never made room in quietly: the caller asks \"Pinned is full.\n * Replace one?\" and calls {@link replacePinnedOrg} with the answer.\n */\nexport function pinOrg(pinned: readonly string[], orgId: string): PinOrgResult {\n const current = effectivePinnedOrgs(pinned)\n if (!orgId) return { pinned: current, outcome: 'alreadyPinned' }\n if (current.includes(orgId)) return { pinned: current, outcome: 'alreadyPinned' }\n if (current.length >= PINNED_ORGS_MAX) return { pinned: current, outcome: 'full' }\n return { pinned: [...current, orgId], outcome: 'pinned' }\n}\n\n/** The pins without one workspace. */\nexport function unpinOrg(pinned: readonly string[], orgId: string): string[] {\n return idList(pinned).filter((id) => id !== orgId)\n}\n\n/**\n * The pins with `orgId` in the place `replacing` held — the answer to\n * \"Pinned is full. Replace one?\". Unchanged when `replacing` is not pinned\n * or `orgId` already is.\n */\nexport function replacePinnedOrg(\n pinned: readonly string[],\n replacing: string,\n orgId: string,\n): string[] {\n const current = effectivePinnedOrgs(pinned)\n if (!orgId || current.includes(orgId) || !current.includes(replacing)) return current\n return current.map((id) => (id === replacing ? orgId : id))\n}\n\n/**\n * The answer to \"Keep which 5?\": the stored pins the person ticked, in the\n * order they were pinned, never more than the cap.\n */\nexport function keepPinnedOrgs(stored: readonly string[], keep: readonly string[]): string[] {\n const kept = new Set(keep)\n return idList(stored)\n .filter((id) => kept.has(id))\n .slice(0, PINNED_ORGS_MAX)\n}\n\n/** The pins with one moved up (`-1`) or down (`1`) a place; unchanged at an end. */\nexport function movePinnedOrg(pinned: readonly string[], orgId: string, offset: number): string[] {\n const current = effectivePinnedOrgs(pinned)\n const from = current.indexOf(orgId)\n const to = from + (offset < 0 ? -1 : 1)\n if (from === -1 || to < 0 || to >= current.length) return current\n const next = [...current]\n next[from] = next[to]\n next[to] = orgId\n return next\n}\n\n// ── Site pins ───────────────────────────────────────────────────────────────\n\n/** `users/{uid}` field holding the sites the person pinned, each with its workspace (AGL-4005). */\nexport const PINNED_HOSTS_FIELD = 'pinnedHosts'\n\n/** The most sites a person may pin in one workspace: five, as for workspaces. */\nexport const PINNED_HOSTS_PER_WORKSPACE = 5\n\n/**\n * The most site pins the account keeps across every workspace, the bound the\n * Firestore rules hold. Nobody meets it by pinning: it takes twenty\n * workspaces with five each. Past it, the oldest pins of OTHER workspaces\n * give way (see {@link pinHost}).\n */\nexport const PINNED_HOSTS_MAX = 100\n\n/**\n * One pinned site and the workspace it belongs to. The workspace rides with\n * the pin so a surface that holds only one workspace's sites (the site\n * switcher's window) can tell its own pins apart without reading every site.\n */\nexport interface PinnedHost {\n orgId: string\n hostId: string\n}\n\nfunction pinnedHostList(value: unknown): PinnedHost[] {\n if (!Array.isArray(value)) return []\n const seen = new Set<string>()\n const pins: PinnedHost[] = []\n for (const entry of value) {\n if (!entry || typeof entry !== 'object') continue\n const { orgId, hostId } = entry as Record<string, unknown>\n if (typeof orgId !== 'string' || !orgId) continue\n if (typeof hostId !== 'string' || !hostId || seen.has(hostId)) continue\n seen.add(hostId)\n pins.push({ orgId, hostId })\n }\n return pins\n}\n\n/**\n * Every site pin the person stored, in the order pinned, without repeats.\n * Anything that is not a `{ orgId, hostId }` reads as no pin, so a stray\n * value can never take the sites list down.\n */\nexport function readPinnedHosts(profile: unknown): PinnedHost[] {\n return pinnedHostList(field(profile, PINNED_HOSTS_FIELD))\n}\n\n/** One workspace's pinned site ids, in the order pinned, at most five. */\nexport function workspacePinnedHosts(stored: readonly PinnedHost[], orgId: string): string[] {\n return pinnedHostList(stored)\n .filter((pin) => pin.orgId === orgId)\n .map((pin) => pin.hostId)\n .slice(0, PINNED_HOSTS_PER_WORKSPACE)\n}\n\nexport interface PinHostResult {\n /** Every stored pin after the request: unchanged unless `outcome` is `pinned`. */\n pinnedHosts: PinnedHost[]\n outcome: PinOrgOutcome\n}\n\n/**\n * Pins a site at the end of its workspace's pins, or says that workspace\n * already has five. As with workspaces, a full list is never made room in\n * quietly: the caller asks \"Pinned is full. Replace one?\" and calls\n * {@link replacePinnedHost} with the answer. Only the account-wide bound\n * ({@link PINNED_HOSTS_MAX}) makes room, and only from other workspaces.\n */\nexport function pinHost(stored: readonly PinnedHost[], pin: PinnedHost): PinHostResult {\n const current = pinnedHostList(stored)\n if (!pin.orgId || !pin.hostId) return { pinnedHosts: current, outcome: 'alreadyPinned' }\n const inWorkspace = workspacePinnedHosts(current, pin.orgId)\n if (inWorkspace.includes(pin.hostId)) return { pinnedHosts: current, outcome: 'alreadyPinned' }\n if (inWorkspace.length >= PINNED_HOSTS_PER_WORKSPACE) {\n return { pinnedHosts: current, outcome: 'full' }\n }\n // A site pinned under the workspace it has since moved out of moves with it.\n const next = [\n ...current.filter((entry) => entry.hostId !== pin.hostId),\n { orgId: pin.orgId, hostId: pin.hostId },\n ]\n while (next.length > PINNED_HOSTS_MAX) {\n const oldest = next.findIndex((entry) => entry.orgId !== pin.orgId)\n if (oldest === -1) break\n next.splice(oldest, 1)\n }\n return { pinnedHosts: next, outcome: 'pinned' }\n}\n\n/** The stored pins without one site. */\nexport function unpinHost(stored: readonly PinnedHost[], hostId: string): PinnedHost[] {\n return pinnedHostList(stored).filter((entry) => entry.hostId !== hostId)\n}\n\n/**\n * The stored pins with `pin` in the place `replacing` held in the same\n * workspace: the answer to \"Pinned is full. Replace one?\". Unchanged when\n * `replacing` is not one of that workspace's pins or `pin` already is.\n */\nexport function replacePinnedHost(\n stored: readonly PinnedHost[],\n replacing: string,\n pin: PinnedHost,\n): PinnedHost[] {\n const current = pinnedHostList(stored)\n const inWorkspace = workspacePinnedHosts(current, pin.orgId)\n if (!pin.hostId || inWorkspace.includes(pin.hostId) || !inWorkspace.includes(replacing)) {\n return current\n }\n return current\n .filter((entry) => entry.hostId !== pin.hostId)\n .map((entry) =>\n entry.hostId === replacing ? { orgId: pin.orgId, hostId: pin.hostId } : entry,\n )\n}\n\n// ── Recent workspaces and the rail ──────────────────────────────────────────\n\n/** The recently opened workspaces as stored, newest first. */\nexport function readRecentOrgs(profile: unknown): string[] {\n return idList(field(profile, RECENT_ORGS_FIELD)).slice(0, RECENT_ORGS_MAX)\n}\n\n/** The recent workspaces after opening one: it moves to the front, the oldest falls off. */\nexport function recordRecentOrg(recent: readonly string[], orgId: string): string[] {\n if (!orgId) return idList(recent).slice(0, RECENT_ORGS_MAX)\n return [orgId, ...idList(recent).filter((id) => id !== orgId)].slice(0, RECENT_ORGS_MAX)\n}\n\n/** What the workspace rail shows. */\nexport interface RailWorkspaces {\n /** Pinned, at the top, in the person's order. */\n pinned: string[]\n /** Below the divider: recently opened and not pinned, at most {@link RAIL_RECENT_ORGS}. */\n recent: string[]\n /**\n * Workspaces listed on the rail beyond the pins and the recents. Always\n * empty: every account reaches the rest through the All tile\n * (AGL-3996). The field stays so the apps that read it need no change.\n */\n rest: string[]\n /** Whether the last tile is \"All workspaces\", opening the searchable switcher: whenever there is a workspace. */\n allTile: boolean\n /** How many workspaces the person belongs to, shown under the All tile. */\n total: number\n}\n\n/**\n * The rail for one account, the same for every account however few\n * workspaces it has (Figma Rail 12:338, \"Many workspaces\"): up to five\n * pinned, a divider, up to three recent under \"Recent\", a divider, then the\n * \"All workspaces\" tile with the total, which opens the switcher where pins\n * are edited. A small account that saw every tile in one unlabeled column\n * had no way into the switcher and no Recent label or divider. `orgIds` is every membership, in the switcher's order;\n * an id the person no longer belongs to is ignored.\n */\nexport function railWorkspaces(\n orgIds: readonly string[],\n pinned: readonly string[],\n recent: readonly string[],\n): RailWorkspaces {\n const members = idList(orgIds)\n const belongs = new Set(members)\n const pins = effectivePinnedOrgs(pinned).filter((id) => belongs.has(id))\n const pinnedSet = new Set(pins)\n return {\n pinned: pins,\n recent: idList(recent)\n .filter((id) => belongs.has(id) && !pinnedSet.has(id))\n .slice(0, RAIL_RECENT_ORGS),\n rest: [],\n allTile: members.length > 0,\n total: members.length,\n }\n}\n\n/**\n * The one letter a workspace tile without a logo shows (Figma Rail/Workspace\n * tile, Type=Initial): the first letter or digit of its name, upper-cased;\n * \"?\" for a name with neither. One letter, not two: the tile's color, picked\n * per workspace, tells two workspaces with the same letter apart.\n */\nexport function workspaceInitial(name: string): string {\n const first = /[\\p{L}\\p{N}]/u.exec(name ?? '')\n return first ? first[0].toUpperCase() : '?'\n}\n\n// ── Starred and recent items ────────────────────────────────────────────────\n\n/** One item's identity: the same screen or record in the same place. */\nexport function accountItemKey(\n item: Pick<AccountItemRef, 'kind' | 'id' | 'orgId' | 'hostId'>,\n): string {\n return `${item.kind}:${item.orgId}:${item.hostId ?? ''}:${item.id}`\n}\n\nfunction stringMap(value: unknown): Record<string, string> | undefined {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return undefined\n const out: Record<string, string> = {}\n for (const [key, entry] of Object.entries(value as Record<string, unknown>)) {\n if (typeof entry === 'string') out[key] = entry\n }\n return Object.keys(out).length ? out : undefined\n}\n\nfunction itemRef(value: unknown): AccountItemRef | null {\n if (!value || typeof value !== 'object') return null\n const raw = value as Record<string, unknown>\n const text = (key: string) => (typeof raw[key] === 'string' ? (raw[key] as string) : '')\n const kind = text('kind')\n const id = text('id')\n const orgId = text('orgId')\n const screen = text('screen')\n if (!kind || !id || !orgId || !screen) return null\n const hostId = text('hostId')\n const params = stringMap(raw['params'])\n return {\n kind,\n id,\n orgId,\n ...(hostId ? { hostId } : {}),\n label: text('label').slice(0, ACCOUNT_ITEM_LABEL_MAX),\n screen,\n ...(params ? { params } : {}),\n }\n}\n\nfunction at(value: unknown): number {\n return typeof value === 'number' && Number.isFinite(value) ? value : 0\n}\n\nfunction isStarColor(value: unknown): value is StarColor {\n return (STAR_COLORS as readonly unknown[]).includes(value)\n}\n\n/** The starred items as stored, each well formed, without repeats, never more than the cap. */\nexport function readStarred(profile: unknown): StarredItem[] {\n const stored = field(profile, STARRED_FIELD)\n if (!Array.isArray(stored)) return []\n const seen = new Set<string>()\n const out: StarredItem[] = []\n for (const entry of stored) {\n const ref = itemRef(entry)\n if (!ref) continue\n const key = accountItemKey(ref)\n if (seen.has(key)) continue\n seen.add(key)\n const color = (entry as Record<string, unknown>)['color']\n out.push({\n ...ref,\n ...(isStarColor(color) ? { color } : {}),\n starredAtMs: at((entry as Record<string, unknown>)['starredAtMs']),\n })\n }\n return out.slice(0, STARRED_MAX)\n}\n\nexport type StarOutcome = 'starred' | 'unstarred' | 'full'\n\nexport interface StarResult {\n /** The starred items after the request: unchanged when `outcome` is `full`. */\n starred: StarredItem[]\n outcome: StarOutcome\n}\n\n/** Stars an item at the end of the list, or unstars it; a full list says so instead. */\nexport function toggleStarred(\n starred: readonly StarredItem[],\n item: AccountItemRef,\n nowMs: number,\n): StarResult {\n const current = readStarred({ [STARRED_FIELD]: starred })\n const ref = itemRef(item)\n if (!ref) return { starred: current, outcome: 'full' }\n const key = accountItemKey(ref)\n if (current.some((entry) => accountItemKey(entry) === key)) {\n return {\n starred: current.filter((entry) => accountItemKey(entry) !== key),\n outcome: 'unstarred',\n }\n }\n if (current.length >= STARRED_MAX) return { starred: current, outcome: 'full' }\n return { starred: [...current, { ...ref, starredAtMs: nowMs }], outcome: 'starred' }\n}\n\n/** The starred items with one item's color dot set, or cleared with `null`. */\nexport function setStarColor(\n starred: readonly StarredItem[],\n key: string,\n color: StarColor | null,\n): StarredItem[] {\n return readStarred({ [STARRED_FIELD]: starred }).map((entry) => {\n if (accountItemKey(entry) !== key) return entry\n const next: StarredItem = { ...entry }\n delete next.color\n return color && isStarColor(color) ? { ...next, color } : next\n })\n}\n\n/** The recent items as stored, newest first, each well formed, never more than the cap. */\nexport function readRecents(profile: unknown): RecentItem[] {\n const stored = field(profile, RECENTS_FIELD)\n if (!Array.isArray(stored)) return []\n const seen = new Set<string>()\n const out: RecentItem[] = []\n for (const entry of stored) {\n const ref = itemRef(entry)\n if (!ref) continue\n const key = accountItemKey(ref)\n if (seen.has(key)) continue\n seen.add(key)\n out.push({ ...ref, openedAtMs: at((entry as Record<string, unknown>)['openedAtMs']) })\n }\n return out.slice(0, RECENTS_MAX)\n}\n\n/** The recent items after opening one: it moves to the front, the oldest falls off. */\nexport function recordRecent(\n recents: readonly RecentItem[],\n item: AccountItemRef,\n nowMs: number,\n): RecentItem[] {\n const current = readRecents({ [RECENTS_FIELD]: recents })\n const ref = itemRef(item)\n if (!ref) return current\n const key = accountItemKey(ref)\n return [\n { ...ref, openedAtMs: nowMs },\n ...current.filter((entry) => accountItemKey(entry) !== key),\n ].slice(0, RECENTS_MAX)\n}\n\n// ── Workspace colors ────────────────────────────────────────────────────────\n\n/** The colors the person picked, by workspace id, the valid ones only. */\nexport function readWorkspaceColors(profile: unknown): Record<string, string> {\n const stored = field(profile, WORKSPACE_COLORS_FIELD)\n if (!stored || typeof stored !== 'object' || Array.isArray(stored)) return {}\n const out: Record<string, string> = {}\n for (const [orgId, color] of Object.entries(stored as Record<string, unknown>)) {\n if (orgId && isAccountColor(color)) out[orgId] = color\n if (Object.keys(out).length >= WORKSPACE_COLORS_MAX) break\n }\n return out\n}\n\n/**\n * The colors a workspace's tile takes when nothing else gives it one\n * ({@link workspaceStableColor}): the console's blue for text on a light\n * ground (primary.dark), deep tones of the brand palette's\n * violet and pink, and a rose, orange, gold, green and teal beside them,\n * each dark enough that the tile's white initial reads at 4.5:1 or more. The\n * slate is left out: it is the tile of a workspace with no id at all.\n */\nexport const WORKSPACE_STABLE_COLORS: readonly string[] = [\n '#0077AD',\n '#6A4FD8',\n '#A62BBF',\n '#C2185B',\n '#B4501A',\n '#8A6A00',\n '#2E7D5B',\n '#00796B',\n]\n\n/**\n * The color a workspace with no picked, brand or logo color shows on its\n * tile: one of {@link WORKSPACE_STABLE_COLORS}, chosen by its id, so the same\n * workspace has the same color on every device and in every app, and two\n * workspaces with the same initial usually differ. The id is hashed with\n * 32-bit FNV-1a over its UTF-16 code units, which each platform computes the\n * same way. Null for an empty id.\n */\nexport function workspaceStableColor(orgId: unknown): string | null {\n if (typeof orgId !== 'string' || orgId === '') return null\n let hash = 0x811c9dc5\n for (let i = 0; i < orgId.length; i++) {\n hash ^= orgId.charCodeAt(i)\n hash = Math.imul(hash, 0x01000193) >>> 0\n }\n return WORKSPACE_STABLE_COLORS[hash % WORKSPACE_STABLE_COLORS.length] ?? null\n}\n\nexport type WorkspaceColorSource = 'picked' | 'brand' | 'logo' | 'stable' | 'none'\n\nexport interface WorkspaceColor {\n /** `#RRGGBB`, or null when nothing gives the workspace a color. */\n color: string | null\n source: WorkspaceColorSource\n /** Whether the app is tinted with it while you are in the workspace. */\n tintsApp: boolean\n}\n\n/**\n * A workspace's color: the one the person picked, else the workspace's brand\n * color (`brandingProfile.primaryColor`), else a color taken from its logo\n * (Zach, 2026-10-18). The rail tile always shows it; the app is tinted with\n * it while you are in the workspace unless the person turned \"Use each\n * workspace's brand\" off, which stops the brand and logo colors tinting the\n * app (a picked color still does: the person chose it).\n *\n * Given the workspace's id, a workspace with none of the three still gets a\n * color: its stable one ({@link workspaceStableColor}). That one colors only\n * its tile (the rail, the pickers, the menus, the sidebar's header), never\n * the app.\n */\nexport function resolveWorkspaceColor(\n picked: unknown,\n brandColor: unknown,\n logoColor: unknown,\n useWorkspaceBrand: boolean,\n orgId?: unknown,\n): WorkspaceColor {\n if (isAccountColor(picked)) return { color: picked, source: 'picked', tintsApp: true }\n if (isAccountColor(brandColor)) {\n return { color: brandColor, source: 'brand', tintsApp: useWorkspaceBrand }\n }\n if (isAccountColor(logoColor)) {\n return { color: logoColor, source: 'logo', tintsApp: useWorkspaceBrand }\n }\n const stable = workspaceStableColor(orgId)\n if (stable) return { color: stable, source: 'stable', tintsApp: false }\n return { color: null, source: 'none', tintsApp: false }\n}\n\n// ── Theme ───────────────────────────────────────────────────────────────────\n\nfunction oneOf<T extends string>(value: unknown, allowed: readonly T[], fallback: T): T {\n return (allowed as readonly unknown[]).includes(value) ? (value as T) : fallback\n}\n\n/** The synced theme, every field filled: a missing or unknown value reads as the default. */\nexport function readAppTheme(profile: unknown): AppThemePrefs {\n const stored = field(profile, APP_THEME_FIELD)\n const raw =\n stored && typeof stored === 'object' && !Array.isArray(stored)\n ? (stored as Record<string, unknown>)\n : {}\n const accent = raw['accent']\n const appIcon = raw['appIcon']\n return {\n appearance: oneOf(raw['appearance'], APP_APPEARANCES, DEFAULT_APP_THEME.appearance),\n theme: oneOf(raw['theme'], APP_THEME_NAMES, DEFAULT_APP_THEME.theme),\n accent: accent === 'theme' || isAccountColor(accent) ? accent : DEFAULT_APP_THEME.accent,\n density: oneOf(raw['density'], APP_DENSITIES, DEFAULT_APP_THEME.density),\n textSize: oneOf(raw['textSize'], APP_TEXT_SIZES, DEFAULT_APP_THEME.textSize),\n sidebarStyle: oneOf(raw['sidebarStyle'], APP_SIDEBAR_STYLES, DEFAULT_APP_THEME.sidebarStyle),\n appIcon:\n typeof appIcon === 'string' && appIcon !== '' && appIcon.length <= APP_ICON_ID_MAX\n ? appIcon\n : DEFAULT_APP_THEME.appIcon,\n useWorkspaceBrand:\n typeof raw['useWorkspaceBrand'] === 'boolean'\n ? (raw['useWorkspaceBrand'] as boolean)\n : DEFAULT_APP_THEME.useWorkspaceBrand,\n }\n}\n\n// ── The phone's tab bar (AGL-4006) ──────────────────────────────────────────\n\n/** `users/{uid}` field holding the areas the person keeps in the phone's tab bar, per site and per workspace. */\nexport const TAB_BARS_FIELD = 'tabBars'\n\n/**\n * The most areas one tab bar holds beside Home: iOS and\n * Material take five destinations at most, and nothing ever overflows into a\n * More tab. With four, Create leaves the bar for the top bar.\n */\nexport const TAB_BAR_AREAS_MAX = 4\n\n/** The most sites and workspaces the account keeps a tab bar for, the bound the Firestore rules hold. */\nexport const TAB_BARS_MAX = 100\n\n/** The tab bar's own slots beside the areas: Home, always first, and Create new. */\nexport const TAB_BAR_HOME = 'home'\nexport const TAB_BAR_CREATE = 'create'\n\n/** One site's or workspace's tab bar. */\nexport interface TabBarPins {\n /** `site:<hostId>` or `org:<orgId>` ({@link tabBarScope}). */\n scope: string\n /** Nav manifest row ids, in the person's order, at most {@link TAB_BAR_AREAS_MAX}. */\n areas: string[]\n /**\n * The person pinned, unpinned or reordered here by hand. Until then the\n * first areas they open take the free spots and stay (the default the\n * orchestrator settled on 2026-10-20: nothing guessed, nothing rotating);\n * after it, only the person changes the bar.\n */\n chosen: boolean\n}\n\nexport type TabPinOutcome = 'pinned' | 'alreadyPinned' | 'full'\n\nexport interface TabPinResult {\n /** Every stored tab bar after the request: unchanged unless `outcome` is `pinned`. */\n tabBars: TabBarPins[]\n outcome: TabPinOutcome\n}\n\n/** What a phone's tab bar shows, in order, and where Create new goes. */\nexport interface TabBarLayout {\n /** {@link TAB_BAR_HOME}, the areas, and {@link TAB_BAR_CREATE} in the centre unless it moved to the top bar. */\n slots: string[]\n /** Four areas fill the bar, so Create new sits in the top bar beside the AI button. */\n createInTopBar: boolean\n}\n\n/** The key of one site's tab bar, or the whole workspace's. */\nexport function tabBarScope(orgId: string, hostId?: string | null): string {\n return hostId ? `site:${hostId}` : `org:${orgId}`\n}\n\nfunction tabAreaList(value: unknown): string[] {\n return idList(value)\n .filter((id) => id !== TAB_BAR_HOME && id !== TAB_BAR_CREATE)\n .slice(0, TAB_BAR_AREAS_MAX)\n}\n\nfunction tabBarList(value: unknown): TabBarPins[] {\n if (!Array.isArray(value)) return []\n const seen = new Set<string>()\n const out: TabBarPins[] = []\n for (const entry of value) {\n if (!entry || typeof entry !== 'object') continue\n const raw = entry as Record<string, unknown>\n const scope = raw['scope']\n if (typeof scope !== 'string' || !/^(site|org):./.test(scope) || seen.has(scope)) continue\n seen.add(scope)\n out.push({ scope, areas: tabAreaList(raw['areas']), chosen: raw['chosen'] === true })\n }\n return out.slice(-TAB_BARS_MAX)\n}\n\n/**\n * Every tab bar the person keeps, each well formed, without repeats. Anything\n * that is not a `{ scope, areas, chosen }` reads as no tab bar, so a stray\n * value can never take the phone's shell down.\n */\nexport function readTabBars(profile: unknown): TabBarPins[] {\n return tabBarList(field(profile, TAB_BARS_FIELD))\n}\n\n/** One scope's areas, in the person's order. */\nexport function tabBarAreas(tabBars: readonly TabBarPins[], scope: string): string[] {\n return tabBarList(tabBars).find((bar) => bar.scope === scope)?.areas ?? []\n}\n\n/**\n * Every tab bar with one scope's replaced. A scope seen for the first time\n * goes last; past {@link TAB_BARS_MAX} the oldest OTHER scopes give way.\n */\nfunction withTabBar(tabBars: readonly TabBarPins[], next: TabBarPins): TabBarPins[] {\n const current = tabBarList(tabBars)\n const at = current.findIndex((bar) => bar.scope === next.scope)\n const out = at === -1 ? [...current, next] : current.map((bar, index) => (index === at ? next : bar))\n while (out.length > TAB_BARS_MAX) {\n const oldest = out.findIndex((bar) => bar.scope !== next.scope)\n if (oldest === -1) break\n out.splice(oldest, 1)\n }\n return out\n}\n\n/**\n * Pins an area at the end of a scope's tab bar (long-press a tile, \"Add to tab\n * bar\"), or says the bar is full: a full bar is never made room in quietly.\n */\nexport function pinTabArea(\n tabBars: readonly TabBarPins[],\n scope: string,\n area: string,\n): TabPinResult {\n const current = tabBarList(tabBars)\n const areas = tabBarAreas(current, scope)\n if (!area || area === TAB_BAR_HOME || area === TAB_BAR_CREATE || areas.includes(area)) {\n return { tabBars: current, outcome: 'alreadyPinned' }\n }\n if (areas.length >= TAB_BAR_AREAS_MAX) return { tabBars: current, outcome: 'full' }\n return {\n tabBars: withTabBar(current, { scope, areas: [...areas, area], chosen: true }),\n outcome: 'pinned',\n }\n}\n\n/** A scope's tab bar without one area; the person chose, so opened areas no longer fill the spot. */\nexport function unpinTabArea(\n tabBars: readonly TabBarPins[],\n scope: string,\n area: string,\n): TabBarPins[] {\n const areas = tabBarAreas(tabBars, scope)\n return withTabBar(tabBars, { scope, areas: areas.filter((id) => id !== area), chosen: true })\n}\n\n/** A scope's tab bar with one area moved left (`-1`) or right (`1`) a place; unchanged at an end. */\nexport function moveTabArea(\n tabBars: readonly TabBarPins[],\n scope: string,\n area: string,\n offset: number,\n): TabBarPins[] {\n const areas = tabBarAreas(tabBars, scope)\n const from = areas.indexOf(area)\n const to = from + (offset < 0 ? -1 : 1)\n if (from === -1 || to < 0 || to >= areas.length) return tabBarList(tabBars)\n const next = [...areas]\n next[from] = next[to]\n next[to] = area\n return withTabBar(tabBars, { scope, areas: next, chosen: true })\n}\n\n/** A scope's tab bar as the Tab bar sheet left it: these areas, in this order, at most four. */\nexport function setTabAreas(\n tabBars: readonly TabBarPins[],\n scope: string,\n areas: readonly string[],\n): TabBarPins[] {\n return withTabBar(tabBars, { scope, areas: tabAreaList(areas), chosen: true })\n}\n\n/**\n * The default before anyone pins: an area the person opens takes a free spot\n * and stays there, until the bar is full or the person changes it by hand.\n * Unchanged once the scope is `chosen`, the area is in the bar already, or the\n * bar is full.\n */\nexport function autoPinTabArea(\n tabBars: readonly TabBarPins[],\n scope: string,\n area: string,\n): TabBarPins[] {\n const current = tabBarList(tabBars)\n const bar = current.find((entry) => entry.scope === scope)\n const areas = bar?.areas ?? []\n if (!area || area === TAB_BAR_HOME || area === TAB_BAR_CREATE) return current\n if (bar?.chosen || areas.includes(area) || areas.length >= TAB_BAR_AREAS_MAX) return current\n return withTabBar(current, { scope, areas: [...areas, area], chosen: false })\n}\n\n/**\n * The tab bar to draw: Home first, then the pinned areas the scope can open\n * (`available`, the Home tiles' ids in this build), with Create new in the\n * centre slot. Four areas fill the bar, and Create moves to the top bar.\n */\nexport function tabBarLayout(areas: readonly string[], available: readonly string[]): TabBarLayout {\n const open = new Set(available)\n const shown = tabAreaList(areas).filter((id) => open.has(id))\n if (shown.length >= TAB_BAR_AREAS_MAX) {\n return { slots: [TAB_BAR_HOME, ...shown], createInTopBar: true }\n }\n const slots = [TAB_BAR_HOME, ...shown]\n slots.splice(Math.floor((shown.length + 2) / 2), 0, TAB_BAR_CREATE)\n return { slots, createInTopBar: false }\n}\n\n// ── Who is signed in ────────────────────────────────────────────────────────\n\n/**\n * `users/{uid}` field holding the person's own picture (AGL-1961). Lowercase\n * `url`: the roster's `photoURL` spelling reads as nothing here.\n */\nexport const ACCOUNT_PHOTO_FIELD = 'photoUrl'\n\nfunction trimmed(value: unknown): string {\n return typeof value === 'string' ? value.trim() : ''\n}\n\n/**\n * The person's own picture, the same answer in the console and both apps\n * (AGL-4010): `users/{uid}.photoUrl` first (the profile they edit, filled from\n * the identity provider on every sign-in), else the sign-in record's\n * `photoURL`, else null, so the caller draws initials. A blank value is never\n * a picture, so a photo in either place wins over an empty one in the other.\n * A library pick is stored as a `/api/media/cdn/...` path; resolving it to an\n * address is the caller's (`mediaPreviewURL` on native).\n */\nexport function readAccountPhoto(profile: unknown, authPhotoUrl: unknown): string | null {\n return trimmed(field(profile, ACCOUNT_PHOTO_FIELD)) || trimmed(authPhotoUrl) || null\n}\n\n/**\n * The person's own name, the same answer in the console and both apps\n * (AGL-2486, AGL-4010): the profile's first and last name, else the sign-in\n * record's display name (empty for an SSO account), else the email address,\n * else empty.\n */\nexport function readAccountName(\n profile: unknown,\n authDisplayName: unknown,\n email: unknown,\n): string {\n const fromProfile = [field(profile, 'firstName'), field(profile, 'lastName')]\n .map(trimmed)\n .filter(Boolean)\n .join(' ')\n return fromProfile || trimmed(authDisplayName) || trimmed(email)\n}\n"],"names":["PINNED_ORGS_FIELD","PINNED_ORGS_MAX","RECENT_ORGS_FIELD","RECENT_ORGS_MAX","RAIL_RECENT_ORGS","STARRED_FIELD","STARRED_MAX","RECENTS_FIELD","RECENTS_MAX","WORKSPACE_COLORS_FIELD","WORKSPACE_COLORS_MAX","APP_THEME_FIELD","ACCOUNT_ITEM_LABEL_MAX","ACCOUNT_COLOR_PATTERN","STAR_COLORS","DEFAULT_APP_THEME","appearance","theme","accent","density","textSize","sidebarStyle","appIcon","useWorkspaceBrand","APP_APPEARANCES","APP_THEME_NAMES","APP_DENSITIES","APP_TEXT_SIZES","APP_SIDEBAR_STYLES","APP_ICON_ID_MAX","field","profile","name","undefined","idList","value","Array","isArray","Set","filter","entry","isAccountColor","RegExp","test","readPinnedOrgs","effectivePinnedOrgs","stored","slice","pinnedOrgsOverCap","length","pinOrg","pinned","orgId","current","outcome","includes","unpinOrg","id","replacePinnedOrg","replacing","map","keepPinnedOrgs","keep","kept","has","movePinnedOrg","offset","from","indexOf","to","next","PINNED_HOSTS_FIELD","PINNED_HOSTS_PER_WORKSPACE","PINNED_HOSTS_MAX","pinnedHostList","seen","pins","hostId","add","push","readPinnedHosts","workspacePinnedHosts","pin","pinHost","pinnedHosts","inWorkspace","oldest","findIndex","splice","unpinHost","replacePinnedHost","readRecentOrgs","recordRecentOrg","recent","railWorkspaces","orgIds","members","belongs","pinnedSet","rest","allTile","total","workspaceInitial","first","exec","toUpperCase","accountItemKey","item","kind","stringMap","out","key","Object","entries","keys","itemRef","raw","text","screen","params","label","at","Number","isFinite","isStarColor","readStarred","ref","color","starredAtMs","toggleStarred","starred","nowMs","some","setStarColor","readRecents","openedAtMs","recordRecent","recents","readWorkspaceColors","WORKSPACE_STABLE_COLORS","workspaceStableColor","hash","i","charCodeAt","Math","imul","resolveWorkspaceColor","picked","brandColor","logoColor","source","tintsApp","stable","oneOf","allowed","fallback","readAppTheme","TAB_BARS_FIELD","TAB_BAR_AREAS_MAX","TAB_BARS_MAX","TAB_BAR_HOME","TAB_BAR_CREATE","tabBarScope","tabAreaList","tabBarList","scope","areas","chosen","readTabBars","tabBarAreas","tabBars","find","bar","withTabBar","index","pinTabArea","area","unpinTabArea","moveTabArea","setTabAreas","autoPinTabArea","tabBarLayout","available","open","shown","slots","createInTopBar","floor","ACCOUNT_PHOTO_FIELD","trimmed","trim","readAccountPhoto","authPhotoUrl","readAccountName","authDisplayName","email","fromProfile","Boolean","join"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BC,GAED,6EAA6E,GAC7E,OAAO,MAAMA,oBAAoB,aAAY;AAE7C,4EAA4E,GAC5E,OAAO,MAAMC,kBAAkB,EAAC;AAEhC,mFAAmF,GACnF,OAAO,MAAMC,oBAAoB,aAAY;AAE7C,kDAAkD,GAClD,OAAO,MAAMC,kBAAkB,EAAC;AAEhC,8DAA8D,GAC9D,OAAO,MAAMC,mBAAmB,EAAC;AAEjC,0EAA0E,GAC1E,OAAO,MAAMC,gBAAgB,UAAS;AAEtC,sCAAsC,GACtC,OAAO,MAAMC,cAAc,GAAE;AAE7B,8EAA8E,GAC9E,OAAO,MAAMC,gBAAgB,UAAS;AAEtC,2DAA2D,GAC3D,OAAO,MAAMC,cAAc,GAAE;AAE7B,gFAAgF,GAChF,OAAO,MAAMC,yBAAyB,kBAAiB;AAEvD,uDAAuD,GACvD,OAAO,MAAMC,uBAAuB,IAAG;AAEvC,wEAAwE,GACxE,OAAO,MAAMC,kBAAkB,WAAU;AAEzC,sDAAsD,GACtD,OAAO,MAAMC,yBAAyB,IAAG;AAEzC,4CAA4C,GAC5C,OAAO,MAAMC,wBAAwB,oBAAmB;AAaxD,0DAA0D,GAC1D,OAAO,MAAMC,cAAoC;IAC/C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAqED,mDAAmD,GACnD,OAAO,MAAMC,oBAAmC;IAC9CC,YAAY;IACZC,OAAO;IACPC,QAAQ;IACRC,SAAS;IACTC,UAAU;IACV,+FAA+F;IAC/FC,cAAc;IACdC,SAAS;IACTC,mBAAmB;AACrB,EAAC;AAED,mFAAmF,GACnF,OAAO,MAAMC,kBAA4C;IAAC;IAAU;IAAS;CAAO,CAAA;AACpF,OAAO,MAAMC,k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AyBC,QAAQG,iBAAiB;AAClF;AAEA;;;;;CAKC,GACD,OAAO,SAASC,gBACdlK,OAAgB,EAChBmK,eAAwB,EACxBC,KAAc;IAEd,MAAMC,cAAc;QAACtK,MAAMC,SAAS;QAAcD,MAAMC,SAAS;KAAY,CAC1E6B,GAAG,CAACiI,SACJtJ,MAAM,CAAC8J,SACPC,IAAI,CAAC;IACR,OAAOF,eAAeP,QAAQK,oBAAoBL,QAAQM;AAC5D"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/account-preferences.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * THE PREFERENCES A PERSON KEEPS ON THEIR ACCOUNT (AGL-3943).\n *\n * One documented shape on `users/{uid}`, read and written the same way by\n * the console and both native apps (docs/mobile/native-navigation.md):\n *\n * | field | shape | cap |\n * | -- | -- | -- |\n * | `pinnedOrgs` | workspace ids, in the order the person keeps them | 5 |\n * | `pinnedHosts` | {@link PinnedHost}s, in the order they were pinned | 500 in all, no cap a workspace |\n * | `recentOrgs` | workspace ids, most recently opened first | 8 |\n * | `starred` | {@link StarredItem}s, in the order they were starred | 50 |\n * | `recents` | {@link RecentItem}s, most recently opened first | 30 |\n * | `workspaceColors` | workspace id → `#RRGGBB` the person picked | 100 |\n * | `appTheme` | {@link AppThemePrefs}, the apps' look, synced | — |\n * | `tabBars` | {@link TabBarPins}, the phone's tab bar per site and per workspace | 4 areas each, 100 in all |\n *\n * The caps are held twice: here, by every writer, and by the Firestore rules,\n * which refuse a write that grows a list past its cap. A list that is ALREADY\n * past it (pins made before the cap, Zach 2026-10-18) may only shrink, so a\n * person with seven pins can still unpin one; the console asks them once\n * which five to keep, and until they answer the first five are the pins.\n *\n * A per-device override of the theme (\"this device only\") is the device's\n * own, kept in local storage on each platform, and never written here.\n *\n * NO IMPORTS, on purpose: the native apps read these constants, types and\n * the answers of these functions through the generated contracts, so it must\n * stay a plain module.\n */\n\n/** `users/{uid}` field holding the ids of the workspaces the person pinned. */\nexport const PINNED_ORGS_FIELD = 'pinnedOrgs'\n\n/** The most workspaces a person may pin, everywhere, the console included. */\nexport const PINNED_ORGS_MAX = 5\n\n/** `users/{uid}` field holding the workspaces opened most recently, newest first. */\nexport const RECENT_ORGS_FIELD = 'recentOrgs'\n\n/** How many recently opened workspaces are kept. */\nexport const RECENT_ORGS_MAX = 8\n\n/** How many recent workspaces the rail shows below the pins. */\nexport const RAIL_RECENT_ORGS = 3\n\n/** `users/{uid}` field holding the person's starred screens and records. */\nexport const STARRED_FIELD = 'starred'\n\n/** The most items a person may star. */\nexport const STARRED_MAX = 50\n\n/** `users/{uid}` field holding the screens and records opened most recently. */\nexport const RECENTS_FIELD = 'recents'\n\n/** How many recently opened screens and records are kept. */\nexport const RECENTS_MAX = 30\n\n/** `users/{uid}` field holding the color the person picked for each workspace. */\nexport const WORKSPACE_COLORS_FIELD = 'workspaceColors'\n\n/** The most workspaces a person may pick a color for. */\nexport const WORKSPACE_COLORS_MAX = 100\n\n/** `users/{uid}` field holding the apps' theme, synced across devices. */\nexport const APP_THEME_FIELD = 'appTheme'\n\n/** The longest label a starred or recent item keeps. */\nexport const ACCOUNT_ITEM_LABEL_MAX = 120\n\n/** A picked color: `#` and six hex digits. */\nexport const ACCOUNT_COLOR_PATTERN = '^#[0-9A-Fa-f]{6}$'\n\n/** The color dot a starred item may carry, named so each platform draws it from its theme. */\nexport type StarColor =\n | 'blue'\n | 'purple'\n | 'pink'\n | 'red'\n | 'orange'\n | 'yellow'\n | 'green'\n | 'grey'\n\n/** Every star color, in the order the picker lists them. */\nexport const STAR_COLORS: readonly StarColor[] = [\n 'blue',\n 'purple',\n 'pink',\n 'red',\n 'orange',\n 'yellow',\n 'green',\n 'grey',\n]\n\n/**\n * A screen or a record the person can come back to: what it is, where it\n * belongs, what it was called, and the native screen that opens it.\n */\nexport interface AccountItemRef {\n /**\n * `screen` for a place in the app (a nav manifest row), otherwise the\n * one-box search kind of the record (`page`, `order`, `contact`, …).\n */\n kind: string\n /** The nav row id for a `screen`, otherwise the record's document id. */\n id: string\n /** The workspace it belongs to. */\n orgId: string\n /** The site, for an item that belongs to one. */\n hostId?: string\n /** What it was called when it was starred or opened. */\n label: string\n /** The native screen that opens it. */\n screen: string\n /** That screen's params. */\n params?: Record<string, string>\n}\n\n/** One starred item. */\nexport interface StarredItem extends AccountItemRef {\n color?: StarColor\n starredAtMs: number\n}\n\n/** One recently opened item. */\nexport interface RecentItem extends AccountItemRef {\n openedAtMs: number\n}\n\nexport type AppAppearance = 'system' | 'light' | 'dark'\n\nexport type AppThemeName = 'aglyn' | 'quiet' | 'night' | 'ocean' | 'warm' | 'highContrast'\n\nexport type AppDensity = 'comfortable' | 'compact'\n\nexport type AppTextSize = 'system' | 'small' | 'medium' | 'large' | 'extraLarge'\n\nexport type AppSidebarStyle = 'tinted' | 'plain'\n\n/** The apps' look, saved on the account so it follows the person to every device. */\nexport interface AppThemePrefs {\n /** Light, dark or the system's. */\n appearance: AppAppearance\n /** The theme: rail, sidebar tint, surfaces and accent for light and dark together. */\n theme: AppThemeName\n /** `theme` for the theme's own accent, or a `#RRGGBB` the person picked. */\n accent: string\n density: AppDensity\n /** `system` follows Dynamic Type or the font scale; the rest are the Mac and Windows sizes. */\n textSize: AppTextSize\n /**\n * `plain` keeps the sidebar on the theme's surface; `tinted` lays the THEME's accent over it at 5%, on a theme other\n * than Aglyn only (Aglyn's sidebar is always neutral). A workspace's color never tints it: that is its rail tile's.\n */\n sidebarStyle: AppSidebarStyle\n /** The app icon's id: `aglyn`, or one of the alternates the apps ship. */\n appIcon: string\n /** A workspace's own brand color tints the app while you are in it. */\n useWorkspaceBrand: boolean\n}\n\n/** What a person who never changed anything sees. */\nexport const DEFAULT_APP_THEME: AppThemePrefs = {\n appearance: 'system',\n theme: 'aglyn',\n accent: 'theme',\n density: 'comfortable',\n textSize: 'system',\n // Plain: a sidebar keeps the theme's neutral ground unless the person picks Tinted (AGL-3990).\n sidebarStyle: 'plain',\n appIcon: 'aglyn',\n useWorkspaceBrand: true,\n}\n\n/** Every value each closed theme field accepts, in the order a picker lists them. */\nexport const APP_APPEARANCES: readonly AppAppearance[] = ['system', 'light', 'dark']\nexport const APP_THEME_NAMES: readonly AppThemeName[] = [\n 'aglyn',\n 'quiet',\n 'night',\n 'ocean',\n 'warm',\n 'highContrast',\n]\nexport const APP_DENSITIES: readonly AppDensity[] = ['comfortable', 'compact']\nexport const APP_TEXT_SIZES: readonly AppTextSize[] = [\n 'system',\n 'small',\n 'medium',\n 'large',\n 'extraLarge',\n]\nexport const APP_SIDEBAR_STYLES: readonly AppSidebarStyle[] = ['tinted', 'plain']\n\n/** The longest app icon id. */\nexport const APP_ICON_ID_MAX = 40\n\nfunction field(profile: unknown, name: string): unknown {\n return profile && typeof profile === 'object'\n ? (profile as Record<string, unknown>)[name]\n : undefined\n}\n\nfunction idList(value: unknown): string[] {\n if (!Array.isArray(value)) return []\n return [\n ...new Set(\n value.filter((entry): entry is string => typeof entry === 'string' && entry !== ''),\n ),\n ]\n}\n\n/** Whether a value is a picked color, `#` and six hex digits. */\nexport function isAccountColor(value: unknown): value is string {\n return typeof value === 'string' && new RegExp(ACCOUNT_COLOR_PATTERN).test(value)\n}\n\n// ── Pins ────────────────────────────────────────────────────────────────────\n\n/**\n * Every id the person stored as pinned, in their order, without repeats.\n *\n * Anything that is not a list of non-empty strings reads as no pins, so a\n * stray value can never take a switcher down. May hold more than\n * {@link PINNED_ORGS_MAX} for an account that pinned before the cap; read\n * {@link effectivePinnedOrgs} for the pins to show.\n */\nexport function readPinnedOrgs(profile: unknown): string[] {\n return idList(field(profile, PINNED_ORGS_FIELD))\n}\n\n/** The pins in force: the first {@link PINNED_ORGS_MAX} stored, until the person picks. */\nexport function effectivePinnedOrgs(stored: readonly string[]): string[] {\n return idList(stored).slice(0, PINNED_ORGS_MAX)\n}\n\n/** The account pinned more than the cap before there was one, and has to pick which to keep. */\nexport function pinnedOrgsOverCap(stored: readonly string[]): boolean {\n return idList(stored).length > PINNED_ORGS_MAX\n}\n\nexport type PinOrgOutcome = 'pinned' | 'alreadyPinned' | 'full'\n\nexport interface PinOrgResult {\n /** The pins after the request: unchanged unless `outcome` is `pinned`. */\n pinned: string[]\n outcome: PinOrgOutcome\n}\n\n/**\n * Pins a workspace at the end of the list, or says the list is full. A full\n * list is never made room in quietly: the caller asks \"Pinned is full.\n * Replace one?\" and calls {@link replacePinnedOrg} with the answer.\n */\nexport function pinOrg(pinned: readonly string[], orgId: string): PinOrgResult {\n const current = effectivePinnedOrgs(pinned)\n if (!orgId) return { pinned: current, outcome: 'alreadyPinned' }\n if (current.includes(orgId)) return { pinned: current, outcome: 'alreadyPinned' }\n if (current.length >= PINNED_ORGS_MAX) return { pinned: current, outcome: 'full' }\n return { pinned: [...current, orgId], outcome: 'pinned' }\n}\n\n/** The pins without one workspace. */\nexport function unpinOrg(pinned: readonly string[], orgId: string): string[] {\n return idList(pinned).filter((id) => id !== orgId)\n}\n\n/**\n * The pins with `orgId` in the place `replacing` held — the answer to\n * \"Pinned is full. Replace one?\". Unchanged when `replacing` is not pinned\n * or `orgId` already is.\n */\nexport function replacePinnedOrg(\n pinned: readonly string[],\n replacing: string,\n orgId: string,\n): string[] {\n const current = effectivePinnedOrgs(pinned)\n if (!orgId || current.includes(orgId) || !current.includes(replacing)) return current\n return current.map((id) => (id === replacing ? orgId : id))\n}\n\n/**\n * The answer to \"Keep which 5?\": the stored pins the person ticked, in the\n * order they were pinned, never more than the cap.\n */\nexport function keepPinnedOrgs(stored: readonly string[], keep: readonly string[]): string[] {\n const kept = new Set(keep)\n return idList(stored)\n .filter((id) => kept.has(id))\n .slice(0, PINNED_ORGS_MAX)\n}\n\n/** The pins with one moved up (`-1`) or down (`1`) a place; unchanged at an end. */\nexport function movePinnedOrg(pinned: readonly string[], orgId: string, offset: number): string[] {\n const current = effectivePinnedOrgs(pinned)\n const from = current.indexOf(orgId)\n const to = from + (offset < 0 ? -1 : 1)\n if (from === -1 || to < 0 || to >= current.length) return current\n const next = [...current]\n next[from] = next[to]\n next[to] = orgId\n return next\n}\n\n// ── Site pins ───────────────────────────────────────────────────────────────\n\n/** `users/{uid}` field holding the sites the person pinned, each with its workspace (AGL-4005). */\nexport const PINNED_HOSTS_FIELD = 'pinnedHosts'\n\n/**\n * The most site pins the account keeps across every workspace, the bound the\n * Firestore rules hold so `users/{uid}` (read on every launch) cannot grow\n * without end. A workspace has no cap of its own: a person pins as many of\n * its sites as they like (AGL-4165, Zach 2026-11-04), where workspace pins\n * stay at five. Past the bound, the oldest pins of OTHER workspaces give way\n * (see {@link pinHost}); only a workspace holding every one of the 500 is\n * ever full.\n */\nexport const PINNED_HOSTS_MAX = 500\n\n/**\n * One pinned site and the workspace it belongs to. The workspace rides with\n * the pin so a surface that holds only one workspace's sites (the site\n * switcher's window) can tell its own pins apart without reading every site.\n */\nexport interface PinnedHost {\n orgId: string\n hostId: string\n}\n\nfunction pinnedHostList(value: unknown): PinnedHost[] {\n if (!Array.isArray(value)) return []\n const seen = new Set<string>()\n const pins: PinnedHost[] = []\n for (const entry of value) {\n if (!entry || typeof entry !== 'object') continue\n const { orgId, hostId } = entry as Record<string, unknown>\n if (typeof orgId !== 'string' || !orgId) continue\n if (typeof hostId !== 'string' || !hostId || seen.has(hostId)) continue\n seen.add(hostId)\n pins.push({ orgId, hostId })\n }\n return pins\n}\n\n/**\n * Every site pin the person stored, in the order pinned, without repeats.\n * Anything that is not a `{ orgId, hostId }` reads as no pin, so a stray\n * value can never take the sites list down.\n */\nexport function readPinnedHosts(profile: unknown): PinnedHost[] {\n return pinnedHostList(field(profile, PINNED_HOSTS_FIELD))\n}\n\n/** One workspace's pinned site ids, in the order pinned. */\nexport function workspacePinnedHosts(stored: readonly PinnedHost[], orgId: string): string[] {\n return pinnedHostList(stored)\n .filter((pin) => pin.orgId === orgId)\n .map((pin) => pin.hostId)\n .slice(0, PINNED_HOSTS_MAX)\n}\n\nexport interface PinHostResult {\n /** Every stored pin after the request: unchanged unless `outcome` is `pinned`. */\n pinnedHosts: PinnedHost[]\n outcome: PinOrgOutcome\n}\n\n/**\n * Pins a site at the end of its workspace's pins. A workspace takes as many\n * as the person likes; only the account-wide bound ({@link PINNED_HOSTS_MAX})\n * makes room, and only from other workspaces. A workspace that already holds\n * every pin the account keeps answers `full`, never a pin dropped quietly:\n * the caller asks \"Pinned is full. Replace one?\" and calls\n * {@link replacePinnedHost} with the answer.\n */\nexport function pinHost(stored: readonly PinnedHost[], pin: PinnedHost): PinHostResult {\n const current = pinnedHostList(stored)\n if (!pin.orgId || !pin.hostId) return { pinnedHosts: current, outcome: 'alreadyPinned' }\n const inWorkspace = workspacePinnedHosts(current, pin.orgId)\n if (inWorkspace.includes(pin.hostId)) return { pinnedHosts: current, outcome: 'alreadyPinned' }\n // A site pinned under the workspace it has since moved out of moves with it.\n const next = [\n ...current.filter((entry) => entry.hostId !== pin.hostId),\n { orgId: pin.orgId, hostId: pin.hostId },\n ]\n while (next.length > PINNED_HOSTS_MAX) {\n const oldest = next.findIndex((entry) => entry.orgId !== pin.orgId)\n if (oldest === -1) return { pinnedHosts: current, outcome: 'full' }\n next.splice(oldest, 1)\n }\n return { pinnedHosts: next, outcome: 'pinned' }\n}\n\n/** The stored pins without one site. */\nexport function unpinHost(stored: readonly PinnedHost[], hostId: string): PinnedHost[] {\n return pinnedHostList(stored).filter((entry) => entry.hostId !== hostId)\n}\n\n/**\n * The stored pins with `pin` in the place `replacing` held in the same\n * workspace: the answer to \"Pinned is full. Replace one?\". Unchanged when\n * `replacing` is not one of that workspace's pins or `pin` already is.\n */\nexport function replacePinnedHost(\n stored: readonly PinnedHost[],\n replacing: string,\n pin: PinnedHost,\n): PinnedHost[] {\n const current = pinnedHostList(stored)\n const inWorkspace = workspacePinnedHosts(current, pin.orgId)\n if (!pin.hostId || inWorkspace.includes(pin.hostId) || !inWorkspace.includes(replacing)) {\n return current\n }\n return current\n .filter((entry) => entry.hostId !== pin.hostId)\n .map((entry) =>\n entry.hostId === replacing ? { orgId: pin.orgId, hostId: pin.hostId } : entry,\n )\n}\n\n// ── Recent workspaces and the rail ──────────────────────────────────────────\n\n/** The recently opened workspaces as stored, newest first. */\nexport function readRecentOrgs(profile: unknown): string[] {\n return idList(field(profile, RECENT_ORGS_FIELD)).slice(0, RECENT_ORGS_MAX)\n}\n\n/** The recent workspaces after opening one: it moves to the front, the oldest falls off. */\nexport function recordRecentOrg(recent: readonly string[], orgId: string): string[] {\n if (!orgId) return idList(recent).slice(0, RECENT_ORGS_MAX)\n return [orgId, ...idList(recent).filter((id) => id !== orgId)].slice(0, RECENT_ORGS_MAX)\n}\n\n/** What the workspace rail shows. */\nexport interface RailWorkspaces {\n /** Pinned, at the top, in the person's order. */\n pinned: string[]\n /** Below the divider: recently opened and not pinned, at most {@link RAIL_RECENT_ORGS}. */\n recent: string[]\n /**\n * Workspaces listed on the rail beyond the pins and the recents. Always\n * empty: every account reaches the rest through the All tile\n * (AGL-3996). The field stays so the apps that read it need no change.\n */\n rest: string[]\n /** Whether the last tile is \"All workspaces\", opening the searchable switcher: whenever there is a workspace. */\n allTile: boolean\n /** How many workspaces the person belongs to, shown under the All tile. */\n total: number\n}\n\n/**\n * The rail for one account, the same for every account however few\n * workspaces it has (Figma Rail 12:338, \"Many workspaces\"): up to five\n * pinned, a divider, up to three recent under \"Recent\", a divider, then the\n * \"All workspaces\" tile with the total, which opens the switcher where pins\n * are edited. A small account that saw every tile in one unlabeled column\n * had no way into the switcher and no Recent label or divider. `orgIds` is every membership, in the switcher's order;\n * an id the person no longer belongs to is ignored.\n */\nexport function railWorkspaces(\n orgIds: readonly string[],\n pinned: readonly string[],\n recent: readonly string[],\n): RailWorkspaces {\n const members = idList(orgIds)\n const belongs = new Set(members)\n const pins = effectivePinnedOrgs(pinned).filter((id) => belongs.has(id))\n const pinnedSet = new Set(pins)\n return {\n pinned: pins,\n recent: idList(recent)\n .filter((id) => belongs.has(id) && !pinnedSet.has(id))\n .slice(0, RAIL_RECENT_ORGS),\n rest: [],\n allTile: members.length > 0,\n total: members.length,\n }\n}\n\n/**\n * The one letter a workspace tile without a logo shows (Figma Rail/Workspace\n * tile, Type=Initial): the first letter or digit of its name, upper-cased;\n * \"?\" for a name with neither. One letter, not two: the tile's color, picked\n * per workspace, tells two workspaces with the same letter apart.\n */\nexport function workspaceInitial(name: string): string {\n const first = /[\\p{L}\\p{N}]/u.exec(name ?? '')\n return first ? first[0].toUpperCase() : '?'\n}\n\n// ── Starred and recent items ────────────────────────────────────────────────\n\n/** One item's identity: the same screen or record in the same place. */\nexport function accountItemKey(\n item: Pick<AccountItemRef, 'kind' | 'id' | 'orgId' | 'hostId'>,\n): string {\n return `${item.kind}:${item.orgId}:${item.hostId ?? ''}:${item.id}`\n}\n\nfunction stringMap(value: unknown): Record<string, string> | undefined {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return undefined\n const out: Record<string, string> = {}\n for (const [key, entry] of Object.entries(value as Record<string, unknown>)) {\n if (typeof entry === 'string') out[key] = entry\n }\n return Object.keys(out).length ? out : undefined\n}\n\nfunction itemRef(value: unknown): AccountItemRef | null {\n if (!value || typeof value !== 'object') return null\n const raw = value as Record<string, unknown>\n const text = (key: string) => (typeof raw[key] === 'string' ? (raw[key] as string) : '')\n const kind = text('kind')\n const id = text('id')\n const orgId = text('orgId')\n const screen = text('screen')\n if (!kind || !id || !orgId || !screen) return null\n const hostId = text('hostId')\n const params = stringMap(raw['params'])\n return {\n kind,\n id,\n orgId,\n ...(hostId ? { hostId } : {}),\n label: text('label').slice(0, ACCOUNT_ITEM_LABEL_MAX),\n screen,\n ...(params ? { params } : {}),\n }\n}\n\nfunction at(value: unknown): number {\n return typeof value === 'number' && Number.isFinite(value) ? value : 0\n}\n\nfunction isStarColor(value: unknown): value is StarColor {\n return (STAR_COLORS as readonly unknown[]).includes(value)\n}\n\n/** The starred items as stored, each well formed, without repeats, never more than the cap. */\nexport function readStarred(profile: unknown): StarredItem[] {\n const stored = field(profile, STARRED_FIELD)\n if (!Array.isArray(stored)) return []\n const seen = new Set<string>()\n const out: StarredItem[] = []\n for (const entry of stored) {\n const ref = itemRef(entry)\n if (!ref) continue\n const key = accountItemKey(ref)\n if (seen.has(key)) continue\n seen.add(key)\n const color = (entry as Record<string, unknown>)['color']\n out.push({\n ...ref,\n ...(isStarColor(color) ? { color } : {}),\n starredAtMs: at((entry as Record<string, unknown>)['starredAtMs']),\n })\n }\n return out.slice(0, STARRED_MAX)\n}\n\nexport type StarOutcome = 'starred' | 'unstarred' | 'full'\n\nexport interface StarResult {\n /** The starred items after the request: unchanged when `outcome` is `full`. */\n starred: StarredItem[]\n outcome: StarOutcome\n}\n\n/** Stars an item at the end of the list, or unstars it; a full list says so instead. */\nexport function toggleStarred(\n starred: readonly StarredItem[],\n item: AccountItemRef,\n nowMs: number,\n): StarResult {\n const current = readStarred({ [STARRED_FIELD]: starred })\n const ref = itemRef(item)\n if (!ref) return { starred: current, outcome: 'full' }\n const key = accountItemKey(ref)\n if (current.some((entry) => accountItemKey(entry) === key)) {\n return {\n starred: current.filter((entry) => accountItemKey(entry) !== key),\n outcome: 'unstarred',\n }\n }\n if (current.length >= STARRED_MAX) return { starred: current, outcome: 'full' }\n return { starred: [...current, { ...ref, starredAtMs: nowMs }], outcome: 'starred' }\n}\n\n/** The starred items with one item's color dot set, or cleared with `null`. */\nexport function setStarColor(\n starred: readonly StarredItem[],\n key: string,\n color: StarColor | null,\n): StarredItem[] {\n return readStarred({ [STARRED_FIELD]: starred }).map((entry) => {\n if (accountItemKey(entry) !== key) return entry\n const next: StarredItem = { ...entry }\n delete next.color\n return color && isStarColor(color) ? { ...next, color } : next\n })\n}\n\n/** The recent items as stored, newest first, each well formed, never more than the cap. */\nexport function readRecents(profile: unknown): RecentItem[] {\n const stored = field(profile, RECENTS_FIELD)\n if (!Array.isArray(stored)) return []\n const seen = new Set<string>()\n const out: RecentItem[] = []\n for (const entry of stored) {\n const ref = itemRef(entry)\n if (!ref) continue\n const key = accountItemKey(ref)\n if (seen.has(key)) continue\n seen.add(key)\n out.push({ ...ref, openedAtMs: at((entry as Record<string, unknown>)['openedAtMs']) })\n }\n return out.slice(0, RECENTS_MAX)\n}\n\n/** The recent items after opening one: it moves to the front, the oldest falls off. */\nexport function recordRecent(\n recents: readonly RecentItem[],\n item: AccountItemRef,\n nowMs: number,\n): RecentItem[] {\n const current = readRecents({ [RECENTS_FIELD]: recents })\n const ref = itemRef(item)\n if (!ref) return current\n const key = accountItemKey(ref)\n return [\n { ...ref, openedAtMs: nowMs },\n ...current.filter((entry) => accountItemKey(entry) !== key),\n ].slice(0, RECENTS_MAX)\n}\n\n// ── Workspace colors ────────────────────────────────────────────────────────\n\n/** The colors the person picked, by workspace id, the valid ones only. */\nexport function readWorkspaceColors(profile: unknown): Record<string, string> {\n const stored = field(profile, WORKSPACE_COLORS_FIELD)\n if (!stored || typeof stored !== 'object' || Array.isArray(stored)) return {}\n const out: Record<string, string> = {}\n for (const [orgId, color] of Object.entries(stored as Record<string, unknown>)) {\n if (orgId && isAccountColor(color)) out[orgId] = color\n if (Object.keys(out).length >= WORKSPACE_COLORS_MAX) break\n }\n return out\n}\n\n/**\n * The colors a workspace's tile takes when nothing else gives it one\n * ({@link workspaceStableColor}): the console's blue for text on a light\n * ground (primary.dark), deep tones of the brand palette's\n * violet and pink, and a rose, orange, gold, green and teal beside them,\n * each dark enough that the tile's white initial reads at 4.5:1 or more. The\n * slate is left out: it is the tile of a workspace with no id at all.\n */\nexport const WORKSPACE_STABLE_COLORS: readonly string[] = [\n '#0077AD',\n '#6A4FD8',\n '#A62BBF',\n '#C2185B',\n '#B4501A',\n '#8A6A00',\n '#2E7D5B',\n '#00796B',\n]\n\n/**\n * The color a workspace with no picked, brand or logo color shows on its\n * tile: one of {@link WORKSPACE_STABLE_COLORS}, chosen by its id, so the same\n * workspace has the same color on every device and in every app, and two\n * workspaces with the same initial usually differ. The id is hashed with\n * 32-bit FNV-1a over its UTF-16 code units, which each platform computes the\n * same way. Null for an empty id.\n */\nexport function workspaceStableColor(orgId: unknown): string | null {\n if (typeof orgId !== 'string' || orgId === '') return null\n let hash = 0x811c9dc5\n for (let i = 0; i < orgId.length; i++) {\n hash ^= orgId.charCodeAt(i)\n hash = Math.imul(hash, 0x01000193) >>> 0\n }\n return WORKSPACE_STABLE_COLORS[hash % WORKSPACE_STABLE_COLORS.length] ?? null\n}\n\nexport type WorkspaceColorSource = 'picked' | 'brand' | 'logo' | 'stable' | 'none'\n\nexport interface WorkspaceColor {\n /** `#RRGGBB`, or null when nothing gives the workspace a color. */\n color: string | null\n source: WorkspaceColorSource\n /** Whether the app is tinted with it while you are in the workspace. */\n tintsApp: boolean\n}\n\n/**\n * A workspace's color: the one the person picked, else the workspace's brand\n * color (`brandingProfile.primaryColor`), else a color taken from its logo\n * (Zach, 2026-10-18). The rail tile always shows it; the app is tinted with\n * it while you are in the workspace unless the person turned \"Use each\n * workspace's brand\" off, which stops the brand and logo colors tinting the\n * app (a picked color still does: the person chose it).\n *\n * Given the workspace's id, a workspace with none of the three still gets a\n * color: its stable one ({@link workspaceStableColor}). That one colors only\n * its tile (the rail, the pickers, the menus, the sidebar's header), never\n * the app.\n */\nexport function resolveWorkspaceColor(\n picked: unknown,\n brandColor: unknown,\n logoColor: unknown,\n useWorkspaceBrand: boolean,\n orgId?: unknown,\n): WorkspaceColor {\n if (isAccountColor(picked)) return { color: picked, source: 'picked', tintsApp: true }\n if (isAccountColor(brandColor)) {\n return { color: brandColor, source: 'brand', tintsApp: useWorkspaceBrand }\n }\n if (isAccountColor(logoColor)) {\n return { color: logoColor, source: 'logo', tintsApp: useWorkspaceBrand }\n }\n const stable = workspaceStableColor(orgId)\n if (stable) return { color: stable, source: 'stable', tintsApp: false }\n return { color: null, source: 'none', tintsApp: false }\n}\n\n// ── Theme ───────────────────────────────────────────────────────────────────\n\nfunction oneOf<T extends string>(value: unknown, allowed: readonly T[], fallback: T): T {\n return (allowed as readonly unknown[]).includes(value) ? (value as T) : fallback\n}\n\n/** The synced theme, every field filled: a missing or unknown value reads as the default. */\nexport function readAppTheme(profile: unknown): AppThemePrefs {\n const stored = field(profile, APP_THEME_FIELD)\n const raw =\n stored && typeof stored === 'object' && !Array.isArray(stored)\n ? (stored as Record<string, unknown>)\n : {}\n const accent = raw['accent']\n const appIcon = raw['appIcon']\n return {\n appearance: oneOf(raw['appearance'], APP_APPEARANCES, DEFAULT_APP_THEME.appearance),\n theme: oneOf(raw['theme'], APP_THEME_NAMES, DEFAULT_APP_THEME.theme),\n accent: accent === 'theme' || isAccountColor(accent) ? accent : DEFAULT_APP_THEME.accent,\n density: oneOf(raw['density'], APP_DENSITIES, DEFAULT_APP_THEME.density),\n textSize: oneOf(raw['textSize'], APP_TEXT_SIZES, DEFAULT_APP_THEME.textSize),\n sidebarStyle: oneOf(raw['sidebarStyle'], APP_SIDEBAR_STYLES, DEFAULT_APP_THEME.sidebarStyle),\n appIcon:\n typeof appIcon === 'string' && appIcon !== '' && appIcon.length <= APP_ICON_ID_MAX\n ? appIcon\n : DEFAULT_APP_THEME.appIcon,\n useWorkspaceBrand:\n typeof raw['useWorkspaceBrand'] === 'boolean'\n ? (raw['useWorkspaceBrand'] as boolean)\n : DEFAULT_APP_THEME.useWorkspaceBrand,\n }\n}\n\n// ── The phone's tab bar (AGL-4006) ──────────────────────────────────────────\n\n/** `users/{uid}` field holding the areas the person keeps in the phone's tab bar, per site and per workspace. */\nexport const TAB_BARS_FIELD = 'tabBars'\n\n/**\n * The most areas one tab bar holds beside Home: iOS and\n * Material take five destinations at most, and nothing ever overflows into a\n * More tab. With four, Create leaves the bar for the top bar.\n */\nexport const TAB_BAR_AREAS_MAX = 4\n\n/** The most sites and workspaces the account keeps a tab bar for, the bound the Firestore rules hold. */\nexport const TAB_BARS_MAX = 100\n\n/** The tab bar's own slots beside the areas: Home, always first, and Create new. */\nexport const TAB_BAR_HOME = 'home'\nexport const TAB_BAR_CREATE = 'create'\n\n/** One site's or workspace's tab bar. */\nexport interface TabBarPins {\n /** `site:<hostId>` or `org:<orgId>` ({@link tabBarScope}). */\n scope: string\n /** Nav manifest row ids, in the person's order, at most {@link TAB_BAR_AREAS_MAX}. */\n areas: string[]\n /**\n * The person pinned, unpinned or reordered here by hand. Until then the\n * first areas they open take the free spots and stay (the default the\n * orchestrator settled on 2026-10-20: nothing guessed, nothing rotating);\n * after it, only the person changes the bar.\n */\n chosen: boolean\n}\n\nexport type TabPinOutcome = 'pinned' | 'alreadyPinned' | 'full'\n\nexport interface TabPinResult {\n /** Every stored tab bar after the request: unchanged unless `outcome` is `pinned`. */\n tabBars: TabBarPins[]\n outcome: TabPinOutcome\n}\n\n/** What a phone's tab bar shows, in order, and where Create new goes. */\nexport interface TabBarLayout {\n /** {@link TAB_BAR_HOME}, the areas, and {@link TAB_BAR_CREATE} in the centre unless it moved to the top bar. */\n slots: string[]\n /** Four areas fill the bar, so Create new sits in the top bar beside the AI button. */\n createInTopBar: boolean\n}\n\n/** The key of one site's tab bar, or the whole workspace's. */\nexport function tabBarScope(orgId: string, hostId?: string | null): string {\n return hostId ? `site:${hostId}` : `org:${orgId}`\n}\n\nfunction tabAreaList(value: unknown): string[] {\n return idList(value)\n .filter((id) => id !== TAB_BAR_HOME && id !== TAB_BAR_CREATE)\n .slice(0, TAB_BAR_AREAS_MAX)\n}\n\nfunction tabBarList(value: unknown): TabBarPins[] {\n if (!Array.isArray(value)) return []\n const seen = new Set<string>()\n const out: TabBarPins[] = []\n for (const entry of value) {\n if (!entry || typeof entry !== 'object') continue\n const raw = entry as Record<string, unknown>\n const scope = raw['scope']\n if (typeof scope !== 'string' || !/^(site|org):./.test(scope) || seen.has(scope)) continue\n seen.add(scope)\n out.push({ scope, areas: tabAreaList(raw['areas']), chosen: raw['chosen'] === true })\n }\n return out.slice(-TAB_BARS_MAX)\n}\n\n/**\n * Every tab bar the person keeps, each well formed, without repeats. Anything\n * that is not a `{ scope, areas, chosen }` reads as no tab bar, so a stray\n * value can never take the phone's shell down.\n */\nexport function readTabBars(profile: unknown): TabBarPins[] {\n return tabBarList(field(profile, TAB_BARS_FIELD))\n}\n\n/** One scope's areas, in the person's order. */\nexport function tabBarAreas(tabBars: readonly TabBarPins[], scope: string): string[] {\n return tabBarList(tabBars).find((bar) => bar.scope === scope)?.areas ?? []\n}\n\n/**\n * Every tab bar with one scope's replaced. A scope seen for the first time\n * goes last; past {@link TAB_BARS_MAX} the oldest OTHER scopes give way.\n */\nfunction withTabBar(tabBars: readonly TabBarPins[], next: TabBarPins): TabBarPins[] {\n const current = tabBarList(tabBars)\n const at = current.findIndex((bar) => bar.scope === next.scope)\n const out = at === -1 ? [...current, next] : current.map((bar, index) => (index === at ? next : bar))\n while (out.length > TAB_BARS_MAX) {\n const oldest = out.findIndex((bar) => bar.scope !== next.scope)\n if (oldest === -1) break\n out.splice(oldest, 1)\n }\n return out\n}\n\n/**\n * Pins an area at the end of a scope's tab bar (long-press a tile, \"Add to tab\n * bar\"), or says the bar is full: a full bar is never made room in quietly.\n */\nexport function pinTabArea(\n tabBars: readonly TabBarPins[],\n scope: string,\n area: string,\n): TabPinResult {\n const current = tabBarList(tabBars)\n const areas = tabBarAreas(current, scope)\n if (!area || area === TAB_BAR_HOME || area === TAB_BAR_CREATE || areas.includes(area)) {\n return { tabBars: current, outcome: 'alreadyPinned' }\n }\n if (areas.length >= TAB_BAR_AREAS_MAX) return { tabBars: current, outcome: 'full' }\n return {\n tabBars: withTabBar(current, { scope, areas: [...areas, area], chosen: true }),\n outcome: 'pinned',\n }\n}\n\n/** A scope's tab bar without one area; the person chose, so opened areas no longer fill the spot. */\nexport function unpinTabArea(\n tabBars: readonly TabBarPins[],\n scope: string,\n area: string,\n): TabBarPins[] {\n const areas = tabBarAreas(tabBars, scope)\n return withTabBar(tabBars, { scope, areas: areas.filter((id) => id !== area), chosen: true })\n}\n\n/** A scope's tab bar with one area moved left (`-1`) or right (`1`) a place; unchanged at an end. */\nexport function moveTabArea(\n tabBars: readonly TabBarPins[],\n scope: string,\n area: string,\n offset: number,\n): TabBarPins[] {\n const areas = tabBarAreas(tabBars, scope)\n const from = areas.indexOf(area)\n const to = from + (offset < 0 ? -1 : 1)\n if (from === -1 || to < 0 || to >= areas.length) return tabBarList(tabBars)\n const next = [...areas]\n next[from] = next[to]\n next[to] = area\n return withTabBar(tabBars, { scope, areas: next, chosen: true })\n}\n\n/** A scope's tab bar as the Tab bar sheet left it: these areas, in this order, at most four. */\nexport function setTabAreas(\n tabBars: readonly TabBarPins[],\n scope: string,\n areas: readonly string[],\n): TabBarPins[] {\n return withTabBar(tabBars, { scope, areas: tabAreaList(areas), chosen: true })\n}\n\n/**\n * The default before anyone pins: an area the person opens takes a free spot\n * and stays there, until the bar is full or the person changes it by hand.\n * Unchanged once the scope is `chosen`, the area is in the bar already, or the\n * bar is full.\n */\nexport function autoPinTabArea(\n tabBars: readonly TabBarPins[],\n scope: string,\n area: string,\n): TabBarPins[] {\n const current = tabBarList(tabBars)\n const bar = current.find((entry) => entry.scope === scope)\n const areas = bar?.areas ?? []\n if (!area || area === TAB_BAR_HOME || area === TAB_BAR_CREATE) return current\n if (bar?.chosen || areas.includes(area) || areas.length >= TAB_BAR_AREAS_MAX) return current\n return withTabBar(current, { scope, areas: [...areas, area], chosen: false })\n}\n\n/**\n * The tab bar to draw: Home first, then the pinned areas the scope can open\n * (`available`, the Home tiles' ids in this build), with Create new in the\n * centre slot. Four areas fill the bar, and Create moves to the top bar.\n */\nexport function tabBarLayout(areas: readonly string[], available: readonly string[]): TabBarLayout {\n const open = new Set(available)\n const shown = tabAreaList(areas).filter((id) => open.has(id))\n if (shown.length >= TAB_BAR_AREAS_MAX) {\n return { slots: [TAB_BAR_HOME, ...shown], createInTopBar: true }\n }\n const slots = [TAB_BAR_HOME, ...shown]\n slots.splice(Math.floor((shown.length + 2) / 2), 0, TAB_BAR_CREATE)\n return { slots, createInTopBar: false }\n}\n\n// ── Who is signed in ────────────────────────────────────────────────────────\n\n/**\n * `users/{uid}` field holding the person's own picture (AGL-1961). Lowercase\n * `url`: the roster's `photoURL` spelling reads as nothing here.\n */\nexport const ACCOUNT_PHOTO_FIELD = 'photoUrl'\n\nfunction trimmed(value: unknown): string {\n return typeof value === 'string' ? value.trim() : ''\n}\n\n/**\n * The person's own picture, the same answer in the console and both apps\n * (AGL-4010): `users/{uid}.photoUrl` first (the profile they edit, filled from\n * the identity provider on every sign-in), else the sign-in record's\n * `photoURL`, else null, so the caller draws initials. A blank value is never\n * a picture, so a photo in either place wins over an empty one in the other.\n * A library pick is stored as a `/api/media/cdn/...` path; resolving it to an\n * address is the caller's (`mediaPreviewURL` on native).\n */\nexport function readAccountPhoto(profile: unknown, authPhotoUrl: unknown): string | null {\n return trimmed(field(profile, ACCOUNT_PHOTO_FIELD)) || trimmed(authPhotoUrl) || null\n}\n\n/**\n * The person's own name, the same answer in the console and both apps\n * (AGL-2486, AGL-4010): the profile's first and last name, else the sign-in\n * record's display name (empty for an SSO account), else the email address,\n * else empty.\n */\nexport function readAccountName(\n profile: unknown,\n authDisplayName: unknown,\n email: unknown,\n): string {\n const fromProfile = [field(profile, 'firstName'), field(profile, 'lastName')]\n .map(trimmed)\n .filter(Boolean)\n .join(' ')\n return fromProfile || trimmed(authDisplayName) || trimmed(email)\n}\n"],"names":["PINNED_ORGS_FIELD","PINNED_ORGS_MAX","RECENT_ORGS_FIELD","RECENT_ORGS_MAX","RAIL_RECENT_ORGS","STARRED_FIELD","STARRED_MAX","RECENTS_FIELD","RECENTS_MAX","WORKSPACE_COLORS_FIELD","WORKSPACE_COLORS_MAX","APP_THEME_FIELD","ACCOUNT_ITEM_LABEL_MAX","ACCOUNT_COLOR_PATTERN","STAR_COLORS","DEFAULT_APP_THEME","appearance","theme","accent","density","textSize","sidebarStyle","appIcon","useWorkspaceBrand","APP_APPEARANCES","APP_THEME_NAMES","APP_DENSITIES","APP_TEXT_SIZES","APP_SIDEBAR_STYLES","APP_ICON_ID_MAX","field","profile","name","undefined","idList","value","Array","isArray","Set","filter","entry","isAccountColor","RegExp","test","readPinnedOrgs","effectivePinnedOrgs","stored","slice","pinnedOrgsOverCap","length","pinOrg","pinned","orgId","current","outcome","includes","unpinOrg","id","replacePinnedOrg","replacing","map","keepPinnedOrgs","keep","kept","has","movePinnedOrg","offset","from","indexOf","to","next","PINNED_HOSTS_FIELD","PINNED_HOSTS_MAX","pinnedHostList","seen","pins","hostId","add","push","readPinnedHosts","workspacePinnedHosts","pin","pinHost","pinnedHosts","inWorkspace","oldest","findIndex","splice","unpinHost","replacePinnedHost","readRecentOrgs","recordRecentOrg","recent","railWorkspaces","orgIds","members","belongs","pinnedSet","rest","allTile","total","workspaceInitial","first","exec","toUpperCase","accountItemKey","item","kind","stringMap","out","key","Object","entries","keys","itemRef","raw","text","screen","params","label","at","Number","isFinite","isStarColor","readStarred","ref","color","starredAtMs","toggleStarred","starred","nowMs","some","setStarColor","readRecents","openedAtMs","recordRecent","recents","readWorkspaceColors","WORKSPACE_STABLE_COLORS","workspaceStableColor","hash","i","charCodeAt","Math","imul","resolveWorkspaceColor","picked","brandColor","logoColor","source","tintsApp","stable","oneOf","allowed","fallback","readAppTheme","TAB_BARS_FIELD","TAB_BAR_AREAS_MAX","TAB_BARS_MAX","TAB_BAR_HOME","TAB_BAR_CREATE","tabBarScope","tabAreaList","tabBarList","scope","areas","chosen","readTabBars","tabBarAreas","tabBars","find","bar","withTabBar","index","pinTabArea","area","unpinTabArea","moveTabArea","setTabAreas","autoPinTabArea","tabBarLayout","available","open","shown","slots","createInTopBar","floor","ACCOUNT_PHOTO_FIELD","trimmed","trim","readAccountPhoto","authPhotoUrl","readAccountName","authDisplayName","email","fromProfile","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,SACJrJ,MAAM,CAAC6J,SACPC,IAAI,CAAC;IACR,OAAOF,eAAeP,QAAQK,oBAAoBL,QAAQM;AAC5D"}
@@ -2927,7 +2927,9 @@ export declare function crmViewFiltersFromSegment(segment: Pick<ContactSegment,
2927
2927
  * operators that mean "has one of these"; a `name startsWith` or an owner
2928
2928
  * clause is not a segment's to keep. What comes back is what "Save as
2929
2929
  * segment" writes, so a campaign audience built from it selects exactly the
2930
- * tags and sources the reader could see on the chips.
2930
+ * tags and sources the reader could see on the chips. That includes a source
2931
+ * a plugin declared: dropping one would save a broader segment than the list
2932
+ * on screen.
2931
2933
  */
2932
2934
  export declare function crmViewSegmentFilters(filters: readonly CrmViewFilterClause[]): Pick<ContactSegment, 'tags' | 'sources'> | null;
2933
2935
  /**
@@ -50,6 +50,7 @@ import { isEmailStateStatus } from "./email-state.js";
50
50
  import { NAME_TOKEN_MAX_PREFIX, nameSearchKey, nameSearchTokens, SCOPED_SEARCH_JOIN, scopedSearchTokens } from "./name-search.js";
51
51
  import { effectivePicklistValueSet, isStandardPicklistValueId, judgePicklistValue, mintPicklistValueId, normalizePicklistLabel, normalizePicklistValueSet, PICKLIST_VALUES_MAX, picklistActiveValues, picklistDefaultLabel, picklistFromLabels, picklistOptions, picklistRank, picklistRefusalSentence, picklistValueByLabel } from "./picklists.js";
52
52
  import { MAX_SCOPE_HOSTS, ORG_SCOPE_TOKEN } from "./scope-tokens.js";
53
+ import { isKnownContactSource } from "../plugin-manager/plugin-contact-capture.js";
53
54
  // The fixed vocabularies and their guards live in a leaf module; every name
54
55
  // stays importable from here.
55
56
  export * from "./crm-kinds.js";
@@ -3758,7 +3759,7 @@ const CRM_VIEW_SOURCE_FIELD = CRM_CONTACT_VIEW_FIELDS.source;
3758
3759
  */ export function crmViewFiltersFromSegment(segment) {
3759
3760
  var _segment_tags, _segment_sources;
3760
3761
  const tags = ((_segment_tags = segment.tags) != null ? _segment_tags : []).map((tag)=>tag.trim()).filter(Boolean);
3761
- const sources = ((_segment_sources = segment.sources) != null ? _segment_sources : []).filter((source)=>source in CONTACT_SOURCE_LABELS);
3762
+ const sources = ((_segment_sources = segment.sources) != null ? _segment_sources : []).filter(isKnownContactSource);
3762
3763
  return [
3763
3764
  ...tags.length === 1 ? [
3764
3765
  {
@@ -3796,7 +3797,9 @@ const CRM_VIEW_SOURCE_FIELD = CRM_CONTACT_VIEW_FIELDS.source;
3796
3797
  * operators that mean "has one of these"; a `name startsWith` or an owner
3797
3798
  * clause is not a segment's to keep. What comes back is what "Save as
3798
3799
  * segment" writes, so a campaign audience built from it selects exactly the
3799
- * tags and sources the reader could see on the chips.
3800
+ * tags and sources the reader could see on the chips. That includes a source
3801
+ * a plugin declared: dropping one would save a broader segment than the list
3802
+ * on screen.
3800
3803
  */ export function crmViewSegmentFilters(filters) {
3801
3804
  const tags = new Set();
3802
3805
  const sources = new Set();
@@ -3812,7 +3815,7 @@ const CRM_VIEW_SOURCE_FIELD = CRM_CONTACT_VIEW_FIELDS.source;
3812
3815
  clause.value.trim()
3813
3816
  ] : clause.op === 'isAnyOf' ? split(clause.value) : [];
3814
3817
  for (const source of values){
3815
- if (source in CONTACT_SOURCE_LABELS) sources.add(source);
3818
+ if (isKnownContactSource(source)) sources.add(source);
3816
3819
  }
3817
3820
  }
3818
3821
  }