Skip to content

feat: use new rest api for api keys#144

Merged
Fjandin merged 2 commits into
mainfrom
api-key-new-rest-api
Jul 9, 2025
Merged

feat: use new rest api for api keys#144
Fjandin merged 2 commits into
mainfrom
api-key-new-rest-api

Conversation

@Fjandin
Copy link
Copy Markdown
Contributor

@Fjandin Fjandin commented Jul 8, 2025

Summary by CodeRabbit

  • New Features

    • Introduced the ability to edit API keys, allowing updates to their descriptions.
  • Improvements

    • API key management commands (create, delete, list) now use a streamlined RESTful approach, resulting in more predictable and efficient operations.
    • Enhanced API key data now includes additional fields such as tenant ID, description, and masked API key for better clarity and management.
  • Bug Fixes

    • Simplified and improved response handling for API key operations, reducing potential errors.

@Fjandin Fjandin requested a review from jbiskur July 8, 2025 12:25
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 8, 2025

Walkthrough

The API key management commands were refactored from a GraphQL-based approach to use RESTful HTTP methods. This includes changes to creation, deletion, listing, and editing of API keys, with corresponding schema updates to support new response structures and properties. The code now uses explicit HTTP methods and simplified response parsing.

Changes

File(s) Change Summary
src/commands/api-key/api-key.create.ts Refactored API key creation from GraphQL to REST POST; updated input interface and response handling.
src/commands/api-key/api-key.delete.ts Refactored API key deletion from GraphQL to REST DELETE; simplified input and response logic.
src/commands/api-key/api-key.edit.ts Added new command for editing API keys using REST PATCH; introduced input interface and response parsing.
src/commands/api-key/api-key.list.ts Refactored API key listing from GraphQL to REST GET; updated request construction and response parsing.
src/contracts/api-key.ts Extended schema and types for API keys; added description, tenantId, maskedApiKey, and new value schema.
src/commands/index.ts Added export for the new API key edit command.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Command
    participant API

    Client->>Command: Create/List/Edit/Delete API Key (with input)
    Command->>API: HTTP Request (POST/GET/PATCH/DELETE)
    API-->>Command: HTTP Response (JSON)
    Command-->>Client: Parsed Result (ApiKey/ApiKeyWithValue/boolean)
Loading

Possibly related PRs

Suggested reviewers

  • jbiskur
  • suuunly

Poem

In the warren of code, a change hops in stride,
From GraphQL fields to RESTful we glide.
Keys are created, deleted, and tweaked,
With schemas extended and logic re-peeked.
The burrow is tidy, the carrots aligned—
API bunnies, your work is refined! 🥕


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc7db6b and 9438f5d.

📒 Files selected for processing (2)
  • src/commands/index.ts (1 hunks)
  • src/contracts/api-key.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/contracts/api-key.ts
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: jbiskur
PR: flowcore-io/flowcore-sdk#59
File: src/contracts/tenant.ts:74-74
Timestamp: 2025-02-27T09:48:49.487Z
Learning: The tenant fetch functionality has been migrated to use a REST API with an updated schema (using 'websiteUrl'), while the tenant list functionality still uses GraphQL API with the old schema format (using 'website'). This is why there are different field names for the same concept in different parts of the codebase.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (1)
src/commands/index.ts (1)

13-13: LGTM! Clean addition following established patterns.

The export for the new API key edit command is properly placed within the API Key section and follows the existing naming convention and logical ordering.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 85709e3 and bc7db6b.

📒 Files selected for processing (5)
  • src/commands/api-key/api-key.create.ts (1 hunks)
  • src/commands/api-key/api-key.delete.ts (1 hunks)
  • src/commands/api-key/api-key.edit.ts (1 hunks)
  • src/commands/api-key/api-key.list.ts (1 hunks)
  • src/contracts/api-key.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: jbiskur
PR: flowcore-io/flowcore-sdk#59
File: src/contracts/tenant.ts:74-74
Timestamp: 2025-02-27T09:48:49.487Z
Learning: The tenant fetch functionality has been migrated to use a REST API with an updated schema (using 'websiteUrl'), while the tenant list functionality still uses GraphQL API with the old schema format (using 'website'). This is why there are different field names for the same concept in different parts of the codebase.
src/contracts/api-key.ts (1)
Learnt from: jbiskur
PR: flowcore-io/flowcore-sdk#59
File: src/contracts/tenant.ts:74-74
Timestamp: 2025-02-27T09:48:49.487Z
Learning: The tenant fetch functionality has been migrated to use a REST API with an updated schema (using 'websiteUrl'), while the tenant list functionality still uses GraphQL API with the old schema format (using 'website'). This is why there are different field names for the same concept in different parts of the codebase.
src/commands/api-key/api-key.delete.ts (1)
Learnt from: jbiskur
PR: flowcore-io/flowcore-sdk#59
File: src/contracts/tenant.ts:74-74
Timestamp: 2025-02-27T09:48:49.487Z
Learning: The tenant fetch functionality has been migrated to use a REST API with an updated schema (using 'websiteUrl'), while the tenant list functionality still uses GraphQL API with the old schema format (using 'website'). This is why there are different field names for the same concept in different parts of the codebase.
src/commands/api-key/api-key.list.ts (1)
Learnt from: jbiskur
PR: flowcore-io/flowcore-sdk#59
File: src/contracts/tenant.ts:74-74
Timestamp: 2025-02-27T09:48:49.487Z
Learning: The tenant fetch functionality has been migrated to use a REST API with an updated schema (using 'websiteUrl'), while the tenant list functionality still uses GraphQL API with the old schema format (using 'website'). This is why there are different field names for the same concept in different parts of the codebase.
🧬 Code Graph Analysis (3)
src/commands/api-key/api-key.edit.ts (2)
src/contracts/api-key.ts (2)
  • ApiKey (27-27)
  • ApiKeySchema (6-22)
src/utils/parse-response-helper.ts (1)
  • parseResponseHelper (8-18)
src/commands/api-key/api-key.create.ts (2)
src/contracts/api-key.ts (2)
  • ApiKeyWithValue (55-55)
  • ApiKeyWithValueSchema (32-50)
src/utils/parse-response-helper.ts (1)
  • parseResponseHelper (8-18)
src/commands/api-key/api-key.list.ts (2)
src/contracts/api-key.ts (2)
  • ApiKey (27-27)
  • ApiKeySchema (6-22)
src/utils/parse-response-helper.ts (1)
  • parseResponseHelper (8-18)
🔇 Additional comments (5)
src/contracts/api-key.ts (1)

1-55: LGTM! Well-structured schema updates for REST API migration.

The schema changes appropriately support the REST API migration:

  • New properties (tenantId, description, maskedApiKey) align with typical REST API responses
  • Making lastUsedAt nullable is sensible for newly created API keys
  • The separation between ApiKeySchema and ApiKeyWithValueSchema follows security best practices by only exposing the actual key value when necessary
src/commands/api-key/api-key.edit.ts (1)

1-55: LGTM! Clean implementation of API key edit functionality.

The PATCH endpoint implementation follows REST best practices:

  • Appropriate use of PATCH for partial updates
  • Restricting edits to only the description field is a good security practice
  • Proper response validation using the schema
src/commands/api-key/api-key.create.ts (1)

1-57: LGTM! Clean refactoring from GraphQL to REST.

The migration to REST is well-executed:

  • POST method is appropriate for resource creation
  • Optional description field aligns with the updated schema
  • Returning ApiKeyWithValue on creation is the expected behavior
  • Simplified response parsing improves maintainability
src/commands/api-key/api-key.list.ts (1)

1-53: Clean migration to REST API.

The refactoring from GraphQL to REST is well-implemented with proper array schema validation.

src/commands/api-key/api-key.delete.ts (1)

1-44: Clean implementation of the DELETE endpoint.

The migration to REST is well-structured with appropriate method and path configuration.

Comment on lines +39 to +41
protected override getPath(): string {
return `/api/v1/api-keys?tenantId=${this.input.tenantId}`
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider URL encoding the query parameter.

The tenantId is directly interpolated into the URL without encoding. This could cause issues if the tenantId contains special characters.

Apply this fix to properly encode the query parameter:

-    return `/api/v1/api-keys?tenantId=${this.input.tenantId}`
+    return `/api/v1/api-keys?tenantId=${encodeURIComponent(this.input.tenantId)}`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
protected override getPath(): string {
return `/api/v1/api-keys?tenantId=${this.input.tenantId}`
}
protected override getPath(): string {
return `/api/v1/api-keys?tenantId=${encodeURIComponent(this.input.tenantId)}`
}
🤖 Prompt for AI Agents
In src/commands/api-key/api-key.list.ts around lines 39 to 41, the tenantId
query parameter is directly interpolated into the URL without encoding, which
can cause issues with special characters. Fix this by applying URL encoding to
the tenantId using encodeURIComponent before including it in the URL string.

Comment on lines +45 to 50
/**
* Parse the response
*/
protected override getBody(): Record<string, unknown> {
return {
query: graphQlQueryById,
variables: this.input,
}
protected override parseResponse(_rawResponse: unknown): boolean {
return true
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Consider proper error handling for DELETE responses.

The parseResponse method always returns true regardless of the actual response or HTTP status. This could mask failures and lead to incorrect state management.

Consider checking the response status or at least documenting why always returning true is acceptable:

  protected override parseResponse(_rawResponse: unknown): boolean {
+   // The base Command class handles HTTP errors, so reaching here means success
    return true
  }

Alternatively, you could validate the response status if the base class provides access to it.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* Parse the response
*/
protected override getBody(): Record<string, unknown> {
return {
query: graphQlQueryById,
variables: this.input,
}
protected override parseResponse(_rawResponse: unknown): boolean {
return true
}
/**
* Parse the response
*/
protected override parseResponse(_rawResponse: unknown): boolean {
// The base Command class handles HTTP errors, so reaching here means success
return true
}
🤖 Prompt for AI Agents
In src/commands/api-key/api-key.delete.ts around lines 45 to 50, the
parseResponse method currently returns true unconditionally, which can hide
errors from the DELETE request. Modify this method to inspect the actual
response or HTTP status code to determine success or failure, returning true
only if the deletion was successful. If the base class provides access to the
response status, use it to validate the outcome; otherwise, document clearly why
always returning true is safe.

@Fjandin Fjandin merged commit bdccaf2 into main Jul 9, 2025
2 checks passed
@Fjandin Fjandin deleted the api-key-new-rest-api branch July 9, 2025 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants