@better-auth/stripe 1.3.4-beta.2 → 1.3.4

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.
@@ -1,17 +1,17 @@
1
1
 
2
- > @better-auth/stripe@1.3.4-beta.2 build /home/runner/work/better-auth/better-auth/packages/stripe
2
+ > @better-auth/stripe@1.3.4 build /home/runner/work/better-auth/better-auth/packages/stripe
3
3
  > unbuild
4
4
 
5
5
  [info] Automatically detected entries: src/index, src/client [esm] [cjs] [dts]
6
6
  [info] Building stripe
7
7
  [success] Build succeeded for stripe
8
- [log] dist/index.cjs (total size: 41.3 kB, chunk size: 41.3 kB, exports: stripe)
8
+ [log] dist/index.cjs (total size: 41.6 kB, chunk size: 41.6 kB, exports: stripe)
9
9
 
10
10
  [log] dist/client.cjs (total size: 224 B, chunk size: 224 B, exports: stripeClient)
11
11
 
12
- [log] dist/index.mjs (total size: 40.5 kB, chunk size: 40.5 kB, exports: stripe)
12
+ [log] dist/index.mjs (total size: 40.9 kB, chunk size: 40.9 kB, exports: stripe)
13
13
 
14
14
  [log] dist/client.mjs (total size: 197 B, chunk size: 197 B, exports: stripeClient)
15
15
 
16
- Σ Total dist size (byte size): 204 kB
16
+ Σ Total dist size (byte size): 205 kB
17
17
  [log]
package/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ # @better-auth/stripe
2
+
3
+ ## 1.3.4
4
+
5
+ ### Patch Changes
6
+
7
+ - ac6baba: chore: fix typo on `freeTrial`
8
+ - c2fb1aa: Fix duplicate trials when switching plans
9
+ - 2bd2fa9: Added support for listing organization members with pagination, sorting, and filtering, and improved client inference for additional organization fields. Also fixed date handling in rate limits and tokens, improved Notion OAuth user extraction, and ensured session is always set in context.
10
+
11
+ Organization
12
+
13
+ - Added listMembers API with pagination, sorting, and filtering.
14
+ - Added membersLimit param to getFullOrganization.
15
+ - Improved client inference for additional fields in organization schemas.
16
+ - Bug Fixes
17
+ - Fixed date handling by casting DB values to Date objects before using date methods.
18
+ - Fixed Notion OAuth to extract user info correctly.
19
+ - Ensured session is set in context when reading from cookie cach
20
+
21
+ - Updated dependencies [2bd2fa9]
22
+ - better-auth@1.3.4
package/dist/index.cjs CHANGED
@@ -527,14 +527,16 @@ const stripe = (options) => {
527
527
  });
528
528
  }
529
529
  }
530
- const activeSubscription = customerId ? await client.subscriptions.list({
531
- customer: customerId,
532
- status: "active"
530
+ const activeSubscriptions = await client.subscriptions.list({
531
+ customer: customerId
533
532
  }).then(
534
- (res) => res.data.find(
535
- (subscription2) => subscription2.id === subscriptionToUpdate?.stripeSubscriptionId || ctx.body.subscriptionId
533
+ (res) => res.data.filter(
534
+ (sub) => sub.status === "active" || sub.status === "trialing"
536
535
  )
537
- ).catch((e) => null) : null;
536
+ );
537
+ const activeSubscription = activeSubscriptions.find(
538
+ (sub) => subscriptionToUpdate?.stripeSubscriptionId ? sub.id === subscriptionToUpdate?.stripeSubscriptionId : true
539
+ );
538
540
  const subscriptions = subscriptionToUpdate ? [subscriptionToUpdate] : await ctx.context.adapter.findMany({
539
541
  model: "subscription",
540
542
  where: [
@@ -558,6 +560,12 @@ const stripe = (options) => {
558
560
  return_url: getUrl(ctx, ctx.body.returnUrl || "/"),
559
561
  flow_data: {
560
562
  type: "subscription_update_confirm",
563
+ after_completion: {
564
+ type: "redirect",
565
+ redirect: {
566
+ return_url: getUrl(ctx, ctx.body.returnUrl || "/")
567
+ }
568
+ },
561
569
  subscription_update_confirm: {
562
570
  subscription: activeSubscription.id,
563
571
  items: [
@@ -605,7 +613,8 @@ const stripe = (options) => {
605
613
  //@ts-expect-error
606
614
  ctx
607
615
  );
608
- const freeTrail = plan.freeTrial ? {
616
+ const alreadyHasTrial = subscription.status === "trialing";
617
+ const freeTrial = !alreadyHasTrial && plan.freeTrial ? {
609
618
  trial_period_days: plan.freeTrial.days
610
619
  } : void 0;
611
620
  let priceIdToUse = void 0;
@@ -651,7 +660,7 @@ const stripe = (options) => {
651
660
  }
652
661
  ],
653
662
  subscription_data: {
654
- ...freeTrail
663
+ ...freeTrial
655
664
  },
656
665
  mode: "subscription",
657
666
  client_reference_id: referenceId,
package/dist/index.d.cts CHANGED
@@ -333,6 +333,11 @@ interface StripeOptions {
333
333
  enabled: boolean;
334
334
  };
335
335
  };
336
+ /**
337
+ * A callback to run after a stripe event is received
338
+ * @param event - Stripe Event
339
+ * @returns
340
+ */
336
341
  onEvent?: (event: Stripe.Event) => Promise<void>;
337
342
  /**
338
343
  * Schema for the stripe plugin
package/dist/index.d.mts CHANGED
@@ -333,6 +333,11 @@ interface StripeOptions {
333
333
  enabled: boolean;
334
334
  };
335
335
  };
336
+ /**
337
+ * A callback to run after a stripe event is received
338
+ * @param event - Stripe Event
339
+ * @returns
340
+ */
336
341
  onEvent?: (event: Stripe.Event) => Promise<void>;
337
342
  /**
338
343
  * Schema for the stripe plugin
package/dist/index.d.ts CHANGED
@@ -333,6 +333,11 @@ interface StripeOptions {
333
333
  enabled: boolean;
334
334
  };
335
335
  };
336
+ /**
337
+ * A callback to run after a stripe event is received
338
+ * @param event - Stripe Event
339
+ * @returns
340
+ */
336
341
  onEvent?: (event: Stripe.Event) => Promise<void>;
337
342
  /**
338
343
  * Schema for the stripe plugin
package/dist/index.mjs CHANGED
@@ -511,14 +511,16 @@ const stripe = (options) => {
511
511
  });
512
512
  }
513
513
  }
514
- const activeSubscription = customerId ? await client.subscriptions.list({
515
- customer: customerId,
516
- status: "active"
514
+ const activeSubscriptions = await client.subscriptions.list({
515
+ customer: customerId
517
516
  }).then(
518
- (res) => res.data.find(
519
- (subscription2) => subscription2.id === subscriptionToUpdate?.stripeSubscriptionId || ctx.body.subscriptionId
517
+ (res) => res.data.filter(
518
+ (sub) => sub.status === "active" || sub.status === "trialing"
520
519
  )
521
- ).catch((e) => null) : null;
520
+ );
521
+ const activeSubscription = activeSubscriptions.find(
522
+ (sub) => subscriptionToUpdate?.stripeSubscriptionId ? sub.id === subscriptionToUpdate?.stripeSubscriptionId : true
523
+ );
522
524
  const subscriptions = subscriptionToUpdate ? [subscriptionToUpdate] : await ctx.context.adapter.findMany({
523
525
  model: "subscription",
524
526
  where: [
@@ -542,6 +544,12 @@ const stripe = (options) => {
542
544
  return_url: getUrl(ctx, ctx.body.returnUrl || "/"),
543
545
  flow_data: {
544
546
  type: "subscription_update_confirm",
547
+ after_completion: {
548
+ type: "redirect",
549
+ redirect: {
550
+ return_url: getUrl(ctx, ctx.body.returnUrl || "/")
551
+ }
552
+ },
545
553
  subscription_update_confirm: {
546
554
  subscription: activeSubscription.id,
547
555
  items: [
@@ -589,7 +597,8 @@ const stripe = (options) => {
589
597
  //@ts-expect-error
590
598
  ctx
591
599
  );
592
- const freeTrail = plan.freeTrial ? {
600
+ const alreadyHasTrial = subscription.status === "trialing";
601
+ const freeTrial = !alreadyHasTrial && plan.freeTrial ? {
593
602
  trial_period_days: plan.freeTrial.days
594
603
  } : void 0;
595
604
  let priceIdToUse = void 0;
@@ -635,7 +644,7 @@ const stripe = (options) => {
635
644
  }
636
645
  ],
637
646
  subscription_data: {
638
- ...freeTrail
647
+ ...freeTrial
639
648
  },
640
649
  mode: "subscription",
641
650
  client_reference_id: referenceId,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@better-auth/stripe",
3
3
  "author": "Bereket Engida",
4
- "version": "1.3.4-beta.2",
4
+ "version": "1.3.4",
5
5
  "main": "dist/index.cjs",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -11,6 +11,9 @@
11
11
  ],
12
12
  "module": "dist/index.mjs",
13
13
  "description": "Stripe plugin for Better Auth",
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
14
17
  "exports": {
15
18
  ".": {
16
19
  "types": "./dist/index.d.ts",
@@ -35,7 +38,7 @@
35
38
  },
36
39
  "dependencies": {
37
40
  "zod": "^4.0.0",
38
- "better-auth": "^1.3.4-beta.2"
41
+ "better-auth": "^1.3.4"
39
42
  },
40
43
  "devDependencies": {
41
44
  "@types/better-sqlite3": "^7.6.12",
package/src/index.ts CHANGED
@@ -319,23 +319,20 @@ export const stripe = <O extends StripeOptions>(options: O) => {
319
319
  }
320
320
  }
321
321
 
322
- const activeSubscription = customerId
323
- ? await client.subscriptions
324
- .list({
325
- customer: customerId,
326
- status: "active",
327
- })
328
- .then((res) =>
329
- res.data.find(
330
- (subscription) =>
331
- subscription.id ===
332
- subscriptionToUpdate?.stripeSubscriptionId ||
333
- ctx.body.subscriptionId,
334
- ),
335
- )
336
- .catch((e) => null)
337
- : null;
338
-
322
+ const activeSubscriptions = await client.subscriptions
323
+ .list({
324
+ customer: customerId,
325
+ })
326
+ .then((res) =>
327
+ res.data.filter(
328
+ (sub) => sub.status === "active" || sub.status === "trialing",
329
+ ),
330
+ );
331
+ const activeSubscription = activeSubscriptions.find((sub) =>
332
+ subscriptionToUpdate?.stripeSubscriptionId
333
+ ? sub.id === subscriptionToUpdate?.stripeSubscriptionId
334
+ : true,
335
+ );
339
336
  const subscriptions = subscriptionToUpdate
340
337
  ? [subscriptionToUpdate]
341
338
  : await ctx.context.adapter.findMany<Subscription>({
@@ -370,6 +367,12 @@ export const stripe = <O extends StripeOptions>(options: O) => {
370
367
  return_url: getUrl(ctx, ctx.body.returnUrl || "/"),
371
368
  flow_data: {
372
369
  type: "subscription_update_confirm",
370
+ after_completion: {
371
+ type: "redirect",
372
+ redirect: {
373
+ return_url: getUrl(ctx, ctx.body.returnUrl || "/"),
374
+ },
375
+ },
373
376
  subscription_update_confirm: {
374
377
  subscription: activeSubscription.id,
375
378
  items: [
@@ -426,11 +429,13 @@ export const stripe = <O extends StripeOptions>(options: O) => {
426
429
  ctx,
427
430
  );
428
431
 
429
- const freeTrail = plan.freeTrial
430
- ? {
431
- trial_period_days: plan.freeTrial.days,
432
- }
433
- : undefined;
432
+ const alreadyHasTrial = subscription.status === "trialing";
433
+ const freeTrial =
434
+ !alreadyHasTrial && plan.freeTrial
435
+ ? {
436
+ trial_period_days: plan.freeTrial.days,
437
+ }
438
+ : undefined;
434
439
 
435
440
  let priceIdToUse: string | undefined = undefined;
436
441
  if (ctx.body.annual) {
@@ -480,7 +485,7 @@ export const stripe = <O extends StripeOptions>(options: O) => {
480
485
  },
481
486
  ],
482
487
  subscription_data: {
483
- ...freeTrail,
488
+ ...freeTrial,
484
489
  },
485
490
  mode: "subscription",
486
491
  client_reference_id: referenceId,
package/src/types.ts CHANGED
@@ -318,6 +318,11 @@ export interface StripeOptions {
318
318
  enabled: boolean;
319
319
  };
320
320
  };
321
+ /**
322
+ * A callback to run after a stripe event is received
323
+ * @param event - Stripe Event
324
+ * @returns
325
+ */
321
326
  onEvent?: (event: Stripe.Event) => Promise<void>;
322
327
  /**
323
328
  * Schema for the stripe plugin