Merge branch 'main' into miho-auth-model-docs
@ -86,6 +86,10 @@ to install Wasp on OSX/Linux/WSL(Win). From there, just follow the instructions
|
||||
|
||||
For more details, check out [the docs](https://wasp-lang.dev/docs).
|
||||
|
||||
# Wasp AI / Mage
|
||||
|
||||
Wasp comes with experimental AI code generator to help you kickstart your next Wasp project -> you can use it via `wasp new` in the CLI (choose "AI" option) if you can provide your OpenAI keys or you can do it via our [Mage web app](https://usemage.ai) in which case our OpenAI keys are used in the background.
|
||||
|
||||
# This repository
|
||||
|
||||
This is the main repo of the Wasp universe, containing core code (mostly `waspc` - Wasp compiler) and the supporting materials.
|
||||
|
3
wasp-ai/.gitignore → mage/.gitignore
vendored
@ -9,3 +9,6 @@
|
||||
# or modify/delete these two lines.
|
||||
*.env
|
||||
*.env.*
|
||||
|
||||
# Emacs specific
|
||||
.projectile
|
@ -33,7 +33,7 @@ RUN cd server && PRISMA_CLIENT_OUTPUT_DIR=../server/node_modules/.prisma/client/
|
||||
RUN cd server && npm run build
|
||||
|
||||
FROM base AS server-production
|
||||
RUN curl -sSL https://get.wasp-lang.dev/installer.sh | sh -s -- -v 0.11.4-wasp-ai-12
|
||||
RUN curl -sSL https://get.wasp-lang.dev/installer.sh | sh -s -- -v 0.12.0
|
||||
ENV PATH "$PATH:/root/.local/bin"
|
||||
ENV NODE_ENV production
|
||||
WORKDIR /app
|
44
mage/README.md
Normal file
@ -0,0 +1,44 @@
|
||||
# Mage
|
||||
|
||||
This directory contains the source code of Mage (aka "GPT Web App Generator" aka "Wasp AI"): a Wasp app (so a full-stack web app) that allows you to create a new Wasp app (inception :)!) from just a short description. It uses ChatGPT in a smart way to accomplish this (so it would be clasified as an AI code agent).
|
||||
|
||||
Mage is hosted at https://usemage.ai and you can use it there for free.
|
||||
|
||||
You can learn more about it [here](https://wasp-lang.dev/blog/2023/07/10/gpt-web-app-generator) and [here](https://wasp-lang.dev/blog/2023/07/17/how-we-built-gpt-web-app-generator).
|
||||
|
||||
## Running locally
|
||||
|
||||
Mage is really just a client / UI for calling "Wasp AI", which is AI logic that does all the heavy lifting, and is integrated into Wasp's CLI: `wasp`.
|
||||
So, if you want to generate Wasp apps via AI locally, on your machine, with your OpenAI keys and your choice of models/parameters, we recommend NOT running the Mage app locally, because it is not so easy, instead we recommend you to do it directly via `wasp` CLI, with `wasp new` or `wasp new:ai` commands. Check our docs on how to install `wasp` CLI: https://wasp-lang.dev/docs/quick-start#installation .
|
||||
|
||||
If you still want to run Mage web app locally for some specific reason, most likely because you want to contribute, you will need to do the following:
|
||||
|
||||
1. Copy `.env.server.example` into `.env.server` and fill in the missing values. You will basically need to provide Github and Google OAuth creds (and first create OAuth apps on both Github and Google if you don't have them yet - if you are a member of Wasp team ask for dev creds, if not you will have to create your own OAuth apps).
|
||||
2. Run `wasp db start` and then `wasp start`! It might ask you to do `wasp db migrate-dev`, do that if needed.
|
||||
3. When running Mage locally, it will be looking for `wasp-cli` binary on your machine to use. To satisfy this requirement, you can go to `waspc/` dir (just next to this one) and run `./run install` there. You will want to check though if that Wasp version matches the version Mage expects (check its Dockerfile to see which version of Wasp it expects).
|
||||
If building `waspc/` is too complex for you (you don't have Haskell toolchain set up, taking too long, ...), you can go into the code of Mage, find where it calls `wasp-cli` and modify that temporarily to call `wasp` instead.
|
||||
|
||||
## Developing
|
||||
|
||||
### Updating Wasp version in Dockerfile
|
||||
|
||||
Keep in mind that Mage, when deployed, will install the version of Wasp specified in its Dockerfile.
|
||||
So, make sure to update that version to be in sync with the version of Wasp that it was developed against.
|
||||
Most often that should be the current version of Wasp on `main`, even if not released yet.
|
||||
|
||||
## Deployment
|
||||
|
||||
Mage is currently deployed on Wasp's Fly.io cloud.
|
||||
|
||||
Same as the rest of Wasp (blog/docs, CLI, ...), the latest deployed version is tracked on `release` branch.
|
||||
|
||||
So if you want to deploy new version of Mage, you should get it in wanted state on `release` branch, and then deploy from there.
|
||||
|
||||
Also, before deploying, check that version of `wasp` in `Dockerfile` makes sense.
|
||||
|
||||
To deploy it, just run `wasp deploy fly deploy`. You might want to add `--org wasp` if needed.
|
||||
|
||||
## FAQ
|
||||
|
||||
Q: What is the difference between Wasp AI and Mage? Are those the same thing?
|
||||
A: When we say "Wasp AI" we refer to logic implemented in `wasp` CLI, while when we say "Mage" we refer to the Mage web app that really serves as a client for "Wasp AI" (calls it in the background). That said, we sometimes use these interchangeably.
|
@ -50,7 +50,7 @@ export function RootComponent({ children }) {
|
||||
cursor-pointer flex-row
|
||||
space-x-3
|
||||
text-white bg-gradient-to-r from-pink-400 to-amber-400"
|
||||
onClick={() => window.open("https://github.com/wasp-lang/wasp/tree/wasp-ai")}
|
||||
onClick={() => window.open("https://github.com/wasp-lang/wasp")}
|
||||
>
|
||||
<div
|
||||
className={`
|
||||
@ -103,7 +103,7 @@ export function RootComponent({ children }) {
|
||||
<p className="text-center text-slate-500 text-sm mt-2">
|
||||
This whole app is open-source, you can find the code{" "}
|
||||
<a
|
||||
href="https://github.com/wasp-lang/wasp/tree/wasp-ai/wasp-ai"
|
||||
href="https://github.com/wasp-lang/wasp/tree/main/mage"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-sky-500 hover:text-sky-600"
|
@ -4,8 +4,8 @@ import { FiChevronDown, FiChevronRight } from 'react-icons/fi'
|
||||
function l(title, overrideTitle) {
|
||||
const links = {
|
||||
"Wasp": "https://wasp-lang.dev/",
|
||||
"web app": "https://github.com/wasp-lang/wasp/tree/wasp-ai/wasp-ai",
|
||||
"GPT code agent": "https://github.com/wasp-lang/wasp/tree/wasp-ai/waspc/src/Wasp/AI",
|
||||
"web app": "https://github.com/wasp-lang/wasp/tree/main/mage",
|
||||
"GPT code agent": "https://github.com/wasp-lang/wasp/tree/main/waspc/src/Wasp/AI",
|
||||
"blog post": "https://wasp-lang.dev/blog/2023/07/10/gpt-web-app-generator"
|
||||
};
|
||||
|
||||
@ -46,7 +46,7 @@ const faqs = [
|
||||
|
||||
<br/><br/>
|
||||
|
||||
With GPT4 increasing its availability and with LLMs improving in general, the quality of generated code will only get better!
|
||||
With LLMs improving in general, the quality of generated code will only get better!
|
||||
</p>
|
||||
},
|
||||
{
|
||||
@ -80,26 +80,28 @@ const faqs = [
|
||||
|
||||
<br/><br/>
|
||||
|
||||
However, in the future, when GPT4 becomes cheaper / more available, it would make sense to switch to it completely, since it does generate better code!
|
||||
However, in the future, when GPT4 becomes cheaper / faster, it would make sense to switch to it completely, since it does generate better code!
|
||||
</p>
|
||||
},
|
||||
{
|
||||
question: '[Advanced] Can I use GPT4 for the whole app?',
|
||||
question: '[Advanced] Can I use GPT4 for the whole app? / Can I run Mage locally?',
|
||||
answer: <p>
|
||||
As mentioned above, we use GPT4 + GPT3.5 for practical reasons, even though using GPT4 exclusively does give better results.<br/>
|
||||
<br/>
|
||||
However, if you have access yourself to the OpenAI API, you can use GPT4 for the whole app, or play with adjusting the temperature, by running the Wasp GPT code agent locally!<br/>
|
||||
However, if you have access yourself to the OpenAI API, you can use GPT4 for the whole app, or play with adjusting the temperature, by running the Wasp GPT code agent locally! So same thing like Mage, but via CLI.<br/>
|
||||
Note: generating an app usually consumes from 20k to 50k tokens, which is then approximately $1 to $2 per app with the current GPT4 pricing (Jul 11th 2023).<br/>
|
||||
<br/>
|
||||
You will need to install special version of Wasp:<br/>
|
||||
To run Wasp AI (Mage) locally, make sure you have wasp {'>='}v0.12 installed and just run:<br/>
|
||||
<span className="bg-slate-800 text-slate-200 p-1 rounded">
|
||||
curl -sSL https://get.wasp-lang.dev/installer.sh | sh -s -- -v 0.11.1-wasp-ai-11
|
||||
wasp new
|
||||
</span><br/>
|
||||
When asked, choose AI generation, answer some questions, and your app will start generating!<br/>
|
||||
<br/>
|
||||
Now you can run app generation locally via:<br/>
|
||||
There is also a command for running the same thing programmatically, without interactive questions:<br/>
|
||||
<span className="bg-slate-800 text-slate-200 p-1 rounded">
|
||||
wasp new-ai:disk MyAwesomeApp "Description of my awesome app." {'"{ \\"defaultGptModel\\": \\"gpt-4\\" }"'}
|
||||
</span>
|
||||
wasp new:ai
|
||||
</span><br/>
|
||||
Run it with no arguments (as above) to see its usage instructions.
|
||||
</p>
|
||||
},
|
||||
]
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 116 KiB |
@ -278,7 +278,7 @@ export const ResultPage = () => {
|
||||
>
|
||||
<span
|
||||
className="item-center flex gap-2 p-1 px-2 cursor-pointer text-pink-800 bg-pink-200 rounded"
|
||||
onClick={() => window.open("https://github.com/wasp-lang/wasp/tree/wasp-ai")}
|
||||
onClick={() => window.open("https://github.com/wasp-lang/wasp")}
|
||||
>
|
||||
<span>
|
||||
🔮 This is a Wasp powered project. If you like it,{" "}
|
Before Width: | Height: | Size: 659 KiB After Width: | Height: | Size: 659 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 725 KiB After Width: | Height: | Size: 725 KiB |
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
@ -62,7 +62,8 @@ export const generateApp: GenerateAppJob<
|
||||
const stdoutMutex = new Mutex();
|
||||
let waspCliProcess = null;
|
||||
const waspCliProcessArgs = [
|
||||
"new-ai",
|
||||
"new:ai",
|
||||
"--stdout",
|
||||
project.name,
|
||||
project.description,
|
||||
JSON.stringify(projectConfig),
|
1
waspc/.nvmrc
Normal file
@ -0,0 +1 @@
|
||||
v18
|
@ -1,11 +1,18 @@
|
||||
# Changelog
|
||||
|
||||
## 0.12.0
|
||||
## [WIP] 0.12.0
|
||||
|
||||
### ⚠️ Breaking changes
|
||||
|
||||
- Auth field customization is no longer possible using the `_waspCustomValidations` on the `User` entity. This is a part of auth refactoring that we are doing to make it easier to customize auth. We will be adding more customization options in the future.
|
||||
|
||||
### 🎉 [New Feature] Wasp now works with any Node version >= 18
|
||||
So far, Wasp required specific Node version that is compatible with latest LTS Node (lately that was 18).
|
||||
|
||||
We relaxed that constraint so it now works with any Node version equal to or newer than the oldest LTS version that Wasp supports, meaning that now Wasp works with any Node version >= 18.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
## 0.11.8
|
||||
|
||||
### 🎉 [New Feature] Serving the Client From a Subdirectory
|
||||
@ -29,11 +36,14 @@ app todoApp {
|
||||
- Fixes a regression where a missing DB on the DB server would prevent project from running. Now, Wasp will tolerate the missing DB error and rely on Prisma to create the DB for you (like before).
|
||||
- Fixes an issue on Linux where running Prisma migration command fails when a project has a path that has spaces in it.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
## 0.11.7
|
||||
|
||||
### 🐞 Bug fixes / 🔧 small improvements
|
||||
- Fixed a bug with Prisma which prevent connections via SSL with our versions of Alpine and OpenSSL. We upgraded to the latest Prisma 4.X.X which fixes this issue.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
## 0.11.6
|
||||
|
||||
|
@ -326,23 +326,24 @@ NOTE: When you run it for the first time it might take a while (~10 minutes) for
|
||||
We use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0-beta.2/) convention when creating commits.
|
||||
|
||||
## Branching and merging strategy
|
||||
This repo contains both the source code that makes up a Wasp release (under `waspc`), as well as our website containing documentation and blog posts (under `web`). In order to facilitate the development of Wasp code while still allowing for website updates or hotfixes of the current release, we have decided on the following minimal branching strategy.
|
||||
This repo contains both the source code that makes up a Wasp release (under `waspc`), as well as our website containing documentation and blog posts (under `web`), and also Mage web app (under `mage`). In order to facilitate the development of Wasp code while still allowing for website / Mage updates or hotfixes of the current release, we have decided on the following minimal branching strategy.
|
||||
|
||||
All Wasp development should be done on feature branches. They form the basis of PRs that will target one of the two following branches:
|
||||
|
||||
- `main`: this branch contains all the actively developed new features and corresponding documentation updates. Some of these things may not yet be released, but anything merged into `main` should be in a release-ready state.
|
||||
- This is the default branch to target for any Wasp feature branches.
|
||||
- `release`: this branch contains the source code of current/latest Wasp release, as well as the documentation and blog posts currently published and therefore visible on the website.
|
||||
- `release`: this branch contains the source code of current/latest Wasp release, as well as the documentation and blog posts currently published and therefore visible on the website, and also currently published version of Mage.
|
||||
- When doing a full release, which means making a new release based on what we have currently on `main`, we do the following:
|
||||
1. Update `main` branch by merging `release` into it. There might be conflicts but they shouldn't be too hard to fix. Once `main` is updated, you can create a new waspc release from it, as well as deploy the website from it.
|
||||
2. Update `release` branch to this new `main` by merging `main` into it. There will be no conflicts since we already resolved all of them in the previous step.
|
||||
|
||||
How do I know where I want to target my PR, to `release` or `main`?
|
||||
- If you have a change that you want to publish right now or very soon, certainly earlier than waiting till `main` is ready for publishing, then you want to target `release`. This could be website content update, new blog post, documentation (hot)fix, compiler hotfix that we need to release quickly via a new patch version, ... .
|
||||
- If you have a change that you want to publish right now or very soon, certainly earlier than waiting till `main` is ready for publishing, then you want to target `release`. This could be website content update, new blog post, documentation (hot)fix, compiler hotfix that we need to release quickly via a new patch version, update for Mage that needs to go out now, ... .
|
||||
- If you have a change that is not urgent and can wait until the next "normal" Wasp release is published, then target `main`. These are new features, refactorings, docs accompanying new features, ... .
|
||||
- Stuff published on `release` (docs, Mage) uses/references version of `wasp` that was last released (so one that is also on `release`).
|
||||
- TLDR;
|
||||
- `release` is for changes to the already published stuff (the present).
|
||||
- `main` is for changes to the to-be-published stuff (the future).
|
||||
- `release` represents the present, and is for changes to the already published stuff.
|
||||
- `main` represents near future, and is for changes to the to-be-published stuff.
|
||||
|
||||
## Deployment / CI
|
||||
We use Github Actions for CI.
|
||||
@ -375,6 +376,7 @@ If it happens just once every so it is probably nothing to worry about. If it ha
|
||||
- Publish the draft release when ready.
|
||||
- Merge `release` back into `main` (`git merge release` while on the `main` branch), if needed.
|
||||
- Publish new [docs](/web#deployment) from the `release` branch as well.
|
||||
- Publish new [Mage](/mage#deployment) from the `release` branch as well, if needed.
|
||||
- Announce new release in Discord.
|
||||
|
||||
#### Determining next version
|
||||
@ -393,7 +395,10 @@ If doing this, steps are the following:
|
||||
|
||||
|
||||
## Documentation
|
||||
External documentation, for users of Wasp, is hosted at https://wasp-lang.dev/docs, and its source is available at [web/docs](/web/docs), next to the website and blog.
|
||||
External documentation, for users of Wasp, is hosted at https://wasp-lang.dev/docs, and its source is available at [web/docs](/web/docs), next to the website and blog.
|
||||
|
||||
## Mage
|
||||
Wasp's magic GPT web app generator aka Wasp AI aka Mage is hosted at https://usemage.ai and its source is available at [mage](/mage).
|
||||
|
||||
Make sure to update it when changes modify how Wasp works.
|
||||
|
||||
|
@ -46,13 +46,7 @@ main = withUtf8 . (`E.catch` handleInternalErrors) $ do
|
||||
args <- getArgs
|
||||
let commandCall = case args of
|
||||
("new" : newArgs) -> Command.Call.New newArgs
|
||||
-- new-ai / new-ai:stdout is meant to be called and consumed programatically (e.g. by our Wasp AI
|
||||
-- web app), while new-ai:disk is useful for us for testing.
|
||||
[newAiCmd, projectName, appDescription, projectConfigJson]
|
||||
| newAiCmd `elem` ["new-ai", "new-ai:stdout"] ->
|
||||
Command.Call.NewAiToStdout projectName appDescription projectConfigJson
|
||||
| newAiCmd == "new-ai:disk" ->
|
||||
Command.Call.NewAiToDisk projectName appDescription projectConfigJson
|
||||
("new:ai" : newAiArgs) -> Command.Call.NewAi newAiArgs
|
||||
["start"] -> Command.Call.Start
|
||||
["start", "db"] -> Command.Call.StartDb
|
||||
["clean"] -> Command.Call.Clean
|
||||
@ -80,18 +74,28 @@ main = withUtf8 . (`E.catch` handleInternalErrors) $ do
|
||||
-- not needed for every command, but checking for every command was decided
|
||||
-- to be more robust than trying to only check for commands that require it.
|
||||
-- See https://github.com/wasp-lang/wasp/issues/1134#issuecomment-1554065668
|
||||
NodeVersion.getAndCheckNodeVersion >>= \case
|
||||
Left errorMsg -> do
|
||||
NodeVersion.getAndCheckUserNodeVersion >>= \case
|
||||
NodeVersion.VersionCheckFail errorMsg -> do
|
||||
cliSendMessage $ Message.Failure "Node requirement not met" errorMsg
|
||||
exitFailure
|
||||
Right _ -> pure ()
|
||||
NodeVersion.VersionCheckSuccess -> pure ()
|
||||
|
||||
case commandCall of
|
||||
Command.Call.New newArgs -> runCommand $ createNewProject newArgs
|
||||
Command.Call.NewAiToStdout projectName appDescription projectConfigJson ->
|
||||
runCommand $ Command.CreateNewProject.AI.createNewProjectNonInteractiveToStdout projectName appDescription projectConfigJson
|
||||
Command.Call.NewAiToDisk projectName appDescription projectConfigJson ->
|
||||
runCommand $ Command.CreateNewProject.AI.createNewProjectNonInteractiveOnDisk projectName appDescription projectConfigJson
|
||||
Command.Call.NewAi newAiArgs -> case newAiArgs of
|
||||
["--stdout", projectName, appDescription, projectConfigJson] ->
|
||||
runCommand $
|
||||
Command.CreateNewProject.AI.createNewProjectNonInteractiveToStdout
|
||||
projectName
|
||||
appDescription
|
||||
projectConfigJson
|
||||
[projectName, appDescription, projectConfigJson] ->
|
||||
runCommand $
|
||||
Command.CreateNewProject.AI.createNewProjectNonInteractiveOnDisk
|
||||
projectName
|
||||
appDescription
|
||||
projectConfigJson
|
||||
_ -> printWaspNewAiUsage
|
||||
Command.Call.Start -> runCommand start
|
||||
Command.Call.StartDb -> runCommand Command.Start.Db.start
|
||||
Command.Call.Clean -> runCommand clean
|
||||
@ -141,6 +145,11 @@ printUsage =
|
||||
" -t|--template <template-name>",
|
||||
" Check out the templates list here: https://github.com/wasp-lang/starters",
|
||||
"",
|
||||
cmd " new:ai <app-name> <app-description> [<config-json>]",
|
||||
" Uses AI to create a new Wasp project just based on the app name and the description.",
|
||||
" You can do the same thing with `wasp new` interactively.",
|
||||
" Run `wasp new:ai` for more info.",
|
||||
"",
|
||||
cmd " version Prints current version of CLI.",
|
||||
cmd " waspls Run Wasp Language Server. Add --help to get more info.",
|
||||
cmd " completion Prints help on bash completion.",
|
||||
@ -230,6 +239,30 @@ printDbUsage =
|
||||
]
|
||||
{- ORMOLU_ENABLE -}
|
||||
|
||||
{- ORMOLU_DISABLE -}
|
||||
printWaspNewAiUsage :: IO ()
|
||||
printWaspNewAiUsage =
|
||||
putStrLn $
|
||||
unlines
|
||||
[ title "USAGE",
|
||||
" wasp new:ai <app-name> <app-description> <config-json>",
|
||||
"",
|
||||
" Config JSON:",
|
||||
" It is used to provide additional configuration to Wasp AI.",
|
||||
" Following fields are supported:",
|
||||
" {",
|
||||
" \"defaultGptTemperature\"?: number (from 0 to 2)",
|
||||
" \"planningGptModel\"?: string (OpenAI model name)",
|
||||
" \"codingGptModel\"?: string (OpenAI model name)",
|
||||
" \"primaryColor\"?: string (Tailwind color name)",
|
||||
" }",
|
||||
"",
|
||||
title "EXAMPLES",
|
||||
" wasp new:ai ButtonApp \"One page with button\" \"{}\"",
|
||||
" wasp new:ai ButtonApp \"One page with button\" \"{ \\\"defaultGptTemperature\\\": 0.5, \\\"codingGptModel\\\": \\\"gpt-4-1106-preview\\\" }\""
|
||||
]
|
||||
{- ORMOLU_ENABLE -}
|
||||
|
||||
cmd :: String -> String
|
||||
cmd = mapFirstWord (Term.applyStyles [Term.Yellow, Term.Bold])
|
||||
|
||||
|
@ -2,8 +2,7 @@ module Wasp.Cli.Command.Call where
|
||||
|
||||
data Call
|
||||
= New Arguments
|
||||
| NewAiToStdout String String String -- projectName, appDescription, projectConfigJson
|
||||
| NewAiToDisk String String String -- projectName, appDescription, projectConfigJson
|
||||
| NewAi Arguments
|
||||
| Start
|
||||
| StartDb
|
||||
| Clean
|
||||
|
@ -132,7 +132,9 @@ analyze waspProjectDir = do
|
||||
-- Throws if there were any compilation errors.
|
||||
analyzeWithOptions :: Path' Abs (Dir WaspProjectDir) -> CompileOptions -> Command AS.AppSpec
|
||||
analyzeWithOptions waspProjectDir options = do
|
||||
liftIO (Wasp.Project.analyzeWaspProject waspProjectDir options) >>= \case
|
||||
(appSpecOrErrors, warnings) <- liftIO $ Wasp.Project.analyzeWaspProject waspProjectDir options
|
||||
liftIO $ printWarningsIfAny warnings
|
||||
case appSpecOrErrors of
|
||||
Left errors ->
|
||||
throwError $
|
||||
CommandError "Analyzing wasp project failed" $
|
||||
|
@ -5,13 +5,11 @@ where
|
||||
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
import Data.Function ((&))
|
||||
import StrongPath (Abs, Dir, Path')
|
||||
import qualified StrongPath as SP
|
||||
import Wasp.Cli.Command (Command)
|
||||
import Wasp.Cli.Command.Call (Arguments)
|
||||
import Wasp.Cli.Command.CreateNewProject.AI (createNewProjectInteractiveOnDisk)
|
||||
import qualified Wasp.Cli.Command.CreateNewProject.AI as AI
|
||||
import Wasp.Cli.Command.CreateNewProject.ArgumentsParser (parseNewProjectArgs)
|
||||
import Wasp.Cli.Command.CreateNewProject.Common (throwProjectCreationError)
|
||||
import Wasp.Cli.Command.CreateNewProject.Common (printGettingStartedInstructions, throwProjectCreationError)
|
||||
import Wasp.Cli.Command.CreateNewProject.ProjectDescription
|
||||
( NewProjectDescription (..),
|
||||
obtainNewProjectDescription,
|
||||
@ -24,9 +22,7 @@ import Wasp.Cli.Command.CreateNewProject.StarterTemplates
|
||||
import Wasp.Cli.Command.CreateNewProject.StarterTemplates.Local (createProjectOnDiskFromLocalTemplate)
|
||||
import Wasp.Cli.Command.CreateNewProject.StarterTemplates.Remote (createProjectOnDiskFromRemoteTemplate)
|
||||
import Wasp.Cli.Command.Message (cliSendMessageC)
|
||||
import Wasp.Cli.Common (WaspProjectDir)
|
||||
import qualified Wasp.Message as Msg
|
||||
import qualified Wasp.Util.Terminal as Term
|
||||
|
||||
-- | It receives all of the arguments that were passed to the `wasp new` command.
|
||||
createNewProject :: Arguments -> Command ()
|
||||
@ -38,19 +34,6 @@ createNewProject args = do
|
||||
|
||||
createProjectOnDisk newProjectDescription
|
||||
liftIO $ printGettingStartedInstructions $ _absWaspProjectDir newProjectDescription
|
||||
where
|
||||
-- This function assumes that the project dir is created inside the current working directory when it
|
||||
-- prints the instructions.
|
||||
printGettingStartedInstructions :: Path' Abs (Dir WaspProjectDir) -> IO ()
|
||||
printGettingStartedInstructions absProjectDir = do
|
||||
let projectFolder = init . SP.toFilePath . SP.basename $ absProjectDir
|
||||
{- ORMOLU_DISABLE -}
|
||||
putStrLn $ Term.applyStyles [Term.Green] $ "Created new Wasp app in ./" ++ projectFolder ++ " directory!"
|
||||
putStrLn "To run it, do:"
|
||||
putStrLn ""
|
||||
putStrLn $ Term.applyStyles [Term.Bold] $ " cd " ++ projectFolder
|
||||
putStrLn $ Term.applyStyles [Term.Bold] " wasp start"
|
||||
{- ORMOLU_ENABLE -}
|
||||
|
||||
createProjectOnDisk :: NewProjectDescription -> Command ()
|
||||
createProjectOnDisk
|
||||
@ -67,4 +50,4 @@ createProjectOnDisk
|
||||
LocalStarterTemplate metadata ->
|
||||
liftIO $ createProjectOnDiskFromLocalTemplate absWaspProjectDir projectName appName $ _path metadata
|
||||
AiGeneratedStarterTemplate ->
|
||||
createNewProjectInteractiveOnDisk absWaspProjectDir appName
|
||||
AI.createNewProjectInteractiveOnDisk absWaspProjectDir appName
|
||||
|
@ -6,32 +6,110 @@ module Wasp.Cli.Command.CreateNewProject.AI
|
||||
where
|
||||
|
||||
import Control.Arrow ()
|
||||
import Control.Monad (unless)
|
||||
import Control.Monad.Except (MonadError (throwError), MonadIO (liftIO))
|
||||
import Data.Function ((&))
|
||||
import Data.Functor ((<&>))
|
||||
import Data.List (intercalate)
|
||||
import qualified Data.List.NonEmpty as NE
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.IO as T.IO
|
||||
import StrongPath (Abs, Dir, Path', fromAbsDir)
|
||||
import StrongPath (Abs, Dir, Path', basename, fromAbsDir, fromRelDir)
|
||||
import StrongPath.Operations ()
|
||||
import System.Directory (createDirectory, createDirectoryIfMissing, setCurrentDirectory)
|
||||
import System.Environment (lookupEnv)
|
||||
import System.FilePath (takeDirectory)
|
||||
import qualified System.FilePath as FP
|
||||
import System.IO (hFlush, stdout)
|
||||
import qualified Wasp.AI.CodeAgent as CA
|
||||
import qualified Wasp.AI.GenerateNewProject as GNP
|
||||
import Wasp.AI.GenerateNewProject.Common (NewProjectConfig, NewProjectDetails (..), emptyNewProjectConfig)
|
||||
import Wasp.AI.GenerateNewProject.Common
|
||||
( NewProjectConfig,
|
||||
NewProjectDetails (..),
|
||||
emptyNewProjectConfig,
|
||||
)
|
||||
import qualified Wasp.AI.GenerateNewProject.Common as GNP.C
|
||||
import qualified Wasp.AI.GenerateNewProject.LogMsg as GNP.L
|
||||
import Wasp.AI.OpenAI (OpenAIApiKey)
|
||||
import qualified Wasp.AI.OpenAI.ChatGPT as ChatGPT
|
||||
import Wasp.Cli.Command (Command, CommandError (CommandError))
|
||||
import Wasp.Cli.Command.CreateNewProject.ProjectDescription (NewProjectAppName (..), obtainAvailableProjectDirPath, parseWaspProjectNameIntoAppName)
|
||||
import Wasp.Cli.Command.CreateNewProject.ProjectDescription
|
||||
( NewProjectAppName (..),
|
||||
obtainAvailableProjectDirPath,
|
||||
parseWaspProjectNameIntoAppName,
|
||||
)
|
||||
import Wasp.Cli.Command.CreateNewProject.StarterTemplates (readWaspProjectSkeletonFiles)
|
||||
import Wasp.Cli.Common (WaspProjectDir)
|
||||
import qualified Wasp.Cli.Interactive as Interactive
|
||||
import qualified Wasp.Util as U
|
||||
import qualified Wasp.Util.Aeson as Utils.Aeson
|
||||
import qualified Wasp.Util.Terminal as T
|
||||
|
||||
createNewProjectInteractiveOnDisk :: Path' Abs (Dir WaspProjectDir) -> NewProjectAppName -> Command ()
|
||||
createNewProjectInteractiveOnDisk waspProjectDir appName = do
|
||||
openAIApiKey <- getOpenAIApiKey
|
||||
appDescription <- liftIO $ Interactive.askForRequiredInput "Describe your app in a couple of sentences"
|
||||
liftIO $ createNewProjectOnDisk openAIApiKey waspProjectDir appName appDescription emptyNewProjectConfig
|
||||
(planningGptModel, codingGptModel) <-
|
||||
liftIO $
|
||||
Interactive.askToChoose'
|
||||
"Choose GPT model(s) you want to use:"
|
||||
$ NE.fromList
|
||||
[ Interactive.Option
|
||||
"gpt-4 (planning) + gpt-3.5-turbo (coding)"
|
||||
(Just "Ok results. Cheap and fast. Best cost/benefit ratio.")
|
||||
(ChatGPT.GPT_4, ChatGPT.GPT_3_5_turbo),
|
||||
Interactive.Option
|
||||
"gpt-4 (planning) + gpt-4-1106-preview (coding)"
|
||||
(Just "Possibly better results, but somewhat slower and somewhat more expensive (~2-3x).")
|
||||
(ChatGPT.GPT_4, ChatGPT.GPT_4_1106_Preview),
|
||||
Interactive.Option
|
||||
"gpt-4 (planning + coding)"
|
||||
(Just "Best results, but quite slower and quite more expensive (~5x).")
|
||||
(ChatGPT.GPT_4, ChatGPT.GPT_4)
|
||||
]
|
||||
temperature <-
|
||||
liftIO $
|
||||
Interactive.askToChoose'
|
||||
"Choose the creativity level (temperature):"
|
||||
$ NE.fromList
|
||||
[ Interactive.Option
|
||||
"Balanced (0.7)"
|
||||
(Just "Optimal trade-off between creativity and possible mistakes.")
|
||||
0.7,
|
||||
Interactive.Option
|
||||
"Conventional (0.4)"
|
||||
(Just "Generates sensible code with minimal amount of mistakes.")
|
||||
0.4,
|
||||
Interactive.Option
|
||||
"Creative (1.0)"
|
||||
(Just "Generates more creative code, but mistakes are more likely.")
|
||||
1.0
|
||||
]
|
||||
let projectConfig =
|
||||
emptyNewProjectConfig
|
||||
{ GNP.C.projectPlanningGptModel = Just planningGptModel,
|
||||
GNP.C.projectCodingGptModel = Just codingGptModel,
|
||||
GNP.C.projectDefaultGptTemperature = Just temperature
|
||||
}
|
||||
|
||||
liftIO $ createNewProjectOnDisk openAIApiKey waspProjectDir appName appDescription projectConfig
|
||||
|
||||
liftIO $ do
|
||||
putStrLn $
|
||||
unlines
|
||||
[ "",
|
||||
"========",
|
||||
"",
|
||||
"⚠️ Experimental tech",
|
||||
"Since this is a GPT generated app, it will likely contain some mistakes, proportional to how",
|
||||
"complex the app is. If there are some in your app, check out Wasp docs for help while",
|
||||
"fixing them, and also feel free to reach out to us on Discord! You can also try",
|
||||
"generating the app again to get different results (try playing with the creativity level).",
|
||||
" - Wasp docs: https://wasp-lang.dev/docs",
|
||||
" - Our Discord: https://discord.gg/rzdnErX",
|
||||
"",
|
||||
"========"
|
||||
]
|
||||
|
||||
createNewProjectNonInteractiveOnDisk :: String -> String -> String -> Command ()
|
||||
createNewProjectNonInteractiveOnDisk projectName appDescription projectConfigJson = do
|
||||
@ -64,14 +142,16 @@ createNewProjectOnDisk openAIApiKey waspProjectDir appName appDescription projec
|
||||
CA._writeLog = forwardLogToStdout
|
||||
}
|
||||
|
||||
writeFileToDisk :: FilePath -> T.Text -> IO ()
|
||||
writeFileToDisk path content = do
|
||||
createDirectoryIfMissing True (takeDirectory path)
|
||||
T.IO.writeFile path content
|
||||
putStrLn $ "> Wrote file at " <> path
|
||||
putStrLn $ T.applyStyles [T.Yellow] $ "> Wrote to file: " <> fromRelDir (basename waspProjectDir) FP.</> path
|
||||
hFlush stdout
|
||||
|
||||
forwardLogToStdout :: GNP.L.LogMsg -> IO ()
|
||||
forwardLogToStdout msg = do
|
||||
putStrLn . T.unpack $ msg
|
||||
putStrLn $ GNP.L.toTermString msg
|
||||
hFlush stdout
|
||||
|
||||
-- | Instead of writing files to disk, it will write files (and logs) to the stdout,
|
||||
@ -97,25 +177,32 @@ createNewProjectNonInteractiveToStdout projectName appDescription projectConfigJ
|
||||
|
||||
liftIO $ generateNewProject codeAgentConfig appName appDescription projectConfig
|
||||
where
|
||||
writeFileToStdoutWithDelimiters :: FilePath -> T.Text -> IO ()
|
||||
writeFileToStdoutWithDelimiters path content =
|
||||
writeToStdoutWithDelimiters "WRITE FILE" [T.pack path, content]
|
||||
writeToStdoutWithDelimiters "WRITE FILE" [path, T.unpack content]
|
||||
|
||||
writeLogToStdoutWithDelimiters :: GNP.L.LogMsg -> IO ()
|
||||
writeLogToStdoutWithDelimiters msg =
|
||||
writeToStdoutWithDelimiters "LOG" [msg]
|
||||
unless (null msg') $
|
||||
writeToStdoutWithDelimiters "LOG" [msg']
|
||||
where
|
||||
msg' = U.trim $ GNP.L.toPlainString msg
|
||||
|
||||
writeToStdoutWithDelimiters :: String -> [String] -> IO ()
|
||||
writeToStdoutWithDelimiters delimiterTitle paragraphs = do
|
||||
T.IO.putStrLn . ("\n" <>) $ withDelimiter delimiterTitle $ T.intercalate "\n" paragraphs
|
||||
putStrLn . ("\n" <>) $ withDelimiter delimiterTitle $ intercalate "\n" paragraphs
|
||||
hFlush stdout
|
||||
|
||||
withDelimiter :: String -> String -> String
|
||||
withDelimiter title content =
|
||||
T.intercalate
|
||||
intercalate
|
||||
"\n"
|
||||
[ "==== WASP AI: " <> title <> " ====",
|
||||
content,
|
||||
"===/ WASP AI: " <> title <> " ===="
|
||||
]
|
||||
|
||||
generateNewProject :: CA.CodeAgentConfig -> NewProjectAppName -> String -> NewProjectConfig -> IO ()
|
||||
generateNewProject :: CA.CodeAgentConfig GNP.L.LogMsg -> NewProjectAppName -> String -> NewProjectConfig -> IO ()
|
||||
generateNewProject codeAgentConfig (NewProjectAppName appName) appDescription projectConfig = do
|
||||
waspProjectSkeletonFiles <- readWaspProjectSkeletonFiles
|
||||
CA.runCodeAgent codeAgentConfig $ do
|
||||
@ -123,9 +210,12 @@ generateNewProject codeAgentConfig (NewProjectAppName appName) appDescription pr
|
||||
|
||||
getOpenAIApiKey :: Command OpenAIApiKey
|
||||
getOpenAIApiKey =
|
||||
liftIO (lookupEnv "OPENAI_API_KEY")
|
||||
liftIO (lookupEnv "OPENAI_API_KEY" <&> (>>= validateKey))
|
||||
>>= maybe throwMissingOpenAIApiKeyEnvVarError pure
|
||||
where
|
||||
validateKey "" = Nothing
|
||||
validateKey k = Just k
|
||||
|
||||
throwMissingOpenAIApiKeyEnvVarError =
|
||||
throwError $
|
||||
CommandError
|
||||
@ -133,9 +223,13 @@ getOpenAIApiKey =
|
||||
$ unlines
|
||||
[ "Wasp AI uses ChatGPT to generate your project, and therefore requires you to provide it with an OpenAI API key.",
|
||||
"You can obtain this key via your OpenAI account's user settings (https://platform.openai.com/account/api-keys).",
|
||||
"Then, add",
|
||||
"Then, set OPENAI_API_KEY env var to it and wasp CLI will read from it.",
|
||||
"",
|
||||
"To persist the OPENAI_API_KEY env var, add",
|
||||
" export OPENAI_API_KEY=<yourkeyhere>",
|
||||
"to .bash_profile or .profile, restart your shell, and you should be good to go."
|
||||
"to your .bash_profile (or .profile or .zprofile or whatever your machine is using), restart your shell, and you should be good to go.",
|
||||
"",
|
||||
"Alternatively, you can go to our Mage web app at https://usemage.ai and generate new Wasp app there for free, with no OpenAI API keys needed."
|
||||
]
|
||||
|
||||
newProjectDetails :: NewProjectConfig -> String -> String -> NewProjectDetails
|
||||
|
@ -1,15 +1,42 @@
|
||||
module Wasp.Cli.Command.CreateNewProject.Common where
|
||||
module Wasp.Cli.Command.CreateNewProject.Common
|
||||
( throwProjectCreationError,
|
||||
throwInvalidTemplateNameUsedError,
|
||||
defaultWaspVersionBounds,
|
||||
printGettingStartedInstructions,
|
||||
)
|
||||
where
|
||||
|
||||
import Control.Monad.Except (throwError)
|
||||
import StrongPath (Abs, Dir, Path')
|
||||
import qualified StrongPath as SP
|
||||
import Wasp.Cli.Command (Command, CommandError (..))
|
||||
import Wasp.Cli.Common (WaspProjectDir)
|
||||
import qualified Wasp.SemanticVersion as SV
|
||||
import qualified Wasp.Util.Terminal as Term
|
||||
import qualified Wasp.Version as WV
|
||||
|
||||
throwProjectCreationError :: String -> Command a
|
||||
throwProjectCreationError = throwError . CommandError "Project creation failed"
|
||||
|
||||
throwInvalidTemplateNameUsedError :: Command a
|
||||
throwInvalidTemplateNameUsedError = throwProjectCreationError "Are you sure that the template exists? 🤔 Check the list of templates here: https://github.com/wasp-lang/starters"
|
||||
throwInvalidTemplateNameUsedError =
|
||||
throwProjectCreationError $
|
||||
"Are you sure that the template exists?"
|
||||
<> " 🤔 Check the list of templates here: https://github.com/wasp-lang/starters"
|
||||
|
||||
defaultWaspVersionBounds :: String
|
||||
defaultWaspVersionBounds = show (SV.backwardsCompatibleWith WV.waspVersion)
|
||||
|
||||
-- | This function assumes that the project dir is created inside the current working directory
|
||||
-- when it prints the instructions.
|
||||
printGettingStartedInstructions :: Path' Abs (Dir WaspProjectDir) -> IO ()
|
||||
printGettingStartedInstructions absProjectDir = do
|
||||
let projectFolder = init . SP.toFilePath . SP.basename $ absProjectDir
|
||||
{- ORMOLU_DISABLE -}
|
||||
putStrLn $ Term.applyStyles [Term.Green] $ "Created new Wasp app in ./" ++ projectFolder ++ " directory!"
|
||||
putStrLn "To run it, do:"
|
||||
putStrLn ""
|
||||
putStrLn $ Term.applyStyles [Term.Bold] $ " cd " ++ projectFolder
|
||||
putStrLn $ Term.applyStyles [Term.Bold] " wasp start"
|
||||
putStrLn ""
|
||||
{- ORMOLU_ENABLE -}
|
||||
|
@ -38,12 +38,12 @@ instance Show StarterTemplate where
|
||||
show (LocalStarterTemplate metadata) = _name metadata
|
||||
show AiGeneratedStarterTemplate = "ai-generated"
|
||||
|
||||
instance Interactive.Option StarterTemplate where
|
||||
instance Interactive.IsOption StarterTemplate where
|
||||
showOption = show
|
||||
showOptionDescription (RemoteStarterTemplate metadata) = Just $ _description metadata
|
||||
showOptionDescription (LocalStarterTemplate metadata) = Just $ _description metadata
|
||||
showOptionDescription AiGeneratedStarterTemplate =
|
||||
Just "[experimental] Describe an app in a couple of sentences and have ChatGPT generate initial code for you."
|
||||
Just "🤖 Describe an app in a couple of sentences and have Wasp AI generate initial code for you. (experimental)"
|
||||
|
||||
getStarterTemplates :: IO [StarterTemplate]
|
||||
getStarterTemplates = do
|
||||
|
@ -20,7 +20,8 @@ import qualified Wasp.Util.Terminal as Term
|
||||
deps :: Command ()
|
||||
deps = do
|
||||
InWaspProject waspProjectDir <- require
|
||||
appSpecOrAnalyzerErrors <- liftIO $ analyzeWaspProject waspProjectDir (defaultCompileOptions waspProjectDir)
|
||||
(appSpecOrAnalyzerErrors, _analyzerWarnings) <-
|
||||
liftIO $ analyzeWaspProject waspProjectDir (defaultCompileOptions waspProjectDir)
|
||||
appSpec <-
|
||||
either
|
||||
(throwError . CommandError "Determining dependencies failed due to a compilation error in your Wasp project" . unwords)
|
||||
|
@ -3,7 +3,9 @@
|
||||
module Wasp.Cli.Interactive
|
||||
( askForInput,
|
||||
askToChoose,
|
||||
askToChoose',
|
||||
askForRequiredInput,
|
||||
IsOption (..),
|
||||
Option (..),
|
||||
)
|
||||
where
|
||||
@ -37,22 +39,35 @@ import qualified Wasp.Util.Terminal as Term
|
||||
We want to avoid this so users can type the name of the option when answering
|
||||
without having to type the quotes as well.
|
||||
|
||||
We introduced the Option class to get different "show" behavior for Strings and other
|
||||
types. If we are using something other then String, an instance of Option needs to be defined,
|
||||
We introduced the IsOption class to get different "show" behavior for Strings and other
|
||||
types. If we are using something other then String, an instance of IsOption needs to be defined,
|
||||
but for Strings it just returns the String itself.
|
||||
-}
|
||||
class Option o where
|
||||
class IsOption o where
|
||||
showOption :: o -> String
|
||||
showOptionDescription :: o -> Maybe String
|
||||
|
||||
instance Option [Char] where
|
||||
instance IsOption [Char] where
|
||||
showOption = id
|
||||
showOptionDescription = const Nothing
|
||||
|
||||
data Option o = Option
|
||||
{ oDisplayName :: !String,
|
||||
oDescription :: !(Maybe String),
|
||||
oValue :: !o
|
||||
}
|
||||
|
||||
instance IsOption (Option o) where
|
||||
showOption = oDisplayName
|
||||
showOptionDescription = oDescription
|
||||
|
||||
askForRequiredInput :: String -> IO String
|
||||
askForRequiredInput = repeatIfNull . askForInput
|
||||
|
||||
askToChoose :: forall o. Option o => String -> NonEmpty o -> IO o
|
||||
askToChoose' :: String -> NonEmpty (Option o) -> IO o
|
||||
askToChoose' question options = oValue <$> askToChoose question options
|
||||
|
||||
askToChoose :: forall o. IsOption o => String -> NonEmpty o -> IO o
|
||||
askToChoose _ (singleOption :| []) = return singleOption
|
||||
askToChoose question options = do
|
||||
putStrLn $ Term.applyStyles [Term.Bold] question
|
||||
@ -83,18 +98,26 @@ askToChoose question options = do
|
||||
showIndexedOptions = intercalate "\n" $ showIndexedOption <$> zip [1 ..] (NE.toList options)
|
||||
where
|
||||
showIndexedOption (idx, option) =
|
||||
Term.applyStyles [Term.Yellow] indexPrefix
|
||||
<> Term.applyStyles [Term.Bold] (showOption option)
|
||||
<> (if isDefaultOption option then " (default)" else "")
|
||||
<> showDescription option (length indexPrefix)
|
||||
concat
|
||||
[ indexPrefix,
|
||||
optionName,
|
||||
tags,
|
||||
optionDescription
|
||||
]
|
||||
where
|
||||
indexPrefix = showIndex idx <> " "
|
||||
indexPrefix = Term.applyStyles [Term.Yellow] (showIndex idx) <> " "
|
||||
optionName = Term.applyStyles [Term.Bold] (showOption option)
|
||||
tags = whenDefault (Term.applyStyles [Term.Yellow] " (default)")
|
||||
optionDescription = showDescription (idx, option)
|
||||
whenDefault xs = if isDefaultOption option then xs else mempty
|
||||
|
||||
showIndex i = "[" ++ show (i :: Int) ++ "]"
|
||||
showIndex idx = "[" ++ show (idx :: Int) ++ "]"
|
||||
|
||||
showDescription option indentLength = case showOptionDescription option of
|
||||
showDescription (idx, option) = case showOptionDescription option of
|
||||
Just description -> "\n" <> replicate indentLength ' ' <> description
|
||||
Nothing -> ""
|
||||
where
|
||||
indentLength = length (showIndex idx) + 1
|
||||
|
||||
defaultOption :: o
|
||||
defaultOption = NE.head options
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Since we can't deduplicate these helper functions in the server and the client
|
||||
// we have them duplicated in this file and in data/Generator/templates/server/src/auth/user.ts
|
||||
// We decided not to deduplicate these helper functions in the server and the client.
|
||||
// We have them duplicated in this file and in data/Generator/templates/server/src/auth/user.ts
|
||||
// If you are changing the logic here, make sure to change it there as well.
|
||||
|
||||
import type { User, ProviderName, DeserializedAuthEntity } from './types'
|
||||
|
@ -43,7 +43,7 @@ export function getSignupRoute({
|
||||
|
||||
/**
|
||||
*
|
||||
* There are two variables to consider in the case of an existing user:
|
||||
* There are two cases to consider in the case of an existing user:
|
||||
* - if we allow unverified login
|
||||
* - if the user is already verified
|
||||
*
|
||||
@ -51,19 +51,34 @@ export function getSignupRoute({
|
||||
*
|
||||
* We are handling the case of an existing auth identity in two ways:
|
||||
*
|
||||
* 1. If the user is already verified, we don't leak information and pretend that the user
|
||||
* 1. If the user already exists and is verified, we don't want
|
||||
* to leak that piece of info and instead we pretend that the user
|
||||
* was created successfully.
|
||||
* - This helps with user enumeration attacks. If we would say that the user already exists,
|
||||
* an attacker would know that an account with that email exists.
|
||||
* - This prevents the attacker from learning which emails already have
|
||||
* an account created.
|
||||
*
|
||||
* 2. If the user is not verified:
|
||||
* - We check when we last sent a verification email and if it was less than X seconds ago,
|
||||
* we don't send another one.
|
||||
* - If it was more than X seconds ago, we delete the user and create a new one.
|
||||
* - This helps with people trying to take other people's emails by signing up with them
|
||||
* and then not verifying the email.
|
||||
* - This prevents the attacker from creating an account with somebody
|
||||
* else's email address and therefore permanently making that email
|
||||
* address unavailable for later account creation (by real owner).
|
||||
*/
|
||||
if (existingAuthIdentity && !allowUnverifiedLogin) {
|
||||
if (existingAuthIdentity) {
|
||||
if (allowUnverifiedLogin) {
|
||||
/**
|
||||
* This is the case where we allow unverified login.
|
||||
*
|
||||
* If we pretended that the user was created successfully that would bring
|
||||
* us little value: the attacker would not be able to login and figure out
|
||||
* if the user exists or not, anyway.
|
||||
*
|
||||
* So, we throw an error that says that the user already exists.
|
||||
*/
|
||||
throw new HttpError(422, "User with that email already exists.")
|
||||
}
|
||||
|
||||
const providerData = deserializeAndSanitizeProviderData<'email'>(existingAuthIdentity.providerData);
|
||||
|
||||
// TOOD: faking work makes sense if the time spent on faking the work matches the time
|
||||
@ -86,17 +101,6 @@ export function getSignupRoute({
|
||||
} catch (e: unknown) {
|
||||
rethrowPossibleAuthError(e);
|
||||
}
|
||||
} else if (existingAuthIdentity && allowUnverifiedLogin) {
|
||||
/**
|
||||
* This is the case where we allow unverified login.
|
||||
*
|
||||
* If we pretended that the user was created successfully that would bring
|
||||
* us little value: the attacker would not be able to login and figure out
|
||||
* if the user exists or not, anyway.
|
||||
*
|
||||
* So, we throw an error that says that the user already exists.
|
||||
*/
|
||||
throw new HttpError(422, "User with that email already exists.")
|
||||
}
|
||||
|
||||
const userFields = await validateAndGetAdditionalFields(fields);
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Since we can't deduplicate these helper functions in the server and the client
|
||||
// we have them duplicated in this file and in data/Generator/templates/react-app/src/auth/user.ts
|
||||
// We decided not to deduplicate these helper functions in the server and the client.
|
||||
// We have them duplicated in this file and in data/Generator/templates/react-app/src/auth/user.ts
|
||||
// If you are changing the logic here, make sure to change it there as well.
|
||||
|
||||
import type { SanitizedUser as User, ProviderName, DeserializedAuthEntity } from '../_types/index'
|
||||
|
@ -38,7 +38,13 @@ export type UsernameProviderData = {
|
||||
|
||||
export type OAuthProviderData = {}
|
||||
|
||||
// This type is used to map provider names to their data types.
|
||||
/**
|
||||
* This type is used for type-level programming e.g. to enumerate
|
||||
* all possible provider data types.
|
||||
*
|
||||
* The keys of this type are the names of the providers and the values
|
||||
* are the types of the provider data.
|
||||
*/
|
||||
export type PossibleProviderData = {
|
||||
email: EmailProviderData;
|
||||
username: UsernameProviderData;
|
||||
|
@ -1,5 +1,6 @@
|
||||
{{={= =}=}}
|
||||
{
|
||||
"extends": "@tsconfig/node18/tsconfig.json",
|
||||
"extends": "@tsconfig/node{= majorNodeVersion =}/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
// Overriding this until we implement more complete TypeScript support.
|
||||
"strict": false,
|
||||
@ -8,7 +9,7 @@
|
||||
"target": "es2017",
|
||||
// Enable source map for debugging
|
||||
"sourceMap": true,
|
||||
// The remaining settings should match node18/tsconfig.json, but I kept
|
||||
// The remaining settings should match the extended nodeXY/tsconfig.json, but I kept
|
||||
// them here to be explicit.
|
||||
|
||||
// Enable default imports in TypeScript.
|
||||
|
@ -53,7 +53,7 @@
|
||||
"file",
|
||||
"server/package.json"
|
||||
],
|
||||
"4f0e17393f778e7b176646feae464aa45a812212776bc4c3adc10d68db624553"
|
||||
"72e5881bb95ccc51f16d4bc27e45f9203aba6a96c814d4626f2abf8906a8cd61"
|
||||
],
|
||||
[
|
||||
[
|
||||
@ -228,7 +228,7 @@
|
||||
"file",
|
||||
"server/tsconfig.json"
|
||||
],
|
||||
"f2632965c1e3678fcc0e63b83d7e33fea1a9008ef5fd5a2f5e7bf278337c3e02"
|
||||
"51a60d6350537a9e0696674aae86b122a7dea2a4497d294fd4fd6bc47b7e9808"
|
||||
],
|
||||
[
|
||||
[
|
||||
@ -270,7 +270,7 @@
|
||||
"file",
|
||||
"web-app/package.json"
|
||||
],
|
||||
"ae9ccdfc4078087dc37ca0e9e9efec21f98b98dab290d8c07a9c65dfcc15ceb7"
|
||||
"80acc7a0e40fbf57cfa9a60749530e2c59c473161a7f379e4f956865cfe9379a"
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -1 +1 @@
|
||||
{"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"express","version":"~4.18.1"},{"name":"morgan","version":"~1.10.0"},{"name":"@prisma/client","version":"4.16.2"},{"name":"jsonwebtoken","version":"^8.5.1"},{"name":"secure-password","version":"^4.0.0"},{"name":"dotenv","version":"16.0.2"},{"name":"helmet","version":"^6.0.0"},{"name":"patch-package","version":"^6.4.7"},{"name":"uuid","version":"^9.0.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"rate-limiter-flexible","version":"^2.4.1"},{"name":"superjson","version":"^1.12.2"}],"devDependencies":[{"name":"nodemon","version":"^2.0.19"},{"name":"standard","version":"^17.0.0"},{"name":"prisma","version":"4.16.2"},{"name":"typescript","version":"^5.1.0"},{"name":"@types/express","version":"^4.17.13"},{"name":"@types/express-serve-static-core","version":"^4.17.13"},{"name":"@types/node","version":"^18.11.9"},{"name":"@tsconfig/node18","version":"^1.0.1"},{"name":"@types/uuid","version":"^9.0.0"},{"name":"@types/cors","version":"^2.8.5"}]},"npmDepsForWebApp":{"dependencies":[{"name":"axios","version":"^1.4.0"},{"name":"react","version":"^18.2.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"react-router-dom","version":"^5.3.3"},{"name":"@prisma/client","version":"4.16.2"},{"name":"superjson","version":"^1.12.2"},{"name":"mitt","version":"3.0.0"},{"name":"react-hook-form","version":"^7.45.4"}],"devDependencies":[{"name":"vite","version":"^4.3.9"},{"name":"typescript","version":"^5.1.0"},{"name":"@types/react","version":"^18.0.37"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@types/react-router-dom","version":"^5.3.3"},{"name":"@vitejs/plugin-react-swc","version":"^3.0.0"},{"name":"dotenv","version":"^16.0.3"},{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"vitest","version":"^0.29.3"},{"name":"@vitest/ui","version":"^0.29.3"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.0.0"},{"name":"@testing-library/jest-dom","version":"^5.16.5"},{"name":"msw","version":"^1.1.0"}]}}
|
||||
{"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"express","version":"~4.18.1"},{"name":"morgan","version":"~1.10.0"},{"name":"@prisma/client","version":"4.16.2"},{"name":"jsonwebtoken","version":"^8.5.1"},{"name":"secure-password","version":"^4.0.0"},{"name":"dotenv","version":"16.0.2"},{"name":"helmet","version":"^6.0.0"},{"name":"patch-package","version":"^6.4.7"},{"name":"uuid","version":"^9.0.0"},{"name":"lodash.merge","version":"^4.6.2"},{"name":"rate-limiter-flexible","version":"^2.4.1"},{"name":"superjson","version":"^1.12.2"}],"devDependencies":[{"name":"nodemon","version":"^2.0.19"},{"name":"standard","version":"^17.0.0"},{"name":"prisma","version":"4.16.2"},{"name":"typescript","version":"^5.1.0"},{"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":"@tsconfig/node18","version":"latest"},{"name":"@types/uuid","version":"^9.0.0"},{"name":"@types/cors","version":"^2.8.5"}]},"npmDepsForWebApp":{"dependencies":[{"name":"axios","version":"^1.4.0"},{"name":"react","version":"^18.2.0"},{"name":"react-dom","version":"^18.2.0"},{"name":"@tanstack/react-query","version":"^4.29.0"},{"name":"react-router-dom","version":"^5.3.3"},{"name":"@prisma/client","version":"4.16.2"},{"name":"superjson","version":"^1.12.2"},{"name":"mitt","version":"3.0.0"},{"name":"react-hook-form","version":"^7.45.4"}],"devDependencies":[{"name":"vite","version":"^4.3.9"},{"name":"typescript","version":"^5.1.0"},{"name":"@types/react","version":"^18.0.37"},{"name":"@types/react-dom","version":"^18.0.11"},{"name":"@types/react-router-dom","version":"^5.3.3"},{"name":"@vitejs/plugin-react-swc","version":"^3.0.0"},{"name":"dotenv","version":"^16.0.3"},{"name":"@tsconfig/vite-react","version":"^2.0.0"},{"name":"vitest","version":"^0.29.3"},{"name":"@vitest/ui","version":"^0.29.3"},{"name":"jsdom","version":"^21.1.1"},{"name":"@testing-library/react","version":"^14.0.0"},{"name":"@testing-library/jest-dom","version":"^5.16.5"},{"name":"msw","version":"^1.1.0"}]}}
|