@better-auth/stripe 1.5.0-beta.2 → 1.5.0-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.
- package/.turbo/turbo-build.log +9 -9
- package/CHANGELOG.md +15 -13
- package/LICENSE.md +15 -12
- package/dist/client.d.mts +105 -1
- package/dist/client.mjs +1 -1
- package/dist/error-codes-Bkj5yJMT.mjs +29 -0
- package/dist/{index-SbT5j9k6.d.mts → index-BnHmwMru.d.mts} +269 -154
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +449 -194
- package/package.json +7 -7
- package/src/error-codes.ts +16 -0
- package/src/hooks.ts +98 -71
- package/src/index.ts +142 -45
- package/src/middleware.ts +89 -42
- package/src/routes.ts +502 -224
- package/src/schema.ts +18 -0
- package/src/types.ts +75 -19
- package/src/utils.ts +11 -0
- package/test/stripe-organization.test.ts +1993 -0
- package/{src → test}/stripe.test.ts +821 -18
- package/dist/error-codes-qqooUh6R.mjs +0 -16
|
@@ -2,6 +2,7 @@ import * as better_auth0 from "better-auth";
|
|
|
2
2
|
import { GenericEndpointContext, InferOptionSchema, Session, User } from "better-auth";
|
|
3
3
|
import * as better_call0 from "better-call";
|
|
4
4
|
import * as zod0 from "zod";
|
|
5
|
+
import { Organization } from "better-auth/plugins/organization";
|
|
5
6
|
import Stripe from "stripe";
|
|
6
7
|
|
|
7
8
|
//#region src/schema.d.ts
|
|
@@ -78,8 +79,29 @@ declare const user: {
|
|
|
78
79
|
};
|
|
79
80
|
};
|
|
80
81
|
};
|
|
82
|
+
declare const organization: {
|
|
83
|
+
organization: {
|
|
84
|
+
fields: {
|
|
85
|
+
stripeCustomerId: {
|
|
86
|
+
type: "string";
|
|
87
|
+
required: false;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
};
|
|
81
92
|
//#endregion
|
|
82
93
|
//#region src/types.d.ts
|
|
94
|
+
type AuthorizeReferenceAction = "upgrade-subscription" | "list-subscription" | "cancel-subscription" | "restore-subscription" | "billing-portal";
|
|
95
|
+
type WithStripeCustomerId = {
|
|
96
|
+
stripeCustomerId?: string;
|
|
97
|
+
};
|
|
98
|
+
type WithActiveOrganizationId = {
|
|
99
|
+
activeOrganizationId?: string;
|
|
100
|
+
};
|
|
101
|
+
type StripeCtxSession = {
|
|
102
|
+
session: Session & WithActiveOrganizationId;
|
|
103
|
+
user: User & WithStripeCustomerId;
|
|
104
|
+
};
|
|
83
105
|
type StripePlan = {
|
|
84
106
|
/**
|
|
85
107
|
* Monthly price id
|
|
@@ -297,7 +319,7 @@ type SubscriptionOptions = {
|
|
|
297
319
|
user: User & Record<string, any>;
|
|
298
320
|
session: Session & Record<string, any>;
|
|
299
321
|
referenceId: string;
|
|
300
|
-
action:
|
|
322
|
+
action: AuthorizeReferenceAction;
|
|
301
323
|
}, ctx: GenericEndpointContext) => Promise<boolean>) | undefined;
|
|
302
324
|
/**
|
|
303
325
|
* A callback to run after a user has deleted their subscription
|
|
@@ -337,12 +359,6 @@ type SubscriptionOptions = {
|
|
|
337
359
|
params?: Stripe.Checkout.SessionCreateParams;
|
|
338
360
|
options?: Stripe.RequestOptions;
|
|
339
361
|
}) | undefined;
|
|
340
|
-
/**
|
|
341
|
-
* Enable organization subscription
|
|
342
|
-
*/
|
|
343
|
-
organization?: {
|
|
344
|
-
enabled: boolean;
|
|
345
|
-
} | undefined;
|
|
346
362
|
};
|
|
347
363
|
interface StripeOptions {
|
|
348
364
|
/**
|
|
@@ -367,9 +383,7 @@ interface StripeOptions {
|
|
|
367
383
|
*/
|
|
368
384
|
onCustomerCreate?: ((data: {
|
|
369
385
|
stripeCustomer: Stripe.Customer;
|
|
370
|
-
user: User &
|
|
371
|
-
stripeCustomerId: string;
|
|
372
|
-
};
|
|
386
|
+
user: User & WithStripeCustomerId;
|
|
373
387
|
}, ctx: GenericEndpointContext) => Promise<void>) | undefined;
|
|
374
388
|
/**
|
|
375
389
|
* A custom function to get the customer create
|
|
@@ -386,6 +400,37 @@ interface StripeOptions {
|
|
|
386
400
|
} | ({
|
|
387
401
|
enabled: true;
|
|
388
402
|
} & SubscriptionOptions)) | undefined;
|
|
403
|
+
/**
|
|
404
|
+
* Organization Stripe integration
|
|
405
|
+
*
|
|
406
|
+
* Enable organizations to have their own Stripe customer ID
|
|
407
|
+
*/
|
|
408
|
+
organization?: {
|
|
409
|
+
/**
|
|
410
|
+
* Enable organization Stripe customer
|
|
411
|
+
*/
|
|
412
|
+
enabled: true;
|
|
413
|
+
/**
|
|
414
|
+
* A custom function to get the customer create params
|
|
415
|
+
* for organization customers.
|
|
416
|
+
*
|
|
417
|
+
* @param organization - the organization
|
|
418
|
+
* @param ctx - the context object
|
|
419
|
+
* @returns
|
|
420
|
+
*/
|
|
421
|
+
getCustomerCreateParams?: ((organization: Organization, ctx: GenericEndpointContext) => Promise<Partial<Stripe.CustomerCreateParams>>) | undefined;
|
|
422
|
+
/**
|
|
423
|
+
* A callback to run after an organization customer has been created
|
|
424
|
+
*
|
|
425
|
+
* @param data - data containing stripeCustomer and organization
|
|
426
|
+
* @param ctx - the context object
|
|
427
|
+
* @returns
|
|
428
|
+
*/
|
|
429
|
+
onCustomerCreate?: ((data: {
|
|
430
|
+
stripeCustomer: Stripe.Customer;
|
|
431
|
+
organization: Organization & WithStripeCustomerId;
|
|
432
|
+
}, ctx: GenericEndpointContext) => Promise<void>) | undefined;
|
|
433
|
+
} | undefined;
|
|
389
434
|
/**
|
|
390
435
|
* A callback to run after a stripe event is received
|
|
391
436
|
* @param event - Stripe Event
|
|
@@ -395,10 +440,17 @@ interface StripeOptions {
|
|
|
395
440
|
/**
|
|
396
441
|
* Schema for the stripe plugin
|
|
397
442
|
*/
|
|
398
|
-
schema?: InferOptionSchema<typeof subscriptions & typeof user> | undefined;
|
|
443
|
+
schema?: InferOptionSchema<typeof subscriptions & typeof user & typeof organization> | undefined;
|
|
399
444
|
}
|
|
400
445
|
//#endregion
|
|
401
446
|
//#region src/index.d.ts
|
|
447
|
+
declare module "@better-auth/core" {
|
|
448
|
+
interface BetterAuthPluginRegistry<Auth, Context> {
|
|
449
|
+
stripe: {
|
|
450
|
+
creator: typeof stripe;
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
}
|
|
402
454
|
declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
403
455
|
id: "stripe";
|
|
404
456
|
endpoints: {
|
|
@@ -425,6 +477,10 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
425
477
|
annual: zod0.ZodOptional<zod0.ZodBoolean>;
|
|
426
478
|
referenceId: zod0.ZodOptional<zod0.ZodString>;
|
|
427
479
|
subscriptionId: zod0.ZodOptional<zod0.ZodString>;
|
|
480
|
+
customerType: zod0.ZodOptional<zod0.ZodEnum<{
|
|
481
|
+
user: "user";
|
|
482
|
+
organization: "organization";
|
|
483
|
+
}>>;
|
|
428
484
|
metadata: zod0.ZodOptional<zod0.ZodRecord<zod0.ZodString, zod0.ZodAny>>;
|
|
429
485
|
seats: zod0.ZodOptional<zod0.ZodNumber>;
|
|
430
486
|
successUrl: zod0.ZodDefault<zod0.ZodString>;
|
|
@@ -437,29 +493,33 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
437
493
|
operationId: string;
|
|
438
494
|
};
|
|
439
495
|
};
|
|
440
|
-
use: (((inputContext: better_call0.MiddlewareInputContext<
|
|
441
|
-
|
|
442
|
-
session:
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
496
|
+
use: (((inputContext: better_call0.MiddlewareInputContext<{
|
|
497
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
498
|
+
session: {
|
|
499
|
+
session: Record<string, any> & {
|
|
500
|
+
id: string;
|
|
501
|
+
createdAt: Date;
|
|
502
|
+
updatedAt: Date;
|
|
503
|
+
userId: string;
|
|
504
|
+
expiresAt: Date;
|
|
505
|
+
token: string;
|
|
506
|
+
ipAddress?: string | null | undefined;
|
|
507
|
+
userAgent?: string | null | undefined;
|
|
508
|
+
};
|
|
509
|
+
user: Record<string, any> & {
|
|
510
|
+
id: string;
|
|
511
|
+
createdAt: Date;
|
|
512
|
+
updatedAt: Date;
|
|
513
|
+
email: string;
|
|
514
|
+
emailVerified: boolean;
|
|
515
|
+
name: string;
|
|
516
|
+
image?: string | null | undefined;
|
|
517
|
+
};
|
|
460
518
|
};
|
|
461
|
-
};
|
|
462
|
-
}>)
|
|
519
|
+
}>)[];
|
|
520
|
+
}>) => Promise<{
|
|
521
|
+
session: StripeCtxSession;
|
|
522
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
463
523
|
}, {
|
|
464
524
|
url: string;
|
|
465
525
|
redirect: boolean;
|
|
@@ -556,6 +616,10 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
556
616
|
body: zod0.ZodObject<{
|
|
557
617
|
referenceId: zod0.ZodOptional<zod0.ZodString>;
|
|
558
618
|
subscriptionId: zod0.ZodOptional<zod0.ZodString>;
|
|
619
|
+
customerType: zod0.ZodOptional<zod0.ZodEnum<{
|
|
620
|
+
user: "user";
|
|
621
|
+
organization: "organization";
|
|
622
|
+
}>>;
|
|
559
623
|
returnUrl: zod0.ZodString;
|
|
560
624
|
disableRedirect: zod0.ZodDefault<zod0.ZodBoolean>;
|
|
561
625
|
}, better_auth0.$strip>;
|
|
@@ -564,29 +628,33 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
564
628
|
operationId: string;
|
|
565
629
|
};
|
|
566
630
|
};
|
|
567
|
-
use: (((inputContext: better_call0.MiddlewareInputContext<
|
|
568
|
-
|
|
569
|
-
session:
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
631
|
+
use: (((inputContext: better_call0.MiddlewareInputContext<{
|
|
632
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
633
|
+
session: {
|
|
634
|
+
session: Record<string, any> & {
|
|
635
|
+
id: string;
|
|
636
|
+
createdAt: Date;
|
|
637
|
+
updatedAt: Date;
|
|
638
|
+
userId: string;
|
|
639
|
+
expiresAt: Date;
|
|
640
|
+
token: string;
|
|
641
|
+
ipAddress?: string | null | undefined;
|
|
642
|
+
userAgent?: string | null | undefined;
|
|
643
|
+
};
|
|
644
|
+
user: Record<string, any> & {
|
|
645
|
+
id: string;
|
|
646
|
+
createdAt: Date;
|
|
647
|
+
updatedAt: Date;
|
|
648
|
+
email: string;
|
|
649
|
+
emailVerified: boolean;
|
|
650
|
+
name: string;
|
|
651
|
+
image?: string | null | undefined;
|
|
652
|
+
};
|
|
587
653
|
};
|
|
588
|
-
};
|
|
589
|
-
}>)
|
|
654
|
+
}>)[];
|
|
655
|
+
}>) => Promise<{
|
|
656
|
+
session: StripeCtxSession;
|
|
657
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
590
658
|
}, {
|
|
591
659
|
url: string;
|
|
592
660
|
redirect: boolean;
|
|
@@ -596,69 +664,85 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
596
664
|
body: zod0.ZodObject<{
|
|
597
665
|
referenceId: zod0.ZodOptional<zod0.ZodString>;
|
|
598
666
|
subscriptionId: zod0.ZodOptional<zod0.ZodString>;
|
|
667
|
+
customerType: zod0.ZodOptional<zod0.ZodEnum<{
|
|
668
|
+
user: "user";
|
|
669
|
+
organization: "organization";
|
|
670
|
+
}>>;
|
|
599
671
|
}, better_auth0.$strip>;
|
|
600
672
|
metadata: {
|
|
601
673
|
openapi: {
|
|
602
674
|
operationId: string;
|
|
603
675
|
};
|
|
604
676
|
};
|
|
605
|
-
use: (((inputContext: better_call0.MiddlewareInputContext<
|
|
606
|
-
|
|
607
|
-
session:
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
677
|
+
use: (((inputContext: better_call0.MiddlewareInputContext<{
|
|
678
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
679
|
+
session: {
|
|
680
|
+
session: Record<string, any> & {
|
|
681
|
+
id: string;
|
|
682
|
+
createdAt: Date;
|
|
683
|
+
updatedAt: Date;
|
|
684
|
+
userId: string;
|
|
685
|
+
expiresAt: Date;
|
|
686
|
+
token: string;
|
|
687
|
+
ipAddress?: string | null | undefined;
|
|
688
|
+
userAgent?: string | null | undefined;
|
|
689
|
+
};
|
|
690
|
+
user: Record<string, any> & {
|
|
691
|
+
id: string;
|
|
692
|
+
createdAt: Date;
|
|
693
|
+
updatedAt: Date;
|
|
694
|
+
email: string;
|
|
695
|
+
emailVerified: boolean;
|
|
696
|
+
name: string;
|
|
697
|
+
image?: string | null | undefined;
|
|
698
|
+
};
|
|
625
699
|
};
|
|
626
|
-
};
|
|
627
|
-
}>)
|
|
700
|
+
}>)[];
|
|
701
|
+
}>) => Promise<{
|
|
702
|
+
session: StripeCtxSession;
|
|
703
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
628
704
|
}, Stripe.Response<Stripe.Subscription>>;
|
|
629
705
|
listActiveSubscriptions: better_call0.StrictEndpoint<"/subscription/list", {
|
|
630
706
|
method: "GET";
|
|
631
707
|
query: zod0.ZodOptional<zod0.ZodObject<{
|
|
632
708
|
referenceId: zod0.ZodOptional<zod0.ZodString>;
|
|
709
|
+
customerType: zod0.ZodOptional<zod0.ZodEnum<{
|
|
710
|
+
user: "user";
|
|
711
|
+
organization: "organization";
|
|
712
|
+
}>>;
|
|
633
713
|
}, better_auth0.$strip>>;
|
|
634
714
|
metadata: {
|
|
635
715
|
openapi: {
|
|
636
716
|
operationId: string;
|
|
637
717
|
};
|
|
638
718
|
};
|
|
639
|
-
use: (((inputContext: better_call0.MiddlewareInputContext<
|
|
640
|
-
|
|
641
|
-
session:
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
719
|
+
use: (((inputContext: better_call0.MiddlewareInputContext<{
|
|
720
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
721
|
+
session: {
|
|
722
|
+
session: Record<string, any> & {
|
|
723
|
+
id: string;
|
|
724
|
+
createdAt: Date;
|
|
725
|
+
updatedAt: Date;
|
|
726
|
+
userId: string;
|
|
727
|
+
expiresAt: Date;
|
|
728
|
+
token: string;
|
|
729
|
+
ipAddress?: string | null | undefined;
|
|
730
|
+
userAgent?: string | null | undefined;
|
|
731
|
+
};
|
|
732
|
+
user: Record<string, any> & {
|
|
733
|
+
id: string;
|
|
734
|
+
createdAt: Date;
|
|
735
|
+
updatedAt: Date;
|
|
736
|
+
email: string;
|
|
737
|
+
emailVerified: boolean;
|
|
738
|
+
name: string;
|
|
739
|
+
image?: string | null | undefined;
|
|
740
|
+
};
|
|
659
741
|
};
|
|
660
|
-
};
|
|
661
|
-
}>)
|
|
742
|
+
}>)[];
|
|
743
|
+
}>) => Promise<{
|
|
744
|
+
session: StripeCtxSession;
|
|
745
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
662
746
|
}, {
|
|
663
747
|
limits: Record<string, unknown> | undefined;
|
|
664
748
|
priceId: string | undefined;
|
|
@@ -688,25 +772,16 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
688
772
|
};
|
|
689
773
|
};
|
|
690
774
|
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>)[];
|
|
691
|
-
},
|
|
692
|
-
status: ("NOT_FOUND" | "FOUND" | "OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "REQUEST_TIMEOUT" | "CONFLICT" | "GONE" | "LENGTH_REQUIRED" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "URI_TOO_LONG" | "UNSUPPORTED_MEDIA_TYPE" | "RANGE_NOT_SATISFIABLE" | "EXPECTATION_FAILED" | "I'M_A_TEAPOT" | "MISDIRECTED_REQUEST" | "UNPROCESSABLE_ENTITY" | "LOCKED" | "FAILED_DEPENDENCY" | "TOO_EARLY" | "UPGRADE_REQUIRED" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "REQUEST_HEADER_FIELDS_TOO_LARGE" | "UNAVAILABLE_FOR_LEGAL_REASONS" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "HTTP_VERSION_NOT_SUPPORTED" | "VARIANT_ALSO_NEGOTIATES" | "INSUFFICIENT_STORAGE" | "LOOP_DETECTED" | "NOT_EXTENDED" | "NETWORK_AUTHENTICATION_REQUIRED") | better_call0.Status;
|
|
693
|
-
body: ({
|
|
694
|
-
message?: string;
|
|
695
|
-
code?: string;
|
|
696
|
-
cause?: unknown;
|
|
697
|
-
} & Record<string, any>) | undefined;
|
|
698
|
-
headers: HeadersInit;
|
|
699
|
-
statusCode: number;
|
|
700
|
-
name: string;
|
|
701
|
-
message: string;
|
|
702
|
-
stack?: string;
|
|
703
|
-
cause?: unknown;
|
|
704
|
-
}>;
|
|
775
|
+
}, never>;
|
|
705
776
|
createBillingPortal: better_call0.StrictEndpoint<"/subscription/billing-portal", {
|
|
706
777
|
method: "POST";
|
|
707
778
|
body: zod0.ZodObject<{
|
|
708
779
|
locale: zod0.ZodOptional<zod0.ZodCustom<Stripe.Checkout.Session.Locale, Stripe.Checkout.Session.Locale>>;
|
|
709
780
|
referenceId: zod0.ZodOptional<zod0.ZodString>;
|
|
781
|
+
customerType: zod0.ZodOptional<zod0.ZodEnum<{
|
|
782
|
+
user: "user";
|
|
783
|
+
organization: "organization";
|
|
784
|
+
}>>;
|
|
710
785
|
returnUrl: zod0.ZodDefault<zod0.ZodString>;
|
|
711
786
|
disableRedirect: zod0.ZodDefault<zod0.ZodBoolean>;
|
|
712
787
|
}, better_auth0.$strip>;
|
|
@@ -715,29 +790,33 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
715
790
|
operationId: string;
|
|
716
791
|
};
|
|
717
792
|
};
|
|
718
|
-
use: (((inputContext: better_call0.MiddlewareInputContext<
|
|
719
|
-
|
|
720
|
-
session:
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
793
|
+
use: (((inputContext: better_call0.MiddlewareInputContext<{
|
|
794
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
795
|
+
session: {
|
|
796
|
+
session: Record<string, any> & {
|
|
797
|
+
id: string;
|
|
798
|
+
createdAt: Date;
|
|
799
|
+
updatedAt: Date;
|
|
800
|
+
userId: string;
|
|
801
|
+
expiresAt: Date;
|
|
802
|
+
token: string;
|
|
803
|
+
ipAddress?: string | null | undefined;
|
|
804
|
+
userAgent?: string | null | undefined;
|
|
805
|
+
};
|
|
806
|
+
user: Record<string, any> & {
|
|
807
|
+
id: string;
|
|
808
|
+
createdAt: Date;
|
|
809
|
+
updatedAt: Date;
|
|
810
|
+
email: string;
|
|
811
|
+
emailVerified: boolean;
|
|
812
|
+
name: string;
|
|
813
|
+
image?: string | null | undefined;
|
|
814
|
+
};
|
|
738
815
|
};
|
|
739
|
-
};
|
|
740
|
-
}>)
|
|
816
|
+
}>)[];
|
|
817
|
+
}>) => Promise<{
|
|
818
|
+
session: StripeCtxSession;
|
|
819
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
741
820
|
}, {
|
|
742
821
|
url: string;
|
|
743
822
|
redirect: boolean;
|
|
@@ -748,34 +827,26 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
748
827
|
databaseHooks: {
|
|
749
828
|
user: {
|
|
750
829
|
create: {
|
|
751
|
-
after(user:
|
|
752
|
-
id: string;
|
|
753
|
-
createdAt: Date;
|
|
754
|
-
updatedAt: Date;
|
|
755
|
-
email: string;
|
|
756
|
-
emailVerified: boolean;
|
|
757
|
-
name: string;
|
|
758
|
-
image?: string | null | undefined;
|
|
759
|
-
} & Record<string, unknown>, ctx: better_auth0.GenericEndpointContext | null): Promise<void>;
|
|
830
|
+
after(user: User & WithStripeCustomerId, ctx: better_auth0.GenericEndpointContext | null): Promise<void>;
|
|
760
831
|
};
|
|
761
832
|
update: {
|
|
762
|
-
after(user:
|
|
763
|
-
id: string;
|
|
764
|
-
createdAt: Date;
|
|
765
|
-
updatedAt: Date;
|
|
766
|
-
email: string;
|
|
767
|
-
emailVerified: boolean;
|
|
768
|
-
name: string;
|
|
769
|
-
image?: string | null | undefined;
|
|
770
|
-
} & Record<string, unknown>, ctx: better_auth0.GenericEndpointContext | null): Promise<void>;
|
|
833
|
+
after(user: User & WithStripeCustomerId, ctx: better_auth0.GenericEndpointContext | null): Promise<void>;
|
|
771
834
|
};
|
|
772
835
|
};
|
|
773
836
|
};
|
|
774
837
|
};
|
|
775
|
-
};
|
|
838
|
+
} | undefined;
|
|
776
839
|
schema: {};
|
|
777
840
|
options: NoInfer<O>;
|
|
778
841
|
$ERROR_CODES: {
|
|
842
|
+
readonly UNAUTHORIZED: {
|
|
843
|
+
code: "UNAUTHORIZED";
|
|
844
|
+
message: "Unauthorized access";
|
|
845
|
+
};
|
|
846
|
+
readonly INVALID_REQUEST_BODY: {
|
|
847
|
+
code: "INVALID_REQUEST_BODY";
|
|
848
|
+
message: "Invalid request body";
|
|
849
|
+
};
|
|
779
850
|
readonly SUBSCRIPTION_NOT_FOUND: {
|
|
780
851
|
code: "SUBSCRIPTION_NOT_FOUND";
|
|
781
852
|
message: "Subscription not found";
|
|
@@ -788,10 +859,38 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
788
859
|
code: "ALREADY_SUBSCRIBED_PLAN";
|
|
789
860
|
message: "You're already subscribed to this plan";
|
|
790
861
|
};
|
|
862
|
+
readonly REFERENCE_ID_NOT_ALLOWED: {
|
|
863
|
+
code: "REFERENCE_ID_NOT_ALLOWED";
|
|
864
|
+
message: "Reference id is not allowed";
|
|
865
|
+
};
|
|
866
|
+
readonly CUSTOMER_NOT_FOUND: {
|
|
867
|
+
code: "CUSTOMER_NOT_FOUND";
|
|
868
|
+
message: "Stripe customer not found for this user";
|
|
869
|
+
};
|
|
791
870
|
readonly UNABLE_TO_CREATE_CUSTOMER: {
|
|
792
871
|
code: "UNABLE_TO_CREATE_CUSTOMER";
|
|
793
872
|
message: "Unable to create customer";
|
|
794
873
|
};
|
|
874
|
+
readonly UNABLE_TO_CREATE_BILLING_PORTAL: {
|
|
875
|
+
code: "UNABLE_TO_CREATE_BILLING_PORTAL";
|
|
876
|
+
message: "Unable to create billing portal session";
|
|
877
|
+
};
|
|
878
|
+
readonly STRIPE_SIGNATURE_NOT_FOUND: {
|
|
879
|
+
code: "STRIPE_SIGNATURE_NOT_FOUND";
|
|
880
|
+
message: "Stripe signature not found";
|
|
881
|
+
};
|
|
882
|
+
readonly STRIPE_WEBHOOK_SECRET_NOT_FOUND: {
|
|
883
|
+
code: "STRIPE_WEBHOOK_SECRET_NOT_FOUND";
|
|
884
|
+
message: "Stripe webhook secret not found";
|
|
885
|
+
};
|
|
886
|
+
readonly STRIPE_WEBHOOK_ERROR: {
|
|
887
|
+
code: "STRIPE_WEBHOOK_ERROR";
|
|
888
|
+
message: "Stripe webhook error";
|
|
889
|
+
};
|
|
890
|
+
readonly FAILED_TO_CONSTRUCT_STRIPE_EVENT: {
|
|
891
|
+
code: "FAILED_TO_CONSTRUCT_STRIPE_EVENT";
|
|
892
|
+
message: "Failed to construct Stripe event";
|
|
893
|
+
};
|
|
795
894
|
readonly FAILED_TO_FETCH_PLANS: {
|
|
796
895
|
code: "FAILED_TO_FETCH_PLANS";
|
|
797
896
|
message: "Failed to fetch plans";
|
|
@@ -808,6 +907,22 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
808
907
|
code: "SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION";
|
|
809
908
|
message: "Subscription is not scheduled for cancellation";
|
|
810
909
|
};
|
|
910
|
+
readonly ORGANIZATION_NOT_FOUND: {
|
|
911
|
+
code: "ORGANIZATION_NOT_FOUND";
|
|
912
|
+
message: "Organization not found";
|
|
913
|
+
};
|
|
914
|
+
readonly ORGANIZATION_SUBSCRIPTION_NOT_ENABLED: {
|
|
915
|
+
code: "ORGANIZATION_SUBSCRIPTION_NOT_ENABLED";
|
|
916
|
+
message: "Organization subscription is not enabled";
|
|
917
|
+
};
|
|
918
|
+
readonly ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION: {
|
|
919
|
+
code: "ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION";
|
|
920
|
+
message: "Cannot delete organization with active subscription";
|
|
921
|
+
};
|
|
922
|
+
readonly ORGANIZATION_REFERENCE_ID_REQUIRED: {
|
|
923
|
+
code: "ORGANIZATION_REFERENCE_ID_REQUIRED";
|
|
924
|
+
message: "Reference ID is required. Provide referenceId or set activeOrganizationId in session";
|
|
925
|
+
};
|
|
811
926
|
};
|
|
812
927
|
};
|
|
813
928
|
type StripePlugin<O extends StripeOptions> = ReturnType<typeof stripe<O>>;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as SubscriptionOptions, i as Subscription, n as stripe, r as StripePlan, t as StripePlugin } from "./index-
|
|
1
|
+
import { a as SubscriptionOptions, i as Subscription, n as stripe, r as StripePlan, t as StripePlugin } from "./index-BnHmwMru.mjs";
|
|
2
2
|
export { StripePlan, StripePlugin, Subscription, SubscriptionOptions, stripe };
|