{"version":3,"file":"tabContext.mjs","names":[],"sources":["../../../src/domain/contexts/tabContext.ts"],"sourcesContent":["import type { Hook } from '@openobserve/js-core/assembly'\nimport { generateUUID } from '../../tools/utils/stringUtils'\n\nexport const TAB_ID_STORAGE_KEY = '_dd_tab_id'\n\nlet cachedTabId: string | undefined\n\n// Exported for test cleanup only — allows specs to reset the in-memory cache between tests.\nexport function resetCachedTabId(): void {\n  cachedTabId = undefined\n}\n\nexport function startTabContext(assembleHook: Hook<any, any>) {\n  const tabId = retrieveOrCreateTabId()\n\n  assembleHook.register(() => ({\n    tab: {\n      id: tabId,\n    },\n  }))\n}\n\nfunction retrieveOrCreateTabId(): string {\n  if (!cachedTabId) {\n    cachedTabId = getOrCreateIdInSessionStorage() ?? generateUUID()\n  }\n  return cachedTabId\n}\n\nfunction getOrCreateIdInSessionStorage(): string | undefined {\n  try {\n    const existingId = sessionStorage.getItem(TAB_ID_STORAGE_KEY)\n    if (existingId) {\n      return existingId\n    }\n    const newId = generateUUID()\n    sessionStorage.setItem(TAB_ID_STORAGE_KEY, newId)\n    return newId\n  } catch {\n    // sessionStorage unavailable (e.g. Web Worker, sandboxed iframe, quota exceeded)\n    return undefined\n  }\n}\n"],"mappings":";;AAGA,MAAa,qBAAqB;AAElC,IAAI;AAOJ,SAAgB,gBAAgB,cAA8B;CAC5D,MAAM,QAAQ,sBAAsB;CAEpC,aAAa,gBAAgB,EAC3B,KAAK,EACH,IAAI,MACN,EACF,EAAE;AACJ;AAEA,SAAS,wBAAgC;CACvC,IAAI,CAAC,aACH,cAAc,8BAA8B,KAAK,aAAa;CAEhE,OAAO;AACT;AAEA,SAAS,gCAAoD;CAC3D,IAAI;EACF,MAAM,aAAa,eAAe,QAAQ,kBAAkB;EAC5D,IAAI,YACF,OAAO;EAET,MAAM,QAAQ,aAAa;EAC3B,eAAe,QAAQ,oBAAoB,KAAK;EAChD,OAAO;CACT,QAAQ;EAEN;CACF;AACF"}