better-auth-streampay 3.0.2 → 3.1.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.
@@ -327,22 +327,6 @@ declare const REFERENCE_ID_METADATA_KEY = "streampay_plugin_reference_id";
327
327
  declare const REFERENCE_TYPE_METADATA_KEY = "streampay_plugin_reference_type";
328
328
  declare const SUBSCRIPTION_ROW_ID_METADATA_KEY = "streampay_plugin_subscription_row_id";
329
329
 
330
- interface ResolvedPlans {
331
- list: readonly StreamPayPlanLike[];
332
- byName: Map<string, StreamPayPlanLike>;
333
- }
334
- type FeatureKey<P> = P extends {
335
- limits?: infer L;
336
- } ? L extends Record<string, unknown> ? Extract<keyof L, string> : string : string;
337
- declare function hasSubscriptionAccess(subscription: Pick<Subscription, "status" | "catalogMapped">, accessStatuses?: readonly SubscriptionStatus[]): boolean;
338
- declare function hasFeature<P extends StreamPayPlanLike>(subscription: Subscription, plan: P | undefined, feature: FeatureKey<P>, accessStatuses?: readonly SubscriptionStatus[]): boolean;
339
- interface LimitCheckResult {
340
- allowed: boolean;
341
- limit: number;
342
- remaining: number;
343
- }
344
- declare function checkLimit<P extends StreamPayPlanLike>(subscription: Subscription, plan: P | undefined, feature: FeatureKey<P>, requested: number, accessStatuses?: readonly SubscriptionStatus[]): LimitCheckResult;
345
-
346
330
  interface PluginAdapter {
347
331
  create: <T = unknown, D extends object = Record<string, unknown>>(args: {
348
332
  model: string;
@@ -368,6 +352,7 @@ interface PluginAdapter {
368
352
  where?: Array<{
369
353
  field: string;
370
354
  value: unknown;
355
+ operator?: "lt" | "lte";
371
356
  }>;
372
357
  limit?: number;
373
358
  offset?: number;
@@ -392,6 +377,22 @@ interface PluginAdapter {
392
377
  }) => Promise<number>;
393
378
  }
394
379
 
380
+ interface ResolvedPlans {
381
+ list: readonly StreamPayPlanLike[];
382
+ byName: Map<string, StreamPayPlanLike>;
383
+ }
384
+ type FeatureKey<P> = P extends {
385
+ limits?: infer L;
386
+ } ? L extends Record<string, unknown> ? Extract<keyof L, string> : string : string;
387
+ declare function hasSubscriptionAccess(subscription: Pick<Subscription, "status" | "catalogMapped">, accessStatuses?: readonly SubscriptionStatus[]): boolean;
388
+ declare function hasFeature<P extends StreamPayPlanLike>(subscription: Subscription, plan: P | undefined, feature: FeatureKey<P>, accessStatuses?: readonly SubscriptionStatus[]): boolean;
389
+ interface LimitCheckResult {
390
+ allowed: boolean;
391
+ limit: number;
392
+ remaining: number;
393
+ }
394
+ declare function checkLimit<P extends StreamPayPlanLike>(subscription: Subscription, plan: P | undefined, feature: FeatureKey<P>, requested: number, accessStatuses?: readonly SubscriptionStatus[]): LimitCheckResult;
395
+
395
396
  interface SyncContext {
396
397
  context: {
397
398
  adapter: PluginAdapter;
@@ -428,6 +429,10 @@ interface WebhookEventRow {
428
429
  lastError: string | null;
429
430
  lastErrorCode: string | null;
430
431
  }
432
+ interface WebhookReplayOptions {
433
+ /** Keep a failed replay retryable until the inbox attempt budget is spent instead of dead-lettering it. */
434
+ retryUntilExhausted?: boolean;
435
+ }
431
436
  declare function syncWebhookPayload(ctx: SyncContext, payload: StreamPayWebhookPayload, client: StreamPayClient, plans: ResolvedPlans, callbacks: SubscriptionCallbacks, options?: {
432
437
  dedupe?: boolean;
433
438
  rawBody?: string | null;
@@ -444,7 +449,7 @@ interface StreamPayPluginRegistry {
444
449
  rawBody?: string;
445
450
  signatureHeader?: string | null;
446
451
  }) => Promise<void>;
447
- replayWebhookEvent?: (ctx: GenericEndpointContext, eventId: string) => Promise<{
452
+ replayWebhookEvent?: (ctx: GenericEndpointContext, eventId: string, options?: WebhookReplayOptions) => Promise<{
448
453
  replayed: true;
449
454
  eventId: string;
450
455
  }>;
@@ -6962,6 +6967,21 @@ declare const webhooks: (webhooksOptions: WebhooksOptions) => (_options: StreamP
6962
6967
  }, {
6963
6968
  received: boolean;
6964
6969
  }>;
6970
+ processDueStreampayWebhookEvents: better_auth.StrictEndpoint<"/streampay/webhooks/process-due", {
6971
+ method: "POST";
6972
+ body: z.ZodOptional<z.ZodObject<{
6973
+ limit: z.ZodOptional<z.ZodNumber>;
6974
+ }, z.core.$strip>>;
6975
+ metadata: {
6976
+ SERVER_ONLY: true;
6977
+ };
6978
+ }, {
6979
+ succeeded: string[];
6980
+ failed: {
6981
+ eventId: string;
6982
+ error: string;
6983
+ }[];
6984
+ }>;
6965
6985
  };
6966
6986
  };
6967
6987
 
@@ -13145,6 +13165,21 @@ declare const streampay: <O extends StreamPayOptions>(options: O) => {
13145
13165
  }, {
13146
13166
  received: boolean;
13147
13167
  }>;
13168
+ processDueStreampayWebhookEvents: better_auth.StrictEndpoint<"/streampay/webhooks/process-due", {
13169
+ method: "POST";
13170
+ body: zod.ZodOptional<zod.ZodObject<{
13171
+ limit: zod.ZodOptional<zod.ZodNumber>;
13172
+ }, zod_v4_core.$strip>>;
13173
+ metadata: {
13174
+ SERVER_ONLY: true;
13175
+ };
13176
+ }, {
13177
+ succeeded: string[];
13178
+ failed: {
13179
+ eventId: string;
13180
+ error: string;
13181
+ }[];
13182
+ }>;
13148
13183
  };
13149
13184
  schema: {
13150
13185
  user: {
@@ -327,22 +327,6 @@ declare const REFERENCE_ID_METADATA_KEY = "streampay_plugin_reference_id";
327
327
  declare const REFERENCE_TYPE_METADATA_KEY = "streampay_plugin_reference_type";
328
328
  declare const SUBSCRIPTION_ROW_ID_METADATA_KEY = "streampay_plugin_subscription_row_id";
329
329
 
330
- interface ResolvedPlans {
331
- list: readonly StreamPayPlanLike[];
332
- byName: Map<string, StreamPayPlanLike>;
333
- }
334
- type FeatureKey<P> = P extends {
335
- limits?: infer L;
336
- } ? L extends Record<string, unknown> ? Extract<keyof L, string> : string : string;
337
- declare function hasSubscriptionAccess(subscription: Pick<Subscription, "status" | "catalogMapped">, accessStatuses?: readonly SubscriptionStatus[]): boolean;
338
- declare function hasFeature<P extends StreamPayPlanLike>(subscription: Subscription, plan: P | undefined, feature: FeatureKey<P>, accessStatuses?: readonly SubscriptionStatus[]): boolean;
339
- interface LimitCheckResult {
340
- allowed: boolean;
341
- limit: number;
342
- remaining: number;
343
- }
344
- declare function checkLimit<P extends StreamPayPlanLike>(subscription: Subscription, plan: P | undefined, feature: FeatureKey<P>, requested: number, accessStatuses?: readonly SubscriptionStatus[]): LimitCheckResult;
345
-
346
330
  interface PluginAdapter {
347
331
  create: <T = unknown, D extends object = Record<string, unknown>>(args: {
348
332
  model: string;
@@ -368,6 +352,7 @@ interface PluginAdapter {
368
352
  where?: Array<{
369
353
  field: string;
370
354
  value: unknown;
355
+ operator?: "lt" | "lte";
371
356
  }>;
372
357
  limit?: number;
373
358
  offset?: number;
@@ -392,6 +377,22 @@ interface PluginAdapter {
392
377
  }) => Promise<number>;
393
378
  }
394
379
 
380
+ interface ResolvedPlans {
381
+ list: readonly StreamPayPlanLike[];
382
+ byName: Map<string, StreamPayPlanLike>;
383
+ }
384
+ type FeatureKey<P> = P extends {
385
+ limits?: infer L;
386
+ } ? L extends Record<string, unknown> ? Extract<keyof L, string> : string : string;
387
+ declare function hasSubscriptionAccess(subscription: Pick<Subscription, "status" | "catalogMapped">, accessStatuses?: readonly SubscriptionStatus[]): boolean;
388
+ declare function hasFeature<P extends StreamPayPlanLike>(subscription: Subscription, plan: P | undefined, feature: FeatureKey<P>, accessStatuses?: readonly SubscriptionStatus[]): boolean;
389
+ interface LimitCheckResult {
390
+ allowed: boolean;
391
+ limit: number;
392
+ remaining: number;
393
+ }
394
+ declare function checkLimit<P extends StreamPayPlanLike>(subscription: Subscription, plan: P | undefined, feature: FeatureKey<P>, requested: number, accessStatuses?: readonly SubscriptionStatus[]): LimitCheckResult;
395
+
395
396
  interface SyncContext {
396
397
  context: {
397
398
  adapter: PluginAdapter;
@@ -428,6 +429,10 @@ interface WebhookEventRow {
428
429
  lastError: string | null;
429
430
  lastErrorCode: string | null;
430
431
  }
432
+ interface WebhookReplayOptions {
433
+ /** Keep a failed replay retryable until the inbox attempt budget is spent instead of dead-lettering it. */
434
+ retryUntilExhausted?: boolean;
435
+ }
431
436
  declare function syncWebhookPayload(ctx: SyncContext, payload: StreamPayWebhookPayload, client: StreamPayClient, plans: ResolvedPlans, callbacks: SubscriptionCallbacks, options?: {
432
437
  dedupe?: boolean;
433
438
  rawBody?: string | null;
@@ -444,7 +449,7 @@ interface StreamPayPluginRegistry {
444
449
  rawBody?: string;
445
450
  signatureHeader?: string | null;
446
451
  }) => Promise<void>;
447
- replayWebhookEvent?: (ctx: GenericEndpointContext, eventId: string) => Promise<{
452
+ replayWebhookEvent?: (ctx: GenericEndpointContext, eventId: string, options?: WebhookReplayOptions) => Promise<{
448
453
  replayed: true;
449
454
  eventId: string;
450
455
  }>;
@@ -6962,6 +6967,21 @@ declare const webhooks: (webhooksOptions: WebhooksOptions) => (_options: StreamP
6962
6967
  }, {
6963
6968
  received: boolean;
6964
6969
  }>;
6970
+ processDueStreampayWebhookEvents: better_auth.StrictEndpoint<"/streampay/webhooks/process-due", {
6971
+ method: "POST";
6972
+ body: z.ZodOptional<z.ZodObject<{
6973
+ limit: z.ZodOptional<z.ZodNumber>;
6974
+ }, z.core.$strip>>;
6975
+ metadata: {
6976
+ SERVER_ONLY: true;
6977
+ };
6978
+ }, {
6979
+ succeeded: string[];
6980
+ failed: {
6981
+ eventId: string;
6982
+ error: string;
6983
+ }[];
6984
+ }>;
6965
6985
  };
6966
6986
  };
6967
6987
 
@@ -13145,6 +13165,21 @@ declare const streampay: <O extends StreamPayOptions>(options: O) => {
13145
13165
  }, {
13146
13166
  received: boolean;
13147
13167
  }>;
13168
+ processDueStreampayWebhookEvents: better_auth.StrictEndpoint<"/streampay/webhooks/process-due", {
13169
+ method: "POST";
13170
+ body: zod.ZodOptional<zod.ZodObject<{
13171
+ limit: zod.ZodOptional<zod.ZodNumber>;
13172
+ }, zod_v4_core.$strip>>;
13173
+ metadata: {
13174
+ SERVER_ONLY: true;
13175
+ };
13176
+ }, {
13177
+ succeeded: string[];
13178
+ failed: {
13179
+ eventId: string;
13180
+ error: string;
13181
+ }[];
13182
+ }>;
13148
13183
  };
13149
13184
  schema: {
13150
13185
  user: {
@@ -578,7 +578,22 @@ the `handlers:` event ID prefix and support the existing authenticated admin rep
578
578
  The default is `false` to preserve existing installations that have no inbox table.
579
579
 
580
580
  Verified payloads are persisted when processing is claimed, so an interrupted delivery can be
581
- recovered after its two-minute lease expires. A callback that outlives the lease can run again
581
+ recovered after its two-minute lease expires. A delivery that arrives while another worker holds
582
+ the lease gets `503`, so StreamPay redelivers it instead of treating it as handled.
583
+
584
+ StreamPay redelivery is not a retry schedule you control. Run the server-only retry endpoint on a
585
+ schedule (for example every minute) so failed events are retried at `nextAttemptAt` and abandoned
586
+ leases are reclaimed:
587
+
588
+ ```ts
589
+ const { succeeded, failed } = await auth.api.processDueStreampayWebhookEvents({
590
+ body: { limit: 25 },
591
+ });
592
+ ```
593
+
594
+ It processes pending events whose retry time has passed or whose lease expired, keeps failures
595
+ 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 callback that outlives the lease can run again
582
597
  when another delivery claims it. Callbacks must still be idempotent: a crash after an external
583
598
  side effect, or failure of a later callback, can repeat earlier work on retry. Inbox deduplication
584
599
  does not provide exactly-once execution of external side effects.
@@ -124,7 +124,7 @@ processing idempotent and observable.
124
124
  | `eventType` | string, required | StreamPay event such as `SUBSCRIPTION_PLAN_UPDATED`. Useful for routing, debugging, and operations. |
125
125
  | `receivedAt` | date, required, indexed | First receipt time. |
126
126
  | `lastAttemptAt` | nullable date, indexed | Most recent processing/replay attempt. |
127
- | `nextAttemptAt` | nullable date, indexed | Earliest automatic retry time after transient failure. |
127
+ | `nextAttemptAt` | nullable date, indexed | Earliest time `processDueStreampayWebhookEvents` retries the event after a transient failure. |
128
128
  | `completedAt` | nullable date, indexed | Successful completion time. Completed events no longer retain replay payload/signature data. |
129
129
  | `deadLetteredAt` | nullable date, indexed | Time a permanent failure or exhausted retry budget moved the event to manual review. |
130
130
  | `lockedAt` | nullable date, indexed | Start time of the current processing lease. Stale leases can be safely reclaimed. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-auth-streampay",
3
- "version": "3.0.2",
3
+ "version": "3.1.0",
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",