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

feat(api): Add slug in entities #415

Merged
merged 5 commits into from
Sep 9, 2024
Merged

Conversation

rajdip-b
Copy link
Member

@rajdip-b rajdip-b commented Sep 9, 2024

User description

Description

This PR added a slug field to the following entities:

  • Workspace
  • Workspace Role
  • Integration
  • Project
  • Environment
  • Variable
  • Secret
  • API Key

The motivation behind this PR is very simple, to have user-friendly unique entity names rather than IDs. For example, If there is a workspace named My Org, it will have a slug value of my-org-4tm2. The old way of accessing this resource would be using the following:

GET /api/workspace/<workspaceId>

The new way would be this:

GET /api/workspace/<workspaceSlug>

So, we would be using:

GET /api/workspace/my-org-4tm2

Along with that, there are also a lot of refactorings in the E2E test files.


PR Type

enhancement, tests, documentation


Description

  • Added slug field to multiple entities (Workspace, Workspace Role, Integration, Project, Environment, Variable, Secret) for user-friendly unique names.
  • Refactored E2E tests to use slug instead of id, enhancing test coverage and organization.
  • Updated services and controllers to support slug-based operations, replacing ID-based operations.
  • Improved authority checks and error messages to reflect slug usage.
  • Added JSDoc comments to the paginate function for better documentation.

Changes walkthrough 📝

Relevant files
Tests
6 files
workspace.e2e.spec.ts
Refactor workspace tests to use slugs and improve coverage

apps/api/src/workspace/workspace.e2e.spec.ts

  • Updated imports and refactored test cases to use slug instead of id.
  • Added new test cases for workspace operations using slug.
  • Grouped related test cases into describe blocks for better
    organization.
  • Enhanced test coverage for workspace-related events and operations.
  • +1056/-1013
    integration.e2e.spec.ts
    Refactor integration tests to use slugs and improve coverage

    apps/api/src/integration/integration.e2e.spec.ts

  • Updated imports and refactored test cases to use slug instead of id.
  • Added new test cases for integration operations using slug.
  • Grouped related test cases into describe blocks for better
    organization.
  • Enhanced test coverage for integration-related events and operations.
  • +468/-456
    project.e2e.spec.ts
    Refactor E2E Tests to Use Slugs for Projects and Workspaces

    apps/api/src/project/project.e2e.spec.ts

  • Updated test cases to use workspaceSlug and projectSlug instead of
    IDs.
  • Added new test cases for slug-based project operations.
  • Refactored tests into descriptive sections for better organization.
  • Introduced checks for slug existence and uniqueness.
  • +534/-522
    secret.e2e.spec.ts
    Refactor E2E Tests to Use Slugs for Secrets and Environments

    apps/api/src/secret/secret.e2e.spec.ts

  • Updated test cases to use workspaceSlug, projectSlug, and
    environmentSlug.
  • Refactored tests into descriptive sections for better organization.
  • Added new test cases for slug-based secret operations.
  • Introduced checks for slug existence and uniqueness.
  • +704/-693
    workspace-role.e2e.spec.ts
    Refactor workspace role tests to use slugs                             

    apps/api/src/workspace-role/workspace-role.e2e.spec.ts

  • Updated test cases to use slug instead of id for workspace roles.
  • Refactored test descriptions for better organization and readability.
  • Added new test cases for scenarios involving slugs.
  • Modified imports to reflect new file paths.
  • +668/-613
    variable.e2e.spec.ts
    Refactor variable tests to use slugs                                         

    apps/api/src/variable/variable.e2e.spec.ts

  • Updated test cases to use slug instead of id for variables and
    projects.
  • Refactored test descriptions and organized them into describe blocks.
  • Added new test cases for scenarios involving slugs.
  • Modified imports to reflect new file paths.
  • +572/-559
    Enhancement
    6 files
    authority-checker.service.ts
    Update authority checks to use slugs for entities               

    apps/api/src/common/authority-checker.service.ts

  • Updated authority checks to use slug instead of id.
  • Refactored imports for collective authority functions.
  • Improved error messages to reflect slug usage.
  • +35/-27 
    event.controller.ts
    Update event controller to use workspace slugs                     

    apps/api/src/event/controller/event.controller.ts

  • Changed event retrieval to use workspaceSlug instead of workspaceId.
  • Updated parameter names and annotations to reflect slug usage.
  • +3/-3     
    project.service.ts
    Implement Slug-Based Operations and Refactor Project Service

    apps/api/src/project/service/project.service.ts

  • Replaced ID-based operations with slug-based operations for projects
    and workspaces.
  • Added slug generation for projects, environments, and other entities.
  • Refactored authority checks to use slugs.
  • Improved utility imports and organized code structure.
  • +101/-75
    workspace.service.ts
    Update workspace service to use slugs                                       

    apps/api/src/workspace/service/workspace.service.ts

  • Replaced usage of id with slug for workspace operations.
  • Added slug generation for workspaces during updates.
  • Updated method signatures to accept slugs instead of ids.
  • Refactored imports to reflect new file paths.
  • +204/-186
    environment.service.ts
    Update environment service to use slugs                                   

    apps/api/src/environment/service/environment.service.ts

  • Replaced usage of id with slug for environment operations.
  • Added slug generation for environments during creation and updates.
  • Updated method signatures to accept slugs instead of ids.
  • Refactored imports to reflect new file paths.
  • +43/-27 
    create-workspace-role.ts
    Update DTO to use project slugs                                                   

    apps/api/src/workspace-role/dto/create-workspace-role/create-workspace-role.ts

  • Changed projectIds to projectSlugs in the CreateWorkspaceRole DTO.
  • +1/-1     
    Documentation
    1 files
    paginate.ts
    Add documentation to paginate function                                     

    apps/api/src/common/paginate.ts

  • Added JSDoc comments for the paginate function.
  • Corrected a typo in a comment within the paginate function.
  • +9/-1     
    Additional files (token-limit)
    47 files
    environment.e2e.spec.ts
    ...                                                                                                           

    apps/api/src/environment/environment.e2e.spec.ts

    ...

    +349/-315
    event.e2e.spec.ts
    ...                                                                                                           

    apps/api/src/event/event.e2e.spec.ts

    ...

    +176/-103
    api-key.e2e.spec.ts
    ...                                                                                                           

    apps/api/src/api-key/api-key.e2e.spec.ts

    ...

    +272/-238
    secret.service.ts
    ...                                                                                                           

    apps/api/src/secret/service/secret.service.ts

    ...

    +117/-101
    variable.service.ts
    ...                                                                                                           

    apps/api/src/variable/service/variable.service.ts

    ...

    +113/-104
    integration.service.ts
    ...                                                                                                           

    apps/api/src/integration/service/integration.service.ts

    ...

    +76/-61 
    workspace-role.service.ts
    ...                                                                                                           

    apps/api/src/workspace-role/service/workspace-role.service.ts

    ...

    +83/-51 
    workspace.controller.ts
    ...                                                                                                           

    apps/api/src/workspace/controller/workspace.controller.ts

    ...

    +63/-55 
    api-key.service.ts
    ...                                                                                                           

    apps/api/src/api-key/service/api-key.service.ts

    ...

    +34/-38 
    slug-generator.ts
    ...                                                                                                           

    apps/api/src/common/slug-generator.ts

    ...

    +150/-0 
    project.controller.ts
    ...                                                                                                           

    apps/api/src/project/controller/project.controller.ts

    ...

    +27/-27 
    secret.controller.ts
    ...                                                                                                           

    apps/api/src/secret/controller/secret.controller.ts

    ...

    +28/-28 
    variable.controller.ts
    ...                                                                                                           

    apps/api/src/variable/controller/variable.controller.ts

    ...

    +27/-27 
    integration.controller.ts
    ...                                                                                                           

    apps/api/src/integration/controller/integration.controller.ts

    ...

    +18/-15 
    util.ts
    ...                                                                                                           

    apps/api/src/common/util.ts

    ...

    +105/-0 
    environment.controller.ts
    ...                                                                                                           

    apps/api/src/environment/controller/environment.controller.ts

    ...

    +22/-15 
    workspace-role.controller.ts
    ...                                                                                                           

    apps/api/src/workspace-role/controller/workspace-role.controller.ts

    ...

    +18/-18 
    environment.ts
    ...                                                                                                           

    apps/api/src/common/environment.ts

    ...

    +62/-2   
    collective-authorities.ts
    ...                                                                                                           

    apps/api/src/common/collective-authorities.ts

    ...

    +95/-0   
    event.service.ts
    ...                                                                                                           

    apps/api/src/event/service/event.service.ts

    ...

    +18/-10 
    user.ts
    ...                                                                                                           

    apps/api/src/common/user.ts

    ...

    +76/-0   
    change-notifier.socket.ts
    ...                                                                                                           

    apps/api/src/socket/change-notifier.socket.ts

    ...

    +25/-40 
    cryptography.ts
    ...                                                                                                           

    apps/api/src/common/cryptography.ts

    ...

    +83/-0   
    api-key.controller.ts
    ...                                                                                                           

    apps/api/src/api-key/controller/api-key.controller.ts

    ...

    +15/-9   
    event.ts
    ...                                                                                                           

    apps/api/src/common/event.ts

    ...

    +42/-4   
    cryptography.spec.ts
    ...                                                                                                           

    apps/api/src/common/cryptography.spec.ts

    ...

    +59/-0   
    workspace.ts
    ...                                                                                                           

    apps/api/src/common/workspace.ts

    ...

    +22/-5   
    util.spec.ts
    ...                                                                                                           

    apps/api/src/common/util.spec.ts

    ...

    +2/-40   
    user.service.ts
    ...                                                                                                           

    apps/api/src/user/service/user.service.ts

    ...

    +10/-5   
    auth.guard.ts
    ...                                                                                                           

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

    ...

    +3/-3     
    user.controller.spec.ts
    ...                                                                                                           

    apps/api/src/user/controller/user.controller.spec.ts

    ...

    +5/-1     
    query.transform.pipe.ts
    ...                                                                                                           

    apps/api/src/common/pipes/query.transform.pipe.ts

    ...

    +19/-1   
    user.service.spec.ts
    ...                                                                                                           

    apps/api/src/user/service/user.service.spec.ts

    ...

    +5/-1     
    feedback.e2e.spec.ts
    ...                                                                                                           

    apps/api/src/feedback/feedback.e2e.spec.ts

    ...

    +2/-2     
    auth.service.ts
    ...                                                                                                           

    apps/api/src/auth/service/auth.service.ts

    ...

    +2/-2     
    create.integration.ts
    ...                                                                                                           

    apps/api/src/integration/dto/create.integration/create.integration.ts

    ...

    +2/-2     
    auth.controller.ts
    ...                                                                                                           

    apps/api/src/auth/controller/auth.controller.ts

    ...

    +1/-1     
    main.ts
    ...                                                                                                           

    apps/api/src/main.ts

    ...

    +1/-1     
    socket.types.ts
    ...                                                                                                           

    apps/api/src/socket/socket.types.ts

    ...

    +3/-9     
    integration.types.ts
    ...                                                                                                           

    apps/api/src/integration/integration.types.ts

    ...

    +4/-0     
    fork.project.ts
    ...                                                                                                           

    apps/api/src/project/dto/fork.project/fork.project.ts

    ...

    +1/-1     
    query.transform.pipe.spec.ts
    ...                                                                                                           

    apps/api/src/common/pipes/query.transform.pipe.spec.ts

    ...

    +8/-1     
    create.secret.ts
    ...                                                                                                           

    apps/api/src/secret/dto/create.secret/create.secret.ts

    ...

    +1/-1     
    create.variable.ts
    ...                                                                                                           

    apps/api/src/variable/dto/create.variable/create.variable.ts

    ...

    +1/-1     
    create.workspace.ts
    ...                                                                                                           

    apps/api/src/workspace/dto/create.workspace/create.workspace.ts

    ...

    +1/-1     
    migration.sql
    ...                                                                                                           

    apps/api/src/prisma/migrations/20240908063241_add_slug/migration.sql

    ...

    +68/-0   
    schema.prisma
    ...                                                                                                           

    apps/api/src/prisma/schema.prisma

    ...

    +21/-13 

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

    @keyshade-xyz keyshade-xyz deleted a comment from codiumai-pr-agent-free bot Sep 9, 2024
    @keyshade-xyz keyshade-xyz deleted a comment from codiumai-pr-agent-free bot Sep 9, 2024
    @keyshade-xyz keyshade-xyz deleted a comment from codecov bot Sep 9, 2024
    Copy link

    codecov bot commented Sep 9, 2024

    Codecov Report

    Attention: Patch coverage is 94.53861% with 29 lines in your changes missing coverage. Please review.

    Project coverage is 87.77%. Comparing base (ce50743) to head (a9f4373).
    Report is 150 commits behind head on develop.

    Files with missing lines Patch % Lines
    apps/api/src/socket/change-notifier.socket.ts 0.00% 9 Missing ⚠️
    apps/api/src/common/slug-generator.ts 88.05% 8 Missing ⚠️
    apps/api/src/common/util.ts 78.26% 5 Missing ⚠️
    apps/api/src/common/environment.ts 86.66% 2 Missing ⚠️
    ...pps/api/src/workspace/service/workspace.service.ts 96.72% 2 Missing ⚠️
    apps/api/src/api-key/service/api-key.service.ts 92.30% 1 Missing ⚠️
    apps/api/src/common/user.ts 95.23% 1 Missing ⚠️
    ...api/src/environment/service/environment.service.ts 94.11% 1 Missing ⚠️
    Additional details and impacted files
    @@             Coverage Diff             @@
    ##           develop     #415      +/-   ##
    ===========================================
    - Coverage    91.71%   87.77%   -3.94%     
    ===========================================
      Files          111      102       -9     
      Lines         2510     2635     +125     
      Branches       469      401      -68     
    ===========================================
    + Hits          2302     2313      +11     
    - Misses         208      322     +114     
    Flag Coverage Δ
    api-e2e-tests 87.77% <94.53%> (-3.94%) ⬇️

    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
    Contributor

    CI Failure Feedback 🧐

    Action: Validate Cli

    Failed stage: Build [❌]

    Failure summary:

    The action failed due to a TypeScript compilation error:

  • In the file src/commands/environment/get.environment.ts at line 48, column 37, the code attempted to
    access a property getEnvironmentById on the type EnvironmentController.
  • The property getEnvironmentById does not exist on EnvironmentController. The error message suggests
    that the intended property might be getEnvironment.
  • This caused the TypeScript compiler (tsc) to exit with code 2, leading to the failure of the build
    command.

  • Relevant error logs:
    1:  ##[group]Operating System
    2:  Ubuntu
    ...
    
    273:  > tsc && tsc-alias
    274:  ##[endgroup]
    275:  Tasks:    1 successful, 1 total
    276:  Cached:    0 cached, 1 total
    277:  Time:    2.319s 
    278:  • Packages in scope: cli
    279:  • Running build in 1 packages
    280:  • Remote caching disabled
    281:  ##[error]cli#build: command (/home/runner/work/keyshade/keyshade/apps/cli) /home/runner/setup-pnpm/node_modules/.bin/pnpm run build exited (2)
    282:  �[;31mcli:build�[;0m
    283:  cache miss, executing 620fe2664ae7dba2
    284:  > cli@1.0.0 build /home/runner/work/keyshade/keyshade/apps/cli
    285:  > tsc && tsc-alias
    286:  ##[error]src/commands/environment/get.environment.ts(48,37): error TS2551: Property 'getEnvironmentById' does not exist on type 'EnvironmentController'. Did you mean 'getEnvironment'?
    287:  ELIFECYCLE  Command failed with exit code 2.
    288:  [ERROR] command finished with error: command (/home/runner/work/keyshade/keyshade/apps/cli) /home/runner/setup-pnpm/node_modules/.bin/pnpm run build exited (2)
    289:  Tasks:    0 successful, 1 total
    290:  Cached:    0 cached, 1 total
    291:  Time:    2.138s 
    292:  Failed:    cli#build
    293:  ERROR  run failed: command  exited (2)
    294:  ELIFECYCLE  Command failed with exit code 2.
    295:  ##[error]Process completed with exit code 2.
    

    ✨ CI feedback usage guide:

    The CI feedback tool (/checks) automatically triggers when a PR has a failed check.
    The tool analyzes the failed checks and provides several feedbacks:

    • Failed stage
    • Failed test name
    • Failure summary
    • Relevant error logs

    In addition to being automatically triggered, the tool can also be invoked manually by commenting on a PR:

    /checks "https://github.com/{repo_name}/actions/runs/{run_number}/job/{job_number}"
    

    where {repo_name} is the name of the repository, {run_number} is the run number of the failed check, and {job_number} is the job number of the failed check.

    Configuration options

    • enable_auto_checks_feedback - if set to true, the tool will automatically provide feedback when a check is failed. Default is true.
    • excluded_checks_list - a list of checks to exclude from the feedback, for example: ["check1", "check2"]. Default is an empty list.
    • enable_help_text - if set to true, the tool will provide a help message with the feedback. Default is true.
    • persistent_comment - if set to true, the tool will overwrite a previous checks comment with the new feedback. Default is true.
    • final_update_message - if persistent_comment is true and updating a previous checks message, the tool will also create a new message: "Persistent checks updated to latest commit". Default is true.

    See more information about the checks tool in the docs.

    @rajdip-b rajdip-b merged commit 89e2fcc into develop Sep 9, 2024
    6 checks passed
    @rajdip-b rajdip-b deleted the feat/add-slug-in-entities branch September 9, 2024 14:31
    rajdip-b pushed a commit that referenced this pull request Sep 16, 2024
    ## [2.5.0](v2.4.0...v2.5.0) (2024-09-16)
    
    ### 🚀 Features
    
    * **api-client:** Added workspace controller ([#427](#427)) ([2f4edec](2f4edec))
    * **api-client:** Added workspace role controller ([#430](#430)) ([b03ce8e](b03ce8e))
    * **api-client:** Synced with latest API ([27f4309](27f4309))
    * **api:** Add slug in entities ([#415](#415)) ([89e2fcc](89e2fcc))
    * **api:** Included default workspace details in getSelf function ([#414](#414)) ([e67bbd6](e67bbd6))
    * **platform:** Add loading skeleton in the [secure]s page ([#423](#423)) ([a97681e](a97681e))
    * **schema:** Added a schema package ([01ea232](01ea232))
    * **web:** Update about and careers page ([e167f53](e167f53))
    
    ### 🐛 Bug Fixes
    
    * **api:** Error messages fixed in api-key service ([#418](#418)) ([edfbce0](edfbce0))
    
    ### 📚 Documentation
    
    * Fixed minor typo in postman workspace link ([#411](#411)) ([ed23116](ed23116))
    * Updated Postman links ([444bfb1](444bfb1))
    
    ### 🔧 Miscellaneous Chores
    
    * **api:** Suppressed version check test in [secure] ([4688e8c](4688e8c))
    * **api:** Update slug generation method ([#420](#420)) ([1f864df](1f864df))
    
    ### 🔨 Code Refactoring
    
    * **API:** Refactor workspace-membership into a separate module ([#421](#421)) ([574170f](574170f))
    * **platform:** added optional chaining due to strict null check ([#413](#413)) ([907e369](907e369))
    @rajdip-b
    Copy link
    Member Author

    🎉 This PR is included in version 2.5.0 🎉

    The release is available on GitHub release

    Your semantic-release bot 📦🚀

    Kiranchaudhary537 pushed a commit to Kiranchaudhary537/keyshade that referenced this pull request Oct 13, 2024
    Kiranchaudhary537 pushed a commit to Kiranchaudhary537/keyshade that referenced this pull request Oct 13, 2024
    ## [2.5.0](keyshade-xyz/keyshade@v2.4.0...v2.5.0) (2024-09-16)
    
    ### 🚀 Features
    
    * **api-client:** Added workspace controller ([keyshade-xyz#427](keyshade-xyz#427)) ([2f4edec](keyshade-xyz@2f4edec))
    * **api-client:** Added workspace role controller ([keyshade-xyz#430](keyshade-xyz#430)) ([b03ce8e](keyshade-xyz@b03ce8e))
    * **api-client:** Synced with latest API ([27f4309](keyshade-xyz@27f4309))
    * **api:** Add slug in entities ([keyshade-xyz#415](keyshade-xyz#415)) ([89e2fcc](keyshade-xyz@89e2fcc))
    * **api:** Included default workspace details in getSelf function ([keyshade-xyz#414](keyshade-xyz#414)) ([e67bbd6](keyshade-xyz@e67bbd6))
    * **platform:** Add loading skeleton in the [secure]s page ([keyshade-xyz#423](keyshade-xyz#423)) ([a97681e](keyshade-xyz@a97681e))
    * **schema:** Added a schema package ([01ea232](keyshade-xyz@01ea232))
    * **web:** Update about and careers page ([e167f53](keyshade-xyz@e167f53))
    
    ### 🐛 Bug Fixes
    
    * **api:** Error messages fixed in api-key service ([keyshade-xyz#418](keyshade-xyz#418)) ([edfbce0](keyshade-xyz@edfbce0))
    
    ### 📚 Documentation
    
    * Fixed minor typo in postman workspace link ([keyshade-xyz#411](keyshade-xyz#411)) ([ed23116](keyshade-xyz@ed23116))
    * Updated Postman links ([444bfb1](keyshade-xyz@444bfb1))
    
    ### 🔧 Miscellaneous Chores
    
    * **api:** Suppressed version check test in [secure] ([4688e8c](keyshade-xyz@4688e8c))
    * **api:** Update slug generation method ([keyshade-xyz#420](keyshade-xyz#420)) ([1f864df](keyshade-xyz@1f864df))
    
    ### 🔨 Code Refactoring
    
    * **API:** Refactor workspace-membership into a separate module ([keyshade-xyz#421](keyshade-xyz#421)) ([574170f](keyshade-xyz@574170f))
    * **platform:** added optional chaining due to strict null check ([keyshade-xyz#413](keyshade-xyz#413)) ([907e369](keyshade-xyz@907e369))
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant