-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable users to define their env var validations #2363
Conversation
69e2944
to
f0ffeec
Compare
3d27ce2
to
c606b6b
Compare
Signed-off-by: Mihovil Ilakovac <[email protected]>
Signed-off-by: Mihovil Ilakovac <[email protected]>
Signed-off-by: Mihovil Ilakovac <[email protected]>
@infomiho could you please describe how this works, what is the experience for the user? I see there are no docs yet, and it would help me with reviewing so I don't have to guess it from the code + so I can consider if code does indeed do what the idea was. |
@Martinsos I've updated the PR description to give you a proper intro into the task I was tackling |
@infomiho from the high level / DX perspective, sounds good to me, thanks for the detailed description! If they define the same var as Wasp already defines, what happens? Conflict or override or nothing? What do we want to happen, is there any benefit in them being able to override Wasp's var definitions? Maybe conflict is the best? |
@Martinsos right now, since we merge their schema into ours, they can override our rules: example how that works If their validation rules are less strict or wrong, they will get a type error (change We can merge our schema into theirs, therefore our rules would always win - that seems okay to me, even good enough. I think, we could go through their schema keys and our schema keys and if they are conflicts, output a custom error. But this is something I would need to check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
Two main requests: the public API change and updating the TS SDK.
What was the naming problem you mentioned?
@@ -72,6 +71,11 @@ data-files: | |||
packages/studio/dist/**/*.css | |||
packages/studio/package.json | |||
packages/studio/package-lock.json | |||
packages/wasp-config/dist/**/*.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sodic I've added this change here so I could cabal install
and test things locally. I can make a separate PR if you want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can stay here 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noice
@@ -72,6 +71,11 @@ data-files: | |||
packages/studio/dist/**/*.css | |||
packages/studio/package.json | |||
packages/studio/package-lock.json | |||
packages/wasp-config/dist/**/*.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can stay here 👍
[ "defaultServerUrl" .= Server.defaultDevServerUrl, | ||
"envValidationSchema" .= GJI.jsImportToImportJson (extImportToJsImport <$> maybeEnvValidationSchema) | ||
] | ||
maybeEnvValidationSchema = AS.App.client app >>= AS.App.Client.envValidationSchema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd maybe call this maybeJsImport
and put more logic from line 66 here.
Same applies to the server function
The idea
Wasp uses Zod to define its validation rules for the env variables it expects e.g. it defines that
JWT_SECRET
is required and a string. After this validation passes, Zod gives us a validated object that we can safely use knowing that e.g.JWT_SECRET
is present and it is a string:Users need their own user-land env vars e.g.
STRIPE_API_KEY
. Some users validate their env vars with manual checks to make sure that the env var is set before running the app e.g.Since Wasp already uses Zod to validate env vars, we want to expose the same mechanism to our users. There are two main benefits:
env
object for both Wasp defined env vars and their own user-land env varsHow this works
Users need to define their env vars validation by defining a Zod object schema. They then declare that in the Wasp file. Something like this:
and then:
Wasp merges this user defined schema with its built-in env vars validation schema when it validates the
process.env
object on the server and theimport.meta.env
object on the client.Now users can use the
env
object to access their env vars like this:Caveats
env.ts