Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/cloud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@effect-atom/atom-react": "^0.5.0",
"@effect/platform": "catalog:",
"@executor/api": "workspace:*",
"@executor/env": "workspace:*",
"@executor/execution": "workspace:*",
"@executor/plugin-google-discovery": "workspace:*",
"@executor/plugin-graphql": "workspace:*",
Expand Down
5 changes: 3 additions & 2 deletions apps/cloud/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { CloudAuthHandlers, CloudAuthPublicHandlers } from "./auth/handlers";
import { WorkOSAuth } from "./auth/workos";
import { DbService } from "./services/db";
import { createTeamExecutor } from "./services/executor";
import { server } from "./env";

const ProtectedCloudApi = addGroup(OpenApiGroup)
.add(McpGroup)
Expand Down Expand Up @@ -104,7 +105,7 @@ const COOKIE_OPTIONS = {
httpOnly: true,
sameSite: "lax" as const,
maxAge: 60 * 60 * 24 * 7,
secure: process.env.NODE_ENV === "production",
secure: server.NODE_ENV === "production",
};

const resolveAuth = (request: Request) =>
Expand Down Expand Up @@ -151,7 +152,7 @@ const resolveExecutor = (teamId: string) =>
const users = yield* UserStoreService;
const team = yield* users.use((store) => store.getTeam(teamId));
const teamName = team?.name ?? "Unknown Team";
const encryptionKey = process.env.ENCRYPTION_KEY ?? "local-dev-encryption-key";
const encryptionKey = server.ENCRYPTION_KEY;
return yield* createTeamExecutor(teamId, teamName, encryptionKey);
});

Expand Down
3 changes: 2 additions & 1 deletion apps/cloud/src/auth/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { addGroup } from "@executor/api";
import { AUTH_PATHS, CloudAuthApi, CloudAuthPublicApi } from "./api";
import { AuthContext, UserStoreService } from "./context";
import { WorkOSAuth } from "./workos";
import { server } from "../env";

const COOKIE_OPTIONS = {
path: "/",
httpOnly: true,
sameSite: "lax" as const,
maxAge: 60 * 60 * 24 * 7,
secure: process.env.NODE_ENV === "production",
secure: server.NODE_ENV === "production",
};

// ---------------------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions apps/cloud/src/auth/workos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { Context, Effect, Layer } from "effect";
import { WorkOS } from "@workos-inc/node";
import { WorkOSError } from "./errors";
import { server } from "../env";

const COOKIE_NAME = "wos-session";

Expand All @@ -14,9 +15,9 @@ const COOKIE_NAME = "wos-session";


const make = Effect.gen(function* () {
const apiKey = process.env.WORKOS_API_KEY!;
const clientId = process.env.WORKOS_CLIENT_ID!;
const cookiePassword = process.env.WORKOS_COOKIE_PASSWORD!;
const apiKey = server.WORKOS_API_KEY;
const clientId = server.WORKOS_CLIENT_ID;
const cookiePassword = server.WORKOS_COOKIE_PASSWORD;

if (!cookiePassword || cookiePassword.length < 32) {
return yield* Effect.die(new Error("WORKOS_COOKIE_PASSWORD must be at least 32 characters"));
Expand Down
55 changes: 55 additions & 0 deletions apps/cloud/src/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { createEnv, Env } from "@executor/env";

const sharedShape = {
NODE_ENV: Env.literalOr(
"NODE_ENV",
"development",
"development",
"test",
"production",
),
};

const serverShape = {
DATABASE_URL: Env.stringOr("DATABASE_URL", ""),
PGLITE_DATA_DIR: Env.stringOr("PGLITE_DATA_DIR", ".pglite"),
ENCRYPTION_KEY: Env.stringOr(
"ENCRYPTION_KEY",
"local-dev-encryption-key",
),
WORKOS_API_KEY: Env.string("WORKOS_API_KEY"),
WORKOS_CLIENT_ID: Env.string("WORKOS_CLIENT_ID"),
WORKOS_COOKIE_PASSWORD: Env.string("WORKOS_COOKIE_PASSWORD"),
};

type SharedEnv = Readonly<{
NODE_ENV: "development" | "test" | "production";
}>;

type ServerEnv = SharedEnv & Readonly<{
DATABASE_URL: string;
PGLITE_DATA_DIR: string;
ENCRYPTION_KEY: string;
WORKOS_API_KEY: string;
WORKOS_CLIENT_ID: string;
WORKOS_COOKIE_PASSWORD: string;
}>;

type WebEnv = Readonly<Record<string, never>>;

export const shared = createEnv(sharedShape, {
runtimeEnv: process.env,
emptyStringAsUndefined: true,
}) as SharedEnv;

export const web = createEnv({}, {
prefix: "PUBLIC_",
runtimeEnv: process.env,
emptyStringAsUndefined: true,
}) as WebEnv;

export const server = createEnv(serverShape, {
extends: [shared],
runtimeEnv: process.env,
emptyStringAsUndefined: true,
}) as ServerEnv;
7 changes: 4 additions & 3 deletions apps/cloud/src/services/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { resolve } from "node:path";
import * as sharedSchema from "@executor/storage-postgres/schema";
import * as cloudSchema from "./schema";
import type { DrizzleDb } from "@executor/storage-postgres";
import { server } from "../env";

const schema = { ...sharedSchema, ...cloudSchema };

Expand All @@ -23,11 +24,11 @@ type DbResource = {
};

const createDbResource = async (): Promise<DbResource> => {
if (process.env.DATABASE_URL) {
if (server.DATABASE_URL) {
const { drizzle } = await import("drizzle-orm/node-postgres");
const { migrate } = await import("drizzle-orm/node-postgres/migrator");
const { Pool } = await import("pg");
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const pool = new Pool({ connectionString: server.DATABASE_URL });
const db = drizzle(pool, { schema }) as DrizzleDb;
await migrate(db as any, { migrationsFolder: MIGRATIONS_DIR });
return {
Expand All @@ -39,7 +40,7 @@ const createDbResource = async (): Promise<DbResource> => {
const { PGlite } = await import("@electric-sql/pglite");
const { drizzle } = await import("drizzle-orm/pglite");
const { migrate } = await import("drizzle-orm/pglite/migrator");
const dataDir = process.env.PGLITE_DATA_DIR ?? ".pglite";
const dataDir = server.PGLITE_DATA_DIR;
const client = new PGlite(dataDir);
const db = drizzle(client, { schema }) as DrizzleDb;
await migrate(db, { migrationsFolder: MIGRATIONS_DIR });
Expand Down
7 changes: 4 additions & 3 deletions apps/cloud/src/web/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ type AuthTeam = {
// Auth atom — typed query against CloudAuthApi
// ---------------------------------------------------------------------------

export const authAtom = CloudApiClient.query("cloudAuth", "me", {
timeToLive: "5 minutes",
});
export const authAtom =
CloudApiClient.query("cloudAuth", "me", {
timeToLive: "5 minutes",
});

// ---------------------------------------------------------------------------
// Provider + hook
Expand Down
4 changes: 2 additions & 2 deletions apps/cloud/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"skipLibCheck": true,
"outDir": "dist",
"rootDir": ".",
"declaration": true,
"declarationMap": true,
"declaration": false,
"declarationMap": false,
"sourceMap": true,
"jsx": "react-jsx",
"plugins": [
Expand Down
16 changes: 15 additions & 1 deletion apps/cloud/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@ import { defineConfig } from "vite";
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
import { createEnv, Env } from "@executor/env";

const server = {
PORT: Env.numberOr("PORT", 5173),
};

type ViteEnv = Readonly<{
PORT: number;
}>;

const viteEnv = createEnv(server, {
runtimeEnv: process.env,
emptyStringAsUndefined: true,
}) as ViteEnv;

export default defineConfig({
server: {
port: parseInt(process.env.PORT ?? "5173", 10),
port: viteEnv.PORT,
host: "127.0.0.1",
},
resolve: { tsconfigPaths: true },
Expand Down
1 change: 1 addition & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.