Skip to content

Commit 73db571

Browse files
committed
feat(webapp): Private Links PR review improvements
1 parent e105c48 commit 73db571

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

apps/webapp/app/env.server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,10 @@ const EnvironmentSchema = z
13851385
REALTIME_STREAMS_S2_WAIT_SECONDS: z.coerce.number().int().default(60),
13861386
REALTIME_STREAMS_DEFAULT_VERSION: z.enum(["v1", "v2"]).default("v1"),
13871387
WAIT_UNTIL_TIMEOUT_MS: z.coerce.number().int().default(600_000),
1388+
1389+
// Private connections
1390+
PRIVATE_CONNECTIONS_ENABLED: z.string().optional(),
1391+
PRIVATE_CONNECTIONS_AWS_ACCOUNT_IDS: z.string().optional(),
13881392
})
13891393
.and(GithubAppEnvSchema)
13901394
.and(S2EnvSchema);

apps/webapp/app/features.server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { env } from "./env.server";
12
import { requestUrl } from "./utils/requestUrl.server";
23

34
export type TriggerFeatures = {
@@ -15,7 +16,7 @@ function isManagedCloud(host: string): boolean {
1516
}
1617

1718
function hasPrivateConnections(host: string): boolean {
18-
if (process.env.PRIVATE_CONNECTIONS_ENABLED === "1") {
19+
if (env.PRIVATE_CONNECTIONS_ENABLED === "1") {
1920
return isManagedCloud(host);
2021
}
2122
return false;

apps/webapp/app/routes/_app.orgs.$organizationSlug.settings.private-connections._index/route.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { LinkButton } from "~/components/primitives/Buttons";
22
import { Form, useFetcher, useRevalidator, type MetaFunction } from "@remix-run/react";
33
import { type LoaderFunctionArgs } from "@remix-run/server-runtime";
4-
import { tryCatch } from "@trigger.dev/core";
4+
import { tryCatch } from "@trigger.dev/core/utils";
55
import { redirect, typedjson, useTypedLoaderData } from "remix-typedjson";
66
import {
77
MainHorizontallyCenteredContainer,
@@ -14,6 +14,7 @@ import { NavBar, PageAccessories, PageTitle } from "~/components/primitives/Page
1414
import { Paragraph } from "~/components/primitives/Paragraph";
1515
import { prisma } from "~/db.server";
1616
import { featuresForRequest } from "~/features.server";
17+
import { logger } from "~/services/logger.server";
1718
import { getPrivateLinks } from "~/services/platform.v3.server";
1819
import { requireUserId } from "~/services/session.server";
1920
import {
@@ -58,7 +59,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
5859

5960
const [error, connections] = await tryCatch(getPrivateLinks(organization.id));
6061
if (error) {
61-
console.error("Error loading private link connections", error);
62+
logger.error("Error loading private link connections", { error, organizationId: organization.id });
6263
}
6364

6465
return typedjson({

apps/webapp/app/routes/_app.orgs.$organizationSlug.settings.private-connections.new/route.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { conform, useForm } from "@conform-to/react";
22
import { parse } from "@conform-to/zod";
33
import { Form, useActionData, useParams, type MetaFunction } from "@remix-run/react";
44
import { json, type ActionFunction, type LoaderFunctionArgs } from "@remix-run/server-runtime";
5-
import { tryCatch } from "@trigger.dev/core";
5+
import { tryCatch } from "@trigger.dev/core/utils";
66
import { useState } from "react";
77
import { redirect, typedjson, useTypedLoaderData } from "remix-typedjson";
88
import { z } from "zod";
@@ -23,11 +23,13 @@ import { NavBar, PageTitle } from "~/components/primitives/PageHeader";
2323
import { Paragraph } from "~/components/primitives/Paragraph";
2424
import { Select, SelectItem } from "~/components/primitives/Select";
2525
import { prisma } from "~/db.server";
26+
import { env } from "~/env.server";
2627
import { featuresForRequest } from "~/features.server";
2728
import {
2829
redirectWithErrorMessage,
2930
redirectWithSuccessMessage,
3031
} from "~/models/message.server";
32+
import type { CreatePrivateLinkConnectionBody } from "@trigger.dev/platform";
3133
import {
3234
createPrivateLink,
3335
getPrivateLinkRegions,
@@ -69,7 +71,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
6971

7072
const [error, regions] = await tryCatch(getPrivateLinkRegions(organization.id));
7173

72-
const awsAccountIds = process.env.PRIVATE_CONNECTIONS_AWS_ACCOUNT_IDS?.split(",").filter(Boolean) ?? [];
74+
const awsAccountIds = env.PRIVATE_CONNECTIONS_AWS_ACCOUNT_IDS?.split(",").filter(Boolean) ?? [];
7375

7476
return typedjson({
7577
availableRegions: regions?.availableRegions ?? ["us-east-1", "eu-central-1"],
@@ -128,7 +130,10 @@ export const action: ActionFunction = async ({ request, params }) => {
128130
}
129131

130132
const [error] = await tryCatch(
131-
createPrivateLink(organization.id, { ...rest, targetRegion: selectedRegion })
133+
createPrivateLink(organization.id, {
134+
...rest,
135+
targetRegion: selectedRegion as CreatePrivateLinkConnectionBody["targetRegion"],
136+
})
132137
);
133138

134139
if (error) {

apps/webapp/app/services/platform.v3.server.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -667,18 +667,18 @@ export async function createPrivateLink(
667667
organizationId: string,
668668
body: CreatePrivateLinkConnectionBody
669669
): Promise<PrivateLinkConnection | undefined> {
670-
if (!client) return undefined;
670+
if (!client) throw new Error("Platform client not configured");
671671

672672
const [error, result] = await tryCatch(client.createPrivateLink(organizationId, body));
673673

674674
if (error) {
675675
logger.error("Error creating private link", { organizationId, error });
676-
return undefined;
676+
throw error;
677677
}
678678

679679
if (!result.success) {
680680
logger.error("Error creating private link - no success", { organizationId, error: result.error });
681-
return undefined;
681+
throw new Error(result.error ?? "Failed to create private link");
682682
}
683683

684684
return result;
@@ -688,18 +688,18 @@ export async function deletePrivateLink(
688688
organizationId: string,
689689
connectionId: string
690690
): Promise<void> {
691-
if (!client) return;
691+
if (!client) throw new Error("Platform client not configured");
692692

693693
const [error, result] = await tryCatch(client.deletePrivateLink(organizationId, connectionId));
694694

695695
if (error) {
696696
logger.error("Error deleting private link", { organizationId, connectionId, error });
697-
return;
697+
throw error;
698698
}
699699

700700
if (!result.success) {
701701
logger.error("Error deleting private link - no success", { organizationId, connectionId, error: result.error });
702-
return;
702+
throw new Error(result.error ?? "Failed to delete private link");
703703
}
704704
}
705705

0 commit comments

Comments
 (0)