{"version":3,"file":"client.mjs","sources":["../../src/client.ts"],"sourcesContent":["import type {\n  BaseTransportOptions,\n  ClientOptions,\n  Event,\n  EventHint,\n  Options,\n  ParameterizedString,\n  Scope,\n  SeverityLevel,\n} from '@sentry/core';\nimport {\n  GLOBAL_OBJ,\n  Client,\n  addAutoIpAddressToSession,\n  addAutoIpAddressToUser,\n  makeDsn,\n  logger,\n} from '@sentry/core';\nimport { eventFromException, eventFromMessage } from '@sentry/browser';\nimport { SDK_VERSION } from './version';\nimport { getEnvelopeEndpointWithUrlEncodedAuth } from './utils/api';\n\nexport const WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & {\n  document: any;\n};\n\ntype SharedOptions = 'dsn'\n  | 'integrations'\n  | 'debug'\n  | 'beforeSend'\n  | 'attachStacktrace'\n  | 'transport'\n  | 'stackParser'\n  | 'release'\n  | 'sendClientReports'\n  | 'sendDefaultPii'\n  | 'transportOptions';\n\n/**\n * Configuration options for the Sentry Lynx SDK.\n * @see @sentry/core Options for more information.\n */\nexport type LynxOptions = Pick<\n  Options<BaseTransportOptions>,\n  SharedOptions | 'defaultIntegrations'\n>;\n\n/**\n * Configuration options for the Sentry Lynx SDK Client class\n * @see LynxClient for more information.\n */\nexport type LynxClientOptions = Pick<\n  ClientOptions<BaseTransportOptions>,\n  SharedOptions | '_metadata'\n>;\n\n/**\n * The Sentry Lynx SDK Client.\n *\n * @see LynxOptions for documentation on configuration options.\n * @see SentryClient for usage documentation.\n */\nexport class LynxClient extends Client<LynxClientOptions> {\n  /**\n   * Creates a new Lynx SDK instance.\n   *\n   * @param options Configuration options for this SDK.\n   */\n  public constructor(options: LynxClientOptions) {\n    const opts = {\n      // We default this to true, as it is the safer scenario\n      parentSpanIsAlwaysRootSpan: true,\n      ...options,\n      // TODO: Temporary fix for URLSearchParams not defined in Lynx\n      dsn: undefined,\n    };\n    applySdkMetadata(opts, 'lynx', ['lynx']);\n\n    super(opts);\n\n    // TODO: Temporary fix for URLSearchParams not defined in Lynx\n    if (options.dsn) {\n      // @ts-ignore _dsn is read-only\n      this._dsn = makeDsn(options.dsn);\n    } else {\n      logger.warn('No DSN provided, client will not send events.');\n    }\n\n    if (this._dsn) {\n      const url = getEnvelopeEndpointWithUrlEncodedAuth(\n        this._dsn,\n        undefined,\n        opts._metadata ? opts._metadata.sdk : undefined,\n      );\n      // @ts-ignore _transport is read-only\n      this._transport = options.transport({\n        recordDroppedEvent: this.recordDroppedEvent.bind(this),\n        ...opts.transportOptions,\n        url,\n      });\n    }\n    // TODO: End Of Temporary fix for URLSearchParams not defined in Lynx\n\n    // eslint-disable-next-line @typescript-eslint/no-this-alias\n    const client = this;\n    const { sendDefaultPii, } = client._options;\n\n    if (opts.sendClientReports && WINDOW.document) {\n      WINDOW.document.addEventListener('visibilitychange', () => {\n        if (WINDOW.document.visibilityState === 'hidden') {\n          this._flushOutcomes();\n        }\n      });\n    }\n\n    if (sendDefaultPii) {\n      client.on('postprocessEvent', addAutoIpAddressToUser);\n      client.on('beforeSendSession', addAutoIpAddressToSession);\n    }\n  }\n\n  /**\n   * @inheritDoc\n   */\n  public eventFromException(exception: unknown, hint?: EventHint): PromiseLike<Event> {\n    return eventFromException(this._options.stackParser, exception, hint, this._options.attachStacktrace);\n  }\n\n  /**\n   * @inheritDoc\n   */\n  public eventFromMessage(\n    message: ParameterizedString,\n    level: SeverityLevel = 'info',\n    hint?: EventHint,\n  ): PromiseLike<Event> {\n    return eventFromMessage(this._options.stackParser, message, level, hint, this._options.attachStacktrace);\n  }\n\n  /**\n   * @inheritDoc\n   */\n  protected _prepareEvent(\n    event: Event,\n    hint: EventHint,\n    currentScope: Scope,\n    isolationScope: Scope,\n  ): PromiseLike<Event | null> {\n    event.platform = event.platform || 'javascript';\n\n    return super._prepareEvent(event, hint, currentScope, isolationScope);\n  }\n}\n\n/**\n * A builder for the SDK metadata in the options for the SDK initialization.\n *\n * Note: This function is identical to `buildMetadata` in Remix and NextJS and SvelteKit.\n * We don't extract it for bundle size reasons.\n * @see https://github.com/getsentry/sentry-javascript/pull/7404\n * @see https://github.com/getsentry/sentry-javascript/pull/4196\n *\n * If you make changes to this function consider updating the others as well.\n *\n * @param options SDK options object that gets mutated\n * @param names list of package names\n */\nexport function applySdkMetadata(options: Options, name: string, names = [name], source = 'npm'): void {\n  const metadata = options._metadata || {};\n\n  if (!metadata.sdk) {\n    metadata.sdk = {\n      name: `sentry.javascript.${name}`,\n      packages: names.map(name => ({\n        name: `${source}:@sentry/${name}`,\n        version: SDK_VERSION,\n      })),\n      version: SDK_VERSION,\n    };\n  }\n\n  options._metadata = metadata;\n}\n"],"names":[],"mappings":";;;;;AAsBO,MAAM,MAAM,GAAG;AAkCtB;;;;;AAKG;AACG,MAAO,UAAW,SAAQ,MAAyB,CAAA;AACvD;;;;AAIG;AACH,IAAA,WAAA,CAAmB,OAA0B,EAAA;AAC3C,QAAA,MAAM,IAAI,GAAG;;AAEX,YAAA,0BAA0B,EAAE,IAAI;AAChC,YAAA,GAAG,OAAO;;AAEV,YAAA,GAAG,EAAE,SAAS;SACf;QACD,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;QAExC,KAAK,CAAC,IAAI,CAAC;;QAGX,IAAI,OAAO,CAAC,GAAG,EAAE;;YAEf,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC;AACjC;AAAM,aAAA;AACL,YAAA,MAAM,CAAC,IAAI,CAAC,+CAA+C,CAAC;AAC7D;QAED,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,MAAM,GAAG,GAAG,qCAAqC,CAC/C,IAAI,CAAC,IAAI,EACT,SAAS,EACT,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,GAAG,SAAS,CAChD;;AAED,YAAA,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;gBAClC,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,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