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): Add api-key schemas and types #557

Open muntaxir4 opened 14 hours ago

muntaxir4 commented 14 hours ago

User description

Description

@keyshade/schema

@keyshade/schema

Related to #519

Future Improvements

The GetApiKeysOfUserResponseSchema could be changed to extend PageResponse once the API returns paginated response for this.

Developer's checklist

If changes are made in the code:

Documentation Update


PR Type

Enhancement, Tests


Description


Changes walkthrough 📝

Relevant files
Enhancement
index.ts
Add comprehensive API key schemas and transformations       

packages/schema/src/api-key/index.ts
  • Added comprehensive API key schemas using zod.
  • Defined request and response schemas for API key operations.
  • Included transformations for date fields.
  • +64/-0   
    index.types.ts
    Define and export API key types                                                   

    packages/schema/src/api-key/index.types.ts
  • Defined TypeScript types inferred from API key schemas.
  • Exported types for API key operations.
  • +50/-0   
    index.ts
    Export API key schemas from index                                               

    packages/schema/src/index.ts - Exported API key schemas from the main index file.
    +2/-1     
    index.types.ts
    Export API key types from index.types                                       

    packages/schema/src/index.types.ts - Exported API key types from the main index types file.
    +1/-4     
    Tests
    api-key.spec.ts
    Add tests for API key schemas                                                       

    packages/schema/tests/api-key.spec.ts
  • Added tests for API key schemas.
  • Validated both valid and invalid cases for each schema.
  • +292/-8 
    Configuration changes
    tsconfig.json
    Update tsconfig base path                                                               

    packages/schema/tsconfig.json - Modified the path for extending base tsconfig.
    +1/-1     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    codiumai-pr-agent-free[bot] commented 14 hours 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) - Partially compliant** Compliant requirements: - Created api-key folder with index.ts and index.types.ts - Added zod schemas for API key base type, requests and responses - Added type exports - Exported schemas and types from main index files Non-compliant requirements: - No evidence of api-client package updates to use the new schema types
    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Data Validation
    The date transformations in ApiKeySchema may lose timezone information when converting to ISO string. Consider preserving timezone data. Code Design
    GetApiKeysOfUserResponseSchema does not implement pagination which may cause performance issues with large datasets
    codiumai-pr-agent-free[bot] commented 14 hours ago

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Security
    Enforce minimum length requirement for API key values to maintain security standards ___ **Add validation for minimum length of API key value to ensure security. A minimum
    length of 32 characters is recommended for API keys.** [packages/schema/src/api-key/index.ts [9]](https://github.com/keyshade-xyz/keyshade/pull/557/files#diff-eb680e1da49b1fb5b8806fe44f2a7cafcbef3240be6a1ea689f865b58bb363ecR9-R9) ```diff -value: z.string(), +value: z.string().min(32), ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 9 Why: Adding minimum length validation for API keys is crucial for security, as it helps prevent weak or easily guessable keys. This is a critical security enhancement.
    9
    General
    Enforce URL-safe format for identifier fields ___ **Add validation for slug field to ensure it follows URL-safe format using regex
    pattern.** [packages/schema/src/api-key/index.ts [8]](https://github.com/keyshade-xyz/keyshade/pull/557/files#diff-eb680e1da49b1fb5b8806fe44f2a7cafcbef3240be6a1ea689f865b58bb363ecR8-R8) ```diff -slug: z.string(), +slug: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/), ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: Adding regex validation for the slug field ensures consistent, URL-safe formatting, preventing potential issues in API endpoints and improving system reliability.
    7
    Add length constraints to string fields to prevent invalid data ___ **Add validation for name field to prevent empty strings and enforce reasonable length
    limits.** [packages/schema/src/api-key/index.ts [7]](https://github.com/keyshade-xyz/keyshade/pull/557/files#diff-eb680e1da49b1fb5b8806fe44f2a7cafcbef3240be6a1ea689f865b58bb363ecR7-R7) ```diff -name: z.string(), +name: z.string().min(1).max(100), ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 6 Why: Adding length constraints to the name field prevents empty or excessively long values, improving data quality and user experience.
    6

    💡 Need additional feedback ? start a PR chat

    muntaxir4 commented 14 hours ago

    I will try to modify the date types for previously implemented schemas and also update the docs for integration in this PR.

    muntaxir4 commented 14 hours ago

    Looks good, can you also include the API client changes?

    Implementation for API-KEY controller? I was thinking of creating a new PR for that.

    rajdip-b commented 11 hours ago

    Actually the parent issue is a centralized one, so i was thinking it would be best to stash both of the changes in here

    muntaxir4 commented 9 hours ago

    Actually the parent issue is a centralized one, so i was thinking it would be best to stash both of the changes in here

    Done with this.