mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add @types/hapi__call and @types/hapi__subtext (#5574)
This commit is contained in:
parent
3058bea88f
commit
808875f491
@ -204,7 +204,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@astronautlabs/jsonpath": "^1.1.0",
|
||||
"@hapi/call": "^8.0.1",
|
||||
"@hapi/call": "^9.0.0",
|
||||
"@hapi/subtext": "^7.0.3",
|
||||
"@kubernetes/client-node": "^0.16.3",
|
||||
"@material-ui/styles": "^4.11.5",
|
||||
@ -307,6 +307,8 @@
|
||||
"@types/fs-extra": "^9.0.13",
|
||||
"@types/glob-to-regexp": "^0.4.1",
|
||||
"@types/gunzip-maybe": "^1.4.0",
|
||||
"@types/hapi__call": "^9.0.0",
|
||||
"@types/hapi__subtext": "^7.0.0",
|
||||
"@types/html-webpack-plugin": "^3.2.6",
|
||||
"@types/http-proxy": "^1.17.9",
|
||||
"@types/jest": "^28.1.1",
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import Subtext from "@hapi/subtext";
|
||||
|
||||
export type ParseRequest = typeof Subtext.parse;
|
||||
|
||||
const parseRequestInjectable = getInjectable({
|
||||
id: "parse-http-request",
|
||||
instantiate: () => Subtext.parse,
|
||||
|
||||
@ -32,7 +32,10 @@ describe("router", () => {
|
||||
|
||||
mockFs();
|
||||
|
||||
di.override(parseRequestInjectable, () => () => Promise.resolve({ payload: "some-payload" }));
|
||||
di.override(parseRequestInjectable, () => () => Promise.resolve({
|
||||
payload: "some-payload",
|
||||
mime: "some-mime",
|
||||
}));
|
||||
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
||||
di.override(kubectlBinaryNameInjectable, () => "kubectl");
|
||||
di.override(kubectlDownloadingNormalizedArchInjectable, () => "amd64");
|
||||
|
||||
@ -10,21 +10,22 @@ import type { Cluster } from "../../common/cluster/cluster";
|
||||
import { contentTypes } from "./router-content-types";
|
||||
import type { LensApiRequest, LensApiResult, Route } from "./route";
|
||||
import type { ServerIncomingMessage } from "../lens-proxy/lens-proxy";
|
||||
import type { ParseRequest } from "./parse-request.injectable";
|
||||
|
||||
export interface RouterRequestOpts {
|
||||
req: http.IncomingMessage;
|
||||
res: http.ServerResponse;
|
||||
cluster: Cluster | undefined;
|
||||
params: any;
|
||||
params: Partial<Record<string, string>>;
|
||||
url: URL;
|
||||
}
|
||||
|
||||
interface Dependencies {
|
||||
parseRequest: (request: http.IncomingMessage, _: null, options: { parse: boolean; output: string }) => Promise<{ payload: any }>;
|
||||
parseRequest: ParseRequest;
|
||||
}
|
||||
|
||||
export class Router {
|
||||
protected router = new Call.Router();
|
||||
protected router = new Call.Router<ReturnType<typeof handleRoute>>();
|
||||
|
||||
constructor(routes: Route<unknown, string>[], private dependencies: Dependencies) {
|
||||
routes.forEach(route => {
|
||||
@ -37,9 +38,11 @@ export class Router {
|
||||
const path = url.pathname;
|
||||
const method = req.method.toLowerCase();
|
||||
const matchingRoute = this.router.route(method, path);
|
||||
const routeFound = !matchingRoute.isBoom;
|
||||
|
||||
if (routeFound) {
|
||||
if (matchingRoute instanceof Error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const request = await this.getRequest({ req, res, cluster, url, params: matchingRoute.params });
|
||||
|
||||
await matchingRoute.route(request, res);
|
||||
@ -47,9 +50,6 @@ export class Router {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected async getRequest(opts: RouterRequestOpts): Promise<LensApiRequest<string>> {
|
||||
const { req, res, url, cluster, params } = opts;
|
||||
|
||||
@ -64,7 +64,7 @@ export class Router {
|
||||
raw: {
|
||||
req, res,
|
||||
},
|
||||
query: url.searchParams as never,
|
||||
query: url.searchParams,
|
||||
payload,
|
||||
params,
|
||||
};
|
||||
|
||||
2
types/mocks.d.ts
vendored
2
types/mocks.d.ts
vendored
@ -5,8 +5,6 @@
|
||||
declare module "mac-ca"
|
||||
declare module "win-ca"
|
||||
declare module "win-ca/api"
|
||||
declare module "@hapi/call"
|
||||
declare module "@hapi/subtext"
|
||||
|
||||
// Support import for custom module extensions
|
||||
// https://www.typescriptlang.org/docs/handbook/modules.html#wildcard-module-declarations
|
||||
|
||||
38
yarn.lock
38
yarn.lock
@ -627,18 +627,25 @@
|
||||
dependencies:
|
||||
"@hapi/hoek" "9.x.x"
|
||||
|
||||
"@hapi/boom@^10.0.0":
|
||||
version "10.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@hapi/boom/-/boom-10.0.0.tgz#3624831d0a26b3378423b246f50eacea16e04a08"
|
||||
integrity sha512-1YVs9tLHhypBqqinKQRqh7FUERIolarQApO37OWkzD+z6y6USi871Sv746zBPKcIOBuI6g6y4FrwX87mmJ90Gg==
|
||||
dependencies:
|
||||
"@hapi/hoek" "10.x.x"
|
||||
|
||||
"@hapi/bourne@2.x.x":
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@hapi/bourne/-/bourne-2.1.0.tgz#66aff77094dc3080bd5df44ec63881f2676eb020"
|
||||
integrity sha512-i1BpaNDVLJdRBEKeJWkVO6tYX6DMFBuwMhSuWqLsY4ufeTKGVuV5rBsUhxPayXqnnWHgXUAmWK16H/ykO5Wj4Q==
|
||||
|
||||
"@hapi/call@^8.0.1":
|
||||
version "8.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@hapi/call/-/call-8.0.1.tgz#9e64cd8ba6128eb5be6e432caaa572b1ed8cd7c0"
|
||||
integrity sha512-bOff6GTdOnoe5b8oXRV3lwkQSb/LAWylvDMae6RgEWWntd0SHtkYbQukDHKlfaYtVnSAgIavJ0kqszF/AIBb6g==
|
||||
"@hapi/call@^9.0.0":
|
||||
version "9.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@hapi/call/-/call-9.0.0.tgz#add16e7cb81933ae5b549f7e26e411ef803ebc98"
|
||||
integrity sha512-Z6byqbEtKF3RIH2kWG6cX64RwEqHBWYEVkNoEx6oKvkPaTrC6WTPRgr+ANo9Xa8G1GXyvs/NCMTnn3Mdj12TSA==
|
||||
dependencies:
|
||||
"@hapi/boom" "9.x.x"
|
||||
"@hapi/hoek" "9.x.x"
|
||||
"@hapi/boom" "^10.0.0"
|
||||
"@hapi/hoek" "^10.0.0"
|
||||
|
||||
"@hapi/content@^5.0.2":
|
||||
version "5.0.2"
|
||||
@ -652,6 +659,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@hapi/file/-/file-2.0.0.tgz#2ecda37d1ae9d3078a67c13b7da86e8c3237dfb9"
|
||||
integrity sha512-WSrlgpvEqgPWkI18kkGELEZfXr0bYLtr16iIN4Krh9sRnzBZN6nnWxHFxtsnP684wueEySBbXPDg/WfA9xJdBQ==
|
||||
|
||||
"@hapi/hoek@10.x.x", "@hapi/hoek@^10.0.0":
|
||||
version "10.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-10.0.0.tgz#b17be58febab7dbc60cde5f522da197ccde12713"
|
||||
integrity sha512-CeNFz1JcLZ5xE8Vc9aau37cgHw9bxXqSDK/D55GF2GAOv0n0XjyyjSodHtKahB7A1tV3FlgCpijp3zkSITmBdA==
|
||||
|
||||
"@hapi/hoek@9.x.x", "@hapi/hoek@^9.0.0", "@hapi/hoek@^9.0.4":
|
||||
version "9.3.0"
|
||||
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.3.0.tgz#8368869dcb735be2e7f5cb7647de78e167a251fb"
|
||||
@ -1823,6 +1835,20 @@
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/hapi__call@^9.0.0":
|
||||
version "9.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/hapi__call/-/hapi__call-9.0.0.tgz#17e287ce9333c59716b194720eea9f12e63a72f2"
|
||||
integrity sha512-WJlvjk4i7uLhALYJfWMdhW58B4OphXuE0Ob4DZFwc0zqC5fnM9Wjgk3B1fd/C6jEKnM9Y1Pzz8QeSrUJ1mue5A==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/hapi__subtext@^7.0.0":
|
||||
version "7.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/hapi__subtext/-/hapi__subtext-7.0.0.tgz#b931ccf863a694a08983ce229e7696dd0ca38151"
|
||||
integrity sha512-CwZZpuf7qXj/JKeMhFkiJQDupf7PhjZcHQ0RaeetAyxoR7vDN6kmQcGMZKEG5VTvlS/JfZGNIkq7F7nd/K+j+g==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/history@*":
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/history/-/history-5.0.0.tgz#29f919f0c8e302763798118f45b19cab4a886f14"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user