{"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type {\n  LDContext,\n  LDClient as TLDClient,\n  LDOptions as TLDOptions,\n} from '@launchdarkly/js-client-sdk';\nimport type React from 'react';\n\nexport type TFlagName = string;\nexport type TFlagVariation =\n  | boolean\n  | string\n  | number\n  | Record<string, unknown>\n  | unknown[];\nexport type TFlag = [flagName: TFlagName, flagVariation: TFlagVariation];\nexport type TFlags = Record<string, TFlagVariation>;\nexport type TUser<TAdditionalUserProperties = Record<string, unknown>> = {\n  key?: string;\n} & TAdditionalUserProperties;\nexport enum AdapterSubscriptionStatus {\n  Subscribed = 0,\n  Unsubscribed = 1,\n}\nexport enum AdapterConfigurationStatus {\n  Unconfigured = 0,\n  Configuring = 1,\n  Configured = 2,\n}\nexport enum AdapterInitializationStatus {\n  Succeeded = 0,\n  Failed = 1,\n}\nexport type TAdapterConfiguration = {\n  initializationStatus?: AdapterInitializationStatus;\n};\nexport type TAdapterStatus = {\n  configurationStatus: AdapterConfigurationStatus;\n  subscriptionStatus: AdapterSubscriptionStatus;\n};\nexport const cacheModes = {\n  eager: 'eager',\n  lazy: 'lazy',\n} as const;\nexport type TCacheModes = (typeof cacheModes)[keyof typeof cacheModes];\nexport type TAdaptersStatus = Record<TAdapterIdentifiers, TAdapterStatus>;\nexport type TAdapterStatusChange = {\n  id?: TAdapterIdentifiers;\n  status: Partial<TAdapterStatus>;\n};\nexport type TFlagsChange = { id?: TAdapterIdentifiers; flags: TFlags };\nexport type TAdapterEventHandlers = {\n  onFlagsStateChange: (flagsChange: TFlagsChange) => void;\n  onStatusStateChange: (statusChange: TAdapterStatusChange) => void;\n};\ntype TDefaultAdditionalUserProperties = Record<string, unknown>;\nexport type TBaseAdapterArgs<\n  TAdditionalUserProperties = TDefaultAdditionalUserProperties,\n> = {\n  user: TUser<TAdditionalUserProperties>;\n  cacheIdentifier?: TCacheIdentifiers;\n  cacheMode?: TCacheModes;\n};\nexport type TLaunchDarklyContextArgs = { context: LDContext };\nexport type TLaunchDarklyAdapterArgs = TLaunchDarklyContextArgs & {\n  sdk: {\n    clientSideId: string;\n    clientOptions?: TLDOptions;\n  };\n  flags?: TFlags;\n  throwOnInitializationFailure?: boolean;\n  initializationTimeout?: number;\n  flagsUpdateDelayMs?: number;\n  cacheIdentifier?: TCacheIdentifiers;\n  cacheMode?: TCacheModes;\n};\nexport type TGraphQlAdapterArgs<\n  TAdditionalUserProperties = TDefaultAdditionalUserProperties,\n> = TBaseAdapterArgs<TAdditionalUserProperties> & {\n  fetcher?: typeof fetch;\n  uri: string;\n  query: string;\n  pollingIntervalMs?: number;\n  getQueryVariables?: (adapterArgs: TGraphQlAdapterArgs) => unknown;\n  getRequestHeaders?: (\n    adapterArgs: TGraphQlAdapterArgs,\n  ) => Record<string, string>;\n  parseFlags?: <TFetchedFlags = unknown, TParsedFlags = TFlags>(\n    fetchedFlags: TFetchedFlags,\n  ) => TParsedFlags;\n};\nexport type THttpAdapterArgs<\n  TAdditionalUserProperties = TDefaultAdditionalUserProperties,\n> = TBaseAdapterArgs<TAdditionalUserProperties> & {\n  execute: <\n    TPassedAdapterArgs extends TBaseAdapterArgs<TAdditionalUserProperties>,\n  >(\n    adapterArgs: TPassedAdapterArgs,\n  ) => Promise<any>;\n  pollingIntervalMs?: number;\n};\nexport type TLocalStorageAdapterArgs<\n  TAdditionalUserProperties = TDefaultAdditionalUserProperties,\n> = TBaseAdapterArgs<TAdditionalUserProperties> & {\n  pollingIntervalMs?: number;\n};\nexport type TMemoryAdapterArgs<\n  TAdditionalUserProperties = TDefaultAdditionalUserProperties,\n> = TBaseAdapterArgs<TAdditionalUserProperties>;\nexport type TSplitioAdapterArgs = TBaseAdapterArgs & {\n  sdk: {\n    authorizationKey: string;\n    options?: Record<string, unknown> & { core?: Record<string, string> };\n    // Matches the signature of SplitIO.Attributes\n    treatmentAttributes?: Record<\n      string,\n      string | number | boolean | (string | number)[]\n    >;\n  };\n};\nexport type TCombinedAdapterArgs<\n  TAdditionalUserProperties = TDefaultAdditionalUserProperties,\n  TAdditionalHttpUserProperties = TDefaultAdditionalUserProperties,\n  TAdditionalGraphQlUserProperties = TDefaultAdditionalUserProperties,\n  TAdditionalLocalStorageUserProperties = TDefaultAdditionalUserProperties,\n  TAdditionalMemoryUserProperties = TDefaultAdditionalUserProperties,\n> = TBaseAdapterArgs<TAdditionalUserProperties> & {\n  launchdarkly?: TLaunchDarklyAdapterArgs;\n  localstorage?: TLocalStorageAdapterArgs<TAdditionalLocalStorageUserProperties>;\n  memory?: TMemoryAdapterArgs<TAdditionalMemoryUserProperties>;\n  splitio?: TSplitioAdapterArgs;\n  graphql?: TGraphQlAdapterArgs<TAdditionalGraphQlUserProperties>;\n  http?: THttpAdapterArgs<TAdditionalHttpUserProperties>;\n};\nexport type TAdapterArgs =\n  | TLaunchDarklyAdapterArgs\n  | TLocalStorageAdapterArgs\n  | TMemoryAdapterArgs\n  | TSplitioAdapterArgs\n  | TGraphQlAdapterArgs\n  | THttpAdapterArgs\n  | TCombinedAdapterArgs;\n\nexport const adapterIdentifiers = {\n  launchdarkly: 'launchdarkly',\n  localstorage: 'localstorage',\n  memory: 'memory',\n  splitio: 'splitio',\n  graphql: 'graphql',\n  http: 'http',\n  combined: 'combined',\n} as const;\nexport type TAdapterIdentifiers =\n  | (typeof adapterIdentifiers)[keyof typeof adapterIdentifiers]\n  | string;\nexport type TFlagsContext = Record<TAdapterIdentifiers, TFlags>;\nexport const cacheIdentifiers = {\n  local: 'local',\n  session: 'session',\n} as const;\nexport type TCacheIdentifiers =\n  (typeof cacheIdentifiers)[keyof typeof cacheIdentifiers];\nexport type TUpdateFlagsOptions = {\n  lockFlags?: boolean;\n  unsubscribeFlags?: boolean;\n};\nexport type TFlagsUpdateFunction = (\n  flags: TFlags,\n  options?: TUpdateFlagsOptions,\n) => void;\n\nexport interface TAdapterInterface<Args extends TAdapterArgs> {\n  // Identifiers are used to uniquely identify an interface when performing a condition check.\n  id: TAdapterIdentifiers;\n  // Used if a combined adapter intends to affect variaus other adapter's feature states\n  effectIds?: TAdapterIdentifiers[];\n  configure: (\n    adapterArgs: Args,\n    adapterEventHandlers: TAdapterEventHandlers,\n  ) => Promise<TAdapterConfiguration>;\n  reconfigure: (\n    adapterArgs: Args,\n    adapterEventHandlers: TAdapterEventHandlers,\n  ) => Promise<TAdapterConfiguration>;\n  getIsConfigurationStatus: (\n    configurationStatus: AdapterConfigurationStatus,\n  ) => boolean;\n  setConfigurationStatus?: (\n    nextConfigurationStatus: AdapterConfigurationStatus,\n  ) => void;\n  waitUntilConfigured?: () => Promise<unknown>;\n  reset?: () => void;\n  getFlag?: (flagName: TFlagName) => TFlagVariation | undefined;\n  unsubscribe: () => void;\n  subscribe: () => void;\n  updateFlags: TFlagsUpdateFunction;\n  getUser?: () => TUser | undefined;\n}\n\nexport interface TLaunchDarklyAdapterInterface extends TAdapterInterface<TLaunchDarklyAdapterArgs> {\n  id: typeof adapterIdentifiers.launchdarkly;\n  configure: (\n    adapterArgs: TLaunchDarklyAdapterArgs,\n    adapterEventHandlers: TAdapterEventHandlers,\n  ) => Promise<TAdapterConfiguration>;\n  reconfigure: (\n    adapterArgs: TLaunchDarklyAdapterArgs,\n    adapterEventHandlers: TAdapterEventHandlers,\n  ) => Promise<TAdapterConfiguration>;\n  getIsConfigurationStatus: (\n    adapterConfigurationStatus: AdapterConfigurationStatus,\n  ) => boolean;\n  getClient: () => TLDClient | undefined;\n  getFlag: (flagName: TFlagName) => TFlagVariation | undefined;\n  updateClientContext: (\n    updatedContextProps: TLaunchDarklyAdapterArgs['context'],\n  ) => Promise<unknown>;\n  unsubscribe: () => void;\n  subscribe: () => void;\n}\n\nexport interface TLocalStorageAdapterInterface extends TAdapterInterface<TLocalStorageAdapterArgs> {\n  id: typeof adapterIdentifiers.localstorage;\n  configure: (\n    adapterArgs: TLocalStorageAdapterArgs,\n    adapterEventHandlers: TAdapterEventHandlers,\n  ) => Promise<TAdapterConfiguration>;\n  reconfigure: (\n    adapterArgs: TLocalStorageAdapterArgs,\n    adapterEventHandlers: TAdapterEventHandlers,\n  ) => Promise<TAdapterConfiguration>;\n  getIsConfigurationStatus: (\n    adapterConfigurationStatus: AdapterConfigurationStatus,\n  ) => boolean;\n  waitUntilConfigured: () => Promise<unknown>;\n  unsubscribe: () => void;\n  subscribe: () => void;\n}\n\nexport interface TGraphQlAdapterInterface extends TAdapterInterface<TGraphQlAdapterArgs> {\n  id: typeof adapterIdentifiers.graphql;\n  configure: (\n    adapterArgs: TGraphQlAdapterArgs,\n    adapterEventHandlers: TAdapterEventHandlers,\n  ) => Promise<TAdapterConfiguration>;\n  reconfigure: (\n    adapterArgs: TGraphQlAdapterArgs,\n    adapterEventHandlers: TAdapterEventHandlers,\n  ) => Promise<TAdapterConfiguration>;\n  getIsConfigurationStatus: (\n    adapterConfigurationStatus: AdapterConfigurationStatus,\n  ) => boolean;\n  waitUntilConfigured: () => Promise<unknown>;\n  unsubscribe: () => void;\n  subscribe: () => void;\n}\n\nexport interface THttpAdapterInterface extends TAdapterInterface<THttpAdapterArgs> {\n  id: typeof adapterIdentifiers.http;\n  configure: (\n    adapterArgs: THttpAdapterArgs,\n    adapterEventHandlers: TAdapterEventHandlers,\n  ) => Promise<TAdapterConfiguration>;\n  reconfigure: (\n    adapterArgs: THttpAdapterArgs,\n    adapterEventHandlers: TAdapterEventHandlers,\n  ) => Promise<TAdapterConfiguration>;\n  getIsConfigurationStatus: (\n    adapterConfigurationStatus: AdapterConfigurationStatus,\n  ) => boolean;\n  waitUntilConfigured: () => Promise<unknown>;\n  unsubscribe: () => void;\n  subscribe: () => void;\n}\n\nexport interface TMemoryAdapterInterface extends TAdapterInterface<TMemoryAdapterArgs> {\n  id: typeof adapterIdentifiers.memory;\n  configure: (\n    adapterArgs: TMemoryAdapterArgs,\n    adapterEventHandlers: TAdapterEventHandlers,\n  ) => Promise<TAdapterConfiguration>;\n  reconfigure: (\n    adapterArgs: TMemoryAdapterArgs,\n    adapterEventHandlers: TAdapterEventHandlers,\n  ) => Promise<TAdapterConfiguration>;\n  getIsConfigurationStatus: (\n    adapterConfigurationStatus: AdapterConfigurationStatus,\n  ) => boolean;\n  waitUntilConfigured: () => Promise<unknown>;\n  reset: () => void;\n  updateFlags: TFlagsUpdateFunction;\n  unsubscribe: () => void;\n  subscribe: () => void;\n}\n\nexport interface TCombinedAdapterInterface extends TAdapterInterface<TCombinedAdapterArgs> {\n  id: typeof adapterIdentifiers.combined;\n  effectIds?: TAdapterIdentifiers[];\n  combine: <TAdapterInstance extends TAdapter>(\n    adapters: TAdapterInstance[],\n  ) => void;\n  configure: (\n    adapterArgs: TCombinedAdapterArgs,\n    adapterEventHandlers: TAdapterEventHandlers,\n  ) => Promise<TAdapterConfiguration>;\n  reconfigure: (\n    adapterArgs: TCombinedAdapterArgs,\n    adapterEventHandlers: TAdapterEventHandlers,\n  ) => Promise<TAdapterConfiguration>;\n  getIsConfigurationStatus: (\n    adapterConfigurationStatus: AdapterConfigurationStatus,\n  ) => boolean;\n  waitUntilConfigured: () => Promise<unknown>;\n  reset: () => void;\n  updateFlags: TFlagsUpdateFunction;\n  unsubscribe: () => void;\n  subscribe: () => void;\n}\n\nexport interface TSplitioAdapterInterface extends TAdapterInterface<TSplitioAdapterArgs> {\n  id: typeof adapterIdentifiers.splitio;\n  configure: (\n    adapterArgs: TSplitioAdapterArgs,\n    adapterEventHandlers: TAdapterEventHandlers,\n  ) => Promise<TAdapterConfiguration>;\n  reconfigure: (\n    adapterArgs: TSplitioAdapterArgs,\n    adapterEventHandlers: TAdapterEventHandlers,\n  ) => Promise<TAdapterConfiguration>;\n  getIsConfigurationStatus: (\n    adapterConfigurationStatus: AdapterConfigurationStatus,\n  ) => boolean;\n  unsubscribe: () => void;\n  subscribe: () => void;\n}\nexport type TAdapter =\n  | TLaunchDarklyAdapterInterface\n  | TLocalStorageAdapterInterface\n  | TMemoryAdapterInterface\n  | TSplitioAdapterInterface\n  | TGraphQlAdapterInterface\n  | THttpAdapterInterface\n  | TCombinedAdapterInterface;\nexport type TConfigureAdapterArgs<TAdapterInstance extends TAdapter> =\n  TAdapterInstance extends TLaunchDarklyAdapterInterface\n    ? TLaunchDarklyAdapterArgs\n    : TAdapterInstance extends TLocalStorageAdapterInterface\n      ? TLocalStorageAdapterArgs\n      : TAdapterInstance extends TMemoryAdapterInterface\n        ? TMemoryAdapterArgs\n        : TAdapterInstance extends TSplitioAdapterInterface\n          ? TSplitioAdapterArgs\n          : TAdapterInstance extends TGraphQlAdapterInterface\n            ? TGraphQlAdapterArgs\n            : TAdapterInstance extends THttpAdapterInterface\n              ? THttpAdapterArgs\n              : TAdapterInstance extends TCombinedAdapterInterface\n                ? TCombinedAdapterArgs\n                : never;\nexport type TConfigureAdapterProps<TAdapterInstance extends TAdapter> = {\n  adapter: TAdapterInstance extends TLaunchDarklyAdapterInterface\n    ? TLaunchDarklyAdapterInterface\n    : TAdapterInstance extends TLocalStorageAdapterInterface\n      ? TLocalStorageAdapterInterface\n      : TAdapterInstance extends TMemoryAdapterInterface\n        ? TMemoryAdapterInterface\n        : TAdapterInstance extends TSplitioAdapterInterface\n          ? TSplitioAdapterInterface\n          : TAdapterInstance extends TGraphQlAdapterInterface\n            ? TGraphQlAdapterInterface\n            : TAdapterInstance extends THttpAdapterInterface\n              ? THttpAdapterInterface\n              : TAdapterInstance extends TCombinedAdapterInterface\n                ? TCombinedAdapterInterface\n                : never;\n  adapterArgs: TConfigureAdapterArgs<TAdapterInstance>;\n};\nexport type TAdapterReconfigurationOptions = {\n  shouldOverwrite?: boolean;\n};\nexport type TAdapterReconfiguration = {\n  adapterArgs: TAdapterArgs;\n  options: TAdapterReconfigurationOptions;\n};\nexport type TConfigureAdapterChildrenAsFunctionArgs = {\n  isAdapterConfigured: boolean;\n};\nexport type TConfigureAdapterChildrenAsFunction = (\n  args: TConfigureAdapterChildrenAsFunctionArgs,\n) => React.ReactNode;\nexport type TConfigureAdapterChildren =\n  | TConfigureAdapterChildrenAsFunction\n  | React.ReactNode;\nexport type TReconfigureAdapter = (\n  adapterArgs: TAdapterArgs,\n  options: TAdapterReconfigurationOptions,\n) => void;\nexport type TAdapterContext = {\n  adapterEffectIdentifiers: TAdapterIdentifiers[];\n  reconfigure: TReconfigureAdapter;\n  status?: TAdaptersStatus;\n};\n\ntype TLaunchDarklyFlopflipGlobal = {\n  adapter: TLaunchDarklyAdapterInterface;\n  updateFlags: TFlagsUpdateFunction;\n};\ntype TSplitioAdapterGlobal = {\n  adapter: TSplitioAdapterInterface;\n  updateFlags: TFlagsUpdateFunction;\n};\ntype TMemoryAdapterGlobal = {\n  adapter: TMemoryAdapterInterface;\n  updateFlags: TFlagsUpdateFunction;\n};\ntype TLocalStorageAdapterGlobal = {\n  adapter: TLocalStorageAdapterInterface;\n  updateFlags: TFlagsUpdateFunction;\n};\ntype TGraphQlAdapterGlobal = {\n  adapter: TLocalStorageAdapterInterface;\n  updateFlags: TFlagsUpdateFunction;\n};\ntype THttpAdapterGlobal = {\n  adapter: TLocalStorageAdapterInterface;\n  updateFlags: TFlagsUpdateFunction;\n};\ntype TCombinedAdapterGlobal = {\n  adapter: TCombinedAdapterInterface;\n  updateFlags: TFlagsUpdateFunction;\n};\n\nexport type TFlopflipGlobal = {\n  [adapterIdentifiers.launchdarkly]?: TLaunchDarklyFlopflipGlobal;\n  [adapterIdentifiers.splitio]?: TSplitioAdapterGlobal;\n  [adapterIdentifiers.memory]?: TMemoryAdapterGlobal;\n  [adapterIdentifiers.localstorage]?: TLocalStorageAdapterGlobal;\n  [adapterIdentifiers.graphql]?: TGraphQlAdapterGlobal;\n  [adapterIdentifiers.http]?: THttpAdapterGlobal;\n  [adapterIdentifiers.combined]?: TCombinedAdapterGlobal;\n};\ndeclare global {\n  interface Window {\n    __flopflip__: TFlopflipGlobal;\n  }\n}\nexport type TDiff<ExcludedFrom, ToExclude> = Pick<\n  ExcludedFrom,\n  Exclude<keyof ExcludedFrom, keyof ToExclude>\n>;\nexport type TCache = {\n  get: <T = any>(key: string) => T;\n  set: (key: string, value: any) => boolean;\n  unset: (key: string) => void;\n};\nexport type TCacheOptions = {\n  prefix: string;\n};\n"],"mappings":";;AAmBA,IAAY,4BAAL,yBAAA,2BAAA;CACL,0BAAA,0BAAA,gBAAA,KAAA;CACA,0BAAA,0BAAA,kBAAA,KAAA;;AACF,EAAA,CAAA,CAAA;AACA,IAAY,6BAAL,yBAAA,4BAAA;CACL,2BAAA,2BAAA,kBAAA,KAAA;CACA,2BAAA,2BAAA,iBAAA,KAAA;CACA,2BAAA,2BAAA,gBAAA,KAAA;;AACF,EAAA,CAAA,CAAA;AACA,IAAY,8BAAL,yBAAA,6BAAA;CACL,4BAAA,4BAAA,eAAA,KAAA;CACA,4BAAA,4BAAA,YAAA,KAAA;;AACF,EAAA,CAAA,CAAA;AAQA,MAAa,aAAa;CACxB,OAAO;CACP,MAAM;AACR;AAoGA,MAAa,qBAAqB;CAChC,cAAc;CACd,cAAc;CACd,QAAQ;CACR,SAAS;CACT,SAAS;CACT,MAAM;CACN,UAAU;AACZ;AAKA,MAAa,mBAAmB;CAC9B,OAAO;CACP,SAAS;AACX"}