Skip to content

feat: Add Subscription Items API endpoints - #162

Merged
Benzilla merged 2 commits into
zonelessdev:mainfrom
Abhishek-singh88:add-subscription-items-api
Sep 22, 2026
Merged

Benzilla merged 2 commits into
zonelessdev:mainfrom
Abhishek-singh88:add-subscription-items-api

Conversation

@Abhishek-singh88

Copy link
Copy Markdown
Contributor

Resolves #159

Description

This PR adds public API endpoints for Subscription Items to match Stripe's API. Previously, subscription items could only be managed implicitly by updating the parent subscription. This provides developers with dedicated endpoints to manage items directly.

Files Changed:

  • apps/api/src/modules/Subscription.ts: Added public CRUD methods (CreateItem, GetItem, UpdateItem, DeleteItem, ListItems) for Subscription Items. These hook into the existing database models, reuse internal logic, and emit necessary webhook events (like customer.subscription.updated). Modified RequireSubscription to optionally validate the platform account.
  • apps/api/src/routes/subscriptionItems.routes.ts: Created new Express routes to handle the endpoints. Validates incoming requests using the existing Zod schemas (CreateSubscriptionItemSchema, UpdateSubscriptionItemSchema, DeleteSubscriptionItemSchema).
  • apps/api/src/routes/index.ts: Mounted the new subscriptionItems router to the /v1/subscription_items path.
  • apps/api/src/__tests__/SubscriptionItem.spec.ts: Added a focused API test suite for the new Subscription Items module logic to ensure database actions and event emissions behave correctly for all 5 endpoints.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactoring
  • Documentation

How Was This Tested?

  • Unit tests
  • Integration tests
  • Manual testing

Tested all five CRUD operations via the new SubscriptionItem.spec.ts test suite. Ran npx nx test api to ensure all existing test suites pass. Manually verified route registration and authentication rejection (401 vs 404) via terminal cURL.

Screenshots

All test case passed
Screenshot from 2026-09-19 02-06-07

Terminal output showing the new /v1/subscription_items route returning 401 Unauthorized instead of 404 Not Found, proving the endpoint is correctly mounted.
Screenshot from 2026-09-19 02-14-07

Checklist

  • Self-reviewed my code
  • No new warnings
  • Existing tests still pass
  • Breaking changes are documented above

@Benzilla

Copy link
Copy Markdown
Contributor

Thank you! the endpoints are looking good.

Few things I'd want before merging:

Missing items should 404, not 400 invalid_request_error. Stripe uses resource_missing here; we already do the same for invoice items (INVOICE_ITEM_NOT_FOUND). Can we add SUBSCRIPTION_ITEM_NOT_FOUND and use it on retrieve/update/delete?

Small things:

  • import DeleteSubscriptionItemSchema at the top of Subscription.ts rather than the inline typeof import(...).
  • Lets make the function names more explicit, e.g. CreateItem -> CreateSubscriptionItem, DeleteItem-> DeleteSubscriptionItem etc. to match naming conventions across other modules.

@Abhishek-singh88

Copy link
Copy Markdown
Contributor Author

Thanks for the review and catching those, I just pushed a new commit addressing everything:

  • 404 Errors: Added SUBSCRIPTION_ITEM_NOT_FOUND to our centralized errors so that missing items properly throw a 404 resource_missing on the retrieve, update, and delete endpoints to match Stripe's convention.
  • Top-level Import: Moved DeleteSubscriptionItemSchema to the top-level imports in Subscription.ts.
  • Explicit Naming: Renamed the public functions (CreateItem -> CreateSubscriptionItem, etc.) to align with the rest of the modules. (Note: Since there was already an internal helper named CreateSubscriptionItem, I renamed that one to InsertSubscriptionItem to safely avoid conflicts).

I've re run the tests locally and everything is perfectly green. Let me know if there's anything else you need before merging

@Benzilla

Copy link
Copy Markdown
Contributor

Thanks so much! merging now.

@Benzilla
Benzilla merged commit 5633b45 into zonelessdev:main Sep 22, 2026
5 checks passed
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.

Add Subscription Items API endpoints

2 participants