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,EAAM,GACzC,CACA,EAAQ,QACR,KAAK,IAAI,EAAQ,EACnB,CACF,CACA,YAAO,GACL,KAAK,OAAO,OACd,GAEoB,oBAAX,QAA8C,oBAAb,UAC1C,WAAW,qBAGX,sBACA","file":"/npm/featurehub-javascript-client-sdk@1.5.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/featurehub-javascript-client-sdk@1.5.0/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// src/index.ts\nimport {\n  EdgeFeatureHubConfig,\n  FeatureHubPollingClient,\n  fhLog as fhLog2\n} from \"featurehub-javascript-core-sdk\";\n\n// src/polling_sdk.ts\nimport { fhLog, PollingBase } from \"featurehub-javascript-core-sdk\";\n\n// src/crypto-browser.ts\nvar algorithmMap = {\n  sha1: \"SHA-1\",\n  sha256: \"SHA-256\",\n  sha384: \"SHA-384\",\n  sha512: \"SHA-512\"\n};\nvar createBase64UrlSafeHash = async (algorithm, data) => {\n  const encoder = new TextEncoder();\n  const dataBuffer = encoder.encode(data);\n  const cryptoAlgorithm = algorithmMap[algorithm];\n  if (!cryptoAlgorithm) {\n    throw new Error(`Unsupported hash algorithm: ${algorithm}`);\n  }\n  const hashBuffer = await window.crypto.subtle.digest(cryptoAlgorithm, dataBuffer);\n  const hashArray = new Uint8Array(hashBuffer);\n  let binary = \"\";\n  for (let i = 0; i < hashArray.byteLength; i++) {\n    binary += String.fromCharCode(hashArray[i]);\n  }\n  const base64 = btoa(binary);\n  return base64.replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n};\n\n// src/polling_sdk.ts\nvar BrowserPollingService = class _BrowserPollingService extends PollingBase {\n  localStorageLastUrl;\n  // override this in React Native - for example use AsyncStorage\n  static localStorageRequestor = () => {\n    if (window.localStorage) {\n      return localStorage;\n    }\n    return {\n      getItem: () => null,\n      setItem: () => {\n      }\n    };\n  };\n  constructor(_options, url, frequency, callback) {\n    super(url, frequency, createBase64UrlSafeHash, callback);\n  }\n  loadLocalState(url) {\n    if (url !== this.localStorageLastUrl) {\n      this.localStorageLastUrl = url;\n      const storedData = _BrowserPollingService.localStorageRequestor().getItem(url);\n      if (storedData) {\n        try {\n          const data = JSON.parse(storedData);\n          if (data.e) {\n            this._callback(data.e);\n          }\n        } catch (_) {\n        }\n      }\n    }\n  }\n  async poll() {\n    if (this._busy) {\n      return new Promise((resolve, reject) => {\n        this._outstandingPromises.push({ resolve, reject });\n      });\n    }\n    if (this._stopped) {\n      return new Promise((resolve) => {\n        resolve();\n      });\n    }\n    const fullUrl = `${this.url}&contextSha=${this._shaHeader}`;\n    this.loadLocalState(fullUrl);\n    this._busy = true;\n    const headers = {\n      \"Content-type\": \"application/json\",\n      ...this._etag ? { \"if-none-match\": this._etag } : {},\n      ...this._header ? { \"x-featurehub\": this._header } : {}\n    };\n    const response = await fetch(fullUrl, { headers });\n    if (response.status === 304) {\n      this._busy = false;\n      this.resolveOutstanding();\n      return;\n    } else if (!response.ok) {\n      this._busy = false;\n      this.rejectOutstanding(response.status);\n      throw new Error(`Failed to fetch features: ${response.statusText}`);\n    }\n    this._etag = response.headers.get(\"etag\");\n    this.parseCacheControl(response.headers.get(\"cache-control\"));\n    const environments = JSON.parse(await response.text());\n    try {\n      _BrowserPollingService.localStorageRequestor().setItem(\n        fullUrl,\n        JSON.stringify({ e: environments })\n      );\n    } catch (_) {\n      fhLog.error(\"featurehub: unable to cache features\");\n    }\n    this._callback(environments);\n    this._stopped = response.status === 236;\n    this._busy = false;\n    this.resolveOutstanding();\n  }\n};\n\n// src/index.ts\nexport * from \"featurehub-javascript-core-sdk\";\nFeatureHubPollingClient.pollingClientProvider = (opt, url, freq, callback) => new BrowserPollingService(opt, url, freq, callback);\nvar fhConfigKey = \"fhConfig\";\nvar fhContextKey = \"fhContext\";\nvar fhUnloadListenerLoaded = \"fhUnloadListenerExists\";\nvar expectedValueForUnload = \"featurehub-initialized\";\nvar FeatureHub = class {\n  static feature(key) {\n    return this.context.feature(key);\n  }\n  static set(config, context) {\n    window[fhConfigKey] = config;\n    window[fhContextKey] = context;\n  }\n  static get context() {\n    const fhContext = window[fhContextKey];\n    if (fhContext) {\n      return fhContext;\n    }\n    throw new Error(\"No FeatureHub context defined\");\n  }\n  static get config() {\n    const fhConfig = window[fhConfigKey];\n    if (fhConfig) {\n      return fhConfig;\n    }\n    throw new Error(\"No FeatureHub config defined\");\n  }\n  static _initialize() {\n    if (!window[fhUnloadListenerLoaded]) {\n      window[fhUnloadListenerLoaded] = expectedValueForUnload;\n      window.addEventListener(\"beforeunload\", () => {\n        const cfg = window[fhConfigKey];\n        if (cfg) {\n          try {\n            fhLog2.trace(\"unloading featurehub config!\");\n            cfg.close();\n          } catch (_e) {\n          }\n        } else {\n          fhLog2.trace(\"featurehub not configured\");\n        }\n      });\n    }\n    const metaTags = document.getElementsByTagName(\"meta\");\n    const apiKeys = [];\n    let pollInterval;\n    let url;\n    const params = [];\n    for (let count = 0; count < metaTags.length; count++) {\n      const name = metaTags[count]?.getAttribute(\"name\");\n      const content = metaTags[count]?.content;\n      if (name === \"featurehub-url\") {\n        url = content;\n      } else if (content && name === \"featurehub-apiKey\") {\n        apiKeys.push(content);\n      } else if (name === \"featurehub-interval\") {\n        pollInterval = content;\n      } else if (name === \"featurehub-loglevel\") {\n        switch (content) {\n          // @ts-expect-error we want fallthrough\n          case \"trace\":\n            fhLog2.trace = (..._args) => {\n              console.log(\"FeatureHub/Trace: \", ..._args);\n            };\n          // @ts-expect-error  we want fallthrough\n          // eslint-disable-next-line\n          case \"log\":\n            fhLog2.log = (..._args) => {\n              console.log(\"FeatureHub/Debug: \", ..._args);\n            };\n          // eslint-disable-next-line\n          case \"error\":\n            fhLog2.error = (..._args) => {\n              console.error(\"FeatureHub/Debug: \", ..._args);\n            };\n            break;\n          default:\n            fhLog2.trace = () => {\n            };\n            fhLog2.log = () => {\n            };\n            fhLog2.error = () => {\n            };\n            break;\n        }\n      } else if (content && name?.startsWith(\"featurehub-\")) {\n        params.push([name.substring(11), content]);\n      }\n    }\n    if (apiKeys.length > 0) {\n      if (pollInterval) {\n        const _interval = pollInterval;\n        fhLog2.trace(\"setting polling interval to\", pollInterval);\n        EdgeFeatureHubConfig.defaultEdgeServiceSupplier = (repo, config2) => new FeatureHubPollingClient(repo, config2, parseInt(_interval));\n      }\n      const config = EdgeFeatureHubConfig.config(\n        url || \"https://app.featurehub.io/vanilla\",\n        apiKeys[0]\n      );\n      if (apiKeys.length > 1) {\n        for (let count = 1; count < apiKeys.length; count++) {\n          config.apiKey(apiKeys[count]);\n        }\n      }\n      const context = config.newContext();\n      for (let count = 0; count < params.length; count++) {\n        const value = params[count];\n        context.attributeValue(value[0], value[1]);\n      }\n      context.build();\n      this.set(config, context);\n    }\n  }\n  static close() {\n    this.config.close();\n  }\n};\nif (typeof window !== \"undefined\" && typeof document !== \"undefined\") {\n  FeatureHub._initialize();\n}\nexport {\n  BrowserPollingService,\n  FeatureHub\n};\n"]}