@faire-auth/stripe 1.0.0

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.
@@ -0,0 +1,1110 @@
1
+ import * as faire_auth0 from "faire-auth";
2
+ import { ContextVars, InferOptionSchema } from "faire-auth";
3
+ import * as hono0 from "hono";
4
+ import * as _faire_auth_core_types0 from "@faire-auth/core/types";
5
+ import { Context } from "@faire-auth/core/types";
6
+ import { Session, User } from "faire-auth/db";
7
+ import Stripe from "stripe";
8
+ import * as z from "zod";
9
+
10
+ //#region src/schema.d.ts
11
+ declare const subscriptions: {
12
+ subscription: {
13
+ fields: {
14
+ plan: {
15
+ type: "string";
16
+ required: true;
17
+ };
18
+ referenceId: {
19
+ type: "string";
20
+ required: true;
21
+ };
22
+ stripeCustomerId: {
23
+ type: "string";
24
+ required: false;
25
+ };
26
+ stripeSubscriptionId: {
27
+ type: "string";
28
+ required: false;
29
+ };
30
+ status: {
31
+ type: "string";
32
+ defaultValue: string;
33
+ };
34
+ periodStart: {
35
+ type: "date";
36
+ required: false;
37
+ };
38
+ periodEnd: {
39
+ type: "date";
40
+ required: false;
41
+ };
42
+ trialStart: {
43
+ type: "date";
44
+ required: false;
45
+ };
46
+ trialEnd: {
47
+ type: "date";
48
+ required: false;
49
+ };
50
+ cancelAtPeriodEnd: {
51
+ type: "boolean";
52
+ required: false;
53
+ defaultValue: false;
54
+ };
55
+ seats: {
56
+ type: "number";
57
+ required: false;
58
+ };
59
+ };
60
+ };
61
+ };
62
+ declare const user: {
63
+ user: {
64
+ fields: {
65
+ stripeCustomerId: {
66
+ type: "string";
67
+ required: false;
68
+ };
69
+ };
70
+ };
71
+ };
72
+ //#endregion
73
+ //#region src/types.d.ts
74
+ type StripePlan = {
75
+ /**
76
+ * Monthly price id
77
+ */
78
+ priceId?: string;
79
+ /**
80
+ * To use lookup key instead of price id
81
+ *
82
+ * https://docs.stripe.com/products-prices/
83
+ * manage-prices#lookup-keys
84
+ */
85
+ lookupKey?: string;
86
+ /**
87
+ * A yearly discount price id
88
+ *
89
+ * useful when you want to offer a discount for
90
+ * yearly subscription
91
+ */
92
+ annualDiscountPriceId?: string;
93
+ /**
94
+ * To use lookup key instead of price id
95
+ *
96
+ * https://docs.stripe.com/products-prices/
97
+ * manage-prices#lookup-keys
98
+ */
99
+ annualDiscountLookupKey?: string;
100
+ /**
101
+ * Plan name
102
+ */
103
+ name: string;
104
+ /**
105
+ * Limits for the plan
106
+ */
107
+ limits?: Record<string, number>;
108
+ /**
109
+ * Plan group name
110
+ *
111
+ * useful when you want to group plans or
112
+ * when a user can subscribe to multiple plans.
113
+ */
114
+ group?: string;
115
+ /**
116
+ * Free trial days
117
+ */
118
+ freeTrial?: {
119
+ /**
120
+ * Number of days
121
+ */
122
+ days: number;
123
+ /**
124
+ * A function that will be called when the trial
125
+ * starts.
126
+ *
127
+ * @param subscription
128
+ * @returns
129
+ */
130
+ onTrialStart?: (subscription: Subscription) => Promise<void>;
131
+ /**
132
+ * A function that will be called when the trial
133
+ * ends
134
+ *
135
+ * @param subscription - Subscription
136
+ * @returns
137
+ */
138
+ onTrialEnd?: <V extends object>(data: {
139
+ subscription: Subscription;
140
+ }, ctx: Context<ContextVars<V>>) => Promise<void>;
141
+ /**
142
+ * A function that will be called when the trial
143
+ * expired.
144
+ * @param subscription - Subscription
145
+ * @returns
146
+ */
147
+ onTrialExpired?: <V extends object>(subscription: Subscription, ctx: Context<ContextVars<V>>) => Promise<void>;
148
+ };
149
+ };
150
+ interface Subscription {
151
+ /**
152
+ * Database identifier
153
+ */
154
+ id: string;
155
+ /**
156
+ * The plan name
157
+ */
158
+ plan: string;
159
+ /**
160
+ * Stripe customer id
161
+ */
162
+ stripeCustomerId?: string;
163
+ /**
164
+ * Stripe subscription id
165
+ */
166
+ stripeSubscriptionId?: string;
167
+ /**
168
+ * Trial start date
169
+ */
170
+ trialStart?: Date;
171
+ /**
172
+ * Trial end date
173
+ */
174
+ trialEnd?: Date;
175
+ /**
176
+ * Price Id for the subscription
177
+ */
178
+ priceId?: string;
179
+ /**
180
+ * To what reference id the subscription belongs to
181
+ * @example
182
+ * - userId for a user
183
+ * - workspace id for a saas platform
184
+ * - website id for a hosting platform
185
+ *
186
+ * @default - userId
187
+ */
188
+ referenceId: string;
189
+ /**
190
+ * Subscription status
191
+ */
192
+ status: "active" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "trialing" | "unpaid";
193
+ /**
194
+ * The billing cycle start date
195
+ */
196
+ periodStart?: Date;
197
+ /**
198
+ * The billing cycle end date
199
+ */
200
+ periodEnd?: Date;
201
+ /**
202
+ * Whether this subscription will (if status=active)
203
+ * or did (if status=canceled) cancel at the end of the current billing period.
204
+ */
205
+ cancelAtPeriodEnd?: boolean;
206
+ /**
207
+ * If the subscription is scheduled to be canceled,
208
+ * this is the time at which the cancellation will take effect.
209
+ */
210
+ cancelAt?: Date;
211
+ /**
212
+ * If the subscription has been canceled, this is the time when it was canceled.
213
+ *
214
+ * Note: If the subscription was canceled with `cancel_at_period_end`,
215
+ * this reflects the cancellation request time, not when the subscription actually ends.
216
+ */
217
+ canceledAt?: Date;
218
+ /**
219
+ * If the subscription has ended, the date the subscription ended.
220
+ */
221
+ endedAt?: Date;
222
+ /**
223
+ * A field to group subscriptions so you can have multiple subscriptions
224
+ * for one reference id
225
+ */
226
+ groupId?: string;
227
+ /**
228
+ * Number of seats for the subscription (useful for team plans)
229
+ */
230
+ seats?: number;
231
+ }
232
+ interface SubscriptionOptions {
233
+ enabled: boolean;
234
+ /**
235
+ * Subscription Configuration
236
+ */
237
+ /**
238
+ * List of plan
239
+ */
240
+ plans: StripePlan[] | (() => StripePlan[] | Promise<StripePlan[]>);
241
+ /**
242
+ * Require email verification before a user is allowed to upgrade
243
+ * their subscriptions
244
+ *
245
+ * @default false
246
+ */
247
+ requireEmailVerification?: boolean;
248
+ /**
249
+ * A callback to run after a user has subscribed to a package
250
+ * @param event - Stripe Event
251
+ * @param subscription - Subscription Data
252
+ * @returns
253
+ */
254
+ onSubscriptionComplete?: <V extends object>(data: {
255
+ event: Stripe.Event;
256
+ stripeSubscription: Stripe.Subscription;
257
+ subscription: Subscription;
258
+ plan: StripePlan;
259
+ }, ctx: Context<ContextVars<V>>) => Promise<void>;
260
+ /**
261
+ * A callback to run after a user is about to cancel their subscription
262
+ * @returns
263
+ */
264
+ onSubscriptionUpdate?: (data: {
265
+ event: Stripe.Event;
266
+ subscription: Subscription;
267
+ }) => Promise<void>;
268
+ /**
269
+ * A callback to run after a user is about to cancel their subscription
270
+ * @returns
271
+ */
272
+ onSubscriptionCancel?: (data: {
273
+ event?: Stripe.Event | undefined;
274
+ subscription: Subscription;
275
+ stripeSubscription: Stripe.Subscription;
276
+ cancellationDetails?: Stripe.Subscription.CancellationDetails | null;
277
+ }) => Promise<void>;
278
+ /**
279
+ * A function to check if the reference id is valid
280
+ * and belongs to the user
281
+ *
282
+ * @param data - data containing user, session and referenceId
283
+ * @param ctx - the context object
284
+ * @returns
285
+ */
286
+ authorizeReference?: <V extends object>(data: {
287
+ user: User;
288
+ session: Session;
289
+ referenceId: string;
290
+ action: "upgrade-subscription" | "list-subscription" | "cancel-subscription" | "restore-subscription" | "billing-portal";
291
+ }, ctx: Context<ContextVars<V>>) => Promise<boolean>;
292
+ /**
293
+ * A callback to run after a user has deleted their subscription
294
+ * @returns
295
+ */
296
+ onSubscriptionDeleted?: (data: {
297
+ event: Stripe.Event;
298
+ stripeSubscription: Stripe.Subscription;
299
+ subscription: Subscription;
300
+ }) => Promise<void>;
301
+ /**
302
+ * parameters for session create params
303
+ *
304
+ * @param data - data containing user, session and plan
305
+ * @param ctx - the context object
306
+ */
307
+ getCheckoutSessionParams?: <V extends object>(data: {
308
+ user: User;
309
+ session: Session;
310
+ plan: StripePlan;
311
+ subscription: Subscription;
312
+ }, ctx: Context<ContextVars<V>>) => Promise<{
313
+ params?: Stripe.Checkout.SessionCreateParams;
314
+ options?: Stripe.RequestOptions;
315
+ }> | {
316
+ params?: Stripe.Checkout.SessionCreateParams;
317
+ options?: Stripe.RequestOptions;
318
+ };
319
+ /**
320
+ * Enable organization subscription
321
+ */
322
+ organization?: {
323
+ enabled: boolean;
324
+ };
325
+ }
326
+ interface StripeOptions {
327
+ /**
328
+ * Stripe Client
329
+ */
330
+ stripeClient: Stripe;
331
+ /**
332
+ * Stripe Webhook Secret
333
+ *
334
+ * @description Stripe webhook secret key
335
+ */
336
+ stripeWebhookSecret: string;
337
+ /**
338
+ * Enable customer creation when a user signs up
339
+ */
340
+ createCustomerOnSignUp?: boolean;
341
+ /**
342
+ * A callback to run after a customer has been created
343
+ * @param customer - Customer Data
344
+ * @param stripeCustomer - Stripe Customer Data
345
+ * @returns
346
+ */
347
+ onCustomerCreate?: <V extends object>(data: {
348
+ stripeCustomer: Stripe.Customer;
349
+ user: User;
350
+ }, ctx: Context<ContextVars<V>>) => Promise<void>;
351
+ /**
352
+ * A custom function to get the customer create
353
+ * params
354
+ * @param data - data containing user and session
355
+ * @returns
356
+ */
357
+ getCustomerCreateParams?: <V extends object>(data: {
358
+ user: User;
359
+ session: Session;
360
+ }, ctx: Context<ContextVars<V>>) => Promise<{}>;
361
+ /**
362
+ * Subscriptions
363
+ */
364
+ subscription?: {
365
+ enabled: false;
366
+ } | ({
367
+ enabled: true;
368
+ } & SubscriptionOptions);
369
+ /**
370
+ * A callback to run after a stripe event is received
371
+ * @param event - Stripe Event
372
+ * @returns
373
+ */
374
+ onEvent?: (event: Stripe.Event) => Promise<void>;
375
+ /**
376
+ * Schema for the stripe plugin
377
+ */
378
+ schema?: InferOptionSchema<typeof subscriptions & typeof user>;
379
+ }
380
+ //#endregion
381
+ //#region src/index.d.ts
382
+ declare const stripe: <O extends StripeOptions>(options: O) => {
383
+ id: "stripe";
384
+ routes: {
385
+ stripeWebhook: faire_auth0.AuthEndpoint<{
386
+ responses: {
387
+ 200: {
388
+ description: string;
389
+ content: {
390
+ "application/json": {
391
+ schema: z.ZodObject<{
392
+ success: z.ZodLiteral<true>;
393
+ }, z.core.$strip>;
394
+ };
395
+ };
396
+ };
397
+ } & {
398
+ 400: {
399
+ description: string;
400
+ content: {
401
+ "application/json": {
402
+ schema: z.core.$ZodBranded<z.ZodObject<{
403
+ success: z.ZodLiteral<false>;
404
+ code: z.ZodOptional<z.ZodString>;
405
+ message: z.ZodOptional<z.ZodString>;
406
+ }, z.core.$strip>, "error">;
407
+ };
408
+ };
409
+ };
410
+ } & {
411
+ 500: {
412
+ description: string;
413
+ content: {
414
+ "application/json": {
415
+ schema: z.core.$ZodBranded<z.ZodObject<{
416
+ success: z.ZodLiteral<false>;
417
+ code: z.ZodOptional<z.ZodString>;
418
+ message: z.ZodOptional<z.ZodString>;
419
+ }, z.core.$strip>, "error">;
420
+ };
421
+ };
422
+ };
423
+ };
424
+ operationId: "stripeWebhook";
425
+ path: "/stripe/webhook";
426
+ method: "post";
427
+ client: false;
428
+ getRoutingPath: () => "/stripe/webhook";
429
+ }>;
430
+ } & (O["subscription"] extends {
431
+ enabled: boolean;
432
+ } ? {
433
+ /**
434
+ * ### Endpoint
435
+ *
436
+ * POST `/subscription/upgrade`
437
+ *
438
+ * ### API Methods
439
+ *
440
+ * **server:**
441
+ * `auth.api.upgradeSubscription`
442
+ *
443
+ * **client:**
444
+ * `authClient.subscription.upgrade`
445
+ *
446
+ * @see [Read our docs to learn more.](https://faire-auth.com/docs/plugins/stripe#api-method-subscription-upgrade)
447
+ */
448
+ readonly upgradeSubscription: faire_auth0.AuthEndpoint<{
449
+ responses: {
450
+ 200: {
451
+ description: string;
452
+ content: {
453
+ "application/json": {
454
+ schema: z.ZodIntersection<z.ZodDiscriminatedUnion<[z.ZodObject<{
455
+ redirect: z.ZodLiteral<false>;
456
+ url: z.ZodDefault<z.ZodNull>;
457
+ }, z.core.$strip>, z.ZodObject<{
458
+ redirect: z.ZodLiteral<true>;
459
+ url: z.ZodURL;
460
+ }, z.core.$strip>], "redirect">, z.ZodType<Partial<Stripe.Checkout.Session>, Partial<Stripe.Checkout.Session>, z.core.$ZodTypeInternals<Partial<Stripe.Checkout.Session>, Partial<Stripe.Checkout.Session>>>>;
461
+ };
462
+ };
463
+ };
464
+ } & {
465
+ 400: {
466
+ description: string;
467
+ content: {
468
+ "application/json": {
469
+ schema: z.core.$ZodBranded<z.ZodObject<{
470
+ success: z.ZodLiteral<false>;
471
+ code: z.ZodOptional<z.ZodString>;
472
+ message: z.ZodOptional<z.ZodString>;
473
+ }, z.core.$strip>, "error">;
474
+ };
475
+ };
476
+ };
477
+ } & {
478
+ 401: {
479
+ description: string;
480
+ content: {
481
+ "application/json": {
482
+ schema: z.core.$ZodBranded<z.ZodObject<{
483
+ success: z.ZodLiteral<false>;
484
+ code: z.ZodOptional<z.ZodString>;
485
+ message: z.ZodOptional<z.ZodString>;
486
+ }, z.core.$strip>, "error">;
487
+ };
488
+ };
489
+ };
490
+ } & {
491
+ 500: {
492
+ description: string;
493
+ content: {
494
+ "application/json": {
495
+ schema: z.core.$ZodBranded<z.ZodObject<{
496
+ success: z.ZodLiteral<false>;
497
+ code: z.ZodOptional<z.ZodString>;
498
+ message: z.ZodOptional<z.ZodString>;
499
+ }, z.core.$strip>, "error">;
500
+ };
501
+ };
502
+ };
503
+ };
504
+ operationId: "upgradeSubscription";
505
+ path: "/subscription/upgrade";
506
+ method: "post";
507
+ middleware: [(ctx: hono0.Context<faire_auth0.ContextVars<{
508
+ session: {
509
+ user: {
510
+ stripeCustomerId?: string;
511
+ };
512
+ };
513
+ } & {
514
+ session: {
515
+ session: {
516
+ [x: string]: unknown;
517
+ createdAt: Date;
518
+ updatedAt: Date;
519
+ userId: string;
520
+ expiresAt: Date;
521
+ token: string;
522
+ id?: string;
523
+ ipAddress?: string | null;
524
+ userAgent?: string | null;
525
+ };
526
+ user: {
527
+ [x: string]: unknown;
528
+ id: string;
529
+ createdAt: Date;
530
+ updatedAt: Date;
531
+ email: string;
532
+ emailVerified: boolean;
533
+ name?: string;
534
+ image?: string | null;
535
+ };
536
+ };
537
+ }>, string, {}>, next: hono0.Next) => Promise<void | (Response & hono0.TypedResponse<{
538
+ success: false;
539
+ code?: string | undefined;
540
+ message?: string | undefined;
541
+ }, 401>)>, (ctx: hono0.Context<faire_auth0.ContextVars<object>, string, {}>, next: hono0.Next) => Promise<void | Response>, (ctx: hono0.Context<faire_auth0.ContextVars<{
542
+ session?: {
543
+ session: Session;
544
+ user: User;
545
+ };
546
+ }>, "/subscription/upgrade" | "/subscription/cancel" | "/subscription/list" | "/subscription/restore" | "/subscription/billing-portal", {
547
+ out: {
548
+ json: {
549
+ referenceId?: string;
550
+ };
551
+ query: {
552
+ referenceId?: string;
553
+ };
554
+ };
555
+ }>, next: hono0.Next) => Promise<void | (Response & hono0.TypedResponse<{
556
+ success: false;
557
+ }, 401, "json">) | (Response & hono0.TypedResponse<{
558
+ success: false;
559
+ }, 400, "json">)>];
560
+ request: {
561
+ body: {
562
+ description?: string;
563
+ content: {
564
+ "application/json": {
565
+ schema: z.ZodObject<{
566
+ plan: z.ZodString;
567
+ annual: z.ZodOptional<z.ZodBoolean>;
568
+ referenceId: z.ZodOptional<z.ZodString>;
569
+ subscriptionId: z.ZodOptional<z.ZodString>;
570
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
571
+ seats: z.ZodOptional<z.ZodNumber>;
572
+ successUrl: z.ZodDefault<z.ZodString>;
573
+ cancelUrl: z.ZodDefault<z.ZodString>;
574
+ returnUrl: z.ZodOptional<z.ZodString>;
575
+ disableRedirect: z.ZodDefault<z.ZodBoolean>;
576
+ }, z.core.$strip>;
577
+ };
578
+ };
579
+ required: true;
580
+ };
581
+ };
582
+ getRoutingPath: () => "/subscription/upgrade";
583
+ }>;
584
+ readonly cancelSubscriptionCallback: faire_auth0.AuthEndpoint<{
585
+ responses: {
586
+ 200: {
587
+ description: string;
588
+ content: {
589
+ "application/json": {
590
+ schema: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
591
+ };
592
+ };
593
+ };
594
+ } & {
595
+ 302: {
596
+ description: string;
597
+ };
598
+ };
599
+ operationId: "cancelSubscriptionCallback";
600
+ path: "/subscription/cancel/callback";
601
+ method: "get";
602
+ middleware: [(ctx: hono0.Context<faire_auth0.ContextVars<object>, string, {}>, next: hono0.Next) => Promise<void | Response>];
603
+ request: {
604
+ query: z.ZodObject<{
605
+ callbackURL: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodTransform<string | undefined, string | undefined>, z.ZodOptional<z.ZodURL>>, z.ZodTransform<string | undefined, string | undefined>>>;
606
+ subscriptionId: z.ZodOptional<z.ZodString>;
607
+ }, z.core.$strip>;
608
+ };
609
+ getRoutingPath: () => "/subscription/cancel/callback";
610
+ }>;
611
+ /**
612
+ * ### Endpoint
613
+ *
614
+ * POST `/subscription/cancel`
615
+ *
616
+ * ### API Methods
617
+ *
618
+ * **server:**
619
+ * `auth.api.cancelSubscription`
620
+ *
621
+ * **client:**
622
+ * `authClient.subscription.cancel`
623
+ *
624
+ * @see [Read our docs to learn more.](https://faire-auth.com/docs/plugins/stripe#api-method-subscription-cancel)
625
+ */
626
+ readonly cancelSubscription: faire_auth0.AuthEndpoint<{
627
+ responses: {
628
+ 200: {
629
+ description: string;
630
+ content: {
631
+ "application/json": {
632
+ schema: z.ZodObject<{
633
+ url: z.ZodString;
634
+ redirect: z.ZodLiteral<true>;
635
+ }, z.core.$strip>;
636
+ };
637
+ };
638
+ };
639
+ } & {
640
+ 400: {
641
+ description: string;
642
+ content: {
643
+ "application/json": {
644
+ schema: z.core.$ZodBranded<z.ZodObject<{
645
+ success: z.ZodLiteral<false>;
646
+ code: z.ZodOptional<z.ZodString>;
647
+ message: z.ZodOptional<z.ZodString>;
648
+ }, z.core.$strip>, "error">;
649
+ };
650
+ };
651
+ };
652
+ } & {
653
+ 401: {
654
+ description: string;
655
+ content: {
656
+ "application/json": {
657
+ schema: z.core.$ZodBranded<z.ZodObject<{
658
+ success: z.ZodLiteral<false>;
659
+ code: z.ZodOptional<z.ZodString>;
660
+ message: z.ZodOptional<z.ZodString>;
661
+ }, z.core.$strip>, "error">;
662
+ };
663
+ };
664
+ };
665
+ };
666
+ operationId: "cancelSubscription";
667
+ path: "/subscription/cancel";
668
+ method: "post";
669
+ middleware: [(ctx: hono0.Context<faire_auth0.ContextVars<object & {
670
+ session: {
671
+ session: {
672
+ [x: string]: unknown;
673
+ createdAt: Date;
674
+ updatedAt: Date;
675
+ userId: string;
676
+ expiresAt: Date;
677
+ token: string;
678
+ id?: string;
679
+ ipAddress?: string | null;
680
+ userAgent?: string | null;
681
+ };
682
+ user: {
683
+ [x: string]: unknown;
684
+ id: string;
685
+ createdAt: Date;
686
+ updatedAt: Date;
687
+ email: string;
688
+ emailVerified: boolean;
689
+ name?: string;
690
+ image?: string | null;
691
+ };
692
+ };
693
+ }>, string, {}>, next: hono0.Next) => Promise<void | (Response & hono0.TypedResponse<{
694
+ success: false;
695
+ code?: string | undefined;
696
+ message?: string | undefined;
697
+ }, 401>)>, (ctx: hono0.Context<faire_auth0.ContextVars<object>, string, {}>, next: hono0.Next) => Promise<void | Response>, (ctx: hono0.Context<faire_auth0.ContextVars<{
698
+ session?: {
699
+ session: Session;
700
+ user: User;
701
+ };
702
+ }>, "/subscription/upgrade" | "/subscription/cancel" | "/subscription/list" | "/subscription/restore" | "/subscription/billing-portal", {
703
+ out: {
704
+ json: {
705
+ referenceId?: string;
706
+ };
707
+ query: {
708
+ referenceId?: string;
709
+ };
710
+ };
711
+ }>, next: hono0.Next) => Promise<void | (Response & hono0.TypedResponse<{
712
+ success: false;
713
+ }, 401, "json">) | (Response & hono0.TypedResponse<{
714
+ success: false;
715
+ }, 400, "json">)>];
716
+ request: {
717
+ body: {
718
+ description?: string;
719
+ content: {
720
+ "application/json": {
721
+ schema: z.ZodObject<{
722
+ referenceId: z.ZodOptional<z.ZodString>;
723
+ subscriptionId: z.ZodOptional<z.ZodString>;
724
+ returnUrl: z.ZodString;
725
+ }, z.core.$strip>;
726
+ };
727
+ };
728
+ required: true;
729
+ };
730
+ };
731
+ getRoutingPath: () => "/subscription/cancel";
732
+ }>;
733
+ readonly restoreSubscription: faire_auth0.AuthEndpoint<{
734
+ responses: {
735
+ 200: {
736
+ description: string;
737
+ content: {
738
+ "application/json": {
739
+ schema: z.ZodType<Stripe.Subscription, unknown, z.core.$ZodTypeInternals<Stripe.Subscription, unknown>>;
740
+ };
741
+ };
742
+ };
743
+ } & {
744
+ 400: {
745
+ description: string;
746
+ content: {
747
+ "application/json": {
748
+ schema: z.core.$ZodBranded<z.ZodObject<{
749
+ success: z.ZodLiteral<false>;
750
+ code: z.ZodOptional<z.ZodString>;
751
+ message: z.ZodOptional<z.ZodString>;
752
+ }, z.core.$strip>, "error">;
753
+ };
754
+ };
755
+ };
756
+ } & {
757
+ 401: {
758
+ description: string;
759
+ content: {
760
+ "application/json": {
761
+ schema: z.core.$ZodBranded<z.ZodObject<{
762
+ success: z.ZodLiteral<false>;
763
+ code: z.ZodOptional<z.ZodString>;
764
+ message: z.ZodOptional<z.ZodString>;
765
+ }, z.core.$strip>, "error">;
766
+ };
767
+ };
768
+ };
769
+ };
770
+ operationId: "restoreSubscription";
771
+ path: "/subscription/restore";
772
+ method: "post";
773
+ middleware: [(ctx: hono0.Context<faire_auth0.ContextVars<object & {
774
+ session: {
775
+ session: {
776
+ [x: string]: unknown;
777
+ createdAt: Date;
778
+ updatedAt: Date;
779
+ userId: string;
780
+ expiresAt: Date;
781
+ token: string;
782
+ id?: string;
783
+ ipAddress?: string | null;
784
+ userAgent?: string | null;
785
+ };
786
+ user: {
787
+ [x: string]: unknown;
788
+ id: string;
789
+ createdAt: Date;
790
+ updatedAt: Date;
791
+ email: string;
792
+ emailVerified: boolean;
793
+ name?: string;
794
+ image?: string | null;
795
+ };
796
+ };
797
+ }>, string, {}>, next: hono0.Next) => Promise<void | (Response & hono0.TypedResponse<{
798
+ success: false;
799
+ code?: string | undefined;
800
+ message?: string | undefined;
801
+ }, 401>)>, (ctx: hono0.Context<faire_auth0.ContextVars<{
802
+ session?: {
803
+ session: Session;
804
+ user: User;
805
+ };
806
+ }>, "/subscription/upgrade" | "/subscription/cancel" | "/subscription/list" | "/subscription/restore" | "/subscription/billing-portal", {
807
+ out: {
808
+ json: {
809
+ referenceId?: string;
810
+ };
811
+ query: {
812
+ referenceId?: string;
813
+ };
814
+ };
815
+ }>, next: hono0.Next) => Promise<void | (Response & hono0.TypedResponse<{
816
+ success: false;
817
+ }, 401, "json">) | (Response & hono0.TypedResponse<{
818
+ success: false;
819
+ }, 400, "json">)>];
820
+ request: {
821
+ body: {
822
+ description?: string;
823
+ content: {
824
+ "application/json": {
825
+ schema: z.ZodObject<{
826
+ referenceId: z.ZodOptional<z.ZodString>;
827
+ subscriptionId: z.ZodOptional<z.ZodString>;
828
+ }, z.core.$strip>;
829
+ };
830
+ };
831
+ required: true;
832
+ };
833
+ };
834
+ getRoutingPath: () => "/subscription/restore";
835
+ }>;
836
+ /**
837
+ * ### Endpoint
838
+ *
839
+ * GET `/subscription/list`
840
+ *
841
+ * ### API Methods
842
+ *
843
+ * **server:**
844
+ * `auth.api.listActiveSubscriptions`
845
+ *
846
+ * **client:**
847
+ * `authClient.subscription.list`
848
+ *
849
+ * @see [Read our docs to learn more.](https://faire-auth.com/docs/plugins/stripe#api-method-subscription-list)
850
+ */
851
+ readonly listActiveSubscriptions: faire_auth0.AuthEndpoint<{
852
+ responses: {
853
+ 200: {
854
+ description: string;
855
+ content: {
856
+ "application/json": {
857
+ schema: z.ZodType<Subscription[], unknown, z.core.$ZodTypeInternals<Subscription[], unknown>>;
858
+ };
859
+ };
860
+ };
861
+ } & {
862
+ 400: {
863
+ description: string;
864
+ content: {
865
+ "application/json": {
866
+ schema: z.core.$ZodBranded<z.ZodObject<{
867
+ success: z.ZodLiteral<false>;
868
+ code: z.ZodOptional<z.ZodString>;
869
+ message: z.ZodOptional<z.ZodString>;
870
+ }, z.core.$strip>, "error">;
871
+ };
872
+ };
873
+ };
874
+ } & {
875
+ 401: {
876
+ description: string;
877
+ content: {
878
+ "application/json": {
879
+ schema: z.core.$ZodBranded<z.ZodObject<{
880
+ success: z.ZodLiteral<false>;
881
+ code: z.ZodOptional<z.ZodString>;
882
+ message: z.ZodOptional<z.ZodString>;
883
+ }, z.core.$strip>, "error">;
884
+ };
885
+ };
886
+ };
887
+ };
888
+ operationId: "listActiveSubscriptions";
889
+ path: "/subscription/list";
890
+ method: "get";
891
+ middleware: [(ctx: hono0.Context<faire_auth0.ContextVars<object & {
892
+ session: {
893
+ session: {
894
+ [x: string]: unknown;
895
+ createdAt: Date;
896
+ updatedAt: Date;
897
+ userId: string;
898
+ expiresAt: Date;
899
+ token: string;
900
+ id?: string;
901
+ ipAddress?: string | null;
902
+ userAgent?: string | null;
903
+ };
904
+ user: {
905
+ [x: string]: unknown;
906
+ id: string;
907
+ createdAt: Date;
908
+ updatedAt: Date;
909
+ email: string;
910
+ emailVerified: boolean;
911
+ name?: string;
912
+ image?: string | null;
913
+ };
914
+ };
915
+ }>, string, {}>, next: hono0.Next) => Promise<void | (Response & hono0.TypedResponse<{
916
+ success: false;
917
+ code?: string | undefined;
918
+ message?: string | undefined;
919
+ }, 401>)>, (ctx: hono0.Context<faire_auth0.ContextVars<{
920
+ session?: {
921
+ session: Session;
922
+ user: User;
923
+ };
924
+ }>, "/subscription/upgrade" | "/subscription/cancel" | "/subscription/list" | "/subscription/restore" | "/subscription/billing-portal", {
925
+ out: {
926
+ json: {
927
+ referenceId?: string;
928
+ };
929
+ query: {
930
+ referenceId?: string;
931
+ };
932
+ };
933
+ }>, next: hono0.Next) => Promise<void | (Response & hono0.TypedResponse<{
934
+ success: false;
935
+ }, 401, "json">) | (Response & hono0.TypedResponse<{
936
+ success: false;
937
+ }, 400, "json">)>];
938
+ request: {
939
+ query: z.ZodObject<{
940
+ referenceId: z.ZodOptional<z.ZodString>;
941
+ }, z.core.$strip>;
942
+ };
943
+ getRoutingPath: () => "/subscription/list";
944
+ }>;
945
+ readonly subscriptionSuccess: faire_auth0.AuthEndpoint<{
946
+ responses: {
947
+ 200: {
948
+ description: string;
949
+ content: {
950
+ "application/json": {
951
+ schema: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
952
+ };
953
+ };
954
+ };
955
+ } & {
956
+ 302: {
957
+ description: string;
958
+ };
959
+ };
960
+ operationId: "subscriptionSuccess";
961
+ path: "/subscription/success";
962
+ method: "get";
963
+ middleware: [(ctx: hono0.Context<faire_auth0.ContextVars<object>, string, {}>, next: hono0.Next) => Promise<void | Response>];
964
+ request: {
965
+ query: z.ZodObject<{
966
+ callbackURL: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodTransform<string | undefined, string | undefined>, z.ZodOptional<z.ZodURL>>, z.ZodTransform<string | undefined, string | undefined>>>;
967
+ subscriptionId: z.ZodOptional<z.ZodString>;
968
+ }, z.core.$strip>;
969
+ };
970
+ getRoutingPath: () => "/subscription/success";
971
+ }>;
972
+ readonly createBillingPortal: faire_auth0.AuthEndpoint<{
973
+ responses: {
974
+ 200: {
975
+ description: string;
976
+ content: {
977
+ "application/json": {
978
+ schema: z.ZodObject<{
979
+ url: z.ZodString;
980
+ redirect: z.ZodLiteral<true>;
981
+ }, z.core.$strip>;
982
+ };
983
+ };
984
+ };
985
+ } & {
986
+ 400: {
987
+ description: string;
988
+ content: {
989
+ "application/json": {
990
+ schema: z.core.$ZodBranded<z.ZodObject<{
991
+ success: z.ZodLiteral<false>;
992
+ code: z.ZodOptional<z.ZodString>;
993
+ message: z.ZodOptional<z.ZodString>;
994
+ }, z.core.$strip>, "error">;
995
+ };
996
+ };
997
+ };
998
+ } & {
999
+ 401: {
1000
+ description: string;
1001
+ content: {
1002
+ "application/json": {
1003
+ schema: z.core.$ZodBranded<z.ZodObject<{
1004
+ success: z.ZodLiteral<false>;
1005
+ code: z.ZodOptional<z.ZodString>;
1006
+ message: z.ZodOptional<z.ZodString>;
1007
+ }, z.core.$strip>, "error">;
1008
+ };
1009
+ };
1010
+ };
1011
+ };
1012
+ operationId: "createBillingPortal";
1013
+ path: "/subscription/billing-portal";
1014
+ method: "post";
1015
+ middleware: [(ctx: hono0.Context<faire_auth0.ContextVars<{
1016
+ session: {
1017
+ user: {
1018
+ stripeCustomerId?: string;
1019
+ };
1020
+ };
1021
+ } & {
1022
+ session: {
1023
+ session: {
1024
+ [x: string]: unknown;
1025
+ createdAt: Date;
1026
+ updatedAt: Date;
1027
+ userId: string;
1028
+ expiresAt: Date;
1029
+ token: string;
1030
+ id?: string;
1031
+ ipAddress?: string | null;
1032
+ userAgent?: string | null;
1033
+ };
1034
+ user: {
1035
+ [x: string]: unknown;
1036
+ id: string;
1037
+ createdAt: Date;
1038
+ updatedAt: Date;
1039
+ email: string;
1040
+ emailVerified: boolean;
1041
+ name?: string;
1042
+ image?: string | null;
1043
+ };
1044
+ };
1045
+ }>, string, {}>, next: hono0.Next) => Promise<void | (Response & hono0.TypedResponse<{
1046
+ success: false;
1047
+ code?: string | undefined;
1048
+ message?: string | undefined;
1049
+ }, 401>)>, (ctx: hono0.Context<faire_auth0.ContextVars<object>, string, {}>, next: hono0.Next) => Promise<void | Response>, (ctx: hono0.Context<faire_auth0.ContextVars<{
1050
+ session?: {
1051
+ session: Session;
1052
+ user: User;
1053
+ };
1054
+ }>, "/subscription/upgrade" | "/subscription/cancel" | "/subscription/list" | "/subscription/restore" | "/subscription/billing-portal", {
1055
+ out: {
1056
+ json: {
1057
+ referenceId?: string;
1058
+ };
1059
+ query: {
1060
+ referenceId?: string;
1061
+ };
1062
+ };
1063
+ }>, next: hono0.Next) => Promise<void | (Response & hono0.TypedResponse<{
1064
+ success: false;
1065
+ }, 401, "json">) | (Response & hono0.TypedResponse<{
1066
+ success: false;
1067
+ }, 400, "json">)>];
1068
+ request: {
1069
+ body: {
1070
+ description?: string;
1071
+ content: {
1072
+ "application/json": {
1073
+ schema: z.ZodObject<{
1074
+ locale: z.ZodOptional<z.ZodCustom<Stripe.Checkout.Session.Locale, Stripe.Checkout.Session.Locale>>;
1075
+ referenceId: z.ZodOptional<z.ZodString>;
1076
+ returnUrl: z.ZodDefault<z.ZodString>;
1077
+ }, z.core.$strip>;
1078
+ };
1079
+ };
1080
+ required: true;
1081
+ };
1082
+ };
1083
+ getRoutingPath: () => "/subscription/billing-portal";
1084
+ }>;
1085
+ } : {});
1086
+ init(ctx: _faire_auth_core_types0.AuthContext<faire_auth0.ContextVars<any>, _faire_auth_core_types0.FaireAuthOptions<faire_auth0.ContextVars<any>>>): {
1087
+ options: {
1088
+ databaseHooks: {
1089
+ user: {
1090
+ create: {
1091
+ after(user: {
1092
+ [x: string]: unknown;
1093
+ id: string;
1094
+ createdAt: Date;
1095
+ updatedAt: Date;
1096
+ email: string;
1097
+ emailVerified: boolean;
1098
+ name?: string;
1099
+ image?: string | null;
1100
+ }, ctx: hono0.Context<any, any, {}> | undefined): Promise<void>;
1101
+ };
1102
+ };
1103
+ };
1104
+ };
1105
+ };
1106
+ schema: {};
1107
+ };
1108
+ type StripePlugin<O extends StripeOptions> = ReturnType<typeof stripe<O>>;
1109
+ //#endregion
1110
+ export { Subscription as i, stripe as n, StripePlan as r, StripePlugin as t };