better-auth-streampay 1.2.0 → 1.2.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.
@@ -293,15 +293,24 @@ interface ResolvedPlans {
293
293
  list: readonly StreamPayPlanLike[];
294
294
  byName: Map<string, StreamPayPlanLike>;
295
295
  }
296
+ /**
297
+ * Narrow `feature` to the literal keys of `plan.limits` when the caller
298
+ * passes a typed plan (e.g. `StreamPayPlan<{ maxEvents: number }>`).
299
+ * Falls back to `string` for the widened `StreamPayPlanLike` so existing
300
+ * call sites keep compiling without changes.
301
+ */
302
+ type FeatureKey<P> = P extends {
303
+ limits?: infer L;
304
+ } ? L extends Record<string, unknown> ? Extract<keyof L, string> : string : string;
296
305
  /** 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;
306
+ declare function hasFeature<P extends StreamPayPlanLike>(subscription: Subscription, plan: P | undefined, feature: FeatureKey<P>): boolean;
298
307
  interface LimitCheckResult {
299
308
  allowed: boolean;
300
309
  limit: number;
301
310
  remaining: number;
302
311
  }
303
312
  /** Numeric-only quota check. Use `hasFeature` for binary gates. */
304
- declare function checkLimit(subscription: Subscription, plan: StreamPayPlanLike | undefined, feature: string, requested: number): LimitCheckResult;
313
+ declare function checkLimit<P extends StreamPayPlanLike>(subscription: Subscription, plan: P | undefined, feature: FeatureKey<P>, requested: number): LimitCheckResult;
305
314
 
306
315
  /** Subset of Better Auth's `context.adapter` this plugin calls. */
307
316
  interface PluginAdapter {
@@ -4457,6 +4466,9 @@ interface StreamPayLoggerContext {
4457
4466
  context: {
4458
4467
  logger: {
4459
4468
  error: (message: string) => void;
4469
+ warn: (message: string) => void;
4470
+ info: (message: string) => void;
4471
+ debug: (message: string) => void;
4460
4472
  };
4461
4473
  };
4462
4474
  }
@@ -8121,4 +8133,4 @@ declare const streampay: <O extends StreamPayOptions>(options: O) => {
8121
8133
  };
8122
8134
  };
8123
8135
 
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 };
8136
+ 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 };
@@ -293,15 +293,24 @@ interface ResolvedPlans {
293
293
  list: readonly StreamPayPlanLike[];
294
294
  byName: Map<string, StreamPayPlanLike>;
295
295
  }
296
+ /**
297
+ * Narrow `feature` to the literal keys of `plan.limits` when the caller
298
+ * passes a typed plan (e.g. `StreamPayPlan<{ maxEvents: number }>`).
299
+ * Falls back to `string` for the widened `StreamPayPlanLike` so existing
300
+ * call sites keep compiling without changes.
301
+ */
302
+ type FeatureKey<P> = P extends {
303
+ limits?: infer L;
304
+ } ? L extends Record<string, unknown> ? Extract<keyof L, string> : string : string;
296
305
  /** 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;
306
+ declare function hasFeature<P extends StreamPayPlanLike>(subscription: Subscription, plan: P | undefined, feature: FeatureKey<P>): boolean;
298
307
  interface LimitCheckResult {
299
308
  allowed: boolean;
300
309
  limit: number;
301
310
  remaining: number;
302
311
  }
303
312
  /** Numeric-only quota check. Use `hasFeature` for binary gates. */
304
- declare function checkLimit(subscription: Subscription, plan: StreamPayPlanLike | undefined, feature: string, requested: number): LimitCheckResult;
313
+ declare function checkLimit<P extends StreamPayPlanLike>(subscription: Subscription, plan: P | undefined, feature: FeatureKey<P>, requested: number): LimitCheckResult;
305
314
 
306
315
  /** Subset of Better Auth's `context.adapter` this plugin calls. */
307
316
  interface PluginAdapter {
@@ -4457,6 +4466,9 @@ interface StreamPayLoggerContext {
4457
4466
  context: {
4458
4467
  logger: {
4459
4468
  error: (message: string) => void;
4469
+ warn: (message: string) => void;
4470
+ info: (message: string) => void;
4471
+ debug: (message: string) => void;
4460
4472
  };
4461
4473
  };
4462
4474
  }
@@ -8121,4 +8133,4 @@ declare const streampay: <O extends StreamPayOptions>(options: O) => {
8121
8133
  };
8122
8134
  };
8123
8135
 
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 };
8136
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-auth-streampay",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Community Better Auth plugin for StreamPay — consumers, checkout, portal, subscriptions, and signed webhooks. Not affiliated with Stream.",
5
5
  "license": "MIT",
6
6
  "type": "module",