Add SubscriptionEvent wrapping/disable/enable and Invoice updateStatus/disable [PIP-311]#129
Add SubscriptionEvent wrapping/disable/enable and Invoice updateStatus/disable [PIP-311]#129
Conversation
…passing bug - Wrap flat params in `subscription_event` envelope for create/update/delete - Add disable/enable state toggling endpoints - Fix bug where undefined callback arg blocked data extraction in _method() - Add tests verifying body wrapping and error handling Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add Invoice.updateStatus (PATCH /v1/invoices/:uuid) - Add Invoice.disable (PATCH /v1/invoices/:uuid/disable) - Add tests for happy path, callback style, body params, and error cases Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Updates the ChartMogul Node SDK to support newer API behaviors for Subscription Events, Invoices, and Account retrieval by adding/adjusting client methods and expanding test coverage for these behaviors.
Changes:
- Add support for flat (non-enveloped) SubscriptionEvent params by auto-wrapping into a
subscription_eventenvelope, while keeping backward compatibility for already-enveloped inputs. - Add
SubscriptionEvent.enable/disableandInvoice.updateStatus/disableSDK methods and corresponding tests. - Expand invoice/account test fixtures and assertions to cover new/optional response fields (e.g.,
error,id, and accountincludequery param).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
lib/chartmogul/subscription_event.js |
Adds param-wrapping overrides for create/update/delete and adds enable/disable endpoints. |
lib/chartmogul/invoice.js |
Adds PATCH helpers for invoice status updates and invoice disable endpoint. |
test/chartmogul/subscription-event.js |
Updates tests to validate envelope wrapping + adds enable/disable tests and negative cases. |
test/chartmogul/invoice.js |
Adds tests for invoice status updates/disable + extends fixtures with error fields. |
test/chartmogul/account.js |
Adds assertions for id and supports include query param + negative case. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
- Use hasOwnProperty check in wrapParams to handle falsy envelope values - Use typeof callback === 'function' instead of truthy check Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…arden tests - Refactor SubscriptionEvent wrappers into shared wrapMethod helper - Simplify wrapParams to use truthiness check instead of hasOwnProperty - Fix root cause of undefined callback bug in Resource._method by filtering trailing undefined args - Add rejection guards to all .catch-only error tests (invoice, subscription-event, account) - Add callback-style test for SubscriptionEvent.create - Add body capture assertion to Invoice.disable body params test - Add clarifying comment on Invoice.updateStatus shared path Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…route
- Invoice.updateStatus: PATCH /v1/invoices/:uuid -> PUT /v1/data_sources/:ds/invoices/:ext_id/status
- Invoice.disable: /disable -> /disabled_state with { disabled: true } body
- SubscriptionEvent.disable/enable: /disable,/enable -> /disabled_state with body toggle
- Add Invoice.enable convenience wrapper
- Add DRY wrapMethod helper for SubscriptionEvent
- Harden error tests with rejection guards
- Add callback test for SubscriptionEvent.create
- Verify body payloads in disable tests
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Validates the include query param against known field names (churn_recognition, churn_when_zero_mrr, auto_churn_subscription, refund_handling, proximate_movement_reclassification) and warns on unknown values without throwing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
briwa
left a comment
There was a problem hiding this comment.
LGTM 👍
I'm not too sure if the Linear links and references would be helpful outside of our org, so perhaps we could leave it out in the future
| if (typeof dataOrCb === 'function') { | ||
| cb = dataOrCb; | ||
| } else if (dataOrCb && typeof dataOrCb === 'object') { | ||
| body = Object.assign({}, dataOrCb, { disabled: true }); |
There was a problem hiding this comment.
[minor] You can also use object spread syntax to merge object properties:
| body = Object.assign({}, dataOrCb, { disabled: true }); | |
| body = { ...dataOrCb, disabled: true }; |
Similarly:
Summary
Closes PIP-311
subscription_eventenvelope for create/update/delete, with backward compatibility for already-enveloped inputsSubscriptionEvent.disable/SubscriptionEvent.enablevia/disabled_stateendpointundefinedcallback to_method()blocked request body from being sentInvoice.updateStatus(PUT/v1/data_sources/:ds/invoices/:ext_id/status)Invoice.disable/Invoice.enablevia/disabled_stateendpointAccount.retrieveinclude param validation (warns on unknown fields)includequery paramBackwards compatibility review
Additive (zero risk)
Invoice.updateStatus(config, dsUuid, extId, body[, cb])/v1/data_sources/:ds/invoices/:ext_id/statusInvoice.disable(config, uuid[, body][, cb])/v1/invoices/:uuid/disabled_state— auto-sends{disabled: true}Invoice.enable(config, uuid[, cb])/v1/invoices/:uuid/disabled_state— auto-sends{disabled: false}SubscriptionEvent.disable(config, id[, cb])/v1/subscription_events/:id/disabled_stateSubscriptionEvent.enable(config, id[, cb])/v1/subscription_events/:id/disabled_stateBehaviour changes (safe)
SubscriptionEvent.createnow accepts flat paramswrapParamsauto-wraps{foo: 1}to{subscription_event: {foo: 1}}data.subscription_eventtruthy) and not double-wrapped. Flat-param callers were previously sending the wrong shape to the API — this is a bug fix.SubscriptionEvent.updateWithParams/deleteWithParamssame wrappingResource._methodfilters trailingundefinedargsArray.from(arguments).splice(1).filter(a => a !== undefined)fn(config, data, undefined)would popundefinedascb, then popdataas the next candidate — silently losing the request body. After the fix,undefinedis stripped anddatais correctly identified. No legitimate call path passesundefinedintentionally.Account.retrievevalidatesincludeparamNot changed
SubscriptionEvent.all— untouchedInvoice.create/Invoice.all/Invoice.retrieve/Invoice.destroy/Invoice.destroy_all— untouchedTest plan
npm test)test_pip_310.js){disabled: true/false}bodyTesting instructions
SubscriptionEvent flat param wrapping (create)
SubscriptionEvent envelope backward compat (create)
SubscriptionEvent flat param wrapping (update)
SubscriptionEvent flat param wrapping (delete)
SubscriptionEvent disable / enable
Invoice updateStatus
Invoice disable / enable
Account.retrieve include param validation
Cleanup
🤖 Generated with Claude Code