{"version":3,"file":"index.cjs","sources":["../src/context.ts","../src/use-flags.ts","../src/use-feature.ts","../src/Feature.tsx","../src/FireFlags.tsx","../src/use-flag.ts"],"sourcesContent":["import React from 'react';\nimport type { Flag } from './types';\n\nconst FlagsContext = React.createContext<Flag[]>([]);\n\nexport default FlagsContext;\n","import { useContext } from 'react';\nimport FlagsContext from './context';\nimport type { Flag } from './types';\n\n/**\n * Get the list of all flags.\n */\nconst useFlags = (): Flag[] => useContext(FlagsContext);\n\nexport default useFlags;\n","import useFlags from './use-flags';\n\n/**\n * Check if the flag with `name` is active.\n */\nconst useFeature = (name: string) => useFlags()\n  .some((flag) => (flag.name === name && flag.isActive));\n\nexport default useFeature;\n","import React from 'react';\nimport useFeature from './use-feature';\n\nexport type FeatureProps = React.PropsWithChildren<{\n  /**\n   * The name of the flag to check if is active.\n   */\n  name: string,\n  /**\n   * The fallback component to show if the feature don't exists.\n   */\n  fallback?: React.ReactNode,\n}>;\n/**\n * A guard that render the `children` if the flag with `name` exists.\n * The `fallback` is rendered otherwise.\n *\n * @example\n * ```javascript\n * const CoolFeature = () => <p>Coll feature active</p>\n * const Home = () => (\n * <div>\n *   <Feature name=\"fluffy-wolfy\">\n *     <CoolFeature />\n *   </Feature>\n * </div>\n * ```\n */\nconst Feature: React.FunctionComponent<FeatureProps> = ({\n  children,\n  fallback = <></>,\n  name,\n}) => {\n  const hasFeature = useFeature(name);\n  if (hasFeature) return <>{children}</>;\n  return <>{fallback}</>;\n};\n\nexport default Feature;\n","import React, { useEffect, useState } from 'react';\nimport FlagsContext from './context';\nimport type { Flag } from './types';\n\nconst defaultUrl = 'https://flags.stackonfire.dev';\nexport type FireFlagsProps = React.PropsWithChildren<{\n  /**\n   * The id of the [fire-flags](https://flags.stackonfire.dev') project\n   */\n  projectId: string,\n  /**\n   * The url of the [fire-flags](https://flags.stackonfire.dev') backend, to pass if using a\n   * self-hosted version\n   */\n  url?: string,\n}>;\n/**\n * The provider to configure of the fire-flags server.\n * Must be added to the root of the project before using any of the hooks or components.\n *\n * @example\n * ```javascript\n * function App() {\n *   return (\n *     <FireFlags\n *        projectId={process.env.REACT_APP_FIRE_FLAGS_PROJECT_ID}\n *        url={process.env.REACT_APP_FIRE_FLAGS_URL}\n *     >\n *       Hello World!\n *     </FireFlags>\n *   )\n * }\n * ```\n */\nconst FireFlags: React.FunctionComponent<FireFlagsProps> = ({\n  children,\n  projectId,\n  url = defaultUrl,\n}) => {\n  if (projectId === undefined) {\n    throw new Error('FireFlags expects project id');\n  }\n  const [data, setData] = useState<Flag[]>([]);\n  useEffect(() => {\n    fetch(`${url}/api/flags/${projectId}`)\n      .then((res) => res.json())\n      .then(setData);\n  }, [projectId, url]);\n  return (\n    <FlagsContext.Provider value={data}>\n      {children}\n    </FlagsContext.Provider>\n  );\n};\n\nexport default FireFlags;\n\n","import useFlags from './use-flags';\n\n/**\n * Find the flag with then name `name`.\n */\nconst useFlag = (name: string) => useFlags().find((flag) => flag.name === name);\n\nexport default useFlag;\n"],"names":["FlagsContext","React","createContext","useFlags","useContext","useFeature","name","some","flag","isActive","children","fallback","hasFeature","projectId","url","undefined","Error","useState","data","setData","useEffect","fetch","then","res","json","Provider","value","find"],"mappings":"0GAGMA,EAAeC,UAAMC,cAAsB,ICI3CC,EAAW,kBAAcC,aAAWJ,ICFpCK,EAAa,SAACC,UAAiBH,IAClCI,KAAK,SAACC,UAAUA,EAAKF,OAASA,GAAQE,EAAKC,4BCsBS,gBACrDC,IAAAA,aACAC,SAAAA,aAAWV,mDAGLW,EAAaP,IAFnBC,MAGA,OAAuBL,gDAAnBW,EAAsBF,EAChBC,sBCD+C,gBACzDD,IAAAA,SACAG,IAAAA,cACAC,IAAAA,aAjCiB,kCAmCjB,QAAkBC,IAAdF,EACF,UAAUG,MAAM,gCAElB,MAAwBC,WAAiB,IAAlCC,OAAMC,OAMb,OALAC,YAAU,WACRC,MAASP,gBAAiBD,GACvBS,KAAK,SAACC,UAAQA,EAAIC,SAClBF,KAAKH,IACP,CAACN,EAAWC,IAEbb,wBAACD,EAAayB,UAASC,MAAOR,GAC3BR,yCC7CS,SAACJ,UAAiBH,IAAWwB,KAAK,SAACnB,UAASA,EAAKF,OAASA"}