mcp-scraper 0.3.21 → 0.3.22

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.
@@ -23881,7 +23881,7 @@ var PACKAGE_VERSION;
23881
23881
  var init_version = __esm({
23882
23882
  "src/version.ts"() {
23883
23883
  "use strict";
23884
- PACKAGE_VERSION = "0.3.21";
23884
+ PACKAGE_VERSION = "0.3.22";
23885
23885
  }
23886
23886
  });
23887
23887
 
@@ -29280,6 +29280,61 @@ var init_server = __esm({
29280
29280
  return c.json({ error: message }, 500);
29281
29281
  }
29282
29282
  });
29283
+ app.post("/billing/subscribe/terminal-checkout", auth2, async (c) => {
29284
+ try {
29285
+ const user = c.get("user");
29286
+ const raw = await c.req.json().catch(() => ({}));
29287
+ const tier = SUBSCRIPTION_TIER_BY_KEY[String(raw.tier ?? "")];
29288
+ if (!tier) return c.json({ error: "Invalid tier. Choose starter, growth, or scale.", tiers: Object.keys(SUBSCRIPTION_TIER_BY_KEY) }, 400);
29289
+ const secret2 = process.env.STRIPE_SECRET_KEY?.trim();
29290
+ if (!secret2) return c.json({ error: "Stripe is not configured." }, 503);
29291
+ const stripeClient = new import_stripe2.default(secret2, { apiVersion: STRIPE_API_VERSION });
29292
+ let customerId = user.stripe_customer_id;
29293
+ if (!customerId) {
29294
+ const customer = await stripeClient.customers.create({ email: user.email });
29295
+ customerId = customer.id;
29296
+ await setStripeCustomerId(user.id, customerId);
29297
+ }
29298
+ if (user.subscription_id) {
29299
+ const sub = await stripeClient.subscriptions.retrieve(user.subscription_id);
29300
+ const itemId = sub.items.data[0]?.id;
29301
+ if (itemId) {
29302
+ await stripeClient.subscriptions.update(user.subscription_id, {
29303
+ items: [{ id: itemId, price: tier.price_id }],
29304
+ proration_behavior: "create_prorations"
29305
+ });
29306
+ return c.json({ updated: true, tier: tier.tier, message: `Switched to ${tier.label} (prorated). Credits and concurrency update on the next invoice.` });
29307
+ }
29308
+ }
29309
+ const session = await stripeClient.checkout.sessions.create({
29310
+ customer: customerId,
29311
+ mode: "subscription",
29312
+ line_items: [{ price: tier.price_id, quantity: 1 }],
29313
+ ...tier.intro_coupon ? { discounts: [{ coupon: tier.intro_coupon }] } : {},
29314
+ automatic_tax: { enabled: true },
29315
+ billing_address_collection: "required",
29316
+ customer_update: { address: "auto", name: "auto" },
29317
+ tax_id_collection: { enabled: true },
29318
+ success_url: `${appOrigin()}/billing?subscribed=${tier.tier}&source=terminal`,
29319
+ cancel_url: `${appOrigin()}/billing?subscribe_cancelled=1&source=terminal`
29320
+ });
29321
+ if (!session.url) return c.json({ error: "Stripe did not return a checkout URL." }, 502);
29322
+ return c.json({
29323
+ checkout_url: session.url,
29324
+ tier: tier.tier,
29325
+ label: tier.label,
29326
+ monthly_usd: tier.monthly_usd,
29327
+ credits_per_month: tier.credits_mc / 1e3,
29328
+ concurrency: tier.concurrency,
29329
+ intro: tier.intro_coupon ? "$1 first month" : null,
29330
+ next_step: "Open checkout_url in a browser to complete payment."
29331
+ });
29332
+ } catch (err) {
29333
+ const message = err instanceof Error ? err.message : "Unable to start subscription checkout.";
29334
+ console.error("[billing/subscribe/terminal-checkout]", message);
29335
+ return c.json({ error: message }, 500);
29336
+ }
29337
+ });
29283
29338
  app.post("/billing/concurrency/cancel", requireAllowedOrigin, sessionAuth, async (c) => {
29284
29339
  const user = c.get("sessionUser");
29285
29340
  if (!user.concurrency_stripe_sub_id) return c.json({ error: "No active concurrency subscription." }, 404);