Skip to content

Commit

Permalink
Add isManagedCloud feature, remove sentry, and require custom oauth a…
Browse files Browse the repository at this point in the history
…pp on self-hosting
  • Loading branch information
ericallam committed Jun 22, 2023
1 parent 8184c21 commit 40ffde3
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 251 deletions.
11 changes: 8 additions & 3 deletions apps/webapp/app/components/integrations/ConnectToOAuthForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Label } from "../primitives/Label";
import { NamedIcon } from "../primitives/NamedIcon";
import { Paragraph } from "../primitives/Paragraph";
import type { ConnectionType } from "@trigger.dev/database";
import { useFeatures } from "~/hooks/useFeatures";

export type Status = "loading" | "idle";

Expand All @@ -45,6 +46,8 @@ export function ConnectToOAuthForm({
const [id] = useState<string>(cuid());
const transition = useNavigation();
const fetcher = useFetcher();
const { isManagedCloud } = useFeatures();

const [
form,
{ title, scopes, hasCustomClient, customClientId, customClientSecret },
Expand All @@ -66,7 +69,9 @@ export function ConnectToOAuthForm({
)
);

const [useMyOAuthApp, setUseMyOAuthApp] = useState(clientType === "EXTERNAL");
const requiresCustomOAuthApp = clientType === "EXTERNAL" || !isManagedCloud;

const [useMyOAuthApp, setUseMyOAuthApp] = useState(requiresCustomOAuthApp);

const { filterText, setFilterText, filteredItems } = useTextFilter<Scope>({
items: authMethod.scopes,
Expand Down Expand Up @@ -126,10 +131,10 @@ export function ConnectToOAuthForm({
id="hasCustomClient"
label="Use my OAuth App"
variant="simple/small"
defaultChecked={clientType === "EXTERNAL" ? true : useMyOAuthApp}
disabled={clientType === "EXTERNAL"}
disabled={requiresCustomOAuthApp}
onChange={(checked) => setUseMyOAuthApp(checked)}
{...conform.input(hasCustomClient, { type: "checkbox" })}
defaultChecked={requiresCustomOAuthApp}
/>
{useMyOAuthApp && (
<div className="ml-6 mt-2">
Expand Down
23 changes: 0 additions & 23 deletions apps/webapp/app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { RemixBrowser, useLocation, useMatches } from "@remix-run/react";
import { hydrateRoot } from "react-dom/client";
import * as Sentry from "@sentry/remix";
import { useEffect } from "react";
import posthog from "posthog-js";
import { LocaleContextProvider } from "./components/primitives/LocaleProvider";
Expand All @@ -16,25 +15,3 @@ hydrateRoot(
</LocaleContextProvider>
</OperatingSystemContextProvider>
);

if (process.env.NODE_ENV === "production") {
Sentry.init({
dsn: "https://bf96820b08004fa4b2e1506f2ac74a14@o4504419574087680.ingest.sentry.io/4504419607052288",
tracesSampleRate: 1,
integrations: [
new Sentry.BrowserTracing({
routingInstrumentation: Sentry.remixRouterInstrumentation(
useEffect,
useLocation,
useMatches
),
}),
//casted because TypeScript is unhappy about the type from PostHog
new posthog.SentryIntegration(
posthog,
"triggerdev",
4504419607052288
) as any,
],
});
}
2 changes: 0 additions & 2 deletions apps/webapp/app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as Sentry from "~/services/sentry.server";
import * as Worker from "~/services/worker.server";
import { PassThrough } from "stream";
import { renderToPipeableStream } from "react-dom/server";
Expand Down Expand Up @@ -144,5 +143,4 @@ function serveBrowsers(
});
}

Sentry.init();
Worker.init().catch(console.error);
1 change: 0 additions & 1 deletion apps/webapp/app/env.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const EnvironmentSchema = z.object({
.string()
// eslint-disable-next-line turbo/no-undeclared-env-vars
.default(process.env.FC_URL ?? "https://app.trigger.dev"),
SENTRY_DSN: z.string().optional(),
APP_ENV: z
.union([
z.literal("development"),
Expand Down
18 changes: 18 additions & 0 deletions apps/webapp/app/features.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { requestUrl } from "./utils";

export type TriggerFeatures = {
isManagedCloud: boolean;
};

// If the request host is cloud.trigger.dev then we are on the managed cloud
// or if env.NODE_ENV is development
export function featuresForRequest(request: Request): TriggerFeatures {
const url = requestUrl(request);

const isManagedCloud =
url.host === "cloud.trigger.dev" || process.env.NODE_ENV === "development";

return {
isManagedCloud,
};
}
9 changes: 9 additions & 0 deletions apps/webapp/app/hooks/useFeatures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useTypedRouteLoaderData } from "remix-typedjson";
import { loader } from "../root";
import type { TriggerFeatures } from "~/features.server";

export function useFeatures(): TriggerFeatures {
const routeMatch = useTypedRouteLoaderData<typeof loader>("root");

return routeMatch?.features ?? { isManagedCloud: false };
}
1 change: 1 addition & 0 deletions apps/webapp/app/hooks/usePostHog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const usePostHog = (apiKey?: string, logging = false): void => {
//start PostHog once
useEffect(() => {
if (apiKey === undefined) return;
if (apiKey === "") return;
if (postHogInitialized.current === true) return;
if (logging) console.log("posthog.init", apiKey);
postHogInitialized.current = true;
Expand Down
6 changes: 4 additions & 2 deletions apps/webapp/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
isRouteErrorResponse,
useRouteError,
} from "@remix-run/react";
import { withSentry } from "@sentry/remix";
import { typedjson, useTypedLoaderData } from "remix-typedjson";
import type { ToastMessage } from "~/models/message.server";
import { commitSession, getSession } from "~/models/message.server";
Expand All @@ -26,6 +25,7 @@ import { env } from "./env.server";
import { usePostHog } from "./hooks/usePostHog";
import { getUser } from "./services/session.server";
import { friendlyErrorDisplay } from "./utils/httpErrors";
import { featuresForRequest } from "./features.server";

export const links: LinksFunction = () => {
return [{ rel: "stylesheet", href: tailwindStylesheetUrl }];
Expand All @@ -41,12 +41,14 @@ export const loader = async ({ request }: LoaderArgs) => {
const session = await getSession(request.headers.get("cookie"));
const toastMessage = session.get("toastMessage") as ToastMessage;
const posthogProjectKey = env.POSTHOG_PROJECT_KEY;
const features = featuresForRequest(request);

return typedjson(
{
user: await getUser(request),
toastMessage,
posthogProjectKey,
features,
},
{ headers: { "Set-Cookie": await commitSession(session) } }
);
Expand Down Expand Up @@ -128,4 +130,4 @@ function App() {
);
}

export default withSentry(App);
export default App;
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export const airtable: Integration = {
type: "oauth2",
client: {
id: {
envName: "EXTERNAL_AIRTABLE_CLIENT_ID",
envName: "CLOUD_AIRTABLE_CLIENT_ID",
},
secret: {
envName: "EXTERNAL_AIRTABLE_CLIENT_SECRET",
envName: "CLOUD_AIRTABLE_CLIENT_SECRET",
},
},
config: {
Expand Down
4 changes: 2 additions & 2 deletions apps/webapp/app/services/externalApis/integrations/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export const github: Integration = {
type: "oauth2",
client: {
id: {
envName: "EXTERNAL_GITHUB_CLIENT_ID",
envName: "CLOUD_GITHUB_CLIENT_ID",
},
secret: {
envName: "EXTERNAL_GITHUB_CLIENT_SECRET",
envName: "CLOUD_GITHUB_CLIENT_SECRET",
},
},
config: {
Expand Down
6 changes: 3 additions & 3 deletions apps/webapp/app/services/externalApis/integrations/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export const slack: Integration = {
type: "oauth2",
client: {
id: {
envName: "EXTERNAL_SLACK_CLIENT_ID",
envName: "CLOUD_SLACK_CLIENT_ID",
},
secret: {
envName: "EXTERNAL_SLACK_CLIENT_SECRET",
envName: "CLOUD_SLACK_CLIENT_SECRET",
},
},
config: {
Expand All @@ -31,7 +31,7 @@ export const slack: Integration = {
refresh: {
url: "https://slack.com/api/oauth.v2.access",
},
appHostEnvName: "EXTERNAL_SLACK_APP_HOST",
appHostEnvName: "CLOUD_SLACK_APP_HOST",
},
scopes: [
{
Expand Down
30 changes: 0 additions & 30 deletions apps/webapp/app/services/sentry.server.ts

This file was deleted.

2 changes: 0 additions & 2 deletions apps/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"typecheck": "tsc -b",
"db:seed": "ts-node prisma/seed.ts",
"generate:sourcemaps": "remix build --sourcemap",
"sentry-upload": "pnpm run generate:sourcemaps && sentry-upload-sourcemaps",
"clean:sourcemaps": "run-s clean:sourcemaps:*",
"clean:sourcemaps:public": "rimraf ./build/**/*.map",
"clean:sourcemaps:build": "rimraf ./public/build/**/*.map",
Expand Down Expand Up @@ -68,7 +67,6 @@
"@remix-run/react": "1.16.1",
"@remix-run/serve": "^1.16.1",
"@remix-run/server-runtime": "1.16.1",
"@sentry/remix": "^7.53.1",
"@tanstack/react-table": "^8.0.0-alpha.87",
"@team-plain/typescript-sdk": "^2.2.0",
"@trigger.dev/companyicons": "^1.5.8",
Expand Down
8 changes: 1 addition & 7 deletions apps/webapp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ import path from "path";
import express from "express";
import compression from "compression";
import morgan from "morgan";
import { createRequestHandler as expressCreateRequestHandler } from "@remix-run/express";
import { wrapExpressCreateRequestHandler } from "@sentry/remix";

const createRequestHandler =
process.env.NODE_ENV === "production"
? wrapExpressCreateRequestHandler(expressCreateRequestHandler)
: expressCreateRequestHandler;
import { createRequestHandler } from "@remix-run/express";

const app = express();

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"changeset:release": "pnpm run build --filter \"@trigger.dev/*\" && changeset publish",
"changeset:next": "changeset pre enter next",
"changeset:normal": "changeset pre exit",
"sentry-upload": "turbo run sentry-upload",
"clean:sourcemaps": "turbo run clean:sourcemaps",
"storybook": "turbo run storybook"
},
Expand Down

0 comments on commit 40ffde3

Please sign in to comment.