Skip to content

fix(revenuecat): align tools and block with REST v1 API spec#4488

Merged
waleedlatif1 merged 11 commits intostagingfrom
waleedlatif1/revenuecat-v1-alignment
May 7, 2026
Merged

fix(revenuecat): align tools and block with REST v1 API spec#4488
waleedlatif1 merged 11 commits intostagingfrom
waleedlatif1/revenuecat-v1-alignment

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Validated all 10 RevenueCat tools and the block against context7 REST v1 docs
  • Unwrap {value:{subscriber}} envelope across post-receipts, attributes, entitlements, and Google sub endpoints
  • Trim entitlement output to documented v1 fields; add subscriber fields (last_seen, original_application_version, other_purchases, subscriber_attributes)
  • create_purchase: productId optional (Google-only required); add introductoryPrice, attributes, updated_at_ms; surface customer + subscriber; X-Platform required
  • update_subscriber_attributes: read response and surface subscriber
  • defer_google_subscription: enforce XOR(extendByDays, expiryTimeMs) and 1-365 range
  • grant_entitlement: duration optional, added endTimeMs (one-of)
  • refund_google_subscription: corrected to /transactions/{storeTransactionId}/refund
  • delete_customer: read deleted field; list_offerings: corrected X-Platform values
  • Added shared throwIfRevenueCatError helper for {code, message} envelope
  • Moved type coercions from tools.config.tooltools.config.params to preserve dynamic refs

Type of Change

  • Bug fix

Testing

Tested manually; type-check and lint clean

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

- Validated all 10 tools and the block against context7 REST v1 docs
- Unwrap {value:{subscriber}} envelope across post-receipts, attributes,
  entitlements, and Google subscription endpoints
- Trim entitlement output to documented fields (expires_date,
  grace_period_expires_date, product_identifier, purchase_date)
- Add subscriber output fields: last_seen, original_application_version,
  other_purchases, subscriber_attributes
- create_purchase: productId optional (Google-only required); add
  introductoryPrice, attributes, updated_at_ms; surface customer + subscriber;
  X-Platform required; presentedOfferingIdentifier and paymentMode
- update_subscriber_attributes: read response and surface subscriber;
  note required updated_at_ms
- defer_google_subscription: enforce XOR(extendByDays, expiryTimeMs) and
  1-365 range; expiryTimeMs as one-of alternative
- grant_entitlement: duration optional, added endTimeMs (one-of)
- refund_google_subscription: corrected endpoint to
  /transactions/{storeTransactionId}/refund
- delete_customer: read 'deleted' field (was 'was_deleted')
- list_offerings: corrected X-Platform values
- get_customer: count active subscriptions by expiry/refund
- Added shared throwIfRevenueCatError helper for {code, message} envelope
- Moved type coercions from tools.config.tool to tools.config.params to
  preserve dynamic refs
@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped May 7, 2026 4:50pm

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 7, 2026

PR Summary

Medium Risk
Touches all RevenueCat tool request/response shaping and endpoint paths; mistakes could break purchase/entitlement/refund workflows even though changes are mostly spec-alignment and validation.

Overview
Aligns the RevenueCat integration (tools, block config, and docs) with RevenueCat REST v1, including updated parameter requirements, new optional purchase fields, and expanded subscriber output fields.

Normalizes API handling across tools by trimming/reshaping subscriber output, unwrapping { value: { subscriber } } response envelopes, adding consistent error parsing via throwIfRevenueCatError, and trimming user inputs before building request URLs.

Updates several behaviors/endpoints: revenuecat_create_purchase now requires X-Platform, supports additional purchase metadata (offerings/payment mode/intro price/attributes), and can return a top-level customer; grant_entitlement and defer_google_subscription enforce one-of inputs (duration vs endTimeMs, extendByDays vs expiryTimeMs); and refund_google_subscription switches to refunding by storeTransactionId via the /transactions/{id}/refund endpoint.

Reviewed by Cursor Bugbot for commit 8660b21. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 7, 2026

Greptile Summary

This PR aligns all 10 RevenueCat tools and the block against the REST v1 API spec, fixing endpoint URLs, response envelope unwrapping, param contracts, and error handling across the integration.

  • Shared helpers in types.ts: extractSubscriber/extractCustomer handle both the {value:{subscriber}} wrapped and unwrapped response shapes; throwIfRevenueCatError reads a cloned response to surface {code, message} errors before any .json() call on the original; shapeSubscriber normalises the subscriber object to a consistent type.
  • Endpoint and param corrections: refund_google_subscription now targets /transactions/{storeTransactionId}/refund; create_purchase makes productId optional and platform (X-Platform header) required; grant_entitlement and defer_google_subscription gain XOR-guarded alternate params (endTimeMs/expiryTimeMs).
  • Block config improvements: type coercions moved from tool() to params() to preserve dynamic refs; productId→storeTransactionId mapping added for refunds; duration auto-cleared when endTimeMs is populated.

Confidence Score: 5/5

Safe to merge — all changed code paths are consistent, shared helpers handle both response envelope shapes correctly, and previously flagged issues have been resolved.

The changes are narrowly scoped to the RevenueCat integration. Response parsing, error surfacing, XOR guards, and URL corrections all behave correctly. The throwIfRevenueCatError helper uses response.clone() so the original body remains available for subsequent .json() calls. Active-subscription counting in get_customer now correctly filters by date rather than counting all keys.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/tools/revenuecat/types.ts New shared helpers are well-structured and handle both wrapped/unwrapped envelopes correctly; uses response.clone() to avoid double-body-read on errors
apps/sim/blocks/blocks/revenuecat.ts Migrated coercions from tool() to params(); adds endTimeMs/expiryTimeMs fields with correct XOR handling; platform now required for create_purchase
apps/sim/tools/revenuecat/create_purchase.ts productId is now optional; platform is required; attributes JSON parsing has try/catch guard
apps/sim/tools/revenuecat/get_customer.ts Active subscription/entitlement counts now use date-based filtering instead of raw key count
apps/sim/tools/revenuecat/refund_google_subscription.ts URL corrected to /transactions/{storeTransactionId}/refund; throwIfRevenueCatError added
apps/sim/tools/revenuecat/grant_entitlement.ts duration is now optional; endTimeMs added with XOR guard; two_week duration added
apps/sim/tools/revenuecat/defer_google_subscription.ts expiryTimeMs added as alternative to extendByDays; XOR and range validation enforced
apps/sim/tools/revenuecat/delete_customer.ts Now reads deleted/app_user_id from response body with try/catch for empty-body 200 responses
apps/sim/tools/revenuecat/update_subscriber_attributes.ts attributes JSON parsing now has try/catch guard; subscriber output removed since endpoint returns empty 200

Reviews (8): Last reviewed commit: "improvement(revenuecat): include updated..." | Re-trigger Greptile

Comment thread apps/sim/tools/revenuecat/create_purchase.ts
Comment thread apps/sim/tools/revenuecat/grant_entitlement.ts Outdated
Comment thread apps/sim/tools/revenuecat/update_subscriber_attributes.ts
- create_purchase: wrap JSON.parse(attributes) with try/catch and clear error
- update_subscriber_attributes: drop subscriber output (endpoint returns
  empty body) and guard JSON.parse on attributes
- grant_entitlement: throw when both duration and endTimeMs are provided,
  matching defer_google_subscription behavior
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

- delete_customer: drop dead was_deleted fallback (docs specify 'deleted')
- grant_entitlement: mark duration + startTimeMs as deprecated, clarify
  startTimeMs only affects expiration calc (not grant time)
- list_offerings: replace vague platform description with documented
  X-Platform enum (ios, android, amazon, stripe, roku, paddle)
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

bugbot run

Comment thread apps/sim/blocks/blocks/revenuecat.ts
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a5403cd. Configure here.

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/blocks/blocks/revenuecat.ts
Comment thread apps/sim/blocks/blocks/revenuecat.ts
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a5403cd. Configure here.

The duration dropdown defaults to 'monthly' so any user filling in the
advanced endTimeMs field would otherwise hit the XOR guard. Clear
duration in the params mapper so endTimeMs takes precedence.
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/blocks/blocks/revenuecat.ts
…ided

Mirror the duration/endTimeMs fix from 8204e89: when expiryTimeMs is
populated, clear extendByDays in the params mapper so the empty-string
form value does not trip the XOR guard. Also harden the tool-level XOR
checks in defer_google_subscription and grant_entitlement to treat empty
strings as undefined for direct (non-block) callers.
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/blocks/blocks/revenuecat.ts Outdated
Comment thread apps/sim/tools/revenuecat/defer_google_subscription.ts
- Block params mapper: only clear duration/extendByDays when the parsed
  endTimeMs/expiryTimeMs is finite, so invalid input does not silently
  discard the user's valid companion default
- defer_google_subscription: validate extendByDays as integer (was
  Number.isFinite), matching the error message
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/tools/revenuecat/get_customer.ts Outdated
A malformed request_date would parse to NaN, making every entitlement
and subscription compare false and silently zero active counts. Fall
back to Date.now() when the parsed value is not finite.
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit e6495c1. Configure here.

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 8660b21. Configure here.

@waleedlatif1 waleedlatif1 merged commit 38cbefd into staging May 7, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/revenuecat-v1-alignment branch May 7, 2026 20:06
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.

1 participant