From 4a3cc100795562d0110e672c2d8451f1f0bc67bf Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Tue, 25 Jun 2024 13:41:01 +0100 Subject: [PATCH] Use pnpm linked billing package during development --- .../components/billing/PricingCalculator.tsx | 2 +- .../app/components/billing/PricingTiers.tsx | 2 +- .../billing/RunsVolumeDiscountTable.tsx | 2 +- .../app/presenters/OrgBillingPlanPresenter.ts | 2 +- .../app/presenters/OrgUsagePresenter.server.ts | 4 ++-- .../route.tsx | 2 +- .../_app.orgs.$organizationSlug/route.tsx | 2 +- .../route.tsx | 17 ++++++++--------- .../resources.$organizationSlug.subscribe.ts | 4 ++-- ...ces.$organizationSlug.subscription.portal.ts | 2 +- .../{billing.server.ts => billing.v2.server.ts} | 8 ++++++-- .../app/services/deleteOrganization.server.ts | 2 +- apps/webapp/package.json | 4 ++-- pnpm-lock.yaml | 10 ++-------- 14 files changed, 30 insertions(+), 33 deletions(-) rename apps/webapp/app/services/{billing.server.ts => billing.v2.server.ts} (96%) diff --git a/apps/webapp/app/components/billing/PricingCalculator.tsx b/apps/webapp/app/components/billing/PricingCalculator.tsx index daca65a2e..c82c6533c 100644 --- a/apps/webapp/app/components/billing/PricingCalculator.tsx +++ b/apps/webapp/app/components/billing/PricingCalculator.tsx @@ -1,5 +1,5 @@ import * as Slider from "@radix-ui/react-slider"; -import { Plans, estimate } from "@trigger.dev/billing"; +import { Plans, estimate } from "@trigger.dev/billing/v2"; import { useCallback, useState } from "react"; import { DefinitionTip } from "../DefinitionTooltip"; import { Header2 } from "../primitives/Headers"; diff --git a/apps/webapp/app/components/billing/PricingTiers.tsx b/apps/webapp/app/components/billing/PricingTiers.tsx index dfe216f43..3c401bb7e 100644 --- a/apps/webapp/app/components/billing/PricingTiers.tsx +++ b/apps/webapp/app/components/billing/PricingTiers.tsx @@ -2,7 +2,7 @@ import { useForm } from "@conform-to/react"; import { parse } from "@conform-to/zod"; import { CheckIcon, XMarkIcon } from "@heroicons/react/24/solid"; import { Form, useActionData, useNavigation } from "@remix-run/react"; -import { ActiveSubscription, Plan, Plans, SetPlanBodySchema } from "@trigger.dev/billing"; +import { ActiveSubscription, Plan, Plans, SetPlanBodySchema } from "@trigger.dev/billing/v2"; import { useState } from "react"; import { useCurrentPlan } from "~/routes/_app.orgs.$organizationSlug/route"; import { cn } from "~/utils/cn"; diff --git a/apps/webapp/app/components/billing/RunsVolumeDiscountTable.tsx b/apps/webapp/app/components/billing/RunsVolumeDiscountTable.tsx index 2bd1b4455..76a7ccf63 100644 --- a/apps/webapp/app/components/billing/RunsVolumeDiscountTable.tsx +++ b/apps/webapp/app/components/billing/RunsVolumeDiscountTable.tsx @@ -1,4 +1,4 @@ -import { RunPriceBracket } from "@trigger.dev/billing"; +import { RunPriceBracket } from "@trigger.dev/billing/v2"; import { Header2 } from "../primitives/Headers"; import { Paragraph } from "../primitives/Paragraph"; import { formatNumberCompact } from "~/utils/numberFormatter"; diff --git a/apps/webapp/app/presenters/OrgBillingPlanPresenter.ts b/apps/webapp/app/presenters/OrgBillingPlanPresenter.ts index 5404edfaa..7b3132cdb 100644 --- a/apps/webapp/app/presenters/OrgBillingPlanPresenter.ts +++ b/apps/webapp/app/presenters/OrgBillingPlanPresenter.ts @@ -1,4 +1,4 @@ -import { BillingService } from "../services/billing.server"; +import { BillingService } from "../services/billing.v2.server"; import { BasePresenter } from "./v3/basePresenter.server"; export class OrgBillingPlanPresenter extends BasePresenter { diff --git a/apps/webapp/app/presenters/OrgUsagePresenter.server.ts b/apps/webapp/app/presenters/OrgUsagePresenter.server.ts index 927ba1455..7b8abb698 100644 --- a/apps/webapp/app/presenters/OrgUsagePresenter.server.ts +++ b/apps/webapp/app/presenters/OrgUsagePresenter.server.ts @@ -1,7 +1,7 @@ -import { estimate } from "@trigger.dev/billing"; +import { estimate } from "@trigger.dev/billing/v2"; import { sqlDatabaseSchema } from "~/db.server"; import { featuresForRequest } from "~/features.server"; -import { BillingService } from "~/services/billing.server"; +import { BillingService } from "~/services/billing.v2.server"; import { BasePresenter } from "./v3/basePresenter.server"; export class OrgUsagePresenter extends BasePresenter { diff --git a/apps/webapp/app/routes/_app.orgs.$organizationSlug.billing/route.tsx b/apps/webapp/app/routes/_app.orgs.$organizationSlug.billing/route.tsx index 08852fcf3..6b76573b5 100644 --- a/apps/webapp/app/routes/_app.orgs.$organizationSlug.billing/route.tsx +++ b/apps/webapp/app/routes/_app.orgs.$organizationSlug.billing/route.tsx @@ -1,7 +1,7 @@ import { CalendarDaysIcon, ReceiptRefundIcon } from "@heroicons/react/20/solid"; import { ArrowUpCircleIcon } from "@heroicons/react/24/outline"; import { Outlet } from "@remix-run/react"; -import { ActiveSubscription } from "@trigger.dev/billing"; +import { ActiveSubscription } from "@trigger.dev/billing/v2"; import { formatDurationInDays } from "@trigger.dev/core/v3"; import { PageBody, PageContainer } from "~/components/layout/AppLayout"; import { LinkButton } from "~/components/primitives/Buttons"; diff --git a/apps/webapp/app/routes/_app.orgs.$organizationSlug/route.tsx b/apps/webapp/app/routes/_app.orgs.$organizationSlug/route.tsx index 360dc5016..874506193 100644 --- a/apps/webapp/app/routes/_app.orgs.$organizationSlug/route.tsx +++ b/apps/webapp/app/routes/_app.orgs.$organizationSlug/route.tsx @@ -10,7 +10,7 @@ import { useOptionalOrganization } from "~/hooks/useOrganizations"; import { useTypedMatchesData } from "~/hooks/useTypedMatchData"; import { useUser } from "~/hooks/useUser"; import { OrganizationsPresenter } from "~/presenters/OrganizationsPresenter.server"; -import { BillingService } from "~/services/billing.server"; +import { BillingService } from "~/services/billing.v2.server"; import { getImpersonationId } from "~/services/impersonation.server"; import { requireUserId } from "~/services/session.server"; import { telemetry } from "~/services/telemetry.server"; diff --git a/apps/webapp/app/routes/_app.orgs.$organizationSlug_.subscribed/route.tsx b/apps/webapp/app/routes/_app.orgs.$organizationSlug_.subscribed/route.tsx index c88176012..542faa3ba 100644 --- a/apps/webapp/app/routes/_app.orgs.$organizationSlug_.subscribed/route.tsx +++ b/apps/webapp/app/routes/_app.orgs.$organizationSlug_.subscribed/route.tsx @@ -1,20 +1,19 @@ import { CheckBadgeIcon } from "@heroicons/react/24/solid"; +import { LoaderFunctionArgs } from "@remix-run/server-runtime"; +import { typedjson, useTypedLoaderData } from "remix-typedjson"; import { RunsVolumeDiscountTable } from "~/components/billing/RunsVolumeDiscountTable"; import { MainCenteredContainer } from "~/components/layout/AppLayout"; import { LinkButton } from "~/components/primitives/Buttons"; import { FormButtons } from "~/components/primitives/FormButtons"; import { FormTitle } from "~/components/primitives/FormTitle"; import { Paragraph } from "~/components/primitives/Paragraph"; -import { useNewCustomerSubscribed } from "~/hooks/useNewCustomerSubscribed"; -import { useCurrentPlan } from "../_app.orgs.$organizationSlug/route"; -import { Handle } from "~/utils/handle"; -import { LoaderFunctionArgs } from "@remix-run/server-runtime"; -import { requireUserId } from "~/services/session.server"; -import { OrganizationsPresenter } from "~/presenters/OrganizationsPresenter.server"; -import { OrganizationParamsSchema } from "~/utils/pathBuilder"; -import { typedjson, useTypedLoaderData } from "remix-typedjson"; import { featuresForRequest } from "~/features.server"; -import { BillingService } from "~/services/billing.server"; +import { useNewCustomerSubscribed } from "~/hooks/useNewCustomerSubscribed"; +import { OrganizationsPresenter } from "~/presenters/OrganizationsPresenter.server"; +import { BillingService } from "~/services/billing.v2.server"; +import { requireUserId } from "~/services/session.server"; +import { Handle } from "~/utils/handle"; +import { OrganizationParamsSchema } from "~/utils/pathBuilder"; export const loader = async ({ request, params }: LoaderFunctionArgs) => { const userId = await requireUserId(request); diff --git a/apps/webapp/app/routes/resources.$organizationSlug.subscribe.ts b/apps/webapp/app/routes/resources.$organizationSlug.subscribe.ts index 28bc1f6d5..dc92131bf 100644 --- a/apps/webapp/app/routes/resources.$organizationSlug.subscribe.ts +++ b/apps/webapp/app/routes/resources.$organizationSlug.subscribe.ts @@ -1,10 +1,10 @@ import { parse } from "@conform-to/zod"; import { ActionFunctionArgs, json } from "@remix-run/server-runtime"; -import { SetPlanBodySchema } from "@trigger.dev/billing"; +import { SetPlanBodySchema } from "@trigger.dev/billing/v2"; import { redirect } from "remix-typedjson"; import { prisma } from "~/db.server"; import { redirectWithSuccessMessage } from "~/models/message.server"; -import { BillingService } from "~/services/billing.server"; +import { BillingService } from "~/services/billing.v2.server"; import { logger } from "~/services/logger.server"; import { requireUserId } from "~/services/session.server"; import { diff --git a/apps/webapp/app/routes/resources.$organizationSlug.subscription.portal.ts b/apps/webapp/app/routes/resources.$organizationSlug.subscription.portal.ts index 5f9d37fe8..ab2865221 100644 --- a/apps/webapp/app/routes/resources.$organizationSlug.subscription.portal.ts +++ b/apps/webapp/app/routes/resources.$organizationSlug.subscription.portal.ts @@ -2,7 +2,7 @@ import { ActionFunctionArgs } from "@remix-run/server-runtime"; import { redirect } from "remix-typedjson"; import { prisma } from "~/db.server"; import { redirectWithErrorMessage } from "~/models/message.server"; -import { BillingService } from "~/services/billing.server"; +import { BillingService } from "~/services/billing.v2.server"; import { requireUserId } from "~/services/session.server"; import { OrganizationParamsSchema, usagePath } from "~/utils/pathBuilder"; diff --git a/apps/webapp/app/services/billing.server.ts b/apps/webapp/app/services/billing.v2.server.ts similarity index 96% rename from apps/webapp/app/services/billing.server.ts rename to apps/webapp/app/services/billing.v2.server.ts index dbcfbe87b..7c86e6c53 100644 --- a/apps/webapp/app/services/billing.server.ts +++ b/apps/webapp/app/services/billing.v2.server.ts @@ -1,4 +1,4 @@ -import { BillingClient, SetPlanBody } from "@trigger.dev/billing"; +import { BillingClient, SetPlanBody } from "@trigger.dev/billing/v2"; import { $replica, PrismaClient, PrismaReplicaClient, prisma } from "~/db.server"; import { env } from "~/env.server"; import { logger } from "~/services/logger.server"; @@ -9,7 +9,11 @@ export class BillingService { #prismaClient: PrismaClient; #replica: PrismaReplicaClient; - constructor(isManagedCloud: boolean, prismaClient: PrismaClient = prisma, replica: PrismaReplicaClient = $replica) { + constructor( + isManagedCloud: boolean, + prismaClient: PrismaClient = prisma, + replica: PrismaReplicaClient = $replica + ) { this.#prismaClient = prismaClient; this.#replica = replica; if (isManagedCloud && process.env.BILLING_API_URL && process.env.BILLING_API_KEY) { diff --git a/apps/webapp/app/services/deleteOrganization.server.ts b/apps/webapp/app/services/deleteOrganization.server.ts index c93ac8b0d..6d749fcbf 100644 --- a/apps/webapp/app/services/deleteOrganization.server.ts +++ b/apps/webapp/app/services/deleteOrganization.server.ts @@ -2,7 +2,7 @@ import { DateFormatter } from "@internationalized/date"; import { PrismaClient } from "@trigger.dev/database"; import { prisma } from "~/db.server"; import { featuresForRequest } from "~/features.server"; -import { BillingService } from "./billing.server"; +import { BillingService } from "./billing.v2.server"; import { DeleteProjectService } from "./deleteProject.server"; export class DeleteOrganizationService { diff --git a/apps/webapp/package.json b/apps/webapp/package.json index 2aa3b84fd..703e812a3 100644 --- a/apps/webapp/package.json +++ b/apps/webapp/package.json @@ -91,7 +91,7 @@ "@tailwindcss/container-queries": "^0.1.1", "@tanstack/react-virtual": "^3.0.4", "@team-plain/typescript-sdk": "^3.5.0", - "@trigger.dev/billing": "^1.0.10", + "@trigger.dev/billing": "link:../../../cloud/packages/billing", "@trigger.dev/companyicons": "^1.5.35", "@trigger.dev/core": "workspace:*", "@trigger.dev/core-backend": "workspace:*", @@ -239,4 +239,4 @@ "engines": { "node": ">=16.0.0" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bc5476681..f3276f34e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -385,8 +385,8 @@ importers: specifier: ^3.5.0 version: 3.5.0 '@trigger.dev/billing': - specifier: ^1.0.10 - version: 1.0.10 + specifier: link:../../../cloud/packages/billing + version: link:../../../cloud/packages/billing '@trigger.dev/companyicons': specifier: ^1.5.35 version: 1.5.35(react-dom@18.2.0)(react@18.2.0) @@ -15436,12 +15436,6 @@ packages: - supports-color dev: false - /@trigger.dev/billing@1.0.10: - resolution: {integrity: sha512-vkPd1UD0fRji4qFP+s2pP26oztYzyQezQqT4+12I/5+7pOKFbOr2j0tVZj/sf7BTWgRE1Ybsk4CKT0gc9yXfKA==} - dependencies: - zod: 3.22.3 - dev: false - /@trigger.dev/companyicons@1.5.35(react-dom@18.2.0)(react@18.2.0): resolution: {integrity: sha512-AhY7yshwh0onlgB6EGiyjyLSzl38Cuxo4tpUJVHxs5im8gDA+fuUq7o6Vz1WetFeNXwjMqh3f+bPW7bfqR4epg==} peerDependencies: