platform
platform copied to clipboard
refactor: env process into config file
Summary by CodeRabbit
-
New Features
- Introduced a robust environment variable validation system, ensuring all configuration parameters are strictly checked before application startup.
- Added new utility functions for string and URL validation.
- Provided a sample environment file and comprehensive test suite for configuration validation.
-
Tests
- Added extensive tests covering various environment variable formats and validation scenarios.
-
Chores
- Improved code style and readability with minor formatting adjustments and added blank lines for clarity in several files.
Hello! I think the branch is ready to be merged, please tell me if there's any troubles with it, or anything I can improve
Hello @rockito10 Thanks for the PR!
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
@coderabbitai review
✅ Actions performed
Review triggered.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
[!IMPORTANT]
Review skipped
Auto reviews are disabled on base/target branches other than the default branch.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.
Walkthrough
This update introduces a comprehensive runtime environment validation framework in the config directory, including new validation helpers, error handling, and test coverage. It also applies minor whitespace and formatting changes to several TypeScript files in the application and library code, without affecting any functional logic or public interfaces outside the new configuration modules.
Changes
| File(s) | Change Summary |
|---|---|
| .eslintrc.js | Added a newline at the end of the file. |
| apps/api-gateway/src/issuance/dtos/issuance.dto.ts | Added a duplicate import of IsUUID. |
| apps/api-gateway/src/issuance/issuance.controller.ts | Inserted a blank line after an import statement. |
| apps/api-gateway/src/verification/verification.controller.ts | Added a blank line after an object construction in a method. |
| libs/common/src/NATSClient.ts | Removed an extraneous blank line inside a method. |
| config/config.ts | Introduced strict environment variable validation and export of parsed config as env. |
| config/core/error.ts | Added custom error class VError and supporting types for validation errors. |
| config/core/helpers/str-helpers.ts | Added string utility functions grouped under _STR. |
| config/core/helpers/url-helpers.ts | Added URL and email validation utilities under _URL. |
| config/core/index.ts | Added validation framework with builder classes and schema support, exported as v. |
| config/core/validators.ts | Added a comprehensive set of string validators for config inputs. |
| config/test/.env.test.sample | Added a sample environment file with annotated valid/invalid values for testing. |
| config/test/config.spec.ts | Added a test suite for environment validation covering many string formats and constraints. |
Sequence Diagram(s)
sequenceDiagram
participant App as Application
participant Config as config/config.ts
participant Env as process.env
participant Schema as envDemoSchema
participant V as v (validation framework)
participant Error as VError
App->>Config: Import env
Config->>Env: Read environment variables
Config->>Schema: Define validation schema
Config->>V: Use v.schema to validate process.env
V->>Env: Validate each variable with StringBuilder rules
V-->>Config: Return success or VError
alt Validation fails
Config->>Error: Throw VError with details
else Validation passes
Config->>App: Export parsed env config
end
Poem
In the warren where configs dwell,
New helpers and schemas now excel.
With errors caught and strings made neat,
The rabbit hops—validation complete!
Whitespace swept, tests abound,
In every burrow, safety’s found.
🐇✨
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Explain this complex logic.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai explain this code block.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and explain its main purpose.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Hello @rockito10
We were working on some releases, which meant we couldn't merge some PRs. Since that part is about to be finished, we can now merge appropriate PRs.
Do you mind having a look at the suggestions from coderabbit and also some DCO issues
Hello! I read the reviews and worked a bit on them, just a couple of things:
-Regarding the DCO, I did sign my previous commits, these last unsigned ones seem to be from the last merge we did on this branch, from other people. Im not sure if I am allowed to change their commit messages to have signatures.
-Regarding the CodeRabbit review, I did most of the things it requested, except the isOptional conflict, because if the function would receive the input parameter, there'll be no way to use it (since what I am checking is that it could be null or undefined but it could also be anything else), so I just return true in this case. Still, I can change it if you want, no problem on that.
if I am allowed allowed to change their commit messages
You won't be changing their commit messages, you'll be simply be rebasing your branch on top of their unsigned commits and signing them in the process. Shouldn't be an issue, have a look at the suggestions here to resolve them.
I am checking is that it could be null or undefined but it could also be anything else
And from what I understand, coderabbit is suggesting to check the types along with being optional right?
Ah, I see, I didnt know rebasing would help with this. Also, yes, I realized the optional wouldnt allow other checks properly, currently working on that, thanks for the help, hoping to have something soon enough!
That's great, looking forward to getting this merged soon. Also your enthusiasm is truly appreciated.
Quality Gate passed
Issues
4 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.1% Duplication on New Code
Hello, I think it looks good for now, I think the branch is quite behind dev, do ask if you need help with that or if anything went wrong with the code. Already signed everything like you asked, and fixed those things (along with making optional work with validator chaining).