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(schema, api-client): Migrate event schemas and types to @keyshade/schema #546

Merged
merged 2 commits into from
Nov 22, 2024

Conversation

muntaxir4
Copy link
Contributor

@muntaxir4 muntaxir4 commented Nov 20, 2024

User description

Description

@keyshade/schema

  • Add schemas, types and enums for event.
  • Add tests for event schemas.
  • Export event schemas from index and its types from index.types
  • Modify ProjectSchema to use accessLevelEnum
  • Add simple tests for enums.ts.
  • Change "main": "dist/src/index.js" to "main": "dist/src/index.types.js" in package.json due to default export being index.types.ts.

@keyshade/api-client

  • Remove existing event.types.d.ts.
  • Change imports for event types to @keyshade/schema.

Related to #519

Developer's checklist

  • My PR follows the style guidelines of this project
  • I have performed a self-check on my work

If changes are made in the code:

  • I have followed the coding guidelines
  • My changes in code generate no new warnings
  • My changes are breaking another fix/feature of the project
  • I have added test cases to show that my feature works
  • I have added relevant screenshots in my PR
  • There are no UI/UX issues

Documentation Update

  • This PR requires an update to the documentation at docs.keyshade.xyz
  • I have made the necessary updates to the documentation, or no documentation changes are required.

PR Type

enhancement, tests


Description

  • Migrated event schemas and types from api-client to @keyshade/schema.
  • Added new enums for event sources, triggerers, and severities.
  • Created and exported event schemas and types using zod in the schema package.
  • Updated ProjectSchema to use projectAccessLevelEnum.
  • Added tests for the new event schemas and enums.
  • Updated package.json to reflect changes in the main entry point.

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

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis ✅

    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

    Copy link
    Contributor

    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]

    -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]

    -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]

    -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
    Copy link
    Contributor Author

    Fixed ProjectSchema issues. This could be used in #540

    @muntaxir4 muntaxir4 requested a review from rajdip-b November 20, 2024 23:14
    @rajdip-b rajdip-b merged commit a3267de into keyshade-xyz:develop Nov 22, 2024
    7 checks passed
    @muntaxir4 muntaxir4 deleted the event-schemas branch November 23, 2024 21:16
    rajdip-b pushed a commit that referenced this pull request Dec 3, 2024
    ## [2.8.0](v2.7.0...v2.8.0) (2024-12-03)
    
    ### 🚀 Features
    
    * **api:** Add workspace removal notification email template ([#476](#476)) ([40b754f](40b754f))
    * **cli:** Store `metrics_enabled` key in profile config ([#536](#536)) ([9283b22](9283b22))
    * **package, api, cli:** Add api-key schemas and types; Fix schema inconsistencies; Minor fix for CLI build errors  ([#557](#557)) ([126d024](126d024))
    * **platform:** Added screen for CREATE NEW PROJECT ([#540](#540)) ([b644633](b644633))
    * **platform:** Updated the empty state of dashboard ([#522](#522)) ([28739d9](28739d9))
    * **schema, api-client:** Migrate auth types to @keyshade/schema ([#532](#532)) ([d880098](d880098))
    * **schema, api-client:** Migrate event schemas and types to @keyshade/schema ([#546](#546)) ([a3267de](a3267de))
    * **schema, api-client:** Migrate integration schemas and types to @keyshade/schema ([#547](#547)) ([08868c3](08868c3))
    * **schema, api-client:** Migrate project schemas and environment schemas along with their types to @keyshade/schema ([#538](#538)) ([c468af0](c468af0))
    * **schema, api-client:** Migrate [secure] types and schemas to @keyshade/schema ([#539](#539)) ([bc3100b](bc3100b))
    * **schema, api-client:** Migrate user types and schemas to @keyshade/schema ([#535](#535)) ([c24695e](c24695e))
    * **schema, api-client:** Migrate variable schemas and types to @keyshade/schema ([#545](#545)) ([0ee8f9a](0ee8f9a))
    * **schema, api-client:** Migrate workspace-membership schemas and types to @keyshade/schema ([#569](#569)) ([4398969](4398969))
    * **schema, api-client:** Migrate workspace-role schemas and types to @keyshade/schema ([#568](#568)) ([9efbf2d](9efbf2d))
    * **schema:** Add User type inference from UserSchema ([#574](#574)) ([84c1db5](84c1db5))
    
    ### 🐛 Bug Fixes
    
    * **api:** Incorrect oauth redirect url ([58d96e5](58d96e5))
    * **platform:** Resolve loading SVG blocking input field interaction ([#571](#571)) ([30f4f65](30f4f65))
    
    ### 📚 Documentation
    
    * Add pictures to Bruno setup ([#541](#541)) ([210c0fd](210c0fd))
    * Migrate to Bruno ([#525](#525)) ([1793d92](1793d92))
    
    ### 🔧 Miscellaneous Chores
    
    * **ci:** Add script to validate schema package ([59e4280](59e4280))
    * Fixed codecov client version ([a998ae4](a998ae4))
    * **package:** Fixed tests and did housekeeping ([#544](#544)) ([40008e3](40008e3))
    * Update test coverage settings ([5b27e32](5b27e32))
    * Update Turbo to 2.3.1 ([#564](#564)) ([3a63823](3a63823))
    * **web:** Update dockerfile ([10d9cc5](10d9cc5))
    
    ### 🔨 Code Refactoring
    
    * **api-client, schema:** Add workspace's schemas and types in @keyshade/schema ([#520](#520)) ([7c8ee5d](7c8ee5d))
    muntaxir4 pushed a commit to muntaxir4/keyshade that referenced this pull request Jan 1, 2025
    ## [2.8.0](keyshade-xyz/keyshade@v2.7.0...v2.8.0) (2024-12-03)
    
    ### 🚀 Features
    
    * **api:** Add workspace removal notification email template ([keyshade-xyz#476](keyshade-xyz#476)) ([40b754f](keyshade-xyz@40b754f))
    * **cli:** Store `metrics_enabled` key in profile config ([keyshade-xyz#536](keyshade-xyz#536)) ([9283b22](keyshade-xyz@9283b22))
    * **package, api, cli:** Add api-key schemas and types; Fix schema inconsistencies; Minor fix for CLI build errors  ([keyshade-xyz#557](keyshade-xyz#557)) ([126d024](keyshade-xyz@126d024))
    * **platform:** Added screen for CREATE NEW PROJECT ([keyshade-xyz#540](keyshade-xyz#540)) ([b644633](keyshade-xyz@b644633))
    * **platform:** Updated the empty state of dashboard ([keyshade-xyz#522](keyshade-xyz#522)) ([28739d9](keyshade-xyz@28739d9))
    * **schema, api-client:** Migrate auth types to @keyshade/schema ([keyshade-xyz#532](keyshade-xyz#532)) ([d880098](keyshade-xyz@d880098))
    * **schema, api-client:** Migrate event schemas and types to @keyshade/schema ([keyshade-xyz#546](keyshade-xyz#546)) ([a3267de](keyshade-xyz@a3267de))
    * **schema, api-client:** Migrate integration schemas and types to @keyshade/schema ([keyshade-xyz#547](keyshade-xyz#547)) ([08868c3](keyshade-xyz@08868c3))
    * **schema, api-client:** Migrate project schemas and environment schemas along with their types to @keyshade/schema ([keyshade-xyz#538](keyshade-xyz#538)) ([c468af0](keyshade-xyz@c468af0))
    * **schema, api-client:** Migrate [secure] types and schemas to @keyshade/schema ([keyshade-xyz#539](keyshade-xyz#539)) ([bc3100b](keyshade-xyz@bc3100b))
    * **schema, api-client:** Migrate user types and schemas to @keyshade/schema ([keyshade-xyz#535](keyshade-xyz#535)) ([c24695e](keyshade-xyz@c24695e))
    * **schema, api-client:** Migrate variable schemas and types to @keyshade/schema ([keyshade-xyz#545](keyshade-xyz#545)) ([0ee8f9a](keyshade-xyz@0ee8f9a))
    * **schema, api-client:** Migrate workspace-membership schemas and types to @keyshade/schema ([keyshade-xyz#569](keyshade-xyz#569)) ([4398969](keyshade-xyz@4398969))
    * **schema, api-client:** Migrate workspace-role schemas and types to @keyshade/schema ([keyshade-xyz#568](keyshade-xyz#568)) ([9efbf2d](keyshade-xyz@9efbf2d))
    * **schema:** Add User type inference from UserSchema ([keyshade-xyz#574](keyshade-xyz#574)) ([84c1db5](keyshade-xyz@84c1db5))
    
    ### 🐛 Bug Fixes
    
    * **api:** Incorrect oauth redirect url ([58d96e5](keyshade-xyz@58d96e5))
    * **platform:** Resolve loading SVG blocking input field interaction ([keyshade-xyz#571](keyshade-xyz#571)) ([30f4f65](keyshade-xyz@30f4f65))
    
    ### 📚 Documentation
    
    * Add pictures to Bruno setup ([keyshade-xyz#541](keyshade-xyz#541)) ([210c0fd](keyshade-xyz@210c0fd))
    * Migrate to Bruno ([keyshade-xyz#525](keyshade-xyz#525)) ([1793d92](keyshade-xyz@1793d92))
    
    ### 🔧 Miscellaneous Chores
    
    * **ci:** Add script to validate schema package ([59e4280](keyshade-xyz@59e4280))
    * Fixed codecov client version ([a998ae4](keyshade-xyz@a998ae4))
    * **package:** Fixed tests and did housekeeping ([keyshade-xyz#544](keyshade-xyz#544)) ([40008e3](keyshade-xyz@40008e3))
    * Update test coverage settings ([5b27e32](keyshade-xyz@5b27e32))
    * Update Turbo to 2.3.1 ([keyshade-xyz#564](keyshade-xyz#564)) ([3a63823](keyshade-xyz@3a63823))
    * **web:** Update dockerfile ([10d9cc5](keyshade-xyz@10d9cc5))
    
    ### 🔨 Code Refactoring
    
    * **api-client, schema:** Add workspace's schemas and types in @keyshade/schema ([keyshade-xyz#520](keyshade-xyz#520)) ([7c8ee5d](keyshade-xyz@7c8ee5d))
    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.

    2 participants