better-auth-streampay 3.3.0 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,6 +39,7 @@ Tests cover the plugin's implemented features, not every feature of the Stream p
39
39
  | Paid abandoned checkout loses access | Live sandbox payment of a replaced checkout link: the original code dead-lettered the activation and left `/subscription/current` empty; the fix activated it on the first delivery and StreamPay reported the replacement link `INACTIVE`. Replaced links show "Payment link is inactive". See [state machines](state-machines.md#live-sandbox-evidence-for-f1). |
40
40
  | A retried webhook skips its lifecycle callback | Live sandbox subscription with a later cancellation write: on the original code a retried `SUBSCRIPTION_ACTIVATED` completed without a successful `onSubscriptionActivated`; with the fix the retry delivered it. See [state machines](state-machines.md#live-sandbox-evidence-for-f9-and-streampay-timing). |
41
41
  | A renewal written by another event skips its callback | Live sandbox subscription renewed from cycle 4 to 5: on the original code a plan-update event that wrote cycle 5 first left `INVOICE_COMPLETED` with no `onSubscriptionRenewed`; with the fix it ran once. See [state machines](state-machines.md#live-sandbox-evidence-for-f9-and-streampay-timing). |
42
+ | Renewal evidence for an unlinked checkout is dropped | Live sandbox subscription at cycle 5 with only its checkout reservation: on 3.3.0 the completed renewal invoice left the reservation unlinked with no callback; with the fix it linked the reservation and reported the renewal once. See [state machines](state-machines.md#live-sandbox-evidence-for-f9-and-streampay-timing). |
42
43
  | Checkout activates the wrong reservation | Known payment-link and consumer mismatches cannot bind a pending checkout. |
43
44
  | Portal client sends the wrong HTTP method | The real Better Auth client sends POST for the documented no-argument session call. |
44
45
  | Consumer lookup misses an existing account | Exact identity searches follow pagination; later-page failures and repeated provider pages fail instead of creating a duplicate consumer. |
@@ -79,7 +79,7 @@ overlay: StreamPay keeps reporting `ACTIVE` while a renewal payment is outstandi
79
79
 
80
80
  | # | Trigger | From | To | Guard and code |
81
81
  | --- | --- | --- | --- | --- |
82
- | L1 | Paid checkout confirmed by webhook | `incomplete`, `incomplete_expired`, or no row | provider status | Signed metadata row ID, then a payment-link match, then the newest matching reservation (`reconcileFromStreamPay`). Takes the slot from an unpaid holder (S4). The `/subscription/success` fallback also confirms, but only for an `incomplete` row that still holds its slot, matched by consumer, product, and link (`isCheckoutSubscriptionCandidate`). |
82
+ | L1 | Paid checkout confirmed by webhook | `incomplete`, `incomplete_expired`, or no row | provider status | Signed metadata row ID, then a payment-link match, then the newest matching reservation (`reconcileFromStreamPay`). Renewal evidence that finds no linked row links a reservation owning the subscription's checkout link the same way, with the link's signed metadata (`linkCheckoutFromRenewalEvidence`, F28). Takes the slot from an unpaid holder (S4). The `/subscription/success` fallback also confirms, but only for an `incomplete` row that still holds its slot, matched by consumer, product, and link (`isCheckoutSubscriptionCandidate`). |
83
83
  | L2 | `SUBSCRIPTION_CYCLE_RENEWAL_FAILED`, not stale | `active` | `past_due`, billing `past_due` | `sync.ts` |
84
84
  | L3 | `INVOICE_COMPLETED` or `SUBSCRIPTION_CYCLE_RENEWED_SUCCESSFULLY`, not stale, or stale while its invoice is the provider's `COMPLETED` `latest_invoice` | `past_due` | `active`, billing `current` | `handleRenewalEvidence` (`sync.ts`) |
85
85
  | L4 | Any other projection while billing is `past_due` | `past_due` | `past_due` | S5 |
@@ -202,7 +202,8 @@ Invariants: while the lock is set, its cycle's callback has not been delivered,
202
202
  evidence for that subscription waits until the lock clears. Only renewal evidence advances
203
203
  `renewedCycleNumber`. Every other projection leaves it untouched, or initializes it to the row's
204
204
  current cycle when it is still null on a legacy row, so a webhook or endpoint that writes the new
205
- cycle first cannot absorb the renewal (F13). Every lifecycle CAS includes the marker, so a
205
+ cycle first cannot absorb the renewal (F13). A subscription first linked after it already renewed starts at the
206
+ first cycle, so its next renewal evidence reports the missed renewal once (F28). Every lifecycle CAS includes the marker, so a
206
207
  projection prepared before a renewal callback cannot roll it back and let a second renewal event
207
208
  deliver the callback again (F14). StreamPay's cycle counter is the renewal identity because period
208
209
  boundaries drift: live sandbox subscriptions started in July read cycle 5 in November, and their
@@ -328,6 +329,7 @@ PostgreSQL 17. Run the end-to-end tests on PostgreSQL with `STREAMPAY_E2E_DB=pos
328
329
  | F25 | Low | 1 | A row in plan group B still holding group A's slot. | Found by Gemini 4 Neon on re-review. StreamPay moves a subscription to a product in another configured group outside the plugin, and a customer endpoint observes it before any webhook. The endpoint wrote the new group but only moved the slot on a revival. | Upgrades in group A are refused as already active, and group B can hold two live rows. | Endpoints move the slot whenever the desired slot differs |
329
330
  | F26 | Low | 2 | A released reservation whose link stays payable (breaks C2). | Found by Gemini 4 Neon on re-review. A stale-replacement release read the reservation without a link; its own request saved the link before the release write landed. | A payable link without a live reservation, next to the replacement's link. | The release CAS compares the link ID it read |
330
331
  | F27 | Medium | 6 | A renewal callback lock owned by a `completed` event. | Found by GPT-6.2 Astra in the final check of F21's fix. The discard completes the event, then the process stops before it clears the lock. | Every later renewal for that subscription retries until it dead-letters. | Renewal evidence releases a lock whose owning event is completed and continues in the same attempt, so the release cannot spend its last retry; it never queries a disabled inbox |
332
+ | F28 | Medium | 1, 6 | A paid checkout left `incomplete` and its renewals dropped, while every renewal event is `completed`. | The creation webhooks fail past StreamPay's retry window (or are delayed), and renewal evidence arrives first. `handleRenewalEvidence` found no linked row and returned. A later creation replay then started the renewal baseline at the current cycle. This was R11. | The customer has no access until someone replays the creation event, and `onSubscriptionRenewed` never runs for the cycles in between. Reproduced live; see below. | Renewal evidence links the reservation that owns the subscription's checkout link (StreamPay bills every cycle through it), and a first link at a later cycle starts the baseline at cycle 1. If a creation webhook links the row while the evidence is correlating, the evidence continues with that row (found by GPT-6.2 Astra and Gemini 4 Neon in review). Linking reuses the snapshot the evidence fetched, and the cycle-1 baseline applies only to a subscription's first link, never to a linked row that first learns its cycle number |
331
333
  | F14 | High | 6 | `renewedCycleNumber` rolled back after its callback ran, so a second renewal event delivers `onSubscriptionRenewed` again. | Found in review of the F13 fix. A customer endpoint (or webhook) reads the row, `INVOICE_COMPLETED` then advances the marker and runs the callback, and the endpoint write restores the old marker. Its CAS matched because the provider timestamp was unchanged. `SUBSCRIPTION_CYCLE_RENEWED_SUCCESSFULLY` then counted as a new renewal. | Duplicate per-cycle side effects. | Projections only initialize the marker, and every CAS includes it |
332
334
  | F15 | Medium | 7 | A due-queue retry before its backoff, or an automatic retry of a dead letter. | Pre-existing. Two overlapping `processDueStreampayWebhookEvents` runs select the same row. The first claims it and fails. The second replayed by event ID, re-read the updated row, and claimed it again at once, even after it was dead-lettered. | Extra provider calls and callback runs, and dead letters leaving manual review. | The processor passes the selected attempt (`dueAttemptCount`); replay requires the row to still be that pending attempt and due, and the claim CAS includes `attemptCount` |
333
335
  | F16 | Medium | 7 | A repaired event parked as unreplayable. | Found in review of F12. Replay reads a pending row without payload; a redelivery then claims it, stores its payload, fails, and schedules a retry; the stale parking write still matched `pending` and `lockedAt = null`. | The retry time is erased, so the due processor never retries the event. | Parking CAS includes `attemptCount` |
@@ -386,6 +388,17 @@ which is why both are treated as renewal evidence. The [cancel API](https://docs
386
388
  confirms `INACTIVE`, `TRIALING`, and `TRIAL_PENDING` are cancelled immediately and `ACTIVE` at
387
389
  period end.
388
390
 
391
+ **F28.** StreamPay bills every cycle through the checkout link: all five invoices of sandbox
392
+ subscription `a74dcc6a` (cycles 1 to 5) carry payment link `5fcf418c`, whose custom metadata holds
393
+ the plugin's plan, reference, and reservation row ID. `probe-r11-live.mjs` gives each build only the
394
+ reservation that owns that link, as if every creation webhook had failed, then delivers the real
395
+ `INVOICE_COMPLETED` for cycle 5.
396
+
397
+ | Build | Inbox | Reservation | `onSubscriptionRenewed` |
398
+ | --- | --- | --- | --- |
399
+ | 3.3.0 | `completed` | still `incomplete`, unlinked | none |
400
+ | With the fix | `completed` | `active`, linked to `a74dcc6a`, cycle 5 | one, for cycle 5 |
401
+
389
402
  **F10.** The sandbox exposes `latest_invoice` with `id` and `status` on the subscription, and a
390
403
  paid invoice reads `COMPLETED` (subscription `39143aaa`). An invoice's `period_end` does not match
391
404
  the subscription's (12 seconds apart), so the fix compares invoice IDs, not periods.
@@ -463,4 +476,4 @@ file covers F15 and F16; `tests/integration/review-findings.test.ts` covers F18
463
476
  | R8 | Confirmed as F12 and fixed. Parked rather than dead-lettered, so StreamPay retries still count (W4). | |
464
477
  | R9 | Confirmed as F13 and fixed. | |
465
478
  | R10 | Confirmed as F17 and fixed. | |
466
- | R11 | Renewal evidence for a subscription that is not yet linked to a local row is completed and dropped (`handleRenewalEvidence` finds no row). If the creation events fail past StreamPay's retry window and are replayed after a renewal, that cycle's `onSubscriptionRenewed` never runs. | Needs creation events to fail for about 20 hours across a billing boundary. Invoice events carry no plugin metadata, so the fix is to hold uncorrelated evidence for retry; left for a separate change. |
479
+ | R11 | Confirmed as F28 and fixed. Rows created by a webhook without any reservation (no plugin checkout link) still depend on their creation event. | |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-auth-streampay",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "description": "Community Better Auth plugin for StreamPay with consumers, checkout, portal, subscriptions, and signed webhooks. Not affiliated with Stream.",
5
5
  "license": "MIT",
6
6
  "type": "module",