diff --git a/Makefile b/Makefile index 03a610e6..27d8d983 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,8 @@ clean: packages/db/dist \ packages/schemas/node_modules \ packages/schemas/dist \ + packages/crypto/node_modules \ + packages/crypto/dist \ .sourcebot .PHONY: bin diff --git a/packages/crypto/src/environment.ts b/packages/crypto/src/environment.ts index c1f72210..8efe296d 100644 --- a/packages/crypto/src/environment.ts +++ b/packages/crypto/src/environment.ts @@ -1,10 +1,6 @@ import dotenv from 'dotenv'; -export const getEnv = (env: string | undefined, defaultValue?: string, required?: boolean) => { - if (required && !env && !defaultValue) { - throw new Error(`Missing required environment variable`); - } - +export const getEnv = (env: string | undefined, defaultValue?: string) => { return env ?? defaultValue; } @@ -14,4 +10,4 @@ dotenv.config({ }); // @note: You can use https://generate-random.org/encryption-key-generator to create a new 32 byte key -export const SOURCEBOT_ENCRYPTION_KEY = getEnv(process.env.SOURCEBOT_ENCRYPTION_KEY, undefined, true)!; \ No newline at end of file +export const SOURCEBOT_ENCRYPTION_KEY = getEnv(process.env.SOURCEBOT_ENCRYPTION_KEY); \ No newline at end of file diff --git a/packages/crypto/src/index.ts b/packages/crypto/src/index.ts index fc63f764..f0128297 100644 --- a/packages/crypto/src/index.ts +++ b/packages/crypto/src/index.ts @@ -9,6 +9,10 @@ const generateIV = (): Buffer => { }; export function encrypt(text: string): { iv: string; encryptedData: string } { + if (!SOURCEBOT_ENCRYPTION_KEY) { + throw new Error('Encryption key is not set'); + } + const encryptionKey = Buffer.from(SOURCEBOT_ENCRYPTION_KEY, 'ascii'); const iv = generateIV(); @@ -21,6 +25,10 @@ export function encrypt(text: string): { iv: string; encryptedData: string } { } export function decrypt(iv: string, encryptedText: string): string { + if (!SOURCEBOT_ENCRYPTION_KEY) { + throw new Error('Encryption key is not set'); + } + const encryptionKey = Buffer.from(SOURCEBOT_ENCRYPTION_KEY, 'ascii'); const ivBuffer = Buffer.from(iv, 'hex'); diff --git a/packages/schemas/tools/generate.ts b/packages/schemas/tools/generate.ts index a5911e27..7ba1b467 100644 --- a/packages/schemas/tools/generate.ts +++ b/packages/schemas/tools/generate.ts @@ -6,20 +6,18 @@ import { glob } from "glob"; const BANNER_COMMENT = '// THIS IS A AUTO-GENERATED FILE. DO NOT MODIFY MANUALLY!\n'; -// const SCHEMAS: string[] = ["github.json", "shared.json"]; (async () => { const cwd = process.cwd(); const schemasBasePath = path.resolve(`${cwd}/../../schemas`); - const schemas = await glob(`${schemasBasePath}/**/*.json`) + const outDirRoot = path.resolve(`${cwd}/src`); + const schemas = await glob(`${schemasBasePath}/**/*.json`); await Promise.all(schemas.map(async (schemaPath) => { const name = path.parse(schemaPath).name; const version = path.basename(path.dirname(schemaPath)); - const outDir = path.join(cwd, `src/${version}`); + const outDir = path.join(outDirRoot, version); - // Clean output directory first - await rm(outDir, { recursive: true, force: true }); await mkdir(outDir, { recursive: true }); // Generate schema diff --git a/packages/web/src/app/[domain]/layout.tsx b/packages/web/src/app/[domain]/layout.tsx index 740a640d..8e2a2858 100644 --- a/packages/web/src/app/[domain]/layout.tsx +++ b/packages/web/src/app/[domain]/layout.tsx @@ -47,9 +47,7 @@ export default async function Layout({ if (isServiceError(subscription) || (subscription.status !== "active" && subscription.status !== "trialing")) { return (