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
212 stars 105 forks source link

feat(schema, api-client): Migrate event schemas and types to @keyshade/schema #546

Closed muntaxir4 closed 4 days ago

muntaxir4 commented 5 days ago

User description

Description

@keyshade/schema

@keyshade/api-client

Related to #519

Developer's checklist

If changes are made in the code:

Documentation Update


PR Type

enhancement, tests


Description


Changes walkthrough πŸ“

Relevant files
Enhancement
8 files
event.ts
Update event type imports to use schema package                   

packages/api-client/src/controllers/event.ts - Updated imports for event types to use `@keyshade/schema`.
+1/-4     
event.types.d.ts
Remove deprecated event types file                                             

packages/api-client/src/types/event.types.d.ts
  • Removed the entire file as event types are now in @keyshade/schema.
  • +0/-82   
    enums.ts
    Add event-related enums                                                                   

    packages/schema/src/enums.ts - Added enums for event source, triggerer, and severity.
    +14/-0   
    index.ts
    Add event schemas using zod                                                           

    packages/schema/src/event/index.ts
  • Created schemas for GetEventsRequest and GetEventsResponse.
  • Utilized new event enums in schemas.
  • +40/-0   
    index.types.ts
    Define event types using zod inference                                     

    packages/schema/src/event/index.types.ts
  • Defined types for GetEventsRequest and GetEventsResponse using zod
    inference.
  • +6/-0     
    index.ts
    Export event schemas from index                                                   

    packages/schema/src/index.ts - Exported event schemas from the main index file.
    +1/-0     
    index.types.ts
    Export event types from index types                                           

    packages/schema/src/index.types.ts - Exported event types from the main index types file.
    +1/-0     
    index.ts
    Use project access level enum in schema                                   

    packages/schema/src/project/index.ts - Updated `ProjectSchema` to use `projectAccessLevelEnum`.
    +1/-1     
    Tests
    3 files
    enums.test.ts
    Add tests for event enums                                                               

    packages/schema/tests/enums.test.ts - Added tests for event-related enums.
    +149/-0 
    event.spec.ts
    Add tests for event schemas                                                           

    packages/schema/tests/event.spec.ts
  • Added tests for GetEventsRequestSchema and GetEventsResponseSchema.
  • +128/-0 
    project.spec.ts
    Update project schema tests for access level enum               

    packages/schema/tests/project.spec.ts - Updated tests to reflect changes in `ProjectSchema` access level.
    +8/-8     
    Configuration changes
    1 files
    package.json
    Update main entry point in package.json                                   

    packages/schema/package.json - Changed main entry point to `dist/src/index.types.js`.
    +1/-1     

    πŸ’‘ PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    codiumai-pr-agent-free[bot] commented 5 days ago

    PR Reviewer Guide πŸ”

    Here are some key observations to aid the review process:

    **🎫 Ticket compliance analysis βœ…** **[519](https://github.com/keyshade-xyz/keyshade/issues/519) - Fully compliant** Compliant requirements: - Created event folder with required files in schema package - Added zod schemas and types for event module - Updated exports in index files - Updated api-client to use types from schema
    ⏱️ Estimated effort to review: 2 πŸ”΅πŸ”΅βšͺβšͺβšͺ
    πŸ§ͺ PR contains tests
    πŸ”’ No security concerns identified
    ⚑ Recommended focus areas for review

    Code Smell
    The metadata object in GetEventsResponseSchema has many optional fields which could indicate a design that's not fully normalized or consistent
    codiumai-pr-agent-free[bot] commented 5 days ago

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    General
    Enforce proper date-time format validation for timestamp fields ___ **Add validation for the timestamp field to ensure it's a valid ISO 8601 date string
    using z.string().datetime() instead of z.string()** [packages/schema/src/event/index.ts [23]](https://github.com/keyshade-xyz/keyshade/pull/546/files#diff-1b98dc2071de1bad81f6136c16d3d19d4f58c7323e1acf8dd9bea4a6475888bfR23-R23) ```diff -timestamp: z.string(), +timestamp: z.string().datetime(), ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: Using z.string().datetime() ensures timestamp values are valid ISO 8601 dates, preventing potential runtime errors from invalid date formats. This is crucial for data integrity and system reliability.
    8
    Add proper validation for slug format fields ___ **Add refinement validation to ensure workspaceSlug is not empty and follows a valid
    slug format using z.string().min(1).regex()** [packages/schema/src/event/index.ts [11]](https://github.com/keyshade-xyz/keyshade/pull/546/files#diff-1b98dc2071de1bad81f6136c16d3d19d4f58c7323e1acf8dd9bea4a6475888bfR11-R11) ```diff -workspaceSlug: z.string(), +workspaceSlug: z.string().min(1).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/), ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: Adding regex validation for workspaceSlug ensures proper slug format and prevents invalid characters, enhancing data validation and URL compatibility.
    7
    Prevent unwanted whitespace in string fields ___ **Add .trim() validation to string fields that shouldn't contain leading/trailing
    whitespace** [packages/schema/src/event/index.ts [34-35]](https://github.com/keyshade-xyz/keyshade/pull/546/files#diff-1b98dc2071de1bad81f6136c16d3d19d4f58c7323e1acf8dd9bea4a6475888bfR34-R35) ```diff -title: z.string(), -description: z.string(), +title: z.string().trim(), +description: z.string().trim(), ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 5 Why: Adding .trim() validation helps maintain data cleanliness by removing unwanted whitespace from user input, improving data consistency and user experience.
    5

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

    muntaxir4 commented 5 days ago

    Fixed ProjectSchema issues. This could be used in #540