better-auth-streampay 1.2.0 → 1.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.
@@ -5,17 +5,6 @@ import * as zod_v4_core from 'zod/v4/core';
5
5
  import * as zod from 'zod';
6
6
  import { z } from 'zod';
7
7
 
8
- /**
9
- * Plugin-level error taxonomy. Collapses StreamPay's raw 63-code enum
10
- * into billing-focused buckets callers can branch on stably. Raw
11
- * non-billing codes (MFA_*, SAUDI_ID_*, ORGANIZATION_*, …) fall through
12
- * to UNKNOWN — they originate from flows this plugin doesn't exercise.
13
- *
14
- * Shape follows Better Auth's `defineErrorCodes` so client-side error
15
- * reflections match the built-in plugins.
16
- *
17
- * Raw codes: https://stream-app-service.streampay.sa/openapi.json#/components/schemas/StreamErrorCodes
18
- */
19
8
  interface ErrorCodeEntry<K extends string> {
20
9
  code: K;
21
10
  message: string;
@@ -47,7 +36,6 @@ declare const $ERROR_CODES: {
47
36
  UNKNOWN: ErrorCodeEntry<"UNKNOWN">;
48
37
  };
49
38
  type StreamPayErrorCode = keyof typeof $ERROR_CODES;
50
- /** Priority: RAW_CODE_MAP → status classifier (401/403/404/422) → UNKNOWN. */
51
39
  declare function mapToErrorCode(rawCode: string | undefined, status: number | undefined): StreamPayErrorCode;
52
40
 
53
41
  interface StreamPaySessionUser {
@@ -69,12 +57,6 @@ type StreamPayPaymentLinkEventType = (typeof STREAMPAY_PAYMENT_LINK_EVENT_TYPES)
69
57
  declare const STREAMPAY_EVENT_TYPES: readonly ["PAYMENT_SUCCEEDED", "PAYMENT_FAILED", "PAYMENT_CANCELED", "PAYMENT_REFUNDED", "PAYMENT_MARKED_AS_PAID", "INVOICE_CREATED", "INVOICE_SENT", "INVOICE_ACCEPTED", "INVOICE_REJECTED", "INVOICE_COMPLETED", "INVOICE_CANCELED", "INVOICE_UPDATED", "SUBSCRIPTION_CREATED", "SUBSCRIPTION_ACTIVATED", "SUBSCRIPTION_INACTIVATED", "SUBSCRIPTION_CANCELED", "SUBSCRIPTION_FROZEN", "SUBSCRIPTION_CYCLE_RENEWAL_FAILED", "SUBSCRIPTION_CANCEL_AT_PERIOD_END", "SUBSCRIPTION_FREEZE_NOW", "SUBSCRIPTION_UNFREEZE_NOW", "SUBSCRIPTION_UNFREEZE_FUTURE", "SUBSCRIPTION_FREEZE_CANCEL", "PAYMENT_LINK_PAY_ATTEMPT_FAILED"];
70
58
  type StreamPayEventType = (typeof STREAMPAY_EVENT_TYPES)[number];
71
59
  type StreamPayEntityType = "PAYMENT" | "INVOICE" | "SUBSCRIPTION" | "PAYMENT_LINK";
72
- /**
73
- * `data` payload shape. Every entity pointer is optional — StreamPay's
74
- * example shows multiple keys populated at once (payment + invoice +
75
- * payment_link) and the docs don't guarantee any specific one for a
76
- * given event_type.
77
- */
78
60
  interface StreamPayWebhookData {
79
61
  metadata?: Record<string, unknown>;
80
62
  payment?: {
@@ -97,11 +79,6 @@ interface StreamPayWebhookEnvelope<TData extends StreamPayWebhookData = StreamPa
97
79
  timestamp: string;
98
80
  data: TData;
99
81
  }
100
- /**
101
- * Discriminated union of every documented webhook variant. Keying on
102
- * `event_type` narrows both `event_type` AND `entity_type` through a
103
- * switch — dispatcher calls the specific handler without assertions.
104
- */
105
82
  type StreamPayWebhookPayload<TEvent extends StreamPayEventType = StreamPayEventType, TEntity extends StreamPayEntityType = StreamPayEntityType, TData extends StreamPayWebhookData = StreamPayWebhookData> = Extract<StreamPayWebhookPayloadVariant<TData>, {
106
83
  event_type: TEvent;
107
84
  entity_type: TEntity;
@@ -181,20 +158,8 @@ type StreamPayWebhookPayloadVariant<TData extends StreamPayWebhookData = StreamP
181
158
  });
182
159
 
183
160
  type SubscriptionRecurringInterval = NonNullable<SubscriptionDetailed["recurring_interval"]>;
184
- /**
185
- * Local status — a superset of StreamPay's native
186
- * `INACTIVE | ACTIVE | EXPIRED | CANCELED | FROZEN`:
187
- * - `incomplete` — row pre-created at /upgrade; webhook not yet confirmed.
188
- * - `past_due` — renewal failed. StreamPay keeps `ACTIVE` during
189
- * dunning, which would misrepresent billing health.
190
- */
191
161
  type SubscriptionStatus = "incomplete" | "active" | "inactive" | "expired" | "canceled" | "frozen" | "past_due";
192
- /**
193
- * App-declared plan. `Limits` is generic so `hasFeature` / `checkLimit`
194
- * narrow the feature-name argument to the literal keys the app declared —
195
- * typos fail at compile time. `productId` must refer to a RECURRING
196
- * product whose `recurring_interval` matches `billingInterval`.
197
- */
162
+ /** A subscribable plan. `productId` must reference a RECURRING StreamPay product whose interval matches `billingInterval`. */
198
163
  interface StreamPayPlan<Limits extends Record<string, unknown> = Record<string, unknown>> {
199
164
  name: string;
200
165
  productId: string;
@@ -206,10 +171,6 @@ interface StreamPayPlan<Limits extends Record<string, unknown> = Record<string,
206
171
  }
207
172
  type StreamPayPlanLike = StreamPayPlan<Record<string, unknown>>;
208
173
  type PlansInput = readonly StreamPayPlanLike[] | (() => Promise<readonly StreamPayPlanLike[]> | readonly StreamPayPlanLike[]);
209
- /**
210
- * Row shape of the local `subscription` table. Nullable columns use
211
- * `T | null` (not `T | undefined`) to match Better Auth adapter semantics.
212
- */
213
174
  interface Subscription {
214
175
  id: string;
215
176
  referenceId: string;
@@ -253,38 +214,18 @@ interface AuthorizeReferenceContext {
253
214
  action: "upgrade" | "cancel" | "freeze" | "unfreeze" | "read" | "change-plan";
254
215
  }
255
216
  interface SubscriptionsOptionsBase extends SubscriptionCallbacks {
256
- /**
257
- * Subscribable plans — static array or async factory. Shape is
258
- * validated at plugin init; productId existence is checked on first
259
- * /upgrade call (lazy, needs the SDK client).
260
- */
261
217
  plans: PlansInput;
262
- /**
263
- * Additional authorization check per subscription endpoint. Fires
264
- * when the caller's `referenceId` matches their own session id, and
265
- * on every cross-account mutation.
266
- */
267
218
  authorizeReference?: (data: AuthorizeReferenceContext, ctx: GenericEndpointContext) => boolean | Promise<boolean>;
268
- /**
269
- * Per-event delivery attempt cap before the row is parked as
270
- * `dead_letter` and StreamPay is told to stop retrying. Default 10,
271
- * minimum 1 (values <1 are clamped). Tune lower for faster
272
- * surfacing of persistent bugs, higher to absorb longer transient
273
- * outages.
274
- */
275
219
  maxWebhookAttempts?: number;
276
220
  }
277
- /** `enableWebhookEventTable: true` requires `enableSubscriptionTable: true`. */
278
221
  type WebhookTablingOptions = {
279
- /** Default `true`. Set `false` to BYO state via `webhooks({ on* })`. */
280
222
  enableSubscriptionTable?: true;
281
- /** Default `true`. Set `false` if you handle webhook idempotency yourself
282
- * (Redis SETNX, etc.). StreamPay retries — you MUST dedupe externally. */
283
223
  enableWebhookEventTable?: boolean;
284
224
  } | {
285
225
  enableSubscriptionTable: false;
286
226
  enableWebhookEventTable?: false;
287
227
  };
228
+ /** Options for `subscriptions()`: the `plans` catalog, authorization, webhook dedupe, and lifecycle callbacks. */
288
229
  type SubscriptionsOptions = SubscriptionsOptionsBase & WebhookTablingOptions;
289
230
  declare const PLAN_NAME_METADATA_KEY = "streampay_plugin_plan_name";
290
231
  declare const REFERENCE_ID_METADATA_KEY = "streampay_plugin_reference_id";
@@ -293,17 +234,19 @@ interface ResolvedPlans {
293
234
  list: readonly StreamPayPlanLike[];
294
235
  byName: Map<string, StreamPayPlanLike>;
295
236
  }
296
- /** Returns `false` for non-active/frozen subs so expired plans can't leak entitlements. */
297
- declare function hasFeature(subscription: Subscription, plan: StreamPayPlanLike | undefined, feature: string): boolean;
237
+ type FeatureKey<P> = P extends {
238
+ limits?: infer L;
239
+ } ? L extends Record<string, unknown> ? Extract<keyof L, string> : string : string;
240
+ /** Whether the subscription's plan grants `feature`. Returns false for non-live (expired/canceled) subscriptions. */
241
+ declare function hasFeature<P extends StreamPayPlanLike>(subscription: Subscription, plan: P | undefined, feature: FeatureKey<P>): boolean;
298
242
  interface LimitCheckResult {
299
243
  allowed: boolean;
300
244
  limit: number;
301
245
  remaining: number;
302
246
  }
303
- /** Numeric-only quota check. Use `hasFeature` for binary gates. */
304
- declare function checkLimit(subscription: Subscription, plan: StreamPayPlanLike | undefined, feature: string, requested: number): LimitCheckResult;
247
+ /** Check a numeric quota (`feature`) on the subscription's plan against `count`. */
248
+ declare function checkLimit<P extends StreamPayPlanLike>(subscription: Subscription, plan: P | undefined, feature: FeatureKey<P>, requested: number): LimitCheckResult;
305
249
 
306
- /** Subset of Better Auth's `context.adapter` this plugin calls. */
307
250
  interface PluginAdapter {
308
251
  create: <T = unknown, D extends object = Record<string, unknown>>(args: {
309
252
  model: string;
@@ -382,48 +325,26 @@ interface WebhookEventRow {
382
325
  signatureHeader: string | null;
383
326
  lastError: string | null;
384
327
  }
385
- /**
386
- * Webhook sync entry. Called before userland handlers for every
387
- * payload. Idempotent via the `streampayWebhookEvent` state machine:
388
- * first delivery inserts a `pending` row, success flips it to
389
- * `completed`, repeated failure increments `attemptCount` and
390
- * eventually parks the row as `dead_letter` (caller returns 200 so
391
- * StreamPay stops retrying — replay is owned by the operator).
392
- *
393
- * Throws only on transient failures *while a row is still retryable*;
394
- * permanent bad-data modes log and return so StreamPay stops retrying.
395
- */
396
328
  declare function syncWebhookPayload(ctx: SyncContext, payload: StreamPayWebhookPayload, client: StreamPayClient, plans: ResolvedPlans, callbacks: SubscriptionCallbacks, options?: {
397
329
  dedupe?: boolean;
398
330
  rawBody?: string | null;
399
331
  signatureHeader?: string | null;
400
332
  maxAttempts?: number;
401
333
  }): Promise<void>;
402
- /** Permanent → 400 (stop retry). Transient → 500 (retry with backoff). */
403
334
  type WebhookSyncFailure = "PERMANENT" | "TRANSIENT";
404
335
  declare function classifyWebhookFailure(err: unknown): WebhookSyncFailure;
405
336
 
406
- /**
407
- * Shared registry the main `streampay()` plugin hands to each sub-plugin
408
- * factory. Used by sub-plugins that need request-time communication —
409
- * e.g. subscriptions sync → webhooks dispatch. Fresh per `streampay()` call.
410
- */
411
337
  interface StreamPayPluginRegistry {
412
338
  subscriptionWebhookSync?: (ctx: GenericEndpointContext, payload: StreamPayWebhookPayload, meta?: {
413
339
  rawBody?: string;
414
340
  signatureHeader?: string | null;
415
341
  }) => Promise<void>;
416
- /**
417
- * Replay a previously persisted webhook event (typically `dead_letter`
418
- * or stuck `pending`) by re-running the sync pipeline against its
419
- * stored `rawPayload`. Bypasses the dedupe gate — the row IS the
420
- * dedupe — and updates it to `completed` on success.
421
- */
422
342
  replayWebhookEvent?: (ctx: GenericEndpointContext, eventId: string) => Promise<{
423
343
  replayed: true;
424
344
  eventId: string;
425
345
  }>;
426
346
  }
347
+ /** Subscriptions sub-plugin: plan upgrades, cancellation, feature/limit checks, and webhook-driven subscription sync. */
427
348
  declare function subscriptions(subsOptions: SubscriptionsOptions): (options: StreamPayOptions, registry?: StreamPayPluginRegistry) => {
428
349
  schema?: {
429
350
  streampayWebhookEvent?: {
@@ -1224,25 +1145,15 @@ declare function subscriptions(subsOptions: SubscriptionsOptions): (options: Str
1224
1145
  };
1225
1146
  };
1226
1147
 
1227
- /**
1228
- * Back-office CRUD for StreamPay. Gated by a dual check: matches an
1229
- * `adminRoles` entry on `user.role`, OR the optional `isAdmin` callback
1230
- * returns true. Both absent ⇒ endpoint unreachable. `onRefund` and
1231
- * `onPlanChange` hooks run BEFORE the SDK call — throw from them to
1232
- * block an action.
1233
- */
1148
+ /** Options for `admin()`: role gating and back-office mutation hooks. */
1234
1149
  interface AdminOptions {
1235
- /** Role values that grant admin access. Comma-split like Better Auth. Default `["admin"]`. */
1236
1150
  adminRoles?: readonly string[];
1237
- /** Secondary check, called when `role` matching fails. */
1238
1151
  isAdmin?: (user: StreamPaySessionUser, ctx: GenericEndpointContext) => boolean | Promise<boolean>;
1239
- /** Pre-refund hook. Throw to block. */
1240
1152
  onRefund?: (ctx: {
1241
1153
  user: StreamPaySessionUser;
1242
1154
  paymentId: string;
1243
1155
  request: PaymentRefundRequest;
1244
1156
  }) => void | Promise<void>;
1245
- /** Pre-update hook. Receives current sub + incoming patch. */
1246
1157
  onPlanChange?: (ctx: {
1247
1158
  user: StreamPaySessionUser;
1248
1159
  subscriptionId: string;
@@ -1250,6 +1161,7 @@ interface AdminOptions {
1250
1161
  patch: SubscriptionUpdate;
1251
1162
  }) => void | Promise<void>;
1252
1163
  }
1164
+ /** Admin back-office sub-plugin. Exposes role-gated refund and subscription-management endpoints. */
1253
1165
  declare const admin: (adminOptions?: AdminOptions) => (options: StreamPayOptions, registry?: StreamPayPluginRegistry) => {
1254
1166
  endpoints: {
1255
1167
  adminListWebhookEvents: better_auth.StrictEndpoint<"/admin/streampay/webhook-events", {
@@ -3373,14 +3285,6 @@ declare const admin: (adminOptions?: AdminOptions) => (options: StreamPayOptions
3373
3285
  subscription_auto_renewal?: boolean | null;
3374
3286
  };
3375
3287
  }>;
3376
- /**
3377
- * Immediate cancel from admin. Unlike the consumer `/subscription/cancel`,
3378
- * this one bypasses the local ownership check — an admin can cancel
3379
- * any subscription by StreamPay id. Mirrors the SDK's
3380
- * `SubscriptionCancel` body shape verbatim (only
3381
- * `cancel_related_invoices`; no period-end flag — StreamPay doesn't
3382
- * expose one on this endpoint).
3383
- */
3384
3288
  adminCancelSubscription: better_auth.StrictEndpoint<"/admin/streampay/subscriptions/:id/cancel", {
3385
3289
  method: "POST";
3386
3290
  body: z.ZodObject<{}, z.core.$loose>;
@@ -3550,11 +3454,6 @@ declare const admin: (adminOptions?: AdminOptions) => (options: StreamPayOptions
3550
3454
  subscription_auto_renewal?: boolean | null;
3551
3455
  };
3552
3456
  }>;
3553
- /**
3554
- * Admin-initiated freeze. Creates a new freeze window on a
3555
- * subscription. Body matches `FreezeSubscriptionCreateRequest`
3556
- * from the SDK. Returns the created `FreezeSubscriptionBase`.
3557
- */
3558
3457
  adminFreezeSubscription: better_auth.StrictEndpoint<"/admin/streampay/subscriptions/:id/freeze", {
3559
3458
  method: "POST";
3560
3459
  body: z.ZodObject<{}, z.core.$loose>;
@@ -3592,12 +3491,6 @@ declare const admin: (adminOptions?: AdminOptions) => (options: StreamPayOptions
3592
3491
  invoice_id?: string;
3593
3492
  duration?: number | null;
3594
3493
  }>;
3595
- /**
3596
- * List all freeze windows attached to a subscription. Useful for
3597
- * UIs that show "this sub is frozen X times" or for the
3598
- * adminDeleteFreeze / adminUpdateFreeze flows below that need a
3599
- * freeze id.
3600
- */
3601
3494
  adminListSubscriptionFreezes: better_auth.StrictEndpoint<"/admin/streampay/subscriptions/:id/freeze", {
3602
3495
  method: "GET";
3603
3496
  use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
@@ -3644,13 +3537,6 @@ declare const admin: (adminOptions?: AdminOptions) => (options: StreamPayOptions
3644
3537
  has_previous_page?: boolean;
3645
3538
  };
3646
3539
  }>;
3647
- /**
3648
- * Update an existing freeze window (shift start/end, change notes).
3649
- * Matches SDK's `updateSubscriptionFreeze` which takes
3650
- * `FreezeSubscriptionUpdateRequest` — note that
3651
- * `freeze_start_datetime` is REQUIRED on update even if it doesn't
3652
- * change (per OpenAPI schema).
3653
- */
3654
3540
  adminUpdateSubscriptionFreeze: better_auth.StrictEndpoint<"/admin/streampay/subscriptions/:id/freeze/:freezeId", {
3655
3541
  method: "PUT";
3656
3542
  body: z.ZodObject<{}, z.core.$loose>;
@@ -3688,15 +3574,6 @@ declare const admin: (adminOptions?: AdminOptions) => (options: StreamPayOptions
3688
3574
  invoice_id?: string;
3689
3575
  duration?: number | null;
3690
3576
  }>;
3691
- /**
3692
- * Delete (unfreeze) a specific freeze window. This is how you
3693
- * "unfreeze" as an admin: find the active freeze id via
3694
- * adminListSubscriptionFreezes, then DELETE it.
3695
- *
3696
- * Returns `{ deleted: true }` on success — the SDK's
3697
- * `deleteSubscriptionFreeze` returns `void`, so we synthesize a
3698
- * response body for client feedback.
3699
- */
3700
3577
  adminDeleteSubscriptionFreeze: better_auth.StrictEndpoint<"/admin/streampay/subscriptions/:id/freeze/:freezeId", {
3701
3578
  method: "DELETE";
3702
3579
  disableBody: true;
@@ -3856,21 +3733,13 @@ declare const admin: (adminOptions?: AdminOptions) => (options: StreamPayOptions
3856
3733
  };
3857
3734
  };
3858
3735
 
3736
+ /** Options for `checkout()`: product catalog, redirect URLs, and auth gating. */
3859
3737
  interface CheckoutOptions {
3860
- /** Optional slug → productId mapping so callers can request `{ slug }` instead of hard-coding UUIDs. */
3861
3738
  products?: StreamPayProduct[] | (() => Promise<StreamPayProduct[]>);
3862
- /** Absolute or site-relative URL StreamPay redirects to on success. */
3863
3739
  successUrl?: string;
3864
- /** Absolute or site-relative URL StreamPay redirects to on failure. */
3865
3740
  failureUrl?: string;
3866
- /** Reject unauthenticated callers and anonymous sessions. */
3867
3741
  authenticatedUsersOnly?: boolean;
3868
- /**
3869
- * Contact-information type forwarded to StreamPay. The API evolves this
3870
- * enum, so we intentionally don't narrow beyond the two current values.
3871
- */
3872
3742
  contactInformationType?: "EMAIL" | "PHONE";
3873
- /** Custom fields forwarded on every created payment link. */
3874
3743
  customFields?: Record<string, unknown>;
3875
3744
  }
3876
3745
  declare const CheckoutBody: z.ZodObject<{
@@ -3880,7 +3749,6 @@ declare const CheckoutBody: z.ZodObject<{
3880
3749
  }, z.core.$strip>>, z.ZodArray<z.ZodString>, z.ZodString]>>;
3881
3750
  slug: z.ZodOptional<z.ZodString>;
3882
3751
  referenceId: z.ZodOptional<z.ZodString>;
3883
- consumerId: z.ZodOptional<z.ZodString>;
3884
3752
  name: z.ZodOptional<z.ZodString>;
3885
3753
  description: z.ZodOptional<z.ZodString>;
3886
3754
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
@@ -3892,6 +3760,7 @@ declare const CheckoutBody: z.ZodObject<{
3892
3760
  redirect: z.ZodOptional<z.ZodCoercedBoolean<unknown>>;
3893
3761
  }, z.core.$strip>;
3894
3762
  type CheckoutParams = z.infer<typeof CheckoutBody>;
3763
+ /** Hosted-checkout sub-plugin. Exposes `POST /streampay/checkout`, returning a StreamPay payment link. */
3895
3764
  declare const checkout: (checkoutOptions?: CheckoutOptions) => (options: StreamPayOptions) => {
3896
3765
  endpoints: {
3897
3766
  checkout: better_auth.StrictEndpoint<"/checkout", {
@@ -3903,7 +3772,6 @@ declare const checkout: (checkoutOptions?: CheckoutOptions) => (options: StreamP
3903
3772
  }, z.core.$strip>>, z.ZodArray<z.ZodString>, z.ZodString]>>;
3904
3773
  slug: z.ZodOptional<z.ZodString>;
3905
3774
  referenceId: z.ZodOptional<z.ZodString>;
3906
- consumerId: z.ZodOptional<z.ZodString>;
3907
3775
  name: z.ZodOptional<z.ZodString>;
3908
3776
  description: z.ZodOptional<z.ZodString>;
3909
3777
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
@@ -3922,13 +3790,11 @@ declare const checkout: (checkoutOptions?: CheckoutOptions) => (options: StreamP
3922
3790
  };
3923
3791
  };
3924
3792
 
3793
+ /** Options for `portal()`: page size for the billing-portal listings. */
3925
3794
  interface PortalOptions {
3926
- /**
3927
- * Rows per portal list call. Clamped to StreamPay's 100-row server
3928
- * cap. For UIs that need more, add a cursor param later.
3929
- */
3930
3795
  pageSize?: number;
3931
3796
  }
3797
+ /** Billing-portal sub-plugin. Exposes the consumer self-service billing endpoints. */
3932
3798
  declare const portal: ({ pageSize }?: PortalOptions) => (options: StreamPayOptions) => {
3933
3799
  endpoints: {
3934
3800
  state: better_auth.StrictEndpoint<"/consumer/state", {
@@ -4276,14 +4142,8 @@ declare const portal: ({ pageSize }?: PortalOptions) => (options: StreamPayOptio
4276
4142
  };
4277
4143
  };
4278
4144
 
4279
- /**
4280
- * Generic webhook handler. Parameterized on `event_type` and
4281
- * `entity_type` so per-event slots (`onPaymentSucceeded`, …) receive a
4282
- * payload narrowed to the exact literal StreamPay sent.
4283
- */
4284
4145
  type WebhookHandler<TEvent extends StreamPayEventType = StreamPayEventType, TEntity extends StreamPayEntityType = StreamPayEntityType, TData extends StreamPayWebhookData = StreamPayWebhookData> = (payload: StreamPayWebhookPayload<TEvent, TEntity, TData>) => Promise<void> | void;
4285
4146
  interface WebhookHandlers {
4286
- /** Catch-all. Runs BEFORE the specific handler. Wide payload. */
4287
4147
  onPayload?: WebhookHandler;
4288
4148
  onPaymentSucceeded?: WebhookHandler<"PAYMENT_SUCCEEDED", "PAYMENT">;
4289
4149
  onPaymentFailed?: WebhookHandler<"PAYMENT_FAILED", "PAYMENT">;
@@ -4312,15 +4172,12 @@ interface WebhookHandlers {
4312
4172
  }
4313
4173
  declare function dispatchWebhook(payload: StreamPayWebhookPayload, handlers: WebhookHandlers): Promise<void>;
4314
4174
 
4175
+ /** Options for `webhooks()`: the signing `secret` (single or rotated), freshness `toleranceSeconds`, and per-event handlers. */
4315
4176
  interface WebhooksOptions extends WebhookHandlers {
4316
- /**
4317
- * Shared secret configured in the StreamPay dashboard. Accepts a
4318
- * single value or an array of secrets for rolling rotation.
4319
- */
4320
4177
  secret: string | readonly string[];
4321
- /** Maximum age (seconds) a signed payload is considered fresh. */
4322
4178
  toleranceSeconds?: number;
4323
4179
  }
4180
+ /** Signed-webhook sub-plugin. Verifies StreamPay signatures and dispatches `POST /streampay/webhooks` to your handlers. */
4324
4181
  declare const webhooks: (webhooksOptions: WebhooksOptions) => (_options: StreamPayOptions, registry?: StreamPayPluginRegistry) => {
4325
4182
  endpoints: {
4326
4183
  streampayWebhooks: better_auth.StrictEndpoint<"/streampay/webhooks", {
@@ -4431,25 +4288,14 @@ interface ConsumerCreateOverrides {
4431
4288
  }
4432
4289
  type ClaimExistingConsumerIdentifier = "email" | "phone";
4433
4290
  type ClaimExistingConsumerBy = readonly ClaimExistingConsumerIdentifier[];
4291
+ /** Top-level options for `streampay()`: the SDK `client`, the `use` sub-plugins, and consumer-provisioning behavior. */
4434
4292
  interface StreamPayOptions {
4435
- /** StreamPay SDK client (or any value satisfying `StreamPayClient`). */
4436
4293
  client: StreamPayClient;
4437
- /**
4438
- * Eagerly create a StreamPay consumer on sign-up with
4439
- * `external_id: user.id`. Defaults to `false`; consumers are created
4440
- * lazily at first checkout or subscription mutation.
4441
- */
4442
4294
  createConsumerOnSignUp?: boolean;
4443
- /**
4444
- * Reclaim a duplicate consumer that matches by `email`, `phone`, or
4445
- * both. Omit to only reuse consumers with empty `external_id`.
4446
- */
4447
4295
  claimExistingConsumerBy?: ClaimExistingConsumerBy;
4448
- /** StreamPay-specific consumer fields supplied at creation time. */
4449
4296
  getConsumerCreateParams?: (data: {
4450
4297
  user: Partial<User>;
4451
4298
  }, request?: Request) => Promise<ConsumerCreateOverrides> | ConsumerCreateOverrides;
4452
- /** Sub-plugins composed into the main plugin. */
4453
4299
  use: StreamPayPlugins;
4454
4300
  }
4455
4301
 
@@ -4457,12 +4303,16 @@ interface StreamPayLoggerContext {
4457
4303
  context: {
4458
4304
  logger: {
4459
4305
  error: (message: string) => void;
4306
+ warn: (message: string) => void;
4307
+ info: (message: string) => void;
4308
+ debug: (message: string) => void;
4460
4309
  };
4461
4310
  };
4462
4311
  }
4463
4312
 
4464
4313
  type StreamPayHookContext = StreamPayLoggerContext;
4465
4314
 
4315
+ /** Better Auth plugin entry. Composes the StreamPay sub-plugins listed in `use` and wires the consumer lifecycle hooks. */
4466
4316
  declare const streampay: <O extends StreamPayOptions>(options: O) => {
4467
4317
  id: "streampay";
4468
4318
  version: string;
@@ -7043,7 +6893,6 @@ declare const streampay: <O extends StreamPayOptions>(options: O) => {
7043
6893
  }, zod_v4_core.$strip>>, zod.ZodArray<zod.ZodString>, zod.ZodString]>>;
7044
6894
  slug: zod.ZodOptional<zod.ZodString>;
7045
6895
  referenceId: zod.ZodOptional<zod.ZodString>;
7046
- consumerId: zod.ZodOptional<zod.ZodString>;
7047
6896
  name: zod.ZodOptional<zod.ZodString>;
7048
6897
  description: zod.ZodOptional<zod.ZodString>;
7049
6898
  metadata: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodUnion<readonly [zod.ZodString, zod.ZodNumber, zod.ZodBoolean]>>>;
@@ -8121,4 +7970,4 @@ declare const streampay: <O extends StreamPayOptions>(options: O) => {
8121
7970
  };
8122
7971
  };
8123
7972
 
8124
- export { $ERROR_CODES as $, type AdminOptions as A, type StreamPayPlugin as B, CheckoutBody as C, type StreamPayPluginRegistry as D, type ErrorCodeEntry as E, type StreamPayPlugins as F, type StreamPayProduct as G, type StreamPaySubscriptionEventType as H, type StreamPayWebhookData as I, type StreamPayWebhookPayload as J, type Subscription as K, type LimitCheckResult as L, type SubscriptionCallback as M, type SubscriptionCallbackData as N, type SubscriptionCallbacks as O, PLAN_NAME_METADATA_KEY as P, type SubscriptionStatus as Q, REFERENCE_ID_METADATA_KEY as R, type StreamPayErrorCode as S, type SubscriptionsOptions as T, type SyncContext as U, type WebhookHandlers as V, type WebhookHandler as W, type WebhookSyncFailure as X, type WebhooksOptions as Y, admin as Z, checkLimit as _, type StreamPayClient as a, checkout as a0, classifyWebhookFailure as a1, dispatchWebhook as a2, hasFeature as a3, mapToErrorCode as a4, portal as a5, subscriptions as a6, syncWebhookPayload as a7, webhooks as a8, type AuthorizeReferenceContext as b, type CheckoutOptions as c, type CheckoutParams as d, type ClaimExistingConsumerBy as e, type ClaimExistingConsumerIdentifier as f, type ConsumerCreateOverrides as g, type PluginAdapter as h, type PortalOptions as i, type ResolvedPlans as j, STREAMPAY_EVENT_TYPES as k, STREAMPAY_INVOICE_EVENT_TYPES as l, STREAMPAY_PAYMENT_EVENT_TYPES as m, STREAMPAY_PAYMENT_LINK_EVENT_TYPES as n, STREAMPAY_SUBSCRIPTION_EVENT_TYPES as o, type StreamPayEndpoints as p, type StreamPayEntityType as q, type StreamPayEventType as r, streampay as s, type StreamPayHookContext as t, type StreamPayInvoiceEventType as u, type StreamPayOptions as v, type StreamPayPaymentEventType as w, type StreamPayPaymentLinkEventType as x, type StreamPayPlan as y, type StreamPayPlanLike as z };
7973
+ export { $ERROR_CODES as $, type AdminOptions as A, type StreamPayPlugin as B, CheckoutBody as C, type StreamPayPluginRegistry as D, type ErrorCodeEntry as E, type FeatureKey as F, type StreamPayPlugins as G, type StreamPayProduct as H, type StreamPaySubscriptionEventType as I, type StreamPayWebhookData as J, type StreamPayWebhookPayload as K, type LimitCheckResult as L, type Subscription as M, type SubscriptionCallback as N, type SubscriptionCallbackData as O, PLAN_NAME_METADATA_KEY as P, type SubscriptionCallbacks as Q, REFERENCE_ID_METADATA_KEY as R, type StreamPayErrorCode as S, type SubscriptionStatus as T, type SubscriptionsOptions as U, type SyncContext as V, type WebhookHandler as W, type WebhookHandlers as X, type WebhookSyncFailure as Y, type WebhooksOptions as Z, admin as _, type StreamPayClient as a, checkLimit as a0, checkout as a1, classifyWebhookFailure as a2, dispatchWebhook as a3, hasFeature as a4, mapToErrorCode as a5, portal as a6, subscriptions as a7, syncWebhookPayload as a8, webhooks as a9, type AuthorizeReferenceContext as b, type CheckoutOptions as c, type CheckoutParams as d, type ClaimExistingConsumerBy as e, type ClaimExistingConsumerIdentifier as f, type ConsumerCreateOverrides as g, type PluginAdapter as h, type PortalOptions as i, type ResolvedPlans as j, STREAMPAY_EVENT_TYPES as k, STREAMPAY_INVOICE_EVENT_TYPES as l, STREAMPAY_PAYMENT_EVENT_TYPES as m, STREAMPAY_PAYMENT_LINK_EVENT_TYPES as n, STREAMPAY_SUBSCRIPTION_EVENT_TYPES as o, type StreamPayEndpoints as p, type StreamPayEntityType as q, type StreamPayEventType as r, streampay as s, type StreamPayHookContext as t, type StreamPayInvoiceEventType as u, type StreamPayOptions as v, type StreamPayPaymentEventType as w, type StreamPayPaymentLinkEventType as x, type StreamPayPlan as y, type StreamPayPlanLike as z };