Skip to content
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

chore(api): Fix inconsistencies in zod schema #240

Merged
merged 6 commits into from
May 27, 2024

Conversation

Ritika1705
Copy link
Contributor

@Ritika1705 Ritika1705 commented May 25, 2024

Description

Email regex validation added.

z.string().regex(/^[a-zA-Z0-9.%+-]+ [<][a-zA-Z0-9.%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}

In this single line, the regex pattern is directly embedded in the schema definition. This keeps the code concise and straightforward. (Expected format is "your-name your-name@email.com")

Fixes #216

Dependencies

Mention any dependencies/packages used

Future Improvements

Mention any improvements to be done in future related to any file/feature

Mentions

Mention and tag the people

Screenshots of relevant screens

Add screenshots of relevant screens

Developer's checklist

  • My PR follows the style guidelines of this project
  • I have performed a self-check on my work

If changes are made in the code:

  • I have followed the coding guidelines
  • My changes in code generate no new warnings
  • My changes are breaking another fix/feature of the project
  • I have added test cases to show that my feature works
  • I have added relevant screenshots in my PR
  • There are no UI/UX issues

Documentation Update

  • This PR requires an update to the documentation at docs.keyshade.xyz
  • I have made the necessary updates to the documentation, or no documentation changes are required.

@Ritika1705 Ritika1705 requested a review from rajdip-b as a code owner May 25, 2024 17:50
Copy link
Contributor

Failed to generate code suggestions for PR

@rajdip-b rajdip-b changed the title Email regex validation added chore(api): Email regex validation added to zod schema May 25, 2024
@rajdip-b
Copy link
Member

Hey Ritika! Glad that you put up this pr. The issue also mentions 3 other items that you would need to add to make this pr complete! Do let us know if you face any errors.

@Ritika1705
Copy link
Contributor Author

Hi @rajdip-b , if you can kindly elaborate as to what needs to be done for the other issues. As I was not so much clear about them. thanks

@rajdip-b
Copy link
Member

Okay look the second and 3rd bullets point to separate files where we have used @ts-expect-error becuase typecript was complaining about the value of process.env.NODE_ENV. You would have to remove the @ts-expect-error lines in those files and make sure that the type inference is working properly

The last point was to add another regex expression for email in the zod schema. You can just click on the hyperlinks and it will direct you to the files in concern.

@Ritika1705
Copy link
Contributor Author

Okay look the second and 3rd bullets point to separate files where we have used @ts-expect-error becuase typecript was complaining about the value of process.env.NODE_ENV. You would have to remove the @ts-expect-error lines in those files and make sure that the type inference is working properly

The last point was to add another regex expression for email in the zod schema. You can just click on the hyperlinks and it will direct you to the files in concern.

Hi @rajdip-b, so the 4th point is clear to me. But for the 2nd point - I have to remove the '@ts-expect-error' comments? and what about the 3rd point? I am sorry if I am taking time to understand this.

@rajdip-b
Copy link
Member

No worries! Refer to this to understand how ts expect error works. You would need to remove ts error and also make sure that the value for NODE_ENV is properly inferred. You have to do this for both 2nd and 3rd points.

For the 4th one, you would need to validate the email input in the zod schema. The 4th point in the issue points to the line you need to validate.

Also, you can join our discord if you would like to discuss this more! https://discord.gg/tbsUq3Vv

@kriptonian1
Copy link
Contributor

can't we just do z.string().email() rather than writing the regex manuallly

@rajdip-b
Copy link
Member

can't we just do z.string().email() rather than writing the regex manuallly

Yeah totally but not for the first case.

@kriptonian1
Copy link
Contributor

can't we just do z.string().email() rather than writing the regex manuallly

Yeah totally but not for the first case.

oh accha, I didn't check the format that we are using

@kriptonian1
Copy link
Contributor

@rajdip-b I think we should add some zod middleware validation like hono https://hono.dev/guides/validation#zod-validator-middleware

@rajdip-b
Copy link
Member

@rajdip-b I think we should add some zod middleware validation like hono https://hono.dev/guides/validation#zod-validator-middleware

That would be an overkill since we are using the zod schema only during application startup

@Ritika1705
Copy link
Contributor Author

Hi @rajdip-b, made some changes, kindly take a look

@rajdip-b
Copy link
Member

@Ritika1705 Thanks! The PR looks clean. I'll just ask the guy who initially developed this to drop a review.

@jamesfrye420 hey bro mind checking out the PR once? It aims to close those @ts-expect-error clauses in zod :D

@jamesfrye420
Copy link
Contributor

Cool will do

Copy link
Contributor

@jamesfrye420 jamesfrye420 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take your name <email@example.com> into consideration for FROM_EMAIL

@Ritika1705
Copy link
Contributor Author

Take your name <email@example.com> into consideration for FROM_EMAIL

@jamesfrye420 , @rajdip-b updated the code as per review comments

@jamesfrye420
Copy link
Contributor

Looks good.

@rajdip-b you can merge and close this.

@rajdip-b
Copy link
Member

@Ritika1705 can you please try running pnpm e2e:api on your device locally? Seems that it is throwing an error which isn't supposed to happen. This is the line that's responsible for it. Somehow, it is not detecting the e2e NODE_ENV. I specify the NODE_ENV value in this line.

The rest of the PR looks pretty nice, and I think I can merge it as soon as we can fix the error.

@rajdip-b rajdip-b changed the title chore(api): Email regex validation added to zod schema chore(api): Fix inconsistencies in zod schema May 27, 2024
@Ritika1705
Copy link
Contributor Author

@Ritika1705 can you please try running pnpm e2e:api on your device locally? Seems that it is throwing an error which isn't supposed to happen. This is the line that's responsible for it. Somehow, it is not detecting the e2e NODE_ENV. I specify the NODE_ENV value in this line.

The rest of the PR looks pretty nice, and I think I can merge it as soon as we can fix the error.

@rajdip-b , not able to figure out what the issue is here. Some help will be appreciated. Tried in local too. Getting the same error

@rajdip-b
Copy link
Member

@Ritika1705 I would recommend you to log the value of NODE_ENV when you run the e2e tests. Do this before, and after you sset the value of node env like you are doing. I think that will be helpful.

Copy link

sonarcloud bot commented May 27, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
3.9% Duplication on New Code

See analysis details on SonarCloud

@Ritika1705
Copy link
Contributor Author

Hi @rajdip-b , errors are resolved. kindly look at the commits and merge the PR if you feel everything looks good

Copy link
Member

@rajdip-b rajdip-b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this works! Thanks for the PR :D

@rajdip-b rajdip-b merged commit f3a3632 into keyshade-xyz:develop May 27, 2024
5 checks passed
HarshPatel5940 pushed a commit to HarshPatel5940/keyshade that referenced this pull request Jun 1, 2024
rajdip-b pushed a commit that referenced this pull request Jun 12, 2024
## [2.0.0](v1.4.0...v2.0.0) (2024-06-12)

### ⚠ BREAKING CHANGES

* **api:** Refactor environment, [secure] and variable functionality

### 🚀 Features

* **platform:** Workspace integrate ([#241](#241)) ([6107e7d](6107e7d))

### 📚 Documentation

* Fix broken links in README.md ([9266788](9266788))
* Modified environment-variable.md ([#256](#256)) ([4974756](4974756))

### 🔧 Miscellaneous Chores

* Added docker build and run commands to` package.json` ([#258](#258)) ([af61791](af61791))
* **api:** Fix inconsistencies in zod schema ([#240](#240)) ([f3a3632](f3a3632))
* **ci:** Update deploy web ([e80d47d](e80d47d))
* **docker:** Grant correct permissions to docker image ([#251](#251)) ([49546aa](49546aa))
* Update GitHub Action plugin versions  ([#263](#263)) ([020bbf6](020bbf6))
* Update package versions for release ([93785be](93785be))

### 🔨 Code Refactoring

* **api:** Refactor environment, [secure] and variable functionality ([#270](#270)) ([55a6d37](55a6d37))
* **api:** Replace for loop with array indexing while decrypting [secure]s during bulk fetch [#265](#265) ([#266](#266)) ([62a1731](62a1731))
* **api:** Update return type while fetching [secure]s and variables ([#264](#264)) ([fd36abd](fd36abd))
@rajdip-b
Copy link
Member

🎉 This PR is included in version 2.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

rajdip-b pushed a commit that referenced this pull request Jun 27, 2024
## [2.0.0](v1.4.0...v2.0.0) (2024-06-12)

### ⚠ BREAKING CHANGES

* **api:** Refactor environment, [secure] and variable functionality

### 🚀 Features

* **platform:** Workspace integrate ([#241](#241)) ([6107e7d](6107e7d))

### 📚 Documentation

* Fix broken links in README.md ([9266788](9266788))
* Modified environment-variable.md ([#256](#256)) ([4974756](4974756))

### 🔧 Miscellaneous Chores

* Added docker build and run commands to` package.json` ([#258](#258)) ([af61791](af61791))
* **api:** Fix inconsistencies in zod schema ([#240](#240)) ([f3a3632](f3a3632))
* **ci:** Update deploy web ([e80d47d](e80d47d))
* **docker:** Grant correct permissions to docker image ([#251](#251)) ([49546aa](49546aa))
* Update GitHub Action plugin versions  ([#263](#263)) ([020bbf6](020bbf6))
* Update package versions for release ([93785be](93785be))

### 🔨 Code Refactoring

* **api:** Refactor environment, [secure] and variable functionality ([#270](#270)) ([55a6d37](55a6d37))
* **api:** Replace for loop with array indexing while decrypting [secure]s during bulk fetch [#265](#265) ([#266](#266)) ([62a1731](62a1731))
* **api:** Update return type while fetching [secure]s and variables ([#264](#264)) ([fd36abd](fd36abd))
yogesh1801 pushed a commit to yogesh1801/keyshade that referenced this pull request Jun 29, 2024
## [2.0.0](keyshade-xyz/keyshade@v1.4.0...v2.0.0) (2024-06-12)

### ⚠ BREAKING CHANGES

* **api:** Refactor environment, [secure] and variable functionality

### 🚀 Features

* **platform:** Workspace integrate ([keyshade-xyz#241](keyshade-xyz#241)) ([6107e7d](keyshade-xyz@6107e7d))

### 📚 Documentation

* Fix broken links in README.md ([9266788](keyshade-xyz@9266788))
* Modified environment-variable.md ([keyshade-xyz#256](keyshade-xyz#256)) ([4974756](keyshade-xyz@4974756))

### 🔧 Miscellaneous Chores

* Added docker build and run commands to` package.json` ([keyshade-xyz#258](keyshade-xyz#258)) ([af61791](keyshade-xyz@af61791))
* **api:** Fix inconsistencies in zod schema ([keyshade-xyz#240](keyshade-xyz#240)) ([f3a3632](keyshade-xyz@f3a3632))
* **ci:** Update deploy web ([e80d47d](keyshade-xyz@e80d47d))
* **docker:** Grant correct permissions to docker image ([keyshade-xyz#251](keyshade-xyz#251)) ([49546aa](keyshade-xyz@49546aa))
* Update GitHub Action plugin versions  ([keyshade-xyz#263](keyshade-xyz#263)) ([020bbf6](keyshade-xyz@020bbf6))
* Update package versions for release ([93785be](keyshade-xyz@93785be))

### 🔨 Code Refactoring

* **api:** Refactor environment, [secure] and variable functionality ([keyshade-xyz#270](keyshade-xyz#270)) ([55a6d37](keyshade-xyz@55a6d37))
* **api:** Replace for loop with array indexing while decrypting [secure]s during bulk fetch [keyshade-xyz#265](keyshade-xyz#265) ([keyshade-xyz#266](keyshade-xyz#266)) ([62a1731](keyshade-xyz@62a1731))
* **api:** Update return type while fetching [secure]s and variables ([keyshade-xyz#264](keyshade-xyz#264)) ([fd36abd](keyshade-xyz@fd36abd))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API: Address inconsistencies related to zod env parsing
4 participants