Another runtime context issue fix
This commit is contained in:
parent
1bb447eca9
commit
3855c82f8e
|
|
@ -4,6 +4,7 @@ const COMPANY_ID_QUERY_KEYS = [
|
||||||
'blt-gtw-fc-cid',
|
'blt-gtw-fc-cid',
|
||||||
'bltt-gtw-f-c-cid',
|
'bltt-gtw-f-c-cid',
|
||||||
];
|
];
|
||||||
|
const COMPANY_ID_STORAGE_KEY = 'sms_runtime_company_id';
|
||||||
|
|
||||||
function getRuntimeUrl() {
|
function getRuntimeUrl() {
|
||||||
if (typeof window === 'undefined') return null;
|
if (typeof window === 'undefined') return null;
|
||||||
|
|
@ -30,6 +31,26 @@ function getPathMatch(pathname, regex) {
|
||||||
return match?.[1] || '';
|
return match?.[1] || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readStoredCompanyId() {
|
||||||
|
if (typeof sessionStorage === 'undefined') return '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
return (sessionStorage.getItem(COMPANY_ID_STORAGE_KEY) || '').trim();
|
||||||
|
} catch {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function persistCompanyId(companyId) {
|
||||||
|
if (!companyId || typeof sessionStorage === 'undefined') return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sessionStorage.setItem(COMPANY_ID_STORAGE_KEY, companyId);
|
||||||
|
} catch {
|
||||||
|
// Ignore storage errors; URL/referrer extraction still works for the current request.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getFirstSearchParam(url, keys) {
|
function getFirstSearchParam(url, keys) {
|
||||||
if (!url) return '';
|
if (!url) return '';
|
||||||
|
|
||||||
|
|
@ -44,14 +65,17 @@ function getFirstSearchParam(url, keys) {
|
||||||
export function getRuntimeCompanyId() {
|
export function getRuntimeCompanyId() {
|
||||||
const runtimeUrl = getRuntimeUrl();
|
const runtimeUrl = getRuntimeUrl();
|
||||||
const referrerUrl = getReferrerUrl();
|
const referrerUrl = getReferrerUrl();
|
||||||
|
const companyId = (
|
||||||
return (
|
|
||||||
getFirstSearchParam(runtimeUrl, COMPANY_ID_QUERY_KEYS)
|
getFirstSearchParam(runtimeUrl, COMPANY_ID_QUERY_KEYS)
|
||||||
|| getPathMatch(runtimeUrl?.pathname || '', /\/company\/([^/]+)/i)
|
|| getPathMatch(runtimeUrl?.pathname || '', /\/company\/([^/]+)/i)
|
||||||
|| getFirstSearchParam(referrerUrl, COMPANY_ID_QUERY_KEYS)
|
|| getFirstSearchParam(referrerUrl, COMPANY_ID_QUERY_KEYS)
|
||||||
|| getPathMatch(referrerUrl?.pathname || '', /\/company\/([^/]+)/i)
|
|| getPathMatch(referrerUrl?.pathname || '', /\/company\/([^/]+)/i)
|
||||||
|
|| readStoredCompanyId()
|
||||||
|| ''
|
|| ''
|
||||||
);
|
);
|
||||||
|
|
||||||
|
persistCompanyId(companyId);
|
||||||
|
return companyId;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRuntimeApplicationId() {
|
export function getRuntimeApplicationId() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user