1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/common/k8s-api/endpoints/helm-charts.api/request-versions.injectable.ts
Sebastian Malton c850fb6211 Replace apiBaseInjectionToken with tokens for configuration instead
Signed-off-by: Sebastian Malton <sebastian@malton.name>
2022-12-16 09:37:04 -05:00

32 lines
1.2 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { urlBuilderFor } from "../../../utils/buildUrl";
import { HelmChart } from "../helm-charts.api";
import type { RawHelmChart } from "../helm-charts.api";
import { isDefined } from "../../../utils";
import apiBaseInjectable from "../../api-base.injectable";
const requestVersionsEndpoint = urlBuilderFor("/v2/charts/:repo/:name/versions");
export type RequestHelmChartVersions = (repo: string, chartName: string) => Promise<HelmChart[]>;
const requestHelmChartVersionsInjectable = getInjectable({
id: "request-helm-chart-versions",
instantiate: (di): RequestHelmChartVersions => {
const apiBase = di.inject(apiBaseInjectable);
return async (repo, name) => {
const rawVersions = await apiBase.get(requestVersionsEndpoint.compile({ name, repo })) as RawHelmChart[];
return rawVersions
.map(version => HelmChart.create(version, { onError: "log" }))
.filter(isDefined);
};
},
});
export default requestHelmChartVersionsInjectable;