keyshade-xyz / keyshade

Realtime secret and configuration management tool, with the best in class security and seamless integration support
https://keyshade.xyz
Mozilla Public License 2.0
196 stars 96 forks source link

feat(cli): Implemented pagination support #453

Closed Nil2000 closed 1 week ago

Nil2000 commented 1 week ago

User description

Description

Implemented pagination support

Fixes #442

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

If changes are made in the code:

Documentation Update


PR Type

Enhancement, Dependencies


Description


Changes walkthrough πŸ“

Relevant files
Enhancement
list.environment.ts
Add pagination support to environment listing command       

apps/cli/src/commands/environment/list.environment.ts
  • Added pagination options to the command.
  • Updated the action method to handle new options.
  • Enhanced environment fetching with pagination parameters.
  • +35/-4   
    list.workspace.ts
    Add pagination support to workspace listing command           

    apps/cli/src/commands/workspace/list.workspace.ts
  • Added pagination options to the command.
  • Updated the action method to handle new options.
  • Enhanced workspace fetching with pagination parameters.
  • +42/-2   
    Dependencies
    package.json
    Update package dependencies for CLI                                           

    apps/cli/package.json - Added `@keyshade/api-client` as a workspace dependency.
    +2/-1     
    pnpm-lock.yaml
    Update pnpm lock file with new dependencies                           

    pnpm-lock.yaml
  • Updated TypeScript version in lock file.
  • Added @keyshade/api-client to lock file.
  • +13/-143

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

    codiumai-pr-agent-free[bot] commented 1 week ago

    PR Reviewer Guide πŸ”

    ⏱️ Estimated effort to review: 3 πŸ”΅πŸ”΅πŸ”΅βšͺβšͺ
    πŸ§ͺ No relevant tests
    πŸ”’ No security concerns identified
    ⚑ Key issues to review

    Error Handling
    The action method doesn't handle potential errors from the API call. Consider adding error handling and user feedback for failed requests. Error Handling
    The action method doesn't handle potential errors from the API call. Consider adding error handling and user feedback for failed requests.
    codiumai-pr-agent-free[bot] commented 1 week ago

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Validate pagination input parameters before making API calls ___ **Consider adding input validation for the pagination options to ensure they are
    within acceptable ranges before passing them to the API call.** [apps/cli/src/commands/environment/list.environment.ts [60-64]](https://github.com/keyshade-xyz/keyshade/pull/453/files#diff-98e45816c7ac3ca77c1edecd3562146bfd4c9a30ab6f818de69daa6e0b6de5feR60-R64) ```diff const { page, limit, order, sort, search } = options if (!projectSlug) { Logger.error('Project slug is required') return } +if (page && (isNaN(Number(page)) || Number(page) < 1)) { + Logger.error('Invalid page number') + return +} +if (limit && (isNaN(Number(limit)) || Number(limit) < 1)) { + Logger.error('Invalid limit') + return +} ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 9 Why: Adding input validation is crucial for preventing potential errors and ensuring that the API receives valid data, which enhances the robustness of the application.
    9
    Error handling
    βœ… Add error handling for API call failures to improve user feedback ___
    Suggestion Impact:The commit added error handling for failed API calls by logging an error message when fetching workspaces fails. code diff: ```diff } else { Logger.error(`Failed fetching workspaces: ${error.message}`) ```
    ___ **Consider adding error handling for the case when the API call fails, to provide more
    informative feedback to the user.** [apps/cli/src/commands/workspace/list.workspace.ts [51-63]](https://github.com/keyshade-xyz/keyshade/pull/453/files#diff-44e21dcd653ec6af4e48083f066d849c89f46c4843678c4c695d065f1250b202R51-R63) ```diff const { success, data, error } = await ControllerInstance.getInstance().workspaceController.getWorkspacesOfUser( { page, limit, order, sort, search }, this.headers ) if (success) { + // Existing success handling +} else { + Logger.error('Failed to fetch workspaces:', error?.message || 'Unknown error') +} ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: Implementing error handling provides users with informative feedback when API calls fail, improving the user experience and aiding in debugging.
    8
    Enhancement
    βœ… Use object destructuring for function parameters to improve code clarity ___
    Suggestion Impact:The suggestion to use object destructuring was indirectly implemented by spreading the options object in the function call, which simplifies the code and achieves a similar goal of improving readability. code diff: ```diff async action({ args, options }: CommandActionData): Promise { const [projectSlug] = args - const { page, limit, order, sort, search } = options + if (!projectSlug) { Logger.error('Project slug is required') return @@ -75,7 +50,7 @@ data: environments, error } = await environmentController.getAllEnvironmentsOfProject( - { projectSlug, page, limit, order, sort, search }, + { projectSlug, ...options }, ```
    ___ **Consider using object destructuring for the options parameter in the action method
    to improve code readability and maintainability.** [apps/cli/src/commands/environment/list.environment.ts [58-60]](https://github.com/keyshade-xyz/keyshade/pull/453/files#diff-98e45816c7ac3ca77c1edecd3562146bfd4c9a30ab6f818de69daa6e0b6de5feR58-R60) ```diff -async action({ args, options }: CommandActionData): Promise { +async action({ args, options: { page, limit, order, sort, search } }: CommandActionData): Promise { const [projectSlug] = args - const { page, limit, order, sort, search } = options ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: The suggestion improves code readability and maintainability by using object destructuring, which is a common practice in modern JavaScript and TypeScript.
    7
    Best practice
    Add type annotations to destructured options for improved type safety ___ **Consider adding type annotations for the destructured options to ensure type safety
    and improve code maintainability.** [apps/cli/src/commands/workspace/list.workspace.ts [49]](https://github.com/keyshade-xyz/keyshade/pull/453/files#diff-44e21dcd653ec6af4e48083f066d849c89f46c4843678c4c695d065f1250b202R49-R49) ```diff -const { page, limit, order, sort, search } = options +const { page, limit, order, sort, search }: { + page?: number; + limit?: number; + order?: 'ASC' | 'DESC'; + sort?: string; + search?: string; +} = options ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 6 Why: Adding type annotations enhances type safety and maintainability, ensuring that the code adheres to TypeScript's type-checking capabilities.
    6

    πŸ’‘ Need additional feedback ? start a PR chat

    Nil2000 commented 1 week ago

    @rajdip-b Can you help what part has created this build errors?

    Edit: Solved

    rajdip-b commented 1 week ago

    I'll merge #451 by tonight.

    Nil2000 commented 1 week ago

    I'll merge #451 by tonight.

    Ok thanks πŸ™

    rajdip-b commented 1 week ago

    @Nil2000 hey bro, can you now get the remaining stuff fixed?

    Nil2000 commented 1 week ago

    @Nil2000 hey bro, can you now get the remaining stuff fixed?

    Did not get you. Can you be specific about what were you mentioning?