Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
deps: stripe (#2756)
Thibault Le Ouay4d706078893f
diff --git a/apps/dashboard/package.json b/apps/dashboard/package.jsonindex 865d1f540..0b2fb9b73 100644--- a/apps/dashboard/package.json+++ b/apps/dashboard/package.json@@ -69,7 +69,6 @@"@radix-ui/react-slot": "catalog:","@radix-ui/react-tooltip": "catalog:","@sentry/nextjs": "catalog:",- "@stripe/stripe-js": "catalog:","@tanstack/react-query": "catalog:","@tanstack/react-table": "catalog:","@trpc/client": "catalog:",diff --git a/apps/dashboard/src/components/data-table/billing/data-table.tsx b/apps/dashboard/src/components/data-table/billing/data-table.tsxindex 5381f06c1..b33042ca3 100644--- a/apps/dashboard/src/components/data-table/billing/data-table.tsx+++ b/apps/dashboard/src/components/data-table/billing/data-table.tsx@@ -31,7 +31,6 @@ import { Fragment, useState, useTransition } from "react";import { toast } from "sonner";import { config as featureGroups, plans } from "@/data/plans";-import { getStripe } from "@/lib/stripe";import { useTRPC } from "@/lib/trpc/client";import { cn } from "@/lib/utils";@@ -70,8 +69,7 @@ export function DataTable({ restrictTo }: { restrictTo?: WorkspacePlan[] }) {return;}- const stripe = await getStripe();- stripe?.redirectToCheckout({ sessionId: data.session.id });+ if (data.session.url) window.location.assign(data.session.url);},}),);diff --git a/apps/dashboard/src/lib/stripe.ts b/apps/dashboard/src/lib/stripe.tsdeleted file mode 100644index c35ac44eb..000000000--- a/apps/dashboard/src/lib/stripe.ts+++ /dev/null@@ -1,16 +0,0 @@-import type { Stripe as StripeProps } from "@stripe/stripe-js";-import { loadStripe } from "@stripe/stripe-js";--let stripePromise: Promise<StripeProps | null>;--export const getStripe = () => {- if (!process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY) {- throw new Error("NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY is not set");- }-- if (!stripePromise) {- stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY);- }-- return stripePromise;-};diff --git a/apps/status-page/package.json b/apps/status-page/package.jsonindex fff752e1e..4431ef339 100644--- a/apps/status-page/package.json+++ b/apps/status-page/package.json@@ -46,7 +46,6 @@"@radix-ui/react-dropdown-menu": "catalog:","@radix-ui/react-hover-card": "catalog:","@sentry/nextjs": "catalog:",- "@stripe/stripe-js": "catalog:","@tanstack/react-query": "catalog:","@tanstack/react-table": "catalog:","@trpc/client": "catalog:",diff --git a/apps/web/package.json b/apps/web/package.jsonindex da4aa3ead..5e81cb080 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -44,7 +44,6 @@"@openstatus/upstash": "workspace:*","@openstatus/utils": "workspace:*","@sentry/nextjs": "catalog:",- "@stripe/stripe-js": "catalog:","@t3-oss/env-nextjs": "catalog:","@tailwindcss/container-queries": "catalog:","@tailwindcss/typography": "catalog:",diff --git a/apps/web/src/lib/stripe/client.ts b/apps/web/src/lib/stripe/client.tsdeleted file mode 100644index 8e64d21e5..000000000--- a/apps/web/src/lib/stripe/client.ts+++ /dev/null@@ -1,14 +0,0 @@-import type { Stripe as StripeProps } from "@stripe/stripe-js";-import { loadStripe } from "@stripe/stripe-js";--import { env } from "../../env";--let stripePromise: Promise<StripeProps | null>;--export const getStripe = () => {- if (!stripePromise) {- stripePromise = loadStripe(env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY);- }-- return stripePromise;-};diff --git a/packages/api/src/router/stripe/index.ts b/packages/api/src/router/stripe/index.tsindex dbc5b7caf..35c9e4433 100644--- a/packages/api/src/router/stripe/index.ts+++ b/packages/api/src/router/stripe/index.ts@@ -24,6 +24,7 @@ import { z } from "zod";import { createTRPCRouter, protectedProcedure } from "../../trpc";import {buildFromSubscriptionOrThrow,+ getCurrentPeriodEnd,getCurrentSubscription,stripe,} from "./shared";@@ -246,8 +247,8 @@ export const stripeRouter = createTRPCRouter({input: {plan: built.plan,subscriptionId: updated.id,- endsAt: new Date(updated.current_period_end * 1000),- paidUntil: new Date(updated.current_period_end * 1000),+ endsAt: getCurrentPeriodEnd(updated),+ paidUntil: getCurrentPeriodEnd(updated),limits: built.limits,reason: "plan_changed",},diff --git a/packages/api/src/router/stripe/shared.ts b/packages/api/src/router/stripe/shared.tsindex 87827819b..49ef01838 100644--- a/packages/api/src/router/stripe/shared.ts+++ b/packages/api/src/router/stripe/shared.ts@@ -5,7 +5,7 @@ import { env } from "../../env";import { buildLimitsFromSubscription } from "./utils";export const stripe = new Stripe(env.STRIPE_SECRET_KEY ?? "", {- apiVersion: "2023-08-16",+ apiVersion: "2026-08-26.dahlia",appInfo: {name: "OpenStatus",version: "0.1.0",@@ -96,6 +96,20 @@ export async function getCurrentSubscription(customerId: string) {return { live, current };}+/**+ * When the subscription's current period ends. Since API version 2025-03-31+ * the period lives on each item rather than on the subscription. Items share+ * one billing cycle here (add-ons are monthly-only and blocked on yearly+ * plans), so the latest end is the date everything is paid through.+ */+export function getCurrentPeriodEnd(subscription: Stripe.Subscription) {+ const ends = subscription.items.data.map((item) => item.current_period_end);+ if (ends.length === 0) {+ throw new Error(`Subscription ${subscription.id} has no items`);+ }+ return new Date(Math.max(...ends) * 1000);+}+/*** A customer carries exactly one subscription. `current` is the one to keep;* every subscription that predates it is a leftover that would otherwise keepdiff --git a/packages/api/src/router/stripe/webhook.test.ts b/packages/api/src/router/stripe/webhook.test.tsindex 1e4491559..43ad0145f 100644--- a/packages/api/src/router/stripe/webhook.test.ts+++ b/packages/api/src/router/stripe/webhook.test.ts@@ -30,9 +30,13 @@ const now = () => Math.floor(Date.now() / 1000);// biome-ignore lint/suspicious/noExplicitAny: stubs over the Stripe and Resend clientstype AnyStub = Stub<any>;+// `current_period_end` lives on the items since API version 2025-03-31.function subscription(customer: string,- overrides: Partial<Stripe.Subscription> = {},+ {+ current_period_end = now() + 10 * DAY,+ ...overrides+ }: Partial<Stripe.Subscription> & { current_period_end?: number } = {},) {return {id: "sub_test_1",@@ -40,9 +44,10 @@ function subscription(status: "active",created: now() - 30 * DAY,cancel_at_period_end: false,- current_period_end: now() + 10 * DAY,metadata: {},- items: { data: [{ price: { id: TEAM_PRICE }, quantity: 1 }] },+ items: {+ data: [{ price: { id: TEAM_PRICE }, quantity: 1, current_period_end }],+ },...overrides,} as unknown as Stripe.Subscription;}@@ -278,7 +283,7 @@ describe("stripe webhook emails", () => {const [reminder, reminderOptions] = send.calls[1].args;expect(new Date(reminder.scheduledAt).getTime()).toBe(- (sub.current_period_end - 3 * DAY) * 1000,+ (sub.items.data[0].current_period_end - 3 * DAY) * 1000,);expect(reminderOptions).toEqual({idempotencyKey: `stripe:${evt.event.id}:plan-ending-soon`,diff --git a/packages/api/src/router/stripe/webhook.ts b/packages/api/src/router/stripe/webhook.tsindex efae4d450..66b6bdada 100644--- a/packages/api/src/router/stripe/webhook.ts+++ b/packages/api/src/router/stripe/webhook.ts@@ -28,6 +28,7 @@ import { createTRPCRouter, publicProcedure } from "../../trpc";import {buildFromSubscriptionOrThrow,cancelSupersededSubscriptions,+ getCurrentPeriodEnd,getCurrentSubscription,isNewerSubscription,listLiveSubscriptions,@@ -109,7 +110,7 @@ async function sendCancellationEmails(args: {eventId: string;}) {const { db, ws, customerId, current, plan, eventId } = args;- const endsAt = new Date(current.current_period_end * 1000);+ const endsAt = getCurrentPeriodEnd(current);const to = await getBillingRecipients(db, ws.id, customerId);const preview = await previewWorkspaceDowngrade({ctx: {@@ -224,8 +225,8 @@ export const webhookRouter = createTRPCRouter({input: {plan: built.plan,subscriptionId: current.id,- endsAt: new Date(current.current_period_end * 1000),- paidUntil: new Date(current.current_period_end * 1000),+ endsAt: getCurrentPeriodEnd(current),+ paidUntil: getCurrentPeriodEnd(current),limits: built.limits,},});@@ -359,8 +360,8 @@ export const webhookRouter = createTRPCRouter({input: {plan: built.plan,subscriptionId: subscription.id,- endsAt: new Date(subscription.current_period_end * 1000),- paidUntil: new Date(subscription.current_period_end * 1000),+ endsAt: getCurrentPeriodEnd(subscription),+ paidUntil: getCurrentPeriodEnd(subscription),limits: built.limits,reason: "checkout_session_completed",},diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex f0c19df86..cfabae728 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -335,9 +335,6 @@ catalogs:'@slack/web-api':specifier: 7.19.0version: 7.19.0- '@stripe/stripe-js':- specifier: 2.4.0- version: 2.4.0'@t3-oss/env-core':specifier: 0.13.11version: 0.13.11@@ -615,8 +612,8 @@ catalogs:specifier: 2.0.8version: 2.0.8stripe:- specifier: 13.11.0- version: 13.11.0+ specifier: 22.6.2+ version: 22.6.2sugar-high:specifier: 0.9.5version: 0.9.5@@ -859,9 +856,6 @@ importers:'@sentry/nextjs':specifier: 'catalog:'version: 10.75.1(@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))([email protected](@babel/[email protected]([email protected]))(@opentelemetry/[email protected])(@types/[email protected])([email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected])([email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected])([email protected])([email protected](@types/[email protected])))- '@stripe/stripe-js':- specifier: 'catalog:'- version: 2.4.0'@tanstack/react-query':specifier: 'catalog:'version: 5.103.2([email protected])@@ -951,7 +945,7 @@ importers:stripe:specifier: 'catalog:'- version: 13.11.0+ version: 22.6.2(@types/[email protected])superjson:specifier: 'catalog:'version: 2.2.6@@ -1348,9 +1342,6 @@ importers:'@sentry/nextjs':specifier: 'catalog:'version: 10.75.1(@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))([email protected](@babel/[email protected]([email protected]))(@opentelemetry/[email protected])(@types/[email protected])([email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected])([email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected])([email protected])([email protected](@types/[email protected])))- '@stripe/stripe-js':- specifier: 'catalog:'- version: 2.4.0'@tanstack/react-query':specifier: 'catalog:'version: 5.103.2([email protected])@@ -1589,9 +1580,6 @@ importers:'@sentry/nextjs':specifier: 'catalog:'version: 10.75.1(@opentelemetry/[email protected](@opentelemetry/[email protected]))([email protected](@opentelemetry/[email protected])(@types/[email protected])([email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected])([email protected](@swc/[email protected])([email protected])([email protected])([email protected])([email protected](@types/[email protected])))- '@stripe/stripe-js':- specifier: 'catalog:'- version: 2.4.0'@t3-oss/env-nextjs':specifier: 'catalog:'version: 0.13.11([email protected])([email protected])@@ -1726,7 +1714,7 @@ importers:stripe:specifier: 'catalog:'- version: 13.11.0+ version: 22.6.2(@types/[email protected])sugar-high:specifier: 'catalog:'version: 0.9.5@@ -2105,7 +2093,7 @@ importers:version: 19.3.0stripe:specifier: 'catalog:'- version: 13.11.0+ version: 22.6.2(@types/[email protected])superjson:specifier: 'catalog:'version: 2.2.6@@ -7549,9 +7537,6 @@ packages:'@standard-schema/[email protected]':resolution: {integrity: sha512-e7Mew686owMaPJVNNLs55PUvgz371nKgwsc4vxE49zsODpJEnxgxRo2y/OKrqueavXgZNMDVj3DdHFlaSAeU8g==}- '@stripe/[email protected]':- resolution: {integrity: sha512-WFkQx1mbs2b5+7looI9IV1BLa3bIApuN3ehp9FP58xGg7KL9hCHDECgW3BwO9l9L+xBPVAD7Yjn1EhGe6EDTeA==}-'@swc/[email protected]':resolution: {integrity: sha512-i/j0HNbnn79qnTVPicvay92Nark8fW8NQqn1e2mGERjUXNpBV0+SwQxlRpk2zBhn6laJ8PDI6Kn1nHZhnz3LCA==}engines: {node: '>=10'}@@ -11486,9 +11471,14 @@ packages:resolution: {integrity: sha512-1tB5mhVo7U+ETBKNf92xT4hrQa3pm0MZ0PQvuDnWgAAGHDsfp4lPSpiS6psrSiet87wyGPh9ft6wmhOMQ0hDiw==}engines: {node: '>=14.16'}- resolution: {integrity: sha512-yPxVJxUzP1QHhHeFnYjJl48QwDS1+5befcL7ju7+t+i88D5r0rbsL+GkCCS6zgcU+TiV5bF9eMGcKyJfLf8BZQ==}- engines: {node: '>=12.*'}+ resolution: {integrity: sha512-PwRE2scocvXqDKPiskMa5vRJEAEkq46W69XyUYmAwrNSLr675lQnfqLwnsndAWizwgihOWw/irLmoFRo3ez7ew==}+ engines: {node: '>=18'}+ peerDependencies:+ '@types/node': '>=18'+ peerDependenciesMeta:+ '@types/node':+ optional: trueresolution: {integrity: sha512-Y0AvSwDw8y+nlSNFXMm2g6L51rBGdAQT20J3YSOqxC53Lo3bjWRtr2BKcfYoAf352WYpsZSTURrA0tqhfgudPA==}@@ -15842,8 +15832,6 @@ snapshots:'@standard-schema/[email protected]': {}- '@stripe/[email protected]': {}-'@swc/[email protected]':optional: true@@ -20310,10 +20298,9 @@ snapshots:- dependencies:+ [email protected](@types/[email protected]):+ optionalDependencies:'@types/node': 26.6.2- qs: 6.16.0dependencies:diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yamlindex 433411f74..73db75f56 100644--- a/pnpm-workspace.yaml+++ b/pnpm-workspace.yaml@@ -112,7 +112,6 @@ catalog:"@sentry/deno": 10.75.1"@sentry/nextjs": 10.75.1"@slack/web-api": 7.19.0- "@stripe/stripe-js": 2.4.0"@t3-oss/env-core": 0.13.11"@t3-oss/env-nextjs": 0.13.11"@tailwindcss/cli": 4.3.3@@ -205,7 +204,7 @@ catalog:shiki: 3.23.0slugify: 1.6.9sonner: 2.0.8- stripe: 13.11.0+ stripe: 22.6.2sugar-high: 0.9.5superjson: 2.2.6tailwind-merge: 3.7.0diff --git a/scripts/check-doc-refs.mts b/scripts/check-doc-refs.mtsindex d0c4cc77a..f5d1c6a76 100644--- a/scripts/check-doc-refs.mts+++ b/scripts/check-doc-refs.mts@@ -55,13 +55,17 @@ const FILE_LIKE = /\.[a-z0-9]+$/i;type Violation = { file: string; line: number; path: string };function trackedFiles(): string[] {- return execFileSync("git", ["ls-files", "-z"], {- cwd: REPO_ROOT,- encoding: "utf8",- maxBuffer: 64 * 1024 * 1024,- })- .split("\0")- .filter((file) => file.length > 0);+ return (+ execFileSync("git", ["ls-files", "-z"], {+ cwd: REPO_ROOT,+ encoding: "utf8",+ maxBuffer: 64 * 1024 * 1024,+ })+ .split("\0")+ // Under jj the git index lags the working copy, so it still lists files+ // deleted but not yet committed.+ .filter((file) => file.length > 0 && existsSync(join(REPO_ROOT, file)))+ );}/**