{"version":3,"file":"accountContext.mjs","names":[],"sources":["../../../src/domain/contexts/accountContext.ts"],"sourcesContent":["import type { Hook } from '@openobserve/js-core/assembly'\nimport { SKIPPED } from '@openobserve/js-core/assembly'\nimport type { Configuration } from '../configuration'\nimport { CustomerDataType } from '../context/contextConstants'\nimport { storeContextManager } from '../context/storeContextManager'\nimport { isEmptyObject } from '../../tools/utils/objectUtils'\nimport { createContextManager } from '../context/contextManager'\n\n/**\n * Account information for the browser SDK.\n */\nexport interface Account {\n  id: string\n  name?: string | undefined\n  [key: string]: unknown\n}\n\nexport function startAccountContext(assembleHook: Hook<any, any>, configuration: Configuration, productKey: string) {\n  const accountContextManager = buildAccountContextManager()\n\n  if (configuration.storeContextsAcrossPages) {\n    storeContextManager(accountContextManager, productKey, CustomerDataType.Account)\n  }\n\n  assembleHook.register(() => {\n    const account = accountContextManager.getContext() as Account\n\n    if (isEmptyObject(account) || !account.id) {\n      return SKIPPED\n    }\n\n    return {\n      account,\n    }\n  })\n\n  return accountContextManager\n}\n\nexport function buildAccountContextManager() {\n  return createContextManager('account', {\n    propertiesConfig: {\n      id: { type: 'string', required: true },\n      name: { type: 'string' },\n    },\n  })\n}\n"],"mappings":";;;;;;AAiBA,SAAgB,oBAAoB,cAA8B,eAA8B,YAAoB;CAClH,MAAM,wBAAwB,2BAA2B;CAEzD,IAAI,cAAc,0BAChB,oBAAoB,uBAAuB,YAAA,CAAoC;CAGjF,aAAa,eAAe;EAC1B,MAAM,UAAU,sBAAsB,WAAW;EAEjD,IAAI,cAAc,OAAO,KAAK,CAAC,QAAQ,IACrC,OAAO;EAGT,OAAO,EACL,QACF;CACF,CAAC;CAED,OAAO;AACT;AAEA,SAAgB,6BAA6B;CAC3C,OAAO,qBAAqB,WAAW,EACrC,kBAAkB;EAChB,IAAI;GAAE,MAAM;GAAU,UAAU;EAAK;EACrC,MAAM,EAAE,MAAM,SAAS;CACzB,EACF,CAAC;AACH"}