Skip to content

feat!: support @polar-sh/sdk 1.x - #100

Open
candidosales wants to merge 2 commits into
convex:mainfrom
candidosales:feat/polar-sdk-1
Open

candidosales wants to merge 2 commits into
convex:mainfrom
candidosales:feat/polar-sdk-1

Conversation

@candidosales

@candidosales candidosales commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Why

@polar-sh/sdk 1.0 removed the 0.x entry points this component imports (@polar-sh/sdk/core.js, /funcs/*, /webhooks, /models/components/*). Apps that upgrade the SDK can't load @convex-dev/polar at all, so they're stuck on 0.x.

What

Ports the component to the versioned @polar-sh/sdk/2026-10 API:

  • Client (src/client/index.ts): curried service functions (createCheckouts(polar)(...) etc.), which return values and throw on error instead of { ok, value }; createPolarCore({ environment }) in place of new PolarCore({ server }); await webhooks.validateEvent(...) (async in 1.x), with PolarWebhookVerificationError → 403 and PolarWebhookUnknownTypeError → 202 (acked so Polar doesn't retry event types newer than the pinned API version or disable the endpoint).
  • Converters (src/component/util.ts): read the SDK's snake_case fields and ISO string timestamps. The stored schema stays camelCase, so no data migration. Metered price meter is narrowed to { id, name } because 1.x adds fields the schema doesn't allow.
  • syncProducts: pagination.max_page.
  • Example seed: ported. 1.x has no free amount type, so the free tier is a fixed price of 0, as the SDK docs describe.
  • peerDependency: @polar-sh/sdk: ^1.0.0.
  • Dropped the Buffer polyfill and buffer dependency; 1.x verifies signatures with Web Crypto.

Breaking changes (documented in CHANGELOG)

  • Webhook payloads passed to events handlers and the deprecated on* callbacks use snake_case fields, e.g. event.data.customer_cancellation_reason. The README and example are updated.
  • createCheckoutSession, changeSubscription and cancelSubscription return snake_case SDK objects.

Tests

  • The existing converter tests use 1.x-shaped fixtures, including a realistic metered meter object (fails if the narrowing is removed).
  • syncProducts is covered across two pages.
  • The client test mocks moved to the new service modules.
  • New test: a request signed with standard-webhooks headers goes through registerRoutes → HTTP route → subscription.created stored in the component and handler called. A forged signature gets a 403 and nothing is stored. A signed unknown event type gets a 202.

npm run build, typecheck, lint and test (71 passed) all pass locally.

🤖 Generated with Claude Code

The 1.x SDK removed the 0.x entry points (`core.js`, `funcs/*`,
`webhooks`, `models/components/*`), so the component no longer loads with
it. Port to the versioned `@polar-sh/sdk/2026-10` API:

- client: curried service functions, `createPolarCore({ environment })`,
  async `webhooks.validateEvent`, 403 on `PolarWebhookVerificationError`
- converters read the SDK's snake_case fields and ISO string timestamps;
  the stored camelCase schema is unchanged, so no data migration
- syncProducts reads `pagination.max_page`
- example seed: free tier is now a fixed price of 0 (no `free` amount type)
- test: signed webhook request through the HTTP route into the database,
  and a forged signature rejected with 403

Breaking: webhook handler payloads and SDK objects returned from
createCheckoutSession/changeSubscription/cancelSubscription are snake_case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: convex/coderabbit/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 50b477ad-3648-473c-a8ea-c0ee0973bc8c
📥 Commits

Reviewing files that changed from the base of the PR and between 4b7640a and 1a2473a.

⛔ Files ignored due to path filters: 1
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing: 10
  • CHANGELOG.md
  • README.md
  • example/convex/http.ts
  • example/convex/seed.ts
  • package.json
  • src/client/index.test.ts
  • src/client/index.ts
  • src/component/lib.test.ts
  • src/component/lib.ts
  • src/component/util.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

The package, client, component converters, and examples now use the Polar SDK 1.x 2026-10 APIs. The client uses versioned service functions and webhook exports. Component converters map snake_case SDK fields to existing database fields. Tests and examples use the updated SDK shapes, and webhook tests cover signed requests, persistence, and handler invocation.

Suggested reviewers: ianmacartney

Priority: ➖ Normal

Change: Feature

Merge Risk: ⚪ Minimal · up to 1a247

No identified issue blocks the SDK migration from merging after normal checks.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the primary change: support for @polar-sh/sdk 1.x. The breaking-change marker is appropriate.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The pull request description directly explains the migration to @polar-sh/sdk 1.x, the affected client, converters, examples, dependency, breaking changes, and tests. It matches the changeset.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

- Return 202 for PolarWebhookUnknownTypeError so Polar doesn't retry
  event types newer than the pinned API version or disable the endpoint.
- Remove the Buffer polyfill and the buffer dependency; the 1.x SDK
  verifies signatures with Web Crypto.
- Use a realistic meter fixture (unit, custom_label, custom_multiplier)
  so the meter narrowing in convertToDatabaseProduct is covered.
- Cover syncProducts pagination across two pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@candidosales

Copy link
Copy Markdown
Contributor Author

@erquhart, when you get a chance, could you take a look? 🙏

@candidosales

Copy link
Copy Markdown
Contributor Author

@Nicolapps , when you get a chance, could you take a look? 🙏

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