@dodopayments/better-auth 1.3.2 → 1.3.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.
Files changed (59) hide show
  1. package/dist/chunk-52LQJCF4.js +199 -0
  2. package/dist/chunk-52LQJCF4.js.map +1 -0
  3. package/dist/chunk-FBAIEKOL.js +70 -0
  4. package/dist/chunk-FBAIEKOL.js.map +1 -0
  5. package/dist/chunk-PXI4EHZC.js +12 -0
  6. package/dist/chunk-PXI4EHZC.js.map +1 -0
  7. package/dist/chunk-QR7PLJJQ.js +13943 -0
  8. package/dist/chunk-QR7PLJJQ.js.map +1 -0
  9. package/dist/chunk-WIFOXVZ3.js +291 -0
  10. package/dist/chunk-WIFOXVZ3.js.map +1 -0
  11. package/dist/chunk-YK6XO66Y.js +84 -0
  12. package/dist/chunk-YK6XO66Y.js.map +1 -0
  13. package/dist/chunk-Z7VSWPPK.js +181 -0
  14. package/dist/chunk-Z7VSWPPK.js.map +1 -0
  15. package/dist/client.cjs +36 -0
  16. package/dist/client.cjs.map +1 -0
  17. package/dist/client.d.cts +7 -0
  18. package/dist/client.d.ts +7 -5
  19. package/dist/client.js +6 -5
  20. package/dist/client.js.map +1 -0
  21. package/dist/hooks/customer.cjs +14036 -0
  22. package/dist/hooks/customer.cjs.map +1 -0
  23. package/dist/hooks/customer.d.cts +11 -0
  24. package/dist/hooks/customer.d.ts +11 -4
  25. package/dist/hooks/customer.js +9 -62
  26. package/dist/hooks/customer.js.map +1 -0
  27. package/dist/index.cjs +14793 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +797 -0
  30. package/dist/index.d.ts +205 -196
  31. package/dist/index.js +55 -34
  32. package/dist/index.js.map +1 -0
  33. package/dist/plugins/checkout.cjs +14424 -0
  34. package/dist/plugins/checkout.cjs.map +1 -0
  35. package/dist/plugins/checkout.d.cts +6 -0
  36. package/dist/plugins/checkout.d.ts +6 -548
  37. package/dist/plugins/checkout.js +8 -170
  38. package/dist/plugins/checkout.js.map +1 -0
  39. package/dist/plugins/portal.cjs +14446 -0
  40. package/dist/plugins/portal.cjs.map +1 -0
  41. package/dist/plugins/portal.d.cts +6 -0
  42. package/dist/plugins/portal.d.ts +6 -204
  43. package/dist/plugins/portal.js +8 -171
  44. package/dist/plugins/portal.js.map +1 -0
  45. package/dist/plugins/webhooks.cjs +14046 -0
  46. package/dist/plugins/webhooks.cjs.map +1 -0
  47. package/dist/plugins/webhooks.d.cts +6 -0
  48. package/dist/plugins/webhooks.d.ts +6 -41
  49. package/dist/plugins/webhooks.js +7 -61
  50. package/dist/plugins/webhooks.js.map +1 -0
  51. package/dist/types-CbotWcHh.d.cts +841 -0
  52. package/dist/types-CbotWcHh.d.ts +841 -0
  53. package/dist/types.cjs +19 -0
  54. package/dist/types.cjs.map +1 -0
  55. package/dist/types.d.cts +6 -0
  56. package/dist/types.d.ts +6 -52
  57. package/dist/types.js +1 -1
  58. package/dist/types.js.map +1 -0
  59. package/package.json +5 -10
@@ -0,0 +1,6 @@
1
+ import 'better-call';
2
+ import 'dodopayments';
3
+ import 'zod/v3';
4
+ export { p as portal } from '../types-CbotWcHh.cjs';
5
+ import 'better-auth';
6
+ import '@dodopayments/core/webhook';
@@ -1,204 +1,6 @@
1
- import type { DodoPayments } from "dodopayments";
2
- import { z } from "zod/v3";
3
- import { CustomerPortalResponse, PaymentItems, SubscriptionItems } from "../types";
4
- export declare const portal: () => (dodopayments: DodoPayments) => {
5
- dodoPortal: {
6
- <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({
7
- body?: undefined;
8
- } & {
9
- method?: "GET" | undefined;
10
- } & {
11
- query?: Record<string, any> | undefined;
12
- } & {
13
- params?: Record<string, any>;
14
- } & {
15
- request?: Request;
16
- } & {
17
- headers?: HeadersInit;
18
- } & {
19
- asResponse?: boolean;
20
- returnHeaders?: boolean;
21
- use?: import("better-call").Middleware[];
22
- path?: string;
23
- } & {
24
- asResponse?: AsResponse | undefined;
25
- returnHeaders?: ReturnHeaders | undefined;
26
- }) | undefined): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
27
- headers: Headers;
28
- response: CustomerPortalResponse;
29
- } : CustomerPortalResponse>;
30
- options: {
31
- method: "GET";
32
- use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
33
- session: {
34
- session: Record<string, any> & {
35
- id: string;
36
- userId: string;
37
- expiresAt: Date;
38
- createdAt: Date;
39
- updatedAt: Date;
40
- token: string;
41
- ipAddress?: string | null | undefined;
42
- userAgent?: string | null | undefined;
43
- };
44
- user: Record<string, any> & {
45
- id: string;
46
- email: string;
47
- emailVerified: boolean;
48
- name: string;
49
- createdAt: Date;
50
- updatedAt: Date;
51
- image?: string | null | undefined;
52
- };
53
- };
54
- }>)[];
55
- } & {
56
- use: any[];
57
- };
58
- path: "/dodopayments/customer/portal";
59
- };
60
- dodoSubscriptions: {
61
- <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({
62
- body?: undefined;
63
- } & {
64
- method?: "GET" | undefined;
65
- } & {
66
- query?: {
67
- status?: "active" | "cancelled" | "on_hold" | "pending" | "failed" | "expired" | undefined;
68
- page?: number | undefined;
69
- limit?: number | undefined;
70
- } | undefined;
71
- } & {
72
- params?: Record<string, any>;
73
- } & {
74
- request?: Request;
75
- } & {
76
- headers?: HeadersInit;
77
- } & {
78
- asResponse?: boolean;
79
- returnHeaders?: boolean;
80
- use?: import("better-call").Middleware[];
81
- path?: string;
82
- } & {
83
- asResponse?: AsResponse | undefined;
84
- returnHeaders?: ReturnHeaders | undefined;
85
- }) | undefined): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
86
- headers: Headers;
87
- response: SubscriptionItems;
88
- } : SubscriptionItems>;
89
- options: {
90
- method: "GET";
91
- query: z.ZodOptional<z.ZodObject<{
92
- page: z.ZodOptional<z.ZodNumber>;
93
- limit: z.ZodOptional<z.ZodNumber>;
94
- status: z.ZodOptional<z.ZodEnum<["active", "cancelled", "on_hold", "pending", "failed", "expired"]>>;
95
- }, "strip", z.ZodTypeAny, {
96
- status?: "active" | "cancelled" | "on_hold" | "pending" | "failed" | "expired" | undefined;
97
- page?: number | undefined;
98
- limit?: number | undefined;
99
- }, {
100
- status?: "active" | "cancelled" | "on_hold" | "pending" | "failed" | "expired" | undefined;
101
- page?: number | undefined;
102
- limit?: number | undefined;
103
- }>>;
104
- use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
105
- session: {
106
- session: Record<string, any> & {
107
- id: string;
108
- userId: string;
109
- expiresAt: Date;
110
- createdAt: Date;
111
- updatedAt: Date;
112
- token: string;
113
- ipAddress?: string | null | undefined;
114
- userAgent?: string | null | undefined;
115
- };
116
- user: Record<string, any> & {
117
- id: string;
118
- email: string;
119
- emailVerified: boolean;
120
- name: string;
121
- createdAt: Date;
122
- updatedAt: Date;
123
- image?: string | null | undefined;
124
- };
125
- };
126
- }>)[];
127
- } & {
128
- use: any[];
129
- };
130
- path: "/dodopayments/customer/subscriptions/list";
131
- };
132
- dodoPayments: {
133
- <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({
134
- body?: undefined;
135
- } & {
136
- method?: "GET" | undefined;
137
- } & {
138
- query?: {
139
- status?: "cancelled" | "failed" | "succeeded" | "processing" | "requires_customer_action" | "requires_merchant_action" | "requires_payment_method" | "requires_confirmation" | "requires_capture" | "partially_captured" | "partially_captured_and_capturable" | undefined;
140
- page?: number | undefined;
141
- limit?: number | undefined;
142
- } | undefined;
143
- } & {
144
- params?: Record<string, any>;
145
- } & {
146
- request?: Request;
147
- } & {
148
- headers?: HeadersInit;
149
- } & {
150
- asResponse?: boolean;
151
- returnHeaders?: boolean;
152
- use?: import("better-call").Middleware[];
153
- path?: string;
154
- } & {
155
- asResponse?: AsResponse | undefined;
156
- returnHeaders?: ReturnHeaders | undefined;
157
- }) | undefined): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
158
- headers: Headers;
159
- response: PaymentItems;
160
- } : PaymentItems>;
161
- options: {
162
- method: "GET";
163
- query: z.ZodOptional<z.ZodObject<{
164
- page: z.ZodOptional<z.ZodNumber>;
165
- limit: z.ZodOptional<z.ZodNumber>;
166
- status: z.ZodOptional<z.ZodEnum<["succeeded", "failed", "cancelled", "processing", "requires_customer_action", "requires_merchant_action", "requires_payment_method", "requires_confirmation", "requires_capture", "partially_captured", "partially_captured_and_capturable"]>>;
167
- }, "strip", z.ZodTypeAny, {
168
- status?: "cancelled" | "failed" | "succeeded" | "processing" | "requires_customer_action" | "requires_merchant_action" | "requires_payment_method" | "requires_confirmation" | "requires_capture" | "partially_captured" | "partially_captured_and_capturable" | undefined;
169
- page?: number | undefined;
170
- limit?: number | undefined;
171
- }, {
172
- status?: "cancelled" | "failed" | "succeeded" | "processing" | "requires_customer_action" | "requires_merchant_action" | "requires_payment_method" | "requires_confirmation" | "requires_capture" | "partially_captured" | "partially_captured_and_capturable" | undefined;
173
- page?: number | undefined;
174
- limit?: number | undefined;
175
- }>>;
176
- use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
177
- session: {
178
- session: Record<string, any> & {
179
- id: string;
180
- userId: string;
181
- expiresAt: Date;
182
- createdAt: Date;
183
- updatedAt: Date;
184
- token: string;
185
- ipAddress?: string | null | undefined;
186
- userAgent?: string | null | undefined;
187
- };
188
- user: Record<string, any> & {
189
- id: string;
190
- email: string;
191
- emailVerified: boolean;
192
- name: string;
193
- createdAt: Date;
194
- updatedAt: Date;
195
- image?: string | null | undefined;
196
- };
197
- };
198
- }>)[];
199
- } & {
200
- use: any[];
201
- };
202
- path: "/dodopayments/customer/payments/list";
203
- };
204
- };
1
+ import 'better-call';
2
+ import 'dodopayments';
3
+ import 'zod/v3';
4
+ export { p as portal } from '../types-CbotWcHh.js';
5
+ import 'better-auth';
6
+ import '@dodopayments/core/webhook';
@@ -1,172 +1,9 @@
1
- import { APIError } from "better-auth/api";
2
- import { sessionMiddleware } from "better-auth/api";
3
- import { createAuthEndpoint } from "better-auth/plugins";
4
- import { z } from "zod/v3";
5
- export const portal = () => (dodopayments) => {
6
- return {
7
- dodoPortal: createAuthEndpoint("/dodopayments/customer/portal", {
8
- method: "GET",
9
- use: [sessionMiddleware],
10
- }, async (ctx) => {
11
- if (!ctx.context.session?.user.id) {
12
- throw new APIError("BAD_REQUEST", {
13
- message: "User not found",
14
- });
15
- }
16
- if (!ctx.context.session?.user.emailVerified) {
17
- throw new APIError("UNAUTHORIZED", {
18
- message: "User email not verified",
19
- });
20
- }
21
- try {
22
- const customers = await dodopayments.customers.list({
23
- email: ctx.context.session?.user.email,
24
- });
25
- let customer = customers.items[0];
26
- if (!customer) {
27
- // upsert the customer, if they don't exist in DodoPayments
28
- customer = await createCustomer(dodopayments, ctx.context.session.user.email, ctx.context.session.user.name);
29
- }
30
- const customerSession = await dodopayments.customers.customerPortal.create(customer.customer_id);
31
- return ctx.json({
32
- url: customerSession.link,
33
- redirect: true,
34
- });
35
- }
36
- catch (e) {
37
- if (e instanceof Error) {
38
- ctx.context.logger.error(`DodoPayments customer portal creation failed. Error: ${e.message}`);
39
- }
40
- throw new APIError("INTERNAL_SERVER_ERROR", {
41
- message: "Customer portal creation failed",
42
- });
43
- }
44
- }),
45
- dodoSubscriptions: createAuthEndpoint("/dodopayments/customer/subscriptions/list", {
46
- method: "GET",
47
- query: z
48
- .object({
49
- page: z.coerce.number().optional(),
50
- limit: z.coerce.number().optional(),
51
- status: z
52
- .enum([
53
- "active",
54
- "cancelled",
55
- "on_hold",
56
- "pending",
57
- "failed",
58
- "expired",
59
- ])
60
- .optional(),
61
- })
62
- .optional(),
63
- use: [sessionMiddleware],
64
- }, async (ctx) => {
65
- if (!ctx.context.session.user.id) {
66
- throw new APIError("BAD_REQUEST", {
67
- message: "User not found",
68
- });
69
- }
70
- if (!ctx.context.session?.user.emailVerified) {
71
- throw new APIError("UNAUTHORIZED", {
72
- message: "User email not verified",
73
- });
74
- }
75
- try {
76
- const customers = await dodopayments.customers.list({
77
- email: ctx.context.session?.user.email,
78
- });
79
- let customer = customers.items[0];
80
- if (!customer) {
81
- // upsert the customer, if they don't exist in DodoPayments
82
- customer = await createCustomer(dodopayments, ctx.context.session.user.email, ctx.context.session.user.name);
83
- }
84
- const subscriptions = await dodopayments.subscriptions.list({
85
- customer_id: customer.customer_id,
86
- // page number is 0-indexed
87
- page_number: ctx.query?.page ? ctx.query.page - 1 : undefined,
88
- page_size: ctx.query?.limit,
89
- status: ctx.query?.status,
90
- });
91
- return ctx.json({ items: subscriptions.items });
92
- }
93
- catch (e) {
94
- if (e instanceof Error) {
95
- ctx.context.logger.error(`DodoPayments subscriptions list failed. Error: ${e.message}`);
96
- }
97
- throw new APIError("INTERNAL_SERVER_ERROR", {
98
- message: "DodoPayments subscriptions list failed",
99
- });
100
- }
101
- }),
102
- dodoPayments: createAuthEndpoint("/dodopayments/customer/payments/list", {
103
- method: "GET",
104
- query: z
105
- .object({
106
- page: z.coerce.number().optional(),
107
- limit: z.coerce.number().optional(),
108
- status: z
109
- .enum([
110
- "succeeded",
111
- "failed",
112
- "cancelled",
113
- "processing",
114
- "requires_customer_action",
115
- "requires_merchant_action",
116
- "requires_payment_method",
117
- "requires_confirmation",
118
- "requires_capture",
119
- "partially_captured",
120
- "partially_captured_and_capturable",
121
- ])
122
- .optional(),
123
- })
124
- .optional(),
125
- use: [sessionMiddleware],
126
- }, async (ctx) => {
127
- if (!ctx.context.session.user.id) {
128
- throw new APIError("BAD_REQUEST", {
129
- message: "User not found",
130
- });
131
- }
132
- if (!ctx.context.session?.user.emailVerified) {
133
- throw new APIError("UNAUTHORIZED", {
134
- message: "User email not verified",
135
- });
136
- }
137
- try {
138
- const customers = await dodopayments.customers.list({
139
- email: ctx.context.session?.user.email,
140
- });
141
- let customer = customers.items[0];
142
- if (!customer) {
143
- // upsert the customer, if they don't exist in DodoPayments
144
- customer = await createCustomer(dodopayments, ctx.context.session.user.email, ctx.context.session.user.name);
145
- }
146
- const payments = await dodopayments.payments.list({
147
- customer_id: customer.customer_id,
148
- // page number is 0-indexed
149
- page_number: ctx.query?.page ? ctx.query.page - 1 : undefined,
150
- page_size: ctx.query?.limit,
151
- status: ctx.query?.status,
152
- });
153
- return ctx.json({ items: payments.items });
154
- }
155
- catch (e) {
156
- if (e instanceof Error) {
157
- ctx.context.logger.error(`DodoPayments orders list failed. Error: ${e.message}`);
158
- }
159
- throw new APIError("INTERNAL_SERVER_ERROR", {
160
- message: "Orders list failed",
161
- });
162
- }
163
- }),
164
- };
1
+ import {
2
+ portal
3
+ } from "../chunk-52LQJCF4.js";
4
+ import "../chunk-WIFOXVZ3.js";
5
+ import "../chunk-QR7PLJJQ.js";
6
+ export {
7
+ portal
165
8
  };
166
- async function createCustomer(dodopayments, email, name) {
167
- const customer = await dodopayments.customers.create({
168
- email,
169
- name,
170
- });
171
- return customer;
172
- }
9
+ //# sourceMappingURL=portal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}