Fix types

This commit is contained in:
Owen
2026-07-31 16:50:35 -04:00
parent 7e05c16ccd
commit 104dcebda7
14 changed files with 44 additions and 35 deletions
+1
View File
@@ -2411,6 +2411,7 @@
"editInternalResourceDialogModeCidr": "CIDR", "editInternalResourceDialogModeCidr": "CIDR",
"editInternalResourceDialogModeHttp": "HTTP", "editInternalResourceDialogModeHttp": "HTTP",
"editInternalResourceDialogModeHttps": "HTTPS", "editInternalResourceDialogModeHttps": "HTTPS",
"editInternalResourceDialogModeInference": "Inference",
"editInternalResourceDialogModeSsh": "SSH", "editInternalResourceDialogModeSsh": "SSH",
"editInternalResourceDialogScheme": "Scheme", "editInternalResourceDialogScheme": "Scheme",
"editInternalResourceDialogEnableSsl": "Enable TLS", "editInternalResourceDialogEnableSsl": "Enable TLS",
+3 -1
View File
@@ -197,7 +197,9 @@ export const resources = pgTable(
wildcard: boolean("wildcard").notNull().default(false), wildcard: boolean("wildcard").notNull().default(false),
mode: text("mode") mode: text("mode")
.default("http") .default("http")
.$type<"rdp" | "ssh" | "http" | "vnc" | "inference">() .$type<
"rdp" | "ssh" | "http" | "vnc" | "inference" | "tcp" | "udp"
>()
.notNull(), .notNull(),
pamMode: varchar("pamMode", { length: 32 }) pamMode: varchar("pamMode", { length: 32 })
.$type<"passthrough" | "push">() .$type<"passthrough" | "push">()
+1 -1
View File
@@ -206,7 +206,7 @@ export const resources = sqliteTable("resources", {
wildcard: integer("wildcard", { mode: "boolean" }).notNull().default(false), wildcard: integer("wildcard", { mode: "boolean" }).notNull().default(false),
mode: text("mode") mode: text("mode")
.default("http") .default("http")
.$type<"rdp" | "ssh" | "http" | "vnc" | "inference">() .$type<"rdp" | "ssh" | "http" | "vnc" | "inference" | "tcp" | "udp">()
.notNull(), // rdp, ssh, http, vnc, inference .notNull(), // rdp, ssh, http, vnc, inference
pamMode: text("pamMode") pamMode: text("pamMode")
.$type<"passthrough" | "push">() .$type<"passthrough" | "push">()
@@ -18,6 +18,7 @@ import {
domains, domains,
exitNodes, exitNodes,
loginPage, loginPage,
SiteResource,
targetHealthCheck targetHealthCheck
} from "@server/db"; } from "@server/db";
import { import {
@@ -359,7 +360,7 @@ export async function getTraefikConfig(
let siteResourcesWithFullDomain: { let siteResourcesWithFullDomain: {
siteResourceId: number; siteResourceId: number;
fullDomain: string | null; fullDomain: string | null;
mode: "http" | "host" | "cidr" | "ssh"; mode: SiteResource["mode"];
}[] = []; }[] = [];
if ( if (
build == "enterprise" && build == "enterprise" &&
@@ -1,7 +1,8 @@
import { SiteResource } from "@server/db";
import { formatEndpoint, parseEndpoint } from "@server/lib/ip"; import { formatEndpoint, parseEndpoint } from "@server/lib/ip";
export type SiteResourceDestinationInput = { export type SiteResourceDestinationInput = {
mode: "host" | "cidr" | "http" | "ssh"; mode: SiteResource["mode"];
destination: string | null; destination: string | null;
destinationPort: number | null; destinationPort: number | null;
scheme: "http" | "https" | null; scheme: "http" | "https" | null;
+2 -2
View File
@@ -44,11 +44,11 @@ const createResourceParamsSchema = z.strictObject({
}); });
function resolveModeFromLegacyFields(data: { function resolveModeFromLegacyFields(data: {
mode?: "http" | "ssh" | "rdp" | "vnc" | "tcp" | "udp"; mode?: "http" | "ssh" | "rdp" | "vnc" | "tcp" | "udp" | "inference";
http?: boolean; http?: boolean;
protocol?: "tcp" | "udp"; protocol?: "tcp" | "udp";
}): { }): {
mode?: "http" | "ssh" | "rdp" | "vnc" | "tcp" | "udp"; mode?: "http" | "ssh" | "rdp" | "vnc" | "tcp" | "udp" | "inference";
error?: string; error?: string;
} { } {
if (data.mode) { if (data.mode) {
+2 -1
View File
@@ -637,11 +637,12 @@ export async function listResources(
${resourcePassword.passwordId} ${resourcePassword.passwordId}
) )
`; `;
const browserGatewayModes = ["http", "ssh", "rdp", "vnc"]; const browserGatewayModes = ["http", "ssh", "rdp", "vnc"] as const;
switch (authState) { switch (authState) {
case "none": case "none":
conditions.push( conditions.push(
// TODO: Does inference belong here?
or(eq(resources.mode, "tcp"), eq(resources.mode, "udp")) or(eq(resources.mode, "tcp"), eq(resources.mode, "udp"))
); );
break; break;
@@ -1,5 +1,5 @@
import PrivateResourcesBanner from "@app/components/PrivateResourcesBanner"; import PrivateResourcesBanner from "@app/components/PrivateResourcesBanner";
import type { InternalResourceRow } from "@app/components/PrivateResourcesTable"; import type { PrivateResourceRow } from "@app/components/PrivateResourcesTable";
import PrivateResourcesTable from "@app/components/PrivateResourcesTable"; import PrivateResourcesTable from "@app/components/PrivateResourcesTable";
import SettingsSectionTitle from "@app/components/SettingsSectionTitle"; import SettingsSectionTitle from "@app/components/SettingsSectionTitle";
import { internal } from "@app/lib/api"; import { internal } from "@app/lib/api";
@@ -61,7 +61,7 @@ export default async function ClientResourcesPage(
redirect(`/${params.orgId}/settings/resources`); redirect(`/${params.orgId}/settings/resources`);
} }
const internalResourceRows: InternalResourceRow[] = siteResources.map( const internalResourceRows: PrivateResourceRow[] = siteResources.map(
(siteResource) => { (siteResource) => {
return { return {
id: siteResource.siteResourceId, id: siteResource.siteResourceId,
@@ -206,7 +206,7 @@ function createAddTargetSchema(t: TranslateFn) {
); );
} }
type NewResourceType = "http" | "ssh" | "rdp" | "vnc" | "tcp" | "udp"; type NewResourceType = "http" | "ssh" | "rdp" | "vnc" | "tcp" | "udp" | "inference";
type CreateBgTargetFormValues = SshSettingsFormValues; type CreateBgTargetFormValues = SshSettingsFormValues;
+17 -19
View File
@@ -69,20 +69,21 @@ import { LabelColumnFilterButton } from "./LabelColumnFilterButton";
import { LabelsTableCell } from "./LabelsTableCell"; import { LabelsTableCell } from "./LabelsTableCell";
import { ControlledDataTable } from "./ui/controlled-data-table"; import { ControlledDataTable } from "./ui/controlled-data-table";
import { SitesColumnFilterButton } from "./SitesColumnFilterButton"; import { SitesColumnFilterButton } from "./SitesColumnFilterButton";
import { SiteResource } from "@server/db";
export type InternalResourceSiteRow = ResourceSiteRow; export type PrivateResourceSiteRow = ResourceSiteRow;
export type InternalResourceRow = { export type PrivateResourceRow = {
id: number; id: number;
name: string; name: string;
orgId: string; orgId: string;
sites: InternalResourceSiteRow[]; sites: PrivateResourceSiteRow[];
siteNames: string[]; siteNames: string[];
siteAddresses: (string | null)[]; siteAddresses: (string | null)[];
siteIds: number[]; siteIds: number[];
siteNiceIds: string[]; siteNiceIds: string[];
// mode: "host" | "cidr" | "port"; // mode: "host" | "cidr" | "port";
mode: "host" | "cidr" | "http" | "ssh"; mode: SiteResource["mode"];
scheme: "http" | "https" | null; scheme: "http" | "https" | null;
ssl: boolean; ssl: boolean;
// protocol: string | null; // protocol: string | null;
@@ -109,7 +110,7 @@ export type InternalResourceRow = {
}>; }>;
}; };
function formatDestinationDisplay(row: InternalResourceRow): string { function formatDestinationDisplay(row: PrivateResourceRow): string {
return formatSiteResourceDestinationDisplay({ return formatSiteResourceDestinationDisplay({
mode: row.mode, mode: row.mode,
destination: row.destination, destination: row.destination,
@@ -133,7 +134,7 @@ const booleanSearchFilterSchema = z
.catch(undefined); .catch(undefined);
type ClientResourcesTableProps = { type ClientResourcesTableProps = {
internalResources: InternalResourceRow[]; internalResources: PrivateResourceRow[];
orgId: string; orgId: string;
pagination: PaginationState; pagination: PaginationState;
rowCount: number; rowCount: number;
@@ -164,10 +165,10 @@ export default function PrivateResourcesTable({
const [isNavigatingToAddPage, startNavigation] = useTransition(); const [isNavigatingToAddPage, startNavigation] = useTransition();
const [selectedInternalResource, setSelectedInternalResource] = const [selectedInternalResource, setSelectedInternalResource] =
useState<InternalResourceRow | null>(null); useState<PrivateResourceRow | null>(null);
const [isEditDialogOpen, setIsEditDialogOpen] = useState(false); const [isEditDialogOpen, setIsEditDialogOpen] = useState(false);
const [editingResource, setEditingResource] = const [editingResource, setEditingResource] =
useState<InternalResourceRow | null>(); useState<PrivateResourceRow | null>();
const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false); const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false);
const [isRefreshing, startRefreshTransition] = useTransition(); const [isRefreshing, startRefreshTransition] = useTransition();
@@ -241,9 +242,9 @@ export default function PrivateResourcesTable({
}; };
const internalColumns = useMemo< const internalColumns = useMemo<
ExtendedColumnDef<InternalResourceRow>[] ExtendedColumnDef<PrivateResourceRow>[]
>(() => { >(() => {
const cols: ExtendedColumnDef<InternalResourceRow>[] = [ const cols: ExtendedColumnDef<PrivateResourceRow>[] = [
{ {
accessorKey: "name", accessorKey: "name",
enableHiding: false, enableHiding: false,
@@ -364,15 +365,12 @@ export default function PrivateResourcesTable({
), ),
cell: ({ row }) => { cell: ({ row }) => {
const resourceRow = row.original; const resourceRow = row.original;
const modeLabels: Record< const modeLabels: Record<SiteResource["mode"], string> = {
"host" | "cidr" | "port" | "http" | "ssh",
string
> = {
host: t("editInternalResourceDialogModeHost"), host: t("editInternalResourceDialogModeHost"),
cidr: t("editInternalResourceDialogModeCidr"), cidr: t("editInternalResourceDialogModeCidr"),
port: t("editInternalResourceDialogModePort"),
http: t("editInternalResourceDialogModeHttp"), http: t("editInternalResourceDialogModeHttp"),
ssh: t("editInternalResourceDialogModeSsh") ssh: t("editInternalResourceDialogModeSsh"),
inference: t("editInternalResourceDialogModeInference")
}; };
return <span>{modeLabels[resourceRow.mode]}</span>; return <span>{modeLabels[resourceRow.mode]}</span>;
} }
@@ -521,7 +519,7 @@ export default function PrivateResourcesTable({
className="p-3" className="p-3"
/> />
), ),
cell: ({ row }: { row: { original: InternalResourceRow } }) => ( cell: ({ row }: { row: { original: PrivateResourceRow } }) => (
<ClientResourceLabelCell <ClientResourceLabelCell
resource={row.original} resource={row.original}
orgId={orgId} orgId={orgId}
@@ -697,7 +695,7 @@ export default function PrivateResourcesTable({
} }
type ClientResourceLabelCellProps = { type ClientResourceLabelCellProps = {
resource: InternalResourceRow; resource: PrivateResourceRow;
orgId: string; orgId: string;
}; };
@@ -723,7 +721,7 @@ function ClientResourceLabelCell({
} }
type InternalResourceEnabledFormProps = { type InternalResourceEnabledFormProps = {
resource: InternalResourceRow; resource: PrivateResourceRow;
onToggleInternalResourceEnabled: ( onToggleInternalResourceEnabled: (
val: boolean, val: boolean,
resourceId: number resourceId: number
+2 -1
View File
@@ -93,7 +93,8 @@ export function SiteResourceInfoSections({
host: t("editInternalResourceDialogModeHost"), host: t("editInternalResourceDialogModeHost"),
cidr: t("editInternalResourceDialogModeCidr"), cidr: t("editInternalResourceDialogModeCidr"),
http: t("editInternalResourceDialogModeHttp"), http: t("editInternalResourceDialogModeHttp"),
ssh: t("editInternalResourceDialogModeSsh") ssh: t("editInternalResourceDialogModeSsh"),
inference: t("editInternalResourceDialogModeInference")
}; };
const destination = formatSiteResourceDestinationDisplay({ const destination = formatSiteResourceDestinationDisplay({
+2 -1
View File
@@ -70,7 +70,8 @@ function PrivateResourceMeta({ row }: { row: SiteResourceRow }) {
host: t("editInternalResourceDialogModeHost"), host: t("editInternalResourceDialogModeHost"),
cidr: t("editInternalResourceDialogModeCidr"), cidr: t("editInternalResourceDialogModeCidr"),
http: t("editInternalResourceDialogModeHttp"), http: t("editInternalResourceDialogModeHttp"),
ssh: t("editInternalResourceDialogModeSsh") ssh: t("editInternalResourceDialogModeSsh"),
inference: t("editInternalResourceDialogModeInference")
}; };
const dest = formatSiteResourceDestinationDisplay({ const dest = formatSiteResourceDestinationDisplay({
mode: row.mode, mode: row.mode,
+3 -1
View File
@@ -1,5 +1,7 @@
import { SiteResource } from "@server/db";
export type SiteResourceDestinationInput = { export type SiteResourceDestinationInput = {
mode: "host" | "cidr" | "http" | "ssh"; mode: SiteResource["mode"];
destination: string | null; destination: string | null;
destinationPort: number | null; destinationPort: number | null;
scheme: "http" | "https" | null; scheme: "http" | "https" | null;
+4 -3
View File
@@ -1,9 +1,10 @@
import { z } from "zod"; import { z } from "zod";
import type { InternalResourceRow } from "@app/components/PrivateResourcesTable"; import type { PrivateResourceRow } from "@app/components/PrivateResourcesTable";
import { SiteResource } from "@server/db";
export type PrivateResourceMode = "host" | "cidr" | "http" | "ssh"; export type PrivateResourceMode = SiteResource["mode"];
export type SiteResourceData = InternalResourceRow & { export type SiteResourceData = PrivateResourceRow & {
enabled: boolean; enabled: boolean;
}; };