@commet/better-auth 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,1366 @@
1
+ import * as better_auth_client from 'better-auth/client';
2
+ import { BetterFetchOption } from 'better-auth/client';
3
+ import * as zod from 'zod';
4
+ import { z } from 'zod';
5
+ import * as _commet_node from '@commet/node';
6
+ import { Commet, WebhookPayload } from '@commet/node';
7
+ import * as better_auth from 'better-auth';
8
+ import { User, UnionToIntersection } from 'better-auth';
9
+
10
+ interface FeaturesConfig {
11
+ }
12
+ /**
13
+ * Features plugin - Check feature access and usage
14
+ *
15
+ * Endpoints:
16
+ * - GET /features - List all features for the authenticated user
17
+ * - GET /features/:code - Get a specific feature's access/usage
18
+ * - GET /features/:code/check - Check if feature is enabled (boolean check)
19
+ * - GET /features/:code/can-use - Check if user can use one more unit
20
+ */
21
+ declare const features: (_config?: FeaturesConfig) => (commet: Commet) => {
22
+ listFeatures: better_auth.StrictEndpoint<"/commet/features", {
23
+ method: "GET";
24
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
25
+ session: {
26
+ session: Record<string, any> & {
27
+ id: string;
28
+ createdAt: Date;
29
+ updatedAt: Date;
30
+ userId: string;
31
+ expiresAt: Date;
32
+ token: string;
33
+ ipAddress?: string | null | undefined;
34
+ userAgent?: string | null | undefined;
35
+ };
36
+ user: Record<string, any> & {
37
+ id: string;
38
+ createdAt: Date;
39
+ updatedAt: Date;
40
+ email: string;
41
+ emailVerified: boolean;
42
+ name: string;
43
+ image?: string | null | undefined;
44
+ };
45
+ };
46
+ }>)[];
47
+ }, _commet_node.FeatureAccess[] | null>;
48
+ getFeature: better_auth.StrictEndpoint<"/commet/features/:code", {
49
+ method: "GET";
50
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
51
+ session: {
52
+ session: Record<string, any> & {
53
+ id: string;
54
+ createdAt: Date;
55
+ updatedAt: Date;
56
+ userId: string;
57
+ expiresAt: Date;
58
+ token: string;
59
+ ipAddress?: string | null | undefined;
60
+ userAgent?: string | null | undefined;
61
+ };
62
+ user: Record<string, any> & {
63
+ id: string;
64
+ createdAt: Date;
65
+ updatedAt: Date;
66
+ email: string;
67
+ emailVerified: boolean;
68
+ name: string;
69
+ image?: string | null | undefined;
70
+ };
71
+ };
72
+ }>)[];
73
+ }, _commet_node.FeatureAccess | null>;
74
+ checkFeature: better_auth.StrictEndpoint<"/commet/features/:code/check", {
75
+ method: "GET";
76
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
77
+ session: {
78
+ session: Record<string, any> & {
79
+ id: string;
80
+ createdAt: Date;
81
+ updatedAt: Date;
82
+ userId: string;
83
+ expiresAt: Date;
84
+ token: string;
85
+ ipAddress?: string | null | undefined;
86
+ userAgent?: string | null | undefined;
87
+ };
88
+ user: Record<string, any> & {
89
+ id: string;
90
+ createdAt: Date;
91
+ updatedAt: Date;
92
+ email: string;
93
+ emailVerified: boolean;
94
+ name: string;
95
+ image?: string | null | undefined;
96
+ };
97
+ };
98
+ }>)[];
99
+ }, _commet_node.CheckResult | null>;
100
+ canUseFeature: better_auth.StrictEndpoint<"/commet/features/:code/can-use", {
101
+ method: "GET";
102
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
103
+ session: {
104
+ session: Record<string, any> & {
105
+ id: string;
106
+ createdAt: Date;
107
+ updatedAt: Date;
108
+ userId: string;
109
+ expiresAt: Date;
110
+ token: string;
111
+ ipAddress?: string | null | undefined;
112
+ userAgent?: string | null | undefined;
113
+ };
114
+ user: Record<string, any> & {
115
+ id: string;
116
+ createdAt: Date;
117
+ updatedAt: Date;
118
+ email: string;
119
+ emailVerified: boolean;
120
+ name: string;
121
+ image?: string | null | undefined;
122
+ };
123
+ };
124
+ }>)[];
125
+ }, _commet_node.CanUseResult | null>;
126
+ };
127
+
128
+ interface PortalConfig {
129
+ /**
130
+ * URL to return to after leaving the customer portal
131
+ */
132
+ returnUrl?: string;
133
+ }
134
+ /**
135
+ * Portal plugin - Provides customer portal access
136
+ *
137
+ * Endpoints:
138
+ * - GET /customer/portal - Redirects to the Commet customer portal
139
+ */
140
+ declare const portal: ({ returnUrl }?: PortalConfig) => (commet: Commet) => {
141
+ portal: better_auth.StrictEndpoint<"/commet/portal", {
142
+ method: "GET";
143
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
144
+ session: {
145
+ session: Record<string, any> & {
146
+ id: string;
147
+ createdAt: Date;
148
+ updatedAt: Date;
149
+ userId: string;
150
+ expiresAt: Date;
151
+ token: string;
152
+ ipAddress?: string | null | undefined;
153
+ userAgent?: string | null | undefined;
154
+ };
155
+ user: Record<string, any> & {
156
+ id: string;
157
+ createdAt: Date;
158
+ updatedAt: Date;
159
+ email: string;
160
+ emailVerified: boolean;
161
+ name: string;
162
+ image?: string | null | undefined;
163
+ };
164
+ };
165
+ }>)[];
166
+ }, {
167
+ url: string;
168
+ redirect: boolean;
169
+ }>;
170
+ };
171
+
172
+ interface SeatsConfig {
173
+ }
174
+ /**
175
+ * Seats plugin - Manage seat-based licensing
176
+ *
177
+ * Endpoints:
178
+ * - GET /seats - List all seat balances for the authenticated user
179
+ * - POST /seats/add - Add seats of a specific type
180
+ * - POST /seats/remove - Remove seats of a specific type
181
+ * - POST /seats/set - Set seats to a specific count
182
+ * - POST /seats/set-all - Set all seat types at once
183
+ */
184
+ declare const seats: (_config?: SeatsConfig) => (commet: Commet) => {
185
+ listSeats: better_auth.StrictEndpoint<"/commet/seats", {
186
+ method: "GET";
187
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
188
+ session: {
189
+ session: Record<string, any> & {
190
+ id: string;
191
+ createdAt: Date;
192
+ updatedAt: Date;
193
+ userId: string;
194
+ expiresAt: Date;
195
+ token: string;
196
+ ipAddress?: string | null | undefined;
197
+ userAgent?: string | null | undefined;
198
+ };
199
+ user: Record<string, any> & {
200
+ id: string;
201
+ createdAt: Date;
202
+ updatedAt: Date;
203
+ email: string;
204
+ emailVerified: boolean;
205
+ name: string;
206
+ image?: string | null | undefined;
207
+ };
208
+ };
209
+ }>)[];
210
+ }, Record<string, _commet_node.SeatBalance> | null>;
211
+ addSeats: better_auth.StrictEndpoint<"/commet/seats/add", {
212
+ method: "POST";
213
+ body: z.ZodObject<{
214
+ seatType: z.ZodString;
215
+ count: z.ZodNumber;
216
+ }, z.core.$strip>;
217
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
218
+ session: {
219
+ session: Record<string, any> & {
220
+ id: string;
221
+ createdAt: Date;
222
+ updatedAt: Date;
223
+ userId: string;
224
+ expiresAt: Date;
225
+ token: string;
226
+ ipAddress?: string | null | undefined;
227
+ userAgent?: string | null | undefined;
228
+ };
229
+ user: Record<string, any> & {
230
+ id: string;
231
+ createdAt: Date;
232
+ updatedAt: Date;
233
+ email: string;
234
+ emailVerified: boolean;
235
+ name: string;
236
+ image?: string | null | undefined;
237
+ };
238
+ };
239
+ }>)[];
240
+ }, _commet_node.SeatEvent | null>;
241
+ removeSeats: better_auth.StrictEndpoint<"/commet/seats/remove", {
242
+ method: "POST";
243
+ body: z.ZodObject<{
244
+ seatType: z.ZodString;
245
+ count: z.ZodNumber;
246
+ }, z.core.$strip>;
247
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
248
+ session: {
249
+ session: Record<string, any> & {
250
+ id: string;
251
+ createdAt: Date;
252
+ updatedAt: Date;
253
+ userId: string;
254
+ expiresAt: Date;
255
+ token: string;
256
+ ipAddress?: string | null | undefined;
257
+ userAgent?: string | null | undefined;
258
+ };
259
+ user: Record<string, any> & {
260
+ id: string;
261
+ createdAt: Date;
262
+ updatedAt: Date;
263
+ email: string;
264
+ emailVerified: boolean;
265
+ name: string;
266
+ image?: string | null | undefined;
267
+ };
268
+ };
269
+ }>)[];
270
+ }, _commet_node.SeatEvent | null>;
271
+ setSeats: better_auth.StrictEndpoint<"/commet/seats/set", {
272
+ method: "POST";
273
+ body: z.ZodObject<{
274
+ seatType: z.ZodString;
275
+ count: z.ZodNumber;
276
+ }, z.core.$strip>;
277
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
278
+ session: {
279
+ session: Record<string, any> & {
280
+ id: string;
281
+ createdAt: Date;
282
+ updatedAt: Date;
283
+ userId: string;
284
+ expiresAt: Date;
285
+ token: string;
286
+ ipAddress?: string | null | undefined;
287
+ userAgent?: string | null | undefined;
288
+ };
289
+ user: Record<string, any> & {
290
+ id: string;
291
+ createdAt: Date;
292
+ updatedAt: Date;
293
+ email: string;
294
+ emailVerified: boolean;
295
+ name: string;
296
+ image?: string | null | undefined;
297
+ };
298
+ };
299
+ }>)[];
300
+ }, _commet_node.SeatEvent | null>;
301
+ setAllSeats: better_auth.StrictEndpoint<"/commet/seats/set-all", {
302
+ method: "POST";
303
+ body: z.ZodObject<{
304
+ seats: z.ZodRecord<z.ZodString, z.ZodNumber>;
305
+ }, z.core.$strip>;
306
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
307
+ session: {
308
+ session: Record<string, any> & {
309
+ id: string;
310
+ createdAt: Date;
311
+ updatedAt: Date;
312
+ userId: string;
313
+ expiresAt: Date;
314
+ token: string;
315
+ ipAddress?: string | null | undefined;
316
+ userAgent?: string | null | undefined;
317
+ };
318
+ user: Record<string, any> & {
319
+ id: string;
320
+ createdAt: Date;
321
+ updatedAt: Date;
322
+ email: string;
323
+ emailVerified: boolean;
324
+ name: string;
325
+ image?: string | null | undefined;
326
+ };
327
+ };
328
+ }>)[];
329
+ }, _commet_node.SeatEvent[] | null>;
330
+ };
331
+
332
+ interface SubscriptionsConfig {
333
+ /**
334
+ * Optional plan mappings for easy slug-based plan changes
335
+ */
336
+ plans?: Array<{
337
+ planId: string;
338
+ slug: string;
339
+ }>;
340
+ }
341
+ /**
342
+ * Subscriptions plugin - Manage customer subscriptions
343
+ *
344
+ * Endpoints:
345
+ * - GET /subscription - Get active subscription for the authenticated user
346
+ * - POST /subscription/change-plan - Change subscription plan (upgrade/downgrade)
347
+ * - POST /subscription/cancel - Cancel the subscription
348
+ */
349
+ declare const subscriptions: (config?: SubscriptionsConfig) => (commet: Commet) => {
350
+ getSubscription: better_auth.StrictEndpoint<"/commet/subscription", {
351
+ method: "GET";
352
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
353
+ session: {
354
+ session: Record<string, any> & {
355
+ id: string;
356
+ createdAt: Date;
357
+ updatedAt: Date;
358
+ userId: string;
359
+ expiresAt: Date;
360
+ token: string;
361
+ ipAddress?: string | null | undefined;
362
+ userAgent?: string | null | undefined;
363
+ };
364
+ user: Record<string, any> & {
365
+ id: string;
366
+ createdAt: Date;
367
+ updatedAt: Date;
368
+ email: string;
369
+ emailVerified: boolean;
370
+ name: string;
371
+ image?: string | null | undefined;
372
+ };
373
+ };
374
+ }>)[];
375
+ }, _commet_node.ActiveSubscription | null>;
376
+ changePlan: better_auth.StrictEndpoint<"/commet/subscription/change-plan", {
377
+ method: "POST";
378
+ body: z.ZodObject<{
379
+ planId: z.ZodOptional<z.ZodString>;
380
+ slug: z.ZodOptional<z.ZodString>;
381
+ billingInterval: z.ZodOptional<z.ZodEnum<{
382
+ monthly: "monthly";
383
+ quarterly: "quarterly";
384
+ yearly: "yearly";
385
+ }>>;
386
+ }, z.core.$strip>;
387
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
388
+ session: {
389
+ session: Record<string, any> & {
390
+ id: string;
391
+ createdAt: Date;
392
+ updatedAt: Date;
393
+ userId: string;
394
+ expiresAt: Date;
395
+ token: string;
396
+ ipAddress?: string | null | undefined;
397
+ userAgent?: string | null | undefined;
398
+ };
399
+ user: Record<string, any> & {
400
+ id: string;
401
+ createdAt: Date;
402
+ updatedAt: Date;
403
+ email: string;
404
+ emailVerified: boolean;
405
+ name: string;
406
+ image?: string | null | undefined;
407
+ };
408
+ };
409
+ }>)[];
410
+ }, _commet_node.Subscription | null>;
411
+ cancelSubscription: better_auth.StrictEndpoint<"/commet/subscription/cancel", {
412
+ method: "POST";
413
+ body: z.ZodOptional<z.ZodObject<{
414
+ reason: z.ZodOptional<z.ZodString>;
415
+ immediate: z.ZodOptional<z.ZodBoolean>;
416
+ }, z.core.$strip>>;
417
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
418
+ session: {
419
+ session: Record<string, any> & {
420
+ id: string;
421
+ createdAt: Date;
422
+ updatedAt: Date;
423
+ userId: string;
424
+ expiresAt: Date;
425
+ token: string;
426
+ ipAddress?: string | null | undefined;
427
+ userAgent?: string | null | undefined;
428
+ };
429
+ user: Record<string, any> & {
430
+ id: string;
431
+ createdAt: Date;
432
+ updatedAt: Date;
433
+ email: string;
434
+ emailVerified: boolean;
435
+ name: string;
436
+ image?: string | null | undefined;
437
+ };
438
+ };
439
+ }>)[];
440
+ }, _commet_node.Subscription | null>;
441
+ };
442
+
443
+ interface UsageConfig {
444
+ }
445
+ /**
446
+ * Usage plugin - Track usage events for metered billing
447
+ *
448
+ * Endpoints:
449
+ * - POST /usage/track - Track a usage event for the authenticated user
450
+ */
451
+ declare const usage: (_config?: UsageConfig) => (commet: Commet) => {
452
+ trackUsage: better_auth.StrictEndpoint<"/commet/usage/track", {
453
+ method: "POST";
454
+ body: z.ZodObject<{
455
+ eventType: z.ZodString;
456
+ value: z.ZodOptional<z.ZodNumber>;
457
+ idempotencyKey: z.ZodOptional<z.ZodString>;
458
+ properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
459
+ }, z.core.$strip>;
460
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
461
+ session: {
462
+ session: Record<string, any> & {
463
+ id: string;
464
+ createdAt: Date;
465
+ updatedAt: Date;
466
+ userId: string;
467
+ expiresAt: Date;
468
+ token: string;
469
+ ipAddress?: string | null | undefined;
470
+ userAgent?: string | null | undefined;
471
+ };
472
+ user: Record<string, any> & {
473
+ id: string;
474
+ createdAt: Date;
475
+ updatedAt: Date;
476
+ email: string;
477
+ emailVerified: boolean;
478
+ name: string;
479
+ image?: string | null | undefined;
480
+ };
481
+ };
482
+ }>)[];
483
+ }, _commet_node.UsageEvent | null>;
484
+ };
485
+
486
+ /**
487
+ * Webhook handler function type
488
+ */
489
+ type WebhookHandler<T = WebhookPayload> = (payload: T) => Promise<void>;
490
+ /**
491
+ * Webhooks plugin configuration
492
+ *
493
+ * Note: Webhooks are OPTIONAL in Commet. You can always query the current state
494
+ * using subscriptions.get(), features.list(), etc. Webhooks are useful if you want
495
+ * to react immediately to events without polling.
496
+ */
497
+ interface WebhooksConfig {
498
+ /**
499
+ * Webhook secret for signature verification
500
+ */
501
+ secret: string;
502
+ /**
503
+ * Handler for subscription.created events
504
+ */
505
+ onSubscriptionCreated?: WebhookHandler;
506
+ /**
507
+ * Handler for subscription.activated events
508
+ */
509
+ onSubscriptionActivated?: WebhookHandler;
510
+ /**
511
+ * Handler for subscription.canceled events
512
+ */
513
+ onSubscriptionCanceled?: WebhookHandler;
514
+ /**
515
+ * Handler for subscription.updated events
516
+ */
517
+ onSubscriptionUpdated?: WebhookHandler;
518
+ /**
519
+ * Generic handler for all webhook events (catch-all)
520
+ */
521
+ onPayload?: WebhookHandler;
522
+ }
523
+ /**
524
+ * Webhooks plugin - Handle incoming Commet webhooks (OPTIONAL)
525
+ *
526
+ * You can always query the current state directly:
527
+ * - authClient.subscription.get() for subscription status
528
+ * - authClient.features.list() for feature access
529
+ * - authClient.features.canUse() for usage checks
530
+ *
531
+ * Webhooks are useful when you want to:
532
+ * - React immediately to changes (e.g., send email on cancellation)
533
+ * - Avoid polling latency in critical cases
534
+ * - Audit/log events
535
+ *
536
+ * Endpoint:
537
+ * - POST /commet/webhooks - Receive and process Commet webhooks
538
+ */
539
+ declare const webhooks: (config: WebhooksConfig) => (commet: Commet) => {
540
+ commetWebhooks: better_auth.StrictEndpoint<"/commet/webhooks", {
541
+ method: "POST";
542
+ metadata: {
543
+ isAction: false;
544
+ };
545
+ cloneRequest: true;
546
+ }, {
547
+ received: boolean;
548
+ }>;
549
+ };
550
+
551
+ /**
552
+ * Plan mapping for easy reference in subscriptions
553
+ */
554
+ interface PlanMapping {
555
+ /**
556
+ * Plan ID from Commet
557
+ */
558
+ planId: string;
559
+ /**
560
+ * Easily identifiable slug for the plan
561
+ */
562
+ slug: string;
563
+ }
564
+ /**
565
+ * Union type of all Commet plugins
566
+ */
567
+ type CommetPlugin = ReturnType<typeof portal> | ReturnType<typeof subscriptions> | ReturnType<typeof features> | ReturnType<typeof usage> | ReturnType<typeof seats> | ReturnType<typeof webhooks>;
568
+ /**
569
+ * Array of Commet plugins (at least one required)
570
+ */
571
+ type CommetPlugins = [CommetPlugin, ...CommetPlugin[]];
572
+ /**
573
+ * Intersection of all plugin endpoints
574
+ */
575
+ type CommetEndpoints = UnionToIntersection<ReturnType<CommetPlugin>>;
576
+ /**
577
+ * Customer creation parameters that can be customized
578
+ */
579
+ interface CustomerCreateParams {
580
+ /**
581
+ * Legal name of the customer/company
582
+ */
583
+ legalName?: string;
584
+ /**
585
+ * Display name
586
+ */
587
+ displayName?: string;
588
+ /**
589
+ * Company domain
590
+ */
591
+ domain?: string;
592
+ /**
593
+ * Custom metadata
594
+ */
595
+ metadata?: Record<string, unknown>;
596
+ }
597
+ /**
598
+ * Main Commet plugin options
599
+ */
600
+ interface CommetOptions {
601
+ /**
602
+ * Commet SDK client instance
603
+ */
604
+ client: Commet;
605
+ /**
606
+ * Automatically create a Commet customer when a user signs up
607
+ * @default false
608
+ */
609
+ createCustomerOnSignUp?: boolean;
610
+ /**
611
+ * Custom function to provide additional customer creation parameters
612
+ * Called when a new user signs up (if createCustomerOnSignUp is true)
613
+ *
614
+ * @param data - Object containing the user being created
615
+ * @param request - Optional request object for additional context
616
+ * @returns Customer creation parameters
617
+ */
618
+ getCustomerCreateParams?: (data: {
619
+ user: Partial<User>;
620
+ }, request?: Request) => Promise<CustomerCreateParams> | CustomerCreateParams;
621
+ /**
622
+ * Array of Commet plugins to use
623
+ */
624
+ use: CommetPlugins;
625
+ }
626
+
627
+ /**
628
+ * Commet plugin for Better Auth
629
+ *
630
+ * Integrates Commet billing with Better Auth authentication.
631
+ *
632
+ * @example
633
+ * ```typescript
634
+ * import { betterAuth } from "better-auth";
635
+ * import { commet, portal, subscriptions, features, usage, seats, webhooks } from "@commet/better-auth";
636
+ * import { Commet } from "@commet/node";
637
+ *
638
+ * const commetClient = new Commet({
639
+ * apiKey: process.env.COMMET_API_KEY,
640
+ * environment: "production"
641
+ * });
642
+ *
643
+ * const auth = betterAuth({
644
+ * plugins: [
645
+ * commet({
646
+ * client: commetClient,
647
+ * createCustomerOnSignUp: true,
648
+ * getCustomerCreateParams: ({ user }) => ({
649
+ * legalName: user.name,
650
+ * metadata: { source: "signup" }
651
+ * }),
652
+ * use: [
653
+ * portal({ returnUrl: "/dashboard" }),
654
+ * subscriptions(),
655
+ * features(),
656
+ * usage(),
657
+ * seats(),
658
+ * // Webhooks are OPTIONAL - you can always query state directly
659
+ * webhooks({
660
+ * secret: process.env.COMMET_WEBHOOK_SECRET,
661
+ * onSubscriptionActivated: async (payload) => { ... }
662
+ * })
663
+ * ]
664
+ * })
665
+ * ]
666
+ * });
667
+ * ```
668
+ */
669
+ declare const commet: <O extends CommetOptions>(options: O) => {
670
+ id: "commet";
671
+ endpoints: {
672
+ portal: better_auth.StrictEndpoint<"/commet/portal", {
673
+ method: "GET";
674
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
675
+ session: {
676
+ session: Record<string, any> & {
677
+ id: string;
678
+ createdAt: Date;
679
+ updatedAt: Date;
680
+ userId: string;
681
+ expiresAt: Date;
682
+ token: string;
683
+ ipAddress?: string | null | undefined;
684
+ userAgent?: string | null | undefined;
685
+ };
686
+ user: Record<string, any> & {
687
+ id: string;
688
+ createdAt: Date;
689
+ updatedAt: Date;
690
+ email: string;
691
+ emailVerified: boolean;
692
+ name: string;
693
+ image?: string | null | undefined;
694
+ };
695
+ };
696
+ }>)[];
697
+ }, {
698
+ url: string;
699
+ redirect: boolean;
700
+ }>;
701
+ } | {
702
+ getSubscription: better_auth.StrictEndpoint<"/commet/subscription", {
703
+ method: "GET";
704
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
705
+ session: {
706
+ session: Record<string, any> & {
707
+ id: string;
708
+ createdAt: Date;
709
+ updatedAt: Date;
710
+ userId: string;
711
+ expiresAt: Date;
712
+ token: string;
713
+ ipAddress?: string | null | undefined;
714
+ userAgent?: string | null | undefined;
715
+ };
716
+ user: Record<string, any> & {
717
+ id: string;
718
+ createdAt: Date;
719
+ updatedAt: Date;
720
+ email: string;
721
+ emailVerified: boolean;
722
+ name: string;
723
+ image?: string | null | undefined;
724
+ };
725
+ };
726
+ }>)[];
727
+ }, _commet_node.ActiveSubscription | null>;
728
+ changePlan: better_auth.StrictEndpoint<"/commet/subscription/change-plan", {
729
+ method: "POST";
730
+ body: zod.ZodObject<{
731
+ planId: zod.ZodOptional<zod.ZodString>;
732
+ slug: zod.ZodOptional<zod.ZodString>;
733
+ billingInterval: zod.ZodOptional<zod.ZodEnum<{
734
+ monthly: "monthly";
735
+ quarterly: "quarterly";
736
+ yearly: "yearly";
737
+ }>>;
738
+ }, better_auth.$strip>;
739
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
740
+ session: {
741
+ session: Record<string, any> & {
742
+ id: string;
743
+ createdAt: Date;
744
+ updatedAt: Date;
745
+ userId: string;
746
+ expiresAt: Date;
747
+ token: string;
748
+ ipAddress?: string | null | undefined;
749
+ userAgent?: string | null | undefined;
750
+ };
751
+ user: Record<string, any> & {
752
+ id: string;
753
+ createdAt: Date;
754
+ updatedAt: Date;
755
+ email: string;
756
+ emailVerified: boolean;
757
+ name: string;
758
+ image?: string | null | undefined;
759
+ };
760
+ };
761
+ }>)[];
762
+ }, _commet_node.Subscription | null>;
763
+ cancelSubscription: better_auth.StrictEndpoint<"/commet/subscription/cancel", {
764
+ method: "POST";
765
+ body: zod.ZodOptional<zod.ZodObject<{
766
+ reason: zod.ZodOptional<zod.ZodString>;
767
+ immediate: zod.ZodOptional<zod.ZodBoolean>;
768
+ }, better_auth.$strip>>;
769
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
770
+ session: {
771
+ session: Record<string, any> & {
772
+ id: string;
773
+ createdAt: Date;
774
+ updatedAt: Date;
775
+ userId: string;
776
+ expiresAt: Date;
777
+ token: string;
778
+ ipAddress?: string | null | undefined;
779
+ userAgent?: string | null | undefined;
780
+ };
781
+ user: Record<string, any> & {
782
+ id: string;
783
+ createdAt: Date;
784
+ updatedAt: Date;
785
+ email: string;
786
+ emailVerified: boolean;
787
+ name: string;
788
+ image?: string | null | undefined;
789
+ };
790
+ };
791
+ }>)[];
792
+ }, _commet_node.Subscription | null>;
793
+ } | {
794
+ listFeatures: better_auth.StrictEndpoint<"/commet/features", {
795
+ method: "GET";
796
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
797
+ session: {
798
+ session: Record<string, any> & {
799
+ id: string;
800
+ createdAt: Date;
801
+ updatedAt: Date;
802
+ userId: string;
803
+ expiresAt: Date;
804
+ token: string;
805
+ ipAddress?: string | null | undefined;
806
+ userAgent?: string | null | undefined;
807
+ };
808
+ user: Record<string, any> & {
809
+ id: string;
810
+ createdAt: Date;
811
+ updatedAt: Date;
812
+ email: string;
813
+ emailVerified: boolean;
814
+ name: string;
815
+ image?: string | null | undefined;
816
+ };
817
+ };
818
+ }>)[];
819
+ }, _commet_node.FeatureAccess[] | null>;
820
+ getFeature: better_auth.StrictEndpoint<"/commet/features/:code", {
821
+ method: "GET";
822
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
823
+ session: {
824
+ session: Record<string, any> & {
825
+ id: string;
826
+ createdAt: Date;
827
+ updatedAt: Date;
828
+ userId: string;
829
+ expiresAt: Date;
830
+ token: string;
831
+ ipAddress?: string | null | undefined;
832
+ userAgent?: string | null | undefined;
833
+ };
834
+ user: Record<string, any> & {
835
+ id: string;
836
+ createdAt: Date;
837
+ updatedAt: Date;
838
+ email: string;
839
+ emailVerified: boolean;
840
+ name: string;
841
+ image?: string | null | undefined;
842
+ };
843
+ };
844
+ }>)[];
845
+ }, _commet_node.FeatureAccess | null>;
846
+ checkFeature: better_auth.StrictEndpoint<"/commet/features/:code/check", {
847
+ method: "GET";
848
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
849
+ session: {
850
+ session: Record<string, any> & {
851
+ id: string;
852
+ createdAt: Date;
853
+ updatedAt: Date;
854
+ userId: string;
855
+ expiresAt: Date;
856
+ token: string;
857
+ ipAddress?: string | null | undefined;
858
+ userAgent?: string | null | undefined;
859
+ };
860
+ user: Record<string, any> & {
861
+ id: string;
862
+ createdAt: Date;
863
+ updatedAt: Date;
864
+ email: string;
865
+ emailVerified: boolean;
866
+ name: string;
867
+ image?: string | null | undefined;
868
+ };
869
+ };
870
+ }>)[];
871
+ }, _commet_node.CheckResult | null>;
872
+ canUseFeature: better_auth.StrictEndpoint<"/commet/features/:code/can-use", {
873
+ method: "GET";
874
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
875
+ session: {
876
+ session: Record<string, any> & {
877
+ id: string;
878
+ createdAt: Date;
879
+ updatedAt: Date;
880
+ userId: string;
881
+ expiresAt: Date;
882
+ token: string;
883
+ ipAddress?: string | null | undefined;
884
+ userAgent?: string | null | undefined;
885
+ };
886
+ user: Record<string, any> & {
887
+ id: string;
888
+ createdAt: Date;
889
+ updatedAt: Date;
890
+ email: string;
891
+ emailVerified: boolean;
892
+ name: string;
893
+ image?: string | null | undefined;
894
+ };
895
+ };
896
+ }>)[];
897
+ }, _commet_node.CanUseResult | null>;
898
+ } | {
899
+ trackUsage: better_auth.StrictEndpoint<"/commet/usage/track", {
900
+ method: "POST";
901
+ body: zod.ZodObject<{
902
+ eventType: zod.ZodString;
903
+ value: zod.ZodOptional<zod.ZodNumber>;
904
+ idempotencyKey: zod.ZodOptional<zod.ZodString>;
905
+ properties: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodString>>;
906
+ }, better_auth.$strip>;
907
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
908
+ session: {
909
+ session: Record<string, any> & {
910
+ id: string;
911
+ createdAt: Date;
912
+ updatedAt: Date;
913
+ userId: string;
914
+ expiresAt: Date;
915
+ token: string;
916
+ ipAddress?: string | null | undefined;
917
+ userAgent?: string | null | undefined;
918
+ };
919
+ user: Record<string, any> & {
920
+ id: string;
921
+ createdAt: Date;
922
+ updatedAt: Date;
923
+ email: string;
924
+ emailVerified: boolean;
925
+ name: string;
926
+ image?: string | null | undefined;
927
+ };
928
+ };
929
+ }>)[];
930
+ }, _commet_node.UsageEvent | null>;
931
+ } | {
932
+ listSeats: better_auth.StrictEndpoint<"/commet/seats", {
933
+ method: "GET";
934
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
935
+ session: {
936
+ session: Record<string, any> & {
937
+ id: string;
938
+ createdAt: Date;
939
+ updatedAt: Date;
940
+ userId: string;
941
+ expiresAt: Date;
942
+ token: string;
943
+ ipAddress?: string | null | undefined;
944
+ userAgent?: string | null | undefined;
945
+ };
946
+ user: Record<string, any> & {
947
+ id: string;
948
+ createdAt: Date;
949
+ updatedAt: Date;
950
+ email: string;
951
+ emailVerified: boolean;
952
+ name: string;
953
+ image?: string | null | undefined;
954
+ };
955
+ };
956
+ }>)[];
957
+ }, Record<string, _commet_node.SeatBalance> | null>;
958
+ addSeats: better_auth.StrictEndpoint<"/commet/seats/add", {
959
+ method: "POST";
960
+ body: zod.ZodObject<{
961
+ seatType: zod.ZodString;
962
+ count: zod.ZodNumber;
963
+ }, better_auth.$strip>;
964
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
965
+ session: {
966
+ session: Record<string, any> & {
967
+ id: string;
968
+ createdAt: Date;
969
+ updatedAt: Date;
970
+ userId: string;
971
+ expiresAt: Date;
972
+ token: string;
973
+ ipAddress?: string | null | undefined;
974
+ userAgent?: string | null | undefined;
975
+ };
976
+ user: Record<string, any> & {
977
+ id: string;
978
+ createdAt: Date;
979
+ updatedAt: Date;
980
+ email: string;
981
+ emailVerified: boolean;
982
+ name: string;
983
+ image?: string | null | undefined;
984
+ };
985
+ };
986
+ }>)[];
987
+ }, _commet_node.SeatEvent | null>;
988
+ removeSeats: better_auth.StrictEndpoint<"/commet/seats/remove", {
989
+ method: "POST";
990
+ body: zod.ZodObject<{
991
+ seatType: zod.ZodString;
992
+ count: zod.ZodNumber;
993
+ }, better_auth.$strip>;
994
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
995
+ session: {
996
+ session: Record<string, any> & {
997
+ id: string;
998
+ createdAt: Date;
999
+ updatedAt: Date;
1000
+ userId: string;
1001
+ expiresAt: Date;
1002
+ token: string;
1003
+ ipAddress?: string | null | undefined;
1004
+ userAgent?: string | null | undefined;
1005
+ };
1006
+ user: Record<string, any> & {
1007
+ id: string;
1008
+ createdAt: Date;
1009
+ updatedAt: Date;
1010
+ email: string;
1011
+ emailVerified: boolean;
1012
+ name: string;
1013
+ image?: string | null | undefined;
1014
+ };
1015
+ };
1016
+ }>)[];
1017
+ }, _commet_node.SeatEvent | null>;
1018
+ setSeats: better_auth.StrictEndpoint<"/commet/seats/set", {
1019
+ method: "POST";
1020
+ body: zod.ZodObject<{
1021
+ seatType: zod.ZodString;
1022
+ count: zod.ZodNumber;
1023
+ }, better_auth.$strip>;
1024
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
1025
+ session: {
1026
+ session: Record<string, any> & {
1027
+ id: string;
1028
+ createdAt: Date;
1029
+ updatedAt: Date;
1030
+ userId: string;
1031
+ expiresAt: Date;
1032
+ token: string;
1033
+ ipAddress?: string | null | undefined;
1034
+ userAgent?: string | null | undefined;
1035
+ };
1036
+ user: Record<string, any> & {
1037
+ id: string;
1038
+ createdAt: Date;
1039
+ updatedAt: Date;
1040
+ email: string;
1041
+ emailVerified: boolean;
1042
+ name: string;
1043
+ image?: string | null | undefined;
1044
+ };
1045
+ };
1046
+ }>)[];
1047
+ }, _commet_node.SeatEvent | null>;
1048
+ setAllSeats: better_auth.StrictEndpoint<"/commet/seats/set-all", {
1049
+ method: "POST";
1050
+ body: zod.ZodObject<{
1051
+ seats: zod.ZodRecord<zod.ZodString, zod.ZodNumber>;
1052
+ }, better_auth.$strip>;
1053
+ use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
1054
+ session: {
1055
+ session: Record<string, any> & {
1056
+ id: string;
1057
+ createdAt: Date;
1058
+ updatedAt: Date;
1059
+ userId: string;
1060
+ expiresAt: Date;
1061
+ token: string;
1062
+ ipAddress?: string | null | undefined;
1063
+ userAgent?: string | null | undefined;
1064
+ };
1065
+ user: Record<string, any> & {
1066
+ id: string;
1067
+ createdAt: Date;
1068
+ updatedAt: Date;
1069
+ email: string;
1070
+ emailVerified: boolean;
1071
+ name: string;
1072
+ image?: string | null | undefined;
1073
+ };
1074
+ };
1075
+ }>)[];
1076
+ }, _commet_node.SeatEvent[] | null>;
1077
+ } | {
1078
+ commetWebhooks: better_auth.StrictEndpoint<"/commet/webhooks", {
1079
+ method: "POST";
1080
+ metadata: {
1081
+ isAction: false;
1082
+ };
1083
+ cloneRequest: true;
1084
+ }, {
1085
+ received: boolean;
1086
+ }>;
1087
+ };
1088
+ init(): {
1089
+ options: {
1090
+ databaseHooks: {
1091
+ user: {
1092
+ create: {
1093
+ before: (user: Partial<better_auth.User>, context: better_auth.GenericEndpointContext | null) => Promise<void>;
1094
+ after: (user: better_auth.User, context: better_auth.GenericEndpointContext | null) => Promise<void>;
1095
+ };
1096
+ update: {
1097
+ after: (user: better_auth.User, context: better_auth.GenericEndpointContext | null) => Promise<void>;
1098
+ };
1099
+ delete: {
1100
+ after: (user: better_auth.User, context: better_auth.GenericEndpointContext | null) => Promise<void>;
1101
+ };
1102
+ };
1103
+ };
1104
+ };
1105
+ };
1106
+ };
1107
+
1108
+ /**
1109
+ * Commet client plugin for Better Auth
1110
+ *
1111
+ * Provides client-side methods to interact with Commet billing features.
1112
+ *
1113
+ * @example
1114
+ * ```typescript
1115
+ * import { createAuthClient } from "better-auth/react";
1116
+ * import { commetClient } from "@commet/better-auth";
1117
+ *
1118
+ * export const authClient = createAuthClient({
1119
+ * plugins: [commetClient()]
1120
+ * });
1121
+ *
1122
+ * // Usage - you can always query state directly (no webhooks needed)
1123
+ * const { data: subscription } = await authClient.subscription.get();
1124
+ * const { data: features } = await authClient.features.list();
1125
+ * const { data: canUse } = await authClient.features.canUse({ code: "api_calls" });
1126
+ * await authClient.usage.track({ eventType: "api_call" });
1127
+ * await authClient.customer.portal(); // Redirect to portal
1128
+ * ```
1129
+ */
1130
+ declare const commetClient: () => {
1131
+ id: "commet-client";
1132
+ $InferServerPlugin: ReturnType<typeof commet>;
1133
+ getActions: ($fetch: better_auth_client.BetterFetch) => {
1134
+ customer: {
1135
+ /**
1136
+ * Redirect to the Commet customer portal
1137
+ */
1138
+ portal: (fetchOptions?: BetterFetchOption) => Promise<{
1139
+ url: string;
1140
+ redirect: boolean;
1141
+ }>;
1142
+ };
1143
+ subscription: {
1144
+ /**
1145
+ * Get the current subscription for the authenticated user
1146
+ */
1147
+ get: (fetchOptions?: BetterFetchOption) => Promise<{
1148
+ data: unknown;
1149
+ error: null;
1150
+ } | {
1151
+ data: null;
1152
+ error: {
1153
+ message?: string | undefined;
1154
+ status: number;
1155
+ statusText: string;
1156
+ };
1157
+ }>;
1158
+ /**
1159
+ * Change the subscription plan (upgrade/downgrade)
1160
+ */
1161
+ changePlan: (data: {
1162
+ planId?: string;
1163
+ slug?: string;
1164
+ billingInterval?: "monthly" | "quarterly" | "yearly";
1165
+ }, fetchOptions?: BetterFetchOption) => Promise<{
1166
+ data: unknown;
1167
+ error: null;
1168
+ } | {
1169
+ data: null;
1170
+ error: {
1171
+ message?: string | undefined;
1172
+ status: number;
1173
+ statusText: string;
1174
+ };
1175
+ }>;
1176
+ /**
1177
+ * Cancel the subscription
1178
+ */
1179
+ cancel: (data?: {
1180
+ reason?: string;
1181
+ immediate?: boolean;
1182
+ }, fetchOptions?: BetterFetchOption) => Promise<{
1183
+ data: unknown;
1184
+ error: null;
1185
+ } | {
1186
+ data: null;
1187
+ error: {
1188
+ message?: string | undefined;
1189
+ status: number;
1190
+ statusText: string;
1191
+ };
1192
+ }>;
1193
+ };
1194
+ features: {
1195
+ /**
1196
+ * List all features for the authenticated user
1197
+ */
1198
+ list: (fetchOptions?: BetterFetchOption) => Promise<{
1199
+ data: unknown;
1200
+ error: null;
1201
+ } | {
1202
+ data: null;
1203
+ error: {
1204
+ message?: string | undefined;
1205
+ status: number;
1206
+ statusText: string;
1207
+ };
1208
+ }>;
1209
+ /**
1210
+ * Get a specific feature's access/usage
1211
+ */
1212
+ get: (data: {
1213
+ code: string;
1214
+ }, fetchOptions?: BetterFetchOption) => Promise<{
1215
+ data: unknown;
1216
+ error: null;
1217
+ } | {
1218
+ data: null;
1219
+ error: {
1220
+ message?: string | undefined;
1221
+ status: number;
1222
+ statusText: string;
1223
+ };
1224
+ }>;
1225
+ /**
1226
+ * Check if a feature is enabled (boolean check)
1227
+ */
1228
+ check: (data: {
1229
+ code: string;
1230
+ }, fetchOptions?: BetterFetchOption) => Promise<{
1231
+ data: unknown;
1232
+ error: null;
1233
+ } | {
1234
+ data: null;
1235
+ error: {
1236
+ message?: string | undefined;
1237
+ status: number;
1238
+ statusText: string;
1239
+ };
1240
+ }>;
1241
+ /**
1242
+ * Check if user can use one more unit of a feature
1243
+ * Returns { allowed: boolean, willBeCharged: boolean }
1244
+ */
1245
+ canUse: (data: {
1246
+ code: string;
1247
+ }, fetchOptions?: BetterFetchOption) => Promise<{
1248
+ data: unknown;
1249
+ error: null;
1250
+ } | {
1251
+ data: null;
1252
+ error: {
1253
+ message?: string | undefined;
1254
+ status: number;
1255
+ statusText: string;
1256
+ };
1257
+ }>;
1258
+ };
1259
+ usage: {
1260
+ /**
1261
+ * Track a usage event for the authenticated user
1262
+ */
1263
+ track: (data: {
1264
+ eventType: string;
1265
+ value?: number;
1266
+ idempotencyKey?: string;
1267
+ properties?: Record<string, string>;
1268
+ }, fetchOptions?: BetterFetchOption) => Promise<{
1269
+ data: unknown;
1270
+ error: null;
1271
+ } | {
1272
+ data: null;
1273
+ error: {
1274
+ message?: string | undefined;
1275
+ status: number;
1276
+ statusText: string;
1277
+ };
1278
+ }>;
1279
+ };
1280
+ seats: {
1281
+ /**
1282
+ * List all seat balances for the authenticated user
1283
+ */
1284
+ list: (fetchOptions?: BetterFetchOption) => Promise<{
1285
+ data: unknown;
1286
+ error: null;
1287
+ } | {
1288
+ data: null;
1289
+ error: {
1290
+ message?: string | undefined;
1291
+ status: number;
1292
+ statusText: string;
1293
+ };
1294
+ }>;
1295
+ /**
1296
+ * Add seats of a specific type
1297
+ */
1298
+ add: (data: {
1299
+ seatType: string;
1300
+ count: number;
1301
+ }, fetchOptions?: BetterFetchOption) => Promise<{
1302
+ data: unknown;
1303
+ error: null;
1304
+ } | {
1305
+ data: null;
1306
+ error: {
1307
+ message?: string | undefined;
1308
+ status: number;
1309
+ statusText: string;
1310
+ };
1311
+ }>;
1312
+ /**
1313
+ * Remove seats of a specific type
1314
+ */
1315
+ remove: (data: {
1316
+ seatType: string;
1317
+ count: number;
1318
+ }, fetchOptions?: BetterFetchOption) => Promise<{
1319
+ data: unknown;
1320
+ error: null;
1321
+ } | {
1322
+ data: null;
1323
+ error: {
1324
+ message?: string | undefined;
1325
+ status: number;
1326
+ statusText: string;
1327
+ };
1328
+ }>;
1329
+ /**
1330
+ * Set seats to a specific count
1331
+ */
1332
+ set: (data: {
1333
+ seatType: string;
1334
+ count: number;
1335
+ }, fetchOptions?: BetterFetchOption) => Promise<{
1336
+ data: unknown;
1337
+ error: null;
1338
+ } | {
1339
+ data: null;
1340
+ error: {
1341
+ message?: string | undefined;
1342
+ status: number;
1343
+ statusText: string;
1344
+ };
1345
+ }>;
1346
+ /**
1347
+ * Set all seat types at once
1348
+ */
1349
+ setAll: (data: {
1350
+ seats: Record<string, number>;
1351
+ }, fetchOptions?: BetterFetchOption) => Promise<{
1352
+ data: unknown;
1353
+ error: null;
1354
+ } | {
1355
+ data: null;
1356
+ error: {
1357
+ message?: string | undefined;
1358
+ status: number;
1359
+ statusText: string;
1360
+ };
1361
+ }>;
1362
+ };
1363
+ };
1364
+ };
1365
+
1366
+ export { type CommetEndpoints, type CommetOptions, type CommetPlugin, type CommetPlugins, type CustomerCreateParams, type FeaturesConfig, type PlanMapping, type PortalConfig, type SeatsConfig, type SubscriptionsConfig, type UsageConfig, type WebhookHandler, type WebhooksConfig, commet, commetClient, features, portal, seats, subscriptions, usage, webhooks };