-
-
Notifications
You must be signed in to change notification settings - Fork 84
feat(clerk): Add billing endpoints #539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add support for Clerk billing API endpoints following the Orb FDW pattern: - billing/plans - billing/subscription_items - billing/statements - users/billing/subscription (requires user_id WHERE clause) - organizations/billing/subscription (requires organization_id WHERE clause) - billing/statements/payment_attempts (requires statement_id WHERE clause) Implements parameterized URL handling using Context and quals extraction, matching the pattern used in Orb FDW for endpoints like credits/ledger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for Clerk's billing API endpoints to the Clerk Foreign Data Wrapper (FDW), enabling users to query billing-related data such as plans, subscriptions, statements, and payment attempts through SQL queries.
Key Changes:
- Adds 7 new billing-related foreign tables with support for both list and parameterized endpoints
- Implements parameterized endpoint handling for endpoints requiring user_id, organization_id, or statement_id in the WHERE clause
- Updates pagination logic to handle endpoints that don't support ordering and single-object responses
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| wasm-wrappers/fdw/clerk_fdw/src/lib.rs | Implements billing endpoint support with parameterized URL construction, conditional pagination, and special handling for billing endpoints that don't support order_by |
| docs/catalog/clerk.md | Adds comprehensive documentation for all 7 new billing entities with usage examples and API reference links |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Standard endpoints with pagination | ||
| // Billing endpoints don't support order_by | ||
| let is_billing = self.object.starts_with("billing/"); | ||
| let qs = if is_billing { | ||
| vec![ | ||
| format!("offset={}", self.src_offset), | ||
| format!("limit={BATCH_SIZE}"), | ||
| ] | ||
| } else { | ||
| vec![ | ||
| "order_by=-created_at".to_string(), | ||
| format!("offset={}", self.src_offset), | ||
| format!("limit={BATCH_SIZE}"), | ||
| ] | ||
| }; | ||
| let mut url = format!("{}/{}?{}", self.base_url, self.object, qs.join("&")); |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query string with offset/limit parameters is built for all endpoints (lines 131-142) and used to construct the URL (line 143), but for parameterized endpoints (users/billing/subscription, organizations/billing/subscription, billing/statement, billing/payment_attempts), the URL is completely replaced (lines 153, 167, 181, 195), discarding these parameters. Consider checking if the endpoint is parameterized before building the query string to avoid unnecessary string allocation and formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
low prio
|
Thanks for the PR! Could you format the code to fix the CI failure? |
Done! |
|
For non-existing object, is it possible to return an empty dataset rather than return an error? For example, select * from clerk.billing_statement where id='123';This will return an guest fdw error (essentially a HTTP 404 error): I think an empty result might be more semantically correct, as non-existing isn't really an error. |
|
@burmecia agree to that, updated! |
What kind of change does this PR introduce?
Hi everyone, Rob from Clerk here. First of all, thanks for putting up a Wasm Wrapper for Clerk! We added billing recently and figured we can add this endpoints to the FDW as well.
This PR adds support for Clerk's billing API endpoints to the Clerk FDW.
What is the current behavior?
The Clerk FDW currently supports users, organizations, and other core Clerk resources, but does not include any billing-related endpoints. Users cannot query billing plans, subscriptions, statements, or payment data through the FDW.
What is the new behavior?
The Clerk FDW now supports 7 billing-related endpoints:
billing_plansbilling/plansbilling_subscription_itemsbilling/subscription_itemsbilling_statementsbilling/statementsbilling_statementbilling/statementstatement_idbilling_payment_attemptsbilling/payment_attemptsstatement_iduser_billing_subscriptionsusers/billing/subscriptionuser_idorganization_billing_subscriptionsorganizations/billing/subscriptionorganization_idExample queries:
Additional context