Skip to content

feat(sdk): add addons to javascript SDK#2833

Merged
tothandras merged 4 commits intomainfrom
galexi/addons-js-client
May 20, 2025
Merged

feat(sdk): add addons to javascript SDK#2833
tothandras merged 4 commits intomainfrom
galexi/addons-js-client

Conversation

@GAlexIHU
Copy link
Contributor

@GAlexIHU GAlexIHU commented May 16, 2025

Overview

As the title says

Notes for reviewer

Summary by CodeRabbit

  • New Features
    • Added support for managing addons, including creating, listing, updating, deleting, publishing, and archiving addons.
    • Introduced functionality to manage subscription addons, allowing creation, retrieval, listing, and updating of addons for specific subscriptions.

@GAlexIHU GAlexIHU requested a review from a team as a code owner May 16, 2025 12:28
@GAlexIHU GAlexIHU added the release-note/misc Miscellaneous changes label May 16, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 16, 2025

📝 Walkthrough
## Walkthrough

This change introduces two new classes, `Addons` and `SubscriptionAddons`, to the JavaScript API client, providing typed methods for managing addon and subscription addon resources via HTTP API calls. The `OpenMeter` class is updated to expose these new classes as public properties, enabling direct access to their respective methods.

## Changes

| File(s)                                                                                  | Change Summary                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
|------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| api/client/javascript/src/client/addons.ts                                               | Introduced a new exported `Addons` class, providing typed async methods for CRUD and lifecycle operations on addons, including `create`, `list`, `get`, `update`, `delete`, `publish`, and `archive`. All methods use a generic API client and transform responses for consistency.                                                                                                                                                                                                                                                                                                                           |
| api/client/javascript/src/client/subscription-addons.ts                                  | Added a new exported `SubscriptionAddons` class with async methods to create, list, get, and update subscription addons. Each method uses path parameters, strong typing, and response transformation for API interactions.                                                                                                                                                                                                                                                                                                                                                                                    |
| api/client/javascript/src/client/index.ts                                                | Updated the `OpenMeter` class to include two new public properties: `addons` (instance of `Addons`) and `subscriptionAddons` (instance of `SubscriptionAddons`). Added necessary imports and instantiated these classes in the constructor. No other logic was changed.                                                                                                                                                                                                                                                                                                  |
| api/client/javascript/package.json                                                       | Bumped multiple development dependencies including ESLint packages, TypeScript, React types, testing tools, and code formatters. Upgraded "openapi-fetch" from 0.13.5 to 0.14.0. Added a new "onlyBuiltDependencies" array under "pnpm" config listing "esbuild" and "unrs-resolver" as build-only dependencies. No changes to scripts or main entries.                                                                                                                                                                                                                                                     |
| api/client/javascript/src/portal/index.ts                                               | Consolidated import statements by combining separate imports of `createClient` and `createQuerySerializer` from 'openapi-fetch' into a single import statement without changing functionality.                                                                                                                                                                                                                                                                                                                                                                                                    |

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 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 d6fa331 and ee948c4.

⛔ Files ignored due to path filters (1)
  • api/client/javascript/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • api/client/javascript/package.json (2 hunks)
  • api/client/javascript/src/portal/index.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • api/client/javascript/src/portal/index.ts
  • api/client/javascript/package.json
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: Test
  • GitHub Check: Quickstart
  • GitHub Check: Migration Checks
  • GitHub Check: E2E
  • GitHub Check: Lint
  • GitHub Check: Developer environment
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Commit hooks
  • GitHub Check: Analyze (go)
  • GitHub Check: CI
  • GitHub Check: Build
✨ 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
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: 4

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e49464d and 0e516a0.

📒 Files selected for processing (3)
  • api/client/javascript/src/client/addon.ts (1 hunks)
  • api/client/javascript/src/client/index.ts (6 hunks)
  • api/client/javascript/src/client/subscription-addon.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
api/client/javascript/src/client/index.ts (2)
api/client/javascript/src/client/addon.ts (1)
  • Addons (6-161)
api/client/javascript/src/client/subscription-addon.ts (1)
  • SubscriptionAddons (6-114)
api/client/javascript/src/client/addon.ts (3)
api/client/javascript/src/client/schemas.ts (1)
  • paths (1-2056)
api/client/javascript/src/client/common.ts (1)
  • RequestOptions (6-6)
api/client/javascript/src/client/utils.ts (1)
  • transformResponse (15-35)
api/client/javascript/src/client/subscription-addon.ts (3)
api/client/javascript/src/client/schemas.ts (1)
  • paths (1-2056)
api/client/javascript/src/client/common.ts (1)
  • RequestOptions (6-6)
api/client/javascript/src/client/utils.ts (1)
  • transformResponse (15-35)
🪛 Biome (1.9.4)
api/client/javascript/src/client/addon.ts

[error] 110-110: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: E2E
  • GitHub Check: CI
  • GitHub Check: Quickstart
  • GitHub Check: Lint
  • GitHub Check: Developer environment
  • GitHub Check: Commit hooks
  • GitHub Check: Test
  • GitHub Check: Migration Checks
  • GitHub Check: Build
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (15)
api/client/javascript/src/client/addon.ts (7)

6-8: LGTM! Class implementation follows the client pattern.

The Addons class constructor correctly accepts and stores the client instance, following the same pattern as other service classes in the codebase.


9-28: LGTM! Create method implementation looks good.

The create method is properly implemented with appropriate typing, parameter handling, and response transformation.


30-49: LGTM! List method is correctly implemented.

The list method correctly handles optional query parameters and request options, with proper type definitions for parameters and return values.


51-70: LGTM! Get method follows established patterns.

The get method properly accepts an addonId parameter and optional request options, following the established pattern in the codebase.


72-94: LGTM! Update method is properly implemented.

The update method correctly accepts addonId, addon data, and optional request options with appropriate type definitions.


120-139: LGTM! Publish method is correctly implemented.

The publish method correctly accepts addonId and optional request options, with proper type definitions for parameters and return values.


141-160: LGTM! Archive method follows established patterns.

The archive method properly accepts an addonId parameter and optional request options, following the established pattern in the codebase.

api/client/javascript/src/client/index.ts (3)

6-6: LGTM! Imports are properly organized.

The imports for the new Addons and SubscriptionAddons classes are correctly added and maintained in alphabetical order.

Also applies to: 20-20


51-51: LGTM! New properties are properly declared.

The new public properties addons and subscriptionAddons are correctly declared with their respective types, maintaining alphabetical order with existing properties.

Also applies to: 65-65


88-88: LGTM! Properties initialization is correctly implemented.

The addons and subscriptionAddons properties are properly initialized in the constructor, maintaining the same pattern as other service classes and alphabetical order.

Also applies to: 102-102

api/client/javascript/src/client/subscription-addon.ts (5)

6-8: LGTM! Class implementation follows the client pattern.

The SubscriptionAddons class constructor correctly accepts and stores the client instance, following the same pattern as other service classes in the codebase.


9-34: LGTM! Create method implementation looks good.

The create method is properly implemented with appropriate typing for all parameters, proper path parameter handling, and response transformation.


36-58: LGTM! List method is correctly implemented.

The list method properly accepts a subscriptionId parameter and optional request options, with proper type definitions for parameters and return values.


60-84: LGTM! Get method follows established patterns.

The get method correctly handles path parameters for both the subscription ID and subscription addon ID, following the established pattern in the codebase.


86-113: LGTM! Update method is properly implemented.

The update method correctly uses PATCH (instead of PUT used in the Addons class), which is consistent with the API endpoint definition in the schemas.

@GAlexIHU GAlexIHU requested a review from tothandras May 16, 2025 12:41
@tothandras tothandras force-pushed the galexi/addons-js-client branch from 10a2dcd to 3286d28 Compare May 20, 2025 08:21
@tothandras tothandras changed the title feat: write js client for addons feat(sdk): add addons to javascript SDK May 20, 2025
Copy link
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: 0

🧹 Nitpick comments (5)
api/client/javascript/src/client/addons.ts (5)

6-7: Constructor looks good, but consider adding a type for client paths.

The generic client parameter with template literal type works well. For better maintainability, consider defining a type alias for ${string}/${string} to make its purpose clearer.


30-32: Consider adding explicit return type for better clarity.

While TypeScript can infer the return type, explicitly defining it would improve documentation and maintainability.

  public async list(
    params?: operations['listAddons']['parameters']['query'],
    options?: RequestOptions
-  ) {
+  ): Promise<ReturnType<typeof transformResponse>> {

64-67: Simplify the verbose type declaration for better readability.

The type for the addon parameter is quite verbose. Consider creating a type alias for this complex type to improve code readability.

+type AddonUpdateData = operations['updateAddon']['requestBody']['content']['application/json'];

  public async update(
    addonId: string,
-    addon: operations['updateAddon']['requestBody']['content']['application/json'],
+    addon: AddonUpdateData,
    options?: RequestOptions
  ) {

78-83: Improve return type documentation for delete method.

While other methods clearly document what entity is returned, the delete method mentions "void or standard error response structure". Consider making the documentation consistent across all methods or explicitly mentioning the return type for all methods.


6-122: Consider adding error handling or documenting error patterns.

While the transformResponse utility likely handles errors, there's no explicit error handling in the methods. Consider either:

  1. Adding try/catch blocks for more explicit error handling
  2. Documenting the error handling pattern in class-level JSDoc
  3. Ensuring consistent error responses across all methods

This would make the API more predictable for consumers.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 10a2dcd and 3286d28.

📒 Files selected for processing (3)
  • api/client/javascript/src/client/addons.ts (1 hunks)
  • api/client/javascript/src/client/index.ts (6 hunks)
  • api/client/javascript/src/client/subscription-addon.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • api/client/javascript/src/client/index.ts
  • api/client/javascript/src/client/subscription-addon.ts
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: Artifacts / Container image
  • GitHub Check: Artifacts / Benthos Collector Container image
  • GitHub Check: Test
  • GitHub Check: Quickstart
  • GitHub Check: Migration Checks
  • GitHub Check: Lint
  • GitHub Check: E2E
  • GitHub Check: Developer environment
  • GitHub Check: CI
  • GitHub Check: Commit hooks
  • GitHub Check: Build
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
api/client/javascript/src/client/addons.ts (3)

1-5: Imports look appropriate.

The imports include necessary utilities and types for the Addons client implementation. Good use of explicit types from the OpenAPI schema.


9-22: Create method implementation is clean and well-documented.

Good use of JSDoc comments and proper parameter typing. The method correctly passes the addon object in the request body.


1-122: Overall implementation is clean and follows consistent patterns.

The Addons class is well-structured with consistent method implementations for CRUD operations and additional lifecycle actions (publish, archive). Each method is well-documented and follows the same pattern of making an API request and transforming the response.

@tothandras tothandras force-pushed the galexi/addons-js-client branch from 3286d28 to d6fa331 Compare May 20, 2025 08:23
tothandras
tothandras previously approved these changes May 20, 2025
@tothandras tothandras enabled auto-merge (squash) May 20, 2025 08:24
Copy link
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: 0

🧹 Nitpick comments (1)
api/client/javascript/src/client/subscription-addons.ts (1)

6-99: Consider implementing a delete method for subscription addons.

The class implements create, read, and update operations but appears to be missing a delete operation. If the API supports deleting subscription addons, consider adding a delete method to complete the CRUD operations.

/**
 * Delete a subscription addon
 * @param subscriptionId - The ID of the subscription
 * @param subscriptionAddonId - The ID of the subscription addon to delete
 * @param options - Optional request options
 * @returns The operation result
 */
public async delete(
  subscriptionId: string,
  subscriptionAddonId: string,
  options?: RequestOptions
) {
  const resp = await this.client.DELETE(
    '/api/v1/subscriptions/{subscriptionId}/addons/{subscriptionAddonId}',
    {
      params: { path: { subscriptionAddonId, subscriptionId } },
      ...options,
    }
  )

  return transformResponse(resp)
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3286d28 and d6fa331.

📒 Files selected for processing (3)
  • api/client/javascript/src/client/addons.ts (1 hunks)
  • api/client/javascript/src/client/index.ts (6 hunks)
  • api/client/javascript/src/client/subscription-addons.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • api/client/javascript/src/client/index.ts
  • api/client/javascript/src/client/addons.ts
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: Quickstart
  • GitHub Check: E2E
  • GitHub Check: CI
  • GitHub Check: Test
  • GitHub Check: Migration Checks
  • GitHub Check: Lint
  • GitHub Check: Developer environment
  • GitHub Check: Build
  • GitHub Check: Commit hooks
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (7)
api/client/javascript/src/client/subscription-addons.ts (7)

1-5: LGTM: Appropriate imports for functionality.

The imports correctly include all necessary utilities and types for implementing the subscription addons functionality.


6-8: LGTM: Class structure follows the existing pattern.

The SubscriptionAddons class constructor correctly takes a typed client parameter following the pattern used in other client classes.


9-31: LGTM: Well-implemented create method with proper typing.

The create method is properly implemented with:

  • Clear JSDoc documentation
  • Strong typing for parameters
  • Correct HTTP method (POST)
  • Proper path parameter handling
  • Response transformation

33-49: LGTM: Well-implemented list method.

The list method correctly implements the GET operation with appropriate parameter handling and response transformation.


51-72: LGTM: Well-implemented get method.

The get method correctly retrieves a specific subscription addon by ID with proper path parameter handling.


74-98: LGTM: Well-implemented update method.

The update method correctly implements the PATCH operation with appropriate parameter handling.


1-99:

Details

✅ Verification successful

Verify error handling strategy.

The code relies on transformResponse for handling API responses, but there's no explicit error handling in the methods. Please verify that transformResponse properly handles error cases, or consider adding explicit error handling if needed.


🏁 Script executed:

#!/bin/bash
# Check the implementation of transformResponse to understand error handling
cat api/client/javascript/src/client/utils.js | grep -A 20 "transformResponse"

Length of output: 152


Let’s locate and inspect the actual transformResponse implementation to confirm its error handling:


🏁 Script executed:

#!/bin/bash
# Locate and show the implementation of transformResponse
rg -n "transformResponse" -A 20

Length of output: 72759


Error Handling Verified

The transformResponse function (api/client/javascript/src/client/utils.ts lines 24–27) already throws an HTTPError for resp.error or status codes ≥ 400, so all client methods will propagate errors appropriately. No additional error handling is needed in the SubscriptionAddons methods.

@tothandras tothandras merged commit d7c858b into main May 20, 2025
22 checks passed
@tothandras tothandras deleted the galexi/addons-js-client branch May 20, 2025 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/misc Miscellaneous changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants