@codaijs/keel 0.2.2 → 0.2.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.
- package/dist/__tests__/sail-installer.test.js +25 -25
- package/dist/sail-installer.js +174 -174
- package/dist/scaffold.js +68 -68
- package/package.json +58 -58
- package/sails/_template/addon.json +20 -20
- package/sails/_template/install.ts +402 -402
- package/sails/admin-dashboard/README.md +117 -117
- package/sails/admin-dashboard/addon.json +28 -28
- package/sails/admin-dashboard/files/backend/middleware/admin.ts +34 -34
- package/sails/admin-dashboard/files/backend/routes/admin.ts +243 -243
- package/sails/admin-dashboard/files/frontend/components/admin/StatsCard.tsx +40 -40
- package/sails/admin-dashboard/files/frontend/components/admin/UsersTable.tsx +240 -240
- package/sails/admin-dashboard/files/frontend/hooks/useAdmin.ts +149 -149
- package/sails/admin-dashboard/files/frontend/pages/admin/Dashboard.tsx +173 -173
- package/sails/admin-dashboard/files/frontend/pages/admin/UserDetail.tsx +203 -203
- package/sails/admin-dashboard/install.ts +305 -305
- package/sails/analytics/README.md +178 -178
- package/sails/analytics/addon.json +27 -27
- package/sails/analytics/files/frontend/components/AnalyticsProvider.tsx +58 -58
- package/sails/analytics/files/frontend/hooks/useAnalytics.ts +64 -64
- package/sails/analytics/files/frontend/lib/analytics.ts +103 -103
- package/sails/analytics/install.ts +297 -297
- package/sails/file-uploads/addon.json +30 -30
- package/sails/file-uploads/files/backend/routes/files.ts +198 -198
- package/sails/file-uploads/files/backend/schema/files.ts +36 -36
- package/sails/file-uploads/files/backend/services/file-storage.ts +128 -128
- package/sails/file-uploads/files/frontend/components/FileList.tsx +248 -248
- package/sails/file-uploads/files/frontend/components/FileUploadButton.tsx +147 -147
- package/sails/file-uploads/files/frontend/hooks/useFileUpload.ts +106 -106
- package/sails/file-uploads/files/frontend/hooks/useFiles.ts +118 -118
- package/sails/file-uploads/files/frontend/pages/Files.tsx +37 -37
- package/sails/file-uploads/install.ts +466 -466
- package/sails/gdpr/README.md +174 -174
- package/sails/gdpr/addon.json +27 -27
- package/sails/gdpr/files/backend/routes/gdpr.ts +140 -140
- package/sails/gdpr/files/backend/services/gdpr.ts +293 -293
- package/sails/gdpr/files/frontend/components/auth/ConsentCheckboxes.tsx +97 -97
- package/sails/gdpr/files/frontend/components/gdpr/AccountDeletionRequest.tsx +192 -192
- package/sails/gdpr/files/frontend/components/gdpr/DataExportButton.tsx +75 -75
- package/sails/gdpr/files/frontend/pages/PrivacyPolicy.tsx +186 -186
- package/sails/gdpr/install.ts +756 -756
- package/sails/google-oauth/README.md +121 -121
- package/sails/google-oauth/addon.json +22 -22
- package/sails/google-oauth/files/GoogleButton.tsx +50 -50
- package/sails/google-oauth/install.ts +252 -252
- package/sails/i18n/README.md +193 -193
- package/sails/i18n/addon.json +30 -30
- package/sails/i18n/files/frontend/components/LanguageSwitcher.tsx +108 -108
- package/sails/i18n/files/frontend/hooks/useLanguage.ts +31 -31
- package/sails/i18n/files/frontend/lib/i18n.ts +32 -32
- package/sails/i18n/files/frontend/locales/de/common.json +44 -44
- package/sails/i18n/files/frontend/locales/en/common.json +44 -44
- package/sails/i18n/install.ts +407 -407
- package/sails/push-notifications/README.md +163 -163
- package/sails/push-notifications/addon.json +31 -31
- package/sails/push-notifications/files/backend/routes/notifications.ts +153 -153
- package/sails/push-notifications/files/backend/schema/notifications.ts +31 -31
- package/sails/push-notifications/files/backend/services/notifications.ts +117 -117
- package/sails/push-notifications/files/frontend/components/PushNotificationInit.tsx +12 -12
- package/sails/push-notifications/files/frontend/hooks/usePushNotifications.ts +154 -154
- package/sails/push-notifications/install.ts +384 -384
- package/sails/r2-storage/addon.json +29 -29
- package/sails/r2-storage/files/backend/services/storage.ts +71 -71
- package/sails/r2-storage/files/frontend/components/ProfilePictureUpload.tsx +167 -167
- package/sails/r2-storage/install.ts +412 -412
- package/sails/rate-limiting/addon.json +20 -20
- package/sails/rate-limiting/files/backend/middleware/rate-limit-store.ts +104 -104
- package/sails/rate-limiting/files/backend/middleware/rate-limit.ts +137 -137
- package/sails/rate-limiting/install.ts +300 -300
- package/sails/registry.json +107 -107
- package/sails/stripe/README.md +214 -214
- package/sails/stripe/addon.json +24 -24
- package/sails/stripe/files/backend/routes/stripe.ts +154 -154
- package/sails/stripe/files/backend/schema/stripe.ts +74 -74
- package/sails/stripe/files/backend/services/stripe.ts +224 -224
- package/sails/stripe/files/frontend/components/SubscriptionStatus.tsx +135 -135
- package/sails/stripe/files/frontend/hooks/useSubscription.ts +86 -86
- package/sails/stripe/files/frontend/pages/Checkout.tsx +116 -116
- package/sails/stripe/files/frontend/pages/Pricing.tsx +226 -226
- package/sails/stripe/install.ts +378 -378
package/sails/stripe/addon.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "stripe",
|
|
3
|
-
"displayName": "Stripe Payments",
|
|
4
|
-
"description": "Adds Stripe subscription management with checkout, webhooks, and customer portal",
|
|
5
|
-
"version": "1.0.0",
|
|
6
|
-
"compatibility": ">=1.0.0",
|
|
7
|
-
"requiredEnvVars": [
|
|
8
|
-
{ "key": "STRIPE_SECRET_KEY", "description": "Stripe secret key (sk_test_... or sk_live_...)" },
|
|
9
|
-
{ "key": "STRIPE_PUBLISHABLE_KEY", "description": "Stripe publishable key (pk_test_... or pk_live_...)" },
|
|
10
|
-
{ "key": "STRIPE_WEBHOOK_SECRET", "description": "Stripe webhook signing secret (whsec_...)" }
|
|
11
|
-
],
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"backend": { "stripe": "^17.0.0" },
|
|
14
|
-
"frontend": { "@stripe/react-stripe-js": "^3.0.0", "@stripe/stripe-js": "^5.0.0" }
|
|
15
|
-
},
|
|
16
|
-
"modifies": {
|
|
17
|
-
"backend": ["src/index.ts", "src/db/schema/index.ts", "src/env.ts"],
|
|
18
|
-
"frontend": ["src/router.tsx"]
|
|
19
|
-
},
|
|
20
|
-
"adds": {
|
|
21
|
-
"backend": ["src/db/schema/stripe.ts", "src/routes/stripe.ts", "src/services/stripe.ts"],
|
|
22
|
-
"frontend": ["src/pages/Pricing.tsx", "src/pages/Checkout.tsx", "src/components/stripe/SubscriptionStatus.tsx", "src/hooks/useSubscription.ts"]
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "stripe",
|
|
3
|
+
"displayName": "Stripe Payments",
|
|
4
|
+
"description": "Adds Stripe subscription management with checkout, webhooks, and customer portal",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"compatibility": ">=1.0.0",
|
|
7
|
+
"requiredEnvVars": [
|
|
8
|
+
{ "key": "STRIPE_SECRET_KEY", "description": "Stripe secret key (sk_test_... or sk_live_...)" },
|
|
9
|
+
{ "key": "STRIPE_PUBLISHABLE_KEY", "description": "Stripe publishable key (pk_test_... or pk_live_...)" },
|
|
10
|
+
{ "key": "STRIPE_WEBHOOK_SECRET", "description": "Stripe webhook signing secret (whsec_...)" }
|
|
11
|
+
],
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"backend": { "stripe": "^17.0.0" },
|
|
14
|
+
"frontend": { "@stripe/react-stripe-js": "^3.0.0", "@stripe/stripe-js": "^5.0.0" }
|
|
15
|
+
},
|
|
16
|
+
"modifies": {
|
|
17
|
+
"backend": ["src/index.ts", "src/db/schema/index.ts", "src/env.ts"],
|
|
18
|
+
"frontend": ["src/router.tsx"]
|
|
19
|
+
},
|
|
20
|
+
"adds": {
|
|
21
|
+
"backend": ["src/db/schema/stripe.ts", "src/routes/stripe.ts", "src/services/stripe.ts"],
|
|
22
|
+
"frontend": ["src/pages/Pricing.tsx", "src/pages/Checkout.tsx", "src/components/stripe/SubscriptionStatus.tsx", "src/hooks/useSubscription.ts"]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
import { Router, type Request, type Response } from "express";
|
|
2
|
-
import { eq } from "drizzle-orm";
|
|
3
|
-
import { db } from "../db";
|
|
4
|
-
import { customers, subscriptions } from "../db/schema/stripe";
|
|
5
|
-
import {
|
|
6
|
-
createOrGetCustomer,
|
|
7
|
-
createCheckoutSession,
|
|
8
|
-
createPortalSession,
|
|
9
|
-
handleWebhookEvent,
|
|
10
|
-
} from "../services/stripe";
|
|
11
|
-
import { requireAuth } from "../middleware/auth";
|
|
12
|
-
|
|
13
|
-
export const stripeRouter = Router();
|
|
14
|
-
|
|
15
|
-
// ---------------------------------------------------------------------------
|
|
16
|
-
// POST /create-checkout-session
|
|
17
|
-
// ---------------------------------------------------------------------------
|
|
18
|
-
|
|
19
|
-
stripeRouter.post(
|
|
20
|
-
"/create-checkout-session",
|
|
21
|
-
requireAuth,
|
|
22
|
-
async (req: Request, res: Response) => {
|
|
23
|
-
try {
|
|
24
|
-
const { priceId } = req.body;
|
|
25
|
-
|
|
26
|
-
if (!priceId || typeof priceId !== "string") {
|
|
27
|
-
return res.status(400).json({ error: "priceId is required" });
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const user = req.user!;
|
|
31
|
-
const stripeCustomerId = await createOrGetCustomer(user.id, user.email);
|
|
32
|
-
|
|
33
|
-
const baseUrl = `${req.protocol}://${req.get("host")}`;
|
|
34
|
-
const session = await createCheckoutSession(
|
|
35
|
-
stripeCustomerId,
|
|
36
|
-
priceId,
|
|
37
|
-
`${baseUrl}/checkout/success?session_id={CHECKOUT_SESSION_ID}`,
|
|
38
|
-
`${baseUrl}/checkout/cancel`
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
return res.json({ url: session.url });
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.error("Error creating checkout session:", error);
|
|
44
|
-
return res.status(500).json({ error: "Failed to create checkout session" });
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
// ---------------------------------------------------------------------------
|
|
50
|
-
// POST /create-portal-session
|
|
51
|
-
// ---------------------------------------------------------------------------
|
|
52
|
-
|
|
53
|
-
stripeRouter.post(
|
|
54
|
-
"/create-portal-session",
|
|
55
|
-
requireAuth,
|
|
56
|
-
async (req: Request, res: Response) => {
|
|
57
|
-
try {
|
|
58
|
-
const user = req.user!;
|
|
59
|
-
|
|
60
|
-
const customer = await db.query.customers.findFirst({
|
|
61
|
-
where: eq(customers.userId, user.id),
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
if (!customer) {
|
|
65
|
-
return res.status(404).json({ error: "No subscription found" });
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const baseUrl = `${req.protocol}://${req.get("host")}`;
|
|
69
|
-
const session = await createPortalSession(
|
|
70
|
-
customer.stripeCustomerId,
|
|
71
|
-
`${baseUrl}/settings`
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
return res.json({ url: session.url });
|
|
75
|
-
} catch (error) {
|
|
76
|
-
console.error("Error creating portal session:", error);
|
|
77
|
-
return res.status(500).json({ error: "Failed to create portal session" });
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
// ---------------------------------------------------------------------------
|
|
83
|
-
// POST /webhook
|
|
84
|
-
// ---------------------------------------------------------------------------
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Stripe webhook endpoint.
|
|
88
|
-
*
|
|
89
|
-
* IMPORTANT: This route must receive the raw request body (not parsed as JSON).
|
|
90
|
-
* The Express app must be configured with:
|
|
91
|
-
*
|
|
92
|
-
* app.use("/api/stripe/webhook", express.raw({ type: "application/json" }));
|
|
93
|
-
*
|
|
94
|
-
* This should be placed BEFORE the general express.json() middleware.
|
|
95
|
-
*/
|
|
96
|
-
stripeRouter.post("/webhook", async (req: Request, res: Response) => {
|
|
97
|
-
const signature = req.headers["stripe-signature"];
|
|
98
|
-
|
|
99
|
-
if (!signature || typeof signature !== "string") {
|
|
100
|
-
return res.status(400).json({ error: "Missing stripe-signature header" });
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
await handleWebhookEvent(req.body, signature);
|
|
105
|
-
return res.json({ received: true });
|
|
106
|
-
} catch (error) {
|
|
107
|
-
console.error("Webhook error:", error);
|
|
108
|
-
return res
|
|
109
|
-
.status(400)
|
|
110
|
-
.json({ error: error instanceof Error ? error.message : "Webhook failed" });
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
// ---------------------------------------------------------------------------
|
|
115
|
-
// GET /subscription
|
|
116
|
-
// ---------------------------------------------------------------------------
|
|
117
|
-
|
|
118
|
-
stripeRouter.get(
|
|
119
|
-
"/subscription",
|
|
120
|
-
requireAuth,
|
|
121
|
-
async (req: Request, res: Response) => {
|
|
122
|
-
try {
|
|
123
|
-
const user = req.user!;
|
|
124
|
-
|
|
125
|
-
const customer = await db.query.customers.findFirst({
|
|
126
|
-
where: eq(customers.userId, user.id),
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
if (!customer) {
|
|
130
|
-
return res.json({ subscription: null });
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const subscription = await db.query.subscriptions.findFirst({
|
|
134
|
-
where: eq(subscriptions.customerId, customer.id),
|
|
135
|
-
orderBy: (sub, { desc }) => [desc(sub.createdAt)],
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
return res.json({
|
|
139
|
-
subscription: subscription
|
|
140
|
-
? {
|
|
141
|
-
id: subscription.id,
|
|
142
|
-
status: subscription.status,
|
|
143
|
-
priceId: subscription.stripePriceId,
|
|
144
|
-
currentPeriodEnd: subscription.currentPeriodEnd,
|
|
145
|
-
cancelAtPeriodEnd: subscription.cancelAtPeriodEnd,
|
|
146
|
-
}
|
|
147
|
-
: null,
|
|
148
|
-
});
|
|
149
|
-
} catch (error) {
|
|
150
|
-
console.error("Error fetching subscription:", error);
|
|
151
|
-
return res.status(500).json({ error: "Failed to fetch subscription" });
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
);
|
|
1
|
+
import { Router, type Request, type Response } from "express";
|
|
2
|
+
import { eq } from "drizzle-orm";
|
|
3
|
+
import { db } from "../db";
|
|
4
|
+
import { customers, subscriptions } from "../db/schema/stripe";
|
|
5
|
+
import {
|
|
6
|
+
createOrGetCustomer,
|
|
7
|
+
createCheckoutSession,
|
|
8
|
+
createPortalSession,
|
|
9
|
+
handleWebhookEvent,
|
|
10
|
+
} from "../services/stripe";
|
|
11
|
+
import { requireAuth } from "../middleware/auth";
|
|
12
|
+
|
|
13
|
+
export const stripeRouter = Router();
|
|
14
|
+
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// POST /create-checkout-session
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
stripeRouter.post(
|
|
20
|
+
"/create-checkout-session",
|
|
21
|
+
requireAuth,
|
|
22
|
+
async (req: Request, res: Response) => {
|
|
23
|
+
try {
|
|
24
|
+
const { priceId } = req.body;
|
|
25
|
+
|
|
26
|
+
if (!priceId || typeof priceId !== "string") {
|
|
27
|
+
return res.status(400).json({ error: "priceId is required" });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const user = req.user!;
|
|
31
|
+
const stripeCustomerId = await createOrGetCustomer(user.id, user.email);
|
|
32
|
+
|
|
33
|
+
const baseUrl = `${req.protocol}://${req.get("host")}`;
|
|
34
|
+
const session = await createCheckoutSession(
|
|
35
|
+
stripeCustomerId,
|
|
36
|
+
priceId,
|
|
37
|
+
`${baseUrl}/checkout/success?session_id={CHECKOUT_SESSION_ID}`,
|
|
38
|
+
`${baseUrl}/checkout/cancel`
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return res.json({ url: session.url });
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error("Error creating checkout session:", error);
|
|
44
|
+
return res.status(500).json({ error: "Failed to create checkout session" });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// POST /create-portal-session
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
|
|
53
|
+
stripeRouter.post(
|
|
54
|
+
"/create-portal-session",
|
|
55
|
+
requireAuth,
|
|
56
|
+
async (req: Request, res: Response) => {
|
|
57
|
+
try {
|
|
58
|
+
const user = req.user!;
|
|
59
|
+
|
|
60
|
+
const customer = await db.query.customers.findFirst({
|
|
61
|
+
where: eq(customers.userId, user.id),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (!customer) {
|
|
65
|
+
return res.status(404).json({ error: "No subscription found" });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const baseUrl = `${req.protocol}://${req.get("host")}`;
|
|
69
|
+
const session = await createPortalSession(
|
|
70
|
+
customer.stripeCustomerId,
|
|
71
|
+
`${baseUrl}/settings`
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
return res.json({ url: session.url });
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error("Error creating portal session:", error);
|
|
77
|
+
return res.status(500).json({ error: "Failed to create portal session" });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
// POST /webhook
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Stripe webhook endpoint.
|
|
88
|
+
*
|
|
89
|
+
* IMPORTANT: This route must receive the raw request body (not parsed as JSON).
|
|
90
|
+
* The Express app must be configured with:
|
|
91
|
+
*
|
|
92
|
+
* app.use("/api/stripe/webhook", express.raw({ type: "application/json" }));
|
|
93
|
+
*
|
|
94
|
+
* This should be placed BEFORE the general express.json() middleware.
|
|
95
|
+
*/
|
|
96
|
+
stripeRouter.post("/webhook", async (req: Request, res: Response) => {
|
|
97
|
+
const signature = req.headers["stripe-signature"];
|
|
98
|
+
|
|
99
|
+
if (!signature || typeof signature !== "string") {
|
|
100
|
+
return res.status(400).json({ error: "Missing stripe-signature header" });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
await handleWebhookEvent(req.body, signature);
|
|
105
|
+
return res.json({ received: true });
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error("Webhook error:", error);
|
|
108
|
+
return res
|
|
109
|
+
.status(400)
|
|
110
|
+
.json({ error: error instanceof Error ? error.message : "Webhook failed" });
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// ---------------------------------------------------------------------------
|
|
115
|
+
// GET /subscription
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
|
|
118
|
+
stripeRouter.get(
|
|
119
|
+
"/subscription",
|
|
120
|
+
requireAuth,
|
|
121
|
+
async (req: Request, res: Response) => {
|
|
122
|
+
try {
|
|
123
|
+
const user = req.user!;
|
|
124
|
+
|
|
125
|
+
const customer = await db.query.customers.findFirst({
|
|
126
|
+
where: eq(customers.userId, user.id),
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
if (!customer) {
|
|
130
|
+
return res.json({ subscription: null });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const subscription = await db.query.subscriptions.findFirst({
|
|
134
|
+
where: eq(subscriptions.customerId, customer.id),
|
|
135
|
+
orderBy: (sub, { desc }) => [desc(sub.createdAt)],
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
return res.json({
|
|
139
|
+
subscription: subscription
|
|
140
|
+
? {
|
|
141
|
+
id: subscription.id,
|
|
142
|
+
status: subscription.status,
|
|
143
|
+
priceId: subscription.stripePriceId,
|
|
144
|
+
currentPeriodEnd: subscription.currentPeriodEnd,
|
|
145
|
+
cancelAtPeriodEnd: subscription.cancelAtPeriodEnd,
|
|
146
|
+
}
|
|
147
|
+
: null,
|
|
148
|
+
});
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.error("Error fetching subscription:", error);
|
|
151
|
+
return res.status(500).json({ error: "Failed to fetch subscription" });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
);
|
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import {
|
|
2
|
-
pgTable,
|
|
3
|
-
text,
|
|
4
|
-
timestamp,
|
|
5
|
-
boolean,
|
|
6
|
-
uuid,
|
|
7
|
-
} from "drizzle-orm/pg-core";
|
|
8
|
-
import { relations } from "drizzle-orm";
|
|
9
|
-
import { users } from "./users";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Stripe customers table.
|
|
13
|
-
*
|
|
14
|
-
* Maps internal user IDs to Stripe customer IDs. Each user has at most one
|
|
15
|
-
* Stripe customer record, created on their first checkout session.
|
|
16
|
-
*/
|
|
17
|
-
export const customers = pgTable("stripe_customers", {
|
|
18
|
-
id: uuid("id").defaultRandom().primaryKey(),
|
|
19
|
-
userId: text("user_id")
|
|
20
|
-
.notNull()
|
|
21
|
-
.unique()
|
|
22
|
-
.references(() => users.id, { onDelete: "cascade" }),
|
|
23
|
-
stripeCustomerId: text("stripe_customer_id").notNull().unique(),
|
|
24
|
-
createdAt: timestamp("created_at", { withTimezone: true })
|
|
25
|
-
.notNull()
|
|
26
|
-
.defaultNow(),
|
|
27
|
-
updatedAt: timestamp("updated_at", { withTimezone: true })
|
|
28
|
-
.notNull()
|
|
29
|
-
.defaultNow()
|
|
30
|
-
.$onUpdate(() => new Date()),
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
export const customersRelations = relations(customers, ({ one, many }) => ({
|
|
34
|
-
user: one(users, {
|
|
35
|
-
fields: [customers.userId],
|
|
36
|
-
references: [users.id],
|
|
37
|
-
}),
|
|
38
|
-
subscriptions: many(subscriptions),
|
|
39
|
-
}));
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Stripe subscriptions table.
|
|
43
|
-
*
|
|
44
|
-
* Tracks the state of each Stripe subscription. Updated via webhooks whenever
|
|
45
|
-
* Stripe fires subscription lifecycle events.
|
|
46
|
-
*/
|
|
47
|
-
export const subscriptions = pgTable("stripe_subscriptions", {
|
|
48
|
-
id: uuid("id").defaultRandom().primaryKey(),
|
|
49
|
-
customerId: uuid("customer_id")
|
|
50
|
-
.notNull()
|
|
51
|
-
.references(() => customers.id, { onDelete: "cascade" }),
|
|
52
|
-
stripeSubscriptionId: text("stripe_subscription_id").notNull().unique(),
|
|
53
|
-
status: text("status").notNull().default("incomplete"),
|
|
54
|
-
stripePriceId: text("stripe_price_id").notNull(),
|
|
55
|
-
currentPeriodStart: timestamp("current_period_start", {
|
|
56
|
-
withTimezone: true,
|
|
57
|
-
}),
|
|
58
|
-
currentPeriodEnd: timestamp("current_period_end", { withTimezone: true }),
|
|
59
|
-
cancelAtPeriodEnd: boolean("cancel_at_period_end").notNull().default(false),
|
|
60
|
-
createdAt: timestamp("created_at", { withTimezone: true })
|
|
61
|
-
.notNull()
|
|
62
|
-
.defaultNow(),
|
|
63
|
-
updatedAt: timestamp("updated_at", { withTimezone: true })
|
|
64
|
-
.notNull()
|
|
65
|
-
.defaultNow()
|
|
66
|
-
.$onUpdate(() => new Date()),
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
export const subscriptionsRelations = relations(subscriptions, ({ one }) => ({
|
|
70
|
-
customer: one(customers, {
|
|
71
|
-
fields: [subscriptions.customerId],
|
|
72
|
-
references: [customers.id],
|
|
73
|
-
}),
|
|
74
|
-
}));
|
|
1
|
+
import {
|
|
2
|
+
pgTable,
|
|
3
|
+
text,
|
|
4
|
+
timestamp,
|
|
5
|
+
boolean,
|
|
6
|
+
uuid,
|
|
7
|
+
} from "drizzle-orm/pg-core";
|
|
8
|
+
import { relations } from "drizzle-orm";
|
|
9
|
+
import { users } from "./users";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Stripe customers table.
|
|
13
|
+
*
|
|
14
|
+
* Maps internal user IDs to Stripe customer IDs. Each user has at most one
|
|
15
|
+
* Stripe customer record, created on their first checkout session.
|
|
16
|
+
*/
|
|
17
|
+
export const customers = pgTable("stripe_customers", {
|
|
18
|
+
id: uuid("id").defaultRandom().primaryKey(),
|
|
19
|
+
userId: text("user_id")
|
|
20
|
+
.notNull()
|
|
21
|
+
.unique()
|
|
22
|
+
.references(() => users.id, { onDelete: "cascade" }),
|
|
23
|
+
stripeCustomerId: text("stripe_customer_id").notNull().unique(),
|
|
24
|
+
createdAt: timestamp("created_at", { withTimezone: true })
|
|
25
|
+
.notNull()
|
|
26
|
+
.defaultNow(),
|
|
27
|
+
updatedAt: timestamp("updated_at", { withTimezone: true })
|
|
28
|
+
.notNull()
|
|
29
|
+
.defaultNow()
|
|
30
|
+
.$onUpdate(() => new Date()),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const customersRelations = relations(customers, ({ one, many }) => ({
|
|
34
|
+
user: one(users, {
|
|
35
|
+
fields: [customers.userId],
|
|
36
|
+
references: [users.id],
|
|
37
|
+
}),
|
|
38
|
+
subscriptions: many(subscriptions),
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Stripe subscriptions table.
|
|
43
|
+
*
|
|
44
|
+
* Tracks the state of each Stripe subscription. Updated via webhooks whenever
|
|
45
|
+
* Stripe fires subscription lifecycle events.
|
|
46
|
+
*/
|
|
47
|
+
export const subscriptions = pgTable("stripe_subscriptions", {
|
|
48
|
+
id: uuid("id").defaultRandom().primaryKey(),
|
|
49
|
+
customerId: uuid("customer_id")
|
|
50
|
+
.notNull()
|
|
51
|
+
.references(() => customers.id, { onDelete: "cascade" }),
|
|
52
|
+
stripeSubscriptionId: text("stripe_subscription_id").notNull().unique(),
|
|
53
|
+
status: text("status").notNull().default("incomplete"),
|
|
54
|
+
stripePriceId: text("stripe_price_id").notNull(),
|
|
55
|
+
currentPeriodStart: timestamp("current_period_start", {
|
|
56
|
+
withTimezone: true,
|
|
57
|
+
}),
|
|
58
|
+
currentPeriodEnd: timestamp("current_period_end", { withTimezone: true }),
|
|
59
|
+
cancelAtPeriodEnd: boolean("cancel_at_period_end").notNull().default(false),
|
|
60
|
+
createdAt: timestamp("created_at", { withTimezone: true })
|
|
61
|
+
.notNull()
|
|
62
|
+
.defaultNow(),
|
|
63
|
+
updatedAt: timestamp("updated_at", { withTimezone: true })
|
|
64
|
+
.notNull()
|
|
65
|
+
.defaultNow()
|
|
66
|
+
.$onUpdate(() => new Date()),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export const subscriptionsRelations = relations(subscriptions, ({ one }) => ({
|
|
70
|
+
customer: one(customers, {
|
|
71
|
+
fields: [subscriptions.customerId],
|
|
72
|
+
references: [customers.id],
|
|
73
|
+
}),
|
|
74
|
+
}));
|