Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spicy-shirts-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Replace the `/subscriptions` FAPI endpoint with `/subscription_items` for cancelling subscription items.
4 changes: 2 additions & 2 deletions packages/clerk-js/src/core/resources/CommerceSubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export class CommerceSubscription extends BaseResource implements CommerceSubscr
const json = (
await BaseResource._fetch({
path: orgId
? `/organizations/${orgId}/commerce/subscriptions/${this.id}`
: `/me/commerce/subscriptions/${this.id}`,
? `/organizations/${orgId}/commerce/subscription_items/${this.id}`
: `/me/commerce/subscription_items/${this.id}`,
Comment on lines +71 to +72
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify the new endpoint exists and functions correctly.

The endpoint change from /commerce/subscriptions/{id} to /commerce/subscription_items/{id} looks correct for cancelling subscription items. However, ensure that the new endpoint is properly implemented on the backend and handles the same authentication and authorization logic.


🏁 Script executed:

#!/bin/bash
# Description: Verify usage of the new subscription_items endpoint across the codebase
# Expected: Find references to the new endpoint and confirm no remaining old endpoint usage

echo "=== Searching for new subscription_items endpoint usage ==="
rg -A 3 -B 3 "subscription_items" --type ts --type js

echo "=== Searching for potential remaining old subscriptions endpoint usage ==="
rg -A 3 -B 3 "/commerce/subscriptions/" --type ts --type js

echo "=== Searching for tests that might need updating ==="
rg -A 5 -B 5 "CommerceSubscription.*cancel" --type ts --type js

Length of output: 1362


Ensure Test Coverage for CommerceSubscription.cancel

All instances of the old /commerce/subscriptions/{id} endpoint have been replaced with /commerce/subscription_items/{id}, and no remaining references to the old path were found. However, it looks like there are no existing unit tests covering the cancel method in CommerceSubscription. Please add or update tests to validate both user- and organization-scoped cancellation:

• File needing coverage:
packages/clerk-js/src/core/resources/CommerceSubscription.ts (lines 71–72)
/organizations/${orgId}/commerce/subscription_items/${this.id}
/me/commerce/subscription_items/${this.id}

• Suggested tests:
– Mock the HTTP client and verify the correct path is used for org and user calls
– Assert that a DELETE request to each endpoint returns the expected DeletedObjectJSON
– Cover error and edge cases (e.g., missing orgId)

🤖 Prompt for AI Agents
In packages/clerk-js/src/core/resources/CommerceSubscription.ts around lines 71
to 72, add unit tests for the cancel method to ensure coverage of both
organization- and user-scoped cancellation. Mock the HTTP client to verify that
the correct DELETE request is sent to
`/organizations/${orgId}/commerce/subscription_items/${this.id}` when orgId is
present and to `/me/commerce/subscription_items/${this.id}` when it is not.
Include assertions that the response matches the expected DeletedObjectJSON and
add tests for error scenarios such as missing orgId.

method: 'DELETE',
})
)?.response as unknown as DeletedObjectJSON;
Expand Down