@commet/better-auth 1.2.3 → 1.3.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.
- package/README.md +0 -8
- package/dist/client.cjs +0 -10
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +0 -10
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +0 -77
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -93
- package/dist/index.d.ts +0 -93
- package/dist/index.js +0 -77
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -361,7 +361,6 @@ interface SubscriptionsConfig {
|
|
|
361
361
|
*
|
|
362
362
|
* Endpoints:
|
|
363
363
|
* - GET /subscription - Get active subscription for the authenticated user
|
|
364
|
-
* - POST /subscription/change-plan - Change subscription plan (upgrade/downgrade)
|
|
365
364
|
* - POST /subscription/cancel - Cancel the subscription
|
|
366
365
|
*/
|
|
367
366
|
declare const subscriptions: (config?: SubscriptionsConfig) => (commet: Commet) => {
|
|
@@ -393,43 +392,6 @@ declare const subscriptions: (config?: SubscriptionsConfig) => (commet: Commet)
|
|
|
393
392
|
} & {
|
|
394
393
|
use: any[];
|
|
395
394
|
}, _commet_node.ActiveSubscription | null>;
|
|
396
|
-
changePlan: better_auth.StrictEndpoint<"/commet/subscription/change-plan", {
|
|
397
|
-
method: "POST";
|
|
398
|
-
body: z.ZodObject<{
|
|
399
|
-
planId: z.ZodOptional<z.ZodString>;
|
|
400
|
-
slug: z.ZodOptional<z.ZodString>;
|
|
401
|
-
billingInterval: z.ZodOptional<z.ZodEnum<{
|
|
402
|
-
monthly: "monthly";
|
|
403
|
-
quarterly: "quarterly";
|
|
404
|
-
yearly: "yearly";
|
|
405
|
-
}>>;
|
|
406
|
-
}, z.core.$strip>;
|
|
407
|
-
use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
|
|
408
|
-
session: {
|
|
409
|
-
session: Record<string, any> & {
|
|
410
|
-
id: string;
|
|
411
|
-
createdAt: Date;
|
|
412
|
-
updatedAt: Date;
|
|
413
|
-
userId: string;
|
|
414
|
-
expiresAt: Date;
|
|
415
|
-
token: string;
|
|
416
|
-
ipAddress?: string | null | undefined;
|
|
417
|
-
userAgent?: string | null | undefined;
|
|
418
|
-
};
|
|
419
|
-
user: Record<string, any> & {
|
|
420
|
-
id: string;
|
|
421
|
-
createdAt: Date;
|
|
422
|
-
updatedAt: Date;
|
|
423
|
-
email: string;
|
|
424
|
-
emailVerified: boolean;
|
|
425
|
-
name: string;
|
|
426
|
-
image?: string | null | undefined;
|
|
427
|
-
};
|
|
428
|
-
};
|
|
429
|
-
}>)[];
|
|
430
|
-
} & {
|
|
431
|
-
use: any[];
|
|
432
|
-
}, _commet_node.Subscription | null>;
|
|
433
395
|
cancelSubscription: better_auth.StrictEndpoint<"/commet/subscription/cancel", {
|
|
434
396
|
method: "POST";
|
|
435
397
|
body: z.ZodOptional<z.ZodObject<{
|
|
@@ -752,43 +714,6 @@ declare const commet: <O extends CommetOptions>(options: O) => {
|
|
|
752
714
|
} & {
|
|
753
715
|
use: any[];
|
|
754
716
|
}, _commet_node.ActiveSubscription | null>;
|
|
755
|
-
changePlan: better_auth.StrictEndpoint<"/commet/subscription/change-plan", {
|
|
756
|
-
method: "POST";
|
|
757
|
-
body: zod.ZodObject<{
|
|
758
|
-
planId: zod.ZodOptional<zod.ZodString>;
|
|
759
|
-
slug: zod.ZodOptional<zod.ZodString>;
|
|
760
|
-
billingInterval: zod.ZodOptional<zod.ZodEnum<{
|
|
761
|
-
monthly: "monthly";
|
|
762
|
-
quarterly: "quarterly";
|
|
763
|
-
yearly: "yearly";
|
|
764
|
-
}>>;
|
|
765
|
-
}, better_auth.$strip>;
|
|
766
|
-
use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
|
|
767
|
-
session: {
|
|
768
|
-
session: Record<string, any> & {
|
|
769
|
-
id: string;
|
|
770
|
-
createdAt: Date;
|
|
771
|
-
updatedAt: Date;
|
|
772
|
-
userId: string;
|
|
773
|
-
expiresAt: Date;
|
|
774
|
-
token: string;
|
|
775
|
-
ipAddress?: string | null | undefined;
|
|
776
|
-
userAgent?: string | null | undefined;
|
|
777
|
-
};
|
|
778
|
-
user: Record<string, any> & {
|
|
779
|
-
id: string;
|
|
780
|
-
createdAt: Date;
|
|
781
|
-
updatedAt: Date;
|
|
782
|
-
email: string;
|
|
783
|
-
emailVerified: boolean;
|
|
784
|
-
name: string;
|
|
785
|
-
image?: string | null | undefined;
|
|
786
|
-
};
|
|
787
|
-
};
|
|
788
|
-
}>)[];
|
|
789
|
-
} & {
|
|
790
|
-
use: any[];
|
|
791
|
-
}, _commet_node.Subscription | null>;
|
|
792
717
|
cancelSubscription: better_auth.StrictEndpoint<"/commet/subscription/cancel", {
|
|
793
718
|
method: "POST";
|
|
794
719
|
body: zod.ZodOptional<zod.ZodObject<{
|
|
@@ -1208,24 +1133,6 @@ declare const commetClient: () => {
|
|
|
1208
1133
|
statusText: string;
|
|
1209
1134
|
};
|
|
1210
1135
|
}>;
|
|
1211
|
-
/**
|
|
1212
|
-
* Change the subscription plan (upgrade/downgrade)
|
|
1213
|
-
*/
|
|
1214
|
-
changePlan: (data: {
|
|
1215
|
-
planId?: string;
|
|
1216
|
-
slug?: string;
|
|
1217
|
-
billingInterval?: "monthly" | "quarterly" | "yearly";
|
|
1218
|
-
}, fetchOptions?: BetterFetchOption) => Promise<{
|
|
1219
|
-
data: unknown;
|
|
1220
|
-
error: null;
|
|
1221
|
-
} | {
|
|
1222
|
-
data: null;
|
|
1223
|
-
error: {
|
|
1224
|
-
message?: string | undefined;
|
|
1225
|
-
status: number;
|
|
1226
|
-
statusText: string;
|
|
1227
|
-
};
|
|
1228
|
-
}>;
|
|
1229
1136
|
/**
|
|
1230
1137
|
* Cancel the subscription
|
|
1231
1138
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -361,7 +361,6 @@ interface SubscriptionsConfig {
|
|
|
361
361
|
*
|
|
362
362
|
* Endpoints:
|
|
363
363
|
* - GET /subscription - Get active subscription for the authenticated user
|
|
364
|
-
* - POST /subscription/change-plan - Change subscription plan (upgrade/downgrade)
|
|
365
364
|
* - POST /subscription/cancel - Cancel the subscription
|
|
366
365
|
*/
|
|
367
366
|
declare const subscriptions: (config?: SubscriptionsConfig) => (commet: Commet) => {
|
|
@@ -393,43 +392,6 @@ declare const subscriptions: (config?: SubscriptionsConfig) => (commet: Commet)
|
|
|
393
392
|
} & {
|
|
394
393
|
use: any[];
|
|
395
394
|
}, _commet_node.ActiveSubscription | null>;
|
|
396
|
-
changePlan: better_auth.StrictEndpoint<"/commet/subscription/change-plan", {
|
|
397
|
-
method: "POST";
|
|
398
|
-
body: z.ZodObject<{
|
|
399
|
-
planId: z.ZodOptional<z.ZodString>;
|
|
400
|
-
slug: z.ZodOptional<z.ZodString>;
|
|
401
|
-
billingInterval: z.ZodOptional<z.ZodEnum<{
|
|
402
|
-
monthly: "monthly";
|
|
403
|
-
quarterly: "quarterly";
|
|
404
|
-
yearly: "yearly";
|
|
405
|
-
}>>;
|
|
406
|
-
}, z.core.$strip>;
|
|
407
|
-
use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
|
|
408
|
-
session: {
|
|
409
|
-
session: Record<string, any> & {
|
|
410
|
-
id: string;
|
|
411
|
-
createdAt: Date;
|
|
412
|
-
updatedAt: Date;
|
|
413
|
-
userId: string;
|
|
414
|
-
expiresAt: Date;
|
|
415
|
-
token: string;
|
|
416
|
-
ipAddress?: string | null | undefined;
|
|
417
|
-
userAgent?: string | null | undefined;
|
|
418
|
-
};
|
|
419
|
-
user: Record<string, any> & {
|
|
420
|
-
id: string;
|
|
421
|
-
createdAt: Date;
|
|
422
|
-
updatedAt: Date;
|
|
423
|
-
email: string;
|
|
424
|
-
emailVerified: boolean;
|
|
425
|
-
name: string;
|
|
426
|
-
image?: string | null | undefined;
|
|
427
|
-
};
|
|
428
|
-
};
|
|
429
|
-
}>)[];
|
|
430
|
-
} & {
|
|
431
|
-
use: any[];
|
|
432
|
-
}, _commet_node.Subscription | null>;
|
|
433
395
|
cancelSubscription: better_auth.StrictEndpoint<"/commet/subscription/cancel", {
|
|
434
396
|
method: "POST";
|
|
435
397
|
body: z.ZodOptional<z.ZodObject<{
|
|
@@ -752,43 +714,6 @@ declare const commet: <O extends CommetOptions>(options: O) => {
|
|
|
752
714
|
} & {
|
|
753
715
|
use: any[];
|
|
754
716
|
}, _commet_node.ActiveSubscription | null>;
|
|
755
|
-
changePlan: better_auth.StrictEndpoint<"/commet/subscription/change-plan", {
|
|
756
|
-
method: "POST";
|
|
757
|
-
body: zod.ZodObject<{
|
|
758
|
-
planId: zod.ZodOptional<zod.ZodString>;
|
|
759
|
-
slug: zod.ZodOptional<zod.ZodString>;
|
|
760
|
-
billingInterval: zod.ZodOptional<zod.ZodEnum<{
|
|
761
|
-
monthly: "monthly";
|
|
762
|
-
quarterly: "quarterly";
|
|
763
|
-
yearly: "yearly";
|
|
764
|
-
}>>;
|
|
765
|
-
}, better_auth.$strip>;
|
|
766
|
-
use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
|
|
767
|
-
session: {
|
|
768
|
-
session: Record<string, any> & {
|
|
769
|
-
id: string;
|
|
770
|
-
createdAt: Date;
|
|
771
|
-
updatedAt: Date;
|
|
772
|
-
userId: string;
|
|
773
|
-
expiresAt: Date;
|
|
774
|
-
token: string;
|
|
775
|
-
ipAddress?: string | null | undefined;
|
|
776
|
-
userAgent?: string | null | undefined;
|
|
777
|
-
};
|
|
778
|
-
user: Record<string, any> & {
|
|
779
|
-
id: string;
|
|
780
|
-
createdAt: Date;
|
|
781
|
-
updatedAt: Date;
|
|
782
|
-
email: string;
|
|
783
|
-
emailVerified: boolean;
|
|
784
|
-
name: string;
|
|
785
|
-
image?: string | null | undefined;
|
|
786
|
-
};
|
|
787
|
-
};
|
|
788
|
-
}>)[];
|
|
789
|
-
} & {
|
|
790
|
-
use: any[];
|
|
791
|
-
}, _commet_node.Subscription | null>;
|
|
792
717
|
cancelSubscription: better_auth.StrictEndpoint<"/commet/subscription/cancel", {
|
|
793
718
|
method: "POST";
|
|
794
719
|
body: zod.ZodOptional<zod.ZodObject<{
|
|
@@ -1208,24 +1133,6 @@ declare const commetClient: () => {
|
|
|
1208
1133
|
statusText: string;
|
|
1209
1134
|
};
|
|
1210
1135
|
}>;
|
|
1211
|
-
/**
|
|
1212
|
-
* Change the subscription plan (upgrade/downgrade)
|
|
1213
|
-
*/
|
|
1214
|
-
changePlan: (data: {
|
|
1215
|
-
planId?: string;
|
|
1216
|
-
slug?: string;
|
|
1217
|
-
billingInterval?: "monthly" | "quarterly" | "yearly";
|
|
1218
|
-
}, fetchOptions?: BetterFetchOption) => Promise<{
|
|
1219
|
-
data: unknown;
|
|
1220
|
-
error: null;
|
|
1221
|
-
} | {
|
|
1222
|
-
data: null;
|
|
1223
|
-
error: {
|
|
1224
|
-
message?: string | undefined;
|
|
1225
|
-
status: number;
|
|
1226
|
-
statusText: string;
|
|
1227
|
-
};
|
|
1228
|
-
}>;
|
|
1229
1136
|
/**
|
|
1230
1137
|
* Cancel the subscription
|
|
1231
1138
|
*/
|
package/dist/index.js
CHANGED
|
@@ -154,16 +154,6 @@ var commetClient = () => {
|
|
|
154
154
|
...fetchOptions
|
|
155
155
|
});
|
|
156
156
|
},
|
|
157
|
-
/**
|
|
158
|
-
* Change the subscription plan (upgrade/downgrade)
|
|
159
|
-
*/
|
|
160
|
-
changePlan: async (data, fetchOptions) => {
|
|
161
|
-
return $fetch("/commet/subscription/change-plan", {
|
|
162
|
-
method: "POST",
|
|
163
|
-
body: data,
|
|
164
|
-
...fetchOptions
|
|
165
|
-
});
|
|
166
|
-
},
|
|
167
157
|
/**
|
|
168
158
|
* Cancel the subscription
|
|
169
159
|
*/
|
|
@@ -344,11 +334,6 @@ var portal = ({ returnUrl } = {}) => (commet2) => {
|
|
|
344
334
|
import { APIError as APIError3, sessionMiddleware as sessionMiddleware2 } from "better-auth/api";
|
|
345
335
|
import { createAuthEndpoint as createAuthEndpoint2 } from "better-auth/plugins";
|
|
346
336
|
import { z } from "zod";
|
|
347
|
-
var ChangePlanSchema = z.object({
|
|
348
|
-
planId: z.string().optional(),
|
|
349
|
-
slug: z.string().optional(),
|
|
350
|
-
billingInterval: z.enum(["monthly", "quarterly", "yearly"]).optional()
|
|
351
|
-
});
|
|
352
337
|
var CancelSchema = z.object({
|
|
353
338
|
reason: z.string().optional(),
|
|
354
339
|
immediate: z.boolean().optional()
|
|
@@ -391,68 +376,6 @@ var subscriptions = (config = {}) => (commet2) => {
|
|
|
391
376
|
}
|
|
392
377
|
}
|
|
393
378
|
),
|
|
394
|
-
changePlan: createAuthEndpoint2(
|
|
395
|
-
"/commet/subscription/change-plan",
|
|
396
|
-
{
|
|
397
|
-
method: "POST",
|
|
398
|
-
body: ChangePlanSchema,
|
|
399
|
-
use: [sessionMiddleware2]
|
|
400
|
-
},
|
|
401
|
-
async (ctx) => {
|
|
402
|
-
const userId = ctx.context.session?.user.id;
|
|
403
|
-
if (!userId) {
|
|
404
|
-
throw new APIError3("UNAUTHORIZED", {
|
|
405
|
-
message: "You must be logged in to change plan"
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
let planId = ctx.body.planId;
|
|
409
|
-
if (ctx.body.slug && !planId) {
|
|
410
|
-
const plan = config.plans?.find((p) => p.slug === ctx.body.slug);
|
|
411
|
-
if (!plan) {
|
|
412
|
-
throw new APIError3("BAD_REQUEST", {
|
|
413
|
-
message: `Plan with slug "${ctx.body.slug}" not found`
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
planId = plan.planId;
|
|
417
|
-
}
|
|
418
|
-
if (!planId) {
|
|
419
|
-
throw new APIError3("BAD_REQUEST", {
|
|
420
|
-
message: "Either planId or slug must be provided"
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
try {
|
|
424
|
-
const currentSub = await commet2.subscriptions.get(userId);
|
|
425
|
-
if (!currentSub.success || !currentSub.data) {
|
|
426
|
-
throw new APIError3("BAD_REQUEST", {
|
|
427
|
-
message: "No active subscription found"
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
const result = await commet2.subscriptions.changePlan({
|
|
431
|
-
subscriptionId: currentSub.data.id,
|
|
432
|
-
planId,
|
|
433
|
-
billingInterval: ctx.body.billingInterval
|
|
434
|
-
});
|
|
435
|
-
if (!result.success) {
|
|
436
|
-
throw new APIError3("INTERNAL_SERVER_ERROR", {
|
|
437
|
-
message: result.message || "Failed to change plan"
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
return ctx.json(result.data ?? null);
|
|
441
|
-
} catch (e) {
|
|
442
|
-
if (e instanceof APIError3) {
|
|
443
|
-
throw e;
|
|
444
|
-
}
|
|
445
|
-
if (e instanceof Error) {
|
|
446
|
-
ctx.context.logger.error(
|
|
447
|
-
`Commet plan change failed: ${e.message}`
|
|
448
|
-
);
|
|
449
|
-
}
|
|
450
|
-
throw new APIError3("INTERNAL_SERVER_ERROR", {
|
|
451
|
-
message: "Failed to change plan"
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
),
|
|
456
379
|
cancelSubscription: createAuthEndpoint2(
|
|
457
380
|
"/commet/subscription/cancel",
|
|
458
381
|
{
|