{"version":3,"file":"init.mjs","names":[],"sources":["../../src/boot/init.ts"],"sourcesContent":["import { setDebugMode } from '@openobserve/js-core/util'\nimport { catchUserErrors } from '../tools/catchUserErrors'\nimport { display } from '../tools/display'\n\n// replaced at build time\ndeclare const __BUILD_ENV__SDK_VERSION__: string\n\nexport interface PublicApi {\n  /**\n   * Version of the Logs browser SDK\n   */\n  version: string\n\n  /**\n   * For CDN async setup: Early RUM API calls must be wrapped in the `window.OO_RUM.onReady()` callback. This ensures the code only gets executed once the SDK is properly loaded.\n   *\n   * See [CDN async setup](https://docs.datadoghq.com/real_user_monitoring/browser/#cdn-async) for further information.\n   */\n  onReady: (callback: () => void) => void\n}\n\nexport function makePublicApi<T extends PublicApi>(stub: Omit<T, keyof PublicApi>): T {\n  const publicApi = {\n    version: __BUILD_ENV__SDK_VERSION__,\n    // This API method is intentionally not monitored, since the only thing executed is the\n    // user-provided 'callback'.  All SDK usages executed in the callback should be monitored, and\n    // we don't want to interfere with the user uncaught exceptions.\n    onReady(callback: () => void) {\n      callback()\n    },\n    ...stub,\n  }\n\n  // Add a \"hidden\" property to set debug mode. We define it that way to hide it\n  // as much as possible but of course it's not a real protection.\n  Object.defineProperty(publicApi, '_setDebug', {\n    get() {\n      return setDebugMode\n    },\n    enumerable: false,\n  })\n\n  return publicApi as T\n}\n\nexport function defineGlobal<Global, Name extends keyof Global>(global: Global, name: Name, api: Global[Name]) {\n  const existingGlobalVariable = global[name] as { q?: Array<() => void>; version?: string } | undefined\n  if (existingGlobalVariable && !existingGlobalVariable.q && existingGlobalVariable.version) {\n    display.warn('SDK is loaded more than once. This is unsupported and might have unexpected behavior.')\n  }\n  global[name] = api\n  if (existingGlobalVariable?.q) {\n    existingGlobalVariable.q.forEach((fn) => catchUserErrors(fn, 'onReady callback threw an error:')())\n  }\n}\n"],"mappings":";;;;AAqBA,SAAgB,cAAmC,MAAmC;CACpF,MAAM,YAAY;EAChB,SAAA;EAIA,QAAQ,UAAsB;GAC5B,SAAS;EACX;EACA,GAAG;CACL;CAIA,OAAO,eAAe,WAAW,aAAa;EAC5C,MAAM;GACJ,OAAO;EACT;EACA,YAAY;CACd,CAAC;CAED,OAAO;AACT;AAEA,SAAgB,aAAgD,QAAgB,MAAY,KAAmB;CAC7G,MAAM,yBAAyB,OAAO;CACtC,IAAI,0BAA0B,CAAC,uBAAuB,KAAK,uBAAuB,SAChF,QAAQ,KAAK,uFAAuF;CAEtG,OAAO,QAAQ;CACf,IAAI,wBAAwB,GAC1B,uBAAuB,EAAE,SAAS,OAAO,gBAAgB,IAAI,kCAAkC,CAAC,CAAC,CAAC;AAEtG"}