bd0140b6f0
* GrafanaBootData: decouple `config.apps` from boot data IV * chore: changed to openfeature flags eval * chore: updates after PR feedback * chore: updates after PR feedback * chore: copy types to runtime package * chore: add code ownership * chore: deprecate in interface too * chore: add important notice to comments * chore: deprecate the whole interface
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import { config } from '../../config';
|
|
import { evaluateBooleanFlag } from '../../internal/openFeature';
|
|
|
|
import type { PluginMetasResponse } from './types';
|
|
|
|
let initPromise: Promise<PluginMetasResponse> | null = null;
|
|
|
|
function getApiVersion(): string {
|
|
return 'v0alpha1';
|
|
}
|
|
|
|
async function loadPluginMetas(): Promise<PluginMetasResponse> {
|
|
if (!evaluateBooleanFlag('useMTPlugins', false)) {
|
|
const result = { items: [] };
|
|
return result;
|
|
}
|
|
|
|
const metas = await fetch(`/apis/plugins.grafana.app/${getApiVersion()}/namespaces/${config.namespace}/metas`);
|
|
if (!metas.ok) {
|
|
throw new Error(`Failed to load plugin metas ${metas.status}:${metas.statusText}`);
|
|
}
|
|
|
|
const result = await metas.json();
|
|
return result;
|
|
}
|
|
|
|
export function initPluginMetas(): Promise<PluginMetasResponse> {
|
|
if (!initPromise) {
|
|
initPromise = loadPluginMetas();
|
|
}
|
|
|
|
return initPromise;
|
|
}
|
|
|
|
export function clearCache() {
|
|
if (process.env.NODE_ENV !== 'test') {
|
|
throw new Error('clearCache() function can only be called from tests.');
|
|
}
|
|
|
|
initPromise = null;
|
|
}
|