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

refactor(monorepo): Migrate from nx to turbo #153

Merged
merged 12 commits into from
Feb 25, 2024

Conversation

kriptonian1
Copy link
Contributor

@kriptonian1 kriptonian1 commented Feb 22, 2024

Type

enhancement, bug_fix


Description

  • Enhanced authentication guard with error handling for multiple X_KEYSHADE_TOKEN headers.
  • Standardized eccrypto import syntax across utility files.
  • Added explicit return type to fetchEvents function.
  • Removed unused API route files.
  • Refactored global styles and metadata configuration in web app.
  • Updated page component with renamed imports and explicit return type.
  • Added new Killers and Links components with improved types and practices.
  • Introduced a new SDK class for managing projects and secrets.
  • Updated ESLint, Next.js, and TypeScript configurations across projects.

Changes walkthrough

Relevant files
Error handling
1 files
auth.guard.ts
Enhance Authentication Guard with Error Handling for Multiple Headers

apps/api/src/auth/guard/auth/auth.guard.ts

  • Added error handling for multiple X_KEYSHADE_TOKEN headers to prevent
    ambiguous authentication attempts.
  • +3/-0     
    Enhancement
    13 files
    *.ts
    Standardize eccrypto Import Syntax Across Utility Files   

    apps/api/src/common/*.ts

    • Updated eccrypto import statements to use import * as syntax.
    fetch-events.ts
    Add Explicit Return Type to fetchEvents Function                 

    apps/api/src/common/fetch-events.ts

    • Added explicit return type Promise<any> to fetchEvents function.
    +1/-1     
    route.ts
    Remove Unused API Route File                                                         

    apps/web/app/api/hello/route.ts

    • Removed unused API route file.
    +0/-3     
    layout.tsx
    Refactor Global Styles and Metadata Configuration               

    apps/web/app/layout.tsx

  • Refactored global styles and metadata configuration.
  • Improved type annotations.
  • +56/-55 
    page.tsx
    Update Page Component with Renamed Imports and Explicit Return Type

    apps/web/app/page.tsx

  • Updated imports to use renamed components.
  • Added explicit return type to Index function.
  • +6/-5     
    Killers.tsx
    Remove Old Killers Component File                                               

    apps/web/components/Killers.tsx

    • Removed old Killers component file.
    +0/-32   
    Links.tsx
    Remove Old Links Component File                                                   

    apps/web/components/Links.tsx

    • Removed old Links component file.
    +0/-34   
    killers.tsx
    Add New Killers Component with Improved Types and Practices

    apps/web/components/killers.tsx

  • Added new Killers component with improved type annotations and React
    best practices.
  • +0/-32   
    links.tsx
    Add New Links Component with Improved Types and Practices

    apps/web/components/links.tsx

  • Added new Links component with improved type annotations and React
    best practices.
  • +0/-34   
    route.ts
    Remove Unused API Route File in Workspace App                       

    apps/workspace/app/api/hello/route.ts

    • Removed unused API route file.
    +0/-3     
    layout.tsx
    Update Global Styles Configuration in Workspace App           

    apps/workspace/app/layout.tsx

    • Updated global styles configuration.
    • Improved type annotations.
    +7/-7     
    page.tsx
    Add Explicit Return Type to Index Function in Workspace App

    apps/workspace/app/page.tsx

    • Added explicit return type to Index function.
    +1/-1     
    keyshade.ts
    Introduce New SDK Class for Project and Secret Management

    packages/sdk-node/src/keyshade.ts

    • Introduced a new SDK class for managing projects and secrets.
    +38/-0   
    Configuration changes
    4 files
    *.eslintrc.js
    Update ESLint Configuration Across Projects                           

    *.eslintrc.js

  • Added or updated ESLint configuration files across multiple projects.
  • *.next.config.js
    Update Next.js Configuration Across Projects                         

    *.next.config.js

    • Updated Next.js configuration files across multiple projects.
    *.tsconfig.json
    Update TypeScript Configuration Across Projects                   

    *.tsconfig.json

    • Updated TypeScript configuration files across multiple projects.
    *.json
    Miscellaneous Configuration and Metadata Updates                 

    *.json

  • Various configuration and metadata updates across multiple JSON files.

  • PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link
    Contributor

    PR Description updated to latest commit (8cfcbaf)

    Copy link
    Contributor

    PR Review

         PR feedback                    
    ⏱️ Estimated effort to review [1-5]

    4, because the PR includes a significant refactor from nx to turbo, affecting multiple configuration files, adding new components, updating import syntax, and modifying test files. The changes span across the entire monorepo, including backend (API), frontend (web app), and shared components. This requires a thorough review of configuration changes, code style consistency, and ensuring that all new components and updated functions are correctly implemented and tested.

    🧪 Relevant tests

    Yes

    🔍 Possible issues
    • The removal of semicolons in TypeScript files might conflict with the project's linting rules if not updated accordingly.
    • The addition of error handling for multiple X_KEYSHADE_TOKEN headers in auth.guard.ts throws a generic error. It might be beneficial to provide a more descriptive error message.
    • The refactor includes changes to the import syntax of eccrypto from default to named imports across several files. It's crucial to ensure that this does not affect the functionality, especially without corresponding changes in the eccrypto module exports.
    • The explicit return type added to fetchEvents function is Promise<any>, which is too generic. It would be better to define a more specific type or interface for the return value.
    • The removal of the API route file apps/web/app/api/hello/route.ts without context might indicate unused code cleanup or could unintentionally remove functionality if the route is still in use.
    • The renaming of imports in page.tsx from Links and Killers to lowercase might indicate a shift to a different naming convention or could be an error if the filenames weren't renamed to lowercase as well, leading to potential import errors in case-sensitive file systems.
    🔒 Security concerns

    No, the changes do not introduce any clear security vulnerabilities. However, it's important to ensure that the new error handling logic and the refactor of cryptographic operations do not inadvertently expose sensitive information or weaken the application's security posture.


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
    When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:

    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    

    With a configuration file, use the following template:

    [pr_reviewer]
    some_config1=...
    some_config2=...
    
    Utilizing extra instructions

    The review tool can be configured with extra instructions, which can be used to guide the model to a feedback tailored to the needs of your project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify the relevant sub-tool, and the relevant aspects of the PR that you want to emphasize.

    Examples for extra instructions:

    [pr_reviewer] # /review #
    extra_instructions="""
    In the 'possible issues' section, emphasize the following:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    How to enable\disable automation
    • When you first install PR-Agent app, the default mode for the review tool is:
    pr_commands = ["/review", ...]
    

    meaning the review tool will run automatically on every PR, with the default configuration.
    Edit this field to enable/disable the tool, or to change the used configurations

    Auto-labels

    The review tool can auto-generate two specific types of labels for a PR:

    • a possible security issue label, that detects possible security issues (enable_review_labels_security flag)
    • a Review effort [1-5]: x label, where x is the estimated effort to review the PR (enable_review_labels_effort flag)
    Extra sub-tools

    The review tool provides a collection of possible feedbacks about a PR.
    It is recommended to review the possible options, and choose the ones relevant for your use case.
    Some of the feature that are disabled by default are quite useful, and should be considered for enabling. For example:
    require_score_review, require_soc2_ticket, and more.

    Auto-approve PRs

    By invoking:

    /review auto_approve
    

    The tool will automatically approve the PR, and add a comment with the approval.

    To ensure safety, the auto-approval feature is disabled by default. To enable auto-approval, you need to actively set in a pre-defined configuration file the following:

    [pr_reviewer]
    enable_auto_approval = true
    

    (this specific flag cannot be set with a command line argument, only in the configuration file, committed to the repository)

    You can also enable auto-approval only if the PR meets certain requirements, such as that the estimated_review_effort is equal or below a certain threshold, by adjusting the flag:

    [pr_reviewer]
    maximal_review_effort = 5
    
    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details.
    To list the possible configuration parameters, add a /config comment.

    See the review usage page for a comprehensive guide on using this tool.

    Copy link
    Contributor

    codiumai-pr-agent-free bot commented Feb 22, 2024

    PR Code Suggestions

    Suggestions                                                                                                                                                     
    best practice
    Use environment variables for URLs and environment-specific values.          

    Consider using environment variables for URLs and other environment-specific values to
    enhance security and flexibility.

    apps/web/app/layout.tsx [9]

    -metadataBase: new URL('https://keyshade.xyz/'),
    +metadataBase: new URL(process.env.BASE_URL || 'https://keyshade.xyz/'),
     
    Enable explicit function return types in ESLint for better code quality.     

    For better code quality and maintainability, consider enabling the
    @typescript-eslint/explicit-function-return-type rule to require explicit return types on
    functions and class methods.

    apps/api/.eslintrc.js [21]

    -'@typescript-eslint/explicit-function-return-type': 'off',
    +'@typescript-eslint/explicit-function-return-type': 'warn',
     
    Pin dependency versions in package.json to ensure compatibility.

    To ensure compatibility and prevent potential issues with package versions, consider
    pinning your dependency versions by removing the caret (^) symbol.

    package.json [121]

    -"husky": "^9.0.11",
    +"husky": "9.0.11",
     
    Mark the package as private to prevent accidental npm publication.           

    To reduce the risk of accidentally publishing private or sensitive files, consider adding
    a "private": true field to your package.json if you do not intend to publish this package
    to npm.

    apps/api/package.json [89]

    -"license": "ISC"
    +"license": "ISC",
    +"private": true
     
    Enable strict type-checking in TypeScript configuration.                     

    Consider enabling "strict": true in your TypeScript configuration to enforce stricter
    type-checking rules. This can help catch common errors at compile time, improving code
    quality and maintainability.

    apps/api/tsconfig.json [15-17]

    -"strictNullChecks": false,
    -"noImplicitAny": false,
    -"strictBindCallApply": false
    +"strict": true
     
    Ensure consistent file name casing.                                          

    It's recommended to set "forceConsistentCasingInFileNames": true to ensure that the casing
    of referenced file names is consistent. This can help avoid issues on case-sensitive file
    systems.

    apps/api/tsconfig.json [18]

    -"forceConsistentCasingInFileNames": false
    +"forceConsistentCasingInFileNames": true
     
    Add Prettier formatting to the pre-commit hook.                              

    To ensure code formatting consistency across your project, consider adding a command to
    run Prettier in your pre-commit hook. This can automatically format staged files according
    to your project's style guidelines.

    .husky/pre-commit [4]

    -pnpm lint && pnpm test:api
    +pnpm lint && pnpm format && pnpm test:api
     
    performance
    Optimize image loading with next/image.                         

    Use next/image for optimized image loading and to automatically handle different device
    sizes and resolutions.

    apps/web/components/killers.tsx [20]

    -src={`/./${image}.png`}
    +src={`/images/${image}.png`}
     
    Enable Webpack 5 features for better performance.                            

    Enable future Webpack 5 features for improved build performance.

    apps/web/next.config.js [3]

     const nextConfig = {
    +  future: {
    +    webpack5: true,
    +  },
     
    Enable incremental compilation in TypeScript.                                

    To improve build performance and catch errors early, consider setting "incremental": true
    in your TypeScript configuration. This enables incremental compilation by emitting
    .tsbuildinfo files to save information about the project graph for subsequent builds.

    apps/workspace/tsconfig.json [3]

     "compilerOptions": {
    +  "incremental": true
     
    security
    Validate apiKey for format and security.                        

    Ensure that apiKey is validated for proper format and security considerations before using
    it.

    packages/sdk-node/src/keyshade.ts [5-6]

     private constructor(apiKey: string) {
    -  this.apiKey = apiKey
    +  if (!isValidApiKey(apiKey)) {
    +    throw new Error('Invalid API Key format.');
    +  }
    +  this.apiKey = apiKey;
     }
     
    enhancement
    Improve error messaging for API key validation.                              

    Provide a more descriptive error message when rejecting requests with an array of API
    keys.

    apps/api/src/auth/guard/auth/auth.guard.ts [149]

    -throw new Error('Bad auth')
    +throw new Error('Multiple API keys provided. Please provide a single API key.')
     
    Use path.resolve for defining webpack alias to ensure absolute paths.

    Consider using path.resolve instead of path.join for defining aliases to ensure absolute
    paths are generated, which is more reliable for webpack configurations.

    apps/workspace/next.config.js [11]

    -config.resolve.alias["@public"] = path.join(__dirname, "public");
    +config.resolve.alias["@public"] = path.resolve(__dirname, "public");
     
    maintainability
    Use CSS variables for colors and reusable values.                            

    For better maintainability and to avoid hard-coding values, consider using CSS variables
    for colors and other reusable values.

    apps/workspace/app/global.css [6-7]

    -background-color: #0B0D0F;
    -color: white;
    +:root {
    +  --background-color: #0B0D0F;
    +  --text-color: white;
    +}
    +background-color: var(--background-color);
    +color: var(--text-color);
     
    Explicitly include files for compilation in the build configuration.         

    For clarity and maintainability, consider explicitly including the files or directories
    you want to compile in your build configuration, using the "include" property. This can
    help avoid unintentional exclusions and make the build process more predictable.

    apps/api/tsconfig.build.json [3]

    -"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
    +"include": ["src/**/*.ts"]
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.
    When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:

    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    

    With a configuration file, use the following template:

    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    
    Enabling\disabling automation

    When you first install the app, the default mode for the improve tool is:

    pr_commands = ["/improve --pr_code_suggestions.summarize=true", ...]
    

    meaning the improve tool will run automatically on every PR, with summarization enabled. Delete this line to disable the tool from running automatically.

    Utilizing extra instructions

    Extra instructions are very important for the improve tool, since they enable to guide the model to suggestions that are more relevant to the specific needs of the project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify relevant aspects that you want the model to focus on.

    Examples for extra instructions:

    [pr_code_suggestions] # /improve #
    extra_instructions="""
    Emphasize the following aspects:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    A note on code suggestions quality
    • While the current AI for code is getting better and better (GPT-4), it's not flawless. Not all the suggestions will be perfect, and a user should not accept all of them automatically.
    • Suggestions are not meant to be simplistic. Instead, they aim to give deep feedback and raise questions, ideas and thoughts to the user, who can then use his judgment, experience, and understanding of the code base.
    • Recommended to use the 'extra_instructions' field to guide the model to suggestions that are more relevant to the specific needs of the project, or use the custom suggestions 💎 tool
    • With large PRs, best quality will be obtained by using 'improve --extended' mode.
    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details.
    To list the possible configuration parameters, add a /config comment.

    See the improve usage page for a more comprehensive guide on using this tool.

    package.json Fixed Show fixed Hide fixed
    package.json Dismissed Show dismissed Hide dismissed
    package.json Dismissed Show dismissed Hide dismissed
    Copy link

    codecov bot commented Feb 24, 2024

    Codecov Report

    Attention: Patch coverage is 80.00000% with 1 lines in your changes are missing coverage. Please review.

    Project coverage is 94.12%. Comparing base (7bb3d21) to head (e0d0c12).
    Report is 20 commits behind head on develop.

    ❗ Current head e0d0c12 differs from pull request most recent head c2a92b4. Consider uploading reports for the commit c2a92b4 to get more accurate results

    Files Patch % Lines
    apps/api/src/auth/guard/auth/auth.guard.ts 50.00% 1 Missing ⚠️
    Additional details and impacted files
    @@             Coverage Diff              @@
    ##           develop     #153       +/-   ##
    ============================================
    + Coverage    62.20%   94.12%   +31.91%     
    ============================================
      Files           76       83        +7     
      Lines         1503     1582       +79     
      Branches       260      252        -8     
    ============================================
    + Hits           935     1489      +554     
    + Misses         568       93      -475     
    Flag Coverage Δ
    api-e2e-tests 94.12% <80.00%> (+31.91%) ⬆️

    Flags with carried forward coverage won't be shown. Click here to find out more.

    ☔ View full report in Codecov by Sentry.
    📢 Have feedback on the report? Share it here.

    Copy link

    Quality Gate Failed Quality Gate failed

    Failed conditions
    1 Security Hotspot

    See analysis details on SonarCloud

    @rajdip-b rajdip-b merged commit 88b4b00 into develop Feb 25, 2024
    4 of 6 checks passed
    @rajdip-b rajdip-b deleted the refactor(monorepo)-migrate-from-nx-to-turborepo branch February 25, 2024 14:15
    rajdip-b pushed a commit that referenced this pull request May 12, 2024
    ## [1.3.0](v1.2.0...v1.3.0) (2024-05-12)
    
    ### 🚀 Features
    
    * Add approval support ([#158](#158)) ([e09ae60](e09ae60))
    * **api:** Add configuration live update support ([#181](#181)) ([f7d6684](f7d6684))
    * **api:** Add feature to export data of a workspace ([#152](#152)) ([46833aa](46833aa))
    * **api:** Add Integration support ([#203](#203)) ([f1ae87e](f1ae87e))
    * **api:** Add note to [secure] and variable ([#151](#151)) ([2e62351](2e62351))
    * **api:** Add OAuth redirection and polished authentication ([#212](#212)) ([d2968bc](d2968bc))
    * **api:** Add support for storing and managing variables ([#149](#149)) ([963a8ae](963a8ae))
    * **api:** Added GitLab OAuth ([#188](#188)) ([4d3bbe4](4d3bbe4))
    * **api:** Added validation for reason field ([#190](#190)) ([90b8ff2](90b8ff2))
    * **api:** Create default workspace on user's creation ([#182](#182)) ([3dc0c4c](3dc0c4c))
    * **api:** Reading `port` Dynamically ([#170](#170)) ([fd46e3e](fd46e3e))
    * **auth:** Add Google OAuth ([#156](#156)) ([cf387ea](cf387ea))
    * **web:** Added waitlist ([#168](#168)) ([1084c77](1084c77))
    * **web:** Landing revamp ([#165](#165)) ([0bc723b](0bc723b))
    
    ### 🐛 Bug Fixes
    
    * **web:** alignment issue in “Collaboration made easy” section ([#178](#178)) ([df5ca75](df5ca75))
    * **workspace:** delete duplicate tailwind config ([99d922a](99d922a))
    
    ### 📚 Documentation
    
    * add contributor list ([f37569a](f37569a))
    * Add integration docs ([#204](#204)) ([406ddb7](406ddb7))
    * Added integration docs to gitbook summary ([ab37530](ab37530))
    * **api:** Add swagger docs of API key controller ([#167](#167)) ([2910476](2910476))
    * **api:** Add swagger docs of User Controller ([#166](#166)) ([fd59522](fd59522))
    * fix typo in environment-variables.md ([#163](#163)) ([48294c9](48294c9))
    * Remove supabase from docs ([#169](#169)) ([eddbce8](eddbce8))
    * **setup:** replace NX with Turbo in setup instructions ([#175](#175)) ([af8a460](af8a460))
    * Update README.md ([b59f16b](b59f16b))
    * Update running-the-api.md ([177dbbf](177dbbf))
    * Update running-the-api.md ([#193](#193)) ([3d5bcac](3d5bcac))
    
    ### 🔧 Miscellaneous Chores
    
    * Added lockfile ([60a3b9b](60a3b9b))
    * Added lockfile ([6bb512c](6bb512c))
    * **api:** Added type inference and runtime validation to `process.env` ([#200](#200)) ([249e07d](249e07d))
    * **api:** Fixed prisma script env errors ([#209](#209)) ([8762354](8762354))
    * **API:** Refactor authority check functions in API ([#189](#189)) ([e9d710d](e9d710d))
    * **api:** Refactor user e2e tests ([b38d45a](b38d45a))
    * **ci:** Disabled api stage release ([97877c4](97877c4))
    * **ci:** Update stage deployment config ([868a6a1](868a6a1))
    * **codecov:** update api-e2e project coverage ([1e90d7e](1e90d7e))
    * **dockerfile:** Fixed web dockerfile ([6134bb2](6134bb2))
    * **docker:** Optimized web Dockerfile to reduct image size ([#173](#173)) ([444286a](444286a))
    * **release:** Downgraded package version ([c173fee](c173fee))
    * **release:** Fix failing release ([#213](#213)) ([40f64f3](40f64f3))
    * **release:** Install pnpm ([1081bea](1081bea))
    * **release:** Updated release commit ([b8958e7](b8958e7))
    * **release:** Updated release commit ([e270eb8](e270eb8))
    * Update deprecated husky Install command ([#202](#202)) ([e61102c](e61102c))
    * Upgrade @million/lint from 0.0.66 to 0.0.73 ([#172](#172)) ([dd43ed9](dd43ed9))
    * **web:** Updated fly memory config ([4debc66](4debc66))
    
    ### 🔨 Code Refactoring
    
    * **api:** Made events central to workspace ([#159](#159)) ([9bc00ae](9bc00ae))
    * **api:** Migrated to cookie based authentication ([#206](#206)) ([ad6911f](ad6911f))
    * **monorepo:** Migrate from nx to turbo ([#153](#153)) ([88b4b00](88b4b00))
    @rajdip-b
    Copy link
    Member

    🎉 This PR is included in version 1.3.0 🎉

    The release is available on GitHub release

    Your semantic-release bot 📦🚀

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    type: enhancement New feature or request
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants