{"version":3,"file":"userContext.mjs","names":[],"sources":["../../../src/domain/contexts/userContext.ts"],"sourcesContent":["import type { RelativeTime } from '@openobserve/js-core/time'\nimport type { Hook } from '@openobserve/js-core/assembly'\nimport { SKIPPED } from '@openobserve/js-core/assembly'\nimport { CustomerDataType } from '../context/contextConstants'\nimport { storeContextManager } from '../context/storeContextManager'\nimport { createContextManager } from '../context/contextManager'\nimport type { Configuration } from '../configuration'\nimport { isEmptyObject } from '../../tools/utils/objectUtils'\n\nexport interface User {\n  id?: string | undefined\n  email?: string | undefined\n  name?: string | undefined\n  [key: string]: unknown\n}\n\nexport function startUserContext(\n  hook: Hook<{ eventType?: string; startTime: RelativeTime }, { usr?: User }>,\n  configuration: Configuration,\n  sessionManager: {\n    findTrackedSession: (startTime?: RelativeTime) => { anonymousId?: string } | undefined\n  },\n  productKey: string\n) {\n  const userContextManager = buildUserContextManager()\n\n  if (configuration.storeContextsAcrossPages) {\n    storeContextManager(userContextManager, productKey, CustomerDataType.User)\n  }\n\n  hook.register(({ eventType, startTime }) => {\n    const user = userContextManager.getContext()\n    const session = sessionManager.findTrackedSession(startTime)\n\n    if (session?.anonymousId && !user.anonymous_id && !!configuration.trackAnonymousUser) {\n      user.anonymous_id = session.anonymousId\n    }\n\n    if (isEmptyObject(user)) {\n      return SKIPPED\n    }\n\n    return {\n      type: eventType,\n      usr: user,\n    }\n  })\n\n  return userContextManager\n}\n\nexport function buildUserContextManager() {\n  return createContextManager('user', {\n    propertiesConfig: {\n      id: { type: 'string' },\n      name: { type: 'string' },\n      email: { type: 'string' },\n    },\n  })\n}\n"],"mappings":";;;;;;AAgBA,SAAgB,iBACd,MACA,eACA,gBAGA,YACA;CACA,MAAM,qBAAqB,wBAAwB;CAEnD,IAAI,cAAc,0BAChB,oBAAoB,oBAAoB,YAAA,CAAiC;CAG3E,KAAK,UAAU,EAAE,WAAW,gBAAgB;EAC1C,MAAM,OAAO,mBAAmB,WAAW;EAC3C,MAAM,UAAU,eAAe,mBAAmB,SAAS;EAE3D,IAAI,SAAS,eAAe,CAAC,KAAK,gBAAgB,CAAC,CAAC,cAAc,oBAChE,KAAK,eAAe,QAAQ;EAG9B,IAAI,cAAc,IAAI,GACpB,OAAO;EAGT,OAAO;GACL,MAAM;GACN,KAAK;EACP;CACF,CAAC;CAED,OAAO;AACT;AAEA,SAAgB,0BAA0B;CACxC,OAAO,qBAAqB,QAAQ,EAClC,kBAAkB;EAChB,IAAI,EAAE,MAAM,SAAS;EACrB,MAAM,EAAE,MAAM,SAAS;EACvB,OAAO,EAAE,MAAM,SAAS;CAC1B,EACF,CAAC;AACH"}