@better-auth/stripe 1.8.0-beta.8 → 1.8.0-beta.9

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.mts CHANGED
@@ -1,5 +1,4 @@
1
- import { l as StripePlan, n as stripe } from "./index-C_aP9Dqi.mjs";
2
- //#region src/error-codes.d.ts
1
+ import { l as StripePlan, n as stripe } from "./index-CEnreyM7.mjs";
3
2
  export declare const STRIPE_ERROR_CODES: {
4
3
  UNAUTHORIZED: import("better-auth").RawError<"UNAUTHORIZED">;
5
4
  INVALID_REQUEST_BODY: import("better-auth").RawError<"INVALID_REQUEST_BODY">;
@@ -25,8 +24,6 @@ export declare const STRIPE_ERROR_CODES: {
25
24
  ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION: import("better-auth").RawError<"ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION">;
26
25
  ORGANIZATION_REFERENCE_ID_REQUIRED: import("better-auth").RawError<"ORGANIZATION_REFERENCE_ID_REQUIRED">;
27
26
  };
28
- //#endregion
29
- //#region src/client.d.ts
30
27
  export declare const stripeClient: <O extends {
31
28
  subscription: boolean;
32
29
  }>(options?: O | undefined) => {
@@ -72,5 +69,4 @@ export declare const stripeClient: <O extends {
72
69
  ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION: import("better-auth").RawError<"ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION">;
73
70
  ORGANIZATION_REFERENCE_ID_REQUIRED: import("better-auth").RawError<"ORGANIZATION_REFERENCE_ID_REQUIRED">;
74
71
  };
75
- };
76
- //#endregion
72
+ };
package/dist/client.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { n as STRIPE_ERROR_CODES, t as PACKAGE_VERSION } from "./version-DFkXSjav.mjs";
2
- //#region src/client.ts
1
+ import { n as STRIPE_ERROR_CODES, t as PACKAGE_VERSION } from "./version-C0X8DPbc.mjs";
2
+ // src/client.ts
3
3
  const stripeClient = (options) => {
4
4
  return {
5
5
  id: "stripe-client",
@@ -12,5 +12,4 @@ const stripeClient = (options) => {
12
12
  $ERROR_CODES: STRIPE_ERROR_CODES
13
13
  };
14
14
  };
15
- //#endregion
16
15
  export { STRIPE_ERROR_CODES, stripeClient };
@@ -1,7 +1,6 @@
1
1
  import { GenericEndpointContext, InferOptionSchema, Session, User } from "better-auth";
2
2
  import { Organization } from "better-auth/plugins/organization";
3
3
  import Stripe from "stripe";
4
- //#region src/schema.d.ts
5
4
  declare const subscriptions: {
6
5
  subscription: {
7
6
  fields: {
@@ -100,8 +99,6 @@ declare const organization: {
100
99
  };
101
100
  };
102
101
  };
103
- //#endregion
104
- //#region src/types.d.ts
105
102
  type AuthorizeReferenceAction = "upgrade-subscription" | "list-subscription" | "cancel-subscription" | "restore-subscription" | "billing-portal";
106
103
  type CustomerType = "user" | "organization";
107
104
  type WithStripeCustomerId = {
@@ -498,8 +495,6 @@ interface StripeOptions {
498
495
  */
499
496
  schema?: InferOptionSchema<typeof subscriptions & typeof user & typeof organization> | undefined;
500
497
  }
501
- //#endregion
502
- //#region src/index.d.ts
503
498
  declare module "@better-auth/core" {
504
499
  interface BetterAuthPluginRegistry<AuthOptions, Options> {
505
500
  stripe: {
@@ -1089,5 +1084,4 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
1089
1084
  };
1090
1085
  };
1091
1086
  type StripePlugin<O extends StripeOptions> = ReturnType<typeof stripe<O>>;
1092
- //#endregion
1093
1087
  export { CheckoutSessionLocale as a, StripeOptions as c, SubscriptionOptions as d, WithActiveOrganizationId as f, CheckoutSessionLineItem as i, StripePlan as l, stripe as n, CustomerType as o, WithStripeCustomerId as p, AuthorizeReferenceAction as r, StripeCtxSession as s, StripePlugin as t, Subscription as u };
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as CheckoutSessionLocale, c as StripeOptions, d as SubscriptionOptions, f as WithActiveOrganizationId, i as CheckoutSessionLineItem, l as StripePlan, n as stripe, o as CustomerType, p as WithStripeCustomerId, r as AuthorizeReferenceAction, s as StripeCtxSession, t as StripePlugin, u as Subscription } from "./index-C_aP9Dqi.mjs";
1
+ import { a as CheckoutSessionLocale, c as StripeOptions, d as SubscriptionOptions, f as WithActiveOrganizationId, i as CheckoutSessionLineItem, l as StripePlan, n as stripe, o as CustomerType, p as WithStripeCustomerId, r as AuthorizeReferenceAction, s as StripeCtxSession, t as StripePlugin, u as Subscription } from "./index-CEnreyM7.mjs";
2
2
  export { type AuthorizeReferenceAction, type CheckoutSessionLineItem, type CheckoutSessionLocale, type CustomerType, type StripeCtxSession, type StripeOptions, type StripePlan, StripePlugin, type Subscription, type SubscriptionOptions, type WithActiveOrganizationId, type WithStripeCustomerId, stripe };
package/dist/index.mjs CHANGED
@@ -1,11 +1,11 @@
1
- import { n as STRIPE_ERROR_CODES, t as PACKAGE_VERSION } from "./version-DFkXSjav.mjs";
1
+ import { n as STRIPE_ERROR_CODES, t as PACKAGE_VERSION } from "./version-C0X8DPbc.mjs";
2
2
  import { APIError } from "@better-auth/core/error";
3
3
  import { defu } from "defu";
4
4
  import { HIDE_METADATA, createAuthEndpoint, createAuthMiddleware } from "@better-auth/core/api";
5
5
  import { getSessionFromCtx, originCheck, sessionMiddleware } from "better-auth/api";
6
6
  import * as z from "zod";
7
7
  import { mergeSchema } from "better-auth/db";
8
- //#region src/metadata.ts
8
+ // src/metadata.ts
9
9
  const UNSAFE_METADATA_KEYS = /* @__PURE__ */ new Set([
10
10
  "__proto__",
11
11
  "constructor",
@@ -73,8 +73,7 @@ const subscriptionMetadata = {
73
73
  };
74
74
  }
75
75
  };
76
- //#endregion
77
- //#region src/utils.ts
76
+ // src/utils.ts
78
77
  async function getPlans(subscriptionOptions) {
79
78
  if (subscriptionOptions?.enabled) return typeof subscriptionOptions.plans === "function" ? await subscriptionOptions.plans() : subscriptionOptions.plans;
80
79
  throw new Error("Subscriptions are not enabled in the Stripe options.");
@@ -144,8 +143,7 @@ async function resolvePlanItem(options, items) {
144
143
  plan: void 0
145
144
  } : void 0;
146
145
  }
147
- //#endregion
148
- //#region src/hooks.ts
146
+ // src/hooks.ts
149
147
  /**
150
148
  * Find organization or user by stripeCustomerId.
151
149
  * @internal
@@ -384,7 +382,14 @@ async function onSubscriptionUpdated(ctx, options, event) {
384
382
  return;
385
383
  }
386
384
  subscription = activeSub;
387
- } else subscription = subs[0];
385
+ } else {
386
+ const [onlySub] = subs;
387
+ if (!onlySub) {
388
+ ctx.context.logger.warn(`Stripe webhook warning: No subscription found for customerId: ${customerId}`);
389
+ return;
390
+ }
391
+ subscription = onlySub;
392
+ }
388
393
  }
389
394
  const seats = plan ? resolveQuantity(stripeSubscriptionUpdated.items.data, subscriptionItem, plan.seatPriceId) : subscriptionItem.quantity;
390
395
  const trial = stripeSubscriptionUpdated.trial_start && stripeSubscriptionUpdated.trial_end ? {
@@ -488,8 +493,7 @@ async function onSubscriptionDeleted(ctx, options, event) {
488
493
  ctx.context.logger.error(`Stripe webhook failed. Error: ${error}`);
489
494
  }
490
495
  }
491
- //#endregion
492
- //#region src/middleware.ts
496
+ // src/middleware.ts
493
497
  const stripeSessionMiddleware = createAuthMiddleware({ use: [sessionMiddleware] }, async (ctx) => {
494
498
  return { session: ctx.context.session };
495
499
  });
@@ -538,8 +542,7 @@ const referenceMiddleware = (options, action) => createAuthMiddleware(async (ctx
538
542
  customerType: "user"
539
543
  };
540
544
  });
541
- //#endregion
542
- //#region src/routes.ts
545
+ // src/routes.ts
543
546
  /**
544
547
  * Resolves a Stripe price object, either from a lookup key or by retrieving
545
548
  * by ID. Used to inspect `recurring.usage_type` for metered billing.
@@ -1644,8 +1647,7 @@ const stripeWebhook = (options) => {
1644
1647
  return ctx.json({ success: true });
1645
1648
  });
1646
1649
  };
1647
- //#endregion
1648
- //#region src/schema.ts
1650
+ // src/schema.ts
1649
1651
  const subscriptions = { subscription: { fields: {
1650
1652
  plan: {
1651
1653
  type: "string",
@@ -1745,8 +1747,7 @@ const getSchema = (options) => {
1745
1747
  }
1746
1748
  return mergeSchema(baseSchema, options.schema);
1747
1749
  };
1748
- //#endregion
1749
- //#region src/index.ts
1750
+ // src/index.ts
1750
1751
  const stripe = (options) => {
1751
1752
  const client = options.stripeClient;
1752
1753
  const subscriptionEndpoints = {
@@ -1985,5 +1986,4 @@ const stripe = (options) => {
1985
1986
  $ERROR_CODES: STRIPE_ERROR_CODES
1986
1987
  };
1987
1988
  };
1988
- //#endregion
1989
1989
  export { stripe };
@@ -1,5 +1,5 @@
1
1
  import { defineErrorCodes } from "@better-auth/core/utils/error-codes";
2
- //#region src/error-codes.ts
2
+ // src/error-codes.ts
3
3
  const STRIPE_ERROR_CODES = defineErrorCodes({
4
4
  UNAUTHORIZED: "Unauthorized access",
5
5
  INVALID_REQUEST_BODY: "Invalid request body",
@@ -28,8 +28,6 @@ const STRIPE_ERROR_CODES = defineErrorCodes({
28
28
  ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION: "Cannot delete organization with active subscription",
29
29
  ORGANIZATION_REFERENCE_ID_REQUIRED: "Reference ID is required. Provide referenceId or set activeOrganizationId in session"
30
30
  });
31
- //#endregion
32
- //#region src/version.ts
33
- const PACKAGE_VERSION = "1.8.0-beta.8";
34
- //#endregion
31
+ // src/version.ts
32
+ const PACKAGE_VERSION = "1.8.0-beta.9";
35
33
  export { STRIPE_ERROR_CODES as n, PACKAGE_VERSION as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/stripe",
3
- "version": "1.8.0-beta.8",
3
+ "version": "1.8.0-beta.9",
4
4
  "description": "Stripe plugin for Better Auth",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -55,17 +55,17 @@
55
55
  "zod": "^4.5.4"
56
56
  },
57
57
  "devDependencies": {
58
+ "@better-auth/core": "1.8.0-beta.9",
59
+ "better-auth": "1.8.0-beta.9",
58
60
  "better-call": "1.4.5",
59
61
  "stripe": "^23.0.0",
60
- "tsdown": "0.23.1",
61
- "better-auth": "1.8.0-beta.8",
62
- "@better-auth/core": "1.8.0-beta.8"
62
+ "tsdown": "0.23.1"
63
63
  },
64
64
  "peerDependencies": {
65
+ "@better-auth/core": "^1.8.0-beta.9",
66
+ "better-auth": "^1.8.0-beta.9",
65
67
  "better-call": "1.4.5",
66
- "stripe": "^18 || ^19 || ^20 || ^21 || ^22 || ^23",
67
- "@better-auth/core": "^1.8.0-beta.8",
68
- "better-auth": "^1.8.0-beta.8"
68
+ "stripe": "^18 || ^19 || ^20 || ^21 || ^22 || ^23"
69
69
  },
70
70
  "scripts": {
71
71
  "build": "tsdown",