better-auth-streampay 3.1.0 → 3.3.0
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.
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/index.cjs +491 -223
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +491 -223
- package/dist/index.js.map +1 -1
- package/dist/{streampay-Bij1FvXa.d.cts → streampay-idQUxi7x.d.cts} +22 -2
- package/dist/{streampay-Bij1FvXa.d.ts → streampay-idQUxi7x.d.ts} +22 -2
- package/docs/integration.md +10 -4
- package/docs/staging-validation.md +3 -0
- package/docs/state-machines.md +466 -0
- package/docs/subscriptions.md +5 -1
- package/package.json +1 -1
|
@@ -240,6 +240,8 @@ interface Subscription {
|
|
|
240
240
|
periodStart: Date | null;
|
|
241
241
|
periodEnd: Date | null;
|
|
242
242
|
currentCycleNumber: number | null;
|
|
243
|
+
/** Latest provider cycle whose renewal was handled; the baseline for detecting the next renewal. */
|
|
244
|
+
renewedCycleNumber?: number | null;
|
|
243
245
|
/** Event that owns a projected cycle's pending renewal callback. */
|
|
244
246
|
renewalCallbackEventId?: string | null;
|
|
245
247
|
trialStart: Date | null;
|
|
@@ -430,8 +432,13 @@ interface WebhookEventRow {
|
|
|
430
432
|
lastErrorCode: string | null;
|
|
431
433
|
}
|
|
432
434
|
interface WebhookReplayOptions {
|
|
433
|
-
/**
|
|
435
|
+
/** @deprecated No effect: a failed replay keeps a pending event retryable until its attempts are spent. */
|
|
434
436
|
retryUntilExhausted?: boolean;
|
|
437
|
+
/**
|
|
438
|
+
* Set by `processDueStreampayWebhookEvents`: replay only if the event is still pending at this
|
|
439
|
+
* attempt and due. Otherwise the replay fails with `CONFLICT`.
|
|
440
|
+
*/
|
|
441
|
+
dueAttemptCount?: number;
|
|
435
442
|
}
|
|
436
443
|
declare function syncWebhookPayload(ctx: SyncContext, payload: StreamPayWebhookPayload, client: StreamPayClient, plans: ResolvedPlans, callbacks: SubscriptionCallbacks, options?: {
|
|
437
444
|
dedupe?: boolean;
|
|
@@ -440,6 +447,8 @@ declare function syncWebhookPayload(ctx: SyncContext, payload: StreamPayWebhookP
|
|
|
440
447
|
maxAttempts?: number;
|
|
441
448
|
retryOnCallbackError?: boolean;
|
|
442
449
|
retryingRenewalCallback?: boolean;
|
|
450
|
+
/** The inbox table exists. Defaults to `dedupe`; replay processes without dedupe but has an inbox. */
|
|
451
|
+
inboxEnabled?: boolean;
|
|
443
452
|
}): Promise<void>;
|
|
444
453
|
type WebhookSyncFailure = "PERMANENT" | "TRANSIENT";
|
|
445
454
|
declare function classifyWebhookFailure(err: unknown): WebhookSyncFailure;
|
|
@@ -449,7 +458,9 @@ interface StreamPayPluginRegistry {
|
|
|
449
458
|
rawBody?: string;
|
|
450
459
|
signatureHeader?: string | null;
|
|
451
460
|
}) => Promise<void>;
|
|
452
|
-
replayWebhookEvent?: (ctx: GenericEndpointContext, eventId: string,
|
|
461
|
+
replayWebhookEvent?: (ctx: GenericEndpointContext, eventId: string,
|
|
462
|
+
/** @deprecated No effect. */
|
|
463
|
+
options?: WebhookReplayOptions) => Promise<{
|
|
453
464
|
replayed: true;
|
|
454
465
|
eventId: string;
|
|
455
466
|
}>;
|
|
@@ -2369,6 +2380,7 @@ declare function subscriptions(subsOptions: SubscriptionsOptions): (options: Str
|
|
|
2369
2380
|
periodStart: Date | null;
|
|
2370
2381
|
periodEnd: Date | null;
|
|
2371
2382
|
currentCycleNumber: number | null;
|
|
2383
|
+
renewedCycleNumber?: number | null;
|
|
2372
2384
|
renewalCallbackEventId?: string | null;
|
|
2373
2385
|
trialStart: Date | null;
|
|
2374
2386
|
trialEnd: Date | null;
|
|
@@ -2448,6 +2460,7 @@ declare function subscriptions(subsOptions: SubscriptionsOptions): (options: Str
|
|
|
2448
2460
|
periodStart: Date | null;
|
|
2449
2461
|
periodEnd: Date | null;
|
|
2450
2462
|
currentCycleNumber: number | null;
|
|
2463
|
+
renewedCycleNumber?: number | null;
|
|
2451
2464
|
renewalCallbackEventId?: string | null;
|
|
2452
2465
|
trialStart: Date | null;
|
|
2453
2466
|
trialEnd: Date | null;
|
|
@@ -2741,6 +2754,11 @@ declare function subscriptions(subsOptions: SubscriptionsOptions): (options: Str
|
|
|
2741
2754
|
readonly type: "number";
|
|
2742
2755
|
readonly required: false;
|
|
2743
2756
|
};
|
|
2757
|
+
readonly renewedCycleNumber: {
|
|
2758
|
+
readonly type: "number";
|
|
2759
|
+
readonly required: false;
|
|
2760
|
+
readonly input: false;
|
|
2761
|
+
};
|
|
2744
2762
|
readonly renewalCallbackEventId: {
|
|
2745
2763
|
readonly type: "string";
|
|
2746
2764
|
readonly required: false;
|
|
@@ -12977,6 +12995,7 @@ declare const streampay: <O extends StreamPayOptions>(options: O) => {
|
|
|
12977
12995
|
periodStart: Date | null;
|
|
12978
12996
|
periodEnd: Date | null;
|
|
12979
12997
|
currentCycleNumber: number | null;
|
|
12998
|
+
renewedCycleNumber?: number | null;
|
|
12980
12999
|
renewalCallbackEventId?: string | null;
|
|
12981
13000
|
trialStart: Date | null;
|
|
12982
13001
|
trialEnd: Date | null;
|
|
@@ -13056,6 +13075,7 @@ declare const streampay: <O extends StreamPayOptions>(options: O) => {
|
|
|
13056
13075
|
periodStart: Date | null;
|
|
13057
13076
|
periodEnd: Date | null;
|
|
13058
13077
|
currentCycleNumber: number | null;
|
|
13078
|
+
renewedCycleNumber?: number | null;
|
|
13059
13079
|
renewalCallbackEventId?: string | null;
|
|
13060
13080
|
trialStart: Date | null;
|
|
13061
13081
|
trialEnd: Date | null;
|
|
@@ -240,6 +240,8 @@ interface Subscription {
|
|
|
240
240
|
periodStart: Date | null;
|
|
241
241
|
periodEnd: Date | null;
|
|
242
242
|
currentCycleNumber: number | null;
|
|
243
|
+
/** Latest provider cycle whose renewal was handled; the baseline for detecting the next renewal. */
|
|
244
|
+
renewedCycleNumber?: number | null;
|
|
243
245
|
/** Event that owns a projected cycle's pending renewal callback. */
|
|
244
246
|
renewalCallbackEventId?: string | null;
|
|
245
247
|
trialStart: Date | null;
|
|
@@ -430,8 +432,13 @@ interface WebhookEventRow {
|
|
|
430
432
|
lastErrorCode: string | null;
|
|
431
433
|
}
|
|
432
434
|
interface WebhookReplayOptions {
|
|
433
|
-
/**
|
|
435
|
+
/** @deprecated No effect: a failed replay keeps a pending event retryable until its attempts are spent. */
|
|
434
436
|
retryUntilExhausted?: boolean;
|
|
437
|
+
/**
|
|
438
|
+
* Set by `processDueStreampayWebhookEvents`: replay only if the event is still pending at this
|
|
439
|
+
* attempt and due. Otherwise the replay fails with `CONFLICT`.
|
|
440
|
+
*/
|
|
441
|
+
dueAttemptCount?: number;
|
|
435
442
|
}
|
|
436
443
|
declare function syncWebhookPayload(ctx: SyncContext, payload: StreamPayWebhookPayload, client: StreamPayClient, plans: ResolvedPlans, callbacks: SubscriptionCallbacks, options?: {
|
|
437
444
|
dedupe?: boolean;
|
|
@@ -440,6 +447,8 @@ declare function syncWebhookPayload(ctx: SyncContext, payload: StreamPayWebhookP
|
|
|
440
447
|
maxAttempts?: number;
|
|
441
448
|
retryOnCallbackError?: boolean;
|
|
442
449
|
retryingRenewalCallback?: boolean;
|
|
450
|
+
/** The inbox table exists. Defaults to `dedupe`; replay processes without dedupe but has an inbox. */
|
|
451
|
+
inboxEnabled?: boolean;
|
|
443
452
|
}): Promise<void>;
|
|
444
453
|
type WebhookSyncFailure = "PERMANENT" | "TRANSIENT";
|
|
445
454
|
declare function classifyWebhookFailure(err: unknown): WebhookSyncFailure;
|
|
@@ -449,7 +458,9 @@ interface StreamPayPluginRegistry {
|
|
|
449
458
|
rawBody?: string;
|
|
450
459
|
signatureHeader?: string | null;
|
|
451
460
|
}) => Promise<void>;
|
|
452
|
-
replayWebhookEvent?: (ctx: GenericEndpointContext, eventId: string,
|
|
461
|
+
replayWebhookEvent?: (ctx: GenericEndpointContext, eventId: string,
|
|
462
|
+
/** @deprecated No effect. */
|
|
463
|
+
options?: WebhookReplayOptions) => Promise<{
|
|
453
464
|
replayed: true;
|
|
454
465
|
eventId: string;
|
|
455
466
|
}>;
|
|
@@ -2369,6 +2380,7 @@ declare function subscriptions(subsOptions: SubscriptionsOptions): (options: Str
|
|
|
2369
2380
|
periodStart: Date | null;
|
|
2370
2381
|
periodEnd: Date | null;
|
|
2371
2382
|
currentCycleNumber: number | null;
|
|
2383
|
+
renewedCycleNumber?: number | null;
|
|
2372
2384
|
renewalCallbackEventId?: string | null;
|
|
2373
2385
|
trialStart: Date | null;
|
|
2374
2386
|
trialEnd: Date | null;
|
|
@@ -2448,6 +2460,7 @@ declare function subscriptions(subsOptions: SubscriptionsOptions): (options: Str
|
|
|
2448
2460
|
periodStart: Date | null;
|
|
2449
2461
|
periodEnd: Date | null;
|
|
2450
2462
|
currentCycleNumber: number | null;
|
|
2463
|
+
renewedCycleNumber?: number | null;
|
|
2451
2464
|
renewalCallbackEventId?: string | null;
|
|
2452
2465
|
trialStart: Date | null;
|
|
2453
2466
|
trialEnd: Date | null;
|
|
@@ -2741,6 +2754,11 @@ declare function subscriptions(subsOptions: SubscriptionsOptions): (options: Str
|
|
|
2741
2754
|
readonly type: "number";
|
|
2742
2755
|
readonly required: false;
|
|
2743
2756
|
};
|
|
2757
|
+
readonly renewedCycleNumber: {
|
|
2758
|
+
readonly type: "number";
|
|
2759
|
+
readonly required: false;
|
|
2760
|
+
readonly input: false;
|
|
2761
|
+
};
|
|
2744
2762
|
readonly renewalCallbackEventId: {
|
|
2745
2763
|
readonly type: "string";
|
|
2746
2764
|
readonly required: false;
|
|
@@ -12977,6 +12995,7 @@ declare const streampay: <O extends StreamPayOptions>(options: O) => {
|
|
|
12977
12995
|
periodStart: Date | null;
|
|
12978
12996
|
periodEnd: Date | null;
|
|
12979
12997
|
currentCycleNumber: number | null;
|
|
12998
|
+
renewedCycleNumber?: number | null;
|
|
12980
12999
|
renewalCallbackEventId?: string | null;
|
|
12981
13000
|
trialStart: Date | null;
|
|
12982
13001
|
trialEnd: Date | null;
|
|
@@ -13056,6 +13075,7 @@ declare const streampay: <O extends StreamPayOptions>(options: O) => {
|
|
|
13056
13075
|
periodStart: Date | null;
|
|
13057
13076
|
periodEnd: Date | null;
|
|
13058
13077
|
currentCycleNumber: number | null;
|
|
13078
|
+
renewedCycleNumber?: number | null;
|
|
13059
13079
|
renewalCallbackEventId?: string | null;
|
|
13060
13080
|
trialStart: Date | null;
|
|
13061
13081
|
trialEnd: Date | null;
|
package/docs/integration.md
CHANGED
|
@@ -105,6 +105,7 @@ ALTER TABLE subscription ADD COLUMN IF NOT EXISTS "catalogMapped" boolean DEFAUL
|
|
|
105
105
|
ALTER TABLE subscription ALTER COLUMN "catalogMapped" SET DEFAULT true;
|
|
106
106
|
UPDATE subscription SET "catalogMapped" = true WHERE "catalogMapped" IS NULL;
|
|
107
107
|
ALTER TABLE subscription ADD COLUMN IF NOT EXISTS "renewalCallbackEventId" text;
|
|
108
|
+
ALTER TABLE subscription ADD COLUMN IF NOT EXISTS "renewedCycleNumber" integer;
|
|
108
109
|
```
|
|
109
110
|
|
|
110
111
|
Use your configured table name and your database's boolean syntax when they differ. The column
|
|
@@ -593,16 +594,21 @@ const { succeeded, failed } = await auth.api.processDueStreampayWebhookEvents({
|
|
|
593
594
|
|
|
594
595
|
It processes pending events whose retry time has passed or whose lease expired, keeps failures
|
|
595
596
|
pending with backoff until the attempt budget is spent, and then dead-letters them. The endpoint
|
|
596
|
-
has no HTTP route. Dead-lettered events still need the admin replay endpoint. A
|
|
597
|
-
|
|
597
|
+
has no HTTP route. Dead-lettered events still need the admin replay endpoint. A failed admin
|
|
598
|
+
replay follows the same rules: a pending event stays pending unless the failure is permanent or
|
|
599
|
+
its attempts are spent, and a dead-lettered event returns to dead letter. A callback that outlives
|
|
600
|
+
the lease can run again when another delivery claims it. Callbacks must still be idempotent: a crash after an external
|
|
598
601
|
side effect, or failure of a later callback, can repeat earlier work on retry. Inbox deduplication
|
|
599
602
|
does not provide exactly-once execution of external side effects.
|
|
600
603
|
|
|
601
604
|
Typed handlers include `onPaymentPartiallyRefunded` and `onSubscriptionCycleRenewedSuccessfully`.
|
|
602
605
|
Successful renewal events reconcile billing state and share renewal inference with completed
|
|
603
606
|
invoices. The cycle update records its callback owner in `renewalCallbackEventId`; an interrupted
|
|
604
|
-
owner can resume on replay, and competing events cannot take its pending callback.
|
|
605
|
-
|
|
607
|
+
owner can resume on replay, and competing events cannot take its pending callback. A renewal is a
|
|
608
|
+
StreamPay cycle number above `renewedCycleNumber`, the last cycle whose renewal the plugin handled,
|
|
609
|
+
so a plan-change webhook or customer action that writes the new cycle first does not absorb the
|
|
610
|
+
callback. Apply both nullable columns before deploying; existing rows need no backfill. External
|
|
611
|
+
callback side effects still need idempotency.
|
|
606
612
|
|
|
607
613
|
The StreamPay SDK does not export webhook payload types. This package provides checked event
|
|
608
614
|
types based on StreamPay's documented payloads.
|
|
@@ -36,6 +36,9 @@ Tests cover the plugin's implemented features, not every feature of the Stream p
|
|
|
36
36
|
| Dynamic catalog stays stale | The upstream 2.2.1 resolver fix is retained and tested. |
|
|
37
37
|
| Renewal evidence invokes callbacks twice | PostgreSQL aligns invoice and subscription events at the same old cycle; a conditional update gives one callback winner. |
|
|
38
38
|
| Crash skips a renewal callback | SQLite simulates a lost update response and an interrupted worker; replay uses the durable callback owner. |
|
|
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
|
+
| 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
|
+
| 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). |
|
|
39
42
|
| Checkout activates the wrong reservation | Known payment-link and consumer mismatches cannot bind a pending checkout. |
|
|
40
43
|
| Portal client sends the wrong HTTP method | The real Better Auth client sends POST for the documented no-argument session call. |
|
|
41
44
|
| 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. |
|