mcp-twin 1.3.0 → 1.4.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/.env.example +6 -0
- package/dist/cloud/routes/billing.d.ts +7 -0
- package/dist/cloud/routes/billing.d.ts.map +1 -0
- package/dist/cloud/routes/billing.js +368 -0
- package/dist/cloud/routes/billing.js.map +1 -0
- package/dist/cloud/server.d.ts.map +1 -1
- package/dist/cloud/server.js +24 -6
- package/dist/cloud/server.js.map +1 -1
- package/dist/cloud/stripe.d.ts +60 -0
- package/dist/cloud/stripe.d.ts.map +1 -0
- package/dist/cloud/stripe.js +157 -0
- package/dist/cloud/stripe.js.map +1 -0
- package/package.json +3 -1
- package/src/cloud/routes/billing.ts +460 -0
- package/src/cloud/server.ts +26 -6
- package/src/cloud/stripe.ts +192 -0
package/.env.example
CHANGED
|
@@ -16,9 +16,15 @@ JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
|
|
|
16
16
|
CORS_ORIGIN=*
|
|
17
17
|
|
|
18
18
|
# Stripe (for billing - optional)
|
|
19
|
+
# Get keys from https://dashboard.stripe.com/apikeys
|
|
19
20
|
STRIPE_SECRET_KEY=sk_test_...
|
|
20
21
|
STRIPE_WEBHOOK_SECRET=whsec_...
|
|
21
22
|
|
|
23
|
+
# Stripe Price IDs (create in Stripe Dashboard)
|
|
24
|
+
# Products > Add Product > Add Price > Copy Price ID
|
|
25
|
+
STRIPE_PRICE_STARTER=price_starter_monthly
|
|
26
|
+
STRIPE_PRICE_PRO=price_pro_monthly
|
|
27
|
+
|
|
22
28
|
# Debug flags (optional)
|
|
23
29
|
DEBUG_SQL=false
|
|
24
30
|
DEBUG_HTTP=false
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../../../src/cloud/routes/billing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgBH,QAAA,MAAM,MAAM,4CAAW,CAAC;AAwbxB,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Billing Routes
|
|
4
|
+
* MCP Twin Cloud
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const express_1 = require("express");
|
|
8
|
+
const db_1 = require("../db");
|
|
9
|
+
const auth_1 = require("../auth");
|
|
10
|
+
const stripe_1 = require("../stripe");
|
|
11
|
+
const router = (0, express_1.Router)();
|
|
12
|
+
/**
|
|
13
|
+
* GET /api/billing/status
|
|
14
|
+
* Get billing status and current plan
|
|
15
|
+
*/
|
|
16
|
+
router.get('/status', auth_1.authenticateApiKey, async (req, res) => {
|
|
17
|
+
try {
|
|
18
|
+
if (!(0, stripe_1.isStripeConfigured)()) {
|
|
19
|
+
res.json({
|
|
20
|
+
configured: false,
|
|
21
|
+
message: 'Stripe is not configured. Set STRIPE_SECRET_KEY to enable billing.',
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const user = await (0, db_1.queryOne)('SELECT id, email, tier, stripe_customer_id, stripe_subscription_id FROM users WHERE id = $1', [req.user.id]);
|
|
26
|
+
if (!user) {
|
|
27
|
+
res.status(404).json({
|
|
28
|
+
error: { code: 'NOT_FOUND', message: 'User not found' },
|
|
29
|
+
});
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
res.json({
|
|
33
|
+
configured: true,
|
|
34
|
+
tier: user.tier,
|
|
35
|
+
hasSubscription: !!user.stripe_subscription_id,
|
|
36
|
+
customerId: user.stripe_customer_id ? `cus_...${user.stripe_customer_id.slice(-4)}` : null,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error('[Billing] Status error:', error);
|
|
41
|
+
res.status(500).json({
|
|
42
|
+
error: { code: 'INTERNAL_ERROR', message: 'Failed to get billing status' },
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* GET /api/billing/plans
|
|
48
|
+
* Get available plans
|
|
49
|
+
*/
|
|
50
|
+
router.get('/plans', async (req, res) => {
|
|
51
|
+
res.json({
|
|
52
|
+
plans: [
|
|
53
|
+
{
|
|
54
|
+
id: 'free',
|
|
55
|
+
name: 'Free',
|
|
56
|
+
price: 0,
|
|
57
|
+
interval: null,
|
|
58
|
+
features: [
|
|
59
|
+
'1 twin',
|
|
60
|
+
'10,000 requests/month',
|
|
61
|
+
'24-hour log retention',
|
|
62
|
+
'Community support',
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: 'starter',
|
|
67
|
+
name: 'Starter',
|
|
68
|
+
price: 29,
|
|
69
|
+
interval: 'month',
|
|
70
|
+
priceId: stripe_1.TIER_TO_PRICE.starter,
|
|
71
|
+
features: [
|
|
72
|
+
'5 twins',
|
|
73
|
+
'100,000 requests/month',
|
|
74
|
+
'7-day log retention',
|
|
75
|
+
'Email support',
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: 'pro',
|
|
80
|
+
name: 'Professional',
|
|
81
|
+
price: 149,
|
|
82
|
+
interval: 'month',
|
|
83
|
+
priceId: stripe_1.TIER_TO_PRICE.pro,
|
|
84
|
+
features: [
|
|
85
|
+
'Unlimited twins',
|
|
86
|
+
'1,000,000 requests/month',
|
|
87
|
+
'30-day log retention',
|
|
88
|
+
'Priority support',
|
|
89
|
+
'Custom integrations',
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
id: 'enterprise',
|
|
94
|
+
name: 'Enterprise',
|
|
95
|
+
price: null,
|
|
96
|
+
interval: null,
|
|
97
|
+
features: [
|
|
98
|
+
'Unlimited everything',
|
|
99
|
+
'90-day log retention',
|
|
100
|
+
'Dedicated support',
|
|
101
|
+
'SLA guarantee',
|
|
102
|
+
'SSO/SAML',
|
|
103
|
+
'Custom contracts',
|
|
104
|
+
],
|
|
105
|
+
contactSales: true,
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
/**
|
|
111
|
+
* POST /api/billing/checkout
|
|
112
|
+
* Create a Stripe checkout session
|
|
113
|
+
*/
|
|
114
|
+
router.post('/checkout', auth_1.authenticateApiKey, async (req, res) => {
|
|
115
|
+
try {
|
|
116
|
+
if (!(0, stripe_1.isStripeConfigured)()) {
|
|
117
|
+
res.status(400).json({
|
|
118
|
+
error: {
|
|
119
|
+
code: 'STRIPE_NOT_CONFIGURED',
|
|
120
|
+
message: 'Stripe is not configured',
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const { plan, successUrl, cancelUrl } = req.body;
|
|
126
|
+
if (!plan || !successUrl || !cancelUrl) {
|
|
127
|
+
res.status(400).json({
|
|
128
|
+
error: {
|
|
129
|
+
code: 'VALIDATION_ERROR',
|
|
130
|
+
message: 'plan, successUrl, and cancelUrl are required',
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const priceId = stripe_1.TIER_TO_PRICE[plan];
|
|
136
|
+
if (!priceId) {
|
|
137
|
+
res.status(400).json({
|
|
138
|
+
error: {
|
|
139
|
+
code: 'INVALID_PLAN',
|
|
140
|
+
message: `Invalid plan: ${plan}. Valid plans: starter, pro`,
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const user = await (0, db_1.queryOne)('SELECT id, email, stripe_customer_id FROM users WHERE id = $1', [req.user.id]);
|
|
146
|
+
if (!user) {
|
|
147
|
+
res.status(404).json({
|
|
148
|
+
error: { code: 'NOT_FOUND', message: 'User not found' },
|
|
149
|
+
});
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
// Get or create Stripe customer
|
|
153
|
+
const customerId = await (0, stripe_1.getOrCreateCustomer)(user.id, user.email, user.stripe_customer_id);
|
|
154
|
+
// Update user with customer ID if new
|
|
155
|
+
if (!user.stripe_customer_id) {
|
|
156
|
+
await (0, db_1.query)('UPDATE users SET stripe_customer_id = $1 WHERE id = $2', [customerId, user.id]);
|
|
157
|
+
}
|
|
158
|
+
// Create checkout session
|
|
159
|
+
const session = await (0, stripe_1.createCheckoutSession)(customerId, priceId, successUrl, cancelUrl);
|
|
160
|
+
res.json({
|
|
161
|
+
sessionId: session.id,
|
|
162
|
+
url: session.url,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
console.error('[Billing] Checkout error:', error);
|
|
167
|
+
res.status(500).json({
|
|
168
|
+
error: { code: 'INTERNAL_ERROR', message: 'Failed to create checkout session' },
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
/**
|
|
173
|
+
* POST /api/billing/portal
|
|
174
|
+
* Create a Stripe billing portal session
|
|
175
|
+
*/
|
|
176
|
+
router.post('/portal', auth_1.authenticateApiKey, async (req, res) => {
|
|
177
|
+
try {
|
|
178
|
+
if (!(0, stripe_1.isStripeConfigured)()) {
|
|
179
|
+
res.status(400).json({
|
|
180
|
+
error: {
|
|
181
|
+
code: 'STRIPE_NOT_CONFIGURED',
|
|
182
|
+
message: 'Stripe is not configured',
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const { returnUrl } = req.body;
|
|
188
|
+
if (!returnUrl) {
|
|
189
|
+
res.status(400).json({
|
|
190
|
+
error: {
|
|
191
|
+
code: 'VALIDATION_ERROR',
|
|
192
|
+
message: 'returnUrl is required',
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const user = await (0, db_1.queryOne)('SELECT stripe_customer_id FROM users WHERE id = $1', [req.user.id]);
|
|
198
|
+
if (!user?.stripe_customer_id) {
|
|
199
|
+
res.status(400).json({
|
|
200
|
+
error: {
|
|
201
|
+
code: 'NO_SUBSCRIPTION',
|
|
202
|
+
message: 'No billing account found. Subscribe to a plan first.',
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const session = await (0, stripe_1.createPortalSession)(user.stripe_customer_id, returnUrl);
|
|
208
|
+
res.json({
|
|
209
|
+
url: session.url,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
console.error('[Billing] Portal error:', error);
|
|
214
|
+
res.status(500).json({
|
|
215
|
+
error: { code: 'INTERNAL_ERROR', message: 'Failed to create portal session' },
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
/**
|
|
220
|
+
* GET /api/billing/invoices
|
|
221
|
+
* Get user's invoices
|
|
222
|
+
*/
|
|
223
|
+
router.get('/invoices', auth_1.authenticateApiKey, async (req, res) => {
|
|
224
|
+
try {
|
|
225
|
+
if (!(0, stripe_1.isStripeConfigured)()) {
|
|
226
|
+
res.json({ invoices: [] });
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const user = await (0, db_1.queryOne)('SELECT stripe_customer_id FROM users WHERE id = $1', [req.user.id]);
|
|
230
|
+
if (!user?.stripe_customer_id) {
|
|
231
|
+
res.json({ invoices: [] });
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const invoices = await (0, stripe_1.getInvoices)(user.stripe_customer_id);
|
|
235
|
+
res.json({
|
|
236
|
+
invoices: invoices.map((inv) => ({
|
|
237
|
+
id: inv.id,
|
|
238
|
+
number: inv.number,
|
|
239
|
+
status: inv.status,
|
|
240
|
+
amount: inv.amount_due / 100,
|
|
241
|
+
currency: inv.currency,
|
|
242
|
+
created: new Date(inv.created * 1000).toISOString(),
|
|
243
|
+
pdfUrl: inv.invoice_pdf,
|
|
244
|
+
hostedUrl: inv.hosted_invoice_url,
|
|
245
|
+
})),
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
console.error('[Billing] Invoices error:', error);
|
|
250
|
+
res.status(500).json({
|
|
251
|
+
error: { code: 'INTERNAL_ERROR', message: 'Failed to get invoices' },
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
/**
|
|
256
|
+
* POST /api/billing/webhook
|
|
257
|
+
* Handle Stripe webhooks
|
|
258
|
+
*/
|
|
259
|
+
router.post('/webhook',
|
|
260
|
+
// Use raw body for webhook signature verification
|
|
261
|
+
async (req, res) => {
|
|
262
|
+
const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET;
|
|
263
|
+
if (!webhookSecret) {
|
|
264
|
+
console.error('[Billing] STRIPE_WEBHOOK_SECRET not configured');
|
|
265
|
+
res.status(400).json({ error: 'Webhook not configured' });
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const signature = req.headers['stripe-signature'];
|
|
269
|
+
if (!signature) {
|
|
270
|
+
res.status(400).json({ error: 'Missing stripe-signature header' });
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
let event;
|
|
274
|
+
try {
|
|
275
|
+
// req.body should be raw buffer for webhook verification
|
|
276
|
+
const rawBody = req.body;
|
|
277
|
+
event = (0, stripe_1.constructWebhookEvent)(rawBody, signature, webhookSecret);
|
|
278
|
+
}
|
|
279
|
+
catch (err) {
|
|
280
|
+
console.error('[Billing] Webhook signature verification failed:', err.message);
|
|
281
|
+
res.status(400).json({ error: `Webhook Error: ${err.message}` });
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
console.log(`[Billing] Webhook received: ${event.type}`);
|
|
285
|
+
try {
|
|
286
|
+
switch (event.type) {
|
|
287
|
+
case 'checkout.session.completed': {
|
|
288
|
+
const session = event.data.object;
|
|
289
|
+
await handleCheckoutComplete(session);
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
case 'customer.subscription.created':
|
|
293
|
+
case 'customer.subscription.updated': {
|
|
294
|
+
const subscription = event.data.object;
|
|
295
|
+
await handleSubscriptionUpdate(subscription);
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
case 'customer.subscription.deleted': {
|
|
299
|
+
const subscription = event.data.object;
|
|
300
|
+
await handleSubscriptionDeleted(subscription);
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
case 'invoice.payment_failed': {
|
|
304
|
+
const invoice = event.data.object;
|
|
305
|
+
await handlePaymentFailed(invoice);
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
default:
|
|
309
|
+
console.log(`[Billing] Unhandled event type: ${event.type}`);
|
|
310
|
+
}
|
|
311
|
+
res.json({ received: true });
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
console.error('[Billing] Webhook handler error:', error);
|
|
315
|
+
res.status(500).json({ error: 'Webhook handler failed' });
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
/**
|
|
319
|
+
* Handle checkout.session.completed
|
|
320
|
+
*/
|
|
321
|
+
async function handleCheckoutComplete(session) {
|
|
322
|
+
const customerId = session.customer;
|
|
323
|
+
const subscriptionId = session.subscription;
|
|
324
|
+
console.log(`[Billing] Checkout complete for customer ${customerId}`);
|
|
325
|
+
// Update user with subscription ID
|
|
326
|
+
await (0, db_1.query)(`UPDATE users
|
|
327
|
+
SET stripe_subscription_id = $1, updated_at = NOW()
|
|
328
|
+
WHERE stripe_customer_id = $2`, [subscriptionId, customerId]);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Handle subscription created/updated
|
|
332
|
+
*/
|
|
333
|
+
async function handleSubscriptionUpdate(subscription) {
|
|
334
|
+
const customerId = subscription.customer;
|
|
335
|
+
const status = subscription.status;
|
|
336
|
+
const priceId = subscription.items.data[0]?.price?.id;
|
|
337
|
+
console.log(`[Billing] Subscription update: ${customerId} -> ${status} (${priceId})`);
|
|
338
|
+
if (status === 'active' || status === 'trialing') {
|
|
339
|
+
// Determine tier from price
|
|
340
|
+
const tier = stripe_1.PRICE_TO_TIER[priceId] || 'free';
|
|
341
|
+
await (0, db_1.query)(`UPDATE users
|
|
342
|
+
SET tier = $1, stripe_subscription_id = $2, updated_at = NOW()
|
|
343
|
+
WHERE stripe_customer_id = $3`, [tier, subscription.id, customerId]);
|
|
344
|
+
console.log(`[Billing] User upgraded to ${tier}`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Handle subscription deleted
|
|
349
|
+
*/
|
|
350
|
+
async function handleSubscriptionDeleted(subscription) {
|
|
351
|
+
const customerId = subscription.customer;
|
|
352
|
+
console.log(`[Billing] Subscription deleted for ${customerId}`);
|
|
353
|
+
// Downgrade to free tier
|
|
354
|
+
await (0, db_1.query)(`UPDATE users
|
|
355
|
+
SET tier = 'free', stripe_subscription_id = NULL, updated_at = NOW()
|
|
356
|
+
WHERE stripe_customer_id = $1`, [customerId]);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Handle payment failed
|
|
360
|
+
*/
|
|
361
|
+
async function handlePaymentFailed(invoice) {
|
|
362
|
+
const customerId = invoice.customer;
|
|
363
|
+
console.log(`[Billing] Payment failed for ${customerId}`);
|
|
364
|
+
// Could send email notification, etc.
|
|
365
|
+
// For now just log it
|
|
366
|
+
}
|
|
367
|
+
exports.default = router;
|
|
368
|
+
//# sourceMappingURL=billing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../../src/cloud/routes/billing.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,qCAAoD;AACpD,8BAAwC;AACxC,kCAAmD;AACnD,sCASmB;AAEnB,MAAM,MAAM,GAAG,IAAA,gBAAM,GAAE,CAAC;AAExB;;;GAGG;AACH,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,yBAAkB,EAAE,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,EAAE;IAC9E,IAAI,CAAC;QACH,IAAI,CAAC,IAAA,2B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|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/cloud/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/cloud/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH,QAAA,MAAM,GAAG,6CAAY,CAAC;AAkHtB,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAqCjD;AAED,eAAe,GAAG,CAAC"}
|
package/dist/cloud/server.js
CHANGED
|
@@ -17,6 +17,8 @@ const db_1 = require("./db");
|
|
|
17
17
|
const auth_1 = __importDefault(require("./routes/auth"));
|
|
18
18
|
const twins_1 = __importDefault(require("./routes/twins"));
|
|
19
19
|
const usage_1 = __importDefault(require("./routes/usage"));
|
|
20
|
+
const billing_1 = __importDefault(require("./routes/billing"));
|
|
21
|
+
const stripe_1 = require("./stripe");
|
|
20
22
|
const app = (0, express_1.default)();
|
|
21
23
|
const PORT = parseInt(process.env.PORT || '3000');
|
|
22
24
|
const HOST = process.env.HOST || '0.0.0.0';
|
|
@@ -26,6 +28,9 @@ app.use((0, cors_1.default)({
|
|
|
26
28
|
origin: process.env.CORS_ORIGIN || '*',
|
|
27
29
|
credentials: true,
|
|
28
30
|
}));
|
|
31
|
+
// Raw body for Stripe webhooks (must be before json parser)
|
|
32
|
+
app.use('/api/billing/webhook', express_1.default.raw({ type: 'application/json' }));
|
|
33
|
+
// JSON parser for all other routes
|
|
29
34
|
app.use(express_1.default.json({ limit: '10mb' }));
|
|
30
35
|
// Request logging
|
|
31
36
|
app.use((req, res, next) => {
|
|
@@ -43,14 +48,16 @@ app.get('/health', (req, res) => {
|
|
|
43
48
|
res.json({
|
|
44
49
|
status: 'healthy',
|
|
45
50
|
service: 'mcp-twin-cloud',
|
|
46
|
-
version: '1.
|
|
51
|
+
version: '1.4.0',
|
|
47
52
|
timestamp: new Date().toISOString(),
|
|
53
|
+
stripe: (0, stripe_1.isStripeConfigured)(),
|
|
48
54
|
});
|
|
49
55
|
});
|
|
50
56
|
// API Routes
|
|
51
57
|
app.use('/api/auth', auth_1.default);
|
|
52
58
|
app.use('/api/twins', twins_1.default);
|
|
53
59
|
app.use('/api/usage', usage_1.default);
|
|
60
|
+
app.use('/api/billing', billing_1.default);
|
|
54
61
|
// API documentation
|
|
55
62
|
app.get('/api', (req, res) => {
|
|
56
63
|
res.json({
|
|
@@ -85,6 +92,14 @@ app.get('/api', (req, res) => {
|
|
|
85
92
|
'GET /api/usage/history': 'Get usage history',
|
|
86
93
|
'GET /api/usage/by-twin': 'Get usage by twin',
|
|
87
94
|
},
|
|
95
|
+
billing: {
|
|
96
|
+
'GET /api/billing/status': 'Get billing status',
|
|
97
|
+
'GET /api/billing/plans': 'Get available plans',
|
|
98
|
+
'POST /api/billing/checkout': 'Create Stripe checkout session',
|
|
99
|
+
'POST /api/billing/portal': 'Create billing portal session',
|
|
100
|
+
'GET /api/billing/invoices': 'Get invoices',
|
|
101
|
+
'POST /api/billing/webhook': 'Stripe webhook endpoint',
|
|
102
|
+
},
|
|
88
103
|
},
|
|
89
104
|
});
|
|
90
105
|
});
|
|
@@ -122,11 +137,14 @@ async function startServer() {
|
|
|
122
137
|
console.log(`[Server] Listening on http://${HOST}:${PORT}`);
|
|
123
138
|
console.log('');
|
|
124
139
|
console.log('API Endpoints:');
|
|
125
|
-
console.log(` Health:
|
|
126
|
-
console.log(` Docs:
|
|
127
|
-
console.log(` Auth:
|
|
128
|
-
console.log(` Twins:
|
|
129
|
-
console.log(` Usage:
|
|
140
|
+
console.log(` Health: http://${HOST}:${PORT}/health`);
|
|
141
|
+
console.log(` Docs: http://${HOST}:${PORT}/api`);
|
|
142
|
+
console.log(` Auth: http://${HOST}:${PORT}/api/auth/*`);
|
|
143
|
+
console.log(` Twins: http://${HOST}:${PORT}/api/twins/*`);
|
|
144
|
+
console.log(` Usage: http://${HOST}:${PORT}/api/usage/*`);
|
|
145
|
+
console.log(` Billing: http://${HOST}:${PORT}/api/billing/*`);
|
|
146
|
+
console.log('');
|
|
147
|
+
console.log(`Stripe: ${(0, stripe_1.isStripeConfigured)() ? 'configured' : 'not configured (set STRIPE_SECRET_KEY)'}`);
|
|
130
148
|
console.log('');
|
|
131
149
|
console.log('─────────────────────────────────────────');
|
|
132
150
|
});
|
package/dist/cloud/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/cloud/server.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/cloud/server.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AA8HH,kCAqCC;AAjKD,sDAAmE;AACnE,gDAAwB;AACxB,oDAA4B;AAC5B,6BAAqD;AACrD,yDAAuC;AACvC,2DAAwC;AACxC,2DAAyC;AACzC,+DAA6C;AAC7C,qCAA8C;AAE9C,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;AACtB,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC;AAClD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,SAAS,CAAC;AAE3C,aAAa;AACb,GAAG,CAAC,GAAG,CAAC,IAAA,gBAAM,GAAE,CAAC,CAAC;AAClB,GAAG,CAAC,GAAG,CAAC,IAAA,cAAI,EAAC;IACX,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,GAAG;IACtC,WAAW,EAAE,IAAI;CAClB,CAAC,CAAC,CAAC;AAEJ,4DAA4D;AAC5D,GAAG,CAAC,GAAG,CAAC,sBAAsB,EAAE,iBAAO,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC,CAAC,CAAC;AAE3E,mCAAmC;AACnC,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAA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|
7
|
+
export declare function isStripeConfigured(): boolean;
|
|
8
|
+
export declare const PRICE_IDS: {
|
|
9
|
+
starter_monthly: string;
|
|
10
|
+
pro_monthly: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const PRICE_TO_TIER: Record<string, string>;
|
|
13
|
+
export declare const TIER_TO_PRICE: Record<string, string>;
|
|
14
|
+
/**
|
|
15
|
+
* Create or get Stripe customer for user
|
|
16
|
+
*/
|
|
17
|
+
export declare function getOrCreateCustomer(userId: string, email: string, existingCustomerId?: string | null): Promise<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Create a checkout session for subscription
|
|
20
|
+
*/
|
|
21
|
+
export declare function createCheckoutSession(customerId: string, priceId: string, successUrl: string, cancelUrl: string): Promise<Stripe.Checkout.Session>;
|
|
22
|
+
/**
|
|
23
|
+
* Create a billing portal session
|
|
24
|
+
*/
|
|
25
|
+
export declare function createPortalSession(customerId: string, returnUrl: string): Promise<Stripe.BillingPortal.Session>;
|
|
26
|
+
/**
|
|
27
|
+
* Get subscription details
|
|
28
|
+
*/
|
|
29
|
+
export declare function getSubscription(subscriptionId: string): Promise<Stripe.Subscription | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Cancel subscription
|
|
32
|
+
*/
|
|
33
|
+
export declare function cancelSubscription(subscriptionId: string, immediately?: boolean): Promise<Stripe.Subscription>;
|
|
34
|
+
/**
|
|
35
|
+
* Get customer's invoices
|
|
36
|
+
*/
|
|
37
|
+
export declare function getInvoices(customerId: string, limit?: number): Promise<Stripe.Invoice[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Construct webhook event from request
|
|
40
|
+
*/
|
|
41
|
+
export declare function constructWebhookEvent(payload: Buffer, signature: string, webhookSecret: string): Stripe.Event;
|
|
42
|
+
declare const _default: {
|
|
43
|
+
getStripe: typeof getStripe;
|
|
44
|
+
isStripeConfigured: typeof isStripeConfigured;
|
|
45
|
+
getOrCreateCustomer: typeof getOrCreateCustomer;
|
|
46
|
+
createCheckoutSession: typeof createCheckoutSession;
|
|
47
|
+
createPortalSession: typeof createPortalSession;
|
|
48
|
+
getSubscription: typeof getSubscription;
|
|
49
|
+
cancelSubscription: typeof cancelSubscription;
|
|
50
|
+
getInvoices: typeof getInvoices;
|
|
51
|
+
constructWebhookEvent: typeof constructWebhookEvent;
|
|
52
|
+
PRICE_IDS: {
|
|
53
|
+
starter_monthly: string;
|
|
54
|
+
pro_monthly: string;
|
|
55
|
+
};
|
|
56
|
+
PRICE_TO_TIER: Record<string, string>;
|
|
57
|
+
TIER_TO_PRICE: Record<string, string>;
|
|
58
|
+
};
|
|
59
|
+
export default _default;
|
|
60
|
+
//# sourceMappingURL=stripe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe.d.ts","sourceRoot":"","sources":["../../src/cloud/stripe.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAO5B,wBAAgB,SAAS,IAAI,MAAM,CAQlC;AAED,wBAAgB,kBAAkB,IAAI,OAAO,CAE5C;AAGD,eAAO,MAAM,SAAS;;;CAGrB,CAAC;AAGF,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAGhD,CAAC;AAGF,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAGhD,CAAC;AAEF;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,GACjC,OAAO,CAAC,MAAM,CAAC,CAejB;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAmBlC;AAED;;GAEG;AACH,wBAAsB,mBAAmB,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