{"version":3,"file":"hooks.cjs","sources":["../../../../src/services/pluginSettings/hooks.ts"],"sourcesContent":["import { useAsync } from 'react-use';\n\nimport { type PluginMeta } from '@grafana/data';\n\nimport { isFetchError } from '../backendSrv';\n\nimport { getPluginSettings } from './getPluginSettings';\nimport { getAppPluginEnabled } from './settings';\n\n/**\n * Hook that checks if an app plugin is installed and enabled.\n * @param pluginId - The ID of the app plugin.\n * @returns loading, error, value of the app plugin installed and enabled status.\n * The value is true if the app plugin is installed and enabled, false otherwise.\n */\nexport function useAppPluginEnabled(pluginId: string) {\n  const { loading, error, value } = useAsync(async () => getAppPluginEnabled(pluginId), [pluginId]);\n  return { loading, error, value };\n}\n\n/**\n * Hook that fetches the full plugin settings (PluginMeta) for a given plugin ID.\n * @param pluginId - The ID of the plugin.\n * @returns loading, error, value where value is the PluginMeta or undefined if not found.\n * A 404 (plugin not installed) resolves to value: undefined with no error.\n * Other failures (auth errors, server errors) are surfaced via the error field.\n */\nexport function usePluginSettings(pluginId: string) {\n  const { loading, error, value } = useAsync(async (): Promise<PluginMeta | undefined> => {\n    if (!pluginId) {\n      return undefined;\n    }\n    try {\n      return await getPluginSettings(pluginId);\n    } catch (err) {\n      // getLegacySettings wraps the raw fetch error as the `cause`. A 404 means the\n      // plugin is simply not installed — treat it as a normal absence, not an error.\n      const cause = err instanceof Error ? err.cause : err;\n      if (isFetchError(cause) && cause.status === 404) {\n        return undefined;\n      }\n      throw err;\n    }\n  }, [pluginId]);\n  return { loading, error, value };\n}\n"],"names":["useAsync","getAppPluginEnabled","getPluginSettings","isFetchError"],"mappings":";;;;;;;;;;AAeO,SAAS,oBAAoB,QAAA,EAAkB;AACpD,EAAA,MAAM,EAAE,OAAA,EAAS,KAAA,EAAO,KAAA,EAAM,GAAIA,iBAAA,CAAS,YAAYC,4BAAA,CAAoB,QAAQ,CAAA,EAAG,CAAC,QAAQ,CAAC,CAAA;AAChG,EAAA,OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,KAAA,EAAM;AACjC;AASO,SAAS,kBAAkB,QAAA,EAAkB;AAClD,EAAA,MAAM,EAAE,OAAA,EAAS,KAAA,EAAO,KAAA,EAAM,GAAID,kBAAS,YAA6C;AACtF,IAAA,IAAI,CAAC,QAAA,EAAU;AACb,MAAA,OAAO,KAAA,CAAA;AAAA,IACT;AACA,IAAA,IAAI;AACF,MAAA,OAAO,MAAME,oCAAkB,QAAQ,CAAA;AAAA,IACzC,SAAS,GAAA,EAAK;AAGZ,MAAA,MAAM,KAAA,GAAQ,GAAA,YAAe,KAAA,GAAQ,GAAA,CAAI,KAAA,GAAQ,GAAA;AACjD,MAAA,IAAIC,uBAAA,CAAa,KAAK,CAAA,IAAK,KAAA,CAAM,WAAW,GAAA,EAAK;AAC/C,QAAA,OAAO,KAAA,CAAA;AAAA,MACT;AACA,MAAA,MAAM,GAAA;AAAA,IACR;AAAA,EACF,CAAA,EAAG,CAAC,QAAQ,CAAC,CAAA;AACb,EAAA,OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,KAAA,EAAM;AACjC;;;;;"}