From 9d618ead9db815b8761e6d16508501a07da32770 Mon Sep 17 00:00:00 2001 From: Mihovil Ilakovac Date: Fri, 25 Oct 2024 16:51:44 +0200 Subject: [PATCH 1/9] Zod env validation WIP Signed-off-by: Mihovil Ilakovac --- .../templates/sdk/wasp/client/env/index.ts | 11 ++++++++ .../Generator/templates/sdk/wasp/env/index.ts | 17 +++++++++++ .../Generator/templates/sdk/wasp/package.json | 2 ++ .../templates/sdk/wasp/server/env/index.ts | 19 +++++++++++++ waspc/examples/todoApp/package-lock.json | 11 +++++++- waspc/examples/todoApp/src/App.tsx | 1 + waspc/src/Wasp/Generator/SdkGenerator.hs | 5 +++- .../Generator/SdkGenerator/EnvValidation.hs | 28 +++++++++++++++++++ waspc/waspc.cabal | 1 + 9 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 waspc/data/Generator/templates/sdk/wasp/client/env/index.ts create mode 100644 waspc/data/Generator/templates/sdk/wasp/env/index.ts create mode 100644 waspc/data/Generator/templates/sdk/wasp/server/env/index.ts create mode 100644 waspc/src/Wasp/Generator/SdkGenerator/EnvValidation.hs diff --git a/waspc/data/Generator/templates/sdk/wasp/client/env/index.ts b/waspc/data/Generator/templates/sdk/wasp/client/env/index.ts new file mode 100644 index 0000000000..230223436a --- /dev/null +++ b/waspc/data/Generator/templates/sdk/wasp/client/env/index.ts @@ -0,0 +1,11 @@ +import * as z from 'zod' + +import { ensureEnvSchema } from '../../env/index.js' + +const serverEnvSchema = z.object({ + REACT_APP_API_URL: z.string({ + required_error: 'REACT_APP_API_URL is required', + }), +}) + +export const env = ensureEnvSchema(import.meta.env, serverEnvSchema) diff --git a/waspc/data/Generator/templates/sdk/wasp/env/index.ts b/waspc/data/Generator/templates/sdk/wasp/env/index.ts new file mode 100644 index 0000000000..82537e7a42 --- /dev/null +++ b/waspc/data/Generator/templates/sdk/wasp/env/index.ts @@ -0,0 +1,17 @@ +import * as z from 'zod' + +export function ensureEnvSchema( + data: unknown, + schema: Schema, +): z.infer { + try { + return schema.parse(data) + } catch (e) { + // TODO: figure out how to output the error message in a better way + if (e instanceof z.ZodError) { + throw new Error(e.errors.map((error) => error.message).join('\n')) + } else { + throw e + } + } +} diff --git a/waspc/data/Generator/templates/sdk/wasp/package.json b/waspc/data/Generator/templates/sdk/wasp/package.json index 5995a7e777..366c12a8f5 100644 --- a/waspc/data/Generator/templates/sdk/wasp/package.json +++ b/waspc/data/Generator/templates/sdk/wasp/package.json @@ -109,6 +109,8 @@ "./client/test": "./dist/client/test/index.js", "./client": "./dist/client/index.js", "./dev": "./dist/dev/index.js", + "./client/env": "./dist/client/env/index.js", + "./server/env": "./dist/server/env/index.js", {=! todo(filip): Fixes below are for type errors in 0.13.1, remove ASAP =} {=! Used by our code (SDK for full-stack type safety), uncodumented (but accessible) for users. =} diff --git a/waspc/data/Generator/templates/sdk/wasp/server/env/index.ts b/waspc/data/Generator/templates/sdk/wasp/server/env/index.ts new file mode 100644 index 0000000000..345f77c5fa --- /dev/null +++ b/waspc/data/Generator/templates/sdk/wasp/server/env/index.ts @@ -0,0 +1,19 @@ +import * as z from 'zod' + +import { ensureEnvSchema } from '../../env/index.js' + +const serverEnvSchema = z.object({ + NODE_ENV: z.enum(['development', 'production']).default('development'), + PORT: z.coerce.number().default(3000), + SERVER_URL: z.string({ + required_error: 'SERVER_URL is required', + }), + CLIENT_URL: z.string({ + required_error: 'CLIENT_URL is required', + }), + JWT_SECRET: z.string({ + required_error: 'JWT_SECRET is required', + }), +}) + +export const env = ensureEnvSchema(process.env, serverEnvSchema) diff --git a/waspc/examples/todoApp/package-lock.json b/waspc/examples/todoApp/package-lock.json index 63d0da935f..1df4199aec 100644 --- a/waspc/examples/todoApp/package-lock.json +++ b/waspc/examples/todoApp/package-lock.json @@ -54,7 +54,8 @@ "socket.io-client": "^4.6.1", "superjson": "^2.2.1", "tailwindcss": "^3.2.7", - "vitest": "^1.2.1" + "vitest": "^1.2.1", + "zod": "^3.23.8" }, "devDependencies": { "@tsconfig/node18": "latest", @@ -9966,6 +9967,14 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zod": { + "version": "3.23.8", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", + "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } diff --git a/waspc/examples/todoApp/src/App.tsx b/waspc/examples/todoApp/src/App.tsx index e7f0fbb3b0..bacb1f1ca1 100644 --- a/waspc/examples/todoApp/src/App.tsx +++ b/waspc/examples/todoApp/src/App.tsx @@ -3,6 +3,7 @@ import { useSocket } from 'wasp/client/webSocket' import { Link } from 'wasp/client/router' import { logout, useAuth } from 'wasp/client/auth' import { useQuery, getDate } from 'wasp/client/operations' +import { env } from 'wasp/client/env' import './Main.css' import { getName } from './user' diff --git a/waspc/src/Wasp/Generator/SdkGenerator.hs b/waspc/src/Wasp/Generator/SdkGenerator.hs index f2c382d856..8646cef6d7 100644 --- a/waspc/src/Wasp/Generator/SdkGenerator.hs +++ b/waspc/src/Wasp/Generator/SdkGenerator.hs @@ -49,6 +49,7 @@ import qualified Wasp.Generator.SdkGenerator.Client.OperationsGenerator as Clien import Wasp.Generator.SdkGenerator.Client.RouterGenerator (genNewClientRouterApi) import qualified Wasp.Generator.SdkGenerator.Common as C import Wasp.Generator.SdkGenerator.CrudG (genCrud) +import Wasp.Generator.SdkGenerator.EnvValidation (depsRequiredByEnvValidation, genEnvValidation) import Wasp.Generator.SdkGenerator.Server.AuthG (genNewServerApi) import Wasp.Generator.SdkGenerator.Server.CrudG (genNewServerCrudApi) import Wasp.Generator.SdkGenerator.Server.EmailSenderG (depsRequiredByEmail, genNewEmailSenderApi) @@ -125,6 +126,7 @@ genSdk spec = <++> genNewEmailSenderApi spec <++> genNewJobsApi spec <++> genNewClientRouterApi spec + <++> genEnvValidation spec where genFileCopy = return . C.mkTmplFd @@ -217,7 +219,8 @@ npmDepsForSdk spec = -- These deps need to be installed in the SDK becasue when we run client tests, -- we are running them from the project root dir and PostCSS and Tailwind -- can't be resolved from WebApp node_modules, so we need to install them in the SDK. - ++ depsRequiredByTailwind spec, + ++ depsRequiredByTailwind spec + ++ depsRequiredByEnvValidation, N.devDependencies = AS.Dependency.fromList [ ("@tsconfig/node" <> majorNodeVersionStr, "latest"), diff --git a/waspc/src/Wasp/Generator/SdkGenerator/EnvValidation.hs b/waspc/src/Wasp/Generator/SdkGenerator/EnvValidation.hs new file mode 100644 index 0000000000..e4398bba6c --- /dev/null +++ b/waspc/src/Wasp/Generator/SdkGenerator/EnvValidation.hs @@ -0,0 +1,28 @@ +module Wasp.Generator.SdkGenerator.EnvValidation + ( genEnvValidation, + depsRequiredByEnvValidation, + ) +where + +import StrongPath (relfile) +import Wasp.AppSpec (AppSpec) +import qualified Wasp.AppSpec.App.Dependency as AS.Dependency +import Wasp.Generator.FileDraft (FileDraft) +import Wasp.Generator.Monad (Generator) +import qualified Wasp.Generator.SdkGenerator.Common as C + +genEnvValidation :: AppSpec -> Generator [FileDraft] +genEnvValidation _spec = + sequence + [ genFileCopy [relfile|env/index.ts|], + genFileCopy [relfile|client/env/index.ts|], + genFileCopy [relfile|server/env/index.ts|] + ] + where + genFileCopy = return . C.mkTmplFd + +depsRequiredByEnvValidation :: [AS.Dependency.Dependency] +depsRequiredByEnvValidation = + AS.Dependency.fromList + [ ("zod", "^3.23.8") + ] diff --git a/waspc/waspc.cabal b/waspc/waspc.cabal index 9fd3e69690..655c6f9180 100644 --- a/waspc/waspc.cabal +++ b/waspc/waspc.cabal @@ -317,6 +317,7 @@ library Wasp.Generator.SdkGenerator.Common Wasp.Generator.SdkGenerator.CrudG Wasp.Generator.SdkGenerator.EmailSender.Providers + Wasp.Generator.SdkGenerator.EnvValidation Wasp.Generator.SdkGenerator.Server.AuthG Wasp.Generator.SdkGenerator.Server.OAuthG Wasp.Generator.SdkGenerator.Server.CrudG From 7333b259af5827d814706e8ae288e225cc71ae60 Mon Sep 17 00:00:00 2001 From: Mihovil Ilakovac Date: Tue, 29 Oct 2024 14:59:50 +0100 Subject: [PATCH 2/9] Define env vars validation. Use validate env vars. --- waspc/data/Generator/templates/Dockerfile | 6 +- .../templates/sdk/wasp/client/config.ts | 3 +- .../templates/sdk/wasp/client/env.ts | 14 ++ .../templates/sdk/wasp/client/env/index.ts | 11 -- .../templates/sdk/wasp/client/index.ts | 3 + .../Generator/templates/sdk/wasp/env/index.ts | 33 +++-- .../Generator/templates/sdk/wasp/package.json | 2 - .../templates/sdk/wasp/prettier.config.js | 7 + .../sdk/wasp/server/auth/oauth/env.ts | 15 -- .../sdk/wasp/server/auth/oauth/provider.ts | 6 +- .../server/auth/oauth/providers/discord.ts | 18 +-- .../server/auth/oauth/providers/github.ts | 16 +-- .../server/auth/oauth/providers/google.ts | 18 +-- .../server/auth/oauth/providers/keycloak.ts | 18 +-- .../templates/sdk/wasp/server/config.ts | 50 +++---- .../templates/sdk/wasp/server/email/index.ts | 18 +-- .../templates/sdk/wasp/server/env.ts | 136 ++++++++++++++++++ .../templates/sdk/wasp/server/env/index.ts | 19 --- .../templates/sdk/wasp/server/index.ts | 2 + .../wasp/server/jobs/core/pgBoss/pgBoss.ts | 7 +- .../templates/sdk/wasp/universal/url.ts | 2 + .../Generator/templates/server/package.json | 3 +- .../templates/server/scripts/validate-env.mjs | 5 - .../server/src/auth/providers/config/email.ts | 3 +- .../src/auth/providers/oauth/cookies.ts | 10 +- waspc/examples/todoApp/src/App.tsx | 3 +- waspc/examples/todoApp/src/serverSetup.ts | 1 + waspc/src/Wasp/Generator/EmailSenders.hs | 23 +++ .../SdkGenerator/EmailSender/Providers.hs | 17 +-- .../Generator/SdkGenerator/EnvValidation.hs | 42 +++++- .../SdkGenerator/Server/EmailSenderG.hs | 21 ++- .../Generator/SdkGenerator/Server/OAuthG.hs | 1 - waspc/src/Wasp/Generator/ServerGenerator.hs | 7 - waspc/src/Wasp/Generator/WebAppGenerator.hs | 2 + waspc/waspc.cabal | 1 + 35 files changed, 333 insertions(+), 210 deletions(-) create mode 100644 waspc/data/Generator/templates/sdk/wasp/client/env.ts delete mode 100644 waspc/data/Generator/templates/sdk/wasp/client/env/index.ts create mode 100644 waspc/data/Generator/templates/sdk/wasp/prettier.config.js delete mode 100644 waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/env.ts create mode 100644 waspc/data/Generator/templates/sdk/wasp/server/env.ts delete mode 100644 waspc/data/Generator/templates/sdk/wasp/server/env/index.ts delete mode 100644 waspc/data/Generator/templates/server/scripts/validate-env.mjs create mode 100644 waspc/src/Wasp/Generator/EmailSenders.hs diff --git a/waspc/data/Generator/templates/Dockerfile b/waspc/data/Generator/templates/Dockerfile index f0713ce6db..d8e2d3d4a8 100644 --- a/waspc/data/Generator/templates/Dockerfile +++ b/waspc/data/Generator/templates/Dockerfile @@ -58,12 +58,12 @@ COPY --from=server-builder /app/node_modules ./node_modules # Copying the SDK because 'validate-env.mjs' executes independent of the bundle # and references the 'wasp' package. COPY --from=server-builder /app/.wasp/out/sdk .wasp/out/sdk -# Copying 'server/node_modules' because 'validate-env.mjs' executes independent -# of the bundle and references the dotenv package. +# Copying 'server/node_modules' because we require dotenv package to +# load environment variables +# TODO: replace dotenv with native Node.js environment variable loading COPY --from=server-builder /app/.wasp/build/server/node_modules .wasp/build/server/node_modules COPY --from=server-builder /app/.wasp/build/server/bundle .wasp/build/server/bundle COPY --from=server-builder /app/.wasp/build/server/package*.json .wasp/build/server/ -COPY --from=server-builder /app/.wasp/build/server/scripts .wasp/build/server/scripts COPY db/ .wasp/build/db/ EXPOSE ${PORT} WORKDIR /app/.wasp/build/server diff --git a/waspc/data/Generator/templates/sdk/wasp/client/config.ts b/waspc/data/Generator/templates/sdk/wasp/client/config.ts index 39b620af01..978755541d 100644 --- a/waspc/data/Generator/templates/sdk/wasp/client/config.ts +++ b/waspc/data/Generator/templates/sdk/wasp/client/config.ts @@ -1,7 +1,8 @@ {{={= =}=}} import { stripTrailingSlash } from '../universal/url.js' +import { env } from './env.js' -const apiUrl = stripTrailingSlash(import.meta.env.REACT_APP_API_URL) || '{= defaultServerUrl =}'; +const apiUrl = stripTrailingSlash(env.REACT_APP_API_URL) // PUBLIC API export type ClientConfig = { diff --git a/waspc/data/Generator/templates/sdk/wasp/client/env.ts b/waspc/data/Generator/templates/sdk/wasp/client/env.ts new file mode 100644 index 0000000000..0de23660f4 --- /dev/null +++ b/waspc/data/Generator/templates/sdk/wasp/client/env.ts @@ -0,0 +1,14 @@ +{{={= =}=}} +import * as z from 'zod' + +import { ensureEnvSchema } from '../env/index.js' + +const clientEnvSchema = z.object({ + REACT_APP_API_URL: z + .string({ + required_error: 'REACT_APP_API_URL is required', + }) + .default('{= defaultServerUrl =}') +}) + +export const env = ensureEnvSchema(import.meta.env, clientEnvSchema) diff --git a/waspc/data/Generator/templates/sdk/wasp/client/env/index.ts b/waspc/data/Generator/templates/sdk/wasp/client/env/index.ts deleted file mode 100644 index 230223436a..0000000000 --- a/waspc/data/Generator/templates/sdk/wasp/client/env/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -import * as z from 'zod' - -import { ensureEnvSchema } from '../../env/index.js' - -const serverEnvSchema = z.object({ - REACT_APP_API_URL: z.string({ - required_error: 'REACT_APP_API_URL is required', - }), -}) - -export const env = ensureEnvSchema(import.meta.env, serverEnvSchema) diff --git a/waspc/data/Generator/templates/sdk/wasp/client/index.ts b/waspc/data/Generator/templates/sdk/wasp/client/index.ts index cfce564c4d..33db447837 100644 --- a/waspc/data/Generator/templates/sdk/wasp/client/index.ts +++ b/waspc/data/Generator/templates/sdk/wasp/client/index.ts @@ -12,3 +12,6 @@ export type Route = { method: HttpMethod; path: string } // PUBLIC API export { config, ClientConfig } from './config' + +// PUBLIC API +export { env } from './env.js' diff --git a/waspc/data/Generator/templates/sdk/wasp/env/index.ts b/waspc/data/Generator/templates/sdk/wasp/env/index.ts index 82537e7a42..5295a47f1a 100644 --- a/waspc/data/Generator/templates/sdk/wasp/env/index.ts +++ b/waspc/data/Generator/templates/sdk/wasp/env/index.ts @@ -1,17 +1,28 @@ import * as z from 'zod' +const redColor = '\x1b[31m' + export function ensureEnvSchema( - data: unknown, - schema: Schema, + data: unknown, + schema: Schema ): z.infer { - try { - return schema.parse(data) - } catch (e) { + try { + return schema.parse(data) + } catch (e) { // TODO: figure out how to output the error message in a better way - if (e instanceof z.ZodError) { - throw new Error(e.errors.map((error) => error.message).join('\n')) - } else { - throw e - } - } + if (e instanceof z.ZodError) { + console.error(redColor, '╔═════════════════════════════╗'); + console.error(redColor, '║ Env vars validation failed ║'); + console.error(redColor, '╚═════════════════════════════╝'); + console.error() + for (const error of e.errors) { + console.error(`- ${error.message}`) + } + console.error() + console.error(redColor, '═══════════════════════════════'); + throw new Error('Error parsing environment variables') + } else { + throw e + } + } } diff --git a/waspc/data/Generator/templates/sdk/wasp/package.json b/waspc/data/Generator/templates/sdk/wasp/package.json index 366c12a8f5..5995a7e777 100644 --- a/waspc/data/Generator/templates/sdk/wasp/package.json +++ b/waspc/data/Generator/templates/sdk/wasp/package.json @@ -109,8 +109,6 @@ "./client/test": "./dist/client/test/index.js", "./client": "./dist/client/index.js", "./dev": "./dist/dev/index.js", - "./client/env": "./dist/client/env/index.js", - "./server/env": "./dist/server/env/index.js", {=! todo(filip): Fixes below are for type errors in 0.13.1, remove ASAP =} {=! Used by our code (SDK for full-stack type safety), uncodumented (but accessible) for users. =} diff --git a/waspc/data/Generator/templates/sdk/wasp/prettier.config.js b/waspc/data/Generator/templates/sdk/wasp/prettier.config.js new file mode 100644 index 0000000000..38597ed8a0 --- /dev/null +++ b/waspc/data/Generator/templates/sdk/wasp/prettier.config.js @@ -0,0 +1,7 @@ +// Used for internal Wasp development only, not copied to generated app. +module.exports = { + trailingComma: 'es5', + tabWidth: 2, + semi: false, + singleQuote: true, +} diff --git a/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/env.ts b/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/env.ts deleted file mode 100644 index ada2452b8e..0000000000 --- a/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/env.ts +++ /dev/null @@ -1,15 +0,0 @@ -// PRIVATE API (SDK) -export function ensureEnvVarsForProvider( - envVarNames: EnvVarName[], - providerName: string, -): Record { - const result: Record = {}; - for (const envVarName of envVarNames) { - const value = process.env[envVarName]; - if (!value) { - throw new Error(`${envVarName} env variable is required when using the ${providerName} auth provider.`); - } - result[envVarName] = value; - } - return result as Record; -} diff --git a/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/provider.ts b/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/provider.ts index c2aee70897..c02e5adbee 100644 --- a/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/provider.ts +++ b/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/provider.ts @@ -1,23 +1,19 @@ import { OAuth2Provider, OAuth2ProviderWithPKCE } from "arctic"; export function defineProvider< - OAuthClient extends OAuth2Provider | OAuth2ProviderWithPKCE, - Env extends Record + OAuthClient extends OAuth2Provider | OAuth2ProviderWithPKCE >({ id, displayName, - env, oAuthClient, }: { id: string; displayName: string; - env: Env; oAuthClient: OAuthClient; }) { return { id, displayName, - env, oAuthClient, }; } diff --git a/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/discord.ts b/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/discord.ts index 52e396f7a6..f8799170ca 100644 --- a/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/discord.ts +++ b/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/discord.ts @@ -1,17 +1,12 @@ {{={= =}=}} -import { Discord } from "arctic"; +import { Discord } from 'arctic'; -import { defineProvider } from "../provider.js"; -import { ensureEnvVarsForProvider } from "../env.js"; -import { getRedirectUriForCallback } from "../redirect.js"; +import { defineProvider } from '../provider.js'; +import { getRedirectUriForCallback } from '../redirect.js'; +import { env } from '../../../env.js'; -const id = "{= providerId =}"; -const displayName = "{= displayName =}"; - -const env = ensureEnvVarsForProvider( - ["DISCORD_CLIENT_ID", "DISCORD_CLIENT_SECRET"], - displayName -); +const id = '{= providerId =}'; +const displayName = '{= displayName =}'; const oAuthClient = new Discord( env.DISCORD_CLIENT_ID, @@ -23,6 +18,5 @@ const oAuthClient = new Discord( export const discord = defineProvider({ id, displayName, - env, oAuthClient, }); diff --git a/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/github.ts b/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/github.ts index e9c5019c37..604946dce5 100644 --- a/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/github.ts +++ b/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/github.ts @@ -1,16 +1,11 @@ {{={= =}=}} -import { GitHub } from "arctic"; +import { GitHub } from 'arctic'; -import { ensureEnvVarsForProvider } from "../env.js"; -import { defineProvider } from "../provider.js"; +import { defineProvider } from '../provider.js'; +import { env } from '../../../env.js'; -const id = "{= providerId =}"; -const displayName = "{= displayName =}"; - -const env = ensureEnvVarsForProvider( - ["GITHUB_CLIENT_ID", "GITHUB_CLIENT_SECRET"], - displayName -); +const id = '{= providerId =}'; +const displayName = '{= displayName =}'; const oAuthClient = new GitHub( env.GITHUB_CLIENT_ID, @@ -21,6 +16,5 @@ const oAuthClient = new GitHub( export const github = defineProvider({ id, displayName, - env, oAuthClient, }); diff --git a/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/google.ts b/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/google.ts index cf157ae12b..4fc8ceaa47 100644 --- a/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/google.ts +++ b/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/google.ts @@ -1,17 +1,12 @@ {{={= =}=}} -import { Google } from "arctic"; +import { Google } from 'arctic'; -import { ensureEnvVarsForProvider } from "../env.js"; -import { getRedirectUriForCallback } from "../redirect.js"; -import { defineProvider } from "../provider.js"; +import { getRedirectUriForCallback } from '../redirect.js'; +import { defineProvider } from '../provider.js'; +import { env } from '../../../env.js'; -const id = "{= providerId =}"; -const displayName = "{= displayName =}"; - -const env = ensureEnvVarsForProvider( - ["GOOGLE_CLIENT_ID", "GOOGLE_CLIENT_SECRET"], - displayName, -); +const id = '{= providerId =}'; +const displayName = '{= displayName =}'; const oAuthClient = new Google( env.GOOGLE_CLIENT_ID, @@ -23,6 +18,5 @@ const oAuthClient = new Google( export const google = defineProvider({ id, displayName, - env, oAuthClient, }); diff --git a/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/keycloak.ts b/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/keycloak.ts index 93136732d9..003d5aba62 100644 --- a/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/keycloak.ts +++ b/waspc/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/keycloak.ts @@ -1,17 +1,12 @@ {{={= =}=}} -import { Keycloak } from "arctic"; +import { Keycloak } from 'arctic'; -import { ensureEnvVarsForProvider } from "../env.js"; -import { getRedirectUriForCallback } from "../redirect.js"; -import { defineProvider } from "../provider.js"; +import { getRedirectUriForCallback } from '../redirect.js'; +import { defineProvider } from '../provider.js'; +import { env } from '../../../env.js'; -const id = "{= providerId =}"; -const displayName = "{= displayName =}"; - -const env = ensureEnvVarsForProvider( - ["KEYCLOAK_REALM_URL", "KEYCLOAK_CLIENT_ID", "KEYCLOAK_CLIENT_SECRET"], - displayName, -); +const id = '{= providerId =}'; +const displayName = '{= displayName =}'; const oAuthClient = new Keycloak( env.KEYCLOAK_REALM_URL, @@ -24,6 +19,5 @@ const oAuthClient = new Keycloak( export const keycloak = defineProvider({ id, displayName, - env, oAuthClient, }); diff --git a/waspc/data/Generator/templates/sdk/wasp/server/config.ts b/waspc/data/Generator/templates/sdk/wasp/server/config.ts index 01f9622c08..e87ed1a9fb 100644 --- a/waspc/data/Generator/templates/sdk/wasp/server/config.ts +++ b/waspc/data/Generator/templates/sdk/wasp/server/config.ts @@ -1,9 +1,8 @@ {{={= =}=}} import merge from 'lodash.merge' -import { stripTrailingSlash } from "../universal/url.js"; - -const nodeEnv = process.env.NODE_ENV ?? 'development' +import { env } from './env.js' +import { stripTrailingSlash } from '../universal/url.js' // TODO: // - Use dotenv library to consume env vars from a file. @@ -12,11 +11,6 @@ const nodeEnv = process.env.NODE_ENV ?? 'development' type BaseConfig = { allowedCORSOrigins: string | string[]; - {=# isAuthEnabled =} - auth: { - jwtSecret: string | undefined; - } - {=/ isAuthEnabled =} } type CommonConfig = BaseConfig & { @@ -24,6 +18,11 @@ type CommonConfig = BaseConfig & { isDevelopment: boolean; port: number; databaseUrl: string | undefined; + {=# isAuthEnabled =} + auth: { + jwtSecret: string | undefined; + } + {=/ isAuthEnabled =} } type EnvConfig = BaseConfig & { @@ -39,14 +38,14 @@ const config: { production: EnvConfig, } = { all: { - env: nodeEnv, - isDevelopment: nodeEnv === 'development', - port: process.env.PORT ? parseInt(process.env.PORT) : {= defaultServerPort =}, - databaseUrl: process.env.{= databaseUrlEnvVarName =}, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.{= databaseUrlEnvVarName =}, allowedCORSOrigins: [], {=# isAuthEnabled =} auth: { - jwtSecret: undefined + jwtSecret: env.JWT_SECRET } {=/ isAuthEnabled =} }, @@ -54,41 +53,26 @@ const config: { production: getProductionConfig(), } -const resolvedConfig: Config = merge(config.all, config[nodeEnv]) +const resolvedConfig: Config = merge(config.all, config[env.NODE_ENV]) // PUBLIC API export default resolvedConfig function getDevelopmentConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL ?? '{= defaultClientUrl =}'); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL ?? '{= defaultServerUrl =}'); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, allowedCORSOrigins: '*', - {=# isAuthEnabled =} - auth: { - jwtSecret: 'DEVJWTSECRET' - } - {=/ isAuthEnabled =} } } function getProductionConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, - // @ts-ignore allowedCORSOrigins: [frontendUrl], - {=# isAuthEnabled =} - auth: { - jwtSecret: process.env.JWT_SECRET - } - {=/ isAuthEnabled =} } } diff --git a/waspc/data/Generator/templates/sdk/wasp/server/email/index.ts b/waspc/data/Generator/templates/sdk/wasp/server/email/index.ts index 4a0c9377db..7417cfc90b 100644 --- a/waspc/data/Generator/templates/sdk/wasp/server/email/index.ts +++ b/waspc/data/Generator/templates/sdk/wasp/server/email/index.ts @@ -1,4 +1,5 @@ {{={= =}=}} +import { env } from '../env.js'; import { initEmailSender } from "./core/index.js"; import { EmailSender } from "./core/types.js"; @@ -7,25 +8,24 @@ import { EmailSender } from "./core/types.js"; {=# isSmtpProviderUsed =} const emailProvider = { type: "smtp", - host: process.env.SMTP_HOST!, - // @ts-ignore - port: parseInt(process.env.SMTP_PORT, 10), - username: process.env.SMTP_USERNAME!, - password: process.env.SMTP_PASSWORD!, + host: env.SMTP_HOST, + port: env.SMTP_PORT, + username: env.SMTP_USERNAME, + password: env.SMTP_PASSWORD, } as const; {=/ isSmtpProviderUsed =} {=# isSendGridProviderUsed =} const emailProvider = { type: "sendgrid", - apiKey: process.env.SENDGRID_API_KEY!, + apiKey: env.SENDGRID_API_KEY, } as const; {=/ isSendGridProviderUsed =} {=# isMailgunProviderUsed =} const emailProvider = { type: "mailgun", - apiKey: process.env.MAILGUN_API_KEY!, - domain: process.env.MAILGUN_DOMAIN!, - apiUrl: process.env.MAILGUN_API_URL!, + apiKey: env.MAILGUN_API_KEY, + domain: env.MAILGUN_DOMAIN, + apiUrl: env.MAILGUN_API_URL, } as const; {=/ isMailgunProviderUsed =} {=# isDummyProviderUsed =} diff --git a/waspc/data/Generator/templates/sdk/wasp/server/env.ts b/waspc/data/Generator/templates/sdk/wasp/server/env.ts new file mode 100644 index 0000000000..f7d37879cd --- /dev/null +++ b/waspc/data/Generator/templates/sdk/wasp/server/env.ts @@ -0,0 +1,136 @@ +{{={= =}=}} +import * as z from 'zod' + +import { ensureEnvSchema } from '../env/index.js' + +const serverCommonSchema = z.object({ + PORT: z.coerce.number().default({= defaultServerPort =}), + {= databaseUrlEnvVarName =}: z.string({ + required_error: '{= databaseUrlEnvVarName =} is required', + }), + PG_BOSS_NEW_OPTIONS: z.string().optional(), + {=# isEmailSenderUsed =} + {=# enabledEmailSenders.isSmtpProviderUsed =} + SMTP_HOST: z.string({ + required_error: 'SMTP_HOST is required', + }), + SMTP_PORT: z.coerce.number({ + required_error: 'SMTP_PORT is required', + invalid_type_error: 'SMTP_PORT must be a number', + }), + SMTP_USERNAME: z.string({ + required_error: 'SMTP_USERNAME is required', + }), + SMTP_PASSWORD: z.string({ + required_error: 'SMTP_PASSWORD is required', + }), + {=/ enabledEmailSenders.isSmtpProviderUsed =} + {=# enabledEmailSenders.isSendGridProviderUsed =} + SENDGRID_API_KEY: z.string({ + required_error: 'SENDGRID_API_KEY is required', + }), + {=/ enabledEmailSenders.isSendGridProviderUsed =} + {=# enabledEmailSenders.isMailgunProviderUsed =} + MAILGUN_API_KEY: z.string({ + required_error: 'MAILGUN_API_KEY is required', + }), + MAILGUN_DOMAIN: z.string({ + required_error: 'MAILGUN_DOMAIN is required', + }), + MAILGUN_API_URL: z.string().optional(), + {=/ enabledEmailSenders.isMailgunProviderUsed =} + {=/ isEmailSenderUsed =} + SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), + {=# isAuthEnabled =} + {=# enabledAuthProviders.isGoogleAuthEnabled =} + GOOGLE_CLIENT_ID: z.string({ + required_error: 'GOOGLE_CLIENT_ID is required', + }), + GOOGLE_CLIENT_SECRET: z.string({ + required_error: 'GOOGLE_CLIENT_SECRET is required', + }), + {=/ enabledAuthProviders.isGoogleAuthEnabled =} + {=# enabledAuthProviders.isGitHubAuthEnabled =} + GITHUB_CLIENT_ID: z.string({ + required_error: 'GITHUB_CLIENT_ID is required', + }), + GITHUB_CLIENT_SECRET: z.string({ + required_error: 'GITHUB_CLIENT_SECRET is required', + }), + {=/ enabledAuthProviders.isGitHubAuthEnabled =} + {=# enabledAuthProviders.isDiscordAuthEnabled =} + DISCORD_CLIENT_ID: z.string({ + required_error: 'DISCORD_CLIENT_ID is required', + }), + DISCORD_CLIENT_SECRET: z.string({ + required_error: 'DISCORD_CLIENT_SECRET is required', + }), + {=/ enabledAuthProviders.isDiscordAuthEnabled =} + {=# enabledAuthProviders.isKeycloakAuthEnabled =} + KEYCLOAK_CLIENT_ID: z.string({ + required_error: 'KEYCLOAK_CLIENT_ID is required', + }), + KEYCLOAK_CLIENT_SECRET: z.string({ + required_error: 'KEYCLOAK_CLIENT_SECRET is required', + }), + KEYCLOAK_REALM_URL: z + .string({ + required_error: 'KEYCLOAK_REALM_URL is required', + }) + .url({ + message: 'KEYCLOAK_REALM_URL must be a valid URL', + }), + {=/ enabledAuthProviders.isKeycloakAuthEnabled =} + {=/ isAuthEnabled =} +}) + +const serverUrlSchema = z + .string({ + required_error: 'WASP_SERVER_URL is required', + }) + .url({ + message: 'WASP_SERVER_URL must be a valid URL', + }) + +const clientUrlSchema = z + .string({ + required_error: 'WASP_WEB_CLIENT_URL is required', + }) + .url({ + message: 'WASP_WEB_CLIENT_URL must be a valid URL', + }) + +const jwtTokenSchema = z + .string({ + required_error: 'JWT_SECRET is required', + }) + +// In development, we provide default values for some environment variables +// to make the development process easier +const serverDevSchema = z.object({ + NODE_ENV: z.literal('development'), + WASP_SERVER_URL: serverUrlSchema + .default('{= defaultServerUrl =}'), + WASP_WEB_CLIENT_URL: clientUrlSchema + .default('{= defaultClientUrl =}'), + {=# isAuthEnabled =} + JWT_SECRET: jwtTokenSchema + .default('DEVJWTSECRET'), + {=/ isAuthEnabled =} +}) + +const serverProdSchema = z.object({ + NODE_ENV: z.literal('production'), + WASP_SERVER_URL: serverUrlSchema, + WASP_WEB_CLIENT_URL: clientUrlSchema, + {=# isAuthEnabled =} + JWT_SECRET: jwtTokenSchema, + {=/ isAuthEnabled =} +}) + +const serverEnvSchema = z.discriminatedUnion('NODE_ENV', [ + serverDevSchema.merge(serverCommonSchema), + serverProdSchema.merge(serverCommonSchema) +]) + +export const env = ensureEnvSchema(process.env, serverEnvSchema) diff --git a/waspc/data/Generator/templates/sdk/wasp/server/env/index.ts b/waspc/data/Generator/templates/sdk/wasp/server/env/index.ts deleted file mode 100644 index 345f77c5fa..0000000000 --- a/waspc/data/Generator/templates/sdk/wasp/server/env/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -import * as z from 'zod' - -import { ensureEnvSchema } from '../../env/index.js' - -const serverEnvSchema = z.object({ - NODE_ENV: z.enum(['development', 'production']).default('development'), - PORT: z.coerce.number().default(3000), - SERVER_URL: z.string({ - required_error: 'SERVER_URL is required', - }), - CLIENT_URL: z.string({ - required_error: 'CLIENT_URL is required', - }), - JWT_SECRET: z.string({ - required_error: 'JWT_SECRET is required', - }), -}) - -export const env = ensureEnvSchema(process.env, serverEnvSchema) diff --git a/waspc/data/Generator/templates/sdk/wasp/server/index.ts b/waspc/data/Generator/templates/sdk/wasp/server/index.ts index 535077900b..0f95deb90a 100644 --- a/waspc/data/Generator/templates/sdk/wasp/server/index.ts +++ b/waspc/data/Generator/templates/sdk/wasp/server/index.ts @@ -10,6 +10,8 @@ export { type ServerSetupFn } from './types/index.js' export { HttpError } from './HttpError.js' // PUBLIC API export { MiddlewareConfigFn } from './middleware/index.js' +// PUBLIC API +export { env } from './env.js' // PUBLIC API export type DbSeedFn = (prisma: PrismaClient) => Promise diff --git a/waspc/data/Generator/templates/sdk/wasp/server/jobs/core/pgBoss/pgBoss.ts b/waspc/data/Generator/templates/sdk/wasp/server/jobs/core/pgBoss/pgBoss.ts index a48992aad0..0292f11176 100644 --- a/waspc/data/Generator/templates/sdk/wasp/server/jobs/core/pgBoss/pgBoss.ts +++ b/waspc/data/Generator/templates/sdk/wasp/server/jobs/core/pgBoss/pgBoss.ts @@ -1,5 +1,6 @@ import PgBoss from 'pg-boss' -import { config } from 'wasp/server' +import { env } from '../../../env.js' +import { config } from '../../../index.js' const boss = createPgBoss() @@ -9,9 +10,9 @@ function createPgBoss() { } // Add an escape hatch for advanced configuration of pg-boss to overwrite our defaults. - if (process.env.PG_BOSS_NEW_OPTIONS) { + if (env.PG_BOSS_NEW_OPTIONS) { try { - pgBossNewOptions = JSON.parse(process.env.PG_BOSS_NEW_OPTIONS) + pgBossNewOptions = JSON.parse(env.PG_BOSS_NEW_OPTIONS) } catch { console.error( 'Environment variable PG_BOSS_NEW_OPTIONS was not parsable by JSON.parse()!' diff --git a/waspc/data/Generator/templates/sdk/wasp/universal/url.ts b/waspc/data/Generator/templates/sdk/wasp/universal/url.ts index d21c06c65c..126678dac9 100644 --- a/waspc/data/Generator/templates/sdk/wasp/universal/url.ts +++ b/waspc/data/Generator/templates/sdk/wasp/universal/url.ts @@ -1,3 +1,5 @@ +export function stripTrailingSlash(url: string): string +export function stripTrailingSlash(url: undefined): undefined export function stripTrailingSlash(url?: string): string | undefined { return url?.replace(/\/$/, ""); } diff --git a/waspc/data/Generator/templates/server/package.json b/waspc/data/Generator/templates/server/package.json index 24d7a2c1a7..14f6464bbe 100644 --- a/waspc/data/Generator/templates/server/package.json +++ b/waspc/data/Generator/templates/server/package.json @@ -7,10 +7,9 @@ "comment-filip": "The server.js location changed because we have now included client source files above .wasp/out/server/src.", "scripts": { "bundle": "rollup --config --silent", - "start": "npm run validate-env && node --enable-source-maps -r dotenv/config bundle/server.js", + "start": "node --enable-source-maps -r dotenv/config bundle/server.js", "bundle-and-start": "npm run bundle && npm run start", "watch": "nodemon --exec 'npm run bundle-and-start || exit 1'", - "validate-env": "node -r dotenv/config ./scripts/validate-env.mjs", "db-seed": "npm run bundle && node --enable-source-maps -r dotenv/config bundle/dbSeed.js", "db-migrate-prod": "prisma migrate deploy --schema=../db/schema.prisma", "start-production": "{=& startProductionScript =}" diff --git a/waspc/data/Generator/templates/server/scripts/validate-env.mjs b/waspc/data/Generator/templates/server/scripts/validate-env.mjs deleted file mode 100644 index f6e50aceca..0000000000 --- a/waspc/data/Generator/templates/server/scripts/validate-env.mjs +++ /dev/null @@ -1,5 +0,0 @@ -import { throwIfNotValidAbsoluteURL } from 'wasp/universal/validators'; - -console.info("🔍 Validating environment variables..."); -throwIfNotValidAbsoluteURL(process.env.WASP_WEB_CLIENT_URL, 'Environment variable WASP_WEB_CLIENT_URL'); -throwIfNotValidAbsoluteURL(process.env.WASP_SERVER_URL, 'Environment variable WASP_SERVER_URL'); diff --git a/waspc/data/Generator/templates/server/src/auth/providers/config/email.ts b/waspc/data/Generator/templates/server/src/auth/providers/config/email.ts index a350e07b00..a0ba47d756 100644 --- a/waspc/data/Generator/templates/server/src/auth/providers/config/email.ts +++ b/waspc/data/Generator/templates/server/src/auth/providers/config/email.ts @@ -11,6 +11,7 @@ import { resetPassword } from "../email/resetPassword.js"; import { verifyEmail } from "../email/verifyEmail.js"; import { GetVerificationEmailContentFn, GetPasswordResetEmailContentFn } from "wasp/server/auth/email"; import { handleRejection } from "wasp/server/utils"; +import { env } from "wasp/server"; {=# userSignupFields.isDefined =} {=& userSignupFields.importStatement =} @@ -70,7 +71,7 @@ const config: ProviderConfig = { clientRoute: '{= emailVerificationClientRoute =}', getVerificationEmailContent: _waspGetVerificationEmailContent, {=# isDevelopment =} - isEmailAutoVerified: process.env.SKIP_EMAIL_VERIFICATION_IN_DEV === 'true', + isEmailAutoVerified: env.SKIP_EMAIL_VERIFICATION_IN_DEV, {=/ isDevelopment =} {=^ isDevelopment =} isEmailAutoVerified: false, diff --git a/waspc/data/Generator/templates/server/src/auth/providers/oauth/cookies.ts b/waspc/data/Generator/templates/server/src/auth/providers/oauth/cookies.ts index 10fdd63984..b398c2e40d 100644 --- a/waspc/data/Generator/templates/server/src/auth/providers/oauth/cookies.ts +++ b/waspc/data/Generator/templates/server/src/auth/providers/oauth/cookies.ts @@ -1,10 +1,11 @@ import { Request as ExpressRequest, Response as ExpressResponse, -} from "express"; -import { parseCookies } from "oslo/cookie"; +} from 'express'; +import { parseCookies } from 'oslo/cookie'; -import type { ProviderConfig } from "wasp/auth/providers/types"; +import type { ProviderConfig } from 'wasp/auth/providers/types'; +import { config } from 'wasp/server'; import type { OAuthStateFieldName } from './state'; @@ -17,8 +18,7 @@ export function setOAuthCookieValue( const cookieName = `${provider.id}_${fieldName}`; res.cookie(cookieName, value, { httpOnly: true, - // TODO: use server config to determine if secure - secure: process.env.NODE_ENV === "production", + secure: !config.isDevelopment, path: "/", maxAge: 60 * 60 * 1000, // 1 hour }); diff --git a/waspc/examples/todoApp/src/App.tsx b/waspc/examples/todoApp/src/App.tsx index bacb1f1ca1..0b8b3f2323 100644 --- a/waspc/examples/todoApp/src/App.tsx +++ b/waspc/examples/todoApp/src/App.tsx @@ -3,7 +3,7 @@ import { useSocket } from 'wasp/client/webSocket' import { Link } from 'wasp/client/router' import { logout, useAuth } from 'wasp/client/auth' import { useQuery, getDate } from 'wasp/client/operations' -import { env } from 'wasp/client/env' +import { env } from 'wasp/client' import './Main.css' import { getName } from './user' @@ -17,6 +17,7 @@ export function App() { const connectionIcon = isConnected ? '🟢' : '🔴' + // TODO: enable users to define their own client env vars const appName = import.meta.env.REACT_APP_NAME ? import.meta.env.REACT_APP_NAME : 'TODO App' diff --git a/waspc/examples/todoApp/src/serverSetup.ts b/waspc/examples/todoApp/src/serverSetup.ts index 09b73d42b2..4d499763ab 100644 --- a/waspc/examples/todoApp/src/serverSetup.ts +++ b/waspc/examples/todoApp/src/serverSetup.ts @@ -2,6 +2,7 @@ import { type Application } from 'express' import { mySpecialJob } from 'wasp/server/jobs' import { config, + env, type MiddlewareConfigFn, type ServerSetupFn, } from 'wasp/server' diff --git a/waspc/src/Wasp/Generator/EmailSenders.hs b/waspc/src/Wasp/Generator/EmailSenders.hs new file mode 100644 index 0000000000..a90ab18774 --- /dev/null +++ b/waspc/src/Wasp/Generator/EmailSenders.hs @@ -0,0 +1,23 @@ +module Wasp.Generator.EmailSenders + ( getEnabledEmailProvidersJson, + ) +where + +import Data.Aeson (KeyValue ((.=)), object) +import qualified Data.Aeson as Aeson +import qualified Wasp.AppSpec.App.EmailSender as AS.App.EmailSender + +getEnabledEmailProvidersJson :: AS.App.EmailSender.EmailSender -> Aeson.Value +getEnabledEmailProvidersJson emailSender = + object $ + makeProviderJson + <$> providersKeyAndName + where + providersKeyAndName = + [ ("isSmtpProviderUsed", AS.App.EmailSender.SMTP), + ("isSendGridProviderUsed", AS.App.EmailSender.SendGrid), + ("isMailgunProviderUsed", AS.App.EmailSender.Mailgun), + ("isDummyProviderUsed", AS.App.EmailSender.Dummy) + ] + makeProviderJson (key, name) = key .= (enabledEmailSenderName == name) + enabledEmailSenderName = AS.App.EmailSender.provider emailSender diff --git a/waspc/src/Wasp/Generator/SdkGenerator/EmailSender/Providers.hs b/waspc/src/Wasp/Generator/SdkGenerator/EmailSender/Providers.hs index cea9734e70..528a550694 100644 --- a/waspc/src/Wasp/Generator/SdkGenerator/EmailSender/Providers.hs +++ b/waspc/src/Wasp/Generator/SdkGenerator/EmailSender/Providers.hs @@ -15,10 +15,7 @@ import qualified Wasp.SemanticVersion as SV data EmailSenderProvider = EmailSenderProvider { npmDependency :: Maybe AS.Dependency.Dependency, - setupFnFile :: Path' (Rel ProvidersDir) File', - -- We have to use explicit boolean keys in templates (e.g. "isSMTPProviderEnabled") so each - -- provider provides its own key which we pass to the template. - isEnabledKey :: String + setupFnFile :: Path' (Rel ProvidersDir) File' } deriving (Show, Eq) @@ -31,8 +28,7 @@ smtp :: EmailSenderProvider smtp = EmailSenderProvider { npmDependency = Just nodeMailerDependency, - setupFnFile = [relfile|smtp.ts|], - isEnabledKey = "isSmtpProviderUsed" + setupFnFile = [relfile|smtp.ts|] } where nodeMailerVersionRange :: SV.Range @@ -45,8 +41,7 @@ sendGrid :: EmailSenderProvider sendGrid = EmailSenderProvider { npmDependency = Just sendGridDependency, - setupFnFile = [relfile|sendgrid.ts|], - isEnabledKey = "isSendGridProviderUsed" + setupFnFile = [relfile|sendgrid.ts|] } where sendGridVersionRange :: SV.Range @@ -59,8 +54,7 @@ mailgun :: EmailSenderProvider mailgun = EmailSenderProvider { npmDependency = Just mailgunDependency, - setupFnFile = [relfile|mailgun.ts|], - isEnabledKey = "isMailgunProviderUsed" + setupFnFile = [relfile|mailgun.ts|] } where mailgunVersionRange :: SV.Range @@ -73,6 +67,5 @@ dummy :: EmailSenderProvider dummy = EmailSenderProvider { npmDependency = Nothing, - setupFnFile = [relfile|dummy.ts|], - isEnabledKey = "isDummyProviderUsed" + setupFnFile = [relfile|dummy.ts|] } diff --git a/waspc/src/Wasp/Generator/SdkGenerator/EnvValidation.hs b/waspc/src/Wasp/Generator/SdkGenerator/EnvValidation.hs index e4398bba6c..e7787d4ae2 100644 --- a/waspc/src/Wasp/Generator/SdkGenerator/EnvValidation.hs +++ b/waspc/src/Wasp/Generator/SdkGenerator/EnvValidation.hs @@ -4,23 +4,57 @@ module Wasp.Generator.SdkGenerator.EnvValidation ) where +import Data.Aeson (KeyValue ((.=)), object) +import Data.Maybe (isJust) import StrongPath (relfile) import Wasp.AppSpec (AppSpec) +import qualified Wasp.AppSpec.App as AS.App import qualified Wasp.AppSpec.App.Dependency as AS.Dependency +import Wasp.AppSpec.Valid (getApp) +import qualified Wasp.Generator.AuthProviders as AuthProviders +import qualified Wasp.Generator.EmailSenders as EmailSenders import Wasp.Generator.FileDraft (FileDraft) import Wasp.Generator.Monad (Generator) import qualified Wasp.Generator.SdkGenerator.Common as C +import qualified Wasp.Generator.ServerGenerator.Common as Server +import qualified Wasp.Generator.WebAppGenerator.Common as WebApp +import qualified Wasp.Project.Db as Db genEnvValidation :: AppSpec -> Generator [FileDraft] -genEnvValidation _spec = +genEnvValidation spec = sequence - [ genFileCopy [relfile|env/index.ts|], - genFileCopy [relfile|client/env/index.ts|], - genFileCopy [relfile|server/env/index.ts|] + [ genServerEnv spec, + genClientEnv, + genFileCopy [relfile|env/index.ts|] ] where genFileCopy = return . C.mkTmplFd +genServerEnv :: AppSpec -> Generator FileDraft +genServerEnv spec = return $ C.mkTmplFdWithData tmplPath tmplData + where + tmplPath = [relfile|server/env.ts|] + tmplData = + object + [ "isAuthEnabled" .= isJust maybeAuth, + "databaseUrlEnvVarName" .= Db.databaseUrlEnvVarName, + "defaultClientUrl" .= WebApp.getDefaultDevClientUrl spec, + "defaultServerUrl" .= Server.defaultDevServerUrl, + "defaultServerPort" .= Server.defaultServerPort, + "enabledAuthProviders" .= (AuthProviders.getEnabledAuthProvidersJson <$> maybeAuth), + "isEmailSenderUsed" .= isJust maybeEmailSender, + "enabledEmailSenders" .= (EmailSenders.getEnabledEmailProvidersJson <$> maybeEmailSender) + ] + maybeAuth = AS.App.auth app + maybeEmailSender = AS.App.emailSender app + app = snd $ getApp spec + +genClientEnv :: Generator FileDraft +genClientEnv = return $ C.mkTmplFdWithData tmplPath tmplData + where + tmplPath = [relfile|client/env.ts|] + tmplData = object ["defaultServerUrl" .= Server.defaultDevServerUrl] + depsRequiredByEnvValidation :: [AS.Dependency.Dependency] depsRequiredByEnvValidation = AS.Dependency.fromList diff --git a/waspc/src/Wasp/Generator/SdkGenerator/Server/EmailSenderG.hs b/waspc/src/Wasp/Generator/SdkGenerator/Server/EmailSenderG.hs index fa6cb2b315..87effec2b9 100644 --- a/waspc/src/Wasp/Generator/SdkGenerator/Server/EmailSenderG.hs +++ b/waspc/src/Wasp/Generator/SdkGenerator/Server/EmailSenderG.hs @@ -1,9 +1,11 @@ -module Wasp.Generator.SdkGenerator.Server.EmailSenderG where +module Wasp.Generator.SdkGenerator.Server.EmailSenderG + ( genNewEmailSenderApi, + depsRequiredByEmail, + ) +where import Data.Aeson (object, (.=)) -import qualified Data.Aeson as Aeson import Data.Maybe (fromMaybe, isJust, maybeToList) -import qualified Data.Text import StrongPath (File', Path', Rel, relfile, ()) import Wasp.AppSpec (AppSpec) import qualified Wasp.AppSpec.App as AS.App @@ -11,6 +13,7 @@ import qualified Wasp.AppSpec.App.Dependency as AS.Dependency import Wasp.AppSpec.App.EmailSender (EmailSender) import qualified Wasp.AppSpec.App.EmailSender as AS.EmailSender import Wasp.AppSpec.Valid (getApp) +import qualified Wasp.Generator.EmailSenders as EmailSenders import Wasp.Generator.FileDraft (FileDraft) import Wasp.Generator.Monad (Generator) import qualified Wasp.Generator.SdkGenerator.Common as C @@ -32,7 +35,7 @@ genIndex :: EmailSender -> Generator FileDraft genIndex email = return $ C.mkTmplFdWithData tmplPath tmplData where tmplPath = [relfile|server/email/index.ts|] - tmplData = getEmailProvidersJson email + tmplData = EmailSenders.getEnabledEmailProvidersJson email genCore :: EmailSender -> Generator [FileDraft] genCore email = @@ -47,7 +50,7 @@ genCoreIndex :: EmailSender -> Generator FileDraft genCoreIndex email = return $ C.mkTmplFdWithData tmplPath tmplData where tmplPath = [relfile|server/email/core/index.ts|] - tmplData = getEmailProvidersJson email + tmplData = EmailSenders.getEnabledEmailProvidersJson email genCoreTypes :: EmailSender -> Generator FileDraft genCoreTypes email = return $ C.mkTmplFdWithData tmplPath tmplData @@ -95,14 +98,6 @@ depsRequiredByEmail spec = maybeToList maybeNpmDepedency maybeProvider = getEmailSenderProvider <$> (AS.App.emailSender . snd . getApp $ spec) maybeNpmDepedency = maybeProvider >>= Providers.npmDependency -getEmailProvidersJson :: EmailSender -> Aeson.Value -getEmailProvidersJson email = - object [isEnabledKey .= True] - where - provider :: Providers.EmailSenderProvider - provider = getEmailSenderProvider email - isEnabledKey = Data.Text.pack $ Providers.isEnabledKey provider - getEmailSenderProvider :: EmailSender -> Providers.EmailSenderProvider getEmailSenderProvider email = case AS.EmailSender.provider email of AS.EmailSender.SMTP -> Providers.smtp diff --git a/waspc/src/Wasp/Generator/SdkGenerator/Server/OAuthG.hs b/waspc/src/Wasp/Generator/SdkGenerator/Server/OAuthG.hs index fb533e22f1..0050aff479 100644 --- a/waspc/src/Wasp/Generator/SdkGenerator/Server/OAuthG.hs +++ b/waspc/src/Wasp/Generator/SdkGenerator/Server/OAuthG.hs @@ -35,7 +35,6 @@ genOAuth auth sequence [ genIndexTs auth, genRedirectHelper, - genFileCopy $ oauthDirInSdkTemplatesDir [relfile|env.ts|], genFileCopy $ oauthDirInSdkTemplatesDir [relfile|oneTimeCode.ts|], genFileCopy $ oauthDirInSdkTemplatesDir [relfile|provider.ts|] ] diff --git a/waspc/src/Wasp/Generator/ServerGenerator.hs b/waspc/src/Wasp/Generator/ServerGenerator.hs index 269e878336..e40797511c 100644 --- a/waspc/src/Wasp/Generator/ServerGenerator.hs +++ b/waspc/src/Wasp/Generator/ServerGenerator.hs @@ -75,7 +75,6 @@ genServer spec = <++> genSrcDir spec <++> genDotEnv spec <++> genJobs spec - <++> genEnvValidationScript <++> genApis spec <++> genCrud spec where @@ -252,12 +251,6 @@ genRoutesIndex spec = operationsRouteInRootRouter :: String operationsRouteInRootRouter = "operations" -genEnvValidationScript :: Generator [FileDraft] -genEnvValidationScript = - return - [ C.mkTmplFd [relfile|scripts/validate-env.mjs|] - ] - genMiddleware :: AppSpec -> Generator [FileDraft] genMiddleware spec = sequence diff --git a/waspc/src/Wasp/Generator/WebAppGenerator.hs b/waspc/src/Wasp/Generator/WebAppGenerator.hs index e1f4b481ed..f94e5dcece 100644 --- a/waspc/src/Wasp/Generator/WebAppGenerator.hs +++ b/waspc/src/Wasp/Generator/WebAppGenerator.hs @@ -227,6 +227,8 @@ getIndexTs spec = relPathToWebAppSrcDir :: Path Posix (Rel importLocation) (Dir C.WebAppSrcDir) relPathToWebAppSrcDir = [reldirP|./|] +-- TODO: see if this is still needed after introducing the Zod +-- validation for the env vars. genEnvValidationScript :: Generator [FileDraft] genEnvValidationScript = return diff --git a/waspc/waspc.cabal b/waspc/waspc.cabal index 655c6f9180..9005a512d6 100644 --- a/waspc/waspc.cabal +++ b/waspc/waspc.cabal @@ -281,6 +281,7 @@ library Wasp.Generator.DbGenerator.Jobs Wasp.Generator.DbGenerator.Operations Wasp.Generator.DockerGenerator + Wasp.Generator.EmailSenders Wasp.Generator.ExternalCodeGenerator.Common Wasp.Generator.ExternalConfig.Common Wasp.Generator.ExternalConfig.PackageJson From 80baf9c3b106b27f404d0b76ba75382674b3dff7 Mon Sep 17 00:00:00 2001 From: Mihovil Ilakovac Date: Tue, 29 Oct 2024 15:03:15 +0100 Subject: [PATCH 3/9] Update e2e tests --- .../waspBuild-golden/files.manifest | 25 ++++++- .../waspBuild/.wasp/build/.waspchecksums | 44 ++++++++---- .../waspBuild/.wasp/build/Dockerfile | 6 +- .../.wasp/build/installedNpmDepsLog.json | 2 +- .../.wasp/build/sdk/wasp/client/config.ts | 3 +- .../.wasp/build/sdk/wasp/client/env.ts | 13 ++++ .../.wasp/build/sdk/wasp/client/index.ts | 3 + .../build/sdk/wasp/dist/client/config.js | 3 +- .../build/sdk/wasp/dist/client/config.js.map | 2 +- .../.wasp/build/sdk/wasp/dist/client/env.d.ts | 3 + .../.wasp/build/sdk/wasp/dist/client/env.js | 11 +++ .../build/sdk/wasp/dist/client/env.js.map | 1 + .../build/sdk/wasp/dist/client/index.d.ts | 1 + .../.wasp/build/sdk/wasp/dist/client/index.js | 2 + .../build/sdk/wasp/dist/client/index.js.map | 2 +- .../.wasp/build/sdk/wasp/dist/env/index.d.ts | 2 + .../.wasp/build/sdk/wasp/dist/env/index.js | 26 +++++++ .../build/sdk/wasp/dist/env/index.js.map | 1 + .../build/sdk/wasp/dist/server/config.js | 29 +++----- .../build/sdk/wasp/dist/server/config.js.map | 2 +- .../.wasp/build/sdk/wasp/dist/server/env.d.ts | 17 +++++ .../.wasp/build/sdk/wasp/dist/server/env.js | 48 +++++++++++++ .../build/sdk/wasp/dist/server/env.js.map | 1 + .../build/sdk/wasp/dist/server/index.d.ts | 1 + .../.wasp/build/sdk/wasp/dist/server/index.js | 2 + .../build/sdk/wasp/dist/server/index.js.map | 2 +- .../build/sdk/wasp/dist/universal/url.d.ts | 3 +- .../build/sdk/wasp/dist/universal/url.js.map | 2 +- .../.wasp/build/sdk/wasp/env/index.ts | 28 ++++++++ .../.wasp/build/sdk/wasp/package.json | 3 +- .../.wasp/build/sdk/wasp/server/config.ts | 28 +++----- .../.wasp/build/sdk/wasp/server/env.ts | 56 +++++++++++++++ .../.wasp/build/sdk/wasp/server/index.ts | 2 + .../.wasp/build/sdk/wasp/universal/url.ts | 2 + .../waspBuild/.wasp/build/server/package.json | 3 +- .../build/server/scripts/validate-env.mjs | 5 -- .../.wasp/out/sdk/wasp/client/config.ts | 3 +- .../.wasp/out/sdk/wasp/client/env.ts | 13 ++++ .../.wasp/out/sdk/wasp/client/index.ts | 3 + .../.wasp/out/sdk/wasp/dist/client/config.js | 3 +- .../out/sdk/wasp/dist/client/config.js.map | 2 +- .../.wasp/out/sdk/wasp/dist/client/env.d.ts | 3 + .../.wasp/out/sdk/wasp/dist/client/env.js | 11 +++ .../.wasp/out/sdk/wasp/dist/client/env.js.map | 1 + .../.wasp/out/sdk/wasp/dist/client/index.d.ts | 1 + .../.wasp/out/sdk/wasp/dist/client/index.js | 2 + .../out/sdk/wasp/dist/client/index.js.map | 2 +- .../.wasp/out/sdk/wasp/dist/env/index.d.ts | 2 + .../.wasp/out/sdk/wasp/dist/env/index.js | 26 +++++++ .../.wasp/out/sdk/wasp/dist/env/index.js.map | 1 + .../.wasp/out/sdk/wasp/dist/server/config.js | 29 +++----- .../out/sdk/wasp/dist/server/config.js.map | 2 +- .../.wasp/out/sdk/wasp/dist/server/env.d.ts | 17 +++++ .../.wasp/out/sdk/wasp/dist/server/env.js | 48 +++++++++++++ .../.wasp/out/sdk/wasp/dist/server/env.js.map | 1 + .../.wasp/out/sdk/wasp/dist/server/index.d.ts | 1 + .../.wasp/out/sdk/wasp/dist/server/index.js | 2 + .../out/sdk/wasp/dist/server/index.js.map | 2 +- .../out/sdk/wasp/dist/universal/url.d.ts | 3 +- .../out/sdk/wasp/dist/universal/url.js.map | 2 +- .../waspBuild/.wasp/out/sdk/wasp/env/index.ts | 28 ++++++++ .../waspBuild/.wasp/out/sdk/wasp/package.json | 3 +- .../.wasp/out/sdk/wasp/server/config.ts | 28 +++----- .../.wasp/out/sdk/wasp/server/env.ts | 56 +++++++++++++++ .../.wasp/out/sdk/wasp/server/index.ts | 2 + .../.wasp/out/sdk/wasp/universal/url.ts | 2 + .../waspCompile-golden/files.manifest | 13 +++- .../waspCompile/.wasp/out/.waspchecksums | 44 ++++++++---- .../waspCompile/.wasp/out/Dockerfile | 6 +- .../.wasp/out/installedNpmDepsLog.json | 2 +- .../.wasp/out/sdk/wasp/client/config.ts | 3 +- .../.wasp/out/sdk/wasp/client/env.ts | 13 ++++ .../.wasp/out/sdk/wasp/client/index.ts | 3 + .../.wasp/out/sdk/wasp/dist/client/config.js | 3 +- .../out/sdk/wasp/dist/client/config.js.map | 2 +- .../.wasp/out/sdk/wasp/dist/client/env.d.ts | 3 + .../.wasp/out/sdk/wasp/dist/client/env.js | 11 +++ .../.wasp/out/sdk/wasp/dist/client/env.js.map | 1 + .../.wasp/out/sdk/wasp/dist/client/index.d.ts | 1 + .../.wasp/out/sdk/wasp/dist/client/index.js | 2 + .../out/sdk/wasp/dist/client/index.js.map | 2 +- .../.wasp/out/sdk/wasp/dist/env/index.d.ts | 2 + .../.wasp/out/sdk/wasp/dist/env/index.js | 26 +++++++ .../.wasp/out/sdk/wasp/dist/env/index.js.map | 1 + .../.wasp/out/sdk/wasp/dist/server/config.js | 29 +++----- .../out/sdk/wasp/dist/server/config.js.map | 2 +- .../.wasp/out/sdk/wasp/dist/server/env.d.ts | 17 +++++ .../.wasp/out/sdk/wasp/dist/server/env.js | 48 +++++++++++++ .../.wasp/out/sdk/wasp/dist/server/env.js.map | 1 + .../.wasp/out/sdk/wasp/dist/server/index.d.ts | 1 + .../.wasp/out/sdk/wasp/dist/server/index.js | 2 + .../out/sdk/wasp/dist/server/index.js.map | 2 +- .../out/sdk/wasp/dist/universal/url.d.ts | 3 +- .../out/sdk/wasp/dist/universal/url.js.map | 2 +- .../.wasp/out/sdk/wasp/env/index.ts | 28 ++++++++ .../.wasp/out/sdk/wasp/package.json | 3 +- .../.wasp/out/sdk/wasp/server/config.ts | 28 +++----- .../.wasp/out/sdk/wasp/server/env.ts | 56 +++++++++++++++ .../.wasp/out/sdk/wasp/server/index.ts | 2 + .../.wasp/out/sdk/wasp/universal/url.ts | 2 + .../waspCompile/.wasp/out/server/package.json | 3 +- .../.wasp/out/server/scripts/validate-env.mjs | 5 -- .../waspComplexTest-golden/files.manifest | 17 +++-- .../waspComplexTest/.wasp/out/.waspchecksums | 61 +++++++++-------- .../waspComplexTest/.wasp/out/Dockerfile | 6 +- .../.wasp/out/installedNpmDepsLog.json | 2 +- .../.wasp/out/sdk/wasp/client/config.ts | 3 +- .../.wasp/out/sdk/wasp/client/env.ts | 13 ++++ .../.wasp/out/sdk/wasp/client/index.ts | 3 + .../.wasp/out/sdk/wasp/dist/client/config.js | 3 +- .../out/sdk/wasp/dist/client/config.js.map | 2 +- .../.wasp/out/sdk/wasp/dist/client/env.d.ts | 3 + .../.wasp/out/sdk/wasp/dist/client/env.js | 11 +++ .../.wasp/out/sdk/wasp/dist/client/env.js.map | 1 + .../.wasp/out/sdk/wasp/dist/client/index.d.ts | 1 + .../.wasp/out/sdk/wasp/dist/client/index.js | 2 + .../out/sdk/wasp/dist/client/index.js.map | 2 +- .../.wasp/out/sdk/wasp/dist/env/index.d.ts | 2 + .../.wasp/out/sdk/wasp/dist/env/index.js | 26 +++++++ .../.wasp/out/sdk/wasp/dist/env/index.js.map | 1 + .../sdk/wasp/dist/server/auth/oauth/env.d.ts | 1 - .../sdk/wasp/dist/server/auth/oauth/env.js | 13 ---- .../wasp/dist/server/auth/oauth/env.js.map | 1 - .../wasp/dist/server/auth/oauth/provider.d.ts | 4 +- .../wasp/dist/server/auth/oauth/provider.js | 3 +- .../dist/server/auth/oauth/provider.js.map | 2 +- .../server/auth/oauth/providers/google.d.ts | 3 +- .../server/auth/oauth/providers/google.js | 14 ++-- .../server/auth/oauth/providers/google.js.map | 2 +- .../out/sdk/wasp/dist/server/config.d.ts | 6 +- .../.wasp/out/sdk/wasp/dist/server/config.js | 37 ++++------ .../out/sdk/wasp/dist/server/config.js.map | 2 +- .../out/sdk/wasp/dist/server/email/index.js | 3 +- .../sdk/wasp/dist/server/email/index.js.map | 2 +- .../.wasp/out/sdk/wasp/dist/server/env.d.ts | 25 +++++++ .../.wasp/out/sdk/wasp/dist/server/env.js | 60 ++++++++++++++++ .../.wasp/out/sdk/wasp/dist/server/env.js.map | 1 + .../.wasp/out/sdk/wasp/dist/server/index.d.ts | 1 + .../.wasp/out/sdk/wasp/dist/server/index.js | 2 + .../out/sdk/wasp/dist/server/index.js.map | 2 +- .../dist/server/jobs/core/pgBoss/pgBoss.js | 7 +- .../server/jobs/core/pgBoss/pgBoss.js.map | 2 +- .../out/sdk/wasp/dist/universal/url.d.ts | 3 +- .../out/sdk/wasp/dist/universal/url.js.map | 2 +- .../.wasp/out/sdk/wasp/env/index.ts | 28 ++++++++ .../.wasp/out/sdk/wasp/package.json | 3 +- .../out/sdk/wasp/server/auth/oauth/env.ts | 15 ---- .../sdk/wasp/server/auth/oauth/provider.ts | 6 +- .../server/auth/oauth/providers/google.ts | 18 ++--- .../.wasp/out/sdk/wasp/server/config.ts | 42 ++++-------- .../.wasp/out/sdk/wasp/server/email/index.ts | 3 +- .../.wasp/out/sdk/wasp/server/env.ts | 68 +++++++++++++++++++ .../.wasp/out/sdk/wasp/server/index.ts | 2 + .../wasp/server/jobs/core/pgBoss/pgBoss.ts | 7 +- .../.wasp/out/sdk/wasp/universal/url.ts | 2 + .../.wasp/out/server/package.json | 3 +- .../.wasp/out/server/scripts/validate-env.mjs | 5 -- .../src/auth/providers/oauth/cookies.ts | 10 +-- .../waspJob-golden/files.manifest | 13 +++- .../waspJob/.wasp/out/.waspchecksums | 46 ++++++++----- .../waspJob/.wasp/out/Dockerfile | 6 +- .../.wasp/out/installedNpmDepsLog.json | 2 +- .../.wasp/out/sdk/wasp/client/config.ts | 3 +- .../waspJob/.wasp/out/sdk/wasp/client/env.ts | 13 ++++ .../.wasp/out/sdk/wasp/client/index.ts | 3 + .../.wasp/out/sdk/wasp/dist/client/config.js | 3 +- .../out/sdk/wasp/dist/client/config.js.map | 2 +- .../.wasp/out/sdk/wasp/dist/client/env.d.ts | 3 + .../.wasp/out/sdk/wasp/dist/client/env.js | 11 +++ .../.wasp/out/sdk/wasp/dist/client/env.js.map | 1 + .../.wasp/out/sdk/wasp/dist/client/index.d.ts | 1 + .../.wasp/out/sdk/wasp/dist/client/index.js | 2 + .../out/sdk/wasp/dist/client/index.js.map | 2 +- .../.wasp/out/sdk/wasp/dist/env/index.d.ts | 2 + .../.wasp/out/sdk/wasp/dist/env/index.js | 26 +++++++ .../.wasp/out/sdk/wasp/dist/env/index.js.map | 1 + .../.wasp/out/sdk/wasp/dist/server/config.js | 29 +++----- .../out/sdk/wasp/dist/server/config.js.map | 2 +- .../.wasp/out/sdk/wasp/dist/server/env.d.ts | 17 +++++ .../.wasp/out/sdk/wasp/dist/server/env.js | 48 +++++++++++++ .../.wasp/out/sdk/wasp/dist/server/env.js.map | 1 + .../.wasp/out/sdk/wasp/dist/server/index.d.ts | 1 + .../.wasp/out/sdk/wasp/dist/server/index.js | 2 + .../out/sdk/wasp/dist/server/index.js.map | 2 +- .../dist/server/jobs/core/pgBoss/pgBoss.js | 7 +- .../server/jobs/core/pgBoss/pgBoss.js.map | 2 +- .../out/sdk/wasp/dist/universal/url.d.ts | 3 +- .../out/sdk/wasp/dist/universal/url.js.map | 2 +- .../waspJob/.wasp/out/sdk/wasp/env/index.ts | 28 ++++++++ .../waspJob/.wasp/out/sdk/wasp/package.json | 3 +- .../.wasp/out/sdk/wasp/server/config.ts | 28 +++----- .../waspJob/.wasp/out/sdk/wasp/server/env.ts | 56 +++++++++++++++ .../.wasp/out/sdk/wasp/server/index.ts | 2 + .../wasp/server/jobs/core/pgBoss/pgBoss.ts | 7 +- .../.wasp/out/sdk/wasp/universal/url.ts | 2 + .../waspJob/.wasp/out/server/package.json | 3 +- .../.wasp/out/server/scripts/validate-env.mjs | 5 -- .../waspMigrate-golden/files.manifest | 13 +++- .../waspMigrate/.wasp/out/.waspchecksums | 44 ++++++++---- .../waspMigrate/.wasp/out/Dockerfile | 6 +- .../.wasp/out/installedNpmDepsLog.json | 2 +- .../.wasp/out/sdk/wasp/client/config.ts | 3 +- .../.wasp/out/sdk/wasp/client/env.ts | 13 ++++ .../.wasp/out/sdk/wasp/client/index.ts | 3 + .../.wasp/out/sdk/wasp/dist/client/config.js | 3 +- .../out/sdk/wasp/dist/client/config.js.map | 2 +- .../.wasp/out/sdk/wasp/dist/client/env.d.ts | 3 + .../.wasp/out/sdk/wasp/dist/client/env.js | 11 +++ .../.wasp/out/sdk/wasp/dist/client/env.js.map | 1 + .../.wasp/out/sdk/wasp/dist/client/index.d.ts | 1 + .../.wasp/out/sdk/wasp/dist/client/index.js | 2 + .../out/sdk/wasp/dist/client/index.js.map | 2 +- .../.wasp/out/sdk/wasp/dist/env/index.d.ts | 2 + .../.wasp/out/sdk/wasp/dist/env/index.js | 26 +++++++ .../.wasp/out/sdk/wasp/dist/env/index.js.map | 1 + .../.wasp/out/sdk/wasp/dist/server/config.js | 29 +++----- .../out/sdk/wasp/dist/server/config.js.map | 2 +- .../.wasp/out/sdk/wasp/dist/server/env.d.ts | 17 +++++ .../.wasp/out/sdk/wasp/dist/server/env.js | 48 +++++++++++++ .../.wasp/out/sdk/wasp/dist/server/env.js.map | 1 + .../.wasp/out/sdk/wasp/dist/server/index.d.ts | 1 + .../.wasp/out/sdk/wasp/dist/server/index.js | 2 + .../out/sdk/wasp/dist/server/index.js.map | 2 +- .../out/sdk/wasp/dist/universal/url.d.ts | 3 +- .../out/sdk/wasp/dist/universal/url.js.map | 2 +- .../.wasp/out/sdk/wasp/env/index.ts | 28 ++++++++ .../.wasp/out/sdk/wasp/package.json | 3 +- .../.wasp/out/sdk/wasp/server/config.ts | 28 +++----- .../.wasp/out/sdk/wasp/server/env.ts | 56 +++++++++++++++ .../.wasp/out/sdk/wasp/server/index.ts | 2 + .../.wasp/out/sdk/wasp/universal/url.ts | 2 + .../waspMigrate/.wasp/out/server/package.json | 3 +- .../.wasp/out/server/scripts/validate-env.mjs | 5 -- 233 files changed, 1864 insertions(+), 522 deletions(-) create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/client/env.ts create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/env.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/env.js create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/env.js.map create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.js create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.js.map create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.js create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.js.map create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/env/index.ts create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/env.ts delete mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/scripts/validate-env.mjs create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/client/env.ts create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/env.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/env.js create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/env.js.map create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.js create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.js.map create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.js create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.js.map create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/env/index.ts create mode 100644 waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/env.ts create mode 100644 waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/client/env.ts create mode 100644 waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/env.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/env.js create mode 100644 waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/env.js.map create mode 100644 waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.js create mode 100644 waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.js.map create mode 100644 waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.js create mode 100644 waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.js.map create mode 100644 waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/env/index.ts create mode 100644 waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/env.ts delete mode 100644 waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/scripts/validate-env.mjs create mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/client/env.ts create mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/env.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/env.js create mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/env.js.map create mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js create mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js.map delete mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/env.d.ts delete mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/env.js delete mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/env.js.map create mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js create mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js.map create mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/env/index.ts delete mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/auth/oauth/env.ts create mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/env.ts delete mode 100644 waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/server/scripts/validate-env.mjs create mode 100644 waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/client/env.ts create mode 100644 waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/env.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/env.js create mode 100644 waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/env.js.map create mode 100644 waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.js create mode 100644 waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.js.map create mode 100644 waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.js create mode 100644 waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.js.map create mode 100644 waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/env/index.ts create mode 100644 waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/env.ts delete mode 100644 waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/scripts/validate-env.mjs create mode 100644 waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/client/env.ts create mode 100644 waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/env.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/env.js create mode 100644 waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/env.js.map create mode 100644 waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js create mode 100644 waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js.map create mode 100644 waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.d.ts create mode 100644 waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js create mode 100644 waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js.map create mode 100644 waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/env/index.ts create mode 100644 waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/env.ts delete mode 100644 waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/scripts/validate-env.mjs diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/files.manifest b/waspc/e2e-test/test-outputs/waspBuild-golden/files.manifest index 1ef46f2f24..fdefab5e0d 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/files.manifest +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/files.manifest @@ -7,6 +7,7 @@ waspBuild/.wasp/build/package.json waspBuild/.wasp/build/sdk/wasp/api/events.ts waspBuild/.wasp/build/sdk/wasp/api/index.ts waspBuild/.wasp/build/sdk/wasp/client/config.ts +waspBuild/.wasp/build/sdk/wasp/client/env.ts waspBuild/.wasp/build/sdk/wasp/client/index.ts waspBuild/.wasp/build/sdk/wasp/client/operations/actions/core.ts waspBuild/.wasp/build/sdk/wasp/client/operations/actions/index.ts @@ -36,6 +37,9 @@ waspBuild/.wasp/build/sdk/wasp/dist/api/index.js.map waspBuild/.wasp/build/sdk/wasp/dist/client/config.d.ts waspBuild/.wasp/build/sdk/wasp/dist/client/config.js waspBuild/.wasp/build/sdk/wasp/dist/client/config.js.map +waspBuild/.wasp/build/sdk/wasp/dist/client/env.d.ts +waspBuild/.wasp/build/sdk/wasp/dist/client/env.js +waspBuild/.wasp/build/sdk/wasp/dist/client/env.js.map waspBuild/.wasp/build/sdk/wasp/dist/client/index.d.ts waspBuild/.wasp/build/sdk/wasp/dist/client/index.js waspBuild/.wasp/build/sdk/wasp/dist/client/index.js.map @@ -99,6 +103,9 @@ waspBuild/.wasp/build/sdk/wasp/dist/dev/index.js.map waspBuild/.wasp/build/sdk/wasp/dist/entities/index.d.ts waspBuild/.wasp/build/sdk/wasp/dist/entities/index.js waspBuild/.wasp/build/sdk/wasp/dist/entities/index.js.map +waspBuild/.wasp/build/sdk/wasp/dist/env/index.d.ts +waspBuild/.wasp/build/sdk/wasp/dist/env/index.js +waspBuild/.wasp/build/sdk/wasp/dist/env/index.js.map waspBuild/.wasp/build/sdk/wasp/dist/ext-src/MainPage.d.ts waspBuild/.wasp/build/sdk/wasp/dist/ext-src/MainPage.jsx waspBuild/.wasp/build/sdk/wasp/dist/ext-src/MainPage.jsx.map @@ -120,6 +127,9 @@ waspBuild/.wasp/build/sdk/wasp/dist/server/config.js.map waspBuild/.wasp/build/sdk/wasp/dist/server/dbClient.d.ts waspBuild/.wasp/build/sdk/wasp/dist/server/dbClient.js waspBuild/.wasp/build/sdk/wasp/dist/server/dbClient.js.map +waspBuild/.wasp/build/sdk/wasp/dist/server/env.d.ts +waspBuild/.wasp/build/sdk/wasp/dist/server/env.js +waspBuild/.wasp/build/sdk/wasp/dist/server/env.js.map waspBuild/.wasp/build/sdk/wasp/dist/server/index.d.ts waspBuild/.wasp/build/sdk/wasp/dist/server/index.js waspBuild/.wasp/build/sdk/wasp/dist/server/index.js.map @@ -163,6 +173,7 @@ waspBuild/.wasp/build/sdk/wasp/dist/universal/validators.d.ts waspBuild/.wasp/build/sdk/wasp/dist/universal/validators.js waspBuild/.wasp/build/sdk/wasp/dist/universal/validators.js.map waspBuild/.wasp/build/sdk/wasp/entities/index.ts +waspBuild/.wasp/build/sdk/wasp/env/index.ts waspBuild/.wasp/build/sdk/wasp/ext-src/Main.css waspBuild/.wasp/build/sdk/wasp/ext-src/MainPage.jsx waspBuild/.wasp/build/sdk/wasp/ext-src/vite-env.d.ts @@ -175,6 +186,7 @@ waspBuild/.wasp/build/sdk/wasp/server/_types/serialization.ts waspBuild/.wasp/build/sdk/wasp/server/_types/taggedEntities.ts waspBuild/.wasp/build/sdk/wasp/server/config.ts waspBuild/.wasp/build/sdk/wasp/server/dbClient.ts +waspBuild/.wasp/build/sdk/wasp/server/env.ts waspBuild/.wasp/build/sdk/wasp/server/index.ts waspBuild/.wasp/build/sdk/wasp/server/middleware/globalMiddleware.ts waspBuild/.wasp/build/sdk/wasp/server/middleware/index.ts @@ -196,7 +208,6 @@ waspBuild/.wasp/build/server/README.md waspBuild/.wasp/build/server/nodemon.json waspBuild/.wasp/build/server/package.json waspBuild/.wasp/build/server/rollup.config.js -waspBuild/.wasp/build/server/scripts/validate-env.mjs waspBuild/.wasp/build/server/src/app.js waspBuild/.wasp/build/server/src/middleware/globalMiddleware.ts waspBuild/.wasp/build/server/src/middleware/index.ts @@ -236,6 +247,7 @@ waspBuild/.wasp/build/web-app/vite.config.ts waspBuild/.wasp/out/sdk/wasp/api/events.ts waspBuild/.wasp/out/sdk/wasp/api/index.ts waspBuild/.wasp/out/sdk/wasp/client/config.ts +waspBuild/.wasp/out/sdk/wasp/client/env.ts waspBuild/.wasp/out/sdk/wasp/client/index.ts waspBuild/.wasp/out/sdk/wasp/client/operations/actions/core.ts waspBuild/.wasp/out/sdk/wasp/client/operations/actions/index.ts @@ -265,6 +277,9 @@ waspBuild/.wasp/out/sdk/wasp/dist/api/index.js.map waspBuild/.wasp/out/sdk/wasp/dist/client/config.d.ts waspBuild/.wasp/out/sdk/wasp/dist/client/config.js waspBuild/.wasp/out/sdk/wasp/dist/client/config.js.map +waspBuild/.wasp/out/sdk/wasp/dist/client/env.d.ts +waspBuild/.wasp/out/sdk/wasp/dist/client/env.js +waspBuild/.wasp/out/sdk/wasp/dist/client/env.js.map waspBuild/.wasp/out/sdk/wasp/dist/client/index.d.ts waspBuild/.wasp/out/sdk/wasp/dist/client/index.js waspBuild/.wasp/out/sdk/wasp/dist/client/index.js.map @@ -328,6 +343,9 @@ waspBuild/.wasp/out/sdk/wasp/dist/dev/index.js.map waspBuild/.wasp/out/sdk/wasp/dist/entities/index.d.ts waspBuild/.wasp/out/sdk/wasp/dist/entities/index.js waspBuild/.wasp/out/sdk/wasp/dist/entities/index.js.map +waspBuild/.wasp/out/sdk/wasp/dist/env/index.d.ts +waspBuild/.wasp/out/sdk/wasp/dist/env/index.js +waspBuild/.wasp/out/sdk/wasp/dist/env/index.js.map waspBuild/.wasp/out/sdk/wasp/dist/ext-src/MainPage.d.ts waspBuild/.wasp/out/sdk/wasp/dist/ext-src/MainPage.jsx waspBuild/.wasp/out/sdk/wasp/dist/ext-src/MainPage.jsx.map @@ -349,6 +367,9 @@ waspBuild/.wasp/out/sdk/wasp/dist/server/config.js.map waspBuild/.wasp/out/sdk/wasp/dist/server/dbClient.d.ts waspBuild/.wasp/out/sdk/wasp/dist/server/dbClient.js waspBuild/.wasp/out/sdk/wasp/dist/server/dbClient.js.map +waspBuild/.wasp/out/sdk/wasp/dist/server/env.d.ts +waspBuild/.wasp/out/sdk/wasp/dist/server/env.js +waspBuild/.wasp/out/sdk/wasp/dist/server/env.js.map waspBuild/.wasp/out/sdk/wasp/dist/server/index.d.ts waspBuild/.wasp/out/sdk/wasp/dist/server/index.js waspBuild/.wasp/out/sdk/wasp/dist/server/index.js.map @@ -392,6 +413,7 @@ waspBuild/.wasp/out/sdk/wasp/dist/universal/validators.d.ts waspBuild/.wasp/out/sdk/wasp/dist/universal/validators.js waspBuild/.wasp/out/sdk/wasp/dist/universal/validators.js.map waspBuild/.wasp/out/sdk/wasp/entities/index.ts +waspBuild/.wasp/out/sdk/wasp/env/index.ts waspBuild/.wasp/out/sdk/wasp/ext-src/Main.css waspBuild/.wasp/out/sdk/wasp/ext-src/MainPage.jsx waspBuild/.wasp/out/sdk/wasp/ext-src/vite-env.d.ts @@ -404,6 +426,7 @@ waspBuild/.wasp/out/sdk/wasp/server/_types/serialization.ts waspBuild/.wasp/out/sdk/wasp/server/_types/taggedEntities.ts waspBuild/.wasp/out/sdk/wasp/server/config.ts waspBuild/.wasp/out/sdk/wasp/server/dbClient.ts +waspBuild/.wasp/out/sdk/wasp/server/env.ts waspBuild/.wasp/out/sdk/wasp/server/index.ts waspBuild/.wasp/out/sdk/wasp/server/middleware/globalMiddleware.ts waspBuild/.wasp/out/sdk/wasp/server/middleware/index.ts diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/.waspchecksums b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/.waspchecksums index dffe3ed8c9..17e9cdd4db 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/.waspchecksums @@ -18,14 +18,21 @@ "file", "../out/sdk/wasp/client/config.ts" ], - "d94e8bee5fd8f6793b511652b9ee558e57f4913595763137a5385cd929648168" + "4c5835ad64352cc87a4a17e41fd70333bc0d1eedd7339d7ad3d3507cdb64038d" + ], + [ + [ + "file", + "../out/sdk/wasp/client/env.ts" + ], + "f630ded0392d5b60be93e1852f80ea8c75bc10262aee6fb106b6eb2561339362" ], [ [ "file", "../out/sdk/wasp/client/index.ts" ], - "2b3651e7040a63cfd6a271c2aa89f21cf01170e0abeb6c5ab74adde324852fe4" + "d5a83474d2db10e1ac90899a0e302503bf26b3ab5ab00c07b5f5ce0d9e6de2d4" ], [ [ @@ -167,6 +174,13 @@ ], "c59b97b122b977b5171686c92ee5ff2d80d397c2e83cc0915affb6ee136406fb" ], + [ + [ + "file", + "../out/sdk/wasp/env/index.ts" + ], + "cd4e86f3c0f1cacd868984f4103a47fe100037758adc8ba3adf1a5a9d6c1c880" + ], [ [ "file", @@ -200,7 +214,7 @@ "file", "../out/sdk/wasp/package.json" ], - "6f1afd30c951e1f49740256440cd626c9cb521cf0822d93d2d2a5d63d8719d7b" + "d18af37d0188a6c4c9eef72705e31caf179664cb8621eaacf8bc4c21bc57c212" ], [ [ @@ -242,7 +256,7 @@ "file", "../out/sdk/wasp/server/config.ts" ], - "5dd35660e0969defaa3c180179919f4922ab7bc041746872dff7f2280c1872ae" + "dd528b5db722210a5781f39c4d410024211f31964383bcc708a2611bd8d9d195" ], [ [ @@ -251,12 +265,19 @@ ], "50f11eb232174184be5fd44e8ee3875c30707b486c8c70c3f7bfb93609d38e66" ], + [ + [ + "file", + "../out/sdk/wasp/server/env.ts" + ], + "b6195fe1bead580b7e4009586a55066196c496f085e68505bafd767f7b0048cf" + ], [ [ "file", "../out/sdk/wasp/server/index.ts" ], - "51c3e0802764f72b88f6daaf148dba514ae817e233a40cc9b92ec91784f71f98" + "a8d2ffa7dfd0a13f7fb6135193bcdac1f860603bdd0ddc2843033fd4f6f6151f" ], [ [ @@ -347,7 +368,7 @@ "file", "../out/sdk/wasp/universal/url.ts" ], - "8dc6e044a1a231b796465d94985ca47c5efd42a5d411b407a7d83a61ebae4b6d" + "58ff4ad8ffc79264d7215461571d909f3c5fb177ff32c67058d1da9cd4115d6e" ], [ [ @@ -375,7 +396,7 @@ "file", "Dockerfile" ], - "8851d4e81582d58921a5646dcf063b31dbf8ce9a46f3d4710360d2047dc644b5" + "c7525922516652d1be259b7f1bf3a242e0ce1d3516c190aa0c28de57fe3d41de" ], [ [ @@ -417,7 +438,7 @@ "file", "server/package.json" ], - "a4eb7e59ac5309fc5c39ccd7e19f4fdc7a9a568a3b393f62358ef6a6065d65c3" + "eaaa1e16e4962f38deb7220a7439a26b920ed7f852890242d084b4cebc63b7c3" ], [ [ @@ -426,13 +447,6 @@ ], "c1beb8264f11898364288d73b16f08d1923bac5f70038d9827978deb5b58a2da" ], - [ - [ - "file", - "server/scripts/validate-env.mjs" - ], - "100177b4326ccab7362eff378315d532ad1cc17cd28d1ed5978cb167fd627746" - ], [ [ "file", diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/Dockerfile b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/Dockerfile index 44152eecda..df538e8aba 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/Dockerfile +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/Dockerfile @@ -53,12 +53,12 @@ COPY --from=server-builder /app/node_modules ./node_modules # Copying the SDK because 'validate-env.mjs' executes independent of the bundle # and references the 'wasp' package. COPY --from=server-builder /app/.wasp/out/sdk .wasp/out/sdk -# Copying 'server/node_modules' because 'validate-env.mjs' executes independent -# of the bundle and references the dotenv package. +# Copying 'server/node_modules' because we require dotenv package to +# load environment variables +# TODO: replace dotenv with native Node.js environment variable loading COPY --from=server-builder /app/.wasp/build/server/node_modules .wasp/build/server/node_modules COPY --from=server-builder /app/.wasp/build/server/bundle .wasp/build/server/bundle COPY --from=server-builder /app/.wasp/build/server/package*.json .wasp/build/server/ -COPY --from=server-builder /app/.wasp/build/server/scripts .wasp/build/server/scripts COPY db/ .wasp/build/db/ EXPOSE ${PORT} WORKDIR /app/.wasp/build/server diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/installedNpmDepsLog.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/installedNpmDepsLog.json index 88f5516a48..90c0d4bc56 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/installedNpmDepsLog.json +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/installedNpmDepsLog.json @@ -1 +1 @@ -{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file +{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"zod","version":"^3.23.8"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/client/config.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/client/config.ts index 82b0f80b6a..fff77cb01c 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/client/config.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/client/config.ts @@ -1,6 +1,7 @@ import { stripTrailingSlash } from '../universal/url.js' +import { env } from './env.js' -const apiUrl = stripTrailingSlash(import.meta.env.REACT_APP_API_URL) || 'http://localhost:3001'; +const apiUrl = stripTrailingSlash(env.REACT_APP_API_URL) // PUBLIC API export type ClientConfig = { diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/client/env.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/client/env.ts new file mode 100644 index 0000000000..dfa9e70ee3 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/client/env.ts @@ -0,0 +1,13 @@ +import * as z from 'zod' + +import { ensureEnvSchema } from '../env/index.js' + +const clientEnvSchema = z.object({ + REACT_APP_API_URL: z + .string({ + required_error: 'REACT_APP_API_URL is required', + }) + .default('http://localhost:3001') +}) + +export const env = ensureEnvSchema(import.meta.env, clientEnvSchema) diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/client/index.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/client/index.ts index cfce564c4d..33db447837 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/client/index.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/client/index.ts @@ -12,3 +12,6 @@ export type Route = { method: HttpMethod; path: string } // PUBLIC API export { config, ClientConfig } from './config' + +// PUBLIC API +export { env } from './env.js' diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/config.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/config.js index 1dffbd68bc..7e6149f386 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/config.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/config.js @@ -1,5 +1,6 @@ import { stripTrailingSlash } from '../universal/url.js'; -const apiUrl = stripTrailingSlash(import.meta.env.REACT_APP_API_URL) || 'http://localhost:3001'; +import { env } from './env.js'; +const apiUrl = stripTrailingSlash(env.REACT_APP_API_URL); // PUBLIC API export const config = { apiUrl, diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/config.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/config.js.map index d26d37022b..f9e186b838 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/config.js.map +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../client/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAExD,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,uBAAuB,CAAC;AAOhG,aAAa;AACb,MAAM,CAAC,MAAM,MAAM,GAAiB;IAClC,MAAM;CACP,CAAA"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../client/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;AAOxD,aAAa;AACb,MAAM,CAAC,MAAM,MAAM,GAAiB;IAClC,MAAM;CACP,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/env.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/env.d.ts new file mode 100644 index 0000000000..5a9417a810 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/env.d.ts @@ -0,0 +1,3 @@ +export declare const env: { + REACT_APP_API_URL: string; +}; diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/env.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/env.js new file mode 100644 index 0000000000..692179bc05 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/env.js @@ -0,0 +1,11 @@ +import * as z from 'zod'; +import { ensureEnvSchema } from '../env/index.js'; +const clientEnvSchema = z.object({ + REACT_APP_API_URL: z + .string({ + required_error: 'REACT_APP_API_URL is required', + }) + .default('http://localhost:3001') +}); +export const env = ensureEnvSchema(import.meta.env, clientEnvSchema); +//# sourceMappingURL=env.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/env.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/env.js.map new file mode 100644 index 0000000000..bde7e9e367 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/env.js.map @@ -0,0 +1 @@ +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../client/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,iBAAiB,EAAE,CAAC;SACjB,MAAM,CAAC;QACN,cAAc,EAAE,+BAA+B;KAChD,CAAC;SACD,OAAO,CAAC,uBAAuB,CAAC;CACpC,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/index.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/index.d.ts index 7f5f4bfbc8..d5196de766 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/index.d.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/index.d.ts @@ -9,3 +9,4 @@ export type Route = { path: string; }; export { config, ClientConfig } from './config'; +export { env } from './env.js'; diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/index.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/index.js index 5a7f13dcae..38dec51286 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/index.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/index.js @@ -9,4 +9,6 @@ export var HttpMethod; })(HttpMethod || (HttpMethod = {})); // PUBLIC API export { config } from './config'; +// PUBLIC API +export { env } from './env.js'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/index.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/index.js.map index 879953c8df..c827752797 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/index.js.map +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/client/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../client/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,mFAAmF;AACnF,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACrB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;AAClB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AAKD,aAAa;AACb,OAAO,EAAE,MAAM,EAAgB,MAAM,UAAU,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../client/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,mFAAmF;AACnF,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACrB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;AAClB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AAKD,aAAa;AACb,OAAO,EAAE,MAAM,EAAgB,MAAM,UAAU,CAAA;AAE/C,aAAa;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.d.ts new file mode 100644 index 0000000000..6bc9d059a3 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.d.ts @@ -0,0 +1,2 @@ +import * as z from 'zod'; +export declare function ensureEnvSchema(data: unknown, schema: Schema): z.infer; diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.js new file mode 100644 index 0000000000..a44104d78e --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.js @@ -0,0 +1,26 @@ +import * as z from 'zod'; +const redColor = '\x1b[31m'; +export function ensureEnvSchema(data, schema) { + try { + return schema.parse(data); + } + catch (e) { + // TODO: figure out how to output the error message in a better way + if (e instanceof z.ZodError) { + console.error(redColor, '╔═════════════════════════════╗'); + console.error(redColor, '║ Env vars validation failed ║'); + console.error(redColor, '╚═════════════════════════════╝'); + console.error(); + for (const error of e.errors) { + console.error(`- ${error.message}`); + } + console.error(); + console.error(redColor, '═══════════════════════════════'); + throw new Error('Error parsing environment variables'); + } + else { + throw e; + } + } +} +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.js.map new file mode 100644 index 0000000000..8cf4149a5b --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YACrC,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.js index e4f89082c8..f38fa5795a 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.js @@ -1,42 +1,35 @@ -var _a; import merge from 'lodash.merge'; -import { stripTrailingSlash } from "../universal/url.js"; -const nodeEnv = (_a = process.env.NODE_ENV) !== null && _a !== void 0 ? _a : 'development'; +import { env } from './env.js'; +import { stripTrailingSlash } from '../universal/url.js'; const config = { all: { - env: nodeEnv, - isDevelopment: nodeEnv === 'development', - port: process.env.PORT ? parseInt(process.env.PORT) : 3001, - databaseUrl: process.env.DATABASE_URL, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, allowedCORSOrigins: [], }, development: getDevelopmentConfig(), production: getProductionConfig(), }; -const resolvedConfig = merge(config.all, config[nodeEnv]); +const resolvedConfig = merge(config.all, config[env.NODE_ENV]); // PUBLIC API export default resolvedConfig; function getDevelopmentConfig() { - var _a, _b; - const frontendUrl = stripTrailingSlash((_a = process.env.WASP_WEB_CLIENT_URL) !== null && _a !== void 0 ? _a : 'http://localhost:3000/'); - const serverUrl = stripTrailingSlash((_b = process.env.WASP_SERVER_URL) !== null && _b !== void 0 ? _b : 'http://localhost:3001'); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, allowedCORSOrigins: '*', }; } function getProductionConfig() { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, - // @ts-ignore allowedCORSOrigins: [frontendUrl], }; } diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.js.map index e284580bbd..fe5abce123 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.js.map +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,QAAQ,mCAAI,aAAa,CAAA;AAyBrD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,OAAO;QACZ,aAAa,EAAE,OAAO,KAAK,aAAa;QACxC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;QAC1D,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;QACrC,kBAAkB,EAAE,EAAE;KACvB;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;AACjE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,mBAAmB,mCAAI,wBAAwB,CAAC,CAAC;IACpG,MAAM,SAAS,GAAG,kBAAkB,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,eAAe,mCAAI,uBAAuB,CAAC,CAAC;IAC7F,OAAO;QACL,aAAa;QACb,WAAW;QACX,aAAa;QACb,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACxE,MAAM,SAAS,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAClE,OAAO;QACL,aAAa;QACb,WAAW;QACX,aAAa;QACb,SAAS;QACT,aAAa;QACb,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAyBxD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,GAAG,CAAC,QAAQ;QACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;QAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,YAAY;QAC7B,kBAAkB,EAAE,EAAE;KACvB;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;AACtE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.d.ts new file mode 100644 index 0000000000..667ea30e35 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.d.ts @@ -0,0 +1,17 @@ +export declare const env: { + PORT: number; + DATABASE_URL: string; + SKIP_EMAIL_VERIFICATION_IN_DEV: boolean; + NODE_ENV: "development"; + WASP_SERVER_URL: string; + WASP_WEB_CLIENT_URL: string; + PG_BOSS_NEW_OPTIONS?: string | undefined; +} | { + PORT: number; + DATABASE_URL: string; + SKIP_EMAIL_VERIFICATION_IN_DEV: boolean; + NODE_ENV: "production"; + WASP_SERVER_URL: string; + WASP_WEB_CLIENT_URL: string; + PG_BOSS_NEW_OPTIONS?: string | undefined; +}; diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.js new file mode 100644 index 0000000000..d6bdbc9f66 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.js @@ -0,0 +1,48 @@ +import * as z from 'zod'; +import { ensureEnvSchema } from '../env/index.js'; +const serverCommonSchema = z.object({ + PORT: z.coerce.number().default(3001), + DATABASE_URL: z.string({ + required_error: 'DATABASE_URL is required', + }), + PG_BOSS_NEW_OPTIONS: z.string().optional(), + SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), +}); +const serverUrlSchema = z + .string({ + required_error: 'WASP_SERVER_URL is required', +}) + .url({ + message: 'WASP_SERVER_URL must be a valid URL', +}); +const clientUrlSchema = z + .string({ + required_error: 'WASP_WEB_CLIENT_URL is required', +}) + .url({ + message: 'WASP_WEB_CLIENT_URL must be a valid URL', +}); +const jwtTokenSchema = z + .string({ + required_error: 'JWT_SECRET is required', +}); +// In development, we provide default values for some environment variables +// to make the development process easier +const serverDevSchema = z.object({ + NODE_ENV: z.literal('development'), + WASP_SERVER_URL: serverUrlSchema + .default('http://localhost:3001'), + WASP_WEB_CLIENT_URL: clientUrlSchema + .default('http://localhost:3000/'), +}); +const serverProdSchema = z.object({ + NODE_ENV: z.literal('production'), + WASP_SERVER_URL: serverUrlSchema, + WASP_WEB_CLIENT_URL: clientUrlSchema, +}); +const serverEnvSchema = z.discriminatedUnion('NODE_ENV', [ + serverDevSchema.merge(serverCommonSchema), + serverProdSchema.merge(serverCommonSchema) +]); +export const env = ensureEnvSchema(process.env, serverEnvSchema); +//# sourceMappingURL=env.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.js.map new file mode 100644 index 0000000000..ecf2d3e0fa --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.js.map @@ -0,0 +1 @@ +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,8BAA8B,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;CAC3D,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;CACrC,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/index.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/index.d.ts index dee9613a53..a108f6123f 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/index.d.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/index.d.ts @@ -4,4 +4,5 @@ export { default as prisma } from './dbClient.js'; export { type ServerSetupFn } from './types/index.js'; export { HttpError } from './HttpError.js'; export { MiddlewareConfigFn } from './middleware/index.js'; +export { env } from './env.js'; export type DbSeedFn = (prisma: PrismaClient) => Promise; diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/index.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/index.js index 0e53e0deab..8e75e6f78c 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/index.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/index.js @@ -4,4 +4,6 @@ export { default as config } from './config.js'; export { default as prisma } from './dbClient.js'; // PUBLIC API export { HttpError } from './HttpError.js'; +// PUBLIC API +export { env } from './env.js'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/index.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/index.js.map index b84ac1b303..87ed22f3af 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/index.js.map +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/index.ts"],"names":[],"mappings":"AAEA,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,eAAe,CAAA;AAGjD,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/index.ts"],"names":[],"mappings":"AAEA,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,eAAe,CAAA;AAGjD,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG1C,aAAa;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/universal/url.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/universal/url.d.ts index aa893e7838..7ceb994694 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/universal/url.d.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/universal/url.d.ts @@ -1 +1,2 @@ -export declare function stripTrailingSlash(url?: string): string | undefined; +export declare function stripTrailingSlash(url: string): string; +export declare function stripTrailingSlash(url: undefined): undefined; diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/universal/url.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/universal/url.js.map index a7bad96020..e236f1b977 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/universal/url.js.map +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/universal/url.js.map @@ -1 +1 @@ -{"version":3,"file":"url.js","sourceRoot":"","sources":["../../universal/url.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC3C,OAAO,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC"} \ No newline at end of file +{"version":3,"file":"url.js","sourceRoot":"","sources":["../../universal/url.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC3C,OAAO,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/env/index.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/env/index.ts new file mode 100644 index 0000000000..5295a47f1a --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/env/index.ts @@ -0,0 +1,28 @@ +import * as z from 'zod' + +const redColor = '\x1b[31m' + +export function ensureEnvSchema( + data: unknown, + schema: Schema +): z.infer { + try { + return schema.parse(data) + } catch (e) { + // TODO: figure out how to output the error message in a better way + if (e instanceof z.ZodError) { + console.error(redColor, '╔═════════════════════════════╗'); + console.error(redColor, '║ Env vars validation failed ║'); + console.error(redColor, '╚═════════════════════════════╝'); + console.error() + for (const error of e.errors) { + console.error(`- ${error.message}`) + } + console.error() + console.error(redColor, '═══════════════════════════════'); + throw new Error('Error parsing environment variables') + } else { + throw e + } + } +} diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/package.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/package.json index 2589c5362f..cae34c05e7 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/package.json +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/package.json @@ -16,7 +16,8 @@ "react-hook-form": "^7.45.4", "react-router-dom": "^6.26.2", "superjson": "^2.2.1", - "vitest": "^1.2.1" + "vitest": "^1.2.1", + "zod": "^3.23.8" }, "devDependencies": { "@tsconfig/node18": "latest", diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/config.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/config.ts index 1dc9bafb93..27a7537a0f 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/config.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/config.ts @@ -1,8 +1,7 @@ import merge from 'lodash.merge' -import { stripTrailingSlash } from "../universal/url.js"; - -const nodeEnv = process.env.NODE_ENV ?? 'development' +import { env } from './env.js' +import { stripTrailingSlash } from '../universal/url.js' // TODO: // - Use dotenv library to consume env vars from a file. @@ -33,41 +32,36 @@ const config: { production: EnvConfig, } = { all: { - env: nodeEnv, - isDevelopment: nodeEnv === 'development', - port: process.env.PORT ? parseInt(process.env.PORT) : 3001, - databaseUrl: process.env.DATABASE_URL, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, allowedCORSOrigins: [], }, development: getDevelopmentConfig(), production: getProductionConfig(), } -const resolvedConfig: Config = merge(config.all, config[nodeEnv]) +const resolvedConfig: Config = merge(config.all, config[env.NODE_ENV]) // PUBLIC API export default resolvedConfig function getDevelopmentConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL ?? 'http://localhost:3000/'); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL ?? 'http://localhost:3001'); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, allowedCORSOrigins: '*', } } function getProductionConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, - // @ts-ignore allowedCORSOrigins: [frontendUrl], } } diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/env.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/env.ts new file mode 100644 index 0000000000..cd30bc35f5 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/env.ts @@ -0,0 +1,56 @@ +import * as z from 'zod' + +import { ensureEnvSchema } from '../env/index.js' + +const serverCommonSchema = z.object({ + PORT: z.coerce.number().default(3001), + DATABASE_URL: z.string({ + required_error: 'DATABASE_URL is required', + }), + PG_BOSS_NEW_OPTIONS: z.string().optional(), + SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), +}) + +const serverUrlSchema = z + .string({ + required_error: 'WASP_SERVER_URL is required', + }) + .url({ + message: 'WASP_SERVER_URL must be a valid URL', + }) + +const clientUrlSchema = z + .string({ + required_error: 'WASP_WEB_CLIENT_URL is required', + }) + .url({ + message: 'WASP_WEB_CLIENT_URL must be a valid URL', + }) + +const jwtTokenSchema = z + .string({ + required_error: 'JWT_SECRET is required', + }) + +// In development, we provide default values for some environment variables +// to make the development process easier +const serverDevSchema = z.object({ + NODE_ENV: z.literal('development'), + WASP_SERVER_URL: serverUrlSchema + .default('http://localhost:3001'), + WASP_WEB_CLIENT_URL: clientUrlSchema + .default('http://localhost:3000/'), +}) + +const serverProdSchema = z.object({ + NODE_ENV: z.literal('production'), + WASP_SERVER_URL: serverUrlSchema, + WASP_WEB_CLIENT_URL: clientUrlSchema, +}) + +const serverEnvSchema = z.discriminatedUnion('NODE_ENV', [ + serverDevSchema.merge(serverCommonSchema), + serverProdSchema.merge(serverCommonSchema) +]) + +export const env = ensureEnvSchema(process.env, serverEnvSchema) diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/index.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/index.ts index 535077900b..0f95deb90a 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/index.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/index.ts @@ -10,6 +10,8 @@ export { type ServerSetupFn } from './types/index.js' export { HttpError } from './HttpError.js' // PUBLIC API export { MiddlewareConfigFn } from './middleware/index.js' +// PUBLIC API +export { env } from './env.js' // PUBLIC API export type DbSeedFn = (prisma: PrismaClient) => Promise diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/universal/url.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/universal/url.ts index d21c06c65c..126678dac9 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/universal/url.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/universal/url.ts @@ -1,3 +1,5 @@ +export function stripTrailingSlash(url: string): string +export function stripTrailingSlash(url: undefined): undefined export function stripTrailingSlash(url?: string): string | undefined { return url?.replace(/\/$/, ""); } diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/package.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/package.json index 7a57413e11..51ec87354a 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/package.json +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/package.json @@ -34,9 +34,8 @@ "bundle-and-start": "npm run bundle && npm run start", "db-migrate-prod": "prisma migrate deploy --schema=../db/schema.prisma", "db-seed": "npm run bundle && node --enable-source-maps -r dotenv/config bundle/dbSeed.js", - "start": "npm run validate-env && node --enable-source-maps -r dotenv/config bundle/server.js", + "start": "node --enable-source-maps -r dotenv/config bundle/server.js", "start-production": "NODE_ENV=production npm run start", - "validate-env": "node -r dotenv/config ./scripts/validate-env.mjs", "watch": "nodemon --exec 'npm run bundle-and-start || exit 1'" }, "type": "module", diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/scripts/validate-env.mjs b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/scripts/validate-env.mjs deleted file mode 100644 index f6e50aceca..0000000000 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/scripts/validate-env.mjs +++ /dev/null @@ -1,5 +0,0 @@ -import { throwIfNotValidAbsoluteURL } from 'wasp/universal/validators'; - -console.info("🔍 Validating environment variables..."); -throwIfNotValidAbsoluteURL(process.env.WASP_WEB_CLIENT_URL, 'Environment variable WASP_WEB_CLIENT_URL'); -throwIfNotValidAbsoluteURL(process.env.WASP_SERVER_URL, 'Environment variable WASP_SERVER_URL'); diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/client/config.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/client/config.ts index 82b0f80b6a..fff77cb01c 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/client/config.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/client/config.ts @@ -1,6 +1,7 @@ import { stripTrailingSlash } from '../universal/url.js' +import { env } from './env.js' -const apiUrl = stripTrailingSlash(import.meta.env.REACT_APP_API_URL) || 'http://localhost:3001'; +const apiUrl = stripTrailingSlash(env.REACT_APP_API_URL) // PUBLIC API export type ClientConfig = { diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/client/env.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/client/env.ts new file mode 100644 index 0000000000..dfa9e70ee3 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/client/env.ts @@ -0,0 +1,13 @@ +import * as z from 'zod' + +import { ensureEnvSchema } from '../env/index.js' + +const clientEnvSchema = z.object({ + REACT_APP_API_URL: z + .string({ + required_error: 'REACT_APP_API_URL is required', + }) + .default('http://localhost:3001') +}) + +export const env = ensureEnvSchema(import.meta.env, clientEnvSchema) diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/client/index.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/client/index.ts index cfce564c4d..33db447837 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/client/index.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/client/index.ts @@ -12,3 +12,6 @@ export type Route = { method: HttpMethod; path: string } // PUBLIC API export { config, ClientConfig } from './config' + +// PUBLIC API +export { env } from './env.js' diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/config.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/config.js index 1dffbd68bc..7e6149f386 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/config.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/config.js @@ -1,5 +1,6 @@ import { stripTrailingSlash } from '../universal/url.js'; -const apiUrl = stripTrailingSlash(import.meta.env.REACT_APP_API_URL) || 'http://localhost:3001'; +import { env } from './env.js'; +const apiUrl = stripTrailingSlash(env.REACT_APP_API_URL); // PUBLIC API export const config = { apiUrl, diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/config.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/config.js.map index d26d37022b..f9e186b838 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/config.js.map +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../client/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAExD,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,uBAAuB,CAAC;AAOhG,aAAa;AACb,MAAM,CAAC,MAAM,MAAM,GAAiB;IAClC,MAAM;CACP,CAAA"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../client/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;AAOxD,aAAa;AACb,MAAM,CAAC,MAAM,MAAM,GAAiB;IAClC,MAAM;CACP,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/env.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/env.d.ts new file mode 100644 index 0000000000..5a9417a810 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/env.d.ts @@ -0,0 +1,3 @@ +export declare const env: { + REACT_APP_API_URL: string; +}; diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/env.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/env.js new file mode 100644 index 0000000000..692179bc05 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/env.js @@ -0,0 +1,11 @@ +import * as z from 'zod'; +import { ensureEnvSchema } from '../env/index.js'; +const clientEnvSchema = z.object({ + REACT_APP_API_URL: z + .string({ + required_error: 'REACT_APP_API_URL is required', + }) + .default('http://localhost:3001') +}); +export const env = ensureEnvSchema(import.meta.env, clientEnvSchema); +//# sourceMappingURL=env.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/env.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/env.js.map new file mode 100644 index 0000000000..bde7e9e367 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/env.js.map @@ -0,0 +1 @@ +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../client/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,iBAAiB,EAAE,CAAC;SACjB,MAAM,CAAC;QACN,cAAc,EAAE,+BAA+B;KAChD,CAAC;SACD,OAAO,CAAC,uBAAuB,CAAC;CACpC,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/index.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/index.d.ts index 7f5f4bfbc8..d5196de766 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/index.d.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/index.d.ts @@ -9,3 +9,4 @@ export type Route = { path: string; }; export { config, ClientConfig } from './config'; +export { env } from './env.js'; diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/index.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/index.js index 5a7f13dcae..38dec51286 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/index.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/index.js @@ -9,4 +9,6 @@ export var HttpMethod; })(HttpMethod || (HttpMethod = {})); // PUBLIC API export { config } from './config'; +// PUBLIC API +export { env } from './env.js'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/index.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/index.js.map index 879953c8df..c827752797 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/index.js.map +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/client/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../client/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,mFAAmF;AACnF,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACrB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;AAClB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AAKD,aAAa;AACb,OAAO,EAAE,MAAM,EAAgB,MAAM,UAAU,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../client/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,mFAAmF;AACnF,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACrB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;AAClB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AAKD,aAAa;AACb,OAAO,EAAE,MAAM,EAAgB,MAAM,UAAU,CAAA;AAE/C,aAAa;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.d.ts new file mode 100644 index 0000000000..6bc9d059a3 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.d.ts @@ -0,0 +1,2 @@ +import * as z from 'zod'; +export declare function ensureEnvSchema(data: unknown, schema: Schema): z.infer; diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.js new file mode 100644 index 0000000000..a44104d78e --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.js @@ -0,0 +1,26 @@ +import * as z from 'zod'; +const redColor = '\x1b[31m'; +export function ensureEnvSchema(data, schema) { + try { + return schema.parse(data); + } + catch (e) { + // TODO: figure out how to output the error message in a better way + if (e instanceof z.ZodError) { + console.error(redColor, '╔═════════════════════════════╗'); + console.error(redColor, '║ Env vars validation failed ║'); + console.error(redColor, '╚═════════════════════════════╝'); + console.error(); + for (const error of e.errors) { + console.error(`- ${error.message}`); + } + console.error(); + console.error(redColor, '═══════════════════════════════'); + throw new Error('Error parsing environment variables'); + } + else { + throw e; + } + } +} +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.js.map new file mode 100644 index 0000000000..8cf4149a5b --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YACrC,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.js index e4f89082c8..f38fa5795a 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.js @@ -1,42 +1,35 @@ -var _a; import merge from 'lodash.merge'; -import { stripTrailingSlash } from "../universal/url.js"; -const nodeEnv = (_a = process.env.NODE_ENV) !== null && _a !== void 0 ? _a : 'development'; +import { env } from './env.js'; +import { stripTrailingSlash } from '../universal/url.js'; const config = { all: { - env: nodeEnv, - isDevelopment: nodeEnv === 'development', - port: process.env.PORT ? parseInt(process.env.PORT) : 3001, - databaseUrl: process.env.DATABASE_URL, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, allowedCORSOrigins: [], }, development: getDevelopmentConfig(), production: getProductionConfig(), }; -const resolvedConfig = merge(config.all, config[nodeEnv]); +const resolvedConfig = merge(config.all, config[env.NODE_ENV]); // PUBLIC API export default resolvedConfig; function getDevelopmentConfig() { - var _a, _b; - const frontendUrl = stripTrailingSlash((_a = process.env.WASP_WEB_CLIENT_URL) !== null && _a !== void 0 ? _a : 'http://localhost:3000/'); - const serverUrl = stripTrailingSlash((_b = process.env.WASP_SERVER_URL) !== null && _b !== void 0 ? _b : 'http://localhost:3001'); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, allowedCORSOrigins: '*', }; } function getProductionConfig() { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, - // @ts-ignore allowedCORSOrigins: [frontendUrl], }; } diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.js.map index e284580bbd..fe5abce123 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.js.map +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,QAAQ,mCAAI,aAAa,CAAA;AAyBrD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,OAAO;QACZ,aAAa,EAAE,OAAO,KAAK,aAAa;QACxC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;QAC1D,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;QACrC,kBAAkB,EAAE,EAAE;KACvB;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;AACjE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,mBAAmB,mCAAI,wBAAwB,CAAC,CAAC;IACpG,MAAM,SAAS,GAAG,kBAAkB,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,eAAe,mCAAI,uBAAuB,CAAC,CAAC;IAC7F,OAAO;QACL,aAAa;QACb,WAAW;QACX,aAAa;QACb,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACxE,MAAM,SAAS,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAClE,OAAO;QACL,aAAa;QACb,WAAW;QACX,aAAa;QACb,SAAS;QACT,aAAa;QACb,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAyBxD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,GAAG,CAAC,QAAQ;QACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;QAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,YAAY;QAC7B,kBAAkB,EAAE,EAAE;KACvB;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;AACtE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.d.ts new file mode 100644 index 0000000000..667ea30e35 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.d.ts @@ -0,0 +1,17 @@ +export declare const env: { + PORT: number; + DATABASE_URL: string; + SKIP_EMAIL_VERIFICATION_IN_DEV: boolean; + NODE_ENV: "development"; + WASP_SERVER_URL: string; + WASP_WEB_CLIENT_URL: string; + PG_BOSS_NEW_OPTIONS?: string | undefined; +} | { + PORT: number; + DATABASE_URL: string; + SKIP_EMAIL_VERIFICATION_IN_DEV: boolean; + NODE_ENV: "production"; + WASP_SERVER_URL: string; + WASP_WEB_CLIENT_URL: string; + PG_BOSS_NEW_OPTIONS?: string | undefined; +}; diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.js new file mode 100644 index 0000000000..d6bdbc9f66 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.js @@ -0,0 +1,48 @@ +import * as z from 'zod'; +import { ensureEnvSchema } from '../env/index.js'; +const serverCommonSchema = z.object({ + PORT: z.coerce.number().default(3001), + DATABASE_URL: z.string({ + required_error: 'DATABASE_URL is required', + }), + PG_BOSS_NEW_OPTIONS: z.string().optional(), + SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), +}); +const serverUrlSchema = z + .string({ + required_error: 'WASP_SERVER_URL is required', +}) + .url({ + message: 'WASP_SERVER_URL must be a valid URL', +}); +const clientUrlSchema = z + .string({ + required_error: 'WASP_WEB_CLIENT_URL is required', +}) + .url({ + message: 'WASP_WEB_CLIENT_URL must be a valid URL', +}); +const jwtTokenSchema = z + .string({ + required_error: 'JWT_SECRET is required', +}); +// In development, we provide default values for some environment variables +// to make the development process easier +const serverDevSchema = z.object({ + NODE_ENV: z.literal('development'), + WASP_SERVER_URL: serverUrlSchema + .default('http://localhost:3001'), + WASP_WEB_CLIENT_URL: clientUrlSchema + .default('http://localhost:3000/'), +}); +const serverProdSchema = z.object({ + NODE_ENV: z.literal('production'), + WASP_SERVER_URL: serverUrlSchema, + WASP_WEB_CLIENT_URL: clientUrlSchema, +}); +const serverEnvSchema = z.discriminatedUnion('NODE_ENV', [ + serverDevSchema.merge(serverCommonSchema), + serverProdSchema.merge(serverCommonSchema) +]); +export const env = ensureEnvSchema(process.env, serverEnvSchema); +//# sourceMappingURL=env.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.js.map new file mode 100644 index 0000000000..ecf2d3e0fa --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.js.map @@ -0,0 +1 @@ +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,8BAA8B,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;CAC3D,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;CACrC,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/index.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/index.d.ts index dee9613a53..a108f6123f 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/index.d.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/index.d.ts @@ -4,4 +4,5 @@ export { default as prisma } from './dbClient.js'; export { type ServerSetupFn } from './types/index.js'; export { HttpError } from './HttpError.js'; export { MiddlewareConfigFn } from './middleware/index.js'; +export { env } from './env.js'; export type DbSeedFn = (prisma: PrismaClient) => Promise; diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/index.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/index.js index 0e53e0deab..8e75e6f78c 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/index.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/index.js @@ -4,4 +4,6 @@ export { default as config } from './config.js'; export { default as prisma } from './dbClient.js'; // PUBLIC API export { HttpError } from './HttpError.js'; +// PUBLIC API +export { env } from './env.js'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/index.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/index.js.map index b84ac1b303..87ed22f3af 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/index.js.map +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/index.ts"],"names":[],"mappings":"AAEA,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,eAAe,CAAA;AAGjD,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/index.ts"],"names":[],"mappings":"AAEA,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,eAAe,CAAA;AAGjD,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG1C,aAAa;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/universal/url.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/universal/url.d.ts index aa893e7838..7ceb994694 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/universal/url.d.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/universal/url.d.ts @@ -1 +1,2 @@ -export declare function stripTrailingSlash(url?: string): string | undefined; +export declare function stripTrailingSlash(url: string): string; +export declare function stripTrailingSlash(url: undefined): undefined; diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/universal/url.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/universal/url.js.map index a7bad96020..e236f1b977 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/universal/url.js.map +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/universal/url.js.map @@ -1 +1 @@ -{"version":3,"file":"url.js","sourceRoot":"","sources":["../../universal/url.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC3C,OAAO,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC"} \ No newline at end of file +{"version":3,"file":"url.js","sourceRoot":"","sources":["../../universal/url.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC3C,OAAO,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/env/index.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/env/index.ts new file mode 100644 index 0000000000..5295a47f1a --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/env/index.ts @@ -0,0 +1,28 @@ +import * as z from 'zod' + +const redColor = '\x1b[31m' + +export function ensureEnvSchema( + data: unknown, + schema: Schema +): z.infer { + try { + return schema.parse(data) + } catch (e) { + // TODO: figure out how to output the error message in a better way + if (e instanceof z.ZodError) { + console.error(redColor, '╔═════════════════════════════╗'); + console.error(redColor, '║ Env vars validation failed ║'); + console.error(redColor, '╚═════════════════════════════╝'); + console.error() + for (const error of e.errors) { + console.error(`- ${error.message}`) + } + console.error() + console.error(redColor, '═══════════════════════════════'); + throw new Error('Error parsing environment variables') + } else { + throw e + } + } +} diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/package.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/package.json index 2589c5362f..cae34c05e7 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/package.json +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/package.json @@ -16,7 +16,8 @@ "react-hook-form": "^7.45.4", "react-router-dom": "^6.26.2", "superjson": "^2.2.1", - "vitest": "^1.2.1" + "vitest": "^1.2.1", + "zod": "^3.23.8" }, "devDependencies": { "@tsconfig/node18": "latest", diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/config.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/config.ts index 1dc9bafb93..27a7537a0f 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/config.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/config.ts @@ -1,8 +1,7 @@ import merge from 'lodash.merge' -import { stripTrailingSlash } from "../universal/url.js"; - -const nodeEnv = process.env.NODE_ENV ?? 'development' +import { env } from './env.js' +import { stripTrailingSlash } from '../universal/url.js' // TODO: // - Use dotenv library to consume env vars from a file. @@ -33,41 +32,36 @@ const config: { production: EnvConfig, } = { all: { - env: nodeEnv, - isDevelopment: nodeEnv === 'development', - port: process.env.PORT ? parseInt(process.env.PORT) : 3001, - databaseUrl: process.env.DATABASE_URL, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, allowedCORSOrigins: [], }, development: getDevelopmentConfig(), production: getProductionConfig(), } -const resolvedConfig: Config = merge(config.all, config[nodeEnv]) +const resolvedConfig: Config = merge(config.all, config[env.NODE_ENV]) // PUBLIC API export default resolvedConfig function getDevelopmentConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL ?? 'http://localhost:3000/'); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL ?? 'http://localhost:3001'); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, allowedCORSOrigins: '*', } } function getProductionConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, - // @ts-ignore allowedCORSOrigins: [frontendUrl], } } diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/env.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/env.ts new file mode 100644 index 0000000000..cd30bc35f5 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/env.ts @@ -0,0 +1,56 @@ +import * as z from 'zod' + +import { ensureEnvSchema } from '../env/index.js' + +const serverCommonSchema = z.object({ + PORT: z.coerce.number().default(3001), + DATABASE_URL: z.string({ + required_error: 'DATABASE_URL is required', + }), + PG_BOSS_NEW_OPTIONS: z.string().optional(), + SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), +}) + +const serverUrlSchema = z + .string({ + required_error: 'WASP_SERVER_URL is required', + }) + .url({ + message: 'WASP_SERVER_URL must be a valid URL', + }) + +const clientUrlSchema = z + .string({ + required_error: 'WASP_WEB_CLIENT_URL is required', + }) + .url({ + message: 'WASP_WEB_CLIENT_URL must be a valid URL', + }) + +const jwtTokenSchema = z + .string({ + required_error: 'JWT_SECRET is required', + }) + +// In development, we provide default values for some environment variables +// to make the development process easier +const serverDevSchema = z.object({ + NODE_ENV: z.literal('development'), + WASP_SERVER_URL: serverUrlSchema + .default('http://localhost:3001'), + WASP_WEB_CLIENT_URL: clientUrlSchema + .default('http://localhost:3000/'), +}) + +const serverProdSchema = z.object({ + NODE_ENV: z.literal('production'), + WASP_SERVER_URL: serverUrlSchema, + WASP_WEB_CLIENT_URL: clientUrlSchema, +}) + +const serverEnvSchema = z.discriminatedUnion('NODE_ENV', [ + serverDevSchema.merge(serverCommonSchema), + serverProdSchema.merge(serverCommonSchema) +]) + +export const env = ensureEnvSchema(process.env, serverEnvSchema) diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/index.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/index.ts index 535077900b..0f95deb90a 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/index.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/index.ts @@ -10,6 +10,8 @@ export { type ServerSetupFn } from './types/index.js' export { HttpError } from './HttpError.js' // PUBLIC API export { MiddlewareConfigFn } from './middleware/index.js' +// PUBLIC API +export { env } from './env.js' // PUBLIC API export type DbSeedFn = (prisma: PrismaClient) => Promise diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/universal/url.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/universal/url.ts index d21c06c65c..126678dac9 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/universal/url.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/universal/url.ts @@ -1,3 +1,5 @@ +export function stripTrailingSlash(url: string): string +export function stripTrailingSlash(url: undefined): undefined export function stripTrailingSlash(url?: string): string | undefined { return url?.replace(/\/$/, ""); } diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/files.manifest b/waspc/e2e-test/test-outputs/waspCompile-golden/files.manifest index be6525f517..c142de0718 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/files.manifest +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/files.manifest @@ -6,6 +6,7 @@ waspCompile/.wasp/out/installedNpmDepsLog.json waspCompile/.wasp/out/sdk/wasp/api/events.ts waspCompile/.wasp/out/sdk/wasp/api/index.ts waspCompile/.wasp/out/sdk/wasp/client/config.ts +waspCompile/.wasp/out/sdk/wasp/client/env.ts waspCompile/.wasp/out/sdk/wasp/client/index.ts waspCompile/.wasp/out/sdk/wasp/client/operations/actions/core.ts waspCompile/.wasp/out/sdk/wasp/client/operations/actions/index.ts @@ -35,6 +36,9 @@ waspCompile/.wasp/out/sdk/wasp/dist/api/index.js.map waspCompile/.wasp/out/sdk/wasp/dist/client/config.d.ts waspCompile/.wasp/out/sdk/wasp/dist/client/config.js waspCompile/.wasp/out/sdk/wasp/dist/client/config.js.map +waspCompile/.wasp/out/sdk/wasp/dist/client/env.d.ts +waspCompile/.wasp/out/sdk/wasp/dist/client/env.js +waspCompile/.wasp/out/sdk/wasp/dist/client/env.js.map waspCompile/.wasp/out/sdk/wasp/dist/client/index.d.ts waspCompile/.wasp/out/sdk/wasp/dist/client/index.js waspCompile/.wasp/out/sdk/wasp/dist/client/index.js.map @@ -98,6 +102,9 @@ waspCompile/.wasp/out/sdk/wasp/dist/dev/index.js.map waspCompile/.wasp/out/sdk/wasp/dist/entities/index.d.ts waspCompile/.wasp/out/sdk/wasp/dist/entities/index.js waspCompile/.wasp/out/sdk/wasp/dist/entities/index.js.map +waspCompile/.wasp/out/sdk/wasp/dist/env/index.d.ts +waspCompile/.wasp/out/sdk/wasp/dist/env/index.js +waspCompile/.wasp/out/sdk/wasp/dist/env/index.js.map waspCompile/.wasp/out/sdk/wasp/dist/ext-src/MainPage.d.ts waspCompile/.wasp/out/sdk/wasp/dist/ext-src/MainPage.jsx waspCompile/.wasp/out/sdk/wasp/dist/ext-src/MainPage.jsx.map @@ -119,6 +126,9 @@ waspCompile/.wasp/out/sdk/wasp/dist/server/config.js.map waspCompile/.wasp/out/sdk/wasp/dist/server/dbClient.d.ts waspCompile/.wasp/out/sdk/wasp/dist/server/dbClient.js waspCompile/.wasp/out/sdk/wasp/dist/server/dbClient.js.map +waspCompile/.wasp/out/sdk/wasp/dist/server/env.d.ts +waspCompile/.wasp/out/sdk/wasp/dist/server/env.js +waspCompile/.wasp/out/sdk/wasp/dist/server/env.js.map waspCompile/.wasp/out/sdk/wasp/dist/server/index.d.ts waspCompile/.wasp/out/sdk/wasp/dist/server/index.js waspCompile/.wasp/out/sdk/wasp/dist/server/index.js.map @@ -162,6 +172,7 @@ waspCompile/.wasp/out/sdk/wasp/dist/universal/validators.d.ts waspCompile/.wasp/out/sdk/wasp/dist/universal/validators.js waspCompile/.wasp/out/sdk/wasp/dist/universal/validators.js.map waspCompile/.wasp/out/sdk/wasp/entities/index.ts +waspCompile/.wasp/out/sdk/wasp/env/index.ts waspCompile/.wasp/out/sdk/wasp/ext-src/Main.css waspCompile/.wasp/out/sdk/wasp/ext-src/MainPage.jsx waspCompile/.wasp/out/sdk/wasp/ext-src/vite-env.d.ts @@ -174,6 +185,7 @@ waspCompile/.wasp/out/sdk/wasp/server/_types/serialization.ts waspCompile/.wasp/out/sdk/wasp/server/_types/taggedEntities.ts waspCompile/.wasp/out/sdk/wasp/server/config.ts waspCompile/.wasp/out/sdk/wasp/server/dbClient.ts +waspCompile/.wasp/out/sdk/wasp/server/env.ts waspCompile/.wasp/out/sdk/wasp/server/index.ts waspCompile/.wasp/out/sdk/wasp/server/middleware/globalMiddleware.ts waspCompile/.wasp/out/sdk/wasp/server/middleware/index.ts @@ -196,7 +208,6 @@ waspCompile/.wasp/out/server/README.md waspCompile/.wasp/out/server/nodemon.json waspCompile/.wasp/out/server/package.json waspCompile/.wasp/out/server/rollup.config.js -waspCompile/.wasp/out/server/scripts/validate-env.mjs waspCompile/.wasp/out/server/src/app.js waspCompile/.wasp/out/server/src/middleware/globalMiddleware.ts waspCompile/.wasp/out/server/src/middleware/index.ts diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/.waspchecksums b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/.waspchecksums index f4cda53651..aca879273e 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/.waspchecksums @@ -18,14 +18,21 @@ "file", "../out/sdk/wasp/client/config.ts" ], - "d94e8bee5fd8f6793b511652b9ee558e57f4913595763137a5385cd929648168" + "4c5835ad64352cc87a4a17e41fd70333bc0d1eedd7339d7ad3d3507cdb64038d" + ], + [ + [ + "file", + "../out/sdk/wasp/client/env.ts" + ], + "f630ded0392d5b60be93e1852f80ea8c75bc10262aee6fb106b6eb2561339362" ], [ [ "file", "../out/sdk/wasp/client/index.ts" ], - "2b3651e7040a63cfd6a271c2aa89f21cf01170e0abeb6c5ab74adde324852fe4" + "d5a83474d2db10e1ac90899a0e302503bf26b3ab5ab00c07b5f5ce0d9e6de2d4" ], [ [ @@ -167,6 +174,13 @@ ], "c59b97b122b977b5171686c92ee5ff2d80d397c2e83cc0915affb6ee136406fb" ], + [ + [ + "file", + "../out/sdk/wasp/env/index.ts" + ], + "cd4e86f3c0f1cacd868984f4103a47fe100037758adc8ba3adf1a5a9d6c1c880" + ], [ [ "file", @@ -200,7 +214,7 @@ "file", "../out/sdk/wasp/package.json" ], - "6f1afd30c951e1f49740256440cd626c9cb521cf0822d93d2d2a5d63d8719d7b" + "d18af37d0188a6c4c9eef72705e31caf179664cb8621eaacf8bc4c21bc57c212" ], [ [ @@ -242,7 +256,7 @@ "file", "../out/sdk/wasp/server/config.ts" ], - "5dd35660e0969defaa3c180179919f4922ab7bc041746872dff7f2280c1872ae" + "dd528b5db722210a5781f39c4d410024211f31964383bcc708a2611bd8d9d195" ], [ [ @@ -251,12 +265,19 @@ ], "50f11eb232174184be5fd44e8ee3875c30707b486c8c70c3f7bfb93609d38e66" ], + [ + [ + "file", + "../out/sdk/wasp/server/env.ts" + ], + "b6195fe1bead580b7e4009586a55066196c496f085e68505bafd767f7b0048cf" + ], [ [ "file", "../out/sdk/wasp/server/index.ts" ], - "51c3e0802764f72b88f6daaf148dba514ae817e233a40cc9b92ec91784f71f98" + "a8d2ffa7dfd0a13f7fb6135193bcdac1f860603bdd0ddc2843033fd4f6f6151f" ], [ [ @@ -347,7 +368,7 @@ "file", "../out/sdk/wasp/universal/url.ts" ], - "8dc6e044a1a231b796465d94985ca47c5efd42a5d411b407a7d83a61ebae4b6d" + "58ff4ad8ffc79264d7215461571d909f3c5fb177ff32c67058d1da9cd4115d6e" ], [ [ @@ -375,7 +396,7 @@ "file", "Dockerfile" ], - "8851d4e81582d58921a5646dcf063b31dbf8ce9a46f3d4710360d2047dc644b5" + "c7525922516652d1be259b7f1bf3a242e0ce1d3516c190aa0c28de57fe3d41de" ], [ [ @@ -424,7 +445,7 @@ "file", "server/package.json" ], - "a4eb7e59ac5309fc5c39ccd7e19f4fdc7a9a568a3b393f62358ef6a6065d65c3" + "eaaa1e16e4962f38deb7220a7439a26b920ed7f852890242d084b4cebc63b7c3" ], [ [ @@ -433,13 +454,6 @@ ], "c1beb8264f11898364288d73b16f08d1923bac5f70038d9827978deb5b58a2da" ], - [ - [ - "file", - "server/scripts/validate-env.mjs" - ], - "100177b4326ccab7362eff378315d532ad1cc17cd28d1ed5978cb167fd627746" - ], [ [ "file", diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/Dockerfile b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/Dockerfile index 44152eecda..df538e8aba 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/Dockerfile +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/Dockerfile @@ -53,12 +53,12 @@ COPY --from=server-builder /app/node_modules ./node_modules # Copying the SDK because 'validate-env.mjs' executes independent of the bundle # and references the 'wasp' package. COPY --from=server-builder /app/.wasp/out/sdk .wasp/out/sdk -# Copying 'server/node_modules' because 'validate-env.mjs' executes independent -# of the bundle and references the dotenv package. +# Copying 'server/node_modules' because we require dotenv package to +# load environment variables +# TODO: replace dotenv with native Node.js environment variable loading COPY --from=server-builder /app/.wasp/build/server/node_modules .wasp/build/server/node_modules COPY --from=server-builder /app/.wasp/build/server/bundle .wasp/build/server/bundle COPY --from=server-builder /app/.wasp/build/server/package*.json .wasp/build/server/ -COPY --from=server-builder /app/.wasp/build/server/scripts .wasp/build/server/scripts COPY db/ .wasp/build/db/ EXPOSE ${PORT} WORKDIR /app/.wasp/build/server diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/installedNpmDepsLog.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/installedNpmDepsLog.json index 88f5516a48..90c0d4bc56 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/installedNpmDepsLog.json +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/installedNpmDepsLog.json @@ -1 +1 @@ -{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file +{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"zod","version":"^3.23.8"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/client/config.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/client/config.ts index 82b0f80b6a..fff77cb01c 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/client/config.ts +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/client/config.ts @@ -1,6 +1,7 @@ import { stripTrailingSlash } from '../universal/url.js' +import { env } from './env.js' -const apiUrl = stripTrailingSlash(import.meta.env.REACT_APP_API_URL) || 'http://localhost:3001'; +const apiUrl = stripTrailingSlash(env.REACT_APP_API_URL) // PUBLIC API export type ClientConfig = { diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/client/env.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/client/env.ts new file mode 100644 index 0000000000..dfa9e70ee3 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/client/env.ts @@ -0,0 +1,13 @@ +import * as z from 'zod' + +import { ensureEnvSchema } from '../env/index.js' + +const clientEnvSchema = z.object({ + REACT_APP_API_URL: z + .string({ + required_error: 'REACT_APP_API_URL is required', + }) + .default('http://localhost:3001') +}) + +export const env = ensureEnvSchema(import.meta.env, clientEnvSchema) diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/client/index.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/client/index.ts index cfce564c4d..33db447837 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/client/index.ts +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/client/index.ts @@ -12,3 +12,6 @@ export type Route = { method: HttpMethod; path: string } // PUBLIC API export { config, ClientConfig } from './config' + +// PUBLIC API +export { env } from './env.js' diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/config.js b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/config.js index 1dffbd68bc..7e6149f386 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/config.js +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/config.js @@ -1,5 +1,6 @@ import { stripTrailingSlash } from '../universal/url.js'; -const apiUrl = stripTrailingSlash(import.meta.env.REACT_APP_API_URL) || 'http://localhost:3001'; +import { env } from './env.js'; +const apiUrl = stripTrailingSlash(env.REACT_APP_API_URL); // PUBLIC API export const config = { apiUrl, diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/config.js.map b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/config.js.map index d26d37022b..f9e186b838 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/config.js.map +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../client/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAExD,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,uBAAuB,CAAC;AAOhG,aAAa;AACb,MAAM,CAAC,MAAM,MAAM,GAAiB;IAClC,MAAM;CACP,CAAA"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../client/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;AAOxD,aAAa;AACb,MAAM,CAAC,MAAM,MAAM,GAAiB;IAClC,MAAM;CACP,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/env.d.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/env.d.ts new file mode 100644 index 0000000000..5a9417a810 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/env.d.ts @@ -0,0 +1,3 @@ +export declare const env: { + REACT_APP_API_URL: string; +}; diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/env.js b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/env.js new file mode 100644 index 0000000000..692179bc05 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/env.js @@ -0,0 +1,11 @@ +import * as z from 'zod'; +import { ensureEnvSchema } from '../env/index.js'; +const clientEnvSchema = z.object({ + REACT_APP_API_URL: z + .string({ + required_error: 'REACT_APP_API_URL is required', + }) + .default('http://localhost:3001') +}); +export const env = ensureEnvSchema(import.meta.env, clientEnvSchema); +//# sourceMappingURL=env.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/env.js.map b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/env.js.map new file mode 100644 index 0000000000..bde7e9e367 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/env.js.map @@ -0,0 +1 @@ +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../client/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,iBAAiB,EAAE,CAAC;SACjB,MAAM,CAAC;QACN,cAAc,EAAE,+BAA+B;KAChD,CAAC;SACD,OAAO,CAAC,uBAAuB,CAAC;CACpC,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/index.d.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/index.d.ts index 7f5f4bfbc8..d5196de766 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/index.d.ts +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/index.d.ts @@ -9,3 +9,4 @@ export type Route = { path: string; }; export { config, ClientConfig } from './config'; +export { env } from './env.js'; diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/index.js b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/index.js index 5a7f13dcae..38dec51286 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/index.js +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/index.js @@ -9,4 +9,6 @@ export var HttpMethod; })(HttpMethod || (HttpMethod = {})); // PUBLIC API export { config } from './config'; +// PUBLIC API +export { env } from './env.js'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/index.js.map b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/index.js.map index 879953c8df..c827752797 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/index.js.map +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/client/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../client/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,mFAAmF;AACnF,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACrB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;AAClB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AAKD,aAAa;AACb,OAAO,EAAE,MAAM,EAAgB,MAAM,UAAU,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../client/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,mFAAmF;AACnF,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACrB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;AAClB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AAKD,aAAa;AACb,OAAO,EAAE,MAAM,EAAgB,MAAM,UAAU,CAAA;AAE/C,aAAa;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.d.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.d.ts new file mode 100644 index 0000000000..6bc9d059a3 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.d.ts @@ -0,0 +1,2 @@ +import * as z from 'zod'; +export declare function ensureEnvSchema(data: unknown, schema: Schema): z.infer; diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.js b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.js new file mode 100644 index 0000000000..a44104d78e --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.js @@ -0,0 +1,26 @@ +import * as z from 'zod'; +const redColor = '\x1b[31m'; +export function ensureEnvSchema(data, schema) { + try { + return schema.parse(data); + } + catch (e) { + // TODO: figure out how to output the error message in a better way + if (e instanceof z.ZodError) { + console.error(redColor, '╔═════════════════════════════╗'); + console.error(redColor, '║ Env vars validation failed ║'); + console.error(redColor, '╚═════════════════════════════╝'); + console.error(); + for (const error of e.errors) { + console.error(`- ${error.message}`); + } + console.error(); + console.error(redColor, '═══════════════════════════════'); + throw new Error('Error parsing environment variables'); + } + else { + throw e; + } + } +} +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.js.map b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.js.map new file mode 100644 index 0000000000..8cf4149a5b --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YACrC,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.js b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.js index e4f89082c8..f38fa5795a 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.js +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.js @@ -1,42 +1,35 @@ -var _a; import merge from 'lodash.merge'; -import { stripTrailingSlash } from "../universal/url.js"; -const nodeEnv = (_a = process.env.NODE_ENV) !== null && _a !== void 0 ? _a : 'development'; +import { env } from './env.js'; +import { stripTrailingSlash } from '../universal/url.js'; const config = { all: { - env: nodeEnv, - isDevelopment: nodeEnv === 'development', - port: process.env.PORT ? parseInt(process.env.PORT) : 3001, - databaseUrl: process.env.DATABASE_URL, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, allowedCORSOrigins: [], }, development: getDevelopmentConfig(), production: getProductionConfig(), }; -const resolvedConfig = merge(config.all, config[nodeEnv]); +const resolvedConfig = merge(config.all, config[env.NODE_ENV]); // PUBLIC API export default resolvedConfig; function getDevelopmentConfig() { - var _a, _b; - const frontendUrl = stripTrailingSlash((_a = process.env.WASP_WEB_CLIENT_URL) !== null && _a !== void 0 ? _a : 'http://localhost:3000/'); - const serverUrl = stripTrailingSlash((_b = process.env.WASP_SERVER_URL) !== null && _b !== void 0 ? _b : 'http://localhost:3001'); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, allowedCORSOrigins: '*', }; } function getProductionConfig() { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, - // @ts-ignore allowedCORSOrigins: [frontendUrl], }; } diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.js.map b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.js.map index e284580bbd..fe5abce123 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.js.map +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,QAAQ,mCAAI,aAAa,CAAA;AAyBrD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,OAAO;QACZ,aAAa,EAAE,OAAO,KAAK,aAAa;QACxC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;QAC1D,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;QACrC,kBAAkB,EAAE,EAAE;KACvB;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;AACjE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,mBAAmB,mCAAI,wBAAwB,CAAC,CAAC;IACpG,MAAM,SAAS,GAAG,kBAAkB,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,eAAe,mCAAI,uBAAuB,CAAC,CAAC;IAC7F,OAAO;QACL,aAAa;QACb,WAAW;QACX,aAAa;QACb,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACxE,MAAM,SAAS,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAClE,OAAO;QACL,aAAa;QACb,WAAW;QACX,aAAa;QACb,SAAS;QACT,aAAa;QACb,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAyBxD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,GAAG,CAAC,QAAQ;QACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;QAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,YAAY;QAC7B,kBAAkB,EAAE,EAAE;KACvB;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;AACtE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.d.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.d.ts new file mode 100644 index 0000000000..667ea30e35 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.d.ts @@ -0,0 +1,17 @@ +export declare const env: { + PORT: number; + DATABASE_URL: string; + SKIP_EMAIL_VERIFICATION_IN_DEV: boolean; + NODE_ENV: "development"; + WASP_SERVER_URL: string; + WASP_WEB_CLIENT_URL: string; + PG_BOSS_NEW_OPTIONS?: string | undefined; +} | { + PORT: number; + DATABASE_URL: string; + SKIP_EMAIL_VERIFICATION_IN_DEV: boolean; + NODE_ENV: "production"; + WASP_SERVER_URL: string; + WASP_WEB_CLIENT_URL: string; + PG_BOSS_NEW_OPTIONS?: string | undefined; +}; diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.js b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.js new file mode 100644 index 0000000000..d6bdbc9f66 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.js @@ -0,0 +1,48 @@ +import * as z from 'zod'; +import { ensureEnvSchema } from '../env/index.js'; +const serverCommonSchema = z.object({ + PORT: z.coerce.number().default(3001), + DATABASE_URL: z.string({ + required_error: 'DATABASE_URL is required', + }), + PG_BOSS_NEW_OPTIONS: z.string().optional(), + SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), +}); +const serverUrlSchema = z + .string({ + required_error: 'WASP_SERVER_URL is required', +}) + .url({ + message: 'WASP_SERVER_URL must be a valid URL', +}); +const clientUrlSchema = z + .string({ + required_error: 'WASP_WEB_CLIENT_URL is required', +}) + .url({ + message: 'WASP_WEB_CLIENT_URL must be a valid URL', +}); +const jwtTokenSchema = z + .string({ + required_error: 'JWT_SECRET is required', +}); +// In development, we provide default values for some environment variables +// to make the development process easier +const serverDevSchema = z.object({ + NODE_ENV: z.literal('development'), + WASP_SERVER_URL: serverUrlSchema + .default('http://localhost:3001'), + WASP_WEB_CLIENT_URL: clientUrlSchema + .default('http://localhost:3000/'), +}); +const serverProdSchema = z.object({ + NODE_ENV: z.literal('production'), + WASP_SERVER_URL: serverUrlSchema, + WASP_WEB_CLIENT_URL: clientUrlSchema, +}); +const serverEnvSchema = z.discriminatedUnion('NODE_ENV', [ + serverDevSchema.merge(serverCommonSchema), + serverProdSchema.merge(serverCommonSchema) +]); +export const env = ensureEnvSchema(process.env, serverEnvSchema); +//# sourceMappingURL=env.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.js.map b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.js.map new file mode 100644 index 0000000000..ecf2d3e0fa --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.js.map @@ -0,0 +1 @@ +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,8BAA8B,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;CAC3D,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;CACrC,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/index.d.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/index.d.ts index dee9613a53..a108f6123f 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/index.d.ts +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/index.d.ts @@ -4,4 +4,5 @@ export { default as prisma } from './dbClient.js'; export { type ServerSetupFn } from './types/index.js'; export { HttpError } from './HttpError.js'; export { MiddlewareConfigFn } from './middleware/index.js'; +export { env } from './env.js'; export type DbSeedFn = (prisma: PrismaClient) => Promise; diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/index.js b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/index.js index 0e53e0deab..8e75e6f78c 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/index.js +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/index.js @@ -4,4 +4,6 @@ export { default as config } from './config.js'; export { default as prisma } from './dbClient.js'; // PUBLIC API export { HttpError } from './HttpError.js'; +// PUBLIC API +export { env } from './env.js'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/index.js.map b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/index.js.map index b84ac1b303..87ed22f3af 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/index.js.map +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/index.ts"],"names":[],"mappings":"AAEA,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,eAAe,CAAA;AAGjD,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/index.ts"],"names":[],"mappings":"AAEA,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,eAAe,CAAA;AAGjD,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG1C,aAAa;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/universal/url.d.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/universal/url.d.ts index aa893e7838..7ceb994694 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/universal/url.d.ts +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/universal/url.d.ts @@ -1 +1,2 @@ -export declare function stripTrailingSlash(url?: string): string | undefined; +export declare function stripTrailingSlash(url: string): string; +export declare function stripTrailingSlash(url: undefined): undefined; diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/universal/url.js.map b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/universal/url.js.map index a7bad96020..e236f1b977 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/universal/url.js.map +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/universal/url.js.map @@ -1 +1 @@ -{"version":3,"file":"url.js","sourceRoot":"","sources":["../../universal/url.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC3C,OAAO,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC"} \ No newline at end of file +{"version":3,"file":"url.js","sourceRoot":"","sources":["../../universal/url.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC3C,OAAO,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/env/index.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/env/index.ts new file mode 100644 index 0000000000..5295a47f1a --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/env/index.ts @@ -0,0 +1,28 @@ +import * as z from 'zod' + +const redColor = '\x1b[31m' + +export function ensureEnvSchema( + data: unknown, + schema: Schema +): z.infer { + try { + return schema.parse(data) + } catch (e) { + // TODO: figure out how to output the error message in a better way + if (e instanceof z.ZodError) { + console.error(redColor, '╔═════════════════════════════╗'); + console.error(redColor, '║ Env vars validation failed ║'); + console.error(redColor, '╚═════════════════════════════╝'); + console.error() + for (const error of e.errors) { + console.error(`- ${error.message}`) + } + console.error() + console.error(redColor, '═══════════════════════════════'); + throw new Error('Error parsing environment variables') + } else { + throw e + } + } +} diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/package.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/package.json index 2589c5362f..cae34c05e7 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/package.json +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/package.json @@ -16,7 +16,8 @@ "react-hook-form": "^7.45.4", "react-router-dom": "^6.26.2", "superjson": "^2.2.1", - "vitest": "^1.2.1" + "vitest": "^1.2.1", + "zod": "^3.23.8" }, "devDependencies": { "@tsconfig/node18": "latest", diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/config.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/config.ts index 1dc9bafb93..27a7537a0f 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/config.ts +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/config.ts @@ -1,8 +1,7 @@ import merge from 'lodash.merge' -import { stripTrailingSlash } from "../universal/url.js"; - -const nodeEnv = process.env.NODE_ENV ?? 'development' +import { env } from './env.js' +import { stripTrailingSlash } from '../universal/url.js' // TODO: // - Use dotenv library to consume env vars from a file. @@ -33,41 +32,36 @@ const config: { production: EnvConfig, } = { all: { - env: nodeEnv, - isDevelopment: nodeEnv === 'development', - port: process.env.PORT ? parseInt(process.env.PORT) : 3001, - databaseUrl: process.env.DATABASE_URL, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, allowedCORSOrigins: [], }, development: getDevelopmentConfig(), production: getProductionConfig(), } -const resolvedConfig: Config = merge(config.all, config[nodeEnv]) +const resolvedConfig: Config = merge(config.all, config[env.NODE_ENV]) // PUBLIC API export default resolvedConfig function getDevelopmentConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL ?? 'http://localhost:3000/'); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL ?? 'http://localhost:3001'); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, allowedCORSOrigins: '*', } } function getProductionConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, - // @ts-ignore allowedCORSOrigins: [frontendUrl], } } diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/env.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/env.ts new file mode 100644 index 0000000000..cd30bc35f5 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/env.ts @@ -0,0 +1,56 @@ +import * as z from 'zod' + +import { ensureEnvSchema } from '../env/index.js' + +const serverCommonSchema = z.object({ + PORT: z.coerce.number().default(3001), + DATABASE_URL: z.string({ + required_error: 'DATABASE_URL is required', + }), + PG_BOSS_NEW_OPTIONS: z.string().optional(), + SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), +}) + +const serverUrlSchema = z + .string({ + required_error: 'WASP_SERVER_URL is required', + }) + .url({ + message: 'WASP_SERVER_URL must be a valid URL', + }) + +const clientUrlSchema = z + .string({ + required_error: 'WASP_WEB_CLIENT_URL is required', + }) + .url({ + message: 'WASP_WEB_CLIENT_URL must be a valid URL', + }) + +const jwtTokenSchema = z + .string({ + required_error: 'JWT_SECRET is required', + }) + +// In development, we provide default values for some environment variables +// to make the development process easier +const serverDevSchema = z.object({ + NODE_ENV: z.literal('development'), + WASP_SERVER_URL: serverUrlSchema + .default('http://localhost:3001'), + WASP_WEB_CLIENT_URL: clientUrlSchema + .default('http://localhost:3000/'), +}) + +const serverProdSchema = z.object({ + NODE_ENV: z.literal('production'), + WASP_SERVER_URL: serverUrlSchema, + WASP_WEB_CLIENT_URL: clientUrlSchema, +}) + +const serverEnvSchema = z.discriminatedUnion('NODE_ENV', [ + serverDevSchema.merge(serverCommonSchema), + serverProdSchema.merge(serverCommonSchema) +]) + +export const env = ensureEnvSchema(process.env, serverEnvSchema) diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/index.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/index.ts index 535077900b..0f95deb90a 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/index.ts +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/index.ts @@ -10,6 +10,8 @@ export { type ServerSetupFn } from './types/index.js' export { HttpError } from './HttpError.js' // PUBLIC API export { MiddlewareConfigFn } from './middleware/index.js' +// PUBLIC API +export { env } from './env.js' // PUBLIC API export type DbSeedFn = (prisma: PrismaClient) => Promise diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/universal/url.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/universal/url.ts index d21c06c65c..126678dac9 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/universal/url.ts +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/universal/url.ts @@ -1,3 +1,5 @@ +export function stripTrailingSlash(url: string): string +export function stripTrailingSlash(url: undefined): undefined export function stripTrailingSlash(url?: string): string | undefined { return url?.replace(/\/$/, ""); } diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/package.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/package.json index 7a57413e11..51ec87354a 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/package.json +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/package.json @@ -34,9 +34,8 @@ "bundle-and-start": "npm run bundle && npm run start", "db-migrate-prod": "prisma migrate deploy --schema=../db/schema.prisma", "db-seed": "npm run bundle && node --enable-source-maps -r dotenv/config bundle/dbSeed.js", - "start": "npm run validate-env && node --enable-source-maps -r dotenv/config bundle/server.js", + "start": "node --enable-source-maps -r dotenv/config bundle/server.js", "start-production": "NODE_ENV=production npm run start", - "validate-env": "node -r dotenv/config ./scripts/validate-env.mjs", "watch": "nodemon --exec 'npm run bundle-and-start || exit 1'" }, "type": "module", diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/scripts/validate-env.mjs b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/scripts/validate-env.mjs deleted file mode 100644 index f6e50aceca..0000000000 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/scripts/validate-env.mjs +++ /dev/null @@ -1,5 +0,0 @@ -import { throwIfNotValidAbsoluteURL } from 'wasp/universal/validators'; - -console.info("🔍 Validating environment variables..."); -throwIfNotValidAbsoluteURL(process.env.WASP_WEB_CLIENT_URL, 'Environment variable WASP_WEB_CLIENT_URL'); -throwIfNotValidAbsoluteURL(process.env.WASP_SERVER_URL, 'Environment variable WASP_SERVER_URL'); diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/files.manifest b/waspc/e2e-test/test-outputs/waspComplexTest-golden/files.manifest index 022dd0bf88..5368cb869a 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/files.manifest +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/files.manifest @@ -37,6 +37,7 @@ waspComplexTest/.wasp/out/sdk/wasp/client/config.ts waspComplexTest/.wasp/out/sdk/wasp/client/crud/index.ts waspComplexTest/.wasp/out/sdk/wasp/client/crud/operationsHelpers.ts waspComplexTest/.wasp/out/sdk/wasp/client/crud/tasks.ts +waspComplexTest/.wasp/out/sdk/wasp/client/env.ts waspComplexTest/.wasp/out/sdk/wasp/client/index.ts waspComplexTest/.wasp/out/sdk/wasp/client/operations/actions/core.ts waspComplexTest/.wasp/out/sdk/wasp/client/operations/actions/index.ts @@ -155,6 +156,9 @@ waspComplexTest/.wasp/out/sdk/wasp/dist/client/crud/operationsHelpers.js.map waspComplexTest/.wasp/out/sdk/wasp/dist/client/crud/tasks.d.ts waspComplexTest/.wasp/out/sdk/wasp/dist/client/crud/tasks.js waspComplexTest/.wasp/out/sdk/wasp/dist/client/crud/tasks.js.map +waspComplexTest/.wasp/out/sdk/wasp/dist/client/env.d.ts +waspComplexTest/.wasp/out/sdk/wasp/dist/client/env.js +waspComplexTest/.wasp/out/sdk/wasp/dist/client/env.js.map waspComplexTest/.wasp/out/sdk/wasp/dist/client/index.d.ts waspComplexTest/.wasp/out/sdk/wasp/dist/client/index.js waspComplexTest/.wasp/out/sdk/wasp/dist/client/index.js.map @@ -224,6 +228,9 @@ waspComplexTest/.wasp/out/sdk/wasp/dist/dev/index.js.map waspComplexTest/.wasp/out/sdk/wasp/dist/entities/index.d.ts waspComplexTest/.wasp/out/sdk/wasp/dist/entities/index.js waspComplexTest/.wasp/out/sdk/wasp/dist/entities/index.js.map +waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.d.ts +waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js +waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js.map waspComplexTest/.wasp/out/sdk/wasp/dist/ext-src/MainPage.d.ts waspComplexTest/.wasp/out/sdk/wasp/dist/ext-src/MainPage.jsx waspComplexTest/.wasp/out/sdk/wasp/dist/ext-src/MainPage.jsx.map @@ -278,9 +285,6 @@ waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/hooks.js.map waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/index.d.ts waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/index.js waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/index.js.map -waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/env.d.ts -waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/env.js -waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/env.js.map waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/index.d.ts waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/index.js waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/index.js.map @@ -326,6 +330,9 @@ waspComplexTest/.wasp/out/sdk/wasp/dist/server/email/core/types.js.map waspComplexTest/.wasp/out/sdk/wasp/dist/server/email/index.d.ts waspComplexTest/.wasp/out/sdk/wasp/dist/server/email/index.js waspComplexTest/.wasp/out/sdk/wasp/dist/server/email/index.js.map +waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.d.ts +waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js +waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js.map waspComplexTest/.wasp/out/sdk/wasp/dist/server/index.d.ts waspComplexTest/.wasp/out/sdk/wasp/dist/server/index.js waspComplexTest/.wasp/out/sdk/wasp/dist/server/index.js.map @@ -393,6 +400,7 @@ waspComplexTest/.wasp/out/sdk/wasp/dist/universal/validators.d.ts waspComplexTest/.wasp/out/sdk/wasp/dist/universal/validators.js waspComplexTest/.wasp/out/sdk/wasp/dist/universal/validators.js.map waspComplexTest/.wasp/out/sdk/wasp/entities/index.ts +waspComplexTest/.wasp/out/sdk/wasp/env/index.ts waspComplexTest/.wasp/out/sdk/wasp/ext-src/Main.css waspComplexTest/.wasp/out/sdk/wasp/ext-src/MainPage.jsx waspComplexTest/.wasp/out/sdk/wasp/ext-src/auth/hooks.ts @@ -416,7 +424,6 @@ waspComplexTest/.wasp/out/sdk/wasp/server/_types/taggedEntities.ts waspComplexTest/.wasp/out/sdk/wasp/server/api/index.ts waspComplexTest/.wasp/out/sdk/wasp/server/auth/hooks.ts waspComplexTest/.wasp/out/sdk/wasp/server/auth/index.ts -waspComplexTest/.wasp/out/sdk/wasp/server/auth/oauth/env.ts waspComplexTest/.wasp/out/sdk/wasp/server/auth/oauth/index.ts waspComplexTest/.wasp/out/sdk/wasp/server/auth/oauth/oneTimeCode.ts waspComplexTest/.wasp/out/sdk/wasp/server/auth/oauth/provider.ts @@ -432,6 +439,7 @@ waspComplexTest/.wasp/out/sdk/wasp/server/email/core/index.ts waspComplexTest/.wasp/out/sdk/wasp/server/email/core/providers/sendgrid.ts waspComplexTest/.wasp/out/sdk/wasp/server/email/core/types.ts waspComplexTest/.wasp/out/sdk/wasp/server/email/index.ts +waspComplexTest/.wasp/out/sdk/wasp/server/env.ts waspComplexTest/.wasp/out/sdk/wasp/server/index.ts waspComplexTest/.wasp/out/sdk/wasp/server/jobs/core/job.ts waspComplexTest/.wasp/out/sdk/wasp/server/jobs/core/pgBoss/index.ts @@ -462,7 +470,6 @@ waspComplexTest/.wasp/out/server/README.md waspComplexTest/.wasp/out/server/nodemon.json waspComplexTest/.wasp/out/server/package.json waspComplexTest/.wasp/out/server/rollup.config.js -waspComplexTest/.wasp/out/server/scripts/validate-env.mjs waspComplexTest/.wasp/out/server/src/actions/mySpecialAction.ts waspComplexTest/.wasp/out/server/src/app.js waspComplexTest/.wasp/out/server/src/auth/hooks.ts diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/.waspchecksums b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/.waspchecksums index 9647705526..ef76c07ab3 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/.waspchecksums @@ -200,7 +200,7 @@ "file", "../out/sdk/wasp/client/config.ts" ], - "d94e8bee5fd8f6793b511652b9ee558e57f4913595763137a5385cd929648168" + "4c5835ad64352cc87a4a17e41fd70333bc0d1eedd7339d7ad3d3507cdb64038d" ], [ [ @@ -223,12 +223,19 @@ ], "083c93c278fe261989cec8a4ea52e0dc706fae1a79aa91d6f1b8c17eca938c40" ], + [ + [ + "file", + "../out/sdk/wasp/client/env.ts" + ], + "f630ded0392d5b60be93e1852f80ea8c75bc10262aee6fb106b6eb2561339362" + ], [ [ "file", "../out/sdk/wasp/client/index.ts" ], - "2b3651e7040a63cfd6a271c2aa89f21cf01170e0abeb6c5ab74adde324852fe4" + "d5a83474d2db10e1ac90899a0e302503bf26b3ab5ab00c07b5f5ce0d9e6de2d4" ], [ [ @@ -384,6 +391,13 @@ ], "becac9b39c6920dee40a97958331da143e06dd26d6756ad08dcc6402b23e2efb" ], + [ + [ + "file", + "../out/sdk/wasp/env/index.ts" + ], + "cd4e86f3c0f1cacd868984f4103a47fe100037758adc8ba3adf1a5a9d6c1c880" + ], [ [ "file", @@ -487,7 +501,7 @@ "file", "../out/sdk/wasp/package.json" ], - "6fdae74af8f40e1e3287c93d6af2a7ebe9140b1995b6511d2bb4a0c002ab8d48" + "27e50b464aa1785f4651f4229f509fd2d71ed19076e341c4f3fafb98b11955c0" ], [ [ @@ -545,13 +559,6 @@ ], "9f932aba0d2ca6d1d2ff6fd826d238da3719b7676e7b42e97430af6f86fd03e2" ], - [ - [ - "file", - "../out/sdk/wasp/server/auth/oauth/env.ts" - ], - "50416a8c284fdbb3952e21e1617da2270b99dba717023babc7c32f5b12a63a32" - ], [ [ "file", @@ -571,14 +578,14 @@ "file", "../out/sdk/wasp/server/auth/oauth/provider.ts" ], - "2a2015d905a2ceddb45ff1034b283b242df153ddf2cabd05fddd4746365622df" + "f286a5c5f04b197bc5cf21711722b6265887dae1782a26e41124606616c27122" ], [ [ "file", "../out/sdk/wasp/server/auth/oauth/providers/google.ts" ], - "2a30b51f7be3a627d652e164669b01832345763597aa1e0badf7d321ccdc3bdb" + "42fe943be534df3df054480df3c3672742159a5f9d48a5a2bb0cb0a3500168e7" ], [ [ @@ -599,7 +606,7 @@ "file", "../out/sdk/wasp/server/config.ts" ], - "7222022fceced6be8ce57e8fd06ea6dfe2100de5984d7a9bc752ed4d9ba6f4ef" + "ee59e87efd7cf4904b33d15cde4ef65994f156a3f7fb634942a6414c3505bcf7" ], [ [ @@ -655,14 +662,21 @@ "file", "../out/sdk/wasp/server/email/index.ts" ], - "7fc9cea5624d921d9cd2397767522282e3f1a8a0013806f8d3e721560526b177" + "7f5d5dc724dcb623047b39800a55e1eca2e03984f0f0ee996949ff6846f4e97c" + ], + [ + [ + "file", + "../out/sdk/wasp/server/env.ts" + ], + "593c28a9be1dc1382c6dd36a1f93b960dc60142e9309c5d45cb8d4fedb7fd727" ], [ [ "file", "../out/sdk/wasp/server/index.ts" ], - "51c3e0802764f72b88f6daaf148dba514ae817e233a40cc9b92ec91784f71f98" + "a8d2ffa7dfd0a13f7fb6135193bcdac1f860603bdd0ddc2843033fd4f6f6151f" ], [ [ @@ -683,7 +697,7 @@ "file", "../out/sdk/wasp/server/jobs/core/pgBoss/pgBoss.ts" ], - "4c405b3cf98a4cea0ee906a46e4676ebe7ce08c1652c1b502403a93ebbbf943a" + "6ffb60e3dd86ebf2f83248d18e3d647018b3d583233c64259559221fe9d2c882" ], [ [ @@ -809,7 +823,7 @@ "file", "../out/sdk/wasp/universal/url.ts" ], - "8dc6e044a1a231b796465d94985ca47c5efd42a5d411b407a7d83a61ebae4b6d" + "58ff4ad8ffc79264d7215461571d909f3c5fb177ff32c67058d1da9cd4115d6e" ], [ [ @@ -837,7 +851,7 @@ "file", "Dockerfile" ], - "db2dae70d212749a7e758117e55f00968f84974d8307dc7d33154bf1429486c2" + "3adb787bfea53c4b0a04c73992cba82163fa0b2217169c822a754e54511cee64" ], [ [ @@ -886,7 +900,7 @@ "file", "server/package.json" ], - "00ae054bb5597a45cc4e5277f88d24f4399fccabaa3614bf6ea89424fcd23480" + "ddda728300aaca5ccbd8342479cede7930cd5841c01f048415da8172314a1e0a" ], [ [ @@ -895,13 +909,6 @@ ], "c1beb8264f11898364288d73b16f08d1923bac5f70038d9827978deb5b58a2da" ], - [ - [ - "file", - "server/scripts/validate-env.mjs" - ], - "100177b4326ccab7362eff378315d532ad1cc17cd28d1ed5978cb167fd627746" - ], [ [ "file", @@ -949,7 +956,7 @@ "file", "server/src/auth/providers/oauth/cookies.ts" ], - "7fb6658564e8af442d0f0b5874879e6788e91e89d98a8265621dd323135f5916" + "d3550ba07c6685f033962a47b326609f3a15ab5456638b9a4cf6fbb84379044c" ], [ [ diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/Dockerfile b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/Dockerfile index 76baedb0e0..1030b7ec6c 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/Dockerfile +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/Dockerfile @@ -55,12 +55,12 @@ COPY --from=server-builder /app/node_modules ./node_modules # Copying the SDK because 'validate-env.mjs' executes independent of the bundle # and references the 'wasp' package. COPY --from=server-builder /app/.wasp/out/sdk .wasp/out/sdk -# Copying 'server/node_modules' because 'validate-env.mjs' executes independent -# of the bundle and references the dotenv package. +# Copying 'server/node_modules' because we require dotenv package to +# load environment variables +# TODO: replace dotenv with native Node.js environment variable loading COPY --from=server-builder /app/.wasp/build/server/node_modules .wasp/build/server/node_modules COPY --from=server-builder /app/.wasp/build/server/bundle .wasp/build/server/bundle COPY --from=server-builder /app/.wasp/build/server/package*.json .wasp/build/server/ -COPY --from=server-builder /app/.wasp/build/server/scripts .wasp/build/server/scripts COPY db/ .wasp/build/db/ EXPOSE ${PORT} WORKDIR /app/.wasp/build/server diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/installedNpmDepsLog.json b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/installedNpmDepsLog.json index c0f1ff6bfa..2dac6a447e 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/installedNpmDepsLog.json +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/installedNpmDepsLog.json @@ -1 +1 @@ -{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"@stitches/react","version":"^1.2.8"},{"name":"@node-rs/argon2","version":"^1.8.3"},{"name":"arctic","version":"^1.2.1"},{"name":"lucia","version":"^3.0.1"},{"name":"oslo","version":"^1.1.2"},{"name":"@lucia-auth/adapter-prisma","version":"^4.0.0"},{"name":"@sendgrid/mail","version":"^7.7.0"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"pg-boss","version":"^8.4.2"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file +{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"@stitches/react","version":"^1.2.8"},{"name":"@node-rs/argon2","version":"^1.8.3"},{"name":"arctic","version":"^1.2.1"},{"name":"lucia","version":"^3.0.1"},{"name":"oslo","version":"^1.1.2"},{"name":"@lucia-auth/adapter-prisma","version":"^4.0.0"},{"name":"@sendgrid/mail","version":"^7.7.0"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"pg-boss","version":"^8.4.2"},{"name":"zod","version":"^3.23.8"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/client/config.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/client/config.ts index 82b0f80b6a..fff77cb01c 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/client/config.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/client/config.ts @@ -1,6 +1,7 @@ import { stripTrailingSlash } from '../universal/url.js' +import { env } from './env.js' -const apiUrl = stripTrailingSlash(import.meta.env.REACT_APP_API_URL) || 'http://localhost:3001'; +const apiUrl = stripTrailingSlash(env.REACT_APP_API_URL) // PUBLIC API export type ClientConfig = { diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/client/env.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/client/env.ts new file mode 100644 index 0000000000..dfa9e70ee3 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/client/env.ts @@ -0,0 +1,13 @@ +import * as z from 'zod' + +import { ensureEnvSchema } from '../env/index.js' + +const clientEnvSchema = z.object({ + REACT_APP_API_URL: z + .string({ + required_error: 'REACT_APP_API_URL is required', + }) + .default('http://localhost:3001') +}) + +export const env = ensureEnvSchema(import.meta.env, clientEnvSchema) diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/client/index.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/client/index.ts index cfce564c4d..33db447837 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/client/index.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/client/index.ts @@ -12,3 +12,6 @@ export type Route = { method: HttpMethod; path: string } // PUBLIC API export { config, ClientConfig } from './config' + +// PUBLIC API +export { env } from './env.js' diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/config.js b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/config.js index 1dffbd68bc..7e6149f386 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/config.js +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/config.js @@ -1,5 +1,6 @@ import { stripTrailingSlash } from '../universal/url.js'; -const apiUrl = stripTrailingSlash(import.meta.env.REACT_APP_API_URL) || 'http://localhost:3001'; +import { env } from './env.js'; +const apiUrl = stripTrailingSlash(env.REACT_APP_API_URL); // PUBLIC API export const config = { apiUrl, diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/config.js.map b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/config.js.map index d26d37022b..f9e186b838 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/config.js.map +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../client/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAExD,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,uBAAuB,CAAC;AAOhG,aAAa;AACb,MAAM,CAAC,MAAM,MAAM,GAAiB;IAClC,MAAM;CACP,CAAA"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../client/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;AAOxD,aAAa;AACb,MAAM,CAAC,MAAM,MAAM,GAAiB;IAClC,MAAM;CACP,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/env.d.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/env.d.ts new file mode 100644 index 0000000000..5a9417a810 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/env.d.ts @@ -0,0 +1,3 @@ +export declare const env: { + REACT_APP_API_URL: string; +}; diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/env.js b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/env.js new file mode 100644 index 0000000000..692179bc05 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/env.js @@ -0,0 +1,11 @@ +import * as z from 'zod'; +import { ensureEnvSchema } from '../env/index.js'; +const clientEnvSchema = z.object({ + REACT_APP_API_URL: z + .string({ + required_error: 'REACT_APP_API_URL is required', + }) + .default('http://localhost:3001') +}); +export const env = ensureEnvSchema(import.meta.env, clientEnvSchema); +//# sourceMappingURL=env.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/env.js.map b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/env.js.map new file mode 100644 index 0000000000..bde7e9e367 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/env.js.map @@ -0,0 +1 @@ +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../client/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,iBAAiB,EAAE,CAAC;SACjB,MAAM,CAAC;QACN,cAAc,EAAE,+BAA+B;KAChD,CAAC;SACD,OAAO,CAAC,uBAAuB,CAAC;CACpC,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/index.d.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/index.d.ts index 7f5f4bfbc8..d5196de766 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/index.d.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/index.d.ts @@ -9,3 +9,4 @@ export type Route = { path: string; }; export { config, ClientConfig } from './config'; +export { env } from './env.js'; diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/index.js b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/index.js index 5a7f13dcae..38dec51286 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/index.js +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/index.js @@ -9,4 +9,6 @@ export var HttpMethod; })(HttpMethod || (HttpMethod = {})); // PUBLIC API export { config } from './config'; +// PUBLIC API +export { env } from './env.js'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/index.js.map b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/index.js.map index 879953c8df..c827752797 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/index.js.map +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/client/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../client/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,mFAAmF;AACnF,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACrB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;AAClB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AAKD,aAAa;AACb,OAAO,EAAE,MAAM,EAAgB,MAAM,UAAU,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../client/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,mFAAmF;AACnF,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACrB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;AAClB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AAKD,aAAa;AACb,OAAO,EAAE,MAAM,EAAgB,MAAM,UAAU,CAAA;AAE/C,aAAa;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.d.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.d.ts new file mode 100644 index 0000000000..6bc9d059a3 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.d.ts @@ -0,0 +1,2 @@ +import * as z from 'zod'; +export declare function ensureEnvSchema(data: unknown, schema: Schema): z.infer; diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js new file mode 100644 index 0000000000..a44104d78e --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js @@ -0,0 +1,26 @@ +import * as z from 'zod'; +const redColor = '\x1b[31m'; +export function ensureEnvSchema(data, schema) { + try { + return schema.parse(data); + } + catch (e) { + // TODO: figure out how to output the error message in a better way + if (e instanceof z.ZodError) { + console.error(redColor, '╔═════════════════════════════╗'); + console.error(redColor, '║ Env vars validation failed ║'); + console.error(redColor, '╚═════════════════════════════╝'); + console.error(); + for (const error of e.errors) { + console.error(`- ${error.message}`); + } + console.error(); + console.error(redColor, '═══════════════════════════════'); + throw new Error('Error parsing environment variables'); + } + else { + throw e; + } + } +} +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js.map b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js.map new file mode 100644 index 0000000000..8cf4149a5b --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YACrC,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/env.d.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/env.d.ts deleted file mode 100644 index 08d2627b88..0000000000 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/env.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function ensureEnvVarsForProvider(envVarNames: EnvVarName[], providerName: string): Record; diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/env.js b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/env.js deleted file mode 100644 index 56281b5e36..0000000000 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/env.js +++ /dev/null @@ -1,13 +0,0 @@ -// PRIVATE API (SDK) -export function ensureEnvVarsForProvider(envVarNames, providerName) { - const result = {}; - for (const envVarName of envVarNames) { - const value = process.env[envVarName]; - if (!value) { - throw new Error(`${envVarName} env variable is required when using the ${providerName} auth provider.`); - } - result[envVarName] = value; - } - return result; -} -//# sourceMappingURL=env.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/env.js.map b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/env.js.map deleted file mode 100644 index b25f2f9870..0000000000 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/env.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"env.js","sourceRoot":"","sources":["../../../../server/auth/oauth/env.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,MAAM,UAAU,wBAAwB,CACtC,WAAyB,EACzB,YAAoB;IAEpB,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACtC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,4CAA4C,YAAY,iBAAiB,CAAC,CAAC;QAC1G,CAAC;QACD,MAAM,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC;IAC7B,CAAC;IACD,OAAO,MAAoC,CAAC;AAC9C,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/provider.d.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/provider.d.ts index 44d23b4952..8738b530a5 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/provider.d.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/provider.d.ts @@ -1,12 +1,10 @@ import { OAuth2Provider, OAuth2ProviderWithPKCE } from "arctic"; -export declare function defineProvider>({ id, displayName, env, oAuthClient, }: { +export declare function defineProvider({ id, displayName, oAuthClient, }: { id: string; displayName: string; - env: Env; oAuthClient: OAuthClient; }): { id: string; displayName: string; - env: Env; oAuthClient: OAuthClient; }; diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/provider.js b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/provider.js index bc0d9a2fd8..eb6692b29c 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/provider.js +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/provider.js @@ -1,8 +1,7 @@ -export function defineProvider({ id, displayName, env, oAuthClient, }) { +export function defineProvider({ id, displayName, oAuthClient, }) { return { id, displayName, - env, oAuthClient, }; } diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/provider.js.map b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/provider.js.map index 02fe380099..cf0b0f6459 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/provider.js.map +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/provider.js.map @@ -1 +1 @@ -{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../../server/auth/oauth/provider.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAG5B,EACA,EAAE,EACF,WAAW,EACX,GAAG,EACH,WAAW,GAMZ;IACC,OAAO;QACL,EAAE;QACF,WAAW;QACX,GAAG;QACH,WAAW;KACZ,CAAC;AACJ,CAAC"} \ No newline at end of file +{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../../server/auth/oauth/provider.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAE5B,EACA,EAAE,EACF,WAAW,EACX,WAAW,GAKZ;IACC,OAAO;QACL,EAAE;QACF,WAAW;QACX,WAAW;KACZ,CAAC;AACJ,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/providers/google.d.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/providers/google.d.ts index 7910449649..bf13237ad7 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/providers/google.d.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/providers/google.d.ts @@ -1,7 +1,6 @@ -import { Google } from "arctic"; +import { Google } from 'arctic'; export declare const google: { id: string; displayName: string; - env: Record<"GOOGLE_CLIENT_ID" | "GOOGLE_CLIENT_SECRET", string>; oAuthClient: Google; }; diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/providers/google.js b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/providers/google.js index 7a49678dec..43ddbe1c75 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/providers/google.js +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/providers/google.js @@ -1,16 +1,14 @@ -import { Google } from "arctic"; -import { ensureEnvVarsForProvider } from "../env.js"; -import { getRedirectUriForCallback } from "../redirect.js"; -import { defineProvider } from "../provider.js"; -const id = "google"; -const displayName = "Google"; -const env = ensureEnvVarsForProvider(["GOOGLE_CLIENT_ID", "GOOGLE_CLIENT_SECRET"], displayName); +import { Google } from 'arctic'; +import { getRedirectUriForCallback } from '../redirect.js'; +import { defineProvider } from '../provider.js'; +import { env } from '../../../env.js'; +const id = 'google'; +const displayName = 'Google'; const oAuthClient = new Google(env.GOOGLE_CLIENT_ID, env.GOOGLE_CLIENT_SECRET, getRedirectUriForCallback(id).toString()); // PUBLIC API export const google = defineProvider({ id, displayName, - env, oAuthClient, }); //# sourceMappingURL=google.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/providers/google.js.map b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/providers/google.js.map index 1bebbd38aa..cf4d45a1aa 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/providers/google.js.map +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/auth/oauth/providers/google.js.map @@ -1 +1 @@ -{"version":3,"file":"google.js","sourceRoot":"","sources":["../../../../../server/auth/oauth/providers/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAG,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,EAAE,GAAG,QAAQ,CAAC;AACpB,MAAM,WAAW,GAAG,QAAQ,CAAC;AAE7B,MAAM,GAAG,GAAG,wBAAwB,CAClC,CAAC,kBAAkB,EAAE,sBAAsB,CAAC,EAC5C,WAAW,CACZ,CAAC;AAEF,MAAM,WAAW,GAAG,IAAI,MAAM,CAC5B,GAAG,CAAC,gBAAgB,EACpB,GAAG,CAAC,oBAAoB,EACxB,yBAAyB,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,CACzC,CAAC;AAEF,aAAa;AACb,MAAM,CAAC,MAAM,MAAM,GAAG,cAAc,CAAC;IACnC,EAAE;IACF,WAAW;IACX,GAAG;IACH,WAAW;CACZ,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"google.js","sourceRoot":"","sources":["../../../../../server/auth/oauth/providers/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAG,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAEtC,MAAM,EAAE,GAAG,QAAQ,CAAC;AACpB,MAAM,WAAW,GAAG,QAAQ,CAAC;AAE7B,MAAM,WAAW,GAAG,IAAI,MAAM,CAC5B,GAAG,CAAC,gBAAgB,EACpB,GAAG,CAAC,oBAAoB,EACxB,yBAAyB,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,CACzC,CAAC;AAEF,aAAa;AACb,MAAM,CAAC,MAAM,MAAM,GAAG,cAAc,CAAC;IACnC,EAAE;IACF,WAAW;IACX,WAAW;CACZ,CAAC,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.d.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.d.ts index 56da48e819..9023fd045e 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.d.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.d.ts @@ -1,14 +1,14 @@ type BaseConfig = { allowedCORSOrigins: string | string[]; - auth: { - jwtSecret: string | undefined; - }; }; type CommonConfig = BaseConfig & { env: string; isDevelopment: boolean; port: number; databaseUrl: string | undefined; + auth: { + jwtSecret: string | undefined; + }; }; type EnvConfig = BaseConfig & { frontendUrl: string; diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.js b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.js index cb99fb1dd0..cc2ff362e0 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.js +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.js @@ -1,52 +1,39 @@ -var _a; import merge from 'lodash.merge'; -import { stripTrailingSlash } from "../universal/url.js"; -const nodeEnv = (_a = process.env.NODE_ENV) !== null && _a !== void 0 ? _a : 'development'; +import { env } from './env.js'; +import { stripTrailingSlash } from '../universal/url.js'; const config = { all: { - env: nodeEnv, - isDevelopment: nodeEnv === 'development', - port: process.env.PORT ? parseInt(process.env.PORT) : 3001, - databaseUrl: process.env.DATABASE_URL, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, allowedCORSOrigins: [], auth: { - jwtSecret: undefined + jwtSecret: env.JWT_SECRET } }, development: getDevelopmentConfig(), production: getProductionConfig(), }; -const resolvedConfig = merge(config.all, config[nodeEnv]); +const resolvedConfig = merge(config.all, config[env.NODE_ENV]); // PUBLIC API export default resolvedConfig; function getDevelopmentConfig() { - var _a, _b; - const frontendUrl = stripTrailingSlash((_a = process.env.WASP_WEB_CLIENT_URL) !== null && _a !== void 0 ? _a : 'http://localhost:3000/'); - const serverUrl = stripTrailingSlash((_b = process.env.WASP_SERVER_URL) !== null && _b !== void 0 ? _b : 'http://localhost:3001'); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, allowedCORSOrigins: '*', - auth: { - jwtSecret: 'DEVJWTSECRET' - } }; } function getProductionConfig() { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, - // @ts-ignore allowedCORSOrigins: [frontendUrl], - auth: { - jwtSecret: process.env.JWT_SECRET - } }; } //# sourceMappingURL=config.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.js.map b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.js.map index 0ef81fb2bc..19f008a7ec 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.js.map +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,QAAQ,mCAAI,aAAa,CAAA;AA4BrD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,OAAO;QACZ,aAAa,EAAE,OAAO,KAAK,aAAa;QACxC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;QAC1D,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;QACrC,kBAAkB,EAAE,EAAE;QACtB,IAAI,EAAE;YACJ,SAAS,EAAE,SAAS;SACrB;KACF;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;AACjE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,mBAAmB,mCAAI,wBAAwB,CAAC,CAAC;IACpG,MAAM,SAAS,GAAG,kBAAkB,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,eAAe,mCAAI,uBAAuB,CAAC,CAAC;IAC7F,OAAO;QACL,aAAa;QACb,WAAW;QACX,aAAa;QACb,SAAS;QACT,kBAAkB,EAAE,GAAG;QACvB,IAAI,EAAE;YACJ,SAAS,EAAE,cAAc;SAC1B;KACF,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACxE,MAAM,SAAS,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAClE,OAAO;QACL,aAAa;QACb,WAAW;QACX,aAAa;QACb,SAAS;QACT,aAAa;QACb,kBAAkB,EAAE,CAAC,WAAW,CAAC;QACjC,IAAI,EAAE;YACJ,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU;SAClC;KACF,CAAA;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AA4BxD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,GAAG,CAAC,QAAQ;QACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;QAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,YAAY;QAC7B,kBAAkB,EAAE,EAAE;QACtB,IAAI,EAAE;YACJ,SAAS,EAAE,GAAG,CAAC,UAAU;SAC1B;KACF;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;AACtE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/email/index.js b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/email/index.js index 91c1207b30..d177dedcb3 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/email/index.js +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/email/index.js @@ -1,9 +1,10 @@ +import { env } from '../env.js'; import { initEmailSender } from "./core/index.js"; // TODO: We need to validate all the env variables // For now, we are letting the runtime throw if they are not provided const emailProvider = { type: "sendgrid", - apiKey: process.env.SENDGRID_API_KEY, + apiKey: env.SENDGRID_API_KEY, }; // PUBLIC API export const emailSender = initEmailSender(emailProvider); diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/email/index.js.map b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/email/index.js.map index 1629cdd0f0..69869ee1eb 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/email/index.js.map +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/email/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/email/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,kDAAkD;AAClD,qEAAqE;AACrE,MAAM,aAAa,GAAG;IACpB,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAiB;CAC7B,CAAC;AAEX,aAAa;AACb,MAAM,CAAC,MAAM,WAAW,GAAgB,eAAe,CAAC,aAAa,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/email/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,kDAAkD;AAClD,qEAAqE;AACrE,MAAM,aAAa,GAAG;IACpB,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,GAAG,CAAC,gBAAgB;CACpB,CAAC;AAEX,aAAa;AACb,MAAM,CAAC,MAAM,WAAW,GAAgB,eAAe,CAAC,aAAa,CAAC,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.d.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.d.ts new file mode 100644 index 0000000000..72587aed6b --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.d.ts @@ -0,0 +1,25 @@ +export declare const env: { + PORT: number; + DATABASE_URL: string; + SENDGRID_API_KEY: string; + SKIP_EMAIL_VERIFICATION_IN_DEV: boolean; + GOOGLE_CLIENT_ID: string; + GOOGLE_CLIENT_SECRET: string; + NODE_ENV: "development"; + WASP_SERVER_URL: string; + WASP_WEB_CLIENT_URL: string; + JWT_SECRET: string; + PG_BOSS_NEW_OPTIONS?: string | undefined; +} | { + PORT: number; + DATABASE_URL: string; + SENDGRID_API_KEY: string; + SKIP_EMAIL_VERIFICATION_IN_DEV: boolean; + GOOGLE_CLIENT_ID: string; + GOOGLE_CLIENT_SECRET: string; + NODE_ENV: "production"; + WASP_SERVER_URL: string; + WASP_WEB_CLIENT_URL: string; + JWT_SECRET: string; + PG_BOSS_NEW_OPTIONS?: string | undefined; +}; diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js new file mode 100644 index 0000000000..c08c95130c --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js @@ -0,0 +1,60 @@ +import * as z from 'zod'; +import { ensureEnvSchema } from '../env/index.js'; +const serverCommonSchema = z.object({ + PORT: z.coerce.number().default(3001), + DATABASE_URL: z.string({ + required_error: 'DATABASE_URL is required', + }), + PG_BOSS_NEW_OPTIONS: z.string().optional(), + SENDGRID_API_KEY: z.string({ + required_error: 'SENDGRID_API_KEY is required', + }), + SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), + GOOGLE_CLIENT_ID: z.string({ + required_error: 'GOOGLE_CLIENT_ID is required', + }), + GOOGLE_CLIENT_SECRET: z.string({ + required_error: 'GOOGLE_CLIENT_SECRET is required', + }), +}); +const serverUrlSchema = z + .string({ + required_error: 'WASP_SERVER_URL is required', +}) + .url({ + message: 'WASP_SERVER_URL must be a valid URL', +}); +const clientUrlSchema = z + .string({ + required_error: 'WASP_WEB_CLIENT_URL is required', +}) + .url({ + message: 'WASP_WEB_CLIENT_URL must be a valid URL', +}); +const jwtTokenSchema = z + .string({ + required_error: 'JWT_SECRET is required', +}); +// In development, we provide default values for some environment variables +// to make the development process easier +const serverDevSchema = z.object({ + NODE_ENV: z.literal('development'), + WASP_SERVER_URL: serverUrlSchema + .default('http://localhost:3001'), + WASP_WEB_CLIENT_URL: clientUrlSchema + .default('http://localhost:3000/'), + JWT_SECRET: jwtTokenSchema + .default('DEVJWTSECRET'), +}); +const serverProdSchema = z.object({ + NODE_ENV: z.literal('production'), + WASP_SERVER_URL: serverUrlSchema, + WASP_WEB_CLIENT_URL: clientUrlSchema, + JWT_SECRET: jwtTokenSchema, +}); +const serverEnvSchema = z.discriminatedUnion('NODE_ENV', [ + serverDevSchema.merge(serverCommonSchema), + serverProdSchema.merge(serverCommonSchema) +]); +export const env = ensureEnvSchema(process.env, serverEnvSchema); +//# sourceMappingURL=env.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js.map b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js.map new file mode 100644 index 0000000000..f894f60d45 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js.map @@ -0,0 +1 @@ +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC;QACzB,cAAc,EAAE,8BAA8B;KAC/C,CAAC;IACF,8BAA8B,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IAC1D,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC;QACzB,cAAc,EAAE,8BAA8B;KAC/C,CAAC;IACF,oBAAoB,EAAE,CAAC,CAAC,MAAM,CAAC;QAC7B,cAAc,EAAE,kCAAkC;KACnD,CAAC;CACH,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;IACpC,UAAU,EAAE,cAAc;SACvB,OAAO,CAAC,cAAc,CAAC;CAC3B,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;IACpC,UAAU,EAAE,cAAc;CAC3B,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/index.d.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/index.d.ts index dee9613a53..a108f6123f 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/index.d.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/index.d.ts @@ -4,4 +4,5 @@ export { default as prisma } from './dbClient.js'; export { type ServerSetupFn } from './types/index.js'; export { HttpError } from './HttpError.js'; export { MiddlewareConfigFn } from './middleware/index.js'; +export { env } from './env.js'; export type DbSeedFn = (prisma: PrismaClient) => Promise; diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/index.js b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/index.js index 0e53e0deab..8e75e6f78c 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/index.js +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/index.js @@ -4,4 +4,6 @@ export { default as config } from './config.js'; export { default as prisma } from './dbClient.js'; // PUBLIC API export { HttpError } from './HttpError.js'; +// PUBLIC API +export { env } from './env.js'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/index.js.map b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/index.js.map index b84ac1b303..87ed22f3af 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/index.js.map +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/index.ts"],"names":[],"mappings":"AAEA,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,eAAe,CAAA;AAGjD,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/index.ts"],"names":[],"mappings":"AAEA,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,eAAe,CAAA;AAGjD,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG1C,aAAa;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/jobs/core/pgBoss/pgBoss.js b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/jobs/core/pgBoss/pgBoss.js index d1feb61aed..de0a202c7f 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/jobs/core/pgBoss/pgBoss.js +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/jobs/core/pgBoss/pgBoss.js @@ -1,14 +1,15 @@ import PgBoss from 'pg-boss'; -import { config } from 'wasp/server'; +import { env } from '../../../env.js'; +import { config } from '../../../index.js'; const boss = createPgBoss(); function createPgBoss() { let pgBossNewOptions = { connectionString: config.databaseUrl, }; // Add an escape hatch for advanced configuration of pg-boss to overwrite our defaults. - if (process.env.PG_BOSS_NEW_OPTIONS) { + if (env.PG_BOSS_NEW_OPTIONS) { try { - pgBossNewOptions = JSON.parse(process.env.PG_BOSS_NEW_OPTIONS); + pgBossNewOptions = JSON.parse(env.PG_BOSS_NEW_OPTIONS); } catch (_a) { console.error('Environment variable PG_BOSS_NEW_OPTIONS was not parsable by JSON.parse()!'); diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/jobs/core/pgBoss/pgBoss.js.map b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/jobs/core/pgBoss/pgBoss.js.map index ebe3e7b855..7080f1ddba 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/jobs/core/pgBoss/pgBoss.js.map +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/jobs/core/pgBoss/pgBoss.js.map @@ -1 +1 @@ -{"version":3,"file":"pgBoss.js","sourceRoot":"","sources":["../../../../../server/jobs/core/pgBoss/pgBoss.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,MAAM,IAAI,GAAG,YAAY,EAAE,CAAA;AAE3B,SAAS,YAAY;IACnB,IAAI,gBAAgB,GAAG;QACrB,gBAAgB,EAAE,MAAM,CAAC,WAAW;KACrC,CAAA;IAED,uFAAuF;IACvF,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC;QACpC,IAAI,CAAC;YACH,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;QAChE,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,CAAC,KAAK,CACX,4EAA4E,CAC7E,CAAA;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAA;AACrC,CAAC;AAED,IAAI,oBAA4C,CAAA;AAChD,IAAI,mBAA2C,CAAA;AAC/C,cAAc;AACd,yEAAyE;AACzE,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IACnE,oBAAoB,GAAG,OAAO,CAAA;IAC9B,mBAAmB,GAAG,MAAM,CAAA;AAC9B,CAAC,CAAC,CAAA;AAEF,IAAK,YAKJ;AALD,WAAK,YAAY;IACf,uCAAuB,CAAA;IACvB,qCAAqB,CAAA;IACrB,mCAAmB,CAAA;IACnB,+BAAe,CAAA;AACjB,CAAC,EALI,YAAY,KAAZ,YAAY,QAKhB;AAED,IAAI,YAAY,GAAiB,YAAY,CAAC,SAAS,CAAA;AAEvD,cAAc;AACd;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,sEAAsE;IACtE,IAAI,YAAY,KAAK,YAAY,CAAC,SAAS,EAAE,CAAC;QAC5C,OAAM;IACR,CAAC;IACD,YAAY,GAAG,YAAY,CAAC,QAAQ,CAAA;IACpC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAA;IAElC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;IACjD,IAAI,CAAC;QACH,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAA;QACzC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACpB,YAAY,GAAG,YAAY,CAAC,KAAK,CAAA;QACjC,mBAAmB,CAAC,IAAI,CAAC,CAAA;QACzB,OAAM;IACR,CAAC;IAED,oBAAoB,CAAC,IAAI,CAAC,CAAA;IAE1B,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;IAC/B,YAAY,GAAG,YAAY,CAAC,OAAO,CAAA;AACrC,CAAC"} \ No newline at end of file +{"version":3,"file":"pgBoss.js","sourceRoot":"","sources":["../../../../../server/jobs/core/pgBoss/pgBoss.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,MAAM,IAAI,GAAG,YAAY,EAAE,CAAA;AAE3B,SAAS,YAAY;IACnB,IAAI,gBAAgB,GAAG;QACrB,gBAAgB,EAAE,MAAM,CAAC,WAAW;KACrC,CAAA;IAED,uFAAuF;IACvF,IAAI,GAAG,CAAC,mBAAmB,EAAE,CAAC;QAC5B,IAAI,CAAC;YACH,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;QACxD,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,CAAC,KAAK,CACX,4EAA4E,CAC7E,CAAA;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAA;AACrC,CAAC;AAED,IAAI,oBAA4C,CAAA;AAChD,IAAI,mBAA2C,CAAA;AAC/C,cAAc;AACd,yEAAyE;AACzE,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IACnE,oBAAoB,GAAG,OAAO,CAAA;IAC9B,mBAAmB,GAAG,MAAM,CAAA;AAC9B,CAAC,CAAC,CAAA;AAEF,IAAK,YAKJ;AALD,WAAK,YAAY;IACf,uCAAuB,CAAA;IACvB,qCAAqB,CAAA;IACrB,mCAAmB,CAAA;IACnB,+BAAe,CAAA;AACjB,CAAC,EALI,YAAY,KAAZ,YAAY,QAKhB;AAED,IAAI,YAAY,GAAiB,YAAY,CAAC,SAAS,CAAA;AAEvD,cAAc;AACd;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,sEAAsE;IACtE,IAAI,YAAY,KAAK,YAAY,CAAC,SAAS,EAAE,CAAC;QAC5C,OAAM;IACR,CAAC;IACD,YAAY,GAAG,YAAY,CAAC,QAAQ,CAAA;IACpC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAA;IAElC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;IACjD,IAAI,CAAC;QACH,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAA;QACzC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACpB,YAAY,GAAG,YAAY,CAAC,KAAK,CAAA;QACjC,mBAAmB,CAAC,IAAI,CAAC,CAAA;QACzB,OAAM;IACR,CAAC;IAED,oBAAoB,CAAC,IAAI,CAAC,CAAA;IAE1B,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;IAC/B,YAAY,GAAG,YAAY,CAAC,OAAO,CAAA;AACrC,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/universal/url.d.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/universal/url.d.ts index aa893e7838..7ceb994694 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/universal/url.d.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/universal/url.d.ts @@ -1 +1,2 @@ -export declare function stripTrailingSlash(url?: string): string | undefined; +export declare function stripTrailingSlash(url: string): string; +export declare function stripTrailingSlash(url: undefined): undefined; diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/universal/url.js.map b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/universal/url.js.map index a7bad96020..e236f1b977 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/universal/url.js.map +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/universal/url.js.map @@ -1 +1 @@ -{"version":3,"file":"url.js","sourceRoot":"","sources":["../../universal/url.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC3C,OAAO,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC"} \ No newline at end of file +{"version":3,"file":"url.js","sourceRoot":"","sources":["../../universal/url.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC3C,OAAO,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/env/index.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/env/index.ts new file mode 100644 index 0000000000..5295a47f1a --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/env/index.ts @@ -0,0 +1,28 @@ +import * as z from 'zod' + +const redColor = '\x1b[31m' + +export function ensureEnvSchema( + data: unknown, + schema: Schema +): z.infer { + try { + return schema.parse(data) + } catch (e) { + // TODO: figure out how to output the error message in a better way + if (e instanceof z.ZodError) { + console.error(redColor, '╔═════════════════════════════╗'); + console.error(redColor, '║ Env vars validation failed ║'); + console.error(redColor, '╚═════════════════════════════╝'); + console.error() + for (const error of e.errors) { + console.error(`- ${error.message}`) + } + console.error() + console.error(redColor, '═══════════════════════════════'); + throw new Error('Error parsing environment variables') + } else { + throw e + } + } +} diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/package.json b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/package.json index 39b7641835..35aea6813e 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/package.json +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/package.json @@ -24,7 +24,8 @@ "react-hook-form": "^7.45.4", "react-router-dom": "^6.26.2", "superjson": "^2.2.1", - "vitest": "^1.2.1" + "vitest": "^1.2.1", + "zod": "^3.23.8" }, "devDependencies": { "@tsconfig/node18": "latest", diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/auth/oauth/env.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/auth/oauth/env.ts deleted file mode 100644 index ada2452b8e..0000000000 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/auth/oauth/env.ts +++ /dev/null @@ -1,15 +0,0 @@ -// PRIVATE API (SDK) -export function ensureEnvVarsForProvider( - envVarNames: EnvVarName[], - providerName: string, -): Record { - const result: Record = {}; - for (const envVarName of envVarNames) { - const value = process.env[envVarName]; - if (!value) { - throw new Error(`${envVarName} env variable is required when using the ${providerName} auth provider.`); - } - result[envVarName] = value; - } - return result as Record; -} diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/auth/oauth/provider.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/auth/oauth/provider.ts index c2aee70897..c02e5adbee 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/auth/oauth/provider.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/auth/oauth/provider.ts @@ -1,23 +1,19 @@ import { OAuth2Provider, OAuth2ProviderWithPKCE } from "arctic"; export function defineProvider< - OAuthClient extends OAuth2Provider | OAuth2ProviderWithPKCE, - Env extends Record + OAuthClient extends OAuth2Provider | OAuth2ProviderWithPKCE >({ id, displayName, - env, oAuthClient, }: { id: string; displayName: string; - env: Env; oAuthClient: OAuthClient; }) { return { id, displayName, - env, oAuthClient, }; } diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/auth/oauth/providers/google.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/auth/oauth/providers/google.ts index 9f6aaf216c..792e16d308 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/auth/oauth/providers/google.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/auth/oauth/providers/google.ts @@ -1,16 +1,11 @@ -import { Google } from "arctic"; +import { Google } from 'arctic'; -import { ensureEnvVarsForProvider } from "../env.js"; -import { getRedirectUriForCallback } from "../redirect.js"; -import { defineProvider } from "../provider.js"; +import { getRedirectUriForCallback } from '../redirect.js'; +import { defineProvider } from '../provider.js'; +import { env } from '../../../env.js'; -const id = "google"; -const displayName = "Google"; - -const env = ensureEnvVarsForProvider( - ["GOOGLE_CLIENT_ID", "GOOGLE_CLIENT_SECRET"], - displayName, -); +const id = 'google'; +const displayName = 'Google'; const oAuthClient = new Google( env.GOOGLE_CLIENT_ID, @@ -22,6 +17,5 @@ const oAuthClient = new Google( export const google = defineProvider({ id, displayName, - env, oAuthClient, }); diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/config.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/config.ts index 4ca36bd30f..557c94cf32 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/config.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/config.ts @@ -1,8 +1,7 @@ import merge from 'lodash.merge' -import { stripTrailingSlash } from "../universal/url.js"; - -const nodeEnv = process.env.NODE_ENV ?? 'development' +import { env } from './env.js' +import { stripTrailingSlash } from '../universal/url.js' // TODO: // - Use dotenv library to consume env vars from a file. @@ -11,9 +10,6 @@ const nodeEnv = process.env.NODE_ENV ?? 'development' type BaseConfig = { allowedCORSOrigins: string | string[]; - auth: { - jwtSecret: string | undefined; - } } type CommonConfig = BaseConfig & { @@ -21,6 +17,9 @@ type CommonConfig = BaseConfig & { isDevelopment: boolean; port: number; databaseUrl: string | undefined; + auth: { + jwtSecret: string | undefined; + } } type EnvConfig = BaseConfig & { @@ -36,50 +35,39 @@ const config: { production: EnvConfig, } = { all: { - env: nodeEnv, - isDevelopment: nodeEnv === 'development', - port: process.env.PORT ? parseInt(process.env.PORT) : 3001, - databaseUrl: process.env.DATABASE_URL, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, allowedCORSOrigins: [], auth: { - jwtSecret: undefined + jwtSecret: env.JWT_SECRET } }, development: getDevelopmentConfig(), production: getProductionConfig(), } -const resolvedConfig: Config = merge(config.all, config[nodeEnv]) +const resolvedConfig: Config = merge(config.all, config[env.NODE_ENV]) // PUBLIC API export default resolvedConfig function getDevelopmentConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL ?? 'http://localhost:3000/'); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL ?? 'http://localhost:3001'); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, allowedCORSOrigins: '*', - auth: { - jwtSecret: 'DEVJWTSECRET' - } } } function getProductionConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, - // @ts-ignore allowedCORSOrigins: [frontendUrl], - auth: { - jwtSecret: process.env.JWT_SECRET - } } } diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/email/index.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/email/index.ts index 3168a70671..1fcbbab85a 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/email/index.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/email/index.ts @@ -1,3 +1,4 @@ +import { env } from '../env.js'; import { initEmailSender } from "./core/index.js"; import { EmailSender } from "./core/types.js"; @@ -5,7 +6,7 @@ import { EmailSender } from "./core/types.js"; // For now, we are letting the runtime throw if they are not provided const emailProvider = { type: "sendgrid", - apiKey: process.env.SENDGRID_API_KEY!, + apiKey: env.SENDGRID_API_KEY, } as const; // PUBLIC API diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/env.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/env.ts new file mode 100644 index 0000000000..1675c54615 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/env.ts @@ -0,0 +1,68 @@ +import * as z from 'zod' + +import { ensureEnvSchema } from '../env/index.js' + +const serverCommonSchema = z.object({ + PORT: z.coerce.number().default(3001), + DATABASE_URL: z.string({ + required_error: 'DATABASE_URL is required', + }), + PG_BOSS_NEW_OPTIONS: z.string().optional(), + SENDGRID_API_KEY: z.string({ + required_error: 'SENDGRID_API_KEY is required', + }), + SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), + GOOGLE_CLIENT_ID: z.string({ + required_error: 'GOOGLE_CLIENT_ID is required', + }), + GOOGLE_CLIENT_SECRET: z.string({ + required_error: 'GOOGLE_CLIENT_SECRET is required', + }), +}) + +const serverUrlSchema = z + .string({ + required_error: 'WASP_SERVER_URL is required', + }) + .url({ + message: 'WASP_SERVER_URL must be a valid URL', + }) + +const clientUrlSchema = z + .string({ + required_error: 'WASP_WEB_CLIENT_URL is required', + }) + .url({ + message: 'WASP_WEB_CLIENT_URL must be a valid URL', + }) + +const jwtTokenSchema = z + .string({ + required_error: 'JWT_SECRET is required', + }) + +// In development, we provide default values for some environment variables +// to make the development process easier +const serverDevSchema = z.object({ + NODE_ENV: z.literal('development'), + WASP_SERVER_URL: serverUrlSchema + .default('http://localhost:3001'), + WASP_WEB_CLIENT_URL: clientUrlSchema + .default('http://localhost:3000/'), + JWT_SECRET: jwtTokenSchema + .default('DEVJWTSECRET'), +}) + +const serverProdSchema = z.object({ + NODE_ENV: z.literal('production'), + WASP_SERVER_URL: serverUrlSchema, + WASP_WEB_CLIENT_URL: clientUrlSchema, + JWT_SECRET: jwtTokenSchema, +}) + +const serverEnvSchema = z.discriminatedUnion('NODE_ENV', [ + serverDevSchema.merge(serverCommonSchema), + serverProdSchema.merge(serverCommonSchema) +]) + +export const env = ensureEnvSchema(process.env, serverEnvSchema) diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/index.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/index.ts index 535077900b..0f95deb90a 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/index.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/index.ts @@ -10,6 +10,8 @@ export { type ServerSetupFn } from './types/index.js' export { HttpError } from './HttpError.js' // PUBLIC API export { MiddlewareConfigFn } from './middleware/index.js' +// PUBLIC API +export { env } from './env.js' // PUBLIC API export type DbSeedFn = (prisma: PrismaClient) => Promise diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/jobs/core/pgBoss/pgBoss.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/jobs/core/pgBoss/pgBoss.ts index a48992aad0..0292f11176 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/jobs/core/pgBoss/pgBoss.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/jobs/core/pgBoss/pgBoss.ts @@ -1,5 +1,6 @@ import PgBoss from 'pg-boss' -import { config } from 'wasp/server' +import { env } from '../../../env.js' +import { config } from '../../../index.js' const boss = createPgBoss() @@ -9,9 +10,9 @@ function createPgBoss() { } // Add an escape hatch for advanced configuration of pg-boss to overwrite our defaults. - if (process.env.PG_BOSS_NEW_OPTIONS) { + if (env.PG_BOSS_NEW_OPTIONS) { try { - pgBossNewOptions = JSON.parse(process.env.PG_BOSS_NEW_OPTIONS) + pgBossNewOptions = JSON.parse(env.PG_BOSS_NEW_OPTIONS) } catch { console.error( 'Environment variable PG_BOSS_NEW_OPTIONS was not parsable by JSON.parse()!' diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/universal/url.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/universal/url.ts index d21c06c65c..126678dac9 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/universal/url.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/universal/url.ts @@ -1,3 +1,5 @@ +export function stripTrailingSlash(url: string): string +export function stripTrailingSlash(url: undefined): undefined export function stripTrailingSlash(url?: string): string | undefined { return url?.replace(/\/$/, ""); } diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/server/package.json b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/server/package.json index 413d85a86f..e3d0d954da 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/server/package.json +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/server/package.json @@ -34,9 +34,8 @@ "bundle-and-start": "npm run bundle && npm run start", "db-migrate-prod": "prisma migrate deploy --schema=../db/schema.prisma", "db-seed": "npm run bundle && node --enable-source-maps -r dotenv/config bundle/dbSeed.js", - "start": "npm run validate-env && node --enable-source-maps -r dotenv/config bundle/server.js", + "start": "node --enable-source-maps -r dotenv/config bundle/server.js", "start-production": "npm run db-migrate-prod && NODE_ENV=production npm run start", - "validate-env": "node -r dotenv/config ./scripts/validate-env.mjs", "watch": "nodemon --exec 'npm run bundle-and-start || exit 1'" }, "type": "module", diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/server/scripts/validate-env.mjs b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/server/scripts/validate-env.mjs deleted file mode 100644 index f6e50aceca..0000000000 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/server/scripts/validate-env.mjs +++ /dev/null @@ -1,5 +0,0 @@ -import { throwIfNotValidAbsoluteURL } from 'wasp/universal/validators'; - -console.info("🔍 Validating environment variables..."); -throwIfNotValidAbsoluteURL(process.env.WASP_WEB_CLIENT_URL, 'Environment variable WASP_WEB_CLIENT_URL'); -throwIfNotValidAbsoluteURL(process.env.WASP_SERVER_URL, 'Environment variable WASP_SERVER_URL'); diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/server/src/auth/providers/oauth/cookies.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/server/src/auth/providers/oauth/cookies.ts index 10fdd63984..b398c2e40d 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/server/src/auth/providers/oauth/cookies.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/server/src/auth/providers/oauth/cookies.ts @@ -1,10 +1,11 @@ import { Request as ExpressRequest, Response as ExpressResponse, -} from "express"; -import { parseCookies } from "oslo/cookie"; +} from 'express'; +import { parseCookies } from 'oslo/cookie'; -import type { ProviderConfig } from "wasp/auth/providers/types"; +import type { ProviderConfig } from 'wasp/auth/providers/types'; +import { config } from 'wasp/server'; import type { OAuthStateFieldName } from './state'; @@ -17,8 +18,7 @@ export function setOAuthCookieValue( const cookieName = `${provider.id}_${fieldName}`; res.cookie(cookieName, value, { httpOnly: true, - // TODO: use server config to determine if secure - secure: process.env.NODE_ENV === "production", + secure: !config.isDevelopment, path: "/", maxAge: 60 * 60 * 1000, // 1 hour }); diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/files.manifest b/waspc/e2e-test/test-outputs/waspJob-golden/files.manifest index 7f7ab93dbc..5a841ca13a 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/files.manifest +++ b/waspc/e2e-test/test-outputs/waspJob-golden/files.manifest @@ -7,6 +7,7 @@ waspJob/.wasp/out/installedNpmDepsLog.json waspJob/.wasp/out/sdk/wasp/api/events.ts waspJob/.wasp/out/sdk/wasp/api/index.ts waspJob/.wasp/out/sdk/wasp/client/config.ts +waspJob/.wasp/out/sdk/wasp/client/env.ts waspJob/.wasp/out/sdk/wasp/client/index.ts waspJob/.wasp/out/sdk/wasp/client/operations/actions/core.ts waspJob/.wasp/out/sdk/wasp/client/operations/actions/index.ts @@ -36,6 +37,9 @@ waspJob/.wasp/out/sdk/wasp/dist/api/index.js.map waspJob/.wasp/out/sdk/wasp/dist/client/config.d.ts waspJob/.wasp/out/sdk/wasp/dist/client/config.js waspJob/.wasp/out/sdk/wasp/dist/client/config.js.map +waspJob/.wasp/out/sdk/wasp/dist/client/env.d.ts +waspJob/.wasp/out/sdk/wasp/dist/client/env.js +waspJob/.wasp/out/sdk/wasp/dist/client/env.js.map waspJob/.wasp/out/sdk/wasp/dist/client/index.d.ts waspJob/.wasp/out/sdk/wasp/dist/client/index.js waspJob/.wasp/out/sdk/wasp/dist/client/index.js.map @@ -99,6 +103,9 @@ waspJob/.wasp/out/sdk/wasp/dist/dev/index.js.map waspJob/.wasp/out/sdk/wasp/dist/entities/index.d.ts waspJob/.wasp/out/sdk/wasp/dist/entities/index.js waspJob/.wasp/out/sdk/wasp/dist/entities/index.js.map +waspJob/.wasp/out/sdk/wasp/dist/env/index.d.ts +waspJob/.wasp/out/sdk/wasp/dist/env/index.js +waspJob/.wasp/out/sdk/wasp/dist/env/index.js.map waspJob/.wasp/out/sdk/wasp/dist/ext-src/MainPage.d.ts waspJob/.wasp/out/sdk/wasp/dist/ext-src/MainPage.jsx waspJob/.wasp/out/sdk/wasp/dist/ext-src/MainPage.jsx.map @@ -123,6 +130,9 @@ waspJob/.wasp/out/sdk/wasp/dist/server/config.js.map waspJob/.wasp/out/sdk/wasp/dist/server/dbClient.d.ts waspJob/.wasp/out/sdk/wasp/dist/server/dbClient.js waspJob/.wasp/out/sdk/wasp/dist/server/dbClient.js.map +waspJob/.wasp/out/sdk/wasp/dist/server/env.d.ts +waspJob/.wasp/out/sdk/wasp/dist/server/env.js +waspJob/.wasp/out/sdk/wasp/dist/server/env.js.map waspJob/.wasp/out/sdk/wasp/dist/server/index.d.ts waspJob/.wasp/out/sdk/wasp/dist/server/index.js waspJob/.wasp/out/sdk/wasp/dist/server/index.js.map @@ -187,6 +197,7 @@ waspJob/.wasp/out/sdk/wasp/dist/universal/validators.d.ts waspJob/.wasp/out/sdk/wasp/dist/universal/validators.js waspJob/.wasp/out/sdk/wasp/dist/universal/validators.js.map waspJob/.wasp/out/sdk/wasp/entities/index.ts +waspJob/.wasp/out/sdk/wasp/env/index.ts waspJob/.wasp/out/sdk/wasp/ext-src/Main.css waspJob/.wasp/out/sdk/wasp/ext-src/MainPage.jsx waspJob/.wasp/out/sdk/wasp/ext-src/server/jobs/bar.js @@ -200,6 +211,7 @@ waspJob/.wasp/out/sdk/wasp/server/_types/serialization.ts waspJob/.wasp/out/sdk/wasp/server/_types/taggedEntities.ts waspJob/.wasp/out/sdk/wasp/server/config.ts waspJob/.wasp/out/sdk/wasp/server/dbClient.ts +waspJob/.wasp/out/sdk/wasp/server/env.ts waspJob/.wasp/out/sdk/wasp/server/index.ts waspJob/.wasp/out/sdk/wasp/server/jobs/core/job.ts waspJob/.wasp/out/sdk/wasp/server/jobs/core/pgBoss/index.ts @@ -229,7 +241,6 @@ waspJob/.wasp/out/server/README.md waspJob/.wasp/out/server/nodemon.json waspJob/.wasp/out/server/package.json waspJob/.wasp/out/server/rollup.config.js -waspJob/.wasp/out/server/scripts/validate-env.mjs waspJob/.wasp/out/server/src/app.js waspJob/.wasp/out/server/src/jobs/core/allJobs.ts waspJob/.wasp/out/server/src/jobs/mySpecialJob.ts diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/.waspchecksums b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/.waspchecksums index e78a68deeb..51289675c0 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/.waspchecksums @@ -18,14 +18,21 @@ "file", "../out/sdk/wasp/client/config.ts" ], - "d94e8bee5fd8f6793b511652b9ee558e57f4913595763137a5385cd929648168" + "4c5835ad64352cc87a4a17e41fd70333bc0d1eedd7339d7ad3d3507cdb64038d" + ], + [ + [ + "file", + "../out/sdk/wasp/client/env.ts" + ], + "f630ded0392d5b60be93e1852f80ea8c75bc10262aee6fb106b6eb2561339362" ], [ [ "file", "../out/sdk/wasp/client/index.ts" ], - "2b3651e7040a63cfd6a271c2aa89f21cf01170e0abeb6c5ab74adde324852fe4" + "d5a83474d2db10e1ac90899a0e302503bf26b3ab5ab00c07b5f5ce0d9e6de2d4" ], [ [ @@ -167,6 +174,13 @@ ], "c59b97b122b977b5171686c92ee5ff2d80d397c2e83cc0915affb6ee136406fb" ], + [ + [ + "file", + "../out/sdk/wasp/env/index.ts" + ], + "cd4e86f3c0f1cacd868984f4103a47fe100037758adc8ba3adf1a5a9d6c1c880" + ], [ [ "file", @@ -207,7 +221,7 @@ "file", "../out/sdk/wasp/package.json" ], - "c8e81e8cf56626b9051ba9bd6abc9ad7b3c41419f4b710c28b90382264396402" + "657fd7af5d76fbb099b945cae4f34fa4fab061d3606b1ad1d03e81ee0d59535f" ], [ [ @@ -249,7 +263,7 @@ "file", "../out/sdk/wasp/server/config.ts" ], - "5dd35660e0969defaa3c180179919f4922ab7bc041746872dff7f2280c1872ae" + "dd528b5db722210a5781f39c4d410024211f31964383bcc708a2611bd8d9d195" ], [ [ @@ -258,12 +272,19 @@ ], "50f11eb232174184be5fd44e8ee3875c30707b486c8c70c3f7bfb93609d38e66" ], + [ + [ + "file", + "../out/sdk/wasp/server/env.ts" + ], + "b6195fe1bead580b7e4009586a55066196c496f085e68505bafd767f7b0048cf" + ], [ [ "file", "../out/sdk/wasp/server/index.ts" ], - "51c3e0802764f72b88f6daaf148dba514ae817e233a40cc9b92ec91784f71f98" + "a8d2ffa7dfd0a13f7fb6135193bcdac1f860603bdd0ddc2843033fd4f6f6151f" ], [ [ @@ -284,7 +305,7 @@ "file", "../out/sdk/wasp/server/jobs/core/pgBoss/pgBoss.ts" ], - "4c405b3cf98a4cea0ee906a46e4676ebe7ce08c1652c1b502403a93ebbbf943a" + "6ffb60e3dd86ebf2f83248d18e3d647018b3d583233c64259559221fe9d2c882" ], [ [ @@ -403,7 +424,7 @@ "file", "../out/sdk/wasp/universal/url.ts" ], - "8dc6e044a1a231b796465d94985ca47c5efd42a5d411b407a7d83a61ebae4b6d" + "58ff4ad8ffc79264d7215461571d909f3c5fb177ff32c67058d1da9cd4115d6e" ], [ [ @@ -431,7 +452,7 @@ "file", "Dockerfile" ], - "8851d4e81582d58921a5646dcf063b31dbf8ce9a46f3d4710360d2047dc644b5" + "c7525922516652d1be259b7f1bf3a242e0ce1d3516c190aa0c28de57fe3d41de" ], [ [ @@ -480,7 +501,7 @@ "file", "server/package.json" ], - "a4eb7e59ac5309fc5c39ccd7e19f4fdc7a9a568a3b393f62358ef6a6065d65c3" + "eaaa1e16e4962f38deb7220a7439a26b920ed7f852890242d084b4cebc63b7c3" ], [ [ @@ -489,13 +510,6 @@ ], "c1beb8264f11898364288d73b16f08d1923bac5f70038d9827978deb5b58a2da" ], - [ - [ - "file", - "server/scripts/validate-env.mjs" - ], - "100177b4326ccab7362eff378315d532ad1cc17cd28d1ed5978cb167fd627746" - ], [ [ "file", diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/Dockerfile b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/Dockerfile index 44152eecda..df538e8aba 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/Dockerfile +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/Dockerfile @@ -53,12 +53,12 @@ COPY --from=server-builder /app/node_modules ./node_modules # Copying the SDK because 'validate-env.mjs' executes independent of the bundle # and references the 'wasp' package. COPY --from=server-builder /app/.wasp/out/sdk .wasp/out/sdk -# Copying 'server/node_modules' because 'validate-env.mjs' executes independent -# of the bundle and references the dotenv package. +# Copying 'server/node_modules' because we require dotenv package to +# load environment variables +# TODO: replace dotenv with native Node.js environment variable loading COPY --from=server-builder /app/.wasp/build/server/node_modules .wasp/build/server/node_modules COPY --from=server-builder /app/.wasp/build/server/bundle .wasp/build/server/bundle COPY --from=server-builder /app/.wasp/build/server/package*.json .wasp/build/server/ -COPY --from=server-builder /app/.wasp/build/server/scripts .wasp/build/server/scripts COPY db/ .wasp/build/db/ EXPOSE ${PORT} WORKDIR /app/.wasp/build/server diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/installedNpmDepsLog.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/installedNpmDepsLog.json index 3a691152a0..550b37b38c 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/installedNpmDepsLog.json +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/installedNpmDepsLog.json @@ -1 +1 @@ -{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"pg-boss","version":"^8.4.2"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file +{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"pg-boss","version":"^8.4.2"},{"name":"zod","version":"^3.23.8"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/client/config.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/client/config.ts index 82b0f80b6a..fff77cb01c 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/client/config.ts +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/client/config.ts @@ -1,6 +1,7 @@ import { stripTrailingSlash } from '../universal/url.js' +import { env } from './env.js' -const apiUrl = stripTrailingSlash(import.meta.env.REACT_APP_API_URL) || 'http://localhost:3001'; +const apiUrl = stripTrailingSlash(env.REACT_APP_API_URL) // PUBLIC API export type ClientConfig = { diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/client/env.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/client/env.ts new file mode 100644 index 0000000000..dfa9e70ee3 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/client/env.ts @@ -0,0 +1,13 @@ +import * as z from 'zod' + +import { ensureEnvSchema } from '../env/index.js' + +const clientEnvSchema = z.object({ + REACT_APP_API_URL: z + .string({ + required_error: 'REACT_APP_API_URL is required', + }) + .default('http://localhost:3001') +}) + +export const env = ensureEnvSchema(import.meta.env, clientEnvSchema) diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/client/index.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/client/index.ts index cfce564c4d..33db447837 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/client/index.ts +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/client/index.ts @@ -12,3 +12,6 @@ export type Route = { method: HttpMethod; path: string } // PUBLIC API export { config, ClientConfig } from './config' + +// PUBLIC API +export { env } from './env.js' diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/config.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/config.js index 1dffbd68bc..7e6149f386 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/config.js +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/config.js @@ -1,5 +1,6 @@ import { stripTrailingSlash } from '../universal/url.js'; -const apiUrl = stripTrailingSlash(import.meta.env.REACT_APP_API_URL) || 'http://localhost:3001'; +import { env } from './env.js'; +const apiUrl = stripTrailingSlash(env.REACT_APP_API_URL); // PUBLIC API export const config = { apiUrl, diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/config.js.map b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/config.js.map index d26d37022b..f9e186b838 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/config.js.map +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../client/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAExD,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,uBAAuB,CAAC;AAOhG,aAAa;AACb,MAAM,CAAC,MAAM,MAAM,GAAiB;IAClC,MAAM;CACP,CAAA"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../client/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;AAOxD,aAAa;AACb,MAAM,CAAC,MAAM,MAAM,GAAiB;IAClC,MAAM;CACP,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/env.d.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/env.d.ts new file mode 100644 index 0000000000..5a9417a810 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/env.d.ts @@ -0,0 +1,3 @@ +export declare const env: { + REACT_APP_API_URL: string; +}; diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/env.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/env.js new file mode 100644 index 0000000000..692179bc05 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/env.js @@ -0,0 +1,11 @@ +import * as z from 'zod'; +import { ensureEnvSchema } from '../env/index.js'; +const clientEnvSchema = z.object({ + REACT_APP_API_URL: z + .string({ + required_error: 'REACT_APP_API_URL is required', + }) + .default('http://localhost:3001') +}); +export const env = ensureEnvSchema(import.meta.env, clientEnvSchema); +//# sourceMappingURL=env.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/env.js.map b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/env.js.map new file mode 100644 index 0000000000..bde7e9e367 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/env.js.map @@ -0,0 +1 @@ +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../client/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,iBAAiB,EAAE,CAAC;SACjB,MAAM,CAAC;QACN,cAAc,EAAE,+BAA+B;KAChD,CAAC;SACD,OAAO,CAAC,uBAAuB,CAAC;CACpC,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/index.d.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/index.d.ts index 7f5f4bfbc8..d5196de766 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/index.d.ts +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/index.d.ts @@ -9,3 +9,4 @@ export type Route = { path: string; }; export { config, ClientConfig } from './config'; +export { env } from './env.js'; diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/index.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/index.js index 5a7f13dcae..38dec51286 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/index.js +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/index.js @@ -9,4 +9,6 @@ export var HttpMethod; })(HttpMethod || (HttpMethod = {})); // PUBLIC API export { config } from './config'; +// PUBLIC API +export { env } from './env.js'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/index.js.map b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/index.js.map index 879953c8df..c827752797 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/index.js.map +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/client/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../client/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,mFAAmF;AACnF,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACrB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;AAClB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AAKD,aAAa;AACb,OAAO,EAAE,MAAM,EAAgB,MAAM,UAAU,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../client/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,mFAAmF;AACnF,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACrB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;AAClB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AAKD,aAAa;AACb,OAAO,EAAE,MAAM,EAAgB,MAAM,UAAU,CAAA;AAE/C,aAAa;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.d.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.d.ts new file mode 100644 index 0000000000..6bc9d059a3 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.d.ts @@ -0,0 +1,2 @@ +import * as z from 'zod'; +export declare function ensureEnvSchema(data: unknown, schema: Schema): z.infer; diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.js new file mode 100644 index 0000000000..a44104d78e --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.js @@ -0,0 +1,26 @@ +import * as z from 'zod'; +const redColor = '\x1b[31m'; +export function ensureEnvSchema(data, schema) { + try { + return schema.parse(data); + } + catch (e) { + // TODO: figure out how to output the error message in a better way + if (e instanceof z.ZodError) { + console.error(redColor, '╔═════════════════════════════╗'); + console.error(redColor, '║ Env vars validation failed ║'); + console.error(redColor, '╚═════════════════════════════╝'); + console.error(); + for (const error of e.errors) { + console.error(`- ${error.message}`); + } + console.error(); + console.error(redColor, '═══════════════════════════════'); + throw new Error('Error parsing environment variables'); + } + else { + throw e; + } + } +} +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.js.map b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.js.map new file mode 100644 index 0000000000..8cf4149a5b --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YACrC,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.js index e4f89082c8..f38fa5795a 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.js +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.js @@ -1,42 +1,35 @@ -var _a; import merge from 'lodash.merge'; -import { stripTrailingSlash } from "../universal/url.js"; -const nodeEnv = (_a = process.env.NODE_ENV) !== null && _a !== void 0 ? _a : 'development'; +import { env } from './env.js'; +import { stripTrailingSlash } from '../universal/url.js'; const config = { all: { - env: nodeEnv, - isDevelopment: nodeEnv === 'development', - port: process.env.PORT ? parseInt(process.env.PORT) : 3001, - databaseUrl: process.env.DATABASE_URL, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, allowedCORSOrigins: [], }, development: getDevelopmentConfig(), production: getProductionConfig(), }; -const resolvedConfig = merge(config.all, config[nodeEnv]); +const resolvedConfig = merge(config.all, config[env.NODE_ENV]); // PUBLIC API export default resolvedConfig; function getDevelopmentConfig() { - var _a, _b; - const frontendUrl = stripTrailingSlash((_a = process.env.WASP_WEB_CLIENT_URL) !== null && _a !== void 0 ? _a : 'http://localhost:3000/'); - const serverUrl = stripTrailingSlash((_b = process.env.WASP_SERVER_URL) !== null && _b !== void 0 ? _b : 'http://localhost:3001'); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, allowedCORSOrigins: '*', }; } function getProductionConfig() { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, - // @ts-ignore allowedCORSOrigins: [frontendUrl], }; } diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.js.map b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.js.map index e284580bbd..fe5abce123 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.js.map +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,QAAQ,mCAAI,aAAa,CAAA;AAyBrD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,OAAO;QACZ,aAAa,EAAE,OAAO,KAAK,aAAa;QACxC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;QAC1D,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;QACrC,kBAAkB,EAAE,EAAE;KACvB;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;AACjE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,mBAAmB,mCAAI,wBAAwB,CAAC,CAAC;IACpG,MAAM,SAAS,GAAG,kBAAkB,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,eAAe,mCAAI,uBAAuB,CAAC,CAAC;IAC7F,OAAO;QACL,aAAa;QACb,WAAW;QACX,aAAa;QACb,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACxE,MAAM,SAAS,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAClE,OAAO;QACL,aAAa;QACb,WAAW;QACX,aAAa;QACb,SAAS;QACT,aAAa;QACb,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAyBxD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,GAAG,CAAC,QAAQ;QACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;QAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,YAAY;QAC7B,kBAAkB,EAAE,EAAE;KACvB;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;AACtE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.d.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.d.ts new file mode 100644 index 0000000000..667ea30e35 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.d.ts @@ -0,0 +1,17 @@ +export declare const env: { + PORT: number; + DATABASE_URL: string; + SKIP_EMAIL_VERIFICATION_IN_DEV: boolean; + NODE_ENV: "development"; + WASP_SERVER_URL: string; + WASP_WEB_CLIENT_URL: string; + PG_BOSS_NEW_OPTIONS?: string | undefined; +} | { + PORT: number; + DATABASE_URL: string; + SKIP_EMAIL_VERIFICATION_IN_DEV: boolean; + NODE_ENV: "production"; + WASP_SERVER_URL: string; + WASP_WEB_CLIENT_URL: string; + PG_BOSS_NEW_OPTIONS?: string | undefined; +}; diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.js new file mode 100644 index 0000000000..d6bdbc9f66 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.js @@ -0,0 +1,48 @@ +import * as z from 'zod'; +import { ensureEnvSchema } from '../env/index.js'; +const serverCommonSchema = z.object({ + PORT: z.coerce.number().default(3001), + DATABASE_URL: z.string({ + required_error: 'DATABASE_URL is required', + }), + PG_BOSS_NEW_OPTIONS: z.string().optional(), + SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), +}); +const serverUrlSchema = z + .string({ + required_error: 'WASP_SERVER_URL is required', +}) + .url({ + message: 'WASP_SERVER_URL must be a valid URL', +}); +const clientUrlSchema = z + .string({ + required_error: 'WASP_WEB_CLIENT_URL is required', +}) + .url({ + message: 'WASP_WEB_CLIENT_URL must be a valid URL', +}); +const jwtTokenSchema = z + .string({ + required_error: 'JWT_SECRET is required', +}); +// In development, we provide default values for some environment variables +// to make the development process easier +const serverDevSchema = z.object({ + NODE_ENV: z.literal('development'), + WASP_SERVER_URL: serverUrlSchema + .default('http://localhost:3001'), + WASP_WEB_CLIENT_URL: clientUrlSchema + .default('http://localhost:3000/'), +}); +const serverProdSchema = z.object({ + NODE_ENV: z.literal('production'), + WASP_SERVER_URL: serverUrlSchema, + WASP_WEB_CLIENT_URL: clientUrlSchema, +}); +const serverEnvSchema = z.discriminatedUnion('NODE_ENV', [ + serverDevSchema.merge(serverCommonSchema), + serverProdSchema.merge(serverCommonSchema) +]); +export const env = ensureEnvSchema(process.env, serverEnvSchema); +//# sourceMappingURL=env.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.js.map b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.js.map new file mode 100644 index 0000000000..ecf2d3e0fa --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.js.map @@ -0,0 +1 @@ +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,8BAA8B,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;CAC3D,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;CACrC,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/index.d.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/index.d.ts index dee9613a53..a108f6123f 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/index.d.ts +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/index.d.ts @@ -4,4 +4,5 @@ export { default as prisma } from './dbClient.js'; export { type ServerSetupFn } from './types/index.js'; export { HttpError } from './HttpError.js'; export { MiddlewareConfigFn } from './middleware/index.js'; +export { env } from './env.js'; export type DbSeedFn = (prisma: PrismaClient) => Promise; diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/index.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/index.js index 0e53e0deab..8e75e6f78c 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/index.js +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/index.js @@ -4,4 +4,6 @@ export { default as config } from './config.js'; export { default as prisma } from './dbClient.js'; // PUBLIC API export { HttpError } from './HttpError.js'; +// PUBLIC API +export { env } from './env.js'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/index.js.map b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/index.js.map index b84ac1b303..87ed22f3af 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/index.js.map +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/index.ts"],"names":[],"mappings":"AAEA,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,eAAe,CAAA;AAGjD,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/index.ts"],"names":[],"mappings":"AAEA,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,eAAe,CAAA;AAGjD,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG1C,aAAa;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/jobs/core/pgBoss/pgBoss.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/jobs/core/pgBoss/pgBoss.js index d1feb61aed..de0a202c7f 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/jobs/core/pgBoss/pgBoss.js +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/jobs/core/pgBoss/pgBoss.js @@ -1,14 +1,15 @@ import PgBoss from 'pg-boss'; -import { config } from 'wasp/server'; +import { env } from '../../../env.js'; +import { config } from '../../../index.js'; const boss = createPgBoss(); function createPgBoss() { let pgBossNewOptions = { connectionString: config.databaseUrl, }; // Add an escape hatch for advanced configuration of pg-boss to overwrite our defaults. - if (process.env.PG_BOSS_NEW_OPTIONS) { + if (env.PG_BOSS_NEW_OPTIONS) { try { - pgBossNewOptions = JSON.parse(process.env.PG_BOSS_NEW_OPTIONS); + pgBossNewOptions = JSON.parse(env.PG_BOSS_NEW_OPTIONS); } catch (_a) { console.error('Environment variable PG_BOSS_NEW_OPTIONS was not parsable by JSON.parse()!'); diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/jobs/core/pgBoss/pgBoss.js.map b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/jobs/core/pgBoss/pgBoss.js.map index ebe3e7b855..7080f1ddba 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/jobs/core/pgBoss/pgBoss.js.map +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/jobs/core/pgBoss/pgBoss.js.map @@ -1 +1 @@ -{"version":3,"file":"pgBoss.js","sourceRoot":"","sources":["../../../../../server/jobs/core/pgBoss/pgBoss.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,MAAM,IAAI,GAAG,YAAY,EAAE,CAAA;AAE3B,SAAS,YAAY;IACnB,IAAI,gBAAgB,GAAG;QACrB,gBAAgB,EAAE,MAAM,CAAC,WAAW;KACrC,CAAA;IAED,uFAAuF;IACvF,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC;QACpC,IAAI,CAAC;YACH,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;QAChE,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,CAAC,KAAK,CACX,4EAA4E,CAC7E,CAAA;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAA;AACrC,CAAC;AAED,IAAI,oBAA4C,CAAA;AAChD,IAAI,mBAA2C,CAAA;AAC/C,cAAc;AACd,yEAAyE;AACzE,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IACnE,oBAAoB,GAAG,OAAO,CAAA;IAC9B,mBAAmB,GAAG,MAAM,CAAA;AAC9B,CAAC,CAAC,CAAA;AAEF,IAAK,YAKJ;AALD,WAAK,YAAY;IACf,uCAAuB,CAAA;IACvB,qCAAqB,CAAA;IACrB,mCAAmB,CAAA;IACnB,+BAAe,CAAA;AACjB,CAAC,EALI,YAAY,KAAZ,YAAY,QAKhB;AAED,IAAI,YAAY,GAAiB,YAAY,CAAC,SAAS,CAAA;AAEvD,cAAc;AACd;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,sEAAsE;IACtE,IAAI,YAAY,KAAK,YAAY,CAAC,SAAS,EAAE,CAAC;QAC5C,OAAM;IACR,CAAC;IACD,YAAY,GAAG,YAAY,CAAC,QAAQ,CAAA;IACpC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAA;IAElC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;IACjD,IAAI,CAAC;QACH,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAA;QACzC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACpB,YAAY,GAAG,YAAY,CAAC,KAAK,CAAA;QACjC,mBAAmB,CAAC,IAAI,CAAC,CAAA;QACzB,OAAM;IACR,CAAC;IAED,oBAAoB,CAAC,IAAI,CAAC,CAAA;IAE1B,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;IAC/B,YAAY,GAAG,YAAY,CAAC,OAAO,CAAA;AACrC,CAAC"} \ No newline at end of file +{"version":3,"file":"pgBoss.js","sourceRoot":"","sources":["../../../../../server/jobs/core/pgBoss/pgBoss.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,MAAM,IAAI,GAAG,YAAY,EAAE,CAAA;AAE3B,SAAS,YAAY;IACnB,IAAI,gBAAgB,GAAG;QACrB,gBAAgB,EAAE,MAAM,CAAC,WAAW;KACrC,CAAA;IAED,uFAAuF;IACvF,IAAI,GAAG,CAAC,mBAAmB,EAAE,CAAC;QAC5B,IAAI,CAAC;YACH,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;QACxD,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,CAAC,KAAK,CACX,4EAA4E,CAC7E,CAAA;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAA;AACrC,CAAC;AAED,IAAI,oBAA4C,CAAA;AAChD,IAAI,mBAA2C,CAAA;AAC/C,cAAc;AACd,yEAAyE;AACzE,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IACnE,oBAAoB,GAAG,OAAO,CAAA;IAC9B,mBAAmB,GAAG,MAAM,CAAA;AAC9B,CAAC,CAAC,CAAA;AAEF,IAAK,YAKJ;AALD,WAAK,YAAY;IACf,uCAAuB,CAAA;IACvB,qCAAqB,CAAA;IACrB,mCAAmB,CAAA;IACnB,+BAAe,CAAA;AACjB,CAAC,EALI,YAAY,KAAZ,YAAY,QAKhB;AAED,IAAI,YAAY,GAAiB,YAAY,CAAC,SAAS,CAAA;AAEvD,cAAc;AACd;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,sEAAsE;IACtE,IAAI,YAAY,KAAK,YAAY,CAAC,SAAS,EAAE,CAAC;QAC5C,OAAM;IACR,CAAC;IACD,YAAY,GAAG,YAAY,CAAC,QAAQ,CAAA;IACpC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAA;IAElC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;IACjD,IAAI,CAAC;QACH,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAA;QACzC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACpB,YAAY,GAAG,YAAY,CAAC,KAAK,CAAA;QACjC,mBAAmB,CAAC,IAAI,CAAC,CAAA;QACzB,OAAM;IACR,CAAC;IAED,oBAAoB,CAAC,IAAI,CAAC,CAAA;IAE1B,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;IAC/B,YAAY,GAAG,YAAY,CAAC,OAAO,CAAA;AACrC,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/universal/url.d.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/universal/url.d.ts index aa893e7838..7ceb994694 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/universal/url.d.ts +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/universal/url.d.ts @@ -1 +1,2 @@ -export declare function stripTrailingSlash(url?: string): string | undefined; +export declare function stripTrailingSlash(url: string): string; +export declare function stripTrailingSlash(url: undefined): undefined; diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/universal/url.js.map b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/universal/url.js.map index a7bad96020..e236f1b977 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/universal/url.js.map +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/universal/url.js.map @@ -1 +1 @@ -{"version":3,"file":"url.js","sourceRoot":"","sources":["../../universal/url.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC3C,OAAO,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC"} \ No newline at end of file +{"version":3,"file":"url.js","sourceRoot":"","sources":["../../universal/url.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC3C,OAAO,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/env/index.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/env/index.ts new file mode 100644 index 0000000000..5295a47f1a --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/env/index.ts @@ -0,0 +1,28 @@ +import * as z from 'zod' + +const redColor = '\x1b[31m' + +export function ensureEnvSchema( + data: unknown, + schema: Schema +): z.infer { + try { + return schema.parse(data) + } catch (e) { + // TODO: figure out how to output the error message in a better way + if (e instanceof z.ZodError) { + console.error(redColor, '╔═════════════════════════════╗'); + console.error(redColor, '║ Env vars validation failed ║'); + console.error(redColor, '╚═════════════════════════════╝'); + console.error() + for (const error of e.errors) { + console.error(`- ${error.message}`) + } + console.error() + console.error(redColor, '═══════════════════════════════'); + throw new Error('Error parsing environment variables') + } else { + throw e + } + } +} diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/package.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/package.json index ce5f990604..d8a57527fe 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/package.json +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/package.json @@ -17,7 +17,8 @@ "react-hook-form": "^7.45.4", "react-router-dom": "^6.26.2", "superjson": "^2.2.1", - "vitest": "^1.2.1" + "vitest": "^1.2.1", + "zod": "^3.23.8" }, "devDependencies": { "@tsconfig/node18": "latest", diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/config.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/config.ts index 1dc9bafb93..27a7537a0f 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/config.ts +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/config.ts @@ -1,8 +1,7 @@ import merge from 'lodash.merge' -import { stripTrailingSlash } from "../universal/url.js"; - -const nodeEnv = process.env.NODE_ENV ?? 'development' +import { env } from './env.js' +import { stripTrailingSlash } from '../universal/url.js' // TODO: // - Use dotenv library to consume env vars from a file. @@ -33,41 +32,36 @@ const config: { production: EnvConfig, } = { all: { - env: nodeEnv, - isDevelopment: nodeEnv === 'development', - port: process.env.PORT ? parseInt(process.env.PORT) : 3001, - databaseUrl: process.env.DATABASE_URL, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, allowedCORSOrigins: [], }, development: getDevelopmentConfig(), production: getProductionConfig(), } -const resolvedConfig: Config = merge(config.all, config[nodeEnv]) +const resolvedConfig: Config = merge(config.all, config[env.NODE_ENV]) // PUBLIC API export default resolvedConfig function getDevelopmentConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL ?? 'http://localhost:3000/'); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL ?? 'http://localhost:3001'); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, allowedCORSOrigins: '*', } } function getProductionConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, - // @ts-ignore allowedCORSOrigins: [frontendUrl], } } diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/env.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/env.ts new file mode 100644 index 0000000000..cd30bc35f5 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/env.ts @@ -0,0 +1,56 @@ +import * as z from 'zod' + +import { ensureEnvSchema } from '../env/index.js' + +const serverCommonSchema = z.object({ + PORT: z.coerce.number().default(3001), + DATABASE_URL: z.string({ + required_error: 'DATABASE_URL is required', + }), + PG_BOSS_NEW_OPTIONS: z.string().optional(), + SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), +}) + +const serverUrlSchema = z + .string({ + required_error: 'WASP_SERVER_URL is required', + }) + .url({ + message: 'WASP_SERVER_URL must be a valid URL', + }) + +const clientUrlSchema = z + .string({ + required_error: 'WASP_WEB_CLIENT_URL is required', + }) + .url({ + message: 'WASP_WEB_CLIENT_URL must be a valid URL', + }) + +const jwtTokenSchema = z + .string({ + required_error: 'JWT_SECRET is required', + }) + +// In development, we provide default values for some environment variables +// to make the development process easier +const serverDevSchema = z.object({ + NODE_ENV: z.literal('development'), + WASP_SERVER_URL: serverUrlSchema + .default('http://localhost:3001'), + WASP_WEB_CLIENT_URL: clientUrlSchema + .default('http://localhost:3000/'), +}) + +const serverProdSchema = z.object({ + NODE_ENV: z.literal('production'), + WASP_SERVER_URL: serverUrlSchema, + WASP_WEB_CLIENT_URL: clientUrlSchema, +}) + +const serverEnvSchema = z.discriminatedUnion('NODE_ENV', [ + serverDevSchema.merge(serverCommonSchema), + serverProdSchema.merge(serverCommonSchema) +]) + +export const env = ensureEnvSchema(process.env, serverEnvSchema) diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/index.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/index.ts index 535077900b..0f95deb90a 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/index.ts +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/index.ts @@ -10,6 +10,8 @@ export { type ServerSetupFn } from './types/index.js' export { HttpError } from './HttpError.js' // PUBLIC API export { MiddlewareConfigFn } from './middleware/index.js' +// PUBLIC API +export { env } from './env.js' // PUBLIC API export type DbSeedFn = (prisma: PrismaClient) => Promise diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/jobs/core/pgBoss/pgBoss.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/jobs/core/pgBoss/pgBoss.ts index a48992aad0..0292f11176 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/jobs/core/pgBoss/pgBoss.ts +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/jobs/core/pgBoss/pgBoss.ts @@ -1,5 +1,6 @@ import PgBoss from 'pg-boss' -import { config } from 'wasp/server' +import { env } from '../../../env.js' +import { config } from '../../../index.js' const boss = createPgBoss() @@ -9,9 +10,9 @@ function createPgBoss() { } // Add an escape hatch for advanced configuration of pg-boss to overwrite our defaults. - if (process.env.PG_BOSS_NEW_OPTIONS) { + if (env.PG_BOSS_NEW_OPTIONS) { try { - pgBossNewOptions = JSON.parse(process.env.PG_BOSS_NEW_OPTIONS) + pgBossNewOptions = JSON.parse(env.PG_BOSS_NEW_OPTIONS) } catch { console.error( 'Environment variable PG_BOSS_NEW_OPTIONS was not parsable by JSON.parse()!' diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/universal/url.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/universal/url.ts index d21c06c65c..126678dac9 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/universal/url.ts +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/universal/url.ts @@ -1,3 +1,5 @@ +export function stripTrailingSlash(url: string): string +export function stripTrailingSlash(url: undefined): undefined export function stripTrailingSlash(url?: string): string | undefined { return url?.replace(/\/$/, ""); } diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/package.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/package.json index 7a57413e11..51ec87354a 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/package.json +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/package.json @@ -34,9 +34,8 @@ "bundle-and-start": "npm run bundle && npm run start", "db-migrate-prod": "prisma migrate deploy --schema=../db/schema.prisma", "db-seed": "npm run bundle && node --enable-source-maps -r dotenv/config bundle/dbSeed.js", - "start": "npm run validate-env && node --enable-source-maps -r dotenv/config bundle/server.js", + "start": "node --enable-source-maps -r dotenv/config bundle/server.js", "start-production": "NODE_ENV=production npm run start", - "validate-env": "node -r dotenv/config ./scripts/validate-env.mjs", "watch": "nodemon --exec 'npm run bundle-and-start || exit 1'" }, "type": "module", diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/scripts/validate-env.mjs b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/scripts/validate-env.mjs deleted file mode 100644 index f6e50aceca..0000000000 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/scripts/validate-env.mjs +++ /dev/null @@ -1,5 +0,0 @@ -import { throwIfNotValidAbsoluteURL } from 'wasp/universal/validators'; - -console.info("🔍 Validating environment variables..."); -throwIfNotValidAbsoluteURL(process.env.WASP_WEB_CLIENT_URL, 'Environment variable WASP_WEB_CLIENT_URL'); -throwIfNotValidAbsoluteURL(process.env.WASP_SERVER_URL, 'Environment variable WASP_SERVER_URL'); diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/files.manifest b/waspc/e2e-test/test-outputs/waspMigrate-golden/files.manifest index 5cd0312ecc..bd29970f97 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/files.manifest +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/files.manifest @@ -10,6 +10,7 @@ waspMigrate/.wasp/out/installedNpmDepsLog.json waspMigrate/.wasp/out/sdk/wasp/api/events.ts waspMigrate/.wasp/out/sdk/wasp/api/index.ts waspMigrate/.wasp/out/sdk/wasp/client/config.ts +waspMigrate/.wasp/out/sdk/wasp/client/env.ts waspMigrate/.wasp/out/sdk/wasp/client/index.ts waspMigrate/.wasp/out/sdk/wasp/client/operations/actions/core.ts waspMigrate/.wasp/out/sdk/wasp/client/operations/actions/index.ts @@ -39,6 +40,9 @@ waspMigrate/.wasp/out/sdk/wasp/dist/api/index.js.map waspMigrate/.wasp/out/sdk/wasp/dist/client/config.d.ts waspMigrate/.wasp/out/sdk/wasp/dist/client/config.js waspMigrate/.wasp/out/sdk/wasp/dist/client/config.js.map +waspMigrate/.wasp/out/sdk/wasp/dist/client/env.d.ts +waspMigrate/.wasp/out/sdk/wasp/dist/client/env.js +waspMigrate/.wasp/out/sdk/wasp/dist/client/env.js.map waspMigrate/.wasp/out/sdk/wasp/dist/client/index.d.ts waspMigrate/.wasp/out/sdk/wasp/dist/client/index.js waspMigrate/.wasp/out/sdk/wasp/dist/client/index.js.map @@ -102,6 +106,9 @@ waspMigrate/.wasp/out/sdk/wasp/dist/dev/index.js.map waspMigrate/.wasp/out/sdk/wasp/dist/entities/index.d.ts waspMigrate/.wasp/out/sdk/wasp/dist/entities/index.js waspMigrate/.wasp/out/sdk/wasp/dist/entities/index.js.map +waspMigrate/.wasp/out/sdk/wasp/dist/env/index.d.ts +waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js +waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js.map waspMigrate/.wasp/out/sdk/wasp/dist/ext-src/MainPage.d.ts waspMigrate/.wasp/out/sdk/wasp/dist/ext-src/MainPage.jsx waspMigrate/.wasp/out/sdk/wasp/dist/ext-src/MainPage.jsx.map @@ -123,6 +130,9 @@ waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js.map waspMigrate/.wasp/out/sdk/wasp/dist/server/dbClient.d.ts waspMigrate/.wasp/out/sdk/wasp/dist/server/dbClient.js waspMigrate/.wasp/out/sdk/wasp/dist/server/dbClient.js.map +waspMigrate/.wasp/out/sdk/wasp/dist/server/env.d.ts +waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js +waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js.map waspMigrate/.wasp/out/sdk/wasp/dist/server/index.d.ts waspMigrate/.wasp/out/sdk/wasp/dist/server/index.js waspMigrate/.wasp/out/sdk/wasp/dist/server/index.js.map @@ -166,6 +176,7 @@ waspMigrate/.wasp/out/sdk/wasp/dist/universal/validators.d.ts waspMigrate/.wasp/out/sdk/wasp/dist/universal/validators.js waspMigrate/.wasp/out/sdk/wasp/dist/universal/validators.js.map waspMigrate/.wasp/out/sdk/wasp/entities/index.ts +waspMigrate/.wasp/out/sdk/wasp/env/index.ts waspMigrate/.wasp/out/sdk/wasp/ext-src/Main.css waspMigrate/.wasp/out/sdk/wasp/ext-src/MainPage.jsx waspMigrate/.wasp/out/sdk/wasp/ext-src/vite-env.d.ts @@ -178,6 +189,7 @@ waspMigrate/.wasp/out/sdk/wasp/server/_types/serialization.ts waspMigrate/.wasp/out/sdk/wasp/server/_types/taggedEntities.ts waspMigrate/.wasp/out/sdk/wasp/server/config.ts waspMigrate/.wasp/out/sdk/wasp/server/dbClient.ts +waspMigrate/.wasp/out/sdk/wasp/server/env.ts waspMigrate/.wasp/out/sdk/wasp/server/index.ts waspMigrate/.wasp/out/sdk/wasp/server/middleware/globalMiddleware.ts waspMigrate/.wasp/out/sdk/wasp/server/middleware/index.ts @@ -200,7 +212,6 @@ waspMigrate/.wasp/out/server/README.md waspMigrate/.wasp/out/server/nodemon.json waspMigrate/.wasp/out/server/package.json waspMigrate/.wasp/out/server/rollup.config.js -waspMigrate/.wasp/out/server/scripts/validate-env.mjs waspMigrate/.wasp/out/server/src/app.js waspMigrate/.wasp/out/server/src/middleware/globalMiddleware.ts waspMigrate/.wasp/out/server/src/middleware/index.ts diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/.waspchecksums b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/.waspchecksums index 74fc3dbc3b..989e23fdb5 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/.waspchecksums @@ -18,14 +18,21 @@ "file", "../out/sdk/wasp/client/config.ts" ], - "d94e8bee5fd8f6793b511652b9ee558e57f4913595763137a5385cd929648168" + "4c5835ad64352cc87a4a17e41fd70333bc0d1eedd7339d7ad3d3507cdb64038d" + ], + [ + [ + "file", + "../out/sdk/wasp/client/env.ts" + ], + "f630ded0392d5b60be93e1852f80ea8c75bc10262aee6fb106b6eb2561339362" ], [ [ "file", "../out/sdk/wasp/client/index.ts" ], - "2b3651e7040a63cfd6a271c2aa89f21cf01170e0abeb6c5ab74adde324852fe4" + "d5a83474d2db10e1ac90899a0e302503bf26b3ab5ab00c07b5f5ce0d9e6de2d4" ], [ [ @@ -167,6 +174,13 @@ ], "c5077f0d9a9224986a1c42b54de449e48af1f2b9ecc8778eb44cd55ebd9d23a7" ], + [ + [ + "file", + "../out/sdk/wasp/env/index.ts" + ], + "cd4e86f3c0f1cacd868984f4103a47fe100037758adc8ba3adf1a5a9d6c1c880" + ], [ [ "file", @@ -200,7 +214,7 @@ "file", "../out/sdk/wasp/package.json" ], - "6f1afd30c951e1f49740256440cd626c9cb521cf0822d93d2d2a5d63d8719d7b" + "d18af37d0188a6c4c9eef72705e31caf179664cb8621eaacf8bc4c21bc57c212" ], [ [ @@ -242,7 +256,7 @@ "file", "../out/sdk/wasp/server/config.ts" ], - "5dd35660e0969defaa3c180179919f4922ab7bc041746872dff7f2280c1872ae" + "dd528b5db722210a5781f39c4d410024211f31964383bcc708a2611bd8d9d195" ], [ [ @@ -251,12 +265,19 @@ ], "c5f88f028ad62b4a2fd5d1206aa72165f74c6f46f96250512af6ae55a5354020" ], + [ + [ + "file", + "../out/sdk/wasp/server/env.ts" + ], + "b6195fe1bead580b7e4009586a55066196c496f085e68505bafd767f7b0048cf" + ], [ [ "file", "../out/sdk/wasp/server/index.ts" ], - "51c3e0802764f72b88f6daaf148dba514ae817e233a40cc9b92ec91784f71f98" + "a8d2ffa7dfd0a13f7fb6135193bcdac1f860603bdd0ddc2843033fd4f6f6151f" ], [ [ @@ -347,7 +368,7 @@ "file", "../out/sdk/wasp/universal/url.ts" ], - "8dc6e044a1a231b796465d94985ca47c5efd42a5d411b407a7d83a61ebae4b6d" + "58ff4ad8ffc79264d7215461571d909f3c5fb177ff32c67058d1da9cd4115d6e" ], [ [ @@ -375,7 +396,7 @@ "file", "Dockerfile" ], - "db2dae70d212749a7e758117e55f00968f84974d8307dc7d33154bf1429486c2" + "3adb787bfea53c4b0a04c73992cba82163fa0b2217169c822a754e54511cee64" ], [ [ @@ -424,7 +445,7 @@ "file", "server/package.json" ], - "00ae054bb5597a45cc4e5277f88d24f4399fccabaa3614bf6ea89424fcd23480" + "ddda728300aaca5ccbd8342479cede7930cd5841c01f048415da8172314a1e0a" ], [ [ @@ -433,13 +454,6 @@ ], "c1beb8264f11898364288d73b16f08d1923bac5f70038d9827978deb5b58a2da" ], - [ - [ - "file", - "server/scripts/validate-env.mjs" - ], - "100177b4326ccab7362eff378315d532ad1cc17cd28d1ed5978cb167fd627746" - ], [ [ "file", diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/Dockerfile b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/Dockerfile index 76baedb0e0..1030b7ec6c 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/Dockerfile +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/Dockerfile @@ -55,12 +55,12 @@ COPY --from=server-builder /app/node_modules ./node_modules # Copying the SDK because 'validate-env.mjs' executes independent of the bundle # and references the 'wasp' package. COPY --from=server-builder /app/.wasp/out/sdk .wasp/out/sdk -# Copying 'server/node_modules' because 'validate-env.mjs' executes independent -# of the bundle and references the dotenv package. +# Copying 'server/node_modules' because we require dotenv package to +# load environment variables +# TODO: replace dotenv with native Node.js environment variable loading COPY --from=server-builder /app/.wasp/build/server/node_modules .wasp/build/server/node_modules COPY --from=server-builder /app/.wasp/build/server/bundle .wasp/build/server/bundle COPY --from=server-builder /app/.wasp/build/server/package*.json .wasp/build/server/ -COPY --from=server-builder /app/.wasp/build/server/scripts .wasp/build/server/scripts COPY db/ .wasp/build/db/ EXPOSE ${PORT} WORKDIR /app/.wasp/build/server diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/installedNpmDepsLog.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/installedNpmDepsLog.json index 88f5516a48..90c0d4bc56 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/installedNpmDepsLog.json +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/installedNpmDepsLog.json @@ -1 +1 @@ -{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file +{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"zod","version":"^3.23.8"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/client/config.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/client/config.ts index 82b0f80b6a..fff77cb01c 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/client/config.ts +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/client/config.ts @@ -1,6 +1,7 @@ import { stripTrailingSlash } from '../universal/url.js' +import { env } from './env.js' -const apiUrl = stripTrailingSlash(import.meta.env.REACT_APP_API_URL) || 'http://localhost:3001'; +const apiUrl = stripTrailingSlash(env.REACT_APP_API_URL) // PUBLIC API export type ClientConfig = { diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/client/env.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/client/env.ts new file mode 100644 index 0000000000..dfa9e70ee3 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/client/env.ts @@ -0,0 +1,13 @@ +import * as z from 'zod' + +import { ensureEnvSchema } from '../env/index.js' + +const clientEnvSchema = z.object({ + REACT_APP_API_URL: z + .string({ + required_error: 'REACT_APP_API_URL is required', + }) + .default('http://localhost:3001') +}) + +export const env = ensureEnvSchema(import.meta.env, clientEnvSchema) diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/client/index.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/client/index.ts index cfce564c4d..33db447837 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/client/index.ts +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/client/index.ts @@ -12,3 +12,6 @@ export type Route = { method: HttpMethod; path: string } // PUBLIC API export { config, ClientConfig } from './config' + +// PUBLIC API +export { env } from './env.js' diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/config.js b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/config.js index 1dffbd68bc..7e6149f386 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/config.js +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/config.js @@ -1,5 +1,6 @@ import { stripTrailingSlash } from '../universal/url.js'; -const apiUrl = stripTrailingSlash(import.meta.env.REACT_APP_API_URL) || 'http://localhost:3001'; +import { env } from './env.js'; +const apiUrl = stripTrailingSlash(env.REACT_APP_API_URL); // PUBLIC API export const config = { apiUrl, diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/config.js.map b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/config.js.map index d26d37022b..f9e186b838 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/config.js.map +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../client/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAExD,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,uBAAuB,CAAC;AAOhG,aAAa;AACb,MAAM,CAAC,MAAM,MAAM,GAAiB;IAClC,MAAM;CACP,CAAA"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../client/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;AAOxD,aAAa;AACb,MAAM,CAAC,MAAM,MAAM,GAAiB;IAClC,MAAM;CACP,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/env.d.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/env.d.ts new file mode 100644 index 0000000000..5a9417a810 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/env.d.ts @@ -0,0 +1,3 @@ +export declare const env: { + REACT_APP_API_URL: string; +}; diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/env.js b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/env.js new file mode 100644 index 0000000000..692179bc05 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/env.js @@ -0,0 +1,11 @@ +import * as z from 'zod'; +import { ensureEnvSchema } from '../env/index.js'; +const clientEnvSchema = z.object({ + REACT_APP_API_URL: z + .string({ + required_error: 'REACT_APP_API_URL is required', + }) + .default('http://localhost:3001') +}); +export const env = ensureEnvSchema(import.meta.env, clientEnvSchema); +//# sourceMappingURL=env.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/env.js.map b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/env.js.map new file mode 100644 index 0000000000..bde7e9e367 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/env.js.map @@ -0,0 +1 @@ +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../client/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,iBAAiB,EAAE,CAAC;SACjB,MAAM,CAAC;QACN,cAAc,EAAE,+BAA+B;KAChD,CAAC;SACD,OAAO,CAAC,uBAAuB,CAAC;CACpC,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/index.d.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/index.d.ts index 7f5f4bfbc8..d5196de766 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/index.d.ts +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/index.d.ts @@ -9,3 +9,4 @@ export type Route = { path: string; }; export { config, ClientConfig } from './config'; +export { env } from './env.js'; diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/index.js b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/index.js index 5a7f13dcae..38dec51286 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/index.js +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/index.js @@ -9,4 +9,6 @@ export var HttpMethod; })(HttpMethod || (HttpMethod = {})); // PUBLIC API export { config } from './config'; +// PUBLIC API +export { env } from './env.js'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/index.js.map b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/index.js.map index 879953c8df..c827752797 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/index.js.map +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/client/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../client/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,mFAAmF;AACnF,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACrB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;AAClB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AAKD,aAAa;AACb,OAAO,EAAE,MAAM,EAAgB,MAAM,UAAU,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../client/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,mFAAmF;AACnF,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACrB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;AAClB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AAKD,aAAa;AACb,OAAO,EAAE,MAAM,EAAgB,MAAM,UAAU,CAAA;AAE/C,aAAa;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.d.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.d.ts new file mode 100644 index 0000000000..6bc9d059a3 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.d.ts @@ -0,0 +1,2 @@ +import * as z from 'zod'; +export declare function ensureEnvSchema(data: unknown, schema: Schema): z.infer; diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js new file mode 100644 index 0000000000..a44104d78e --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js @@ -0,0 +1,26 @@ +import * as z from 'zod'; +const redColor = '\x1b[31m'; +export function ensureEnvSchema(data, schema) { + try { + return schema.parse(data); + } + catch (e) { + // TODO: figure out how to output the error message in a better way + if (e instanceof z.ZodError) { + console.error(redColor, '╔═════════════════════════════╗'); + console.error(redColor, '║ Env vars validation failed ║'); + console.error(redColor, '╚═════════════════════════════╝'); + console.error(); + for (const error of e.errors) { + console.error(`- ${error.message}`); + } + console.error(); + console.error(redColor, '═══════════════════════════════'); + throw new Error('Error parsing environment variables'); + } + else { + throw e; + } + } +} +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js.map b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js.map new file mode 100644 index 0000000000..8cf4149a5b --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YACrC,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js index e4f89082c8..f38fa5795a 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js @@ -1,42 +1,35 @@ -var _a; import merge from 'lodash.merge'; -import { stripTrailingSlash } from "../universal/url.js"; -const nodeEnv = (_a = process.env.NODE_ENV) !== null && _a !== void 0 ? _a : 'development'; +import { env } from './env.js'; +import { stripTrailingSlash } from '../universal/url.js'; const config = { all: { - env: nodeEnv, - isDevelopment: nodeEnv === 'development', - port: process.env.PORT ? parseInt(process.env.PORT) : 3001, - databaseUrl: process.env.DATABASE_URL, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, allowedCORSOrigins: [], }, development: getDevelopmentConfig(), production: getProductionConfig(), }; -const resolvedConfig = merge(config.all, config[nodeEnv]); +const resolvedConfig = merge(config.all, config[env.NODE_ENV]); // PUBLIC API export default resolvedConfig; function getDevelopmentConfig() { - var _a, _b; - const frontendUrl = stripTrailingSlash((_a = process.env.WASP_WEB_CLIENT_URL) !== null && _a !== void 0 ? _a : 'http://localhost:3000/'); - const serverUrl = stripTrailingSlash((_b = process.env.WASP_SERVER_URL) !== null && _b !== void 0 ? _b : 'http://localhost:3001'); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, allowedCORSOrigins: '*', }; } function getProductionConfig() { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, - // @ts-ignore allowedCORSOrigins: [frontendUrl], }; } diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js.map b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js.map index e284580bbd..fe5abce123 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js.map +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,QAAQ,mCAAI,aAAa,CAAA;AAyBrD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,OAAO;QACZ,aAAa,EAAE,OAAO,KAAK,aAAa;QACxC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;QAC1D,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;QACrC,kBAAkB,EAAE,EAAE;KACvB;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;AACjE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,mBAAmB,mCAAI,wBAAwB,CAAC,CAAC;IACpG,MAAM,SAAS,GAAG,kBAAkB,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,eAAe,mCAAI,uBAAuB,CAAC,CAAC;IAC7F,OAAO;QACL,aAAa;QACb,WAAW;QACX,aAAa;QACb,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACxE,MAAM,SAAS,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAClE,OAAO;QACL,aAAa;QACb,WAAW;QACX,aAAa;QACb,SAAS;QACT,aAAa;QACb,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAyBxD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,GAAG,CAAC,QAAQ;QACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;QAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,YAAY;QAC7B,kBAAkB,EAAE,EAAE;KACvB;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;AACtE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.d.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.d.ts new file mode 100644 index 0000000000..667ea30e35 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.d.ts @@ -0,0 +1,17 @@ +export declare const env: { + PORT: number; + DATABASE_URL: string; + SKIP_EMAIL_VERIFICATION_IN_DEV: boolean; + NODE_ENV: "development"; + WASP_SERVER_URL: string; + WASP_WEB_CLIENT_URL: string; + PG_BOSS_NEW_OPTIONS?: string | undefined; +} | { + PORT: number; + DATABASE_URL: string; + SKIP_EMAIL_VERIFICATION_IN_DEV: boolean; + NODE_ENV: "production"; + WASP_SERVER_URL: string; + WASP_WEB_CLIENT_URL: string; + PG_BOSS_NEW_OPTIONS?: string | undefined; +}; diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js new file mode 100644 index 0000000000..d6bdbc9f66 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js @@ -0,0 +1,48 @@ +import * as z from 'zod'; +import { ensureEnvSchema } from '../env/index.js'; +const serverCommonSchema = z.object({ + PORT: z.coerce.number().default(3001), + DATABASE_URL: z.string({ + required_error: 'DATABASE_URL is required', + }), + PG_BOSS_NEW_OPTIONS: z.string().optional(), + SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), +}); +const serverUrlSchema = z + .string({ + required_error: 'WASP_SERVER_URL is required', +}) + .url({ + message: 'WASP_SERVER_URL must be a valid URL', +}); +const clientUrlSchema = z + .string({ + required_error: 'WASP_WEB_CLIENT_URL is required', +}) + .url({ + message: 'WASP_WEB_CLIENT_URL must be a valid URL', +}); +const jwtTokenSchema = z + .string({ + required_error: 'JWT_SECRET is required', +}); +// In development, we provide default values for some environment variables +// to make the development process easier +const serverDevSchema = z.object({ + NODE_ENV: z.literal('development'), + WASP_SERVER_URL: serverUrlSchema + .default('http://localhost:3001'), + WASP_WEB_CLIENT_URL: clientUrlSchema + .default('http://localhost:3000/'), +}); +const serverProdSchema = z.object({ + NODE_ENV: z.literal('production'), + WASP_SERVER_URL: serverUrlSchema, + WASP_WEB_CLIENT_URL: clientUrlSchema, +}); +const serverEnvSchema = z.discriminatedUnion('NODE_ENV', [ + serverDevSchema.merge(serverCommonSchema), + serverProdSchema.merge(serverCommonSchema) +]); +export const env = ensureEnvSchema(process.env, serverEnvSchema); +//# sourceMappingURL=env.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js.map b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js.map new file mode 100644 index 0000000000..ecf2d3e0fa --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js.map @@ -0,0 +1 @@ +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,8BAA8B,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;CAC3D,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;CACrC,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/index.d.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/index.d.ts index dee9613a53..a108f6123f 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/index.d.ts +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/index.d.ts @@ -4,4 +4,5 @@ export { default as prisma } from './dbClient.js'; export { type ServerSetupFn } from './types/index.js'; export { HttpError } from './HttpError.js'; export { MiddlewareConfigFn } from './middleware/index.js'; +export { env } from './env.js'; export type DbSeedFn = (prisma: PrismaClient) => Promise; diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/index.js b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/index.js index 0e53e0deab..8e75e6f78c 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/index.js +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/index.js @@ -4,4 +4,6 @@ export { default as config } from './config.js'; export { default as prisma } from './dbClient.js'; // PUBLIC API export { HttpError } from './HttpError.js'; +// PUBLIC API +export { env } from './env.js'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/index.js.map b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/index.js.map index b84ac1b303..87ed22f3af 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/index.js.map +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/index.ts"],"names":[],"mappings":"AAEA,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,eAAe,CAAA;AAGjD,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/index.ts"],"names":[],"mappings":"AAEA,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,eAAe,CAAA;AAGjD,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG1C,aAAa;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/universal/url.d.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/universal/url.d.ts index aa893e7838..7ceb994694 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/universal/url.d.ts +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/universal/url.d.ts @@ -1 +1,2 @@ -export declare function stripTrailingSlash(url?: string): string | undefined; +export declare function stripTrailingSlash(url: string): string; +export declare function stripTrailingSlash(url: undefined): undefined; diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/universal/url.js.map b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/universal/url.js.map index a7bad96020..e236f1b977 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/universal/url.js.map +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/universal/url.js.map @@ -1 +1 @@ -{"version":3,"file":"url.js","sourceRoot":"","sources":["../../universal/url.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC3C,OAAO,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC"} \ No newline at end of file +{"version":3,"file":"url.js","sourceRoot":"","sources":["../../universal/url.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC3C,OAAO,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/env/index.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/env/index.ts new file mode 100644 index 0000000000..5295a47f1a --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/env/index.ts @@ -0,0 +1,28 @@ +import * as z from 'zod' + +const redColor = '\x1b[31m' + +export function ensureEnvSchema( + data: unknown, + schema: Schema +): z.infer { + try { + return schema.parse(data) + } catch (e) { + // TODO: figure out how to output the error message in a better way + if (e instanceof z.ZodError) { + console.error(redColor, '╔═════════════════════════════╗'); + console.error(redColor, '║ Env vars validation failed ║'); + console.error(redColor, '╚═════════════════════════════╝'); + console.error() + for (const error of e.errors) { + console.error(`- ${error.message}`) + } + console.error() + console.error(redColor, '═══════════════════════════════'); + throw new Error('Error parsing environment variables') + } else { + throw e + } + } +} diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/package.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/package.json index 2589c5362f..cae34c05e7 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/package.json +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/package.json @@ -16,7 +16,8 @@ "react-hook-form": "^7.45.4", "react-router-dom": "^6.26.2", "superjson": "^2.2.1", - "vitest": "^1.2.1" + "vitest": "^1.2.1", + "zod": "^3.23.8" }, "devDependencies": { "@tsconfig/node18": "latest", diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/config.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/config.ts index 1dc9bafb93..27a7537a0f 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/config.ts +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/config.ts @@ -1,8 +1,7 @@ import merge from 'lodash.merge' -import { stripTrailingSlash } from "../universal/url.js"; - -const nodeEnv = process.env.NODE_ENV ?? 'development' +import { env } from './env.js' +import { stripTrailingSlash } from '../universal/url.js' // TODO: // - Use dotenv library to consume env vars from a file. @@ -33,41 +32,36 @@ const config: { production: EnvConfig, } = { all: { - env: nodeEnv, - isDevelopment: nodeEnv === 'development', - port: process.env.PORT ? parseInt(process.env.PORT) : 3001, - databaseUrl: process.env.DATABASE_URL, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, allowedCORSOrigins: [], }, development: getDevelopmentConfig(), production: getProductionConfig(), } -const resolvedConfig: Config = merge(config.all, config[nodeEnv]) +const resolvedConfig: Config = merge(config.all, config[env.NODE_ENV]) // PUBLIC API export default resolvedConfig function getDevelopmentConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL ?? 'http://localhost:3000/'); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL ?? 'http://localhost:3001'); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, allowedCORSOrigins: '*', } } function getProductionConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL); + const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); + const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); return { - // @ts-ignore frontendUrl, - // @ts-ignore serverUrl, - // @ts-ignore allowedCORSOrigins: [frontendUrl], } } diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/env.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/env.ts new file mode 100644 index 0000000000..cd30bc35f5 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/env.ts @@ -0,0 +1,56 @@ +import * as z from 'zod' + +import { ensureEnvSchema } from '../env/index.js' + +const serverCommonSchema = z.object({ + PORT: z.coerce.number().default(3001), + DATABASE_URL: z.string({ + required_error: 'DATABASE_URL is required', + }), + PG_BOSS_NEW_OPTIONS: z.string().optional(), + SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), +}) + +const serverUrlSchema = z + .string({ + required_error: 'WASP_SERVER_URL is required', + }) + .url({ + message: 'WASP_SERVER_URL must be a valid URL', + }) + +const clientUrlSchema = z + .string({ + required_error: 'WASP_WEB_CLIENT_URL is required', + }) + .url({ + message: 'WASP_WEB_CLIENT_URL must be a valid URL', + }) + +const jwtTokenSchema = z + .string({ + required_error: 'JWT_SECRET is required', + }) + +// In development, we provide default values for some environment variables +// to make the development process easier +const serverDevSchema = z.object({ + NODE_ENV: z.literal('development'), + WASP_SERVER_URL: serverUrlSchema + .default('http://localhost:3001'), + WASP_WEB_CLIENT_URL: clientUrlSchema + .default('http://localhost:3000/'), +}) + +const serverProdSchema = z.object({ + NODE_ENV: z.literal('production'), + WASP_SERVER_URL: serverUrlSchema, + WASP_WEB_CLIENT_URL: clientUrlSchema, +}) + +const serverEnvSchema = z.discriminatedUnion('NODE_ENV', [ + serverDevSchema.merge(serverCommonSchema), + serverProdSchema.merge(serverCommonSchema) +]) + +export const env = ensureEnvSchema(process.env, serverEnvSchema) diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/index.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/index.ts index 535077900b..0f95deb90a 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/index.ts +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/index.ts @@ -10,6 +10,8 @@ export { type ServerSetupFn } from './types/index.js' export { HttpError } from './HttpError.js' // PUBLIC API export { MiddlewareConfigFn } from './middleware/index.js' +// PUBLIC API +export { env } from './env.js' // PUBLIC API export type DbSeedFn = (prisma: PrismaClient) => Promise diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/universal/url.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/universal/url.ts index d21c06c65c..126678dac9 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/universal/url.ts +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/universal/url.ts @@ -1,3 +1,5 @@ +export function stripTrailingSlash(url: string): string +export function stripTrailingSlash(url: undefined): undefined export function stripTrailingSlash(url?: string): string | undefined { return url?.replace(/\/$/, ""); } diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/package.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/package.json index 413d85a86f..e3d0d954da 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/package.json +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/package.json @@ -34,9 +34,8 @@ "bundle-and-start": "npm run bundle && npm run start", "db-migrate-prod": "prisma migrate deploy --schema=../db/schema.prisma", "db-seed": "npm run bundle && node --enable-source-maps -r dotenv/config bundle/dbSeed.js", - "start": "npm run validate-env && node --enable-source-maps -r dotenv/config bundle/server.js", + "start": "node --enable-source-maps -r dotenv/config bundle/server.js", "start-production": "npm run db-migrate-prod && NODE_ENV=production npm run start", - "validate-env": "node -r dotenv/config ./scripts/validate-env.mjs", "watch": "nodemon --exec 'npm run bundle-and-start || exit 1'" }, "type": "module", diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/scripts/validate-env.mjs b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/scripts/validate-env.mjs deleted file mode 100644 index f6e50aceca..0000000000 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/scripts/validate-env.mjs +++ /dev/null @@ -1,5 +0,0 @@ -import { throwIfNotValidAbsoluteURL } from 'wasp/universal/validators'; - -console.info("🔍 Validating environment variables..."); -throwIfNotValidAbsoluteURL(process.env.WASP_WEB_CLIENT_URL, 'Environment variable WASP_WEB_CLIENT_URL'); -throwIfNotValidAbsoluteURL(process.env.WASP_SERVER_URL, 'Environment variable WASP_SERVER_URL'); From fb899a09ea11867b52781e71531399ce09fee4bb Mon Sep 17 00:00:00 2001 From: Mihovil Ilakovac Date: Tue, 29 Oct 2024 15:10:18 +0100 Subject: [PATCH 4/9] Clean up --- .../Generator/templates/sdk/wasp/client/config.ts | 1 - waspc/src/Wasp/Generator/SdkGenerator.hs | 14 ++------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/waspc/data/Generator/templates/sdk/wasp/client/config.ts b/waspc/data/Generator/templates/sdk/wasp/client/config.ts index 978755541d..fff77cb01c 100644 --- a/waspc/data/Generator/templates/sdk/wasp/client/config.ts +++ b/waspc/data/Generator/templates/sdk/wasp/client/config.ts @@ -1,4 +1,3 @@ -{{={= =}=}} import { stripTrailingSlash } from '../universal/url.js' import { env } from './env.js' diff --git a/waspc/src/Wasp/Generator/SdkGenerator.hs b/waspc/src/Wasp/Generator/SdkGenerator.hs index 8646cef6d7..146cfa3c29 100644 --- a/waspc/src/Wasp/Generator/SdkGenerator.hs +++ b/waspc/src/Wasp/Generator/SdkGenerator.hs @@ -66,7 +66,6 @@ import Wasp.Generator.WebAppGenerator.Common reactRouterVersion, reactVersion, ) -import qualified Wasp.Generator.WebAppGenerator.Common as WebApp import qualified Wasp.Node.Version as NodeVersion import Wasp.Project.Common (WaspProjectDir) import qualified Wasp.Project.Db as Db @@ -100,7 +99,7 @@ genSdk spec = genFileCopy [relfile|client/test/index.ts|], genFileCopy [relfile|client/index.ts|], genFileCopy [relfile|dev/index.ts|], - genClientConfigFile, + genFileCopy [relfile|client/config.ts|], genServerConfigFile spec, genTsConfigJson, genServerUtils spec, @@ -249,18 +248,9 @@ genServerConfigFile spec = return $ C.mkTmplFdWithData relConfigFilePath tmplDat tmplData = object [ "isAuthEnabled" .= isAuthEnabled spec, - "databaseUrlEnvVarName" .= Db.databaseUrlEnvVarName, - "defaultClientUrl" .= WebApp.getDefaultDevClientUrl spec, - "defaultServerUrl" .= Server.defaultDevServerUrl, - "defaultServerPort" .= Server.defaultServerPort + "databaseUrlEnvVarName" .= Db.databaseUrlEnvVarName ] -genClientConfigFile :: Generator FileDraft -genClientConfigFile = return $ C.mkTmplFdWithData relConfigFilePath tmplData - where - relConfigFilePath = [relfile|client/config.ts|] - tmplData = object ["defaultServerUrl" .= Server.defaultDevServerUrl] - -- todo(filip): remove this duplication, we have almost the same thing in the -- ServerGenerator. genTsConfigJson :: Generator FileDraft From 7593ac259045ce528423768b171136fb4b5a0c23 Mon Sep 17 00:00:00 2001 From: Mihovil Ilakovac Date: Tue, 29 Oct 2024 15:29:42 +0100 Subject: [PATCH 5/9] Update SKIP_EMAIL_VERIFICATION_IN_DEV validation --- waspc/data/Generator/templates/sdk/wasp/env/index.ts | 3 ++- waspc/data/Generator/templates/sdk/wasp/server/env.ts | 7 ++++++- .../waspBuild-golden/waspBuild/.wasp/build/.waspchecksums | 4 ++-- .../waspBuild/.wasp/build/sdk/wasp/dist/env/index.js | 3 ++- .../waspBuild/.wasp/build/sdk/wasp/dist/env/index.js.map | 2 +- .../waspBuild/.wasp/build/sdk/wasp/dist/server/env.js | 7 ++++++- .../waspBuild/.wasp/build/sdk/wasp/dist/server/env.js.map | 2 +- .../waspBuild/.wasp/build/sdk/wasp/env/index.ts | 3 ++- .../waspBuild/.wasp/build/sdk/wasp/server/env.ts | 7 ++++++- .../waspBuild/.wasp/out/sdk/wasp/dist/env/index.js | 3 ++- .../waspBuild/.wasp/out/sdk/wasp/dist/env/index.js.map | 2 +- .../waspBuild/.wasp/out/sdk/wasp/dist/server/env.js | 7 ++++++- .../waspBuild/.wasp/out/sdk/wasp/dist/server/env.js.map | 2 +- .../waspBuild/.wasp/out/sdk/wasp/env/index.ts | 3 ++- .../waspBuild/.wasp/out/sdk/wasp/server/env.ts | 7 ++++++- .../waspCompile/.wasp/out/.waspchecksums | 4 ++-- .../waspCompile/.wasp/out/sdk/wasp/dist/env/index.js | 3 ++- .../waspCompile/.wasp/out/sdk/wasp/dist/env/index.js.map | 2 +- .../waspCompile/.wasp/out/sdk/wasp/dist/server/env.js | 7 ++++++- .../waspCompile/.wasp/out/sdk/wasp/dist/server/env.js.map | 2 +- .../waspCompile/.wasp/out/sdk/wasp/env/index.ts | 3 ++- .../waspCompile/.wasp/out/sdk/wasp/server/env.ts | 7 ++++++- .../waspComplexTest/.wasp/out/.waspchecksums | 4 ++-- .../waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js | 3 ++- .../.wasp/out/sdk/wasp/dist/env/index.js.map | 2 +- .../waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js | 7 ++++++- .../.wasp/out/sdk/wasp/dist/server/env.js.map | 2 +- .../waspComplexTest/.wasp/out/sdk/wasp/env/index.ts | 3 ++- .../waspComplexTest/.wasp/out/sdk/wasp/server/env.ts | 7 ++++++- .../waspJob-golden/waspJob/.wasp/out/.waspchecksums | 4 ++-- .../waspJob/.wasp/out/sdk/wasp/dist/env/index.js | 3 ++- .../waspJob/.wasp/out/sdk/wasp/dist/env/index.js.map | 2 +- .../waspJob/.wasp/out/sdk/wasp/dist/server/env.js | 7 ++++++- .../waspJob/.wasp/out/sdk/wasp/dist/server/env.js.map | 2 +- .../waspJob-golden/waspJob/.wasp/out/sdk/wasp/env/index.ts | 3 ++- .../waspJob/.wasp/out/sdk/wasp/server/env.ts | 7 ++++++- .../waspMigrate/.wasp/out/.waspchecksums | 4 ++-- .../waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js | 3 ++- .../waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js.map | 2 +- .../waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js | 7 ++++++- .../waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js.map | 2 +- .../waspMigrate/.wasp/out/sdk/wasp/env/index.ts | 3 ++- .../waspMigrate/.wasp/out/sdk/wasp/server/env.ts | 7 ++++++- 43 files changed, 126 insertions(+), 48 deletions(-) diff --git a/waspc/data/Generator/templates/sdk/wasp/env/index.ts b/waspc/data/Generator/templates/sdk/wasp/env/index.ts index 5295a47f1a..713aa49386 100644 --- a/waspc/data/Generator/templates/sdk/wasp/env/index.ts +++ b/waspc/data/Generator/templates/sdk/wasp/env/index.ts @@ -11,12 +11,13 @@ export function ensureEnvSchema( } catch (e) { // TODO: figure out how to output the error message in a better way if (e instanceof z.ZodError) { + console.error() console.error(redColor, '╔═════════════════════════════╗'); console.error(redColor, '║ Env vars validation failed ║'); console.error(redColor, '╚═════════════════════════════╝'); console.error() for (const error of e.errors) { - console.error(`- ${error.message}`) + console.error(redColor, `- ${error.message}`) } console.error() console.error(redColor, '═══════════════════════════════'); diff --git a/waspc/data/Generator/templates/sdk/wasp/server/env.ts b/waspc/data/Generator/templates/sdk/wasp/server/env.ts index f7d37879cd..c80f1c37e3 100644 --- a/waspc/data/Generator/templates/sdk/wasp/server/env.ts +++ b/waspc/data/Generator/templates/sdk/wasp/server/env.ts @@ -40,7 +40,12 @@ const serverCommonSchema = z.object({ MAILGUN_API_URL: z.string().optional(), {=/ enabledEmailSenders.isMailgunProviderUsed =} {=/ isEmailSenderUsed =} - SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), + SKIP_EMAIL_VERIFICATION_IN_DEV: z + .enum(['true', 'false'], { + message: 'SKIP_EMAIL_VERIFICATION_IN_DEV must be either "true" or "false"', + }) + .transform((value) => value === 'true') + .default('false'), {=# isAuthEnabled =} {=# enabledAuthProviders.isGoogleAuthEnabled =} GOOGLE_CLIENT_ID: z.string({ diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/.waspchecksums b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/.waspchecksums index 17e9cdd4db..6c65f4e741 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/.waspchecksums @@ -179,7 +179,7 @@ "file", "../out/sdk/wasp/env/index.ts" ], - "cd4e86f3c0f1cacd868984f4103a47fe100037758adc8ba3adf1a5a9d6c1c880" + "84a5ba04975efaade7e14b8a58d962bfa234b502d3993d3edf73cf7db85e3e42" ], [ [ @@ -270,7 +270,7 @@ "file", "../out/sdk/wasp/server/env.ts" ], - "b6195fe1bead580b7e4009586a55066196c496f085e68505bafd767f7b0048cf" + "105527a58a272d1c51fc9e5368644aeb4d0df3aa65339b2212af49d9c1992d41" ], [ [ diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.js index a44104d78e..36c04180f7 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.js @@ -7,12 +7,13 @@ export function ensureEnvSchema(data, schema) { catch (e) { // TODO: figure out how to output the error message in a better way if (e instanceof z.ZodError) { + console.error(); console.error(redColor, '╔═════════════════════════════╗'); console.error(redColor, '║ Env vars validation failed ║'); console.error(redColor, '╚═════════════════════════════╝'); console.error(); for (const error of e.errors) { - console.error(`- ${error.message}`); + console.error(redColor, `- ${error.message}`); } console.error(); console.error(redColor, '═══════════════════════════════'); diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.js.map index 8cf4149a5b..71eefab95e 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.js.map +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/env/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YACrC,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YAC/C,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.js index d6bdbc9f66..99c82bd75b 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.js @@ -6,7 +6,12 @@ const serverCommonSchema = z.object({ required_error: 'DATABASE_URL is required', }), PG_BOSS_NEW_OPTIONS: z.string().optional(), - SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), + SKIP_EMAIL_VERIFICATION_IN_DEV: z + .enum(['true', 'false'], { + message: 'SKIP_EMAIL_VERIFICATION_IN_DEV must be either "true" or "false"', + }) + .transform((value) => value === 'true') + .default('false'), }); const serverUrlSchema = z .string({ diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.js.map index ecf2d3e0fa..b118614980 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.js.map +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/env.js.map @@ -1 +1 @@ -{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,8BAA8B,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;CAC3D,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;CACrC,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,8BAA8B,EAAE,CAAC;SAC9B,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;QACvB,OAAO,EAAE,iEAAiE;KAC3E,CAAC;SACD,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC;SACtC,OAAO,CAAC,OAAO,CAAC;CACpB,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;CACrC,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/env/index.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/env/index.ts index 5295a47f1a..713aa49386 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/env/index.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/env/index.ts @@ -11,12 +11,13 @@ export function ensureEnvSchema( } catch (e) { // TODO: figure out how to output the error message in a better way if (e instanceof z.ZodError) { + console.error() console.error(redColor, '╔═════════════════════════════╗'); console.error(redColor, '║ Env vars validation failed ║'); console.error(redColor, '╚═════════════════════════════╝'); console.error() for (const error of e.errors) { - console.error(`- ${error.message}`) + console.error(redColor, `- ${error.message}`) } console.error() console.error(redColor, '═══════════════════════════════'); diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/env.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/env.ts index cd30bc35f5..c48499a728 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/env.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/env.ts @@ -8,7 +8,12 @@ const serverCommonSchema = z.object({ required_error: 'DATABASE_URL is required', }), PG_BOSS_NEW_OPTIONS: z.string().optional(), - SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), + SKIP_EMAIL_VERIFICATION_IN_DEV: z + .enum(['true', 'false'], { + message: 'SKIP_EMAIL_VERIFICATION_IN_DEV must be either "true" or "false"', + }) + .transform((value) => value === 'true') + .default('false'), }) const serverUrlSchema = z diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.js index a44104d78e..36c04180f7 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.js @@ -7,12 +7,13 @@ export function ensureEnvSchema(data, schema) { catch (e) { // TODO: figure out how to output the error message in a better way if (e instanceof z.ZodError) { + console.error(); console.error(redColor, '╔═════════════════════════════╗'); console.error(redColor, '║ Env vars validation failed ║'); console.error(redColor, '╚═════════════════════════════╝'); console.error(); for (const error of e.errors) { - console.error(`- ${error.message}`); + console.error(redColor, `- ${error.message}`); } console.error(); console.error(redColor, '═══════════════════════════════'); diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.js.map index 8cf4149a5b..71eefab95e 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.js.map +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/env/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YACrC,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YAC/C,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.js index d6bdbc9f66..99c82bd75b 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.js @@ -6,7 +6,12 @@ const serverCommonSchema = z.object({ required_error: 'DATABASE_URL is required', }), PG_BOSS_NEW_OPTIONS: z.string().optional(), - SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), + SKIP_EMAIL_VERIFICATION_IN_DEV: z + .enum(['true', 'false'], { + message: 'SKIP_EMAIL_VERIFICATION_IN_DEV must be either "true" or "false"', + }) + .transform((value) => value === 'true') + .default('false'), }); const serverUrlSchema = z .string({ diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.js.map index ecf2d3e0fa..b118614980 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.js.map +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/env.js.map @@ -1 +1 @@ -{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,8BAA8B,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;CAC3D,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;CACrC,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,8BAA8B,EAAE,CAAC;SAC9B,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;QACvB,OAAO,EAAE,iEAAiE;KAC3E,CAAC;SACD,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC;SACtC,OAAO,CAAC,OAAO,CAAC;CACpB,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;CACrC,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/env/index.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/env/index.ts index 5295a47f1a..713aa49386 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/env/index.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/env/index.ts @@ -11,12 +11,13 @@ export function ensureEnvSchema( } catch (e) { // TODO: figure out how to output the error message in a better way if (e instanceof z.ZodError) { + console.error() console.error(redColor, '╔═════════════════════════════╗'); console.error(redColor, '║ Env vars validation failed ║'); console.error(redColor, '╚═════════════════════════════╝'); console.error() for (const error of e.errors) { - console.error(`- ${error.message}`) + console.error(redColor, `- ${error.message}`) } console.error() console.error(redColor, '═══════════════════════════════'); diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/env.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/env.ts index cd30bc35f5..c48499a728 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/env.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/env.ts @@ -8,7 +8,12 @@ const serverCommonSchema = z.object({ required_error: 'DATABASE_URL is required', }), PG_BOSS_NEW_OPTIONS: z.string().optional(), - SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), + SKIP_EMAIL_VERIFICATION_IN_DEV: z + .enum(['true', 'false'], { + message: 'SKIP_EMAIL_VERIFICATION_IN_DEV must be either "true" or "false"', + }) + .transform((value) => value === 'true') + .default('false'), }) const serverUrlSchema = z diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/.waspchecksums b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/.waspchecksums index aca879273e..2aefb5dff4 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/.waspchecksums @@ -179,7 +179,7 @@ "file", "../out/sdk/wasp/env/index.ts" ], - "cd4e86f3c0f1cacd868984f4103a47fe100037758adc8ba3adf1a5a9d6c1c880" + "84a5ba04975efaade7e14b8a58d962bfa234b502d3993d3edf73cf7db85e3e42" ], [ [ @@ -270,7 +270,7 @@ "file", "../out/sdk/wasp/server/env.ts" ], - "b6195fe1bead580b7e4009586a55066196c496f085e68505bafd767f7b0048cf" + "105527a58a272d1c51fc9e5368644aeb4d0df3aa65339b2212af49d9c1992d41" ], [ [ diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.js b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.js index a44104d78e..36c04180f7 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.js +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.js @@ -7,12 +7,13 @@ export function ensureEnvSchema(data, schema) { catch (e) { // TODO: figure out how to output the error message in a better way if (e instanceof z.ZodError) { + console.error(); console.error(redColor, '╔═════════════════════════════╗'); console.error(redColor, '║ Env vars validation failed ║'); console.error(redColor, '╚═════════════════════════════╝'); console.error(); for (const error of e.errors) { - console.error(`- ${error.message}`); + console.error(redColor, `- ${error.message}`); } console.error(); console.error(redColor, '═══════════════════════════════'); diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.js.map b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.js.map index 8cf4149a5b..71eefab95e 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.js.map +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/env/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YACrC,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YAC/C,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.js b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.js index d6bdbc9f66..99c82bd75b 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.js +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.js @@ -6,7 +6,12 @@ const serverCommonSchema = z.object({ required_error: 'DATABASE_URL is required', }), PG_BOSS_NEW_OPTIONS: z.string().optional(), - SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), + SKIP_EMAIL_VERIFICATION_IN_DEV: z + .enum(['true', 'false'], { + message: 'SKIP_EMAIL_VERIFICATION_IN_DEV must be either "true" or "false"', + }) + .transform((value) => value === 'true') + .default('false'), }); const serverUrlSchema = z .string({ diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.js.map b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.js.map index ecf2d3e0fa..b118614980 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.js.map +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/env.js.map @@ -1 +1 @@ -{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,8BAA8B,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;CAC3D,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;CACrC,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,8BAA8B,EAAE,CAAC;SAC9B,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;QACvB,OAAO,EAAE,iEAAiE;KAC3E,CAAC;SACD,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC;SACtC,OAAO,CAAC,OAAO,CAAC;CACpB,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;CACrC,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/env/index.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/env/index.ts index 5295a47f1a..713aa49386 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/env/index.ts +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/env/index.ts @@ -11,12 +11,13 @@ export function ensureEnvSchema( } catch (e) { // TODO: figure out how to output the error message in a better way if (e instanceof z.ZodError) { + console.error() console.error(redColor, '╔═════════════════════════════╗'); console.error(redColor, '║ Env vars validation failed ║'); console.error(redColor, '╚═════════════════════════════╝'); console.error() for (const error of e.errors) { - console.error(`- ${error.message}`) + console.error(redColor, `- ${error.message}`) } console.error() console.error(redColor, '═══════════════════════════════'); diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/env.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/env.ts index cd30bc35f5..c48499a728 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/env.ts +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/env.ts @@ -8,7 +8,12 @@ const serverCommonSchema = z.object({ required_error: 'DATABASE_URL is required', }), PG_BOSS_NEW_OPTIONS: z.string().optional(), - SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), + SKIP_EMAIL_VERIFICATION_IN_DEV: z + .enum(['true', 'false'], { + message: 'SKIP_EMAIL_VERIFICATION_IN_DEV must be either "true" or "false"', + }) + .transform((value) => value === 'true') + .default('false'), }) const serverUrlSchema = z diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/.waspchecksums b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/.waspchecksums index ef76c07ab3..0182a92236 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/.waspchecksums @@ -396,7 +396,7 @@ "file", "../out/sdk/wasp/env/index.ts" ], - "cd4e86f3c0f1cacd868984f4103a47fe100037758adc8ba3adf1a5a9d6c1c880" + "84a5ba04975efaade7e14b8a58d962bfa234b502d3993d3edf73cf7db85e3e42" ], [ [ @@ -669,7 +669,7 @@ "file", "../out/sdk/wasp/server/env.ts" ], - "593c28a9be1dc1382c6dd36a1f93b960dc60142e9309c5d45cb8d4fedb7fd727" + "7fbf42a69723970df679ed0d89fc2c80e9d2bd3e433af73a838e3c1033ba459a" ], [ [ diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js index a44104d78e..36c04180f7 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js @@ -7,12 +7,13 @@ export function ensureEnvSchema(data, schema) { catch (e) { // TODO: figure out how to output the error message in a better way if (e instanceof z.ZodError) { + console.error(); console.error(redColor, '╔═════════════════════════════╗'); console.error(redColor, '║ Env vars validation failed ║'); console.error(redColor, '╚═════════════════════════════╝'); console.error(); for (const error of e.errors) { - console.error(`- ${error.message}`); + console.error(redColor, `- ${error.message}`); } console.error(); console.error(redColor, '═══════════════════════════════'); diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js.map b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js.map index 8cf4149a5b..71eefab95e 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js.map +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/env/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YACrC,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YAC/C,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js index c08c95130c..691331476c 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js @@ -9,7 +9,12 @@ const serverCommonSchema = z.object({ SENDGRID_API_KEY: z.string({ required_error: 'SENDGRID_API_KEY is required', }), - SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), + SKIP_EMAIL_VERIFICATION_IN_DEV: z + .enum(['true', 'false'], { + message: 'SKIP_EMAIL_VERIFICATION_IN_DEV must be either "true" or "false"', + }) + .transform((value) => value === 'true') + .default('false'), GOOGLE_CLIENT_ID: z.string({ required_error: 'GOOGLE_CLIENT_ID is required', }), diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js.map b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js.map index f894f60d45..9ef87fe808 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js.map +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/env.js.map @@ -1 +1 @@ -{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC;QACzB,cAAc,EAAE,8BAA8B;KAC/C,CAAC;IACF,8BAA8B,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IAC1D,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC;QACzB,cAAc,EAAE,8BAA8B;KAC/C,CAAC;IACF,oBAAoB,EAAE,CAAC,CAAC,MAAM,CAAC;QAC7B,cAAc,EAAE,kCAAkC;KACnD,CAAC;CACH,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;IACpC,UAAU,EAAE,cAAc;SACvB,OAAO,CAAC,cAAc,CAAC;CAC3B,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;IACpC,UAAU,EAAE,cAAc;CAC3B,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC;QACzB,cAAc,EAAE,8BAA8B;KAC/C,CAAC;IACF,8BAA8B,EAAE,CAAC;SAC9B,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;QACvB,OAAO,EAAE,iEAAiE;KAC3E,CAAC;SACD,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC;SACtC,OAAO,CAAC,OAAO,CAAC;IACnB,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC;QACzB,cAAc,EAAE,8BAA8B;KAC/C,CAAC;IACF,oBAAoB,EAAE,CAAC,CAAC,MAAM,CAAC;QAC7B,cAAc,EAAE,kCAAkC;KACnD,CAAC;CACH,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;IACpC,UAAU,EAAE,cAAc;SACvB,OAAO,CAAC,cAAc,CAAC;CAC3B,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;IACpC,UAAU,EAAE,cAAc;CAC3B,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/env/index.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/env/index.ts index 5295a47f1a..713aa49386 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/env/index.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/env/index.ts @@ -11,12 +11,13 @@ export function ensureEnvSchema( } catch (e) { // TODO: figure out how to output the error message in a better way if (e instanceof z.ZodError) { + console.error() console.error(redColor, '╔═════════════════════════════╗'); console.error(redColor, '║ Env vars validation failed ║'); console.error(redColor, '╚═════════════════════════════╝'); console.error() for (const error of e.errors) { - console.error(`- ${error.message}`) + console.error(redColor, `- ${error.message}`) } console.error() console.error(redColor, '═══════════════════════════════'); diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/env.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/env.ts index 1675c54615..7b6ef4cafd 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/env.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/env.ts @@ -11,7 +11,12 @@ const serverCommonSchema = z.object({ SENDGRID_API_KEY: z.string({ required_error: 'SENDGRID_API_KEY is required', }), - SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), + SKIP_EMAIL_VERIFICATION_IN_DEV: z + .enum(['true', 'false'], { + message: 'SKIP_EMAIL_VERIFICATION_IN_DEV must be either "true" or "false"', + }) + .transform((value) => value === 'true') + .default('false'), GOOGLE_CLIENT_ID: z.string({ required_error: 'GOOGLE_CLIENT_ID is required', }), diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/.waspchecksums b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/.waspchecksums index 51289675c0..e5c79c1f26 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/.waspchecksums @@ -179,7 +179,7 @@ "file", "../out/sdk/wasp/env/index.ts" ], - "cd4e86f3c0f1cacd868984f4103a47fe100037758adc8ba3adf1a5a9d6c1c880" + "84a5ba04975efaade7e14b8a58d962bfa234b502d3993d3edf73cf7db85e3e42" ], [ [ @@ -277,7 +277,7 @@ "file", "../out/sdk/wasp/server/env.ts" ], - "b6195fe1bead580b7e4009586a55066196c496f085e68505bafd767f7b0048cf" + "105527a58a272d1c51fc9e5368644aeb4d0df3aa65339b2212af49d9c1992d41" ], [ [ diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.js index a44104d78e..36c04180f7 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.js +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.js @@ -7,12 +7,13 @@ export function ensureEnvSchema(data, schema) { catch (e) { // TODO: figure out how to output the error message in a better way if (e instanceof z.ZodError) { + console.error(); console.error(redColor, '╔═════════════════════════════╗'); console.error(redColor, '║ Env vars validation failed ║'); console.error(redColor, '╚═════════════════════════════╝'); console.error(); for (const error of e.errors) { - console.error(`- ${error.message}`); + console.error(redColor, `- ${error.message}`); } console.error(); console.error(redColor, '═══════════════════════════════'); diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.js.map b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.js.map index 8cf4149a5b..71eefab95e 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.js.map +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/env/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YACrC,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YAC/C,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.js index d6bdbc9f66..99c82bd75b 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.js +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.js @@ -6,7 +6,12 @@ const serverCommonSchema = z.object({ required_error: 'DATABASE_URL is required', }), PG_BOSS_NEW_OPTIONS: z.string().optional(), - SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), + SKIP_EMAIL_VERIFICATION_IN_DEV: z + .enum(['true', 'false'], { + message: 'SKIP_EMAIL_VERIFICATION_IN_DEV must be either "true" or "false"', + }) + .transform((value) => value === 'true') + .default('false'), }); const serverUrlSchema = z .string({ diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.js.map b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.js.map index ecf2d3e0fa..b118614980 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.js.map +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/env.js.map @@ -1 +1 @@ -{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,8BAA8B,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;CAC3D,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;CACrC,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,8BAA8B,EAAE,CAAC;SAC9B,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;QACvB,OAAO,EAAE,iEAAiE;KAC3E,CAAC;SACD,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC;SACtC,OAAO,CAAC,OAAO,CAAC;CACpB,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;CACrC,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/env/index.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/env/index.ts index 5295a47f1a..713aa49386 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/env/index.ts +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/env/index.ts @@ -11,12 +11,13 @@ export function ensureEnvSchema( } catch (e) { // TODO: figure out how to output the error message in a better way if (e instanceof z.ZodError) { + console.error() console.error(redColor, '╔═════════════════════════════╗'); console.error(redColor, '║ Env vars validation failed ║'); console.error(redColor, '╚═════════════════════════════╝'); console.error() for (const error of e.errors) { - console.error(`- ${error.message}`) + console.error(redColor, `- ${error.message}`) } console.error() console.error(redColor, '═══════════════════════════════'); diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/env.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/env.ts index cd30bc35f5..c48499a728 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/env.ts +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/env.ts @@ -8,7 +8,12 @@ const serverCommonSchema = z.object({ required_error: 'DATABASE_URL is required', }), PG_BOSS_NEW_OPTIONS: z.string().optional(), - SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), + SKIP_EMAIL_VERIFICATION_IN_DEV: z + .enum(['true', 'false'], { + message: 'SKIP_EMAIL_VERIFICATION_IN_DEV must be either "true" or "false"', + }) + .transform((value) => value === 'true') + .default('false'), }) const serverUrlSchema = z diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/.waspchecksums b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/.waspchecksums index 989e23fdb5..e74030f231 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/.waspchecksums @@ -179,7 +179,7 @@ "file", "../out/sdk/wasp/env/index.ts" ], - "cd4e86f3c0f1cacd868984f4103a47fe100037758adc8ba3adf1a5a9d6c1c880" + "84a5ba04975efaade7e14b8a58d962bfa234b502d3993d3edf73cf7db85e3e42" ], [ [ @@ -270,7 +270,7 @@ "file", "../out/sdk/wasp/server/env.ts" ], - "b6195fe1bead580b7e4009586a55066196c496f085e68505bafd767f7b0048cf" + "105527a58a272d1c51fc9e5368644aeb4d0df3aa65339b2212af49d9c1992d41" ], [ [ diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js index a44104d78e..36c04180f7 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js @@ -7,12 +7,13 @@ export function ensureEnvSchema(data, schema) { catch (e) { // TODO: figure out how to output the error message in a better way if (e instanceof z.ZodError) { + console.error(); console.error(redColor, '╔═════════════════════════════╗'); console.error(redColor, '║ Env vars validation failed ║'); console.error(redColor, '╚═════════════════════════════╝'); console.error(); for (const error of e.errors) { - console.error(`- ${error.message}`); + console.error(redColor, `- ${error.message}`); } console.error(); console.error(redColor, '═══════════════════════════════'); diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js.map b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js.map index 8cf4149a5b..71eefab95e 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js.map +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/env/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YACrC,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAE3B,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mEAAmE;QACnE,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YAC/C,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js index d6bdbc9f66..99c82bd75b 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js @@ -6,7 +6,12 @@ const serverCommonSchema = z.object({ required_error: 'DATABASE_URL is required', }), PG_BOSS_NEW_OPTIONS: z.string().optional(), - SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), + SKIP_EMAIL_VERIFICATION_IN_DEV: z + .enum(['true', 'false'], { + message: 'SKIP_EMAIL_VERIFICATION_IN_DEV must be either "true" or "false"', + }) + .transform((value) => value === 'true') + .default('false'), }); const serverUrlSchema = z .string({ diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js.map b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js.map index ecf2d3e0fa..b118614980 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js.map +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/env.js.map @@ -1 +1 @@ -{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,8BAA8B,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;CAC3D,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;CACrC,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"env.js","sourceRoot":"","sources":["../../server/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,cAAc,EAAE,0BAA0B;KAC3C,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,8BAA8B,EAAE,CAAC;SAC9B,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;QACvB,OAAO,EAAE,iEAAiE;KAC3E,CAAC;SACD,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC;SACtC,OAAO,CAAC,OAAO,CAAC;CACpB,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,6BAA6B;CAC9C,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAA;AAEJ,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,cAAc,EAAE,iCAAiC;CAClD,CAAC;KACD,GAAG,CAAC;IACH,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAA;AAEJ,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,cAAc,EAAE,wBAAwB;CACzC,CAAC,CAAA;AAEJ,2EAA2E;AAC3E,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,eAAe,EAAE,eAAe;SAC7B,OAAO,CAAC,uBAAuB,CAAC;IACnC,mBAAmB,EAAE,eAAe;SACjC,OAAO,CAAC,wBAAwB,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACjC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;CACrC,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACvD,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACzC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/env/index.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/env/index.ts index 5295a47f1a..713aa49386 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/env/index.ts +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/env/index.ts @@ -11,12 +11,13 @@ export function ensureEnvSchema( } catch (e) { // TODO: figure out how to output the error message in a better way if (e instanceof z.ZodError) { + console.error() console.error(redColor, '╔═════════════════════════════╗'); console.error(redColor, '║ Env vars validation failed ║'); console.error(redColor, '╚═════════════════════════════╝'); console.error() for (const error of e.errors) { - console.error(`- ${error.message}`) + console.error(redColor, `- ${error.message}`) } console.error() console.error(redColor, '═══════════════════════════════'); diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/env.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/env.ts index cd30bc35f5..c48499a728 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/env.ts +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/env.ts @@ -8,7 +8,12 @@ const serverCommonSchema = z.object({ required_error: 'DATABASE_URL is required', }), PG_BOSS_NEW_OPTIONS: z.string().optional(), - SKIP_EMAIL_VERIFICATION_IN_DEV: z.boolean().default(false), + SKIP_EMAIL_VERIFICATION_IN_DEV: z + .enum(['true', 'false'], { + message: 'SKIP_EMAIL_VERIFICATION_IN_DEV must be either "true" or "false"', + }) + .transform((value) => value === 'true') + .default('false'), }) const serverUrlSchema = z From 42d121c9e7b62cb5accba382932df729f5bc5367 Mon Sep 17 00:00:00 2001 From: Mihovil Ilakovac Date: Tue, 29 Oct 2024 15:41:42 +0100 Subject: [PATCH 6/9] Update headless tests --- waspc/headless-test/examples/todoApp/.env.server.example | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/waspc/headless-test/examples/todoApp/.env.server.example b/waspc/headless-test/examples/todoApp/.env.server.example index c4b5c097c7..d0918e891b 100644 --- a/waspc/headless-test/examples/todoApp/.env.server.example +++ b/waspc/headless-test/examples/todoApp/.env.server.example @@ -1,3 +1,7 @@ GOOGLE_CLIENT_ID="mock-client-id" GOOGLE_CLIENT_SECRET="mock-client-secret" SKIP_EMAIL_VERIFICATION_IN_DEV=true +SMTP_HOST=dummy +SMTP_PORT=465 +SMTP_USERNAME=dummy +SMTP_PASSWORD=dummy From f877543f65570a9b1277def5948d2fe4614603b8 Mon Sep 17 00:00:00 2001 From: Mihovil Ilakovac Date: Wed, 30 Oct 2024 09:54:50 +0100 Subject: [PATCH 7/9] Update headless tests --- .../headless-test/examples/todoApp/package-lock.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/waspc/headless-test/examples/todoApp/package-lock.json b/waspc/headless-test/examples/todoApp/package-lock.json index 75a03b5861..d459c8c85b 100644 --- a/waspc/headless-test/examples/todoApp/package-lock.json +++ b/waspc/headless-test/examples/todoApp/package-lock.json @@ -51,7 +51,8 @@ "react-router-dom": "^6.26.2", "superjson": "^2.2.1", "tailwindcss": "^3.2.7", - "vitest": "^1.2.1" + "vitest": "^1.2.1", + "zod": "^3.23.8" }, "devDependencies": { "@tsconfig/node18": "latest", @@ -9558,6 +9559,14 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zod": { + "version": "3.23.8", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", + "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } From 025d1852e69125760491b171b52e3998297485e1 Mon Sep 17 00:00:00 2001 From: Mihovil Ilakovac Date: Wed, 30 Oct 2024 11:35:35 +0100 Subject: [PATCH 8/9] Simplify the server config --- .../templates/sdk/wasp/server/config.ts | 89 ++++++------------- .../waspBuild/.wasp/build/.waspchecksums | 4 +- .../.wasp/build/installedNpmDepsLog.json | 2 +- .../build/sdk/wasp/dist/server/config.d.ts | 19 ++-- .../build/sdk/wasp/dist/server/config.js | 45 ++++------ .../build/sdk/wasp/dist/server/config.js.map | 2 +- .../.wasp/build/sdk/wasp/package.json | 1 - .../.wasp/build/sdk/wasp/server/config.ts | 75 +++++----------- .../out/sdk/wasp/dist/server/config.d.ts | 19 ++-- .../.wasp/out/sdk/wasp/dist/server/config.js | 45 ++++------ .../out/sdk/wasp/dist/server/config.js.map | 2 +- .../waspBuild/.wasp/out/sdk/wasp/package.json | 1 - .../.wasp/out/sdk/wasp/server/config.ts | 75 +++++----------- .../waspCompile/.wasp/out/.waspchecksums | 4 +- .../.wasp/out/installedNpmDepsLog.json | 2 +- .../out/sdk/wasp/dist/server/config.d.ts | 19 ++-- .../.wasp/out/sdk/wasp/dist/server/config.js | 45 ++++------ .../out/sdk/wasp/dist/server/config.js.map | 2 +- .../.wasp/out/sdk/wasp/package.json | 1 - .../.wasp/out/sdk/wasp/server/config.ts | 75 +++++----------- .../waspComplexTest/.wasp/out/.waspchecksums | 4 +- .../.wasp/out/installedNpmDepsLog.json | 2 +- .../out/sdk/wasp/dist/server/config.d.ts | 25 +++--- .../.wasp/out/sdk/wasp/dist/server/config.js | 51 ++++------- .../out/sdk/wasp/dist/server/config.js.map | 2 +- .../.wasp/out/sdk/wasp/package.json | 1 - .../.wasp/out/sdk/wasp/server/config.ts | 85 ++++++------------ .../waspJob/.wasp/out/.waspchecksums | 4 +- .../.wasp/out/installedNpmDepsLog.json | 2 +- .../out/sdk/wasp/dist/server/config.d.ts | 19 ++-- .../.wasp/out/sdk/wasp/dist/server/config.js | 45 ++++------ .../out/sdk/wasp/dist/server/config.js.map | 2 +- .../waspJob/.wasp/out/sdk/wasp/package.json | 1 - .../.wasp/out/sdk/wasp/server/config.ts | 75 +++++----------- .../waspMigrate/.wasp/out/.waspchecksums | 4 +- .../.wasp/out/installedNpmDepsLog.json | 2 +- .../out/sdk/wasp/dist/server/config.d.ts | 19 ++-- .../.wasp/out/sdk/wasp/dist/server/config.js | 45 ++++------ .../out/sdk/wasp/dist/server/config.js.map | 2 +- .../.wasp/out/sdk/wasp/package.json | 1 - .../.wasp/out/sdk/wasp/server/config.ts | 75 +++++----------- waspc/examples/todoApp/package-lock.json | 1 - waspc/src/Wasp/Generator/SdkGenerator.hs | 1 - 43 files changed, 331 insertions(+), 664 deletions(-) diff --git a/waspc/data/Generator/templates/sdk/wasp/server/config.ts b/waspc/data/Generator/templates/sdk/wasp/server/config.ts index e87ed1a9fb..1f6b94a258 100644 --- a/waspc/data/Generator/templates/sdk/wasp/server/config.ts +++ b/waspc/data/Generator/templates/sdk/wasp/server/config.ts @@ -1,78 +1,47 @@ {{={= =}=}} -import merge from 'lodash.merge' - import { env } from './env.js' import { stripTrailingSlash } from '../universal/url.js' -// TODO: -// - Use dotenv library to consume env vars from a file. -// - Use convict library to define schema and validate env vars. -// https://codingsans.com/blog/node-config-best-practices +type NodeEnv = typeof env.NODE_ENV -type BaseConfig = { - allowedCORSOrigins: string | string[]; -} - -type CommonConfig = BaseConfig & { - env: string; +type Config = { + env: NodeEnv; isDevelopment: boolean; port: number; - databaseUrl: string | undefined; + databaseUrl: string; + frontendUrl: string; + serverUrl: string; + allowedCORSOrigins: string | string[]; {=# isAuthEnabled =} auth: { - jwtSecret: string | undefined; + jwtSecret: string; } {=/ isAuthEnabled =} } -type EnvConfig = BaseConfig & { - frontendUrl: string; - serverUrl: string; -} - -type Config = CommonConfig & EnvConfig +const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL) +const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL) -const config: { - all: CommonConfig, - development: EnvConfig, - production: EnvConfig, -} = { - all: { - env: env.NODE_ENV, - isDevelopment: env.NODE_ENV === 'development', - port: env.PORT, - databaseUrl: env.{= databaseUrlEnvVarName =}, - allowedCORSOrigins: [], - {=# isAuthEnabled =} - auth: { - jwtSecret: env.JWT_SECRET - } - {=/ isAuthEnabled =} - }, - development: getDevelopmentConfig(), - production: getProductionConfig(), +const allowedCORSOriginsPerEnv: Record = { + development: '*', + production: [frontendUrl] } - -const resolvedConfig: Config = merge(config.all, config[env.NODE_ENV]) -// PUBLIC API -export default resolvedConfig - -function getDevelopmentConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: '*', +const allowedCORSOrigins = allowedCORSOriginsPerEnv[env.NODE_ENV] + +const config: Config = { + frontendUrl, + serverUrl, + allowedCORSOrigins, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.{= databaseUrlEnvVarName =}, + {=# isAuthEnabled =} + auth: { + jwtSecret: env.JWT_SECRET } + {=/ isAuthEnabled =} } -function getProductionConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: [frontendUrl], - } -} +// PUBLIC API +export default config diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/.waspchecksums b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/.waspchecksums index 6c65f4e741..b80125b9b6 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/.waspchecksums @@ -214,7 +214,7 @@ "file", "../out/sdk/wasp/package.json" ], - "d18af37d0188a6c4c9eef72705e31caf179664cb8621eaacf8bc4c21bc57c212" + "9f8844eca690b66c914179693b7f7beedef8b7c8fe2016d9d7353d474cea3d56" ], [ [ @@ -256,7 +256,7 @@ "file", "../out/sdk/wasp/server/config.ts" ], - "dd528b5db722210a5781f39c4d410024211f31964383bcc708a2611bd8d9d195" + "8431eaf0332cdbdd2f36b4c232b4b6b65fd19bad58fe51922f5b2662f22fc8ad" ], [ [ diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/installedNpmDepsLog.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/installedNpmDepsLog.json index 90c0d4bc56..e811a78822 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/installedNpmDepsLog.json +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/installedNpmDepsLog.json @@ -1 +1 @@ -{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"zod","version":"^3.23.8"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file +{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"zod","version":"^3.23.8"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.d.ts index 68bb448c56..70f438bdf0 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.d.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.d.ts @@ -1,16 +1,13 @@ -type BaseConfig = { - allowedCORSOrigins: string | string[]; -}; -type CommonConfig = BaseConfig & { - env: string; +import { env } from './env.js'; +type NodeEnv = typeof env.NODE_ENV; +type Config = { + env: NodeEnv; isDevelopment: boolean; port: number; - databaseUrl: string | undefined; -}; -type EnvConfig = BaseConfig & { + databaseUrl: string; frontendUrl: string; serverUrl: string; + allowedCORSOrigins: string | string[]; }; -type Config = CommonConfig & EnvConfig; -declare const resolvedConfig: Config; -export default resolvedConfig; +declare const config: Config; +export default config; diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.js index f38fa5795a..dcc80722ab 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.js @@ -1,36 +1,21 @@ -import merge from 'lodash.merge'; import { env } from './env.js'; import { stripTrailingSlash } from '../universal/url.js'; +const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); +const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); +const allowedCORSOriginsPerEnv = { + development: '*', + production: [frontendUrl] +}; +const allowedCORSOrigins = allowedCORSOriginsPerEnv[env.NODE_ENV]; const config = { - all: { - env: env.NODE_ENV, - isDevelopment: env.NODE_ENV === 'development', - port: env.PORT, - databaseUrl: env.DATABASE_URL, - allowedCORSOrigins: [], - }, - development: getDevelopmentConfig(), - production: getProductionConfig(), + frontendUrl, + serverUrl, + allowedCORSOrigins, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, }; -const resolvedConfig = merge(config.all, config[env.NODE_ENV]); // PUBLIC API -export default resolvedConfig; -function getDevelopmentConfig() { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: '*', - }; -} -function getProductionConfig() { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: [frontendUrl], - }; -} +export default config; //# sourceMappingURL=config.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.js.map index fe5abce123..9fd077fa81 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.js.map +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/dist/server/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAyBxD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,GAAG,CAAC,QAAQ;QACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;QAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,YAAY;QAC7B,kBAAkB,EAAE,EAAE;KACvB;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;AACtE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAcxD,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;AAC/D,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;AAEzD,MAAM,wBAAwB,GAAuC;IACnE,WAAW,EAAE,GAAG;IAChB,UAAU,EAAE,CAAC,WAAW,CAAC;CAC1B,CAAA;AACD,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAEjE,MAAM,MAAM,GAAW;IACrB,WAAW;IACX,SAAS;IACT,kBAAkB;IAClB,GAAG,EAAE,GAAG,CAAC,QAAQ;IACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;IAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,WAAW,EAAE,GAAG,CAAC,YAAY;CAC9B,CAAA;AAED,aAAa;AACb,eAAe,MAAM,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/package.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/package.json index cae34c05e7..10a54b5d6e 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/package.json +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/package.json @@ -8,7 +8,6 @@ "axios": "^1.4.0", "express": "~4.21.0", "jsdom": "^21.1.1", - "lodash.merge": "^4.6.2", "mitt": "3.0.0", "msw": "^1.1.0", "prisma": "5.19.1", diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/config.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/config.ts index 27a7537a0f..3a000a897f 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/config.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/sdk/wasp/server/config.ts @@ -1,67 +1,36 @@ -import merge from 'lodash.merge' - import { env } from './env.js' import { stripTrailingSlash } from '../universal/url.js' -// TODO: -// - Use dotenv library to consume env vars from a file. -// - Use convict library to define schema and validate env vars. -// https://codingsans.com/blog/node-config-best-practices - -type BaseConfig = { - allowedCORSOrigins: string | string[]; -} +type NodeEnv = typeof env.NODE_ENV -type CommonConfig = BaseConfig & { - env: string; +type Config = { + env: NodeEnv; isDevelopment: boolean; port: number; - databaseUrl: string | undefined; -} - -type EnvConfig = BaseConfig & { + databaseUrl: string; frontendUrl: string; serverUrl: string; + allowedCORSOrigins: string | string[]; } -type Config = CommonConfig & EnvConfig +const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL) +const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL) -const config: { - all: CommonConfig, - development: EnvConfig, - production: EnvConfig, -} = { - all: { - env: env.NODE_ENV, - isDevelopment: env.NODE_ENV === 'development', - port: env.PORT, - databaseUrl: env.DATABASE_URL, - allowedCORSOrigins: [], - }, - development: getDevelopmentConfig(), - production: getProductionConfig(), +const allowedCORSOriginsPerEnv: Record = { + development: '*', + production: [frontendUrl] } - -const resolvedConfig: Config = merge(config.all, config[env.NODE_ENV]) -// PUBLIC API -export default resolvedConfig - -function getDevelopmentConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: '*', - } +const allowedCORSOrigins = allowedCORSOriginsPerEnv[env.NODE_ENV] + +const config: Config = { + frontendUrl, + serverUrl, + allowedCORSOrigins, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, } -function getProductionConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: [frontendUrl], - } -} +// PUBLIC API +export default config diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.d.ts index 68bb448c56..70f438bdf0 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.d.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.d.ts @@ -1,16 +1,13 @@ -type BaseConfig = { - allowedCORSOrigins: string | string[]; -}; -type CommonConfig = BaseConfig & { - env: string; +import { env } from './env.js'; +type NodeEnv = typeof env.NODE_ENV; +type Config = { + env: NodeEnv; isDevelopment: boolean; port: number; - databaseUrl: string | undefined; -}; -type EnvConfig = BaseConfig & { + databaseUrl: string; frontendUrl: string; serverUrl: string; + allowedCORSOrigins: string | string[]; }; -type Config = CommonConfig & EnvConfig; -declare const resolvedConfig: Config; -export default resolvedConfig; +declare const config: Config; +export default config; diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.js index f38fa5795a..dcc80722ab 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.js @@ -1,36 +1,21 @@ -import merge from 'lodash.merge'; import { env } from './env.js'; import { stripTrailingSlash } from '../universal/url.js'; +const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); +const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); +const allowedCORSOriginsPerEnv = { + development: '*', + production: [frontendUrl] +}; +const allowedCORSOrigins = allowedCORSOriginsPerEnv[env.NODE_ENV]; const config = { - all: { - env: env.NODE_ENV, - isDevelopment: env.NODE_ENV === 'development', - port: env.PORT, - databaseUrl: env.DATABASE_URL, - allowedCORSOrigins: [], - }, - development: getDevelopmentConfig(), - production: getProductionConfig(), + frontendUrl, + serverUrl, + allowedCORSOrigins, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, }; -const resolvedConfig = merge(config.all, config[env.NODE_ENV]); // PUBLIC API -export default resolvedConfig; -function getDevelopmentConfig() { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: '*', - }; -} -function getProductionConfig() { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: [frontendUrl], - }; -} +export default config; //# sourceMappingURL=config.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.js.map b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.js.map index fe5abce123..9fd077fa81 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.js.map +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/dist/server/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAyBxD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,GAAG,CAAC,QAAQ;QACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;QAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,YAAY;QAC7B,kBAAkB,EAAE,EAAE;KACvB;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;AACtE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAcxD,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;AAC/D,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;AAEzD,MAAM,wBAAwB,GAAuC;IACnE,WAAW,EAAE,GAAG;IAChB,UAAU,EAAE,CAAC,WAAW,CAAC;CAC1B,CAAA;AACD,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAEjE,MAAM,MAAM,GAAW;IACrB,WAAW;IACX,SAAS;IACT,kBAAkB;IAClB,GAAG,EAAE,GAAG,CAAC,QAAQ;IACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;IAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,WAAW,EAAE,GAAG,CAAC,YAAY;CAC9B,CAAA;AAED,aAAa;AACb,eAAe,MAAM,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/package.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/package.json index cae34c05e7..10a54b5d6e 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/package.json +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/package.json @@ -8,7 +8,6 @@ "axios": "^1.4.0", "express": "~4.21.0", "jsdom": "^21.1.1", - "lodash.merge": "^4.6.2", "mitt": "3.0.0", "msw": "^1.1.0", "prisma": "5.19.1", diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/config.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/config.ts index 27a7537a0f..3a000a897f 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/config.ts +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/out/sdk/wasp/server/config.ts @@ -1,67 +1,36 @@ -import merge from 'lodash.merge' - import { env } from './env.js' import { stripTrailingSlash } from '../universal/url.js' -// TODO: -// - Use dotenv library to consume env vars from a file. -// - Use convict library to define schema and validate env vars. -// https://codingsans.com/blog/node-config-best-practices - -type BaseConfig = { - allowedCORSOrigins: string | string[]; -} +type NodeEnv = typeof env.NODE_ENV -type CommonConfig = BaseConfig & { - env: string; +type Config = { + env: NodeEnv; isDevelopment: boolean; port: number; - databaseUrl: string | undefined; -} - -type EnvConfig = BaseConfig & { + databaseUrl: string; frontendUrl: string; serverUrl: string; + allowedCORSOrigins: string | string[]; } -type Config = CommonConfig & EnvConfig +const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL) +const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL) -const config: { - all: CommonConfig, - development: EnvConfig, - production: EnvConfig, -} = { - all: { - env: env.NODE_ENV, - isDevelopment: env.NODE_ENV === 'development', - port: env.PORT, - databaseUrl: env.DATABASE_URL, - allowedCORSOrigins: [], - }, - development: getDevelopmentConfig(), - production: getProductionConfig(), +const allowedCORSOriginsPerEnv: Record = { + development: '*', + production: [frontendUrl] } - -const resolvedConfig: Config = merge(config.all, config[env.NODE_ENV]) -// PUBLIC API -export default resolvedConfig - -function getDevelopmentConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: '*', - } +const allowedCORSOrigins = allowedCORSOriginsPerEnv[env.NODE_ENV] + +const config: Config = { + frontendUrl, + serverUrl, + allowedCORSOrigins, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, } -function getProductionConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: [frontendUrl], - } -} +// PUBLIC API +export default config diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/.waspchecksums b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/.waspchecksums index 2aefb5dff4..76f8bcf0c0 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/.waspchecksums @@ -214,7 +214,7 @@ "file", "../out/sdk/wasp/package.json" ], - "d18af37d0188a6c4c9eef72705e31caf179664cb8621eaacf8bc4c21bc57c212" + "9f8844eca690b66c914179693b7f7beedef8b7c8fe2016d9d7353d474cea3d56" ], [ [ @@ -256,7 +256,7 @@ "file", "../out/sdk/wasp/server/config.ts" ], - "dd528b5db722210a5781f39c4d410024211f31964383bcc708a2611bd8d9d195" + "8431eaf0332cdbdd2f36b4c232b4b6b65fd19bad58fe51922f5b2662f22fc8ad" ], [ [ diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/installedNpmDepsLog.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/installedNpmDepsLog.json index 90c0d4bc56..e811a78822 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/installedNpmDepsLog.json +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/installedNpmDepsLog.json @@ -1 +1 @@ -{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"zod","version":"^3.23.8"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file +{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"zod","version":"^3.23.8"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.d.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.d.ts index 68bb448c56..70f438bdf0 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.d.ts +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.d.ts @@ -1,16 +1,13 @@ -type BaseConfig = { - allowedCORSOrigins: string | string[]; -}; -type CommonConfig = BaseConfig & { - env: string; +import { env } from './env.js'; +type NodeEnv = typeof env.NODE_ENV; +type Config = { + env: NodeEnv; isDevelopment: boolean; port: number; - databaseUrl: string | undefined; -}; -type EnvConfig = BaseConfig & { + databaseUrl: string; frontendUrl: string; serverUrl: string; + allowedCORSOrigins: string | string[]; }; -type Config = CommonConfig & EnvConfig; -declare const resolvedConfig: Config; -export default resolvedConfig; +declare const config: Config; +export default config; diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.js b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.js index f38fa5795a..dcc80722ab 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.js +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.js @@ -1,36 +1,21 @@ -import merge from 'lodash.merge'; import { env } from './env.js'; import { stripTrailingSlash } from '../universal/url.js'; +const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); +const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); +const allowedCORSOriginsPerEnv = { + development: '*', + production: [frontendUrl] +}; +const allowedCORSOrigins = allowedCORSOriginsPerEnv[env.NODE_ENV]; const config = { - all: { - env: env.NODE_ENV, - isDevelopment: env.NODE_ENV === 'development', - port: env.PORT, - databaseUrl: env.DATABASE_URL, - allowedCORSOrigins: [], - }, - development: getDevelopmentConfig(), - production: getProductionConfig(), + frontendUrl, + serverUrl, + allowedCORSOrigins, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, }; -const resolvedConfig = merge(config.all, config[env.NODE_ENV]); // PUBLIC API -export default resolvedConfig; -function getDevelopmentConfig() { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: '*', - }; -} -function getProductionConfig() { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: [frontendUrl], - }; -} +export default config; //# sourceMappingURL=config.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.js.map b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.js.map index fe5abce123..9fd077fa81 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.js.map +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/dist/server/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAyBxD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,GAAG,CAAC,QAAQ;QACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;QAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,YAAY;QAC7B,kBAAkB,EAAE,EAAE;KACvB;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;AACtE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAcxD,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;AAC/D,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;AAEzD,MAAM,wBAAwB,GAAuC;IACnE,WAAW,EAAE,GAAG;IAChB,UAAU,EAAE,CAAC,WAAW,CAAC;CAC1B,CAAA;AACD,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAEjE,MAAM,MAAM,GAAW;IACrB,WAAW;IACX,SAAS;IACT,kBAAkB;IAClB,GAAG,EAAE,GAAG,CAAC,QAAQ;IACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;IAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,WAAW,EAAE,GAAG,CAAC,YAAY;CAC9B,CAAA;AAED,aAAa;AACb,eAAe,MAAM,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/package.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/package.json index cae34c05e7..10a54b5d6e 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/package.json +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/package.json @@ -8,7 +8,6 @@ "axios": "^1.4.0", "express": "~4.21.0", "jsdom": "^21.1.1", - "lodash.merge": "^4.6.2", "mitt": "3.0.0", "msw": "^1.1.0", "prisma": "5.19.1", diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/config.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/config.ts index 27a7537a0f..3a000a897f 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/config.ts +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/sdk/wasp/server/config.ts @@ -1,67 +1,36 @@ -import merge from 'lodash.merge' - import { env } from './env.js' import { stripTrailingSlash } from '../universal/url.js' -// TODO: -// - Use dotenv library to consume env vars from a file. -// - Use convict library to define schema and validate env vars. -// https://codingsans.com/blog/node-config-best-practices - -type BaseConfig = { - allowedCORSOrigins: string | string[]; -} +type NodeEnv = typeof env.NODE_ENV -type CommonConfig = BaseConfig & { - env: string; +type Config = { + env: NodeEnv; isDevelopment: boolean; port: number; - databaseUrl: string | undefined; -} - -type EnvConfig = BaseConfig & { + databaseUrl: string; frontendUrl: string; serverUrl: string; + allowedCORSOrigins: string | string[]; } -type Config = CommonConfig & EnvConfig +const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL) +const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL) -const config: { - all: CommonConfig, - development: EnvConfig, - production: EnvConfig, -} = { - all: { - env: env.NODE_ENV, - isDevelopment: env.NODE_ENV === 'development', - port: env.PORT, - databaseUrl: env.DATABASE_URL, - allowedCORSOrigins: [], - }, - development: getDevelopmentConfig(), - production: getProductionConfig(), +const allowedCORSOriginsPerEnv: Record = { + development: '*', + production: [frontendUrl] } - -const resolvedConfig: Config = merge(config.all, config[env.NODE_ENV]) -// PUBLIC API -export default resolvedConfig - -function getDevelopmentConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: '*', - } +const allowedCORSOrigins = allowedCORSOriginsPerEnv[env.NODE_ENV] + +const config: Config = { + frontendUrl, + serverUrl, + allowedCORSOrigins, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, } -function getProductionConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: [frontendUrl], - } -} +// PUBLIC API +export default config diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/.waspchecksums b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/.waspchecksums index 0182a92236..f6a0c52eb3 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/.waspchecksums @@ -501,7 +501,7 @@ "file", "../out/sdk/wasp/package.json" ], - "27e50b464aa1785f4651f4229f509fd2d71ed19076e341c4f3fafb98b11955c0" + "e9daaa0fd911e4211651d99935e3191bbc17f33d1c5f8e5e9960fef5a2b0497f" ], [ [ @@ -606,7 +606,7 @@ "file", "../out/sdk/wasp/server/config.ts" ], - "ee59e87efd7cf4904b33d15cde4ef65994f156a3f7fb634942a6414c3505bcf7" + "4a78cfcf41a4fa41fa61ee19404fb6f32d5c25a1f854008ad81fcd8c2191e5ab" ], [ [ diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/installedNpmDepsLog.json b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/installedNpmDepsLog.json index 2dac6a447e..346abfc6d9 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/installedNpmDepsLog.json +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/installedNpmDepsLog.json @@ -1 +1 @@ -{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"@stitches/react","version":"^1.2.8"},{"name":"@node-rs/argon2","version":"^1.8.3"},{"name":"arctic","version":"^1.2.1"},{"name":"lucia","version":"^3.0.1"},{"name":"oslo","version":"^1.1.2"},{"name":"@lucia-auth/adapter-prisma","version":"^4.0.0"},{"name":"@sendgrid/mail","version":"^7.7.0"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"pg-boss","version":"^8.4.2"},{"name":"zod","version":"^3.23.8"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file +{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"@stitches/react","version":"^1.2.8"},{"name":"@node-rs/argon2","version":"^1.8.3"},{"name":"arctic","version":"^1.2.1"},{"name":"lucia","version":"^3.0.1"},{"name":"oslo","version":"^1.1.2"},{"name":"@lucia-auth/adapter-prisma","version":"^4.0.0"},{"name":"@sendgrid/mail","version":"^7.7.0"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"pg-boss","version":"^8.4.2"},{"name":"zod","version":"^3.23.8"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.d.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.d.ts index 9023fd045e..a612dded65 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.d.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.d.ts @@ -1,19 +1,16 @@ -type BaseConfig = { - allowedCORSOrigins: string | string[]; -}; -type CommonConfig = BaseConfig & { - env: string; +import { env } from './env.js'; +type NodeEnv = typeof env.NODE_ENV; +type Config = { + env: NodeEnv; isDevelopment: boolean; port: number; - databaseUrl: string | undefined; - auth: { - jwtSecret: string | undefined; - }; -}; -type EnvConfig = BaseConfig & { + databaseUrl: string; frontendUrl: string; serverUrl: string; + allowedCORSOrigins: string | string[]; + auth: { + jwtSecret: string; + }; }; -type Config = CommonConfig & EnvConfig; -declare const resolvedConfig: Config; -export default resolvedConfig; +declare const config: Config; +export default config; diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.js b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.js index cc2ff362e0..b5096b3b07 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.js +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.js @@ -1,39 +1,24 @@ -import merge from 'lodash.merge'; import { env } from './env.js'; import { stripTrailingSlash } from '../universal/url.js'; +const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); +const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); +const allowedCORSOriginsPerEnv = { + development: '*', + production: [frontendUrl] +}; +const allowedCORSOrigins = allowedCORSOriginsPerEnv[env.NODE_ENV]; const config = { - all: { - env: env.NODE_ENV, - isDevelopment: env.NODE_ENV === 'development', - port: env.PORT, - databaseUrl: env.DATABASE_URL, - allowedCORSOrigins: [], - auth: { - jwtSecret: env.JWT_SECRET - } - }, - development: getDevelopmentConfig(), - production: getProductionConfig(), + frontendUrl, + serverUrl, + allowedCORSOrigins, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, + auth: { + jwtSecret: env.JWT_SECRET + } }; -const resolvedConfig = merge(config.all, config[env.NODE_ENV]); // PUBLIC API -export default resolvedConfig; -function getDevelopmentConfig() { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: '*', - }; -} -function getProductionConfig() { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: [frontendUrl], - }; -} +export default config; //# sourceMappingURL=config.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.js.map b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.js.map index 19f008a7ec..d83a878589 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.js.map +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/dist/server/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AA4BxD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,GAAG,CAAC,QAAQ;QACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;QAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,YAAY;QAC7B,kBAAkB,EAAE,EAAE;QACtB,IAAI,EAAE;YACJ,SAAS,EAAE,GAAG,CAAC,UAAU;SAC1B;KACF;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;AACtE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAiBxD,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;AAC/D,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;AAEzD,MAAM,wBAAwB,GAAuC;IACnE,WAAW,EAAE,GAAG;IAChB,UAAU,EAAE,CAAC,WAAW,CAAC;CAC1B,CAAA;AACD,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAEjE,MAAM,MAAM,GAAW;IACrB,WAAW;IACX,SAAS;IACT,kBAAkB;IAClB,GAAG,EAAE,GAAG,CAAC,QAAQ;IACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;IAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,WAAW,EAAE,GAAG,CAAC,YAAY;IAC7B,IAAI,EAAE;QACJ,SAAS,EAAE,GAAG,CAAC,UAAU;KAC1B;CACF,CAAA;AAED,aAAa;AACb,eAAe,MAAM,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/package.json b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/package.json index 35aea6813e..22e2c2d0e6 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/package.json +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/package.json @@ -13,7 +13,6 @@ "axios": "^1.4.0", "express": "~4.21.0", "jsdom": "^21.1.1", - "lodash.merge": "^4.6.2", "lucia": "^3.0.1", "mitt": "3.0.0", "msw": "^1.1.0", diff --git a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/config.ts b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/config.ts index 557c94cf32..8106e5b84c 100644 --- a/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/config.ts +++ b/waspc/e2e-test/test-outputs/waspComplexTest-golden/waspComplexTest/.wasp/out/sdk/wasp/server/config.ts @@ -1,73 +1,42 @@ -import merge from 'lodash.merge' - import { env } from './env.js' import { stripTrailingSlash } from '../universal/url.js' -// TODO: -// - Use dotenv library to consume env vars from a file. -// - Use convict library to define schema and validate env vars. -// https://codingsans.com/blog/node-config-best-practices +type NodeEnv = typeof env.NODE_ENV -type BaseConfig = { - allowedCORSOrigins: string | string[]; -} - -type CommonConfig = BaseConfig & { - env: string; +type Config = { + env: NodeEnv; isDevelopment: boolean; port: number; - databaseUrl: string | undefined; - auth: { - jwtSecret: string | undefined; - } -} - -type EnvConfig = BaseConfig & { + databaseUrl: string; frontendUrl: string; serverUrl: string; + allowedCORSOrigins: string | string[]; + auth: { + jwtSecret: string; + } } -type Config = CommonConfig & EnvConfig +const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL) +const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL) -const config: { - all: CommonConfig, - development: EnvConfig, - production: EnvConfig, -} = { - all: { - env: env.NODE_ENV, - isDevelopment: env.NODE_ENV === 'development', - port: env.PORT, - databaseUrl: env.DATABASE_URL, - allowedCORSOrigins: [], - auth: { - jwtSecret: env.JWT_SECRET - } - }, - development: getDevelopmentConfig(), - production: getProductionConfig(), +const allowedCORSOriginsPerEnv: Record = { + development: '*', + production: [frontendUrl] } - -const resolvedConfig: Config = merge(config.all, config[env.NODE_ENV]) -// PUBLIC API -export default resolvedConfig - -function getDevelopmentConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: '*', +const allowedCORSOrigins = allowedCORSOriginsPerEnv[env.NODE_ENV] + +const config: Config = { + frontendUrl, + serverUrl, + allowedCORSOrigins, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, + auth: { + jwtSecret: env.JWT_SECRET } } -function getProductionConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: [frontendUrl], - } -} +// PUBLIC API +export default config diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/.waspchecksums b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/.waspchecksums index e5c79c1f26..7bf5e3abbe 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/.waspchecksums @@ -221,7 +221,7 @@ "file", "../out/sdk/wasp/package.json" ], - "657fd7af5d76fbb099b945cae4f34fa4fab061d3606b1ad1d03e81ee0d59535f" + "f045068da4d6b321ff13c7fe91eb01a10f98e7bf477edee21ab1621e95166bf7" ], [ [ @@ -263,7 +263,7 @@ "file", "../out/sdk/wasp/server/config.ts" ], - "dd528b5db722210a5781f39c4d410024211f31964383bcc708a2611bd8d9d195" + "8431eaf0332cdbdd2f36b4c232b4b6b65fd19bad58fe51922f5b2662f22fc8ad" ], [ [ diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/installedNpmDepsLog.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/installedNpmDepsLog.json index 550b37b38c..abf9e1eac0 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/installedNpmDepsLog.json +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/installedNpmDepsLog.json @@ -1 +1 @@ -{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"pg-boss","version":"^8.4.2"},{"name":"zod","version":"^3.23.8"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file +{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"pg-boss","version":"^8.4.2"},{"name":"zod","version":"^3.23.8"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.d.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.d.ts index 68bb448c56..70f438bdf0 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.d.ts +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.d.ts @@ -1,16 +1,13 @@ -type BaseConfig = { - allowedCORSOrigins: string | string[]; -}; -type CommonConfig = BaseConfig & { - env: string; +import { env } from './env.js'; +type NodeEnv = typeof env.NODE_ENV; +type Config = { + env: NodeEnv; isDevelopment: boolean; port: number; - databaseUrl: string | undefined; -}; -type EnvConfig = BaseConfig & { + databaseUrl: string; frontendUrl: string; serverUrl: string; + allowedCORSOrigins: string | string[]; }; -type Config = CommonConfig & EnvConfig; -declare const resolvedConfig: Config; -export default resolvedConfig; +declare const config: Config; +export default config; diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.js index f38fa5795a..dcc80722ab 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.js +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.js @@ -1,36 +1,21 @@ -import merge from 'lodash.merge'; import { env } from './env.js'; import { stripTrailingSlash } from '../universal/url.js'; +const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); +const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); +const allowedCORSOriginsPerEnv = { + development: '*', + production: [frontendUrl] +}; +const allowedCORSOrigins = allowedCORSOriginsPerEnv[env.NODE_ENV]; const config = { - all: { - env: env.NODE_ENV, - isDevelopment: env.NODE_ENV === 'development', - port: env.PORT, - databaseUrl: env.DATABASE_URL, - allowedCORSOrigins: [], - }, - development: getDevelopmentConfig(), - production: getProductionConfig(), + frontendUrl, + serverUrl, + allowedCORSOrigins, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, }; -const resolvedConfig = merge(config.all, config[env.NODE_ENV]); // PUBLIC API -export default resolvedConfig; -function getDevelopmentConfig() { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: '*', - }; -} -function getProductionConfig() { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: [frontendUrl], - }; -} +export default config; //# sourceMappingURL=config.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.js.map b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.js.map index fe5abce123..9fd077fa81 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.js.map +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/dist/server/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAyBxD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,GAAG,CAAC,QAAQ;QACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;QAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,YAAY;QAC7B,kBAAkB,EAAE,EAAE;KACvB;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;AACtE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAcxD,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;AAC/D,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;AAEzD,MAAM,wBAAwB,GAAuC;IACnE,WAAW,EAAE,GAAG;IAChB,UAAU,EAAE,CAAC,WAAW,CAAC;CAC1B,CAAA;AACD,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAEjE,MAAM,MAAM,GAAW;IACrB,WAAW;IACX,SAAS;IACT,kBAAkB;IAClB,GAAG,EAAE,GAAG,CAAC,QAAQ;IACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;IAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,WAAW,EAAE,GAAG,CAAC,YAAY;CAC9B,CAAA;AAED,aAAa;AACb,eAAe,MAAM,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/package.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/package.json index d8a57527fe..096de35ddb 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/package.json +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/package.json @@ -8,7 +8,6 @@ "axios": "^1.4.0", "express": "~4.21.0", "jsdom": "^21.1.1", - "lodash.merge": "^4.6.2", "mitt": "3.0.0", "msw": "^1.1.0", "pg-boss": "^8.4.2", diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/config.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/config.ts index 27a7537a0f..3a000a897f 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/config.ts +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/sdk/wasp/server/config.ts @@ -1,67 +1,36 @@ -import merge from 'lodash.merge' - import { env } from './env.js' import { stripTrailingSlash } from '../universal/url.js' -// TODO: -// - Use dotenv library to consume env vars from a file. -// - Use convict library to define schema and validate env vars. -// https://codingsans.com/blog/node-config-best-practices - -type BaseConfig = { - allowedCORSOrigins: string | string[]; -} +type NodeEnv = typeof env.NODE_ENV -type CommonConfig = BaseConfig & { - env: string; +type Config = { + env: NodeEnv; isDevelopment: boolean; port: number; - databaseUrl: string | undefined; -} - -type EnvConfig = BaseConfig & { + databaseUrl: string; frontendUrl: string; serverUrl: string; + allowedCORSOrigins: string | string[]; } -type Config = CommonConfig & EnvConfig +const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL) +const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL) -const config: { - all: CommonConfig, - development: EnvConfig, - production: EnvConfig, -} = { - all: { - env: env.NODE_ENV, - isDevelopment: env.NODE_ENV === 'development', - port: env.PORT, - databaseUrl: env.DATABASE_URL, - allowedCORSOrigins: [], - }, - development: getDevelopmentConfig(), - production: getProductionConfig(), +const allowedCORSOriginsPerEnv: Record = { + development: '*', + production: [frontendUrl] } - -const resolvedConfig: Config = merge(config.all, config[env.NODE_ENV]) -// PUBLIC API -export default resolvedConfig - -function getDevelopmentConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: '*', - } +const allowedCORSOrigins = allowedCORSOriginsPerEnv[env.NODE_ENV] + +const config: Config = { + frontendUrl, + serverUrl, + allowedCORSOrigins, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, } -function getProductionConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: [frontendUrl], - } -} +// PUBLIC API +export default config diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/.waspchecksums b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/.waspchecksums index e74030f231..20f263b827 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/.waspchecksums @@ -214,7 +214,7 @@ "file", "../out/sdk/wasp/package.json" ], - "d18af37d0188a6c4c9eef72705e31caf179664cb8621eaacf8bc4c21bc57c212" + "9f8844eca690b66c914179693b7f7beedef8b7c8fe2016d9d7353d474cea3d56" ], [ [ @@ -256,7 +256,7 @@ "file", "../out/sdk/wasp/server/config.ts" ], - "dd528b5db722210a5781f39c4d410024211f31964383bcc708a2611bd8d9d195" + "8431eaf0332cdbdd2f36b4c232b4b6b65fd19bad58fe51922f5b2662f22fc8ad" ], [ [ diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/installedNpmDepsLog.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/installedNpmDepsLog.json index 90c0d4bc56..e811a78822 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/installedNpmDepsLog.json +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/installedNpmDepsLog.json @@ -1 +1 @@ -{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"zod","version":"^3.23.8"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file +{"_waspSdkNpmDeps":{"dependencies":[{"name":"@prisma/client","version":"5.19.1"},{"name":"prisma","version":"5.19.1"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"express","version":"~4.21.0"},{"name":"mitt","version":"3.0.0"},{"name":"react","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"},{"name":"react-hook-form","version":"^7.45.4"},{"name":"superjson","version":"^2.2.1"},{"name":"vitest","version":"^1.2.1"},{"name":"@vitest/ui","version":"^1.2.1"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.1.2"},{"name":"@testing-library/jest-dom","version":"^6.3.0"},{"name":"msw","version":"^1.1.0"},{"name":"zod","version":"^3.23.8"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/express-serve-static-core","version":"^4.17.13"}]},"_userNpmDeps":{"userDependencies":[{"name":"react","version":"^18.2.0"},{"name":"wasp","version":"file:.wasp/out/sdk/wasp"}],"userDevDependencies":[{"name":"@types/react","version":"^18.0.37"},{"name":"prisma","version":"5.19.1"},{"name":"typescript","version":"^5.1.0"},{"name":"vite","version":"^4.3.9"}]},"_waspFrameworkNpmDeps":{"npmDepsForWebApp":{"dependencies":[{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"axios","version":"^1.4.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"react-router-dom","version":"^6.26.2"}],"devDependencies":[{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@vitejs/plugin-react","version":"^4.2.1"},{"name":"dotenv","version":"^16.0.3"}]},"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"dotenv","version":"^16.0.2"},{"name":"express","version":"~4.21.0"},{"name":"helmet","version":"^6.0.0"},{"name":"morgan","version":"~1.10.0"},{"name":"superjson","version":"^2.2.1"}],"devDependencies":[{"name":"@tsconfig/node18","version":"latest"},{"name":"@types/cors","version":"^2.8.5"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.0.0"},{"name":"nodemon","version":"^2.0.19"},{"name":"rollup","version":"^4.9.6"},{"name":"rollup-plugin-esbuild","version":"^6.1.1"}]}}} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.d.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.d.ts index 68bb448c56..70f438bdf0 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.d.ts +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.d.ts @@ -1,16 +1,13 @@ -type BaseConfig = { - allowedCORSOrigins: string | string[]; -}; -type CommonConfig = BaseConfig & { - env: string; +import { env } from './env.js'; +type NodeEnv = typeof env.NODE_ENV; +type Config = { + env: NodeEnv; isDevelopment: boolean; port: number; - databaseUrl: string | undefined; -}; -type EnvConfig = BaseConfig & { + databaseUrl: string; frontendUrl: string; serverUrl: string; + allowedCORSOrigins: string | string[]; }; -type Config = CommonConfig & EnvConfig; -declare const resolvedConfig: Config; -export default resolvedConfig; +declare const config: Config; +export default config; diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js index f38fa5795a..dcc80722ab 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js @@ -1,36 +1,21 @@ -import merge from 'lodash.merge'; import { env } from './env.js'; import { stripTrailingSlash } from '../universal/url.js'; +const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); +const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); +const allowedCORSOriginsPerEnv = { + development: '*', + production: [frontendUrl] +}; +const allowedCORSOrigins = allowedCORSOriginsPerEnv[env.NODE_ENV]; const config = { - all: { - env: env.NODE_ENV, - isDevelopment: env.NODE_ENV === 'development', - port: env.PORT, - databaseUrl: env.DATABASE_URL, - allowedCORSOrigins: [], - }, - development: getDevelopmentConfig(), - production: getProductionConfig(), + frontendUrl, + serverUrl, + allowedCORSOrigins, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, }; -const resolvedConfig = merge(config.all, config[env.NODE_ENV]); // PUBLIC API -export default resolvedConfig; -function getDevelopmentConfig() { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: '*', - }; -} -function getProductionConfig() { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: [frontendUrl], - }; -} +export default config; //# sourceMappingURL=config.js.map \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js.map b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js.map index fe5abce123..9fd077fa81 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js.map +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/dist/server/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAyBxD,MAAM,MAAM,GAIR;IACF,GAAG,EAAE;QACH,GAAG,EAAE,GAAG,CAAC,QAAQ;QACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;QAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,YAAY;QAC7B,kBAAkB,EAAE,EAAE;KACvB;IACD,WAAW,EAAE,oBAAoB,EAAE;IACnC,UAAU,EAAE,mBAAmB,EAAE;CAClC,CAAA;AAED,MAAM,cAAc,GAAW,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;AACtE,aAAa;AACb,eAAe,cAAc,CAAA;AAE7B,SAAS,oBAAoB;IAC3B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,GAAG;KACxB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC1D,OAAO;QACL,WAAW;QACX,SAAS;QACT,kBAAkB,EAAE,CAAC,WAAW,CAAC;KAClC,CAAA;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAcxD,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;AAC/D,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;AAEzD,MAAM,wBAAwB,GAAuC;IACnE,WAAW,EAAE,GAAG;IAChB,UAAU,EAAE,CAAC,WAAW,CAAC;CAC1B,CAAA;AACD,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAEjE,MAAM,MAAM,GAAW;IACrB,WAAW;IACX,SAAS;IACT,kBAAkB;IAClB,GAAG,EAAE,GAAG,CAAC,QAAQ;IACjB,aAAa,EAAE,GAAG,CAAC,QAAQ,KAAK,aAAa;IAC7C,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,WAAW,EAAE,GAAG,CAAC,YAAY;CAC9B,CAAA;AAED,aAAa;AACb,eAAe,MAAM,CAAA"} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/package.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/package.json index cae34c05e7..10a54b5d6e 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/package.json +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/package.json @@ -8,7 +8,6 @@ "axios": "^1.4.0", "express": "~4.21.0", "jsdom": "^21.1.1", - "lodash.merge": "^4.6.2", "mitt": "3.0.0", "msw": "^1.1.0", "prisma": "5.19.1", diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/config.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/config.ts index 27a7537a0f..3a000a897f 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/config.ts +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/sdk/wasp/server/config.ts @@ -1,67 +1,36 @@ -import merge from 'lodash.merge' - import { env } from './env.js' import { stripTrailingSlash } from '../universal/url.js' -// TODO: -// - Use dotenv library to consume env vars from a file. -// - Use convict library to define schema and validate env vars. -// https://codingsans.com/blog/node-config-best-practices - -type BaseConfig = { - allowedCORSOrigins: string | string[]; -} +type NodeEnv = typeof env.NODE_ENV -type CommonConfig = BaseConfig & { - env: string; +type Config = { + env: NodeEnv; isDevelopment: boolean; port: number; - databaseUrl: string | undefined; -} - -type EnvConfig = BaseConfig & { + databaseUrl: string; frontendUrl: string; serverUrl: string; + allowedCORSOrigins: string | string[]; } -type Config = CommonConfig & EnvConfig +const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL) +const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL) -const config: { - all: CommonConfig, - development: EnvConfig, - production: EnvConfig, -} = { - all: { - env: env.NODE_ENV, - isDevelopment: env.NODE_ENV === 'development', - port: env.PORT, - databaseUrl: env.DATABASE_URL, - allowedCORSOrigins: [], - }, - development: getDevelopmentConfig(), - production: getProductionConfig(), +const allowedCORSOriginsPerEnv: Record = { + development: '*', + production: [frontendUrl] } - -const resolvedConfig: Config = merge(config.all, config[env.NODE_ENV]) -// PUBLIC API -export default resolvedConfig - -function getDevelopmentConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: '*', - } +const allowedCORSOrigins = allowedCORSOriginsPerEnv[env.NODE_ENV] + +const config: Config = { + frontendUrl, + serverUrl, + allowedCORSOrigins, + env: env.NODE_ENV, + isDevelopment: env.NODE_ENV === 'development', + port: env.PORT, + databaseUrl: env.DATABASE_URL, } -function getProductionConfig(): EnvConfig { - const frontendUrl = stripTrailingSlash(env.WASP_WEB_CLIENT_URL); - const serverUrl = stripTrailingSlash(env.WASP_SERVER_URL); - return { - frontendUrl, - serverUrl, - allowedCORSOrigins: [frontendUrl], - } -} +// PUBLIC API +export default config diff --git a/waspc/examples/todoApp/package-lock.json b/waspc/examples/todoApp/package-lock.json index 1df4199aec..ff2d4aa62e 100644 --- a/waspc/examples/todoApp/package-lock.json +++ b/waspc/examples/todoApp/package-lock.json @@ -38,7 +38,6 @@ "axios": "^1.4.0", "express": "~4.21.0", "jsdom": "^21.1.1", - "lodash.merge": "^4.6.2", "lucia": "^3.0.1", "mitt": "3.0.0", "msw": "^1.1.0", diff --git a/waspc/src/Wasp/Generator/SdkGenerator.hs b/waspc/src/Wasp/Generator/SdkGenerator.hs index 146cfa3c29..8ab5886e82 100644 --- a/waspc/src/Wasp/Generator/SdkGenerator.hs +++ b/waspc/src/Wasp/Generator/SdkGenerator.hs @@ -196,7 +196,6 @@ npmDepsForSdk spec = ("express", Server.expressVersionStr), ("mitt", "3.0.0"), ("react", show reactVersion), - ("lodash.merge", "^4.6.2"), ("react-router-dom", show reactRouterVersion), ("react-hook-form", "^7.45.4"), ("superjson", show superjsonVersion) From 1da4542578111f1e243c1d385987beaa6e6f5ae8 Mon Sep 17 00:00:00 2001 From: Mihovil Ilakovac Date: Wed, 30 Oct 2024 15:16:43 +0100 Subject: [PATCH 9/9] Fixes keycloak env usage --- .../templates/server/src/auth/providers/config/keycloak.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/waspc/data/Generator/templates/server/src/auth/providers/config/keycloak.ts b/waspc/data/Generator/templates/server/src/auth/providers/config/keycloak.ts index f80d56ad46..8bcacd390c 100644 --- a/waspc/data/Generator/templates/server/src/auth/providers/config/keycloak.ts +++ b/waspc/data/Generator/templates/server/src/auth/providers/config/keycloak.ts @@ -2,6 +2,7 @@ import type { ProviderConfig } from "wasp/auth/providers/types"; import { keycloak } from "wasp/server/auth"; +import { env } from "wasp/server"; import { mergeDefaultAndUserConfig } from "../oauth/config.js"; import { createOAuthProviderRouter } from "../oauth/handler.js"; @@ -32,7 +33,7 @@ const _waspConfig: ProviderConfig = { providerProfile: unknown; providerUserId: string; }> { - const userInfoEndpoint = `${keycloak.env.KEYCLOAK_REALM_URL}/protocol/openid-connect/userinfo`; + const userInfoEndpoint = `${env.KEYCLOAK_REALM_URL}/protocol/openid-connect/userinfo`; const response = await fetch( userInfoEndpoint, {