@better-auth/stripe 1.2.6-beta.3 → 1.2.6-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -4
- package/dist/index.cjs +61 -54
- package/dist/index.d.cts +61 -4
- package/dist/index.d.mts +61 -4
- package/dist/index.d.ts +61 -4
- package/dist/index.mjs +61 -54
- package/package.json +2 -2
- package/src/schema.ts +67 -54
- package/src/types.ts +6 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
|
|
2
|
-
> @better-auth/stripe@1.2.6-beta.
|
|
2
|
+
> @better-auth/stripe@1.2.6-beta.5 build /home/runner/work/better-auth/better-auth/packages/stripe
|
|
3
3
|
> unbuild
|
|
4
4
|
|
|
5
5
|
[info] Automatically detected entries: src/index, src/client [esm] [cjs] [dts]
|
|
6
6
|
[info] Building stripe
|
|
7
7
|
[success] Build succeeded for stripe
|
|
8
|
-
[log] dist/index.cjs (total size: 33.
|
|
8
|
+
[log] dist/index.cjs (total size: 33.6 kB, chunk size: 33.6 kB, exports: stripe)
|
|
9
9
|
|
|
10
10
|
[log] dist/client.cjs (total size: 160 B, chunk size: 160 B, exports: stripeClient)
|
|
11
11
|
|
|
12
|
-
[log] dist/index.mjs (total size: 33.
|
|
12
|
+
[log] dist/index.mjs (total size: 33.3 kB, chunk size: 33.3 kB, exports: stripe)
|
|
13
13
|
|
|
14
14
|
[log] dist/client.mjs (total size: 133 B, chunk size: 133 B, exports: stripeClient)
|
|
15
15
|
|
|
16
|
-
Σ Total dist size (byte size):
|
|
16
|
+
Σ Total dist size (byte size): 196 kB
|
|
17
17
|
[log]
|
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ const plugins = require('better-auth/plugins');
|
|
|
5
5
|
const zod = require('zod');
|
|
6
6
|
const api = require('better-auth/api');
|
|
7
7
|
const crypto = require('better-auth/crypto');
|
|
8
|
+
const db = require('better-auth/db');
|
|
8
9
|
|
|
9
10
|
async function getPlans(options) {
|
|
10
11
|
return typeof options?.subscription?.plans === "function" ? await options.subscription?.plans() : options.subscription?.plans;
|
|
@@ -216,64 +217,70 @@ async function onSubscriptionDeleted(ctx, options, event) {
|
|
|
216
217
|
}
|
|
217
218
|
}
|
|
218
219
|
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
required: false
|
|
259
|
-
}
|
|
220
|
+
const subscriptions = {
|
|
221
|
+
subscription: {
|
|
222
|
+
fields: {
|
|
223
|
+
plan: {
|
|
224
|
+
type: "string",
|
|
225
|
+
required: true
|
|
226
|
+
},
|
|
227
|
+
referenceId: {
|
|
228
|
+
type: "string",
|
|
229
|
+
required: true
|
|
230
|
+
},
|
|
231
|
+
stripeCustomerId: {
|
|
232
|
+
type: "string",
|
|
233
|
+
required: false
|
|
234
|
+
},
|
|
235
|
+
stripeSubscriptionId: {
|
|
236
|
+
type: "string",
|
|
237
|
+
required: false
|
|
238
|
+
},
|
|
239
|
+
status: {
|
|
240
|
+
type: "string",
|
|
241
|
+
defaultValue: "incomplete"
|
|
242
|
+
},
|
|
243
|
+
periodStart: {
|
|
244
|
+
type: "date",
|
|
245
|
+
required: false
|
|
246
|
+
},
|
|
247
|
+
periodEnd: {
|
|
248
|
+
type: "date",
|
|
249
|
+
required: false
|
|
250
|
+
},
|
|
251
|
+
cancelAtPeriodEnd: {
|
|
252
|
+
type: "boolean",
|
|
253
|
+
required: false,
|
|
254
|
+
defaultValue: false
|
|
255
|
+
},
|
|
256
|
+
seats: {
|
|
257
|
+
type: "number",
|
|
258
|
+
required: false
|
|
260
259
|
}
|
|
261
260
|
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
const user = {
|
|
264
|
+
user: {
|
|
265
|
+
fields: {
|
|
266
|
+
stripeCustomerId: {
|
|
267
|
+
type: "string",
|
|
268
|
+
required: false
|
|
270
269
|
}
|
|
271
270
|
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
const getSchema = (options) => {
|
|
274
|
+
if (options.schema && !options.subscription?.enabled && "subscription" in options.schema) {
|
|
275
|
+
options.schema.subscription = void 0;
|
|
276
|
+
}
|
|
277
|
+
return db.mergeSchema(
|
|
278
|
+
{
|
|
279
|
+
...options.subscription?.enabled ? subscriptions : {},
|
|
280
|
+
...user
|
|
281
|
+
},
|
|
282
|
+
options.schema
|
|
283
|
+
);
|
|
277
284
|
};
|
|
278
285
|
|
|
279
286
|
const STRIPE_ERROR_CODES = {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,64 @@
|
|
|
1
1
|
import * as better_auth from 'better-auth';
|
|
2
|
-
import { User, Session, GenericEndpointContext } from 'better-auth';
|
|
2
|
+
import { User, Session, InferOptionSchema, GenericEndpointContext } from 'better-auth';
|
|
3
3
|
import * as better_call from 'better-call';
|
|
4
4
|
import Stripe from 'stripe';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { APIError } from 'better-auth/api';
|
|
7
7
|
|
|
8
|
+
declare const subscriptions: {
|
|
9
|
+
subscription: {
|
|
10
|
+
fields: {
|
|
11
|
+
plan: {
|
|
12
|
+
type: "string";
|
|
13
|
+
required: true;
|
|
14
|
+
};
|
|
15
|
+
referenceId: {
|
|
16
|
+
type: "string";
|
|
17
|
+
required: true;
|
|
18
|
+
};
|
|
19
|
+
stripeCustomerId: {
|
|
20
|
+
type: "string";
|
|
21
|
+
required: false;
|
|
22
|
+
};
|
|
23
|
+
stripeSubscriptionId: {
|
|
24
|
+
type: "string";
|
|
25
|
+
required: false;
|
|
26
|
+
};
|
|
27
|
+
status: {
|
|
28
|
+
type: "string";
|
|
29
|
+
defaultValue: string;
|
|
30
|
+
};
|
|
31
|
+
periodStart: {
|
|
32
|
+
type: "date";
|
|
33
|
+
required: false;
|
|
34
|
+
};
|
|
35
|
+
periodEnd: {
|
|
36
|
+
type: "date";
|
|
37
|
+
required: false;
|
|
38
|
+
};
|
|
39
|
+
cancelAtPeriodEnd: {
|
|
40
|
+
type: "boolean";
|
|
41
|
+
required: false;
|
|
42
|
+
defaultValue: false;
|
|
43
|
+
};
|
|
44
|
+
seats: {
|
|
45
|
+
type: "number";
|
|
46
|
+
required: false;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
declare const user: {
|
|
52
|
+
user: {
|
|
53
|
+
fields: {
|
|
54
|
+
stripeCustomerId: {
|
|
55
|
+
type: "string";
|
|
56
|
+
required: false;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
8
62
|
type StripePlan = {
|
|
9
63
|
/**
|
|
10
64
|
* Monthly price id
|
|
@@ -280,6 +334,10 @@ interface StripeOptions {
|
|
|
280
334
|
};
|
|
281
335
|
};
|
|
282
336
|
onEvent?: (event: Stripe.Event) => Promise<void>;
|
|
337
|
+
/**
|
|
338
|
+
* Schema for the stripe plugin
|
|
339
|
+
*/
|
|
340
|
+
schema?: InferOptionSchema<typeof subscriptions & typeof user>;
|
|
283
341
|
}
|
|
284
342
|
interface Customer {
|
|
285
343
|
id: string;
|
|
@@ -964,8 +1022,7 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
964
1022
|
};
|
|
965
1023
|
};
|
|
966
1024
|
};
|
|
967
|
-
|
|
968
|
-
subscription: {
|
|
1025
|
+
subscription?: {
|
|
969
1026
|
fields: {
|
|
970
1027
|
plan: {
|
|
971
1028
|
type: "string";
|
|
@@ -1005,7 +1062,7 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
1005
1062
|
required: false;
|
|
1006
1063
|
};
|
|
1007
1064
|
};
|
|
1008
|
-
};
|
|
1065
|
+
} | undefined;
|
|
1009
1066
|
};
|
|
1010
1067
|
};
|
|
1011
1068
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,64 @@
|
|
|
1
1
|
import * as better_auth from 'better-auth';
|
|
2
|
-
import { User, Session, GenericEndpointContext } from 'better-auth';
|
|
2
|
+
import { User, Session, InferOptionSchema, GenericEndpointContext } from 'better-auth';
|
|
3
3
|
import * as better_call from 'better-call';
|
|
4
4
|
import Stripe from 'stripe';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { APIError } from 'better-auth/api';
|
|
7
7
|
|
|
8
|
+
declare const subscriptions: {
|
|
9
|
+
subscription: {
|
|
10
|
+
fields: {
|
|
11
|
+
plan: {
|
|
12
|
+
type: "string";
|
|
13
|
+
required: true;
|
|
14
|
+
};
|
|
15
|
+
referenceId: {
|
|
16
|
+
type: "string";
|
|
17
|
+
required: true;
|
|
18
|
+
};
|
|
19
|
+
stripeCustomerId: {
|
|
20
|
+
type: "string";
|
|
21
|
+
required: false;
|
|
22
|
+
};
|
|
23
|
+
stripeSubscriptionId: {
|
|
24
|
+
type: "string";
|
|
25
|
+
required: false;
|
|
26
|
+
};
|
|
27
|
+
status: {
|
|
28
|
+
type: "string";
|
|
29
|
+
defaultValue: string;
|
|
30
|
+
};
|
|
31
|
+
periodStart: {
|
|
32
|
+
type: "date";
|
|
33
|
+
required: false;
|
|
34
|
+
};
|
|
35
|
+
periodEnd: {
|
|
36
|
+
type: "date";
|
|
37
|
+
required: false;
|
|
38
|
+
};
|
|
39
|
+
cancelAtPeriodEnd: {
|
|
40
|
+
type: "boolean";
|
|
41
|
+
required: false;
|
|
42
|
+
defaultValue: false;
|
|
43
|
+
};
|
|
44
|
+
seats: {
|
|
45
|
+
type: "number";
|
|
46
|
+
required: false;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
declare const user: {
|
|
52
|
+
user: {
|
|
53
|
+
fields: {
|
|
54
|
+
stripeCustomerId: {
|
|
55
|
+
type: "string";
|
|
56
|
+
required: false;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
8
62
|
type StripePlan = {
|
|
9
63
|
/**
|
|
10
64
|
* Monthly price id
|
|
@@ -280,6 +334,10 @@ interface StripeOptions {
|
|
|
280
334
|
};
|
|
281
335
|
};
|
|
282
336
|
onEvent?: (event: Stripe.Event) => Promise<void>;
|
|
337
|
+
/**
|
|
338
|
+
* Schema for the stripe plugin
|
|
339
|
+
*/
|
|
340
|
+
schema?: InferOptionSchema<typeof subscriptions & typeof user>;
|
|
283
341
|
}
|
|
284
342
|
interface Customer {
|
|
285
343
|
id: string;
|
|
@@ -964,8 +1022,7 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
964
1022
|
};
|
|
965
1023
|
};
|
|
966
1024
|
};
|
|
967
|
-
|
|
968
|
-
subscription: {
|
|
1025
|
+
subscription?: {
|
|
969
1026
|
fields: {
|
|
970
1027
|
plan: {
|
|
971
1028
|
type: "string";
|
|
@@ -1005,7 +1062,7 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
1005
1062
|
required: false;
|
|
1006
1063
|
};
|
|
1007
1064
|
};
|
|
1008
|
-
};
|
|
1065
|
+
} | undefined;
|
|
1009
1066
|
};
|
|
1010
1067
|
};
|
|
1011
1068
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,64 @@
|
|
|
1
1
|
import * as better_auth from 'better-auth';
|
|
2
|
-
import { User, Session, GenericEndpointContext } from 'better-auth';
|
|
2
|
+
import { User, Session, InferOptionSchema, GenericEndpointContext } from 'better-auth';
|
|
3
3
|
import * as better_call from 'better-call';
|
|
4
4
|
import Stripe from 'stripe';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { APIError } from 'better-auth/api';
|
|
7
7
|
|
|
8
|
+
declare const subscriptions: {
|
|
9
|
+
subscription: {
|
|
10
|
+
fields: {
|
|
11
|
+
plan: {
|
|
12
|
+
type: "string";
|
|
13
|
+
required: true;
|
|
14
|
+
};
|
|
15
|
+
referenceId: {
|
|
16
|
+
type: "string";
|
|
17
|
+
required: true;
|
|
18
|
+
};
|
|
19
|
+
stripeCustomerId: {
|
|
20
|
+
type: "string";
|
|
21
|
+
required: false;
|
|
22
|
+
};
|
|
23
|
+
stripeSubscriptionId: {
|
|
24
|
+
type: "string";
|
|
25
|
+
required: false;
|
|
26
|
+
};
|
|
27
|
+
status: {
|
|
28
|
+
type: "string";
|
|
29
|
+
defaultValue: string;
|
|
30
|
+
};
|
|
31
|
+
periodStart: {
|
|
32
|
+
type: "date";
|
|
33
|
+
required: false;
|
|
34
|
+
};
|
|
35
|
+
periodEnd: {
|
|
36
|
+
type: "date";
|
|
37
|
+
required: false;
|
|
38
|
+
};
|
|
39
|
+
cancelAtPeriodEnd: {
|
|
40
|
+
type: "boolean";
|
|
41
|
+
required: false;
|
|
42
|
+
defaultValue: false;
|
|
43
|
+
};
|
|
44
|
+
seats: {
|
|
45
|
+
type: "number";
|
|
46
|
+
required: false;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
declare const user: {
|
|
52
|
+
user: {
|
|
53
|
+
fields: {
|
|
54
|
+
stripeCustomerId: {
|
|
55
|
+
type: "string";
|
|
56
|
+
required: false;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
8
62
|
type StripePlan = {
|
|
9
63
|
/**
|
|
10
64
|
* Monthly price id
|
|
@@ -280,6 +334,10 @@ interface StripeOptions {
|
|
|
280
334
|
};
|
|
281
335
|
};
|
|
282
336
|
onEvent?: (event: Stripe.Event) => Promise<void>;
|
|
337
|
+
/**
|
|
338
|
+
* Schema for the stripe plugin
|
|
339
|
+
*/
|
|
340
|
+
schema?: InferOptionSchema<typeof subscriptions & typeof user>;
|
|
283
341
|
}
|
|
284
342
|
interface Customer {
|
|
285
343
|
id: string;
|
|
@@ -964,8 +1022,7 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
964
1022
|
};
|
|
965
1023
|
};
|
|
966
1024
|
};
|
|
967
|
-
|
|
968
|
-
subscription: {
|
|
1025
|
+
subscription?: {
|
|
969
1026
|
fields: {
|
|
970
1027
|
plan: {
|
|
971
1028
|
type: "string";
|
|
@@ -1005,7 +1062,7 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
1005
1062
|
required: false;
|
|
1006
1063
|
};
|
|
1007
1064
|
};
|
|
1008
|
-
};
|
|
1065
|
+
} | undefined;
|
|
1009
1066
|
};
|
|
1010
1067
|
};
|
|
1011
1068
|
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { createAuthEndpoint, createAuthMiddleware } from 'better-auth/plugins';
|
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { originCheck, getSessionFromCtx, sessionMiddleware, APIError } from 'better-auth/api';
|
|
5
5
|
import { generateRandomString } from 'better-auth/crypto';
|
|
6
|
+
import { mergeSchema } from 'better-auth/db';
|
|
6
7
|
|
|
7
8
|
async function getPlans(options) {
|
|
8
9
|
return typeof options?.subscription?.plans === "function" ? await options.subscription?.plans() : options.subscription?.plans;
|
|
@@ -214,64 +215,70 @@ async function onSubscriptionDeleted(ctx, options, event) {
|
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
required: false
|
|
257
|
-
}
|
|
218
|
+
const subscriptions = {
|
|
219
|
+
subscription: {
|
|
220
|
+
fields: {
|
|
221
|
+
plan: {
|
|
222
|
+
type: "string",
|
|
223
|
+
required: true
|
|
224
|
+
},
|
|
225
|
+
referenceId: {
|
|
226
|
+
type: "string",
|
|
227
|
+
required: true
|
|
228
|
+
},
|
|
229
|
+
stripeCustomerId: {
|
|
230
|
+
type: "string",
|
|
231
|
+
required: false
|
|
232
|
+
},
|
|
233
|
+
stripeSubscriptionId: {
|
|
234
|
+
type: "string",
|
|
235
|
+
required: false
|
|
236
|
+
},
|
|
237
|
+
status: {
|
|
238
|
+
type: "string",
|
|
239
|
+
defaultValue: "incomplete"
|
|
240
|
+
},
|
|
241
|
+
periodStart: {
|
|
242
|
+
type: "date",
|
|
243
|
+
required: false
|
|
244
|
+
},
|
|
245
|
+
periodEnd: {
|
|
246
|
+
type: "date",
|
|
247
|
+
required: false
|
|
248
|
+
},
|
|
249
|
+
cancelAtPeriodEnd: {
|
|
250
|
+
type: "boolean",
|
|
251
|
+
required: false,
|
|
252
|
+
defaultValue: false
|
|
253
|
+
},
|
|
254
|
+
seats: {
|
|
255
|
+
type: "number",
|
|
256
|
+
required: false
|
|
258
257
|
}
|
|
259
258
|
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const user = {
|
|
262
|
+
user: {
|
|
263
|
+
fields: {
|
|
264
|
+
stripeCustomerId: {
|
|
265
|
+
type: "string",
|
|
266
|
+
required: false
|
|
268
267
|
}
|
|
269
268
|
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
const getSchema = (options) => {
|
|
272
|
+
if (options.schema && !options.subscription?.enabled && "subscription" in options.schema) {
|
|
273
|
+
options.schema.subscription = void 0;
|
|
274
|
+
}
|
|
275
|
+
return mergeSchema(
|
|
276
|
+
{
|
|
277
|
+
...options.subscription?.enabled ? subscriptions : {},
|
|
278
|
+
...user
|
|
279
|
+
},
|
|
280
|
+
options.schema
|
|
281
|
+
);
|
|
275
282
|
};
|
|
276
283
|
|
|
277
284
|
const STRIPE_ERROR_CODES = {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/stripe",
|
|
3
3
|
"author": "Bereket Engida",
|
|
4
|
-
"version": "1.2.6-beta.
|
|
4
|
+
"version": "1.2.6-beta.5",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"zod": "^3.24.1",
|
|
38
|
-
"better-auth": "^1.2.6-beta.
|
|
38
|
+
"better-auth": "^1.2.6-beta.5"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/better-sqlite3": "^7.6.12",
|
package/src/schema.ts
CHANGED
|
@@ -1,62 +1,75 @@
|
|
|
1
1
|
import type { AuthPluginSchema } from "better-auth";
|
|
2
2
|
import type { StripeOptions } from "./types";
|
|
3
|
+
import { mergeSchema } from "better-auth/db";
|
|
3
4
|
|
|
4
|
-
export const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
required: false,
|
|
44
|
-
},
|
|
5
|
+
export const subscriptions = {
|
|
6
|
+
subscription: {
|
|
7
|
+
fields: {
|
|
8
|
+
plan: {
|
|
9
|
+
type: "string",
|
|
10
|
+
required: true,
|
|
11
|
+
},
|
|
12
|
+
referenceId: {
|
|
13
|
+
type: "string",
|
|
14
|
+
required: true,
|
|
15
|
+
},
|
|
16
|
+
stripeCustomerId: {
|
|
17
|
+
type: "string",
|
|
18
|
+
required: false,
|
|
19
|
+
},
|
|
20
|
+
stripeSubscriptionId: {
|
|
21
|
+
type: "string",
|
|
22
|
+
required: false,
|
|
23
|
+
},
|
|
24
|
+
status: {
|
|
25
|
+
type: "string",
|
|
26
|
+
defaultValue: "incomplete",
|
|
27
|
+
},
|
|
28
|
+
periodStart: {
|
|
29
|
+
type: "date",
|
|
30
|
+
required: false,
|
|
31
|
+
},
|
|
32
|
+
periodEnd: {
|
|
33
|
+
type: "date",
|
|
34
|
+
required: false,
|
|
35
|
+
},
|
|
36
|
+
cancelAtPeriodEnd: {
|
|
37
|
+
type: "boolean",
|
|
38
|
+
required: false,
|
|
39
|
+
defaultValue: false,
|
|
40
|
+
},
|
|
41
|
+
seats: {
|
|
42
|
+
type: "number",
|
|
43
|
+
required: false,
|
|
45
44
|
},
|
|
46
45
|
},
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
},
|
|
47
|
+
} satisfies AuthPluginSchema;
|
|
48
|
+
|
|
49
|
+
export const user = {
|
|
50
|
+
user: {
|
|
51
|
+
fields: {
|
|
52
|
+
stripeCustomerId: {
|
|
53
|
+
type: "string",
|
|
54
|
+
required: false,
|
|
55
55
|
},
|
|
56
56
|
},
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
},
|
|
58
|
+
} satisfies AuthPluginSchema;
|
|
59
|
+
|
|
60
|
+
export const getSchema = (options: StripeOptions) => {
|
|
61
|
+
if (
|
|
62
|
+
options.schema &&
|
|
63
|
+
!options.subscription?.enabled &&
|
|
64
|
+
"subscription" in options.schema
|
|
65
|
+
) {
|
|
66
|
+
options.schema.subscription = undefined;
|
|
67
|
+
}
|
|
68
|
+
return mergeSchema(
|
|
69
|
+
{
|
|
70
|
+
...(options.subscription?.enabled ? subscriptions : {}),
|
|
71
|
+
...user,
|
|
72
|
+
},
|
|
73
|
+
options.schema,
|
|
74
|
+
);
|
|
62
75
|
};
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { Session, User } from "better-auth";
|
|
1
|
+
import type { InferOptionSchema, Session, User } from "better-auth";
|
|
2
2
|
import type Stripe from "stripe";
|
|
3
|
+
import type { subscriptions, user } from "./schema";
|
|
3
4
|
|
|
4
5
|
export type StripePlan = {
|
|
5
6
|
/**
|
|
@@ -312,6 +313,10 @@ export interface StripeOptions {
|
|
|
312
313
|
};
|
|
313
314
|
};
|
|
314
315
|
onEvent?: (event: Stripe.Event) => Promise<void>;
|
|
316
|
+
/**
|
|
317
|
+
* Schema for the stripe plugin
|
|
318
|
+
*/
|
|
319
|
+
schema?: InferOptionSchema<typeof subscriptions & typeof user>;
|
|
315
320
|
}
|
|
316
321
|
|
|
317
322
|
export interface Customer {
|