@the-portland-company/shell 0.80.2 → 0.81.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/active-org.cjs +9 -0
- package/dist/active-org.cjs.map +1 -1
- package/dist/active-org.d.cts +7 -1
- package/dist/active-org.d.ts +7 -1
- package/dist/active-org.js +1 -1
- package/dist/app-chrome.cjs +49 -28
- package/dist/app-chrome.cjs.map +1 -1
- package/dist/app-chrome.d.cts +20 -5
- package/dist/app-chrome.d.ts +20 -5
- package/dist/app-chrome.js +37 -28
- package/dist/app-chrome.js.map +1 -1
- package/dist/chrome.css +6 -0
- package/dist/{chunk-FBUF7LUE.js → chunk-5LO5W7W5.js} +11 -3
- package/dist/chunk-5LO5W7W5.js.map +1 -0
- package/dist/{chunk-DXJOADNV.js → chunk-BU4NXTLF.js} +9 -7
- package/dist/chunk-BU4NXTLF.js.map +1 -0
- package/dist/{chunk-TUK2IEL5.js → chunk-L73FZKGE.js} +5 -4
- package/dist/chunk-L73FZKGE.js.map +1 -0
- package/dist/{index-fydj5EU2.d.cts → index-_Y7jOKPN.d.cts} +8 -3
- package/dist/{index-KGYMc_1i.d.ts → index-bYu6DxNt.d.ts} +8 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/native.cjs +16 -5
- package/dist/native.cjs.map +1 -1
- package/dist/native.d.cts +1 -1
- package/dist/native.d.ts +1 -1
- package/dist/native.js +3 -3
- package/dist/url-state.cjs.map +1 -1
- package/dist/url-state.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-DXJOADNV.js.map +0 -1
- package/dist/chunk-FBUF7LUE.js.map +0 -1
- package/dist/chunk-TUK2IEL5.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
## 0.81.1
|
|
2
|
+
|
|
3
|
+
The active row's left marker is visible. Spec cited: Specs/Left-Navigation §8.1 ("9% white tint, semibold white text, and a 2px inset marker on the left edge in white").
|
|
4
|
+
|
|
5
|
+
- **Cause.** The marker drew in `--mode-accent`, the Mode's chrome accent, which is graphite (#2F3136) on the graphite Relationship rail (#1B1C20): in the DOM, invisible on screen. The Design Compare for Left Navigation read the Dashboard row as having no active state (measured 2026-10-12 by the visual-regression tester).
|
|
6
|
+
- **Fix.** New `--sidebar-active-marker: #FFFFFF` in chrome.css (Brand `modes.<mode>.accent`, white for every mode as of v153); `NavActiveRail` draws in it, falling back to the old accent on an older sheet.
|
|
7
|
+
- Tests: `__tests__/mode-accent.test.tsx`.
|
|
8
|
+
|
|
9
|
+
## 0.81.0
|
|
10
|
+
|
|
11
|
+
An organization switch without a reload keeps the mode switcher and the address bar right, and no shell link builds on the retired VRM core. Spec cited: Reference/UI-Platform "Retirement of app.politogyvrm.com" and "URL state"; Specs/Left-Navigation §7.
|
|
12
|
+
|
|
13
|
+
- **Cause (mode switcher).** After a switch the pill showed the new organization at once, but the entitlement read (`me` with `x-contacts-org`) ran before the app had re-exchanged its token. The chrome API answers for the verified token org, so the old organization's modes were cached under the new one's key: on an organization that holds Campaign Mode the Campaign button stayed dimmed ("isn't active for this organization") until a reload (reported by Ben; reproduced 2026-10-12 on the Dashboard, `account: <old org>` in the response).
|
|
14
|
+
- **Fix.** `ChromeState` gains `orgPending`; `useChromeMode` waits for it to clear and reads entitlements with the new token.
|
|
15
|
+
- **Cause (address bar).** The shell wrote the new `org_id` tail, then the app's `onReexchange` revalidated its tree and the Next router restored the URL it last navigated to, with the previous tail.
|
|
16
|
+
- **Fix.** The tail is stamped again when the token settles on the new organization, after that refresh.
|
|
17
|
+
- **Links.** My Profile and Add account go to Politogy ID (`auth.politogyvrm.com/my-profile`); Organization settings goes to the Settings app with the 7-char `org_id`; Privacy, Terms and the Beta terms go to Politogy ID; the fuel top-up link goes to the Settings Subscription & Billing tab. New export `settingsBaseUrl()` and `footerLinks()`. `CORE_APP_ORIGIN` stays only for `resolveOrgLogoUrl` (the storage proxy is data service, not UI).
|
|
18
|
+
- Tests: `__tests__/orgSwitchPending.test.tsx`, `__tests__/retiredHostLinks.test.tsx`.
|
|
19
|
+
|
|
1
20
|
## 0.80.2
|
|
2
21
|
|
|
3
22
|
The mode switcher goes to each mode's landing page. Spec cited: Specs/Left-Navigation §7 and §11.1.
|
package/dist/active-org.cjs
CHANGED
|
@@ -66,6 +66,8 @@ var LEGACY_ORG_TAIL_LENGTH = 6;
|
|
|
66
66
|
var TAIL_RE = /^[0-9a-f]{6,7}$/i;
|
|
67
67
|
var AUTH_BASE_URL = "https://auth.politogyvrm.com";
|
|
68
68
|
var AUTH_BASE_URL_STAGING = "https://auth-staging.politogyvrm.com";
|
|
69
|
+
var SETTINGS_BASE_URL = "https://settings.politogyvrm.com";
|
|
70
|
+
var SETTINGS_BASE_URL_STAGING = "https://settings-staging.politogyvrm.com";
|
|
69
71
|
function orgIdTail(orgId) {
|
|
70
72
|
return isOrgId(orgId) ? orgId.trim().toLowerCase().slice(-ORG_ID_TAIL_LENGTH) : null;
|
|
71
73
|
}
|
|
@@ -137,6 +139,12 @@ function authBaseUrl() {
|
|
|
137
139
|
}
|
|
138
140
|
return AUTH_BASE_URL;
|
|
139
141
|
}
|
|
142
|
+
function settingsBaseUrl() {
|
|
143
|
+
if (typeof window !== "undefined" && window.location.hostname.toLowerCase().includes("staging")) {
|
|
144
|
+
return SETTINGS_BASE_URL_STAGING;
|
|
145
|
+
}
|
|
146
|
+
return SETTINGS_BASE_URL;
|
|
147
|
+
}
|
|
140
148
|
var ActiveOrgSwitchError = class extends Error {
|
|
141
149
|
constructor(status, message) {
|
|
142
150
|
super(message);
|
|
@@ -202,6 +210,7 @@ exports.readActiveOrgCookie = readActiveOrgCookie;
|
|
|
202
210
|
exports.readActiveOrgFromUrl = readActiveOrgFromUrl;
|
|
203
211
|
exports.readOrgSelectorFromUrl = readOrgSelectorFromUrl;
|
|
204
212
|
exports.resolveActiveOrg = resolveActiveOrg;
|
|
213
|
+
exports.settingsBaseUrl = settingsBaseUrl;
|
|
205
214
|
exports.switchActiveOrg = switchActiveOrg;
|
|
206
215
|
exports.syncOrgIdInUrl = syncOrgIdInUrl;
|
|
207
216
|
exports.withActiveOrgParam = withActiveOrgParam;
|
package/dist/active-org.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/active-org.ts"],"names":[],"mappings":";;;AAqBO,IAAM,iBAAA,GAAoB;AAC1B,IAAM,sBAAA,GAAyB;AAItC,IAAM,OAAA,GAAU,iEAAA;AAET,SAAS,QAAQ,CAAA,EAAyB;AAC/C,EAAA,OAAO,OAAO,CAAA,KAAM,QAAA,IAAY,QAAQ,IAAA,CAAK,CAAA,CAAE,MAAM,CAAA;AACvD;AAOO,SAAS,mBAAA,GAAqC;AACnD,EAAA,IAAI,OAAO,QAAA,KAAa,WAAA,EAAa,OAAO,IAAA;AAC5C,EAAA,IAAI;AACF,IAAA,MAAM,CAAA,GAAI,SAAS,MAAA,CAAO,KAAA;AAAA,MACxB,IAAI,MAAA,CAAO,CAAA,WAAA,EAAc,iBAAiB,CAAA,QAAA,CAAU;AAAA,KACtD;AACA,IAAA,MAAM,IAAI,CAAA,GAAI,kBAAA,CAAmB,CAAA,CAAE,CAAC,CAAC,CAAA,GAAI,IAAA;AACzC,IAAA,OAAO,OAAA,CAAQ,CAAC,CAAA,GAAI,CAAA,GAAI,IAAA;AAAA,EAC1B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AAMO,SAAS,qBAAqB,KAAA,EAAqB;AACxD,EAAA,IAAI,OAAO,QAAA,KAAa,WAAA,IAAe,OAAO,WAAW,WAAA,EAAa;AACtE,EAAA,IAAI,CAAC,OAAA,CAAQ,KAAK,CAAA,EAAG;AACrB,EAAA,MAAM,IAAA,GAAO,OAAO,QAAA,CAAS,QAAA;AAC7B,EAAA,MAAM,UAAA,GAAa,0BA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EAAA,MAAM,IAAA,GAAO,UAAU,KAAK,CAAA;AAC5B,EAAA,IAAI,CAAC,MAAM,OAAO,IAAA;AAClB,EAAA,IAAI,CAAA;AACJ,EAAA,IAAI;AACF,IAAA,CAAA,GAAI,IAAI,IAAI,IAAI,CAAA;AAAA,EAClB,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,SAAA,GAAY,CAAA,CAAE,YAAA,CAAa,GAAA,CAAI,sBAAsB,CAAA;AAC3D,EAAA,MAAM,OAAA,GAAU,CAAA,CAAE,YAAA,CAAa,GAAA,CAAI,kBAAkB,CAAA;AACrD,EAAA,IAAI,CAAC,SAAA,IAAa,OAAA,KAAY,IAAA,EAAM,OAAO,IAAA;AAC3C,EAAA,IAAI,CAAC,SAAA,IAAa,OAAA,KAAY,IAAA,EAAM,OAAO,IAAA;AAC3C,EAAA,CAAA,CAAE,YAAA,CAAa,OAAO,sBAAsB,CAAA;AAC5C,EAAA,CAAA,CAAE,YAAA,CAAa,GAAA,CAAI,kBAAA,EAAoB,IAAI,CAAA;AAC3C,EAAA,OAAO,EAAE,QAAA,EAAS;AACpB","file":"active-org.cjs","sourcesContent":["// Universal active-organization selection — the ONE cross-app contract.\n//\n// A user belongs to many orgs; ONE active-org choice must follow them across\n// every Politogy app + subdomain so all apps resolve the SAME org (and campaign\n// apps don't land on a rel-only org and lock themselves). Layers cooperate,\n// mirroring the theme-preference contract:\n// 1. URL `?org=<uuid>` — the authoritative per-request selector. The shared\n// chrome stamps it onto every route so it is bookmarkable + shareable, and\n// each app forwards it to the chrome API as `x-contacts-org`.\n// 2. `.politogyvrm.com` cookie `politogy_active_org` — cross-subdomain vehicle\n// (auth session cookies are host-only) that remembers the LAST USED org so\n// a bare URL in the next app opens on the same org.\n//\n// The stored/most-authoritative value is the FULL org UUID: contacts-api\n// (auth/vrmMembership.selectRequestedMembership) matches the selector by EXACT\n// id first, then falls back to a short suffix that can COLLIDE across a user's\n// orgs — so the full UUID is the only collision-free selector.\n//\n// Server-safe (no 'use client'): constants/resolve helpers are importable from\n// server layouts; the cookie read/write helpers no-op on the server.\n\nexport const ACTIVE_ORG_COOKIE = 'politogy_active_org'\nexport const ACTIVE_ORG_QUERY_PARAM = 'org'\n\n// Loose UUID shape check — we only ever store ids that came from the user's own\n// authoritative membership list, so this just rejects obvious garbage.\nconst UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i\n\nexport function isOrgId(v: unknown): v is string {\n return typeof v === 'string' && UUID_RE.test(v.trim())\n}\n\n/**\n * Read the shared active-org cookie (browser only; null on server or unset).\n * @deprecated v2 apps read the org from the token claims (`orgClaimsFromToken`).\n * The cookie stays written during rollout for apps not yet on the token path.\n */\nexport function readActiveOrgCookie(): string | null {\n if (typeof document === 'undefined') return null\n try {\n const m = document.cookie.match(\n new RegExp(`(?:^|;\\\\s*)${ACTIVE_ORG_COOKIE}=([^;]+)`),\n )\n const v = m ? decodeURIComponent(m[1]) : null\n return isOrgId(v) ? v : null\n } catch {\n return null\n }\n}\n\n// Write the cross-subdomain cookie with the SAME scoping rules as the theme\n// cookie: on a *.politogyvrm.com host scope to the parent domain so every app\n// subdomain reads it; on any other host (localhost, *.pages.dev preview) fall\n// back to a host-only cookie. 1-year, SameSite=Lax, Secure on https.\nexport function writeActiveOrgCookie(orgId: string): void {\n if (typeof document === 'undefined' || typeof window === 'undefined') return\n if (!isOrgId(orgId)) return\n const host = window.location.hostname\n const domainAttr = /(^|\\.)politogyvrm\\.com$/i.test(host) ? '; Domain=.politogyvrm.com' : ''\n const secure = window.location.protocol === 'https:' ? '; Secure' : ''\n document.cookie = `${ACTIVE_ORG_COOKIE}=${encodeURIComponent(\n orgId,\n )}; Path=/; Max-Age=31536000; SameSite=Lax${domainAttr}${secure}`\n}\n\n/**\n * Read the `?org=` selector from a URL search string (full UUID only). Accepts a\n * `location.search`-style string or a full URL.\n */\nexport function readActiveOrgFromUrl(search: string | null | undefined): string | null {\n if (!search) return null\n try {\n const qs = search.includes('?') ? search.slice(search.indexOf('?') + 1) : search\n const v = new URLSearchParams(qs).get(ACTIVE_ORG_QUERY_PARAM)\n return isOrgId(v) ? v : null\n } catch {\n return null\n }\n}\n\n/**\n * Resolve the active org with the cross-app precedence:\n * 1. `?org=<uuid>` in the current URL (explicit per-request selector)\n * 2. the `.politogyvrm.com` cookie (last used, cross-subdomain)\n * 3. null → let the app fall back to the chrome-API default (earliest-joined)\n * Pass `search` on the server (from the request URL); it defaults to\n * `window.location.search` in the browser.\n * @deprecated v2 apps use the token `org_id` claim plus `readOrgSelectorFromUrl`\n * as a per-tab override only.\n */\nexport function resolveActiveOrg(search?: string | null): string | null {\n const fromUrl = readActiveOrgFromUrl(\n search ?? (typeof window !== 'undefined' ? window.location.search : null),\n )\n if (fromUrl) return fromUrl\n return readActiveOrgCookie()\n}\n\n/** The canonical `?org=` query fragment for a full org id (no leading `?`/`&`). */\nexport function activeOrgParam(orgId: string | null | undefined): string {\n return isOrgId(orgId) ? `${ACTIVE_ORG_QUERY_PARAM}=${orgId}` : ''\n}\n\n/**\n * Return `url` with `?org=<uuid>` set/replaced. Used by the shared chrome to\n * stamp the active org onto every route so it is always present in the address\n * bar. Leaves the URL unchanged when `orgId` is not a valid id.\n */\nexport function withActiveOrgParam(url: string, orgId: string | null | undefined): string {\n if (!isOrgId(orgId)) return url\n try {\n // Support both absolute and relative URLs.\n const base = typeof window !== 'undefined' ? window.location.origin : 'https://politogyvrm.com'\n const u = new URL(url, base)\n u.searchParams.set(ACTIVE_ORG_QUERY_PARAM, orgId as string)\n // Preserve relative form when the input was relative.\n return /^https?:\\/\\//i.test(url) ? u.toString() : `${u.pathname}${u.search}${u.hash}`\n } catch {\n return url\n }\n}\n\n// ---------------------------------------------------------------------------\n// v2: auth-owned active org (Global-Rules v38 \"Auth / Active Organization\",\n// UI-Platform v46 \"URL state\"). The IdP owns the shared active org on the SSO\n// session; tokens carry `org_id` (full uuid) + `org_role`. The URL carries the\n// 7-char `org_id` tail as a PER-TAB override only: it never changes the shared\n// active org. Full uuids and the legacy 6-char tail are accepted during rollout.\n// ---------------------------------------------------------------------------\n\nexport const ORG_ID_QUERY_PARAM = 'org_id'\nexport const ORG_ID_TAIL_LENGTH = 7\nconst LEGACY_ORG_TAIL_LENGTH = 6\nconst TAIL_RE = /^[0-9a-f]{6,7}$/i\n\nconst AUTH_BASE_URL = 'https://auth.politogyvrm.com'\nconst AUTH_BASE_URL_STAGING = 'https://auth-staging.politogyvrm.com'\n\n/** The URL form of an org id: the last 7 chars of the uuid, lower case. */\nexport function orgIdTail(orgId: string | null | undefined): string | null {\n return isOrgId(orgId) ? (orgId as string).trim().toLowerCase().slice(-ORG_ID_TAIL_LENGTH) : null\n}\n\n/** A full uuid, the 7-char tail, or the legacy 6-char tail. */\nexport function isOrgSelector(v: unknown): v is string {\n return typeof v === 'string' && (UUID_RE.test(v.trim()) || TAIL_RE.test(v.trim()))\n}\n\n/**\n * Resolve a selector against the user's own org list: exact uuid first, then a\n * unique 7-char tail, then a unique 6-char tail. Ambiguous or no match → null\n * (the IdP selector rules, so the shell never picks an org the IdP would not).\n */\nexport function matchOrgSelector<T extends { id: string }>(\n selector: string | null | undefined,\n orgs: readonly T[],\n): T | null {\n if (!isOrgSelector(selector)) return null\n const sel = selector.trim().toLowerCase()\n if (UUID_RE.test(sel)) return orgs.find((o) => o.id.toLowerCase() === sel) ?? null\n if (sel.length !== ORG_ID_TAIL_LENGTH && sel.length !== LEGACY_ORG_TAIL_LENGTH) return null\n const hits = orgs.filter((o) => o.id.toLowerCase().endsWith(sel))\n return hits.length === 1 ? hits[0] : null\n}\n\n/**\n * Read the per-tab org override from a URL: `org_id` (spec), else the legacy\n * `org`. Returns the raw selector (uuid or tail), or null. Never a source for\n * the shared active org.\n */\nexport function readOrgSelectorFromUrl(search: string | null | undefined): string | null {\n if (!search) return null\n try {\n const qs = search.includes('?') ? search.slice(search.indexOf('?') + 1) : search\n const params = new URLSearchParams(qs)\n for (const key of [ORG_ID_QUERY_PARAM, ACTIVE_ORG_QUERY_PARAM]) {\n const v = params.get(key)\n if (isOrgSelector(v)) return v.trim().toLowerCase()\n }\n return null\n } catch {\n return null\n }\n}\n\n/**\n * Return `url` with `org_id=<7-char tail>` set and any legacy `org=` removed.\n * Leaves the URL unchanged when `orgId` is not a full uuid.\n */\nexport function withOrgIdParam(url: string, orgId: string | null | undefined): string {\n const tail = orgIdTail(orgId)\n if (!tail) return url\n try {\n const base = typeof window !== 'undefined' ? window.location.origin : 'https://politogyvrm.com'\n const u = new URL(url, base)\n u.searchParams.delete(ACTIVE_ORG_QUERY_PARAM)\n u.searchParams.set(ORG_ID_QUERY_PARAM, tail)\n return /^https?:\\/\\//i.test(url) ? u.toString() : `${u.pathname}${u.search}${u.hash}`\n } catch {\n return url\n }\n}\n\nexport type OrgClaims = { orgId: string; orgRole: string | null }\n\n/** Pick `org_id` / `org_role` out of a token claim set. */\nexport function orgClaimsFrom(claims: unknown): OrgClaims | null {\n if (!claims || typeof claims !== 'object') return null\n const c = claims as { org_id?: unknown; org_role?: unknown }\n if (!isOrgId(c.org_id)) return null\n return {\n orgId: (c.org_id as string).trim().toLowerCase(),\n orgRole: typeof c.org_role === 'string' ? c.org_role : null,\n }\n}\n\n/**\n * Read `org_id` / `org_role` from a JWT payload WITHOUT verifying it. For\n * display and routing only: the app server verifies the token (JWKS) and every\n * authorization decision keys on the verified claim, never on this.\n */\nexport function orgClaimsFromToken(token: string | null | undefined): OrgClaims | null {\n if (typeof token !== 'string') return null\n const part = token.split('.')[1]\n if (!part) return null\n try {\n const b64 = part.replace(/-/g, '+').replace(/_/g, '/')\n const padded = b64 + '='.repeat((4 - (b64.length % 4)) % 4)\n const json =\n typeof atob === 'function'\n ? decodeURIComponent(\n Array.from(atob(padded), (ch) => '%' + ch.charCodeAt(0).toString(16).padStart(2, '0')).join(''),\n )\n : ''\n return orgClaimsFrom(JSON.parse(json))\n } catch {\n return null\n }\n}\n\n/** The IdP base for the current environment (staging host → staging IdP). */\nexport function authBaseUrl(): string {\n if (typeof window !== 'undefined' && window.location.hostname.toLowerCase().includes('staging')) {\n return AUTH_BASE_URL_STAGING\n }\n return AUTH_BASE_URL\n}\n\nexport class ActiveOrgSwitchError extends Error {\n constructor(\n readonly status: number,\n message: string,\n ) {\n super(message)\n this.name = 'ActiveOrgSwitchError'\n }\n}\n\n/**\n * Switch the SHARED active org on the IdP: `POST {auth}/api/active-org`. The\n * IdP checks membership against VRM Core and updates the SSO session; the\n * caller then re-exchanges (server) for tokens carrying the new `org_id`.\n * Also mirrors the legacy cookie so apps not yet on v2 follow the switch.\n * Throws `ActiveOrgSwitchError` (403 = not a member, 401 = no SSO session).\n */\nexport async function switchActiveOrg(\n orgId: string,\n opts: { authBaseUrl?: string; fetch?: typeof fetch } = {},\n): Promise<OrgClaims> {\n if (!isOrgId(orgId)) throw new ActiveOrgSwitchError(400, 'org_id must be a full uuid')\n const doFetch = opts.fetch ?? fetch\n const res = await doFetch(`${opts.authBaseUrl ?? authBaseUrl()}/api/active-org`, {\n method: 'POST',\n credentials: 'include',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ org_id: orgId }),\n })\n if (!res.ok) {\n let msg = `active-org switch failed (${res.status})`\n try {\n const body = (await res.json()) as { error?: string }\n if (body?.error) msg = body.error\n } catch {\n /* no body */\n }\n throw new ActiveOrgSwitchError(res.status, msg)\n }\n const claims = orgClaimsFrom(await res.json().catch(() => null))\n if (!claims) throw new ActiveOrgSwitchError(502, 'active-org switch returned no org_id')\n writeActiveOrgCookie(claims.orgId)\n return claims\n}\n\n/**\n * URL-sync rule for the address-bar org selector. Returns the new href, or\n * null when nothing should be written. A bare URL (no `org_id`, no legacy\n * `org`) stays bare: the shell must never inject `org_id` on its own, because\n * a self-injected selector then acts as a per-tab override and beats the token\n * org and the cross-app `politogy_active_org` trigger. Only a selector the user\n * brought (or a real switch put there) is canonicalized to the current org.\n */\nexport function syncOrgIdInUrl(href: string, orgId: string | null | undefined): string | null {\n const tail = orgIdTail(orgId)\n if (!tail) return null\n let u: URL\n try {\n u = new URL(href)\n } catch {\n return null\n }\n const hasLegacy = u.searchParams.has(ACTIVE_ORG_QUERY_PARAM)\n const current = u.searchParams.get(ORG_ID_QUERY_PARAM)\n if (!hasLegacy && current === null) return null\n if (!hasLegacy && current === tail) return null\n u.searchParams.delete(ACTIVE_ORG_QUERY_PARAM)\n u.searchParams.set(ORG_ID_QUERY_PARAM, tail)\n return u.toString()\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/active-org.ts"],"names":[],"mappings":";;;AAqBO,IAAM,iBAAA,GAAoB;AAC1B,IAAM,sBAAA,GAAyB;AAItC,IAAM,OAAA,GAAU,iEAAA;AAET,SAAS,QAAQ,CAAA,EAAyB;AAC/C,EAAA,OAAO,OAAO,CAAA,KAAM,QAAA,IAAY,QAAQ,IAAA,CAAK,CAAA,CAAE,MAAM,CAAA;AACvD;AAOO,SAAS,mBAAA,GAAqC;AACnD,EAAA,IAAI,OAAO,QAAA,KAAa,WAAA,EAAa,OAAO,IAAA;AAC5C,EAAA,IAAI;AACF,IAAA,MAAM,CAAA,GAAI,SAAS,MAAA,CAAO,KAAA;AAAA,MACxB,IAAI,MAAA,CAAO,CAAA,WAAA,EAAc,iBAAiB,CAAA,QAAA,CAAU;AAAA,KACtD;AACA,IAAA,MAAM,IAAI,CAAA,GAAI,kBAAA,CAAmB,CAAA,CAAE,CAAC,CAAC,CAAA,GAAI,IAAA;AACzC,IAAA,OAAO,OAAA,CAAQ,CAAC,CAAA,GAAI,CAAA,GAAI,IAAA;AAAA,EAC1B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AAMO,SAAS,qBAAqB,KAAA,EAAqB;AACxD,EAAA,IAAI,OAAO,QAAA,KAAa,WAAA,IAAe,OAAO,WAAW,WAAA,EAAa;AACtE,EAAA,IAAI,CAAC,OAAA,CAAQ,KAA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AAA,MAAM,IAAI,oBAAA,CAAqB,GAAA,CAAI,MAAA,EAAQ,GAAG,CAAA;AAAA,EAChD;AACA,EAAA,MAAM,MAAA,GAAS,cAAc,MAAM,GAAA,CAAI,MAAK,CAAE,KAAA,CAAM,MAAM,IAAI,CAAC,CAAA;AAC/D,EAAA,IAAI,CAAC,MAAA,EAAQ,MAAM,IAAI,oBAAA,CAAqB,KAAK,sCAAsC,CAAA;AACvF,EAAA,oBAAA,CAAqB,OAAO,KAAK,CAAA;AACjC,EAAA,OAAO,MAAA;AACT;AAUO,SAAS,cAAA,CAAe,MAAc,KAAA,EAAiD;AAC5F,EAAA,MAAM,IAAA,GAAO,UAAU,KAAK,CAAA;AAC5B,EAAA,IAAI,CAAC,MAAM,OAAO,IAAA;AAClB,EAAA,IAAI,CAAA;AACJ,EAAA,IAAI;AACF,IAAA,CAAA,GAAI,IAAI,IAAI,IAAI,CAAA;AAAA,EAClB,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,SAAA,GAAY,CAAA,CAAE,YAAA,CAAa,GAAA,CAAI,sBAAsB,CAAA;AAC3D,EAAA,MAAM,OAAA,GAAU,CAAA,CAAE,YAAA,CAAa,GAAA,CAAI,kBAAkB,CAAA;AACrD,EAAA,IAAI,CAAC,SAAA,IAAa,OAAA,KAAY,IAAA,EAAM,OAAO,IAAA;AAC3C,EAAA,IAAI,CAAC,SAAA,IAAa,OAAA,KAAY,IAAA,EAAM,OAAO,IAAA;AAC3C,EAAA,CAAA,CAAE,YAAA,CAAa,OAAO,sBAAsB,CAAA;AAC5C,EAAA,CAAA,CAAE,YAAA,CAAa,GAAA,CAAI,kBAAA,EAAoB,IAAI,CAAA;AAC3C,EAAA,OAAO,EAAE,QAAA,EAAS;AACpB","file":"active-org.cjs","sourcesContent":["// Universal active-organization selection — the ONE cross-app contract.\n//\n// A user belongs to many orgs; ONE active-org choice must follow them across\n// every Politogy app + subdomain so all apps resolve the SAME org (and campaign\n// apps don't land on a rel-only org and lock themselves). Layers cooperate,\n// mirroring the theme-preference contract:\n// 1. URL `?org=<uuid>` — the authoritative per-request selector. The shared\n// chrome stamps it onto every route so it is bookmarkable + shareable, and\n// each app forwards it to the chrome API as `x-contacts-org`.\n// 2. `.politogyvrm.com` cookie `politogy_active_org` — cross-subdomain vehicle\n// (auth session cookies are host-only) that remembers the LAST USED org so\n// a bare URL in the next app opens on the same org.\n//\n// The stored/most-authoritative value is the FULL org UUID: contacts-api\n// (auth/vrmMembership.selectRequestedMembership) matches the selector by EXACT\n// id first, then falls back to a short suffix that can COLLIDE across a user's\n// orgs — so the full UUID is the only collision-free selector.\n//\n// Server-safe (no 'use client'): constants/resolve helpers are importable from\n// server layouts; the cookie read/write helpers no-op on the server.\n\nexport const ACTIVE_ORG_COOKIE = 'politogy_active_org'\nexport const ACTIVE_ORG_QUERY_PARAM = 'org'\n\n// Loose UUID shape check — we only ever store ids that came from the user's own\n// authoritative membership list, so this just rejects obvious garbage.\nconst UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i\n\nexport function isOrgId(v: unknown): v is string {\n return typeof v === 'string' && UUID_RE.test(v.trim())\n}\n\n/**\n * Read the shared active-org cookie (browser only; null on server or unset).\n * @deprecated v2 apps read the org from the token claims (`orgClaimsFromToken`).\n * The cookie stays written during rollout for apps not yet on the token path.\n */\nexport function readActiveOrgCookie(): string | null {\n if (typeof document === 'undefined') return null\n try {\n const m = document.cookie.match(\n new RegExp(`(?:^|;\\\\s*)${ACTIVE_ORG_COOKIE}=([^;]+)`),\n )\n const v = m ? decodeURIComponent(m[1]) : null\n return isOrgId(v) ? v : null\n } catch {\n return null\n }\n}\n\n// Write the cross-subdomain cookie with the SAME scoping rules as the theme\n// cookie: on a *.politogyvrm.com host scope to the parent domain so every app\n// subdomain reads it; on any other host (localhost, *.pages.dev preview) fall\n// back to a host-only cookie. 1-year, SameSite=Lax, Secure on https.\nexport function writeActiveOrgCookie(orgId: string): void {\n if (typeof document === 'undefined' || typeof window === 'undefined') return\n if (!isOrgId(orgId)) return\n const host = window.location.hostname\n const domainAttr = /(^|\\.)politogyvrm\\.com$/i.test(host) ? '; Domain=.politogyvrm.com' : ''\n const secure = window.location.protocol === 'https:' ? '; Secure' : ''\n document.cookie = `${ACTIVE_ORG_COOKIE}=${encodeURIComponent(\n orgId,\n )}; Path=/; Max-Age=31536000; SameSite=Lax${domainAttr}${secure}`\n}\n\n/**\n * Read the `?org=` selector from a URL search string (full UUID only). Accepts a\n * `location.search`-style string or a full URL.\n */\nexport function readActiveOrgFromUrl(search: string | null | undefined): string | null {\n if (!search) return null\n try {\n const qs = search.includes('?') ? search.slice(search.indexOf('?') + 1) : search\n const v = new URLSearchParams(qs).get(ACTIVE_ORG_QUERY_PARAM)\n return isOrgId(v) ? v : null\n } catch {\n return null\n }\n}\n\n/**\n * Resolve the active org with the cross-app precedence:\n * 1. `?org=<uuid>` in the current URL (explicit per-request selector)\n * 2. the `.politogyvrm.com` cookie (last used, cross-subdomain)\n * 3. null → let the app fall back to the chrome-API default (earliest-joined)\n * Pass `search` on the server (from the request URL); it defaults to\n * `window.location.search` in the browser.\n * @deprecated v2 apps use the token `org_id` claim plus `readOrgSelectorFromUrl`\n * as a per-tab override only.\n */\nexport function resolveActiveOrg(search?: string | null): string | null {\n const fromUrl = readActiveOrgFromUrl(\n search ?? (typeof window !== 'undefined' ? window.location.search : null),\n )\n if (fromUrl) return fromUrl\n return readActiveOrgCookie()\n}\n\n/** The canonical `?org=` query fragment for a full org id (no leading `?`/`&`). */\nexport function activeOrgParam(orgId: string | null | undefined): string {\n return isOrgId(orgId) ? `${ACTIVE_ORG_QUERY_PARAM}=${orgId}` : ''\n}\n\n/**\n * Return `url` with `?org=<uuid>` set/replaced. Used by the shared chrome to\n * stamp the active org onto every route so it is always present in the address\n * bar. Leaves the URL unchanged when `orgId` is not a valid id.\n */\nexport function withActiveOrgParam(url: string, orgId: string | null | undefined): string {\n if (!isOrgId(orgId)) return url\n try {\n // Support both absolute and relative URLs.\n const base = typeof window !== 'undefined' ? window.location.origin : 'https://politogyvrm.com'\n const u = new URL(url, base)\n u.searchParams.set(ACTIVE_ORG_QUERY_PARAM, orgId as string)\n // Preserve relative form when the input was relative.\n return /^https?:\\/\\//i.test(url) ? u.toString() : `${u.pathname}${u.search}${u.hash}`\n } catch {\n return url\n }\n}\n\n// ---------------------------------------------------------------------------\n// v2: auth-owned active org (Global-Rules v38 \"Auth / Active Organization\",\n// UI-Platform v46 \"URL state\"). The IdP owns the shared active org on the SSO\n// session; tokens carry `org_id` (full uuid) + `org_role`. The URL carries the\n// 7-char `org_id` tail as a PER-TAB override only: it never changes the shared\n// active org. Full uuids and the legacy 6-char tail are accepted during rollout.\n// ---------------------------------------------------------------------------\n\nexport const ORG_ID_QUERY_PARAM = 'org_id'\nexport const ORG_ID_TAIL_LENGTH = 7\nconst LEGACY_ORG_TAIL_LENGTH = 6\nconst TAIL_RE = /^[0-9a-f]{6,7}$/i\n\nconst AUTH_BASE_URL = 'https://auth.politogyvrm.com'\nconst AUTH_BASE_URL_STAGING = 'https://auth-staging.politogyvrm.com'\nconst SETTINGS_BASE_URL = 'https://settings.politogyvrm.com'\nconst SETTINGS_BASE_URL_STAGING = 'https://settings-staging.politogyvrm.com'\n\n/** The URL form of an org id: the last 7 chars of the uuid, lower case. */\nexport function orgIdTail(orgId: string | null | undefined): string | null {\n return isOrgId(orgId) ? (orgId as string).trim().toLowerCase().slice(-ORG_ID_TAIL_LENGTH) : null\n}\n\n/** A full uuid, the 7-char tail, or the legacy 6-char tail. */\nexport function isOrgSelector(v: unknown): v is string {\n return typeof v === 'string' && (UUID_RE.test(v.trim()) || TAIL_RE.test(v.trim()))\n}\n\n/**\n * Resolve a selector against the user's own org list: exact uuid first, then a\n * unique 7-char tail, then a unique 6-char tail. Ambiguous or no match → null\n * (the IdP selector rules, so the shell never picks an org the IdP would not).\n */\nexport function matchOrgSelector<T extends { id: string }>(\n selector: string | null | undefined,\n orgs: readonly T[],\n): T | null {\n if (!isOrgSelector(selector)) return null\n const sel = selector.trim().toLowerCase()\n if (UUID_RE.test(sel)) return orgs.find((o) => o.id.toLowerCase() === sel) ?? null\n if (sel.length !== ORG_ID_TAIL_LENGTH && sel.length !== LEGACY_ORG_TAIL_LENGTH) return null\n const hits = orgs.filter((o) => o.id.toLowerCase().endsWith(sel))\n return hits.length === 1 ? hits[0] : null\n}\n\n/**\n * Read the per-tab org override from a URL: `org_id` (spec), else the legacy\n * `org`. Returns the raw selector (uuid or tail), or null. Never a source for\n * the shared active org.\n */\nexport function readOrgSelectorFromUrl(search: string | null | undefined): string | null {\n if (!search) return null\n try {\n const qs = search.includes('?') ? search.slice(search.indexOf('?') + 1) : search\n const params = new URLSearchParams(qs)\n for (const key of [ORG_ID_QUERY_PARAM, ACTIVE_ORG_QUERY_PARAM]) {\n const v = params.get(key)\n if (isOrgSelector(v)) return v.trim().toLowerCase()\n }\n return null\n } catch {\n return null\n }\n}\n\n/**\n * Return `url` with `org_id=<7-char tail>` set and any legacy `org=` removed.\n * Leaves the URL unchanged when `orgId` is not a full uuid.\n */\nexport function withOrgIdParam(url: string, orgId: string | null | undefined): string {\n const tail = orgIdTail(orgId)\n if (!tail) return url\n try {\n const base = typeof window !== 'undefined' ? window.location.origin : 'https://politogyvrm.com'\n const u = new URL(url, base)\n u.searchParams.delete(ACTIVE_ORG_QUERY_PARAM)\n u.searchParams.set(ORG_ID_QUERY_PARAM, tail)\n return /^https?:\\/\\//i.test(url) ? u.toString() : `${u.pathname}${u.search}${u.hash}`\n } catch {\n return url\n }\n}\n\nexport type OrgClaims = { orgId: string; orgRole: string | null }\n\n/** Pick `org_id` / `org_role` out of a token claim set. */\nexport function orgClaimsFrom(claims: unknown): OrgClaims | null {\n if (!claims || typeof claims !== 'object') return null\n const c = claims as { org_id?: unknown; org_role?: unknown }\n if (!isOrgId(c.org_id)) return null\n return {\n orgId: (c.org_id as string).trim().toLowerCase(),\n orgRole: typeof c.org_role === 'string' ? c.org_role : null,\n }\n}\n\n/**\n * Read `org_id` / `org_role` from a JWT payload WITHOUT verifying it. For\n * display and routing only: the app server verifies the token (JWKS) and every\n * authorization decision keys on the verified claim, never on this.\n */\nexport function orgClaimsFromToken(token: string | null | undefined): OrgClaims | null {\n if (typeof token !== 'string') return null\n const part = token.split('.')[1]\n if (!part) return null\n try {\n const b64 = part.replace(/-/g, '+').replace(/_/g, '/')\n const padded = b64 + '='.repeat((4 - (b64.length % 4)) % 4)\n const json =\n typeof atob === 'function'\n ? decodeURIComponent(\n Array.from(atob(padded), (ch) => '%' + ch.charCodeAt(0).toString(16).padStart(2, '0')).join(''),\n )\n : ''\n return orgClaimsFrom(JSON.parse(json))\n } catch {\n return null\n }\n}\n\n/** The IdP base for the current environment (staging host → staging IdP). */\nexport function authBaseUrl(): string {\n if (typeof window !== 'undefined' && window.location.hostname.toLowerCase().includes('staging')) {\n return AUTH_BASE_URL_STAGING\n }\n return AUTH_BASE_URL\n}\n\n/**\n * The Settings app base for the current environment (staging host → staging\n * Settings). Organization settings, onboarding, activation and subscription &\n * billing live here (Reference/UI-Platform \"Retirement of app.politogyvrm.com\").\n */\nexport function settingsBaseUrl(): string {\n if (typeof window !== 'undefined' && window.location.hostname.toLowerCase().includes('staging')) {\n return SETTINGS_BASE_URL_STAGING\n }\n return SETTINGS_BASE_URL\n}\n\nexport class ActiveOrgSwitchError extends Error {\n constructor(\n readonly status: number,\n message: string,\n ) {\n super(message)\n this.name = 'ActiveOrgSwitchError'\n }\n}\n\n/**\n * Switch the SHARED active org on the IdP: `POST {auth}/api/active-org`. The\n * IdP checks membership against VRM Core and updates the SSO session; the\n * caller then re-exchanges (server) for tokens carrying the new `org_id`.\n * Also mirrors the legacy cookie so apps not yet on v2 follow the switch.\n * Throws `ActiveOrgSwitchError` (403 = not a member, 401 = no SSO session).\n */\nexport async function switchActiveOrg(\n orgId: string,\n opts: { authBaseUrl?: string; fetch?: typeof fetch } = {},\n): Promise<OrgClaims> {\n if (!isOrgId(orgId)) throw new ActiveOrgSwitchError(400, 'org_id must be a full uuid')\n const doFetch = opts.fetch ?? fetch\n const res = await doFetch(`${opts.authBaseUrl ?? authBaseUrl()}/api/active-org`, {\n method: 'POST',\n credentials: 'include',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ org_id: orgId }),\n })\n if (!res.ok) {\n let msg = `active-org switch failed (${res.status})`\n try {\n const body = (await res.json()) as { error?: string }\n if (body?.error) msg = body.error\n } catch {\n /* no body */\n }\n throw new ActiveOrgSwitchError(res.status, msg)\n }\n const claims = orgClaimsFrom(await res.json().catch(() => null))\n if (!claims) throw new ActiveOrgSwitchError(502, 'active-org switch returned no org_id')\n writeActiveOrgCookie(claims.orgId)\n return claims\n}\n\n/**\n * URL-sync rule for the address-bar org selector. Returns the new href, or\n * null when nothing should be written. A bare URL (no `org_id`, no legacy\n * `org`) stays bare: the shell must never inject `org_id` on its own, because\n * a self-injected selector then acts as a per-tab override and beats the token\n * org and the cross-app `politogy_active_org` trigger. Only a selector the user\n * brought (or a real switch put there) is canonicalized to the current org.\n */\nexport function syncOrgIdInUrl(href: string, orgId: string | null | undefined): string | null {\n const tail = orgIdTail(orgId)\n if (!tail) return null\n let u: URL\n try {\n u = new URL(href)\n } catch {\n return null\n }\n const hasLegacy = u.searchParams.has(ACTIVE_ORG_QUERY_PARAM)\n const current = u.searchParams.get(ORG_ID_QUERY_PARAM)\n if (!hasLegacy && current === null) return null\n if (!hasLegacy && current === tail) return null\n u.searchParams.delete(ACTIVE_ORG_QUERY_PARAM)\n u.searchParams.set(ORG_ID_QUERY_PARAM, tail)\n return u.toString()\n}\n"]}
|
package/dist/active-org.d.cts
CHANGED
|
@@ -71,6 +71,12 @@ declare function orgClaimsFrom(claims: unknown): OrgClaims | null;
|
|
|
71
71
|
declare function orgClaimsFromToken(token: string | null | undefined): OrgClaims | null;
|
|
72
72
|
/** The IdP base for the current environment (staging host → staging IdP). */
|
|
73
73
|
declare function authBaseUrl(): string;
|
|
74
|
+
/**
|
|
75
|
+
* The Settings app base for the current environment (staging host → staging
|
|
76
|
+
* Settings). Organization settings, onboarding, activation and subscription &
|
|
77
|
+
* billing live here (Reference/UI-Platform "Retirement of app.politogyvrm.com").
|
|
78
|
+
*/
|
|
79
|
+
declare function settingsBaseUrl(): string;
|
|
74
80
|
declare class ActiveOrgSwitchError extends Error {
|
|
75
81
|
readonly status: number;
|
|
76
82
|
constructor(status: number, message: string);
|
|
@@ -96,4 +102,4 @@ declare function switchActiveOrg(orgId: string, opts?: {
|
|
|
96
102
|
*/
|
|
97
103
|
declare function syncOrgIdInUrl(href: string, orgId: string | null | undefined): string | null;
|
|
98
104
|
|
|
99
|
-
export { ACTIVE_ORG_COOKIE, ACTIVE_ORG_QUERY_PARAM, ActiveOrgSwitchError, ORG_ID_QUERY_PARAM, ORG_ID_TAIL_LENGTH, type OrgClaims, activeOrgParam, authBaseUrl, isOrgId, isOrgSelector, matchOrgSelector, orgClaimsFrom, orgClaimsFromToken, orgIdTail, readActiveOrgCookie, readActiveOrgFromUrl, readOrgSelectorFromUrl, resolveActiveOrg, switchActiveOrg, syncOrgIdInUrl, withActiveOrgParam, withOrgIdParam, writeActiveOrgCookie };
|
|
105
|
+
export { ACTIVE_ORG_COOKIE, ACTIVE_ORG_QUERY_PARAM, ActiveOrgSwitchError, ORG_ID_QUERY_PARAM, ORG_ID_TAIL_LENGTH, type OrgClaims, activeOrgParam, authBaseUrl, isOrgId, isOrgSelector, matchOrgSelector, orgClaimsFrom, orgClaimsFromToken, orgIdTail, readActiveOrgCookie, readActiveOrgFromUrl, readOrgSelectorFromUrl, resolveActiveOrg, settingsBaseUrl, switchActiveOrg, syncOrgIdInUrl, withActiveOrgParam, withOrgIdParam, writeActiveOrgCookie };
|
package/dist/active-org.d.ts
CHANGED
|
@@ -71,6 +71,12 @@ declare function orgClaimsFrom(claims: unknown): OrgClaims | null;
|
|
|
71
71
|
declare function orgClaimsFromToken(token: string | null | undefined): OrgClaims | null;
|
|
72
72
|
/** The IdP base for the current environment (staging host → staging IdP). */
|
|
73
73
|
declare function authBaseUrl(): string;
|
|
74
|
+
/**
|
|
75
|
+
* The Settings app base for the current environment (staging host → staging
|
|
76
|
+
* Settings). Organization settings, onboarding, activation and subscription &
|
|
77
|
+
* billing live here (Reference/UI-Platform "Retirement of app.politogyvrm.com").
|
|
78
|
+
*/
|
|
79
|
+
declare function settingsBaseUrl(): string;
|
|
74
80
|
declare class ActiveOrgSwitchError extends Error {
|
|
75
81
|
readonly status: number;
|
|
76
82
|
constructor(status: number, message: string);
|
|
@@ -96,4 +102,4 @@ declare function switchActiveOrg(orgId: string, opts?: {
|
|
|
96
102
|
*/
|
|
97
103
|
declare function syncOrgIdInUrl(href: string, orgId: string | null | undefined): string | null;
|
|
98
104
|
|
|
99
|
-
export { ACTIVE_ORG_COOKIE, ACTIVE_ORG_QUERY_PARAM, ActiveOrgSwitchError, ORG_ID_QUERY_PARAM, ORG_ID_TAIL_LENGTH, type OrgClaims, activeOrgParam, authBaseUrl, isOrgId, isOrgSelector, matchOrgSelector, orgClaimsFrom, orgClaimsFromToken, orgIdTail, readActiveOrgCookie, readActiveOrgFromUrl, readOrgSelectorFromUrl, resolveActiveOrg, switchActiveOrg, syncOrgIdInUrl, withActiveOrgParam, withOrgIdParam, writeActiveOrgCookie };
|
|
105
|
+
export { ACTIVE_ORG_COOKIE, ACTIVE_ORG_QUERY_PARAM, ActiveOrgSwitchError, ORG_ID_QUERY_PARAM, ORG_ID_TAIL_LENGTH, type OrgClaims, activeOrgParam, authBaseUrl, isOrgId, isOrgSelector, matchOrgSelector, orgClaimsFrom, orgClaimsFromToken, orgIdTail, readActiveOrgCookie, readActiveOrgFromUrl, readOrgSelectorFromUrl, resolveActiveOrg, settingsBaseUrl, switchActiveOrg, syncOrgIdInUrl, withActiveOrgParam, withOrgIdParam, writeActiveOrgCookie };
|
package/dist/active-org.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { ACTIVE_ORG_COOKIE, ACTIVE_ORG_QUERY_PARAM, ActiveOrgSwitchError, ORG_ID_QUERY_PARAM, ORG_ID_TAIL_LENGTH, activeOrgParam, authBaseUrl, isOrgId, isOrgSelector, matchOrgSelector, orgClaimsFrom, orgClaimsFromToken, orgIdTail, readActiveOrgCookie, readActiveOrgFromUrl, readOrgSelectorFromUrl, resolveActiveOrg, switchActiveOrg, syncOrgIdInUrl, withActiveOrgParam, withOrgIdParam, writeActiveOrgCookie } from './chunk-
|
|
1
|
+
export { ACTIVE_ORG_COOKIE, ACTIVE_ORG_QUERY_PARAM, ActiveOrgSwitchError, ORG_ID_QUERY_PARAM, ORG_ID_TAIL_LENGTH, activeOrgParam, authBaseUrl, isOrgId, isOrgSelector, matchOrgSelector, orgClaimsFrom, orgClaimsFromToken, orgIdTail, readActiveOrgCookie, readActiveOrgFromUrl, readOrgSelectorFromUrl, resolveActiveOrg, settingsBaseUrl, switchActiveOrg, syncOrgIdInUrl, withActiveOrgParam, withOrgIdParam, writeActiveOrgCookie } from './chunk-5LO5W7W5.js';
|
|
2
2
|
//# sourceMappingURL=active-org.js.map
|
|
3
3
|
//# sourceMappingURL=active-org.js.map
|
package/dist/app-chrome.cjs
CHANGED
|
@@ -141,6 +141,8 @@ var LEGACY_ORG_TAIL_LENGTH = 6;
|
|
|
141
141
|
var TAIL_RE = /^[0-9a-f]{6,7}$/i;
|
|
142
142
|
var AUTH_BASE_URL = "https://auth.politogyvrm.com";
|
|
143
143
|
var AUTH_BASE_URL_STAGING = "https://auth-staging.politogyvrm.com";
|
|
144
|
+
var SETTINGS_BASE_URL = "https://settings.politogyvrm.com";
|
|
145
|
+
var SETTINGS_BASE_URL_STAGING = "https://settings-staging.politogyvrm.com";
|
|
144
146
|
function orgIdTail(orgId) {
|
|
145
147
|
return isOrgId(orgId) ? orgId.trim().toLowerCase().slice(-ORG_ID_TAIL_LENGTH) : null;
|
|
146
148
|
}
|
|
@@ -184,6 +186,12 @@ function authBaseUrl() {
|
|
|
184
186
|
}
|
|
185
187
|
return AUTH_BASE_URL;
|
|
186
188
|
}
|
|
189
|
+
function settingsBaseUrl() {
|
|
190
|
+
if (typeof window !== "undefined" && window.location.hostname.toLowerCase().includes("staging")) {
|
|
191
|
+
return SETTINGS_BASE_URL_STAGING;
|
|
192
|
+
}
|
|
193
|
+
return SETTINGS_BASE_URL;
|
|
194
|
+
}
|
|
187
195
|
var ActiveOrgSwitchError = class extends Error {
|
|
188
196
|
constructor(status, message) {
|
|
189
197
|
super(message);
|
|
@@ -488,8 +496,9 @@ function notificationsFeedToPayload(feed, orgId) {
|
|
|
488
496
|
};
|
|
489
497
|
}
|
|
490
498
|
var CORE_APP_ORIGIN = "https://app.politogyvrm.com";
|
|
491
|
-
var
|
|
492
|
-
var
|
|
499
|
+
var SETTINGS_APP_ORIGIN = "https://settings.politogyvrm.com";
|
|
500
|
+
var CORE_BILLING_PATH = "/organization-settings/subscription-billing";
|
|
501
|
+
var CORE_BILLING_URL = `${SETTINGS_APP_ORIGIN}${CORE_BILLING_PATH}`;
|
|
493
502
|
var QUARANTINED_CONTACTS_URL = `https://contacts.politogyvrm.com/duplicates`;
|
|
494
503
|
var SPECS_ORIGIN = "https://specs.politogyvrm.com";
|
|
495
504
|
function withOrgParam(url, orgId) {
|
|
@@ -3161,7 +3170,7 @@ function NavActiveRail() {
|
|
|
3161
3170
|
{
|
|
3162
3171
|
"aria-hidden": "true",
|
|
3163
3172
|
className: "pointer-events-none absolute inset-y-0 left-0 w-[2px]",
|
|
3164
|
-
style: { background: "var(--mode-accent, transparent)" }
|
|
3173
|
+
style: { background: "var(--sidebar-active-marker, var(--mode-accent, transparent))" }
|
|
3165
3174
|
}
|
|
3166
3175
|
);
|
|
3167
3176
|
}
|
|
@@ -3748,7 +3757,9 @@ function NavTopBarActionButton({ action }) {
|
|
|
3748
3757
|
var BETA_BANNER_DEFAULTS = {
|
|
3749
3758
|
text: "Our product is in Beta. Thank you for participating in the Pilot Program. ",
|
|
3750
3759
|
linkLabel: "You can click here to see the Terms & Conditions for Beta users.",
|
|
3751
|
-
|
|
3760
|
+
// Legal pages live on Politogy ID (Reference/UI-Platform "Retirement of
|
|
3761
|
+
// app.politogyvrm.com"); resolved per render so staging stays in staging.
|
|
3762
|
+
href: () => `${authBaseUrl()}/beta-terms`
|
|
3752
3763
|
};
|
|
3753
3764
|
var BETA_BANNER_DISMISS_KEY = "politogy_beta_banner_dismissed";
|
|
3754
3765
|
function clearBetaBannerDismissal() {
|
|
@@ -3761,7 +3772,7 @@ function clearBetaBannerDismissal() {
|
|
|
3761
3772
|
function NavBetaBanner({ text, linkLabel, href, dismissible = true }) {
|
|
3762
3773
|
const body = text ?? BETA_BANNER_DEFAULTS.text;
|
|
3763
3774
|
const label = linkLabel ?? BETA_BANNER_DEFAULTS.linkLabel;
|
|
3764
|
-
const target = href ?? BETA_BANNER_DEFAULTS.href;
|
|
3775
|
+
const target = href ?? BETA_BANNER_DEFAULTS.href();
|
|
3765
3776
|
const [dismissed, setDismissed] = react.useState(false);
|
|
3766
3777
|
react.useEffect(() => {
|
|
3767
3778
|
if (!dismissible) return;
|
|
@@ -4899,16 +4910,6 @@ function FrameBody({
|
|
|
4899
4910
|
}
|
|
4900
4911
|
var ORG_STORAGE_KEY = "vrm.activeOrg";
|
|
4901
4912
|
var MODE_STORAGE_KEY = "vrm.activeMode";
|
|
4902
|
-
var CORE_BASE_URL = "https://app.politogyvrm.com";
|
|
4903
|
-
var CORE_BASE_URL_STAGING = "https://staging-app.politogyvrm.com";
|
|
4904
|
-
function getCoreBaseUrl() {
|
|
4905
|
-
if (typeof window !== "undefined") {
|
|
4906
|
-
if (window.location.hostname.toLowerCase().includes("staging")) {
|
|
4907
|
-
return CORE_BASE_URL_STAGING;
|
|
4908
|
-
}
|
|
4909
|
-
}
|
|
4910
|
-
return CORE_BASE_URL;
|
|
4911
|
-
}
|
|
4912
4913
|
var ChromeStateContext = react.createContext(null);
|
|
4913
4914
|
function useChromeState() {
|
|
4914
4915
|
return react.useContext(ChromeStateContext);
|
|
@@ -4963,7 +4964,13 @@ function TokenChromeStateProvider({
|
|
|
4963
4964
|
);
|
|
4964
4965
|
}, [overrideOrg, tokenOrg.orgId]);
|
|
4965
4966
|
react.useEffect(() => {
|
|
4966
|
-
if (pendingOrg
|
|
4967
|
+
if (!pendingOrg || tokenOrg.orgId !== pendingOrg) return;
|
|
4968
|
+
setPendingOrg(null);
|
|
4969
|
+
try {
|
|
4970
|
+
const next = syncOrgIdInUrl(window.location.href, pendingOrg);
|
|
4971
|
+
if (next) window.history.replaceState(window.history.state, "", next);
|
|
4972
|
+
} catch {
|
|
4973
|
+
}
|
|
4967
4974
|
}, [pendingOrg, tokenOrg.orgId]);
|
|
4968
4975
|
const setOrgId = react.useCallback((id) => {
|
|
4969
4976
|
const current = tokenOrgRef.current;
|
|
@@ -5026,10 +5033,11 @@ function TokenChromeStateProvider({
|
|
|
5026
5033
|
setOrgId,
|
|
5027
5034
|
orgs,
|
|
5028
5035
|
orgsLoading: !tokenOrg.orgs && orgsFetching && !orgsError && !fetchedOrgs,
|
|
5036
|
+
orgPending: pendingOrg !== null,
|
|
5029
5037
|
navDisplay,
|
|
5030
5038
|
setNavDisplay
|
|
5031
5039
|
}),
|
|
5032
|
-
[orgId, setOrgId, orgs, tokenOrg.orgs, orgsFetching, orgsError, fetchedOrgs, navDisplay, setNavDisplay]
|
|
5040
|
+
[orgId, setOrgId, orgs, tokenOrg.orgs, orgsFetching, orgsError, fetchedOrgs, pendingOrg, navDisplay, setNavDisplay]
|
|
5033
5041
|
);
|
|
5034
5042
|
return /* @__PURE__ */ jsxRuntime.jsx(ChromeStateContext.Provider, { value, children });
|
|
5035
5043
|
}
|
|
@@ -5172,6 +5180,7 @@ function ChromeStateProvider({
|
|
|
5172
5180
|
rawRole: o.rawRole ?? null
|
|
5173
5181
|
})),
|
|
5174
5182
|
orgsLoading: false,
|
|
5183
|
+
orgPending: false,
|
|
5175
5184
|
navDisplay,
|
|
5176
5185
|
setNavDisplay
|
|
5177
5186
|
};
|
|
@@ -5190,6 +5199,7 @@ function ChromeStateProvider({
|
|
|
5190
5199
|
// Loading until the fetch settles. On error we stop loading so the frame
|
|
5191
5200
|
// falls back to the app label rather than shimmering forever.
|
|
5192
5201
|
orgsLoading: orgsFetching && !orgsError && !orgs,
|
|
5202
|
+
orgPending: false,
|
|
5193
5203
|
navDisplay,
|
|
5194
5204
|
setNavDisplay
|
|
5195
5205
|
};
|
|
@@ -5396,9 +5406,15 @@ function useIsSuperAdmin() {
|
|
|
5396
5406
|
const state = useChromeState();
|
|
5397
5407
|
return (state?.orgs ?? []).some((o) => /super/i.test(o.rawRole ?? ""));
|
|
5398
5408
|
}
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5409
|
+
function footerLinks() {
|
|
5410
|
+
const auth = authBaseUrl();
|
|
5411
|
+
return [
|
|
5412
|
+
{ label: "Privacy", href: `${auth}/privacy-policy`, external: true },
|
|
5413
|
+
{ label: "Terms", href: `${auth}/terms-and-conditions`, external: true },
|
|
5414
|
+
...FOOTER_LINKS_STATIC
|
|
5415
|
+
];
|
|
5416
|
+
}
|
|
5417
|
+
var FOOTER_LINKS_STATIC = [
|
|
5402
5418
|
{
|
|
5403
5419
|
label: "Subscriptions",
|
|
5404
5420
|
href: "https://politogyvrm.com/subscription-cancellation-policy",
|
|
@@ -5407,7 +5423,7 @@ var FOOTER_LINKS = [
|
|
|
5407
5423
|
];
|
|
5408
5424
|
function useChromeFooter(meta) {
|
|
5409
5425
|
return react.useMemo(
|
|
5410
|
-
() => ({ links:
|
|
5426
|
+
() => ({ links: footerLinks(), ...meta }),
|
|
5411
5427
|
[meta.envLabel, meta.version, meta.commit, meta.commitDate, meta.commitAuthor]
|
|
5412
5428
|
);
|
|
5413
5429
|
}
|
|
@@ -5428,15 +5444,17 @@ function useChromeUserMenu({
|
|
|
5428
5444
|
}) {
|
|
5429
5445
|
const state = useChromeState();
|
|
5430
5446
|
const activeOrg = state?.orgs.find((o) => o.id === state.orgId) ?? null;
|
|
5431
|
-
const
|
|
5432
|
-
const
|
|
5447
|
+
const tail = orgIdTail(activeOrg?.id);
|
|
5448
|
+
const orgSuffix = tail ? `?${ORG_ID_QUERY_PARAM}=${tail}` : "";
|
|
5449
|
+
const auth = authBaseUrl();
|
|
5450
|
+
const settings = settingsBaseUrl();
|
|
5433
5451
|
return {
|
|
5434
|
-
// My Profile is global — NOT org-suffixed
|
|
5435
|
-
myProfileHref: `${
|
|
5436
|
-
organizationSettingsHref: `${
|
|
5452
|
+
// My Profile is global — NOT org-suffixed.
|
|
5453
|
+
myProfileHref: `${auth}/my-profile`,
|
|
5454
|
+
organizationSettingsHref: `${settings}/organization-settings${orgSuffix}`,
|
|
5437
5455
|
roles: (state?.orgs ?? []).filter((o) => o.rawRole || o.role).map((o) => ({ role: o.rawRole ?? o.role, orgName: o.name })),
|
|
5438
5456
|
accounts: [{ id: userId, name: userName, email, avatarUrl: null, active: true }],
|
|
5439
|
-
addAccountHref: `${
|
|
5457
|
+
addAccountHref: `${auth}/my-profile#accounts`,
|
|
5440
5458
|
// No theme control: the product is light only (Reference/UI-Platform
|
|
5441
5459
|
// "Theme — light only"; shell 0.73.0 stopped applying dark). The account
|
|
5442
5460
|
// menu rendered an "Appearance" radio with one option until 0.77.0.
|
|
@@ -5487,6 +5505,7 @@ function useChromeMode(arg = {}) {
|
|
|
5487
5505
|
const dedupedFetch = useNavChromeDedupedFetch();
|
|
5488
5506
|
const { me, loaded: meLoaded } = useChromeMe();
|
|
5489
5507
|
const orgId = ctx?.orgId ?? null;
|
|
5508
|
+
const orgPending = ctx?.orgPending ?? false;
|
|
5490
5509
|
const [entitled, setEntitled] = react.useState(null);
|
|
5491
5510
|
const [selectedModeId, setSelectedModeId] = react.useState(null);
|
|
5492
5511
|
react.useEffect(() => {
|
|
@@ -5498,6 +5517,7 @@ function useChromeMode(arg = {}) {
|
|
|
5498
5517
|
}, []);
|
|
5499
5518
|
react.useEffect(() => {
|
|
5500
5519
|
if (!dedupedFetch || !orgId || !meLoaded) return;
|
|
5520
|
+
if (orgPending) return;
|
|
5501
5521
|
const bootMe = me;
|
|
5502
5522
|
if (bootMe && bootMe.account === orgId && bootMe.modes !== void 0) {
|
|
5503
5523
|
setEntitled(bootMe.modes ?? null);
|
|
@@ -5513,7 +5533,7 @@ function useChromeMode(arg = {}) {
|
|
|
5513
5533
|
return () => {
|
|
5514
5534
|
cancelled = true;
|
|
5515
5535
|
};
|
|
5516
|
-
}, [dedupedFetch, me, meLoaded, orgId]);
|
|
5536
|
+
}, [dedupedFetch, me, meLoaded, orgId, orgPending]);
|
|
5517
5537
|
const options = MODE_DEFS.filter((m) => entitled?.[m.id]);
|
|
5518
5538
|
const pinned = pinnedModeId ? MODE_DEFS.find((m) => m.id === pinnedModeId) ?? null : null;
|
|
5519
5539
|
const selected = selectedModeId ? options.find((m) => m.id === selectedModeId) ?? null : null;
|
|
@@ -5555,6 +5575,7 @@ exports.POLITOGY_APPS = POLITOGY_APPS;
|
|
|
5555
5575
|
exports.PolitogyAppChrome = PolitogyAppChrome;
|
|
5556
5576
|
exports.PolitogyAppFrame = PolitogyAppFrame;
|
|
5557
5577
|
exports.deriveBreadcrumbs = deriveBreadcrumbs;
|
|
5578
|
+
exports.footerLinks = footerLinks;
|
|
5558
5579
|
exports.looksLikeEmail = looksLikeEmail;
|
|
5559
5580
|
exports.modeLandingHref = modeLandingHref;
|
|
5560
5581
|
exports.resolveIdentity = resolveIdentity;
|