mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-29 22:55:24 +00:00
chore: lock the plugin boundary and remove 2.9.0 leftovers
This commit is contained in:
1 parent
6489b62ece
commit
2961297989
399 files changed
+3964
-5627
No files matched your search
@@ -6,7 +6,7 @@
|
||||
"scripts": {
|
||||
"build": "termix-plugin build",
|
||||
"test": "termix-plugin test",
|
||||
"typecheck": "tsc -b ../../tsconfig.plugins.json ../../tsconfig.plugins.frontend.json",
|
||||
"typecheck": "tsc -b ../../tsconfig.plugins.backend.json ../../tsconfig.plugins.frontend.json",
|
||||
"validate": "termix-plugin validate"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -17,8 +17,8 @@ import {
|
||||
SelectValue,
|
||||
SettingRow,
|
||||
} from "@termix/plugin-sdk/ui";
|
||||
import { resolveConnectionOrigin } from "@/lib/connection-origin";
|
||||
import { isElectron } from "@/lib/electron";
|
||||
import { resolveConnectionOrigin } from "@termix/plugin-sdk/ui";
|
||||
import { isElectron } from "@termix/plugin-sdk/ui";
|
||||
import {
|
||||
MAX_WEB_ENDPOINTS,
|
||||
MAX_WEB_ENDPOINT_LABEL_LENGTH,
|
||||
|
||||
@@ -14,10 +14,10 @@ import {
|
||||
openWebEndpointTunnel,
|
||||
requireNumericHostId,
|
||||
} from "./web-endpoint-api";
|
||||
import { copyToClipboard } from "@/lib/clipboard";
|
||||
import { isElectron } from "@/lib/electron";
|
||||
import { Button } from "@/components/button";
|
||||
import type { Host } from "@/types/ui-types";
|
||||
import { copyToClipboard } from "@termix/plugin-sdk/ui";
|
||||
import { isElectron } from "@termix/plugin-sdk/ui";
|
||||
import { Button } from "@termix/plugin-sdk/ui";
|
||||
import type { PluginHostRecord as Host } from "@termix/plugin-sdk/frontend";
|
||||
import type { WebEndpoint } from "../shared/web-endpoint-config";
|
||||
|
||||
const REFUSAL_MESSAGES: Record<WebEndpointRefusalReason, string> = {
|
||||
|
||||
@@ -8,7 +8,7 @@ import type {
|
||||
TabProps,
|
||||
TermixApp,
|
||||
} from "@termix/plugin-sdk/frontend";
|
||||
import type { Host } from "@/types/ui-types";
|
||||
import type { PluginHostRecord as Host } from "@termix/plugin-sdk/frontend";
|
||||
import type { WebEndpoint } from "../shared/web-endpoint-config";
|
||||
import { WebEndpointTab } from "./WebEndpointTab";
|
||||
import { HostEditorWebUiSection } from "./HostEditorWebUiSection";
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import axios from "axios";
|
||||
import type { PluginApiClient } from "@termix/plugin-sdk/frontend";
|
||||
import { handleApiError } from "@/main-axios";
|
||||
import { isElectron } from "@/lib/electron";
|
||||
import { isElectron } from "@termix/plugin-sdk/ui";
|
||||
import type { WebEndpoint } from "../shared/web-endpoint-config";
|
||||
|
||||
let pluginApi: PluginApiClient | null = null;
|
||||
|
||||
function genericFailure(error: unknown, action: string): never {
|
||||
if (!axios.isAxiosError(error) && error instanceof Error) throw error;
|
||||
const status = axios.isAxiosError(error) ? error.response?.status : undefined;
|
||||
throw new WebEndpointTunnelError(`Could not ${action}`, status);
|
||||
}
|
||||
|
||||
/** Set from activate with app.api, cleared on deactivate. */
|
||||
export function setWebEndpointApi(api: PluginApiClient | null): void {
|
||||
pluginApi = api;
|
||||
@@ -15,8 +20,8 @@ export function setWebEndpointApi(api: PluginApiClient | null): void {
|
||||
* Thrown when the backend rejects a web endpoint tunnel open with a specific,
|
||||
* actionable reason -- most commonly a 502 carrying the real cause: SSH auth
|
||||
* rejected, host unreachable, or nothing listening on the target port.
|
||||
* Preserves that reason instead of letting handleApiError collapse three
|
||||
* actionable errors into "Server error occurred. Please try again later."
|
||||
* Preserves that reason instead of collapsing three actionable errors into
|
||||
* one generic failure.
|
||||
*/
|
||||
export class WebEndpointTunnelError extends Error {
|
||||
constructor(
|
||||
@@ -67,7 +72,7 @@ export async function openWebEndpointTunnel(
|
||||
);
|
||||
}
|
||||
}
|
||||
return handleApiError(error, "open web endpoint tunnel");
|
||||
return genericFailure(error, "open web endpoint tunnel");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +150,6 @@ export async function openWebEndpointExternally(
|
||||
);
|
||||
}
|
||||
}
|
||||
return handleApiError(error, "open isolated web endpoint");
|
||||
return genericFailure(error, "open isolated web endpoint");
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
waitFor,
|
||||
} from "@testing-library/react";
|
||||
import type { WebEndpoint } from "../../src/shared/web-endpoint-config";
|
||||
import type { Host } from "@/types/ui-types";
|
||||
import type { PluginHostRecord as Host } from "@termix/plugin-sdk/frontend";
|
||||
|
||||
const openWebEndpointTunnel = vi.hoisted(() => vi.fn());
|
||||
const allowInvalidCertificateForOrigin = vi.hoisted(() => vi.fn());
|
||||
@@ -31,9 +31,13 @@ vi.mock("../../src/frontend/web-endpoint-api", async (importOriginal) => {
|
||||
});
|
||||
|
||||
const electron = vi.hoisted(() => ({ isElectron: vi.fn(() => true) }));
|
||||
vi.mock("@/lib/electron", () => electron);
|
||||
vi.mock("@termix/plugin-sdk/ui", async (importOriginal) => ({
|
||||
...(await importOriginal<object>()),
|
||||
...electron,
|
||||
}));
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
vi.mock("react-i18next", async (importOriginal) => ({
|
||||
...(await importOriginal<object>()),
|
||||
useTranslation: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
|
||||
|
||||
@@ -4,8 +4,7 @@ import {
|
||||
renderWithApp,
|
||||
type RenderedPluginApp,
|
||||
} from "@termix/plugin-sdk/testing";
|
||||
import { hostActionsFor, listHostActions } from "@/sidebar/host-contributions";
|
||||
import type { Host } from "@/types/ui-types";
|
||||
import type { PluginHostRecord as Host } from "@termix/plugin-sdk/frontend";
|
||||
import type { PluginManifest } from "@termix/plugin-sdk/manifest";
|
||||
import type { WebEndpoint } from "../../src/shared/web-endpoint-config";
|
||||
import * as plugin from "../../src/frontend/index";
|
||||
@@ -48,9 +47,9 @@ let rendered: RenderedPluginApp | null = null;
|
||||
|
||||
async function webAction(target: Host) {
|
||||
rendered ??= await renderWithApp(plugin, { manifest });
|
||||
return hostActionsFor(listHostActions(), target).find(
|
||||
(action) => action.id === "web-endpoint",
|
||||
);
|
||||
return rendered.registered
|
||||
.hostActionsFor(target)
|
||||
.find((action) => action.id === "web-endpoint");
|
||||
}
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -2,14 +2,12 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { WebEndpoint } from "../../src/shared/web-endpoint-config";
|
||||
|
||||
const isElectron = vi.hoisted(() => vi.fn(() => false));
|
||||
vi.mock("@/lib/electron", () => ({ isElectron }));
|
||||
vi.mock("@termix/plugin-sdk/ui", async (importOriginal) => ({
|
||||
...(await importOriginal<object>()),
|
||||
isElectron,
|
||||
}));
|
||||
|
||||
const pluginPost = vi.hoisted(() => vi.fn());
|
||||
vi.mock("@/main-axios", () => ({
|
||||
handleApiError: (error: unknown) => {
|
||||
throw new Error(`generic: ${String(error)}`);
|
||||
},
|
||||
}));
|
||||
|
||||
function endpoint(overrides: Partial<WebEndpoint> = {}): WebEndpoint {
|
||||
return {
|
||||
@@ -94,7 +92,9 @@ describe("openWebEndpointTunnel", () => {
|
||||
);
|
||||
const { openWebEndpointTunnel } =
|
||||
await import("../../src/frontend/web-endpoint-api");
|
||||
await expect(openWebEndpointTunnel(7, "e1")).rejects.toThrow(/generic:/);
|
||||
await expect(openWebEndpointTunnel(7, "e1")).rejects.toThrow(
|
||||
/Could not open web endpoint tunnel/,
|
||||
);
|
||||
});
|
||||
|
||||
it("treats a missing port as a failure rather than returning undefined", async () => {
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
{
|
||||
"extends": "@termix/plugin-sdk/tsconfig.plugin.json",
|
||||
"compilerOptions": {
|
||||
"paths": {
|
||||
"@/types/*": ["../../src/types/*"],
|
||||
"@/*": ["../../src/ui/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx", "tests/**/*.ts", "tests/**/*.tsx"]
|
||||
}
|
||||
Reference in new issue
Block a user