@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.
package/src/schema.ts ADDED
@@ -0,0 +1,92 @@
1
+ import type { AuthPluginSchema } from "faire-auth";
2
+ import type { StripeOptions } from "./types";
3
+ import { mergeSchema } from "faire-auth/db";
4
+
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
+ trialStart: {
37
+ type: "date",
38
+ required: false,
39
+ },
40
+ trialEnd: {
41
+ type: "date",
42
+ required: false,
43
+ },
44
+ cancelAtPeriodEnd: {
45
+ type: "boolean",
46
+ required: false,
47
+ defaultValue: false,
48
+ },
49
+ seats: {
50
+ type: "number",
51
+ required: false,
52
+ },
53
+ },
54
+ },
55
+ } satisfies AuthPluginSchema;
56
+
57
+ export const user = {
58
+ user: {
59
+ fields: {
60
+ stripeCustomerId: {
61
+ type: "string",
62
+ required: false,
63
+ },
64
+ },
65
+ },
66
+ } satisfies AuthPluginSchema;
67
+
68
+ export const getSchema = (options: StripeOptions) => {
69
+ let baseSchema = {};
70
+
71
+ if (options.subscription?.enabled) {
72
+ baseSchema = {
73
+ ...subscriptions,
74
+ ...user,
75
+ };
76
+ } else {
77
+ baseSchema = {
78
+ ...user,
79
+ };
80
+ }
81
+
82
+ if (
83
+ options.schema &&
84
+ !options.subscription?.enabled &&
85
+ "subscription" in options.schema
86
+ ) {
87
+ const { subscription, ...restSchema } = options.schema;
88
+ return mergeSchema(baseSchema, restSchema);
89
+ }
90
+
91
+ return mergeSchema(baseSchema, options.schema);
92
+ };