Fix bad imports of node-fetch

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2023-01-10 15:18:11 -05:00
1 parent e8bc887f0b
commit 58cbf5f300
3 files changed
+32 -3

No files matched your search

+14 -2
View File
@@ -7,8 +7,13 @@ import type { Cluster } from "../common/cluster/cluster";
import { getInjectable } from "@ogre-tools/injectable";
import type { RequestInit } from "node-fetch";
import lensFetchInjectable from "../common/fetch/lens-fetch.injectable";
import { withTimeout } from "../common/fetch/timeout-controller";
export type K8sRequest = (cluster: Cluster, path: string, options?: RequestInit) => Promise<unknown>;
export interface K8sRequestInit extends Omit<RequestInit, "signal"> {
timeout?: number;
}
export type K8sRequest = (cluster: Cluster, path: string, init?: K8sRequestInit) => Promise<unknown>;
const k8sRequestInjectable = getInjectable({
id: "k8s-request",
@@ -16,7 +21,14 @@ const k8sRequestInjectable = getInjectable({
instantiate: (di): K8sRequest => {
const lensFetch = di.inject(lensFetchInjectable);
return async (cluster, path, init) => lensFetch(`/${cluster.id}${apiKubePrefix}${path}`, init);
return async (cluster, path, { timeout = 30_000, ...init } = {}) => {
const controller = withTimeout(timeout);
return lensFetch(`/${cluster.id}${apiKubePrefix}${path}`, {
...init,
signal: controller.signal,
});
};
},
});