@better-auth/stripe 1.6.20 → 1.6.22
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
package/dist/client.mjs
CHANGED
|
@@ -576,6 +576,8 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
576
576
|
}>)[];
|
|
577
577
|
}>) => Promise<{
|
|
578
578
|
session: StripeCtxSession;
|
|
579
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
580
|
+
referenceId: string;
|
|
579
581
|
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
580
582
|
}, {
|
|
581
583
|
url: string;
|
|
@@ -637,6 +639,8 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
637
639
|
}>)[];
|
|
638
640
|
}>) => Promise<{
|
|
639
641
|
session: StripeCtxSession;
|
|
642
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
643
|
+
referenceId: string;
|
|
640
644
|
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
641
645
|
}, {
|
|
642
646
|
url: string;
|
|
@@ -683,7 +687,9 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
683
687
|
}>)[];
|
|
684
688
|
}>) => Promise<{
|
|
685
689
|
session: StripeCtxSession;
|
|
686
|
-
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<
|
|
690
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
691
|
+
referenceId: string;
|
|
692
|
+
}>))[];
|
|
687
693
|
}, Stripe.Response<Stripe.Subscription>>;
|
|
688
694
|
listActiveSubscriptions: better_call0.StrictEndpoint<"/subscription/list", {
|
|
689
695
|
method: "GET";
|
|
@@ -725,7 +731,9 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
725
731
|
}>)[];
|
|
726
732
|
}>) => Promise<{
|
|
727
733
|
session: StripeCtxSession;
|
|
728
|
-
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<
|
|
734
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
735
|
+
referenceId: string;
|
|
736
|
+
}>))[];
|
|
729
737
|
}, {
|
|
730
738
|
limits: Record<string, unknown> | undefined;
|
|
731
739
|
priceId: string | undefined;
|
|
@@ -801,6 +809,8 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
801
809
|
}>)[];
|
|
802
810
|
}>) => Promise<{
|
|
803
811
|
session: StripeCtxSession;
|
|
812
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
813
|
+
referenceId: string;
|
|
804
814
|
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
805
815
|
}, {
|
|
806
816
|
url: string;
|
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-
|
|
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-ntN1joRP.mjs";
|
|
2
2
|
export { AuthorizeReferenceAction, CheckoutSessionLineItem, CheckoutSessionLocale, CustomerType, StripeCtxSession, StripeOptions, StripePlan, StripePlugin, Subscription, SubscriptionOptions, WithActiveOrganizationId, WithStripeCustomerId, stripe };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as STRIPE_ERROR_CODES, t as PACKAGE_VERSION } from "./version-
|
|
1
|
+
import { n as STRIPE_ERROR_CODES, t as PACKAGE_VERSION } from "./version-DJ9TCkHy.mjs";
|
|
2
2
|
import { APIError, HIDE_METADATA } from "better-auth";
|
|
3
3
|
import { defu } from "defu";
|
|
4
4
|
import { createAuthEndpoint, createAuthMiddleware } from "@better-auth/core/api";
|
|
@@ -451,7 +451,8 @@ async function onSubscriptionDeleted(ctx, options, event) {
|
|
|
451
451
|
const stripeSessionMiddleware = createAuthMiddleware({ use: [sessionMiddleware] }, async (ctx) => {
|
|
452
452
|
return { session: ctx.context.session };
|
|
453
453
|
});
|
|
454
|
-
const referenceMiddleware = (
|
|
454
|
+
const referenceMiddleware = (options, action) => createAuthMiddleware(async (ctx) => {
|
|
455
|
+
const subscriptionOptions = options.subscription;
|
|
455
456
|
const ctxSession = ctx.context.session;
|
|
456
457
|
if (!ctxSession) throw APIError$1.from("UNAUTHORIZED", STRIPE_ERROR_CODES.UNAUTHORIZED);
|
|
457
458
|
const customerType = ctx.body?.customerType || ctx.query?.customerType;
|
|
@@ -469,10 +470,10 @@ const referenceMiddleware = (subscriptionOptions, action) => createAuthMiddlewar
|
|
|
469
470
|
referenceId,
|
|
470
471
|
action
|
|
471
472
|
}, ctx)) throw APIError$1.from("UNAUTHORIZED", STRIPE_ERROR_CODES.UNAUTHORIZED);
|
|
472
|
-
return;
|
|
473
|
+
return { referenceId };
|
|
473
474
|
}
|
|
474
|
-
|
|
475
|
-
if (explicitReferenceId === ctxSession.user.id) return;
|
|
475
|
+
const referenceId = explicitReferenceId || ctxSession.user.id;
|
|
476
|
+
if (!explicitReferenceId || explicitReferenceId === ctxSession.user.id) return { referenceId };
|
|
476
477
|
if (!subscriptionOptions.authorizeReference) {
|
|
477
478
|
ctx.context.logger.error(`Passing referenceId into a subscription action isn't allowed if subscription.authorizeReference isn't defined in your stripe plugin config.`);
|
|
478
479
|
throw APIError$1.from("BAD_REQUEST", STRIPE_ERROR_CODES.REFERENCE_ID_NOT_ALLOWED);
|
|
@@ -480,9 +481,10 @@ const referenceMiddleware = (subscriptionOptions, action) => createAuthMiddlewar
|
|
|
480
481
|
if (!await subscriptionOptions.authorizeReference({
|
|
481
482
|
user: ctxSession.user,
|
|
482
483
|
session: ctxSession.session,
|
|
483
|
-
referenceId
|
|
484
|
+
referenceId,
|
|
484
485
|
action
|
|
485
486
|
}, ctx)) throw APIError$1.from("UNAUTHORIZED", STRIPE_ERROR_CODES.UNAUTHORIZED);
|
|
487
|
+
return { referenceId };
|
|
486
488
|
});
|
|
487
489
|
//#endregion
|
|
488
490
|
//#region src/routes.ts
|
|
@@ -520,21 +522,6 @@ function getUrl(ctx, url) {
|
|
|
520
522
|
return `${ctx.context.options.baseURL}${url.startsWith("/") ? url : `/${url}`}`;
|
|
521
523
|
}
|
|
522
524
|
/**
|
|
523
|
-
* Determines the reference ID based on customer type.
|
|
524
|
-
* - `user` (default): uses userId
|
|
525
|
-
* - `organization`: uses activeOrganizationId from session
|
|
526
|
-
* @internal
|
|
527
|
-
*/
|
|
528
|
-
function getReferenceId(ctxSession, customerType, options) {
|
|
529
|
-
const { user, session } = ctxSession;
|
|
530
|
-
if ((customerType || "user") === "organization") {
|
|
531
|
-
if (!options.organization?.enabled) throw APIError$1.from("BAD_REQUEST", STRIPE_ERROR_CODES.ORGANIZATION_SUBSCRIPTION_NOT_ENABLED);
|
|
532
|
-
if (!session.activeOrganizationId) throw APIError$1.from("BAD_REQUEST", STRIPE_ERROR_CODES.ORGANIZATION_NOT_FOUND);
|
|
533
|
-
return session.activeOrganizationId;
|
|
534
|
-
}
|
|
535
|
-
return user.id;
|
|
536
|
-
}
|
|
537
|
-
/**
|
|
538
525
|
* Retrieve the subscription a row points to, or `null` if it no longer exists
|
|
539
526
|
* (`resource_missing`) so callers can treat the row as stale.
|
|
540
527
|
* @internal
|
|
@@ -592,7 +579,7 @@ const upgradeSubscription = (options) => {
|
|
|
592
579
|
metadata: { openapi: { operationId: "upgradeSubscription" } },
|
|
593
580
|
use: [
|
|
594
581
|
stripeSessionMiddleware,
|
|
595
|
-
referenceMiddleware(
|
|
582
|
+
referenceMiddleware(options, "upgrade-subscription"),
|
|
596
583
|
originCheck((c) => {
|
|
597
584
|
return [
|
|
598
585
|
c.body.successUrl,
|
|
@@ -604,7 +591,7 @@ const upgradeSubscription = (options) => {
|
|
|
604
591
|
}, async (ctx) => {
|
|
605
592
|
const { user, session } = ctx.context.session;
|
|
606
593
|
const customerType = ctx.body.customerType || "user";
|
|
607
|
-
const referenceId = ctx.
|
|
594
|
+
const referenceId = ctx.context.referenceId;
|
|
608
595
|
if (!user.emailVerified && subscriptionOptions.requireEmailVerification) throw APIError$1.from("BAD_REQUEST", STRIPE_ERROR_CODES.EMAIL_VERIFICATION_REQUIRED);
|
|
609
596
|
const plan = await getPlanByName(options, ctx.body.plan);
|
|
610
597
|
if (!plan) throw APIError$1.from("BAD_REQUEST", STRIPE_ERROR_CODES.SUBSCRIPTION_PLAN_NOT_FOUND);
|
|
@@ -1097,19 +1084,17 @@ const cancelSubscriptionBodySchema = z.object({
|
|
|
1097
1084
|
*/
|
|
1098
1085
|
const cancelSubscription = (options) => {
|
|
1099
1086
|
const client = options.stripeClient;
|
|
1100
|
-
const subscriptionOptions = options.subscription;
|
|
1101
1087
|
return createAuthEndpoint("/subscription/cancel", {
|
|
1102
1088
|
method: "POST",
|
|
1103
1089
|
body: cancelSubscriptionBodySchema,
|
|
1104
1090
|
metadata: { openapi: { operationId: "cancelSubscription" } },
|
|
1105
1091
|
use: [
|
|
1106
1092
|
stripeSessionMiddleware,
|
|
1107
|
-
referenceMiddleware(
|
|
1093
|
+
referenceMiddleware(options, "cancel-subscription"),
|
|
1108
1094
|
originCheck((ctx) => ctx.body.returnUrl)
|
|
1109
1095
|
]
|
|
1110
1096
|
}, async (ctx) => {
|
|
1111
|
-
const
|
|
1112
|
-
const referenceId = ctx.body.referenceId || getReferenceId(ctx.context.session, customerType, options);
|
|
1097
|
+
const referenceId = ctx.context.referenceId;
|
|
1113
1098
|
let subscription = ctx.body.subscriptionId ? await ctx.context.adapter.findOne({
|
|
1114
1099
|
model: "subscription",
|
|
1115
1100
|
where: [{
|
|
@@ -1184,15 +1169,13 @@ const restoreSubscriptionBodySchema = z.object({
|
|
|
1184
1169
|
});
|
|
1185
1170
|
const restoreSubscription = (options) => {
|
|
1186
1171
|
const client = options.stripeClient;
|
|
1187
|
-
const subscriptionOptions = options.subscription;
|
|
1188
1172
|
return createAuthEndpoint("/subscription/restore", {
|
|
1189
1173
|
method: "POST",
|
|
1190
1174
|
body: restoreSubscriptionBodySchema,
|
|
1191
1175
|
metadata: { openapi: { operationId: "restoreSubscription" } },
|
|
1192
|
-
use: [stripeSessionMiddleware, referenceMiddleware(
|
|
1176
|
+
use: [stripeSessionMiddleware, referenceMiddleware(options, "restore-subscription")]
|
|
1193
1177
|
}, async (ctx) => {
|
|
1194
|
-
const
|
|
1195
|
-
const referenceId = ctx.body.referenceId || getReferenceId(ctx.context.session, customerType, options);
|
|
1178
|
+
const referenceId = ctx.context.referenceId;
|
|
1196
1179
|
let subscription = ctx.body.subscriptionId ? await ctx.context.adapter.findOne({
|
|
1197
1180
|
model: "subscription",
|
|
1198
1181
|
where: [{
|
|
@@ -1287,15 +1270,13 @@ const listActiveSubscriptionsQuerySchema = z.optional(z.object({
|
|
|
1287
1270
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/stripe#api-method-subscription-list)
|
|
1288
1271
|
*/
|
|
1289
1272
|
const listActiveSubscriptions = (options) => {
|
|
1290
|
-
const subscriptionOptions = options.subscription;
|
|
1291
1273
|
return createAuthEndpoint("/subscription/list", {
|
|
1292
1274
|
method: "GET",
|
|
1293
1275
|
query: listActiveSubscriptionsQuerySchema,
|
|
1294
1276
|
metadata: { openapi: { operationId: "listActiveSubscriptions" } },
|
|
1295
|
-
use: [stripeSessionMiddleware, referenceMiddleware(
|
|
1277
|
+
use: [stripeSessionMiddleware, referenceMiddleware(options, "list-subscription")]
|
|
1296
1278
|
}, async (ctx) => {
|
|
1297
|
-
const
|
|
1298
|
-
const referenceId = ctx.query?.referenceId || getReferenceId(ctx.context.session, customerType, options);
|
|
1279
|
+
const referenceId = ctx.context.referenceId;
|
|
1299
1280
|
const subscriptions = await ctx.context.adapter.findMany({
|
|
1300
1281
|
model: "subscription",
|
|
1301
1282
|
where: [{
|
|
@@ -1412,20 +1393,19 @@ const createBillingPortalBodySchema = z.object({
|
|
|
1412
1393
|
});
|
|
1413
1394
|
const createBillingPortal = (options) => {
|
|
1414
1395
|
const client = options.stripeClient;
|
|
1415
|
-
const subscriptionOptions = options.subscription;
|
|
1416
1396
|
return createAuthEndpoint("/subscription/billing-portal", {
|
|
1417
1397
|
method: "POST",
|
|
1418
1398
|
body: createBillingPortalBodySchema,
|
|
1419
1399
|
metadata: { openapi: { operationId: "createBillingPortal" } },
|
|
1420
1400
|
use: [
|
|
1421
1401
|
stripeSessionMiddleware,
|
|
1422
|
-
referenceMiddleware(
|
|
1402
|
+
referenceMiddleware(options, "billing-portal"),
|
|
1423
1403
|
originCheck((ctx) => ctx.body.returnUrl)
|
|
1424
1404
|
]
|
|
1425
1405
|
}, async (ctx) => {
|
|
1426
1406
|
const { user } = ctx.context.session;
|
|
1427
1407
|
const customerType = ctx.body.customerType || "user";
|
|
1428
|
-
const referenceId = ctx.
|
|
1408
|
+
const referenceId = ctx.context.referenceId;
|
|
1429
1409
|
let customerId;
|
|
1430
1410
|
if (customerType === "organization") {
|
|
1431
1411
|
customerId = (await ctx.context.adapter.findOne({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/stripe",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.22",
|
|
4
4
|
"description": "Stripe plugin for Better Auth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -55,17 +55,17 @@
|
|
|
55
55
|
"zod": "^4.3.6"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"better-call": "1.3.
|
|
58
|
+
"better-call": "1.3.7",
|
|
59
59
|
"stripe": "^22.0.1",
|
|
60
60
|
"tsdown": "0.21.1",
|
|
61
|
-
"@better-auth/core": "1.6.
|
|
62
|
-
"better-auth": "1.6.
|
|
61
|
+
"@better-auth/core": "1.6.22",
|
|
62
|
+
"better-auth": "1.6.22"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"better-call": "1.3.
|
|
65
|
+
"better-call": "1.3.7",
|
|
66
66
|
"stripe": "^18 || ^19 || ^20 || ^21 || ^22",
|
|
67
|
-
"@better-auth/core": "^1.6.
|
|
68
|
-
"better-auth": "^1.6.
|
|
67
|
+
"@better-auth/core": "^1.6.22",
|
|
68
|
+
"better-auth": "^1.6.22"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"build": "tsdown",
|