{"version":3,"file":"index.cjs","sources":["../../src/types.ts","../../src/context.ts","../../src/utils.ts","../../src/initLDClient.ts","../../src/getFlagsProxy.ts","../../src/provider.tsx","../../src/asyncWithLDProvider.tsx","../../src/useFlags.ts","../../src/useLDClient.ts","../../src/useLDClientError.tsx","../../src/withLDConsumer.tsx","../../src/withLDProvider.tsx"],"sourcesContent":["import { LDClient, LDContext, LDFlagSet, LDOptions } from 'launchdarkly-js-client-sdk';\nimport * as React from 'react';\n\n/**\n * Initialization options for the LaunchDarkly React SDK. These are in addition to the options exposed\n * by [[LDOptions]] which are common to both the JavaScript and React SDKs.\n */\nexport interface LDReactOptions {\n  /**\n   * Whether the React SDK should transform flag keys into camel-cased format.\n   * Using camel-cased flag keys allow for easier use as prop values, however,\n   * these keys won't directly match the flag keys as known to LaunchDarkly.\n   * Consequently, flag key collisions may be possible and the Code References feature\n   * will not function properly.\n   *\n   * This is true by default, meaning that keys will automatically be converted to camel-case.\n   *\n   * For more information, see the React SDK Reference Guide on\n   * [flag keys](https://docs.launchdarkly.com/sdk/client-side/react/react-web#flag-keys).\n   *\n   * @see https://docs.launchdarkly.com/sdk/client-side/react/react-web#flag-keys\n   */\n  useCamelCaseFlagKeys?: boolean;\n\n  /**\n   * Whether to send flag evaluation events when a flag is read from the `flags` object\n   * returned by the `useFlags` hook. This is true by default, meaning flag evaluation\n   * events will be sent by default.\n   */\n  sendEventsOnFlagRead?: boolean;\n}\n\n/**\n * Contains default values for the `reactOptions` object.\n */\nexport const defaultReactOptions = { useCamelCaseFlagKeys: true, sendEventsOnFlagRead: true };\n\n/**\n * Configuration object used to initialise LaunchDarkly's JS client.\n */\nexport interface ProviderConfig {\n  /**\n   * Your project and environment specific client side ID. You can find\n   * this in your LaunchDarkly portal under Account settings. This is\n   * the only mandatory property required to use the React SDK.\n   */\n  clientSideID: string;\n\n  /**\n   * A LaunchDarkly context object. If unspecified, an anonymous context\n   * with kind: 'user' will be created and used.\n   */\n  context?: LDContext;\n\n  /**\n   * @deprecated The `user` property will be removed in a future version,\n   * please update your code to use context instead.\n   */\n  user?: LDContext;\n\n  /**\n   * If set to true, the ldClient will not be initialized until the context prop has been defined.\n   */\n  deferInitialization?: boolean;\n\n  /**\n   * LaunchDarkly initialization options. These options are common between LaunchDarkly's JavaScript and React SDKs.\n   *\n   * @see https://docs.launchdarkly.com/sdk/features/config#javascript\n   */\n  options?: LDOptions;\n\n  /**\n   * Additional initialization options specific to the React SDK.\n   *\n   * @see options\n   */\n  reactOptions?: LDReactOptions;\n\n  /**\n   * If specified, `launchdarkly-react-client-sdk` will only listen for changes to these flags.\n   * Otherwise, all flags will be requested and listened to.\n   * Flag keys must be in their original form as known to LaunchDarkly rather than in their camel-cased form.\n   */\n  flags?: LDFlagSet;\n\n  /**\n   * Optionally, the ldClient can be initialised outside of the provider\n   * and passed in, instead of being initialised by the provider.\n   * Note: it should only be passed in when it has emitted the 'ready'\n   * event, to ensure that the flags are properly set.\n   */\n  ldClient?: LDClient | Promise<LDClient | undefined>;\n}\n\n/**\n * Configuration object used to initialize LaunchDarkly's JS client asynchronously.\n */\nexport type AsyncProviderConfig = Omit<ProviderConfig, 'deferInitialization'> & {\n  /**\n   * @deprecated - `asyncWithLDProvider` does not support the `deferInitialization` config option because\n   * `asyncWithLDProvider` needs to be initialized at the app entry point prior to render to ensure flags and the\n   * ldClient are ready at the beginning of the app.\n   */\n  deferInitialization?: boolean;\n};\n\n/**\n * The return type of withLDProvider HOC. Exported for testing purposes only.\n *\n * @ignore\n */\nexport interface EnhancedComponent extends React.Component {\n  subscribeToChanges(ldClient: LDClient): void;\n  // tslint:disable-next-line:invalid-void\n  componentDidMount(): Promise<void>;\n  // tslint:disable-next-line:invalid-void\n  componentDidUpdate(prevProps: ProviderConfig): Promise<void>;\n}\n\n/**\n * Return type of `initLDClient`.\n */\nexport interface AllFlagsLDClient {\n  /**\n   * Contains all flags from LaunchDarkly.\n   */\n  flags: LDFlagSet;\n\n  /**\n   * An instance of `LDClient` from the LaunchDarkly JS SDK (`launchdarkly-js-client-sdk`).\n   *\n   * @see https://docs.launchdarkly.com/sdk/client-side/javascript\n   */\n  ldClient: LDClient;\n\n  /**\n   * LaunchDarkly client initialization error, if there was one.\n   */\n  error?: Error;\n}\n\n/**\n * Map of camelized flag keys to original unmodified flag keys.\n */\nexport interface LDFlagKeyMap {\n  [camelCasedKey: string]: string;\n}\n\nexport * from 'launchdarkly-js-client-sdk';\n","import { createContext } from 'react';\nimport { LDClient, LDFlagSet } from 'launchdarkly-js-client-sdk';\nimport { LDFlagKeyMap } from './types';\n\n/**\n * The sdk context stored in the Provider state and passed to consumers.\n */\ninterface ReactSdkContext {\n  /**\n   * JavaScript proxy that will trigger a LDClient#variation call on flag read in order\n   * to register a flag evaluation event in LaunchDarkly. Empty {} initially\n   * until flags are fetched from the LaunchDarkly servers.\n   */\n  flags: LDFlagSet;\n\n  /**\n   * Map of camelized flag keys to their original unmodified form. Empty if useCamelCaseFlagKeys option is false.\n   */\n  flagKeyMap: LDFlagKeyMap;\n\n  /**\n   * An instance of `LDClient` from the LaunchDarkly JS SDK (`launchdarkly-js-client-sdk`).\n   * This will be be undefined initially until initialization is complete.\n   *\n   * @see https://docs.launchdarkly.com/sdk/client-side/javascript\n   */\n  ldClient?: LDClient;\n\n  /**\n   * LaunchDarkly client initialization error, if there was one.\n   */\n  error?: Error;\n}\n\n/**\n * @ignore\n */\nconst context = createContext<ReactSdkContext>({ flags: {}, flagKeyMap: {}, ldClient: undefined });\nconst {\n  /**\n   * @ignore\n   */\n  Provider,\n  /**\n   * @ignore\n   */\n  Consumer,\n} = context;\n\nexport { Provider, Consumer, ReactSdkContext };\nexport default context;\n","import { LDClient, LDContext, LDFlagChangeset, LDFlagSet } from 'launchdarkly-js-client-sdk';\nimport camelCase from 'lodash.camelcase';\nimport { ProviderConfig } from './types';\n\n/**\n * Helper function to get the context or fallback to classic user.\n * Safe to remove when the user property is deprecated.\n */\nexport const getContextOrUser = (config: ProviderConfig): LDContext | undefined => config.context ?? config.user;\n\n/**\n * Transforms a set of flags so that their keys are camelCased. This function ignores\n * flag keys which start with `$`.\n *\n * @param rawFlags A mapping of flag keys and their values\n * @return A transformed `LDFlagSet` with camelCased flag keys\n */\nexport const camelCaseKeys = (rawFlags: LDFlagSet) => {\n  const flags: LDFlagSet = {};\n  for (const rawFlag in rawFlags) {\n    // Exclude system keys\n    if (rawFlag.indexOf('$') !== 0) {\n      flags[camelCase(rawFlag)] = rawFlags[rawFlag]; // tslint:disable-line:no-unsafe-any\n    }\n  }\n\n  return flags;\n};\n\n/**\n * Gets the flags to pass to the provider from the changeset.\n *\n * @param changes the `LDFlagChangeset` from the ldClient onchange handler.\n * @param targetFlags if targetFlags are specified, changes to other flags are ignored and not returned in the\n * flattened `LDFlagSet`\n * @return an `LDFlagSet` with the current flag values from the LDFlagChangeset filtered by `targetFlags`. The returned\n * object may be empty `{}` if none of the targetFlags were changed.\n */\nexport const getFlattenedFlagsFromChangeset = (\n  changes: LDFlagChangeset,\n  targetFlags: LDFlagSet | undefined,\n): LDFlagSet => {\n  const flattened: LDFlagSet = {};\n  for (const key in changes) {\n    if (!targetFlags || targetFlags[key] !== undefined) {\n      flattened[key] = changes[key].current;\n    }\n  }\n\n  return flattened;\n};\n\n/**\n * Retrieves flag values.\n *\n * @param ldClient LaunchDarkly client\n * @param targetFlags If specified, `launchdarkly-react-client-sdk` will only listen for changes to these flags.\n * Flag keys must be in their original form as known to LaunchDarkly rather than in their camel-cased form.\n *\n * @returns an `LDFlagSet` with the current flag values from LaunchDarkly filtered by `targetFlags`.\n */\nexport const fetchFlags = (ldClient: LDClient, targetFlags?: LDFlagSet) => {\n  const allFlags = ldClient.allFlags();\n  if (!targetFlags) {\n    return allFlags;\n  }\n\n  return Object.keys(targetFlags).reduce<LDFlagSet>((acc, key) => {\n    acc[key] = Object.prototype.hasOwnProperty.call(allFlags, key) ? allFlags[key] : targetFlags[key];\n\n    return acc;\n  }, {});\n};\n\n/**\n * @deprecated The `camelCaseKeys.camelCaseKeys` property will be removed in a future version,\n * please update your code to use the `camelCaseKeys` function directly.\n */\n// tslint:disable-next-line deprecation\ncamelCaseKeys.camelCaseKeys = camelCaseKeys;\n\nexport default { camelCaseKeys, getFlattenedFlagsFromChangeset, fetchFlags };\n","import { initialize as ldClientInitialize, LDContext, LDFlagSet, LDOptions } from 'launchdarkly-js-client-sdk';\nimport { AllFlagsLDClient } from './types';\nimport { fetchFlags } from './utils';\nimport * as packageInfo from '../package.json';\n\nconst wrapperOptions: LDOptions = {\n  wrapperName: 'react-client-sdk',\n  wrapperVersion: packageInfo.version,\n  sendEventsOnlyForVariation: true,\n};\n\n/**\n * Internal function to initialize the `LDClient`.\n *\n * @param clientSideID Your project and environment specific client side ID\n * @param context A LaunchDarkly context object\n * @param options LaunchDarkly initialization options\n * @param targetFlags If specified, `launchdarkly-react-client-sdk` will only listen for changes to these flags.\n * Flag keys must be in their original form as known to LaunchDarkly rather than in their camel-cased form.\n *\n * @see `ProviderConfig` for more details about the parameters\n * @return An initialized client and flags\n */\nconst initLDClient = async (\n  clientSideID: string,\n  context: LDContext = { anonymous: true, kind: 'user' },\n  options?: LDOptions,\n  targetFlags?: LDFlagSet,\n): Promise<AllFlagsLDClient> => {\n  const ldClient = ldClientInitialize(clientSideID, context, { ...wrapperOptions, ...options });\n\n  return new Promise<AllFlagsLDClient>((resolve) => {\n    function cleanup() {\n      ldClient.off('ready', handleReady);\n      ldClient.off('failed', handleFailure);\n    }\n    function handleFailure(error: Error) {\n      cleanup();\n      resolve({ flags: {}, ldClient, error });\n    }\n    function handleReady() {\n      cleanup();\n      const flags = fetchFlags(ldClient, targetFlags);\n      resolve({ flags, ldClient });\n    }\n    ldClient.on('failed', handleFailure);\n    ldClient.on('ready', handleReady);\n  });\n};\n\nexport default initLDClient;\n","import { LDFlagSet, LDClient } from 'launchdarkly-js-client-sdk';\nimport camelCase from 'lodash.camelcase';\nimport { defaultReactOptions, LDFlagKeyMap, LDReactOptions } from './types';\n\nexport default function getFlagsProxy(\n  ldClient: LDClient,\n  rawFlags: LDFlagSet,\n  reactOptions: LDReactOptions = defaultReactOptions,\n  targetFlags?: LDFlagSet,\n): { flags: LDFlagSet; flagKeyMap: LDFlagKeyMap } {\n  const filteredFlags = filterFlags(rawFlags, targetFlags);\n  const { useCamelCaseFlagKeys = true } = reactOptions;\n  const [flags, flagKeyMap = {}] = useCamelCaseFlagKeys ? getCamelizedKeysAndFlagMap(filteredFlags) : [filteredFlags];\n\n  return {\n    flags: reactOptions.sendEventsOnFlagRead ? toFlagsProxy(ldClient, flags, flagKeyMap, useCamelCaseFlagKeys) : flags,\n    flagKeyMap,\n  };\n}\n\nfunction filterFlags(flags: LDFlagSet, targetFlags?: LDFlagSet): LDFlagSet {\n  if (targetFlags === undefined) {\n    return flags;\n  }\n\n  return Object.keys(targetFlags).reduce<LDFlagSet>((acc, key) => {\n    if (hasFlag(flags, key)) {\n      acc[key] = flags[key];\n    }\n\n    return acc;\n  }, {});\n}\n\nfunction getCamelizedKeysAndFlagMap(rawFlags: LDFlagSet) {\n  const flags: LDFlagSet = {};\n  const flagKeyMap: LDFlagKeyMap = {};\n  for (const rawFlag in rawFlags) {\n    // Exclude system keys\n    if (rawFlag.indexOf('$') === 0) {\n      continue;\n    }\n    const camelKey = camelCase(rawFlag);\n    flags[camelKey] = rawFlags[rawFlag];\n    flagKeyMap[camelKey] = rawFlag;\n  }\n\n  return [flags, flagKeyMap];\n}\n\nfunction hasFlag(flags: LDFlagSet, flagKey: string) {\n  return Object.prototype.hasOwnProperty.call(flags, flagKey);\n}\n\nfunction toFlagsProxy(\n  ldClient: LDClient,\n  flags: LDFlagSet,\n  flagKeyMap: LDFlagKeyMap,\n  useCamelCaseFlagKeys: boolean,\n): LDFlagSet {\n  return new Proxy(flags, {\n    // trap for reading a flag value using `LDClient#variation` to trigger an evaluation event\n    get(target, prop, receiver) {\n      const currentValue = Reflect.get(target, prop, receiver);\n\n      // check if flag key exists as camelCase or original case\n      const validFlagKey =\n        (useCamelCaseFlagKeys && hasFlag(flagKeyMap, prop as string)) || hasFlag(target, prop as string);\n\n      // only process flag keys and ignore symbols and native Object functions\n      if (typeof prop === 'symbol' || !validFlagKey) {\n        return currentValue;\n      }\n\n      if (currentValue === undefined) {\n        return;\n      }\n\n      const pristineFlagKey = useCamelCaseFlagKeys ? flagKeyMap[prop] : prop;\n\n      return ldClient.variation(pristineFlagKey, currentValue);\n    },\n  });\n}\n","import React, { Component, PropsWithChildren } from 'react';\nimport { LDClient, LDFlagChangeset, LDFlagSet } from 'launchdarkly-js-client-sdk';\nimport { EnhancedComponent, ProviderConfig, defaultReactOptions } from './types';\nimport { Provider, ReactSdkContext } from './context';\nimport initLDClient from './initLDClient';\nimport { camelCaseKeys, fetchFlags, getContextOrUser, getFlattenedFlagsFromChangeset } from './utils';\nimport getFlagsProxy from './getFlagsProxy';\n\ninterface LDHocState extends ReactSdkContext {\n  unproxiedFlags: LDFlagSet;\n}\n\n/**\n * The `LDProvider` is a component which accepts a config object which is used to\n * initialize `launchdarkly-js-client-sdk`.\n *\n * This Provider does three things:\n * - It initializes the ldClient instance by calling `launchdarkly-js-client-sdk` initialize on `componentDidMount`\n * - It saves all flags and the ldClient instance in the context API\n * - It subscribes to flag changes and propagate them through the context API\n *\n * Because the `launchdarkly-js-client-sdk` in only initialized on `componentDidMount`, your flags and the\n * ldClient are only available after your app has mounted. This can result in a flicker due to flag changes at\n * startup time.\n *\n * This component can be used as a standalone provider. However, be mindful to only include the component once\n * within your application. This provider is used inside the `withLDProviderHOC` and can be used instead to initialize\n * the `launchdarkly-js-client-sdk`. For async initialization, check out the `asyncWithLDProvider` function\n */\nclass LDProvider extends Component<PropsWithChildren<ProviderConfig>, LDHocState> implements EnhancedComponent {\n  readonly state: Readonly<LDHocState>;\n\n  constructor(props: ProviderConfig) {\n    super(props);\n\n    const { options } = props;\n\n    this.state = {\n      flags: {},\n      unproxiedFlags: {},\n      flagKeyMap: {},\n      ldClient: undefined,\n    };\n\n    if (options) {\n      const { bootstrap } = options;\n      if (bootstrap && bootstrap !== 'localStorage') {\n        const { useCamelCaseFlagKeys } = this.getReactOptions();\n        this.state = {\n          flags: useCamelCaseFlagKeys ? camelCaseKeys(bootstrap) : bootstrap,\n          unproxiedFlags: bootstrap,\n          flagKeyMap: {},\n          ldClient: undefined,\n        };\n      }\n    }\n  }\n\n  getReactOptions = () => ({ ...defaultReactOptions, ...this.props.reactOptions });\n\n  subscribeToChanges = (ldClient: LDClient) => {\n    const { flags: targetFlags } = this.props;\n    ldClient.on('change', (changes: LDFlagChangeset) => {\n      const reactOptions = this.getReactOptions();\n      const updates = getFlattenedFlagsFromChangeset(changes, targetFlags);\n      const unproxiedFlags = {\n        ...this.state.unproxiedFlags,\n        ...updates,\n      };\n      if (Object.keys(updates).length > 0) {\n        this.setState({ unproxiedFlags, ...getFlagsProxy(ldClient, unproxiedFlags, reactOptions, targetFlags) });\n      }\n    });\n  };\n\n  initLDClient = async () => {\n    const { clientSideID, flags, options } = this.props;\n    let ldClient = await this.props.ldClient;\n    const reactOptions = this.getReactOptions();\n    let unproxiedFlags = this.state.unproxiedFlags;\n    let error: Error | undefined;\n    if (ldClient) {\n      unproxiedFlags = fetchFlags(ldClient, flags);\n    } else {\n      const initialisedOutput = await initLDClient(clientSideID, getContextOrUser(this.props), options, flags);\n      error = initialisedOutput.error;\n      if (!error) {\n        unproxiedFlags = initialisedOutput.flags;\n      }\n      ldClient = initialisedOutput.ldClient;\n    }\n    this.setState({ unproxiedFlags, ...getFlagsProxy(ldClient, unproxiedFlags, reactOptions, flags), ldClient, error });\n    this.subscribeToChanges(ldClient);\n  };\n\n  async componentDidMount() {\n    const { deferInitialization } = this.props;\n    if (deferInitialization && !getContextOrUser(this.props)) {\n      return;\n    }\n\n    await this.initLDClient();\n  }\n\n  async componentDidUpdate(prevProps: ProviderConfig) {\n    const { deferInitialization } = this.props;\n    const contextJustLoaded = !getContextOrUser(prevProps) && getContextOrUser(this.props);\n    if (deferInitialization && contextJustLoaded) {\n      await this.initLDClient();\n    }\n  }\n\n  render() {\n    const { flags, flagKeyMap, ldClient, error } = this.state;\n\n    return <Provider value={{ flags, flagKeyMap, ldClient, error }}>{this.props.children}</Provider>;\n  }\n}\n\nexport default LDProvider;\n","import React, { useState, useEffect, ReactNode } from 'react';\nimport { LDFlagChangeset } from 'launchdarkly-js-client-sdk';\nimport { AsyncProviderConfig, defaultReactOptions } from './types';\nimport { Provider } from './context';\nimport initLDClient from './initLDClient';\nimport { getContextOrUser, getFlattenedFlagsFromChangeset } from './utils';\nimport getFlagsProxy from './getFlagsProxy';\n\n/**\n * This is an async function which initializes LaunchDarkly's JS SDK (`launchdarkly-js-client-sdk`)\n * and awaits it so all flags and the ldClient are ready before the consumer app is rendered.\n *\n * The difference between `withLDProvider` and `asyncWithLDProvider` is that `withLDProvider` initializes\n * `launchdarkly-js-client-sdk` at componentDidMount. This means your flags and the ldClient are only available after\n * your app has mounted. This can result in a flicker due to flag changes at startup time.\n *\n * `asyncWithLDProvider` initializes `launchdarkly-js-client-sdk` at the entry point of your app prior to render.\n * This means that your flags and the ldClient are ready at the beginning of your app. This ensures your app does not\n * flicker due to flag changes at startup time.\n *\n * `asyncWithLDProvider` accepts a config object which is used to initialize `launchdarkly-js-client-sdk`.\n *\n * `asyncWithLDProvider` does not support the `deferInitialization` config option because `asyncWithLDProvider` needs\n * to be initialized at the entry point prior to render to ensure your flags and the ldClient are ready at the beginning\n * of your app.\n *\n * It returns a provider which is a React FunctionComponent which:\n * - saves all flags and the ldClient instance in the context API\n * - subscribes to flag changes and propagate them through the context API\n *\n * @param config - The configuration used to initialize LaunchDarkly's JS SDK\n */\nexport default async function asyncWithLDProvider(config: AsyncProviderConfig) {\n  const { clientSideID, flags: targetFlags, options, reactOptions: userReactOptions } = config;\n  const reactOptions = { ...defaultReactOptions, ...userReactOptions };\n  const { ldClient, flags: fetchedFlags, error } = await initLDClient(\n    clientSideID,\n    getContextOrUser(config),\n    options,\n    targetFlags,\n  );\n\n  const initialFlags = options?.bootstrap && options.bootstrap !== 'localStorage' ? options.bootstrap : fetchedFlags;\n\n  const LDProvider = ({ children }: { children: ReactNode }) => {\n    const [ldData, setLDData] = useState(() => ({\n      unproxiedFlags: initialFlags,\n      ...getFlagsProxy(ldClient, initialFlags, reactOptions, targetFlags),\n    }));\n\n    useEffect(() => {\n      function onChange(changes: LDFlagChangeset) {\n        const updates = getFlattenedFlagsFromChangeset(changes, targetFlags);\n        if (Object.keys(updates).length > 0) {\n          setLDData(({ unproxiedFlags }) => {\n            const updatedUnproxiedFlags = { ...unproxiedFlags, ...updates };\n\n            return {\n              unproxiedFlags: updatedUnproxiedFlags,\n              ...getFlagsProxy(ldClient, updatedUnproxiedFlags, reactOptions, targetFlags),\n            };\n          });\n        }\n      }\n      ldClient.on('change', onChange);\n\n      return function cleanup() {\n        ldClient.off('change', onChange);\n      };\n    }, []);\n\n    const { flags, flagKeyMap } = ldData;\n\n    return <Provider value={{ flags, flagKeyMap, ldClient, error }}>{children}</Provider>;\n  };\n\n  return LDProvider;\n}\n","import { LDFlagSet } from 'launchdarkly-js-client-sdk';\nimport { useContext } from 'react';\nimport context, { ReactSdkContext } from './context';\n\n/**\n * `useFlags` is a custom hook which returns all feature flags. It uses the `useContext` primitive\n * to access the LaunchDarkly context set up by `withLDProvider`. As such you will still need to\n * use the `withLDProvider` HOC at the root of your app to initialize the React SDK and populate the\n * context with `ldClient` and your flags.\n *\n * @return All the feature flags configured in your LaunchDarkly project\n */\nconst useFlags = <T extends LDFlagSet = LDFlagSet>(): T => {\n  const { flags } = useContext<ReactSdkContext>(context);\n\n  return flags as T;\n};\n\nexport default useFlags;\n","import { useContext } from 'react';\nimport context from './context';\n\n// tslint:disable:max-line-length\n/**\n * `useLDClient` is a custom hook which returns the underlying [LaunchDarkly JavaScript SDK client object](https://launchdarkly.github.io/js-client-sdk/interfaces/LDClient.html).\n * Like the `useFlags` custom hook, `useLDClient` also uses the `useContext` primitive to access the LaunchDarkly\n * context set up by `withLDProvider`. You will still need to use the `withLDProvider` HOC\n * to initialise the react sdk to use this custom hook.\n *\n * @return The `launchdarkly-js-client-sdk` `LDClient` object\n */\n// tslint:enable:max-line-length\nconst useLDClient = () => {\n  const { ldClient } = useContext(context);\n\n  return ldClient;\n};\n\nexport default useLDClient;\n","import { useContext } from 'react';\nimport context from './context';\n\n/**\n * Provides the LaunchDarkly client initialization error, if there was one.\n *\n * @return The `launchdarkly-js-client-sdk` `LDClient` initialization error\n */\nexport default function useLDClientError() {\n  const { error } = useContext(context);\n\n  return error;\n}\n","import * as React from 'react';\nimport { Consumer, ReactSdkContext } from './context';\nimport { LDClient, LDFlagSet } from 'launchdarkly-js-client-sdk';\n\n/**\n * Controls the props the wrapped component receives from the `LDConsumer` HOC.\n */\nexport interface ConsumerOptions {\n  /**\n   * If true then the wrapped component only receives the `ldClient` instance\n   * and nothing else.\n   */\n  clientOnly: boolean;\n}\n\n/**\n * The possible props the wrapped component can receive from the `LDConsumer` HOC.\n */\nexport interface LDProps {\n  /**\n   * A map of feature flags from their keys to their values.\n   * Keys are camelCased using `lodash.camelcase`.\n   */\n  flags?: LDFlagSet;\n\n  /**\n   * An instance of `LDClient` from the LaunchDarkly JS SDK (`launchdarkly-js-client-sdk`)\n   *\n   * @see https://docs.launchdarkly.com/sdk/client-side/javascript\n   */\n  ldClient?: LDClient;\n}\n\n/**\n * withLDConsumer is a function which accepts an optional options object and returns a function\n * which accepts your React component. This function returns a HOC with flags\n * and the ldClient instance injected via props.\n *\n * @param options - If you need only the `ldClient` instance and not flags, then set `{ clientOnly: true }`\n * to only pass the ldClient prop to your component. Defaults to `{ clientOnly: false }`.\n * @return A HOC with flags and the `ldClient` instance injected via props\n */\nfunction withLDConsumer(options: ConsumerOptions = { clientOnly: false }) {\n  return function withLDConsumerHoc<P>(WrappedComponent: React.ComponentType<P & LDProps>) {\n    return (props: P) => (\n      <Consumer>\n        {({ flags, ldClient }: ReactSdkContext) => {\n          if (options.clientOnly) {\n            return <WrappedComponent ldClient={ldClient} {...props} />;\n          }\n\n          return <WrappedComponent flags={flags} ldClient={ldClient} {...props} />;\n        }}\n      </Consumer>\n    );\n  };\n}\n\nexport default withLDConsumer;\n","import * as React from 'react';\nimport { defaultReactOptions, ProviderConfig } from './types';\nimport LDProvider from './provider';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\n\n/**\n * `withLDProvider` is a function which accepts a config object which is used to\n * initialize `launchdarkly-js-client-sdk`.\n *\n * This HOC handles passing configuration to the `LDProvider`, which does the following:\n * - It initializes the ldClient instance by calling `launchdarkly-js-client-sdk` initialize on `componentDidMount`\n * - It saves all flags and the ldClient instance in the context API\n * - It subscribes to flag changes and propagate them through the context API\n *\n * The difference between `withLDProvider` and `asyncWithLDProvider` is that `withLDProvider` initializes\n * `launchdarkly-js-client-sdk` at `componentDidMount`. This means your flags and the ldClient are only available after\n * your app has mounted. This can result in a flicker due to flag changes at startup time.\n *\n * `asyncWithLDProvider` initializes `launchdarkly-js-client-sdk` at the entry point of your app prior to render.\n * This means that your flags and the ldClient are ready at the beginning of your app. This ensures your app does not\n * flicker due to flag changes at startup time.\n *\n * @param config - The configuration used to initialize LaunchDarkly's JS SDK\n * @return A function which accepts your root React component and returns a HOC\n */\nexport function withLDProvider<T extends JSX.IntrinsicAttributes = {}>(\n  config: ProviderConfig,\n): (WrappedComponent: React.ComponentType<T>) => React.ComponentType<T> {\n  return function withLDProviderHoc(WrappedComponent: React.ComponentType<T>): React.ComponentType<T> {\n    const { reactOptions: userReactOptions } = config;\n    const reactOptions = { ...defaultReactOptions, ...userReactOptions };\n    const providerProps = { ...config, reactOptions };\n\n    function HoistedComponent(props: T) {\n      return (\n        <LDProvider {...providerProps}>\n          <WrappedComponent {...props} />\n        </LDProvider>\n      );\n    }\n\n    hoistNonReactStatics(HoistedComponent, WrappedComponent);\n\n    return HoistedComponent;\n  };\n}\n\nexport default withLDProvider;\n"],"names":["defaultReactOptions","useCamelCaseFlagKeys","sendEventsOnFlagRead","context","createContext","flags","flagKeyMap","ldClient","Provider","Consumer","getContextOrUser","config","_a","user","camelCaseKeys","rawFlags","rawFlag","indexOf","camelCase","getFlattenedFlagsFromChangeset","changes","targetFlags","flattened","key","current","fetchFlags","allFlags","Object","keys","reduce","acc","prototype","hasOwnProperty","call","wrapperOptions","wrapperName","wrapperVersion","sendEventsOnlyForVariation","initLDClient","_0","_1","__async","clientSideID","anonymous","kind","options","ldClientInitialize","__spreadValues","Promise","resolve","cleanup","off","handleReady","handleFailure","error","on","getFlagsProxy","reactOptions","filteredFlags","hasFlag","filterFlags","camelKey","getCamelizedKeysAndFlagMap","toFlagsProxy","flagKey","Proxy","get","target","prop","receiver","currentValue","Reflect","validFlagKey","pristineFlagKey","variation","LDProvider","Component","constructor","props","super","__publicField","this","getReactOptions","updates","unproxiedFlags","state","length","setState","initialisedOutput","subscribeToChanges","bootstrap","componentDidMount","deferInitialization","componentDidUpdate","prevProps","contextJustLoaded","render","React","createElement","value","children","userReactOptions","fetchedFlags","initialFlags","ldData","setLDData","useState","useEffect","onChange","updatedUnproxiedFlags","useContext","clientOnly","WrappedComponent","providerProps","HoistedComponent","hoistNonReactStatics"],"mappings":"6ZAmCO,MAAMA,EAAsB,CAAEC,sBAAsB,EAAMC,sBAAsB,GCEjFC,EAAUC,EAAAA,cAA+B,CAAEC,MAAO,CAAI,EAAAC,WAAY,CAAA,EAAIC,cAAU,KAChFC,SAIJA,EAAAC,SAIAA,GACEN,ECvCSO,EAAoBC,IARjC,IAAAC,EAQ0F,OAAP,OAAOA,EAAAD,EAAAR,WAAWQ,EAAOE,IAAA,EAS/FC,EAAiBC,IAC5B,MAAMV,EAAmB,CAAA,EACzB,IAAA,MAAWW,KAAWD,EAES,IAAzBC,EAAQC,QAAQ,OAClBZ,EAAMa,EAAUF,IAAYD,EAASC,IAIlC,OAAAX,CAAA,EAYIc,EAAiC,CAC5CC,EACAC,KAEA,MAAMC,EAAuB,CAAA,EAC7B,IAAA,MAAWC,KAAOH,EACXC,QAAoC,IAArBA,EAAYE,KA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