@better-auth/stripe 1.2.4-beta.3 → 1.2.4-beta.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.2.4-beta.3 build /home/runner/work/better-auth/better-auth/packages/stripe
2
+ > @better-auth/stripe@1.2.4-beta.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: 30.7 kB, chunk size: 30.7 kB, exports: stripe)
8
+ [log] dist/index.cjs (total size: 30.8 kB, chunk size: 30.8 kB, exports: stripe)
9
9
 
10
10
  [log] dist/client.cjs (total size: 160 B, chunk size: 160 B, exports: stripeClient)
11
11
 
12
- [log] dist/index.mjs (total size: 30.5 kB, chunk size: 30.5 kB, exports: stripe)
12
+ [log] dist/index.mjs (total size: 30.6 kB, chunk size: 30.6 kB, exports: stripe)
13
13
 
14
14
  [log] dist/client.mjs (total size: 133 B, chunk size: 133 B, exports: stripeClient)
15
15
 
16
- Σ Total dist size (byte size): 171 kB
16
+ Σ Total dist size (byte size): 173 kB
17
17
  [log]
package/dist/index.cjs CHANGED
@@ -324,7 +324,6 @@ const stripe = (options) => {
324
324
  seats: zod.z.number({
325
325
  description: "Number of seats to upgrade to (if applicable)"
326
326
  }).optional(),
327
- uiMode: zod.z.enum(["embedded", "hosted"]).default("hosted"),
328
327
  successUrl: zod.z.string({
329
328
  description: "callback url to redirect back after successful subscription"
330
329
  }).default("/"),
@@ -525,7 +524,8 @@ const stripe = (options) => {
525
524
  "/subscription/cancel/callback",
526
525
  {
527
526
  method: "GET",
528
- query: zod.z.record(zod.z.string(), zod.z.any()).optional()
527
+ query: zod.z.record(zod.z.string(), zod.z.any()).optional(),
528
+ use: [api.originCheck((ctx) => ctx.query.callbackURL)]
529
529
  },
530
530
  async (ctx) => {
531
531
  if (!ctx.query || !ctx.query.callbackURL || !ctx.query.reference) {
@@ -738,7 +738,8 @@ const stripe = (options) => {
738
738
  "/subscription/success",
739
739
  {
740
740
  method: "GET",
741
- query: zod.z.record(zod.z.string(), zod.z.any()).optional()
741
+ query: zod.z.record(zod.z.string(), zod.z.any()).optional(),
742
+ use: [api.originCheck((ctx) => ctx.query.callbackURL)]
742
743
  },
743
744
  async (ctx) => {
744
745
  if (!ctx.query || !ctx.query.callbackURL || !ctx.query.reference) {
package/dist/index.d.cts CHANGED
@@ -331,7 +331,6 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
331
331
  annual?: boolean | undefined;
332
332
  referenceId?: string | undefined;
333
333
  seats?: number | undefined;
334
- uiMode?: "embedded" | "hosted" | undefined;
335
334
  successUrl?: string | undefined;
336
335
  cancelUrl?: string | undefined;
337
336
  returnUrl?: string | undefined;
@@ -508,14 +507,12 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
508
507
  referenceId: z.ZodOptional<z.ZodString>;
509
508
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
510
509
  seats: z.ZodOptional<z.ZodNumber>;
511
- uiMode: z.ZodDefault<z.ZodEnum<["embedded", "hosted"]>>;
512
510
  successUrl: z.ZodDefault<z.ZodString>;
513
511
  cancelUrl: z.ZodDefault<z.ZodString>;
514
512
  returnUrl: z.ZodOptional<z.ZodString>;
515
513
  disableRedirect: z.ZodDefault<z.ZodBoolean>;
516
514
  }, "strip", z.ZodTypeAny, {
517
515
  plan: string;
518
- uiMode: "embedded" | "hosted";
519
516
  successUrl: string;
520
517
  cancelUrl: string;
521
518
  disableRedirect: boolean;
@@ -530,7 +527,6 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
530
527
  annual?: boolean | undefined;
531
528
  referenceId?: string | undefined;
532
529
  seats?: number | undefined;
533
- uiMode?: "embedded" | "hosted" | undefined;
534
530
  successUrl?: string | undefined;
535
531
  cancelUrl?: string | undefined;
536
532
  returnUrl?: string | undefined;
@@ -603,6 +599,15 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
603
599
  options: {
604
600
  method: "GET";
605
601
  query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
602
+ use: ((inputContext: {
603
+ body?: any;
604
+ query?: Record<string, any> | undefined;
605
+ request?: Request | undefined;
606
+ headers?: Headers | undefined;
607
+ asResponse?: boolean | undefined;
608
+ returnHeaders?: boolean | undefined;
609
+ use?: better_call.Middleware[] | undefined;
610
+ }) => Promise<void>)[];
606
611
  } & {
607
612
  use: any[];
608
613
  };
@@ -823,6 +828,15 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
823
828
  options: {
824
829
  method: "GET";
825
830
  query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
831
+ use: ((inputContext: {
832
+ body?: any;
833
+ query?: Record<string, any> | undefined;
834
+ request?: Request | undefined;
835
+ headers?: Headers | undefined;
836
+ asResponse?: boolean | undefined;
837
+ returnHeaders?: boolean | undefined;
838
+ use?: better_call.Middleware[] | undefined;
839
+ }) => Promise<void>)[];
826
840
  } & {
827
841
  use: any[];
828
842
  };
package/dist/index.d.mts CHANGED
@@ -331,7 +331,6 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
331
331
  annual?: boolean | undefined;
332
332
  referenceId?: string | undefined;
333
333
  seats?: number | undefined;
334
- uiMode?: "embedded" | "hosted" | undefined;
335
334
  successUrl?: string | undefined;
336
335
  cancelUrl?: string | undefined;
337
336
  returnUrl?: string | undefined;
@@ -508,14 +507,12 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
508
507
  referenceId: z.ZodOptional<z.ZodString>;
509
508
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
510
509
  seats: z.ZodOptional<z.ZodNumber>;
511
- uiMode: z.ZodDefault<z.ZodEnum<["embedded", "hosted"]>>;
512
510
  successUrl: z.ZodDefault<z.ZodString>;
513
511
  cancelUrl: z.ZodDefault<z.ZodString>;
514
512
  returnUrl: z.ZodOptional<z.ZodString>;
515
513
  disableRedirect: z.ZodDefault<z.ZodBoolean>;
516
514
  }, "strip", z.ZodTypeAny, {
517
515
  plan: string;
518
- uiMode: "embedded" | "hosted";
519
516
  successUrl: string;
520
517
  cancelUrl: string;
521
518
  disableRedirect: boolean;
@@ -530,7 +527,6 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
530
527
  annual?: boolean | undefined;
531
528
  referenceId?: string | undefined;
532
529
  seats?: number | undefined;
533
- uiMode?: "embedded" | "hosted" | undefined;
534
530
  successUrl?: string | undefined;
535
531
  cancelUrl?: string | undefined;
536
532
  returnUrl?: string | undefined;
@@ -603,6 +599,15 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
603
599
  options: {
604
600
  method: "GET";
605
601
  query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
602
+ use: ((inputContext: {
603
+ body?: any;
604
+ query?: Record<string, any> | undefined;
605
+ request?: Request | undefined;
606
+ headers?: Headers | undefined;
607
+ asResponse?: boolean | undefined;
608
+ returnHeaders?: boolean | undefined;
609
+ use?: better_call.Middleware[] | undefined;
610
+ }) => Promise<void>)[];
606
611
  } & {
607
612
  use: any[];
608
613
  };
@@ -823,6 +828,15 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
823
828
  options: {
824
829
  method: "GET";
825
830
  query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
831
+ use: ((inputContext: {
832
+ body?: any;
833
+ query?: Record<string, any> | undefined;
834
+ request?: Request | undefined;
835
+ headers?: Headers | undefined;
836
+ asResponse?: boolean | undefined;
837
+ returnHeaders?: boolean | undefined;
838
+ use?: better_call.Middleware[] | undefined;
839
+ }) => Promise<void>)[];
826
840
  } & {
827
841
  use: any[];
828
842
  };
package/dist/index.d.ts CHANGED
@@ -331,7 +331,6 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
331
331
  annual?: boolean | undefined;
332
332
  referenceId?: string | undefined;
333
333
  seats?: number | undefined;
334
- uiMode?: "embedded" | "hosted" | undefined;
335
334
  successUrl?: string | undefined;
336
335
  cancelUrl?: string | undefined;
337
336
  returnUrl?: string | undefined;
@@ -508,14 +507,12 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
508
507
  referenceId: z.ZodOptional<z.ZodString>;
509
508
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
510
509
  seats: z.ZodOptional<z.ZodNumber>;
511
- uiMode: z.ZodDefault<z.ZodEnum<["embedded", "hosted"]>>;
512
510
  successUrl: z.ZodDefault<z.ZodString>;
513
511
  cancelUrl: z.ZodDefault<z.ZodString>;
514
512
  returnUrl: z.ZodOptional<z.ZodString>;
515
513
  disableRedirect: z.ZodDefault<z.ZodBoolean>;
516
514
  }, "strip", z.ZodTypeAny, {
517
515
  plan: string;
518
- uiMode: "embedded" | "hosted";
519
516
  successUrl: string;
520
517
  cancelUrl: string;
521
518
  disableRedirect: boolean;
@@ -530,7 +527,6 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
530
527
  annual?: boolean | undefined;
531
528
  referenceId?: string | undefined;
532
529
  seats?: number | undefined;
533
- uiMode?: "embedded" | "hosted" | undefined;
534
530
  successUrl?: string | undefined;
535
531
  cancelUrl?: string | undefined;
536
532
  returnUrl?: string | undefined;
@@ -603,6 +599,15 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
603
599
  options: {
604
600
  method: "GET";
605
601
  query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
602
+ use: ((inputContext: {
603
+ body?: any;
604
+ query?: Record<string, any> | undefined;
605
+ request?: Request | undefined;
606
+ headers?: Headers | undefined;
607
+ asResponse?: boolean | undefined;
608
+ returnHeaders?: boolean | undefined;
609
+ use?: better_call.Middleware[] | undefined;
610
+ }) => Promise<void>)[];
606
611
  } & {
607
612
  use: any[];
608
613
  };
@@ -823,6 +828,15 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
823
828
  options: {
824
829
  method: "GET";
825
830
  query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
831
+ use: ((inputContext: {
832
+ body?: any;
833
+ query?: Record<string, any> | undefined;
834
+ request?: Request | undefined;
835
+ headers?: Headers | undefined;
836
+ asResponse?: boolean | undefined;
837
+ returnHeaders?: boolean | undefined;
838
+ use?: better_call.Middleware[] | undefined;
839
+ }) => Promise<void>)[];
826
840
  } & {
827
841
  use: any[];
828
842
  };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createAuthEndpoint, createAuthMiddleware } from 'better-auth/plugins';
2
2
  import { z } from 'zod';
3
- import { getSessionFromCtx, sessionMiddleware, originCheck, APIError } from 'better-auth/api';
3
+ import { originCheck, getSessionFromCtx, sessionMiddleware, APIError } from 'better-auth/api';
4
4
  import { generateRandomString } from 'better-auth/crypto';
5
5
  import { logger } from 'better-auth';
6
6
 
@@ -322,7 +322,6 @@ const stripe = (options) => {
322
322
  seats: z.number({
323
323
  description: "Number of seats to upgrade to (if applicable)"
324
324
  }).optional(),
325
- uiMode: z.enum(["embedded", "hosted"]).default("hosted"),
326
325
  successUrl: z.string({
327
326
  description: "callback url to redirect back after successful subscription"
328
327
  }).default("/"),
@@ -523,7 +522,8 @@ const stripe = (options) => {
523
522
  "/subscription/cancel/callback",
524
523
  {
525
524
  method: "GET",
526
- query: z.record(z.string(), z.any()).optional()
525
+ query: z.record(z.string(), z.any()).optional(),
526
+ use: [originCheck((ctx) => ctx.query.callbackURL)]
527
527
  },
528
528
  async (ctx) => {
529
529
  if (!ctx.query || !ctx.query.callbackURL || !ctx.query.reference) {
@@ -736,7 +736,8 @@ const stripe = (options) => {
736
736
  "/subscription/success",
737
737
  {
738
738
  method: "GET",
739
- query: z.record(z.string(), z.any()).optional()
739
+ query: z.record(z.string(), z.any()).optional(),
740
+ use: [originCheck((ctx) => ctx.query.callbackURL)]
740
741
  },
741
742
  async (ctx) => {
742
743
  if (!ctx.query || !ctx.query.callbackURL || !ctx.query.reference) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@better-auth/stripe",
3
3
  "author": "Bereket Engida",
4
- "version": "1.2.4-beta.3",
4
+ "version": "1.2.4-beta.4",
5
5
  "main": "dist/index.cjs",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "zod": "^3.24.1",
38
- "better-auth": "^1.2.4-beta.3"
38
+ "better-auth": "^1.2.4-beta.4"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/better-sqlite3": "^7.6.12",
package/src/index.ts CHANGED
@@ -92,7 +92,6 @@ export const stripe = <O extends StripeOptions>(options: O) => {
92
92
  description: "Number of seats to upgrade to (if applicable)",
93
93
  })
94
94
  .optional(),
95
- uiMode: z.enum(["embedded", "hosted"]).default("hosted"),
96
95
  successUrl: z
97
96
  .string({
98
97
  description:
@@ -338,6 +337,7 @@ export const stripe = <O extends StripeOptions>(options: O) => {
338
337
  {
339
338
  method: "GET",
340
339
  query: z.record(z.string(), z.any()).optional(),
340
+ use: [originCheck((ctx) => ctx.query.callbackURL)],
341
341
  },
342
342
  async (ctx) => {
343
343
  if (!ctx.query || !ctx.query.callbackURL || !ctx.query.reference) {
@@ -575,6 +575,7 @@ export const stripe = <O extends StripeOptions>(options: O) => {
575
575
  {
576
576
  method: "GET",
577
577
  query: z.record(z.string(), z.any()).optional(),
578
+ use: [originCheck((ctx) => ctx.query.callbackURL)],
578
579
  },
579
580
  async (ctx) => {
580
581
  if (!ctx.query || !ctx.query.callbackURL || !ctx.query.reference) {
@@ -298,7 +298,9 @@ describe("stripe", async () => {
298
298
  retrieve: vi.fn().mockResolvedValue(mockSubscription),
299
299
  },
300
300
  webhooks: {
301
- constructEvent: vi.fn().mockReturnValue(mockCheckoutSessionEvent),
301
+ constructEventAsync: vi
302
+ .fn()
303
+ .mockResolvedValue(mockCheckoutSessionEvent),
302
304
  },
303
305
  };
304
306
 
@@ -403,7 +405,7 @@ describe("stripe", async () => {
403
405
  const stripeForTest = {
404
406
  ...stripeOptions.stripeClient,
405
407
  webhooks: {
406
- constructEvent: vi.fn().mockReturnValue(mockDeleteEvent),
408
+ constructEventAsync: vi.fn().mockResolvedValue(mockDeleteEvent),
407
409
  },
408
410
  subscriptions: {
409
411
  retrieve: vi.fn().mockResolvedValue({
@@ -514,7 +516,7 @@ describe("stripe", async () => {
514
516
  retrieve: vi.fn().mockResolvedValue(mockSubscription),
515
517
  },
516
518
  webhooks: {
517
- constructEvent: vi.fn().mockReturnValue(completeEvent),
519
+ constructEventAsync: vi.fn().mockResolvedValue(completeEvent),
518
520
  },
519
521
  };
520
522
 
@@ -591,7 +593,9 @@ describe("stripe", async () => {
591
593
  },
592
594
  );
593
595
 
594
- mockStripeForEvents.webhooks.constructEvent.mockReturnValue(updateEvent);
596
+ mockStripeForEvents.webhooks.constructEventAsync.mockReturnValue(
597
+ updateEvent,
598
+ );
595
599
  await eventTestAuth.handler(updateRequest);
596
600
  expect(onSubscriptionUpdate).toHaveBeenCalledWith(
597
601
  expect.objectContaining({
@@ -632,7 +636,7 @@ describe("stripe", async () => {
632
636
  },
633
637
  );
634
638
 
635
- mockStripeForEvents.webhooks.constructEvent.mockReturnValue(
639
+ mockStripeForEvents.webhooks.constructEventAsync.mockReturnValue(
636
640
  userCancelEvent,
637
641
  );
638
642
  await eventTestAuth.handler(userCancelRequest);
@@ -664,7 +668,9 @@ describe("stripe", async () => {
664
668
  },
665
669
  );
666
670
 
667
- mockStripeForEvents.webhooks.constructEvent.mockReturnValue(cancelEvent);
671
+ mockStripeForEvents.webhooks.constructEventAsync.mockReturnValue(
672
+ cancelEvent,
673
+ );
668
674
  await eventTestAuth.handler(cancelRequest);
669
675
 
670
676
  expect(onSubscriptionCancel).toHaveBeenCalled();
@@ -695,7 +701,9 @@ describe("stripe", async () => {
695
701
  },
696
702
  );
697
703
 
698
- mockStripeForEvents.webhooks.constructEvent.mockReturnValue(deleteEvent);
704
+ mockStripeForEvents.webhooks.constructEventAsync.mockReturnValue(
705
+ deleteEvent,
706
+ );
699
707
  await eventTestAuth.handler(deleteRequest);
700
708
 
701
709
  expect(onSubscriptionDeleted).toHaveBeenCalled();