From 5a9ecd29b1bc6069d59fb1f45a34a532c390e60b Mon Sep 17 00:00:00 2001 From: John Yeo Date: Fri, 5 Sep 2025 15:29:23 -0700 Subject: [PATCH] merged PRs --- server/shell/g1.sh | 2 +- .../handleCreateInvoiceCheckout.ts | 13 ++- .../attach/attachUtils/getAttachFunction.ts | 4 + .../attach/checkout/handleCheckout.ts | 2 + .../internal/orgs/handlers/handleInvite.ts | 89 ------------------- server/src/internal/orgs/orgRouter.ts | 24 +---- server/src/internal/products/productUtils.ts | 28 +++--- 7 files changed, 36 insertions(+), 126 deletions(-) delete mode 100644 server/src/internal/orgs/handlers/handleInvite.ts diff --git a/server/shell/g1.sh b/server/shell/g1.sh index d03a1905c..fcebec0ca 100755 --- a/server/shell/g1.sh +++ b/server/shell/g1.sh @@ -12,7 +12,7 @@ fi $MOCHA_CMD \ 'tests/attach/basic/*.ts' \ 'tests/attach/upgrade/*.ts' \ -'tests/attach/downgrade/*.ts'\ +'tests/attach/downgrade/*.ts' \ 'tests/attach/addOn/*.ts' $MOCHA_CMD \ diff --git a/server/src/internal/customers/add-product/handleCreateInvoiceCheckout.ts b/server/src/internal/customers/add-product/handleCreateInvoiceCheckout.ts index 67b6f03a9..6ea666c62 100644 --- a/server/src/internal/customers/add-product/handleCreateInvoiceCheckout.ts +++ b/server/src/internal/customers/add-product/handleCreateInvoiceCheckout.ts @@ -8,7 +8,12 @@ import { createCheckoutMetadata } from "@/internal/metadata/metadataUtils.js"; import { isOneOff } from "@/internal/products/productUtils.js"; import { handlePaidProduct } from "../attach/attachFunctions/addProductFlow/handlePaidProduct.js"; -import { AttachBranch, AttachConfig, SuccessCode } from "@autumn/shared"; +import { + AttachBody, + AttachBranch, + AttachConfig, + SuccessCode, +} from "@autumn/shared"; import Stripe from "stripe"; import { handleOneOffFunction } from "../attach/attachFunctions/addProductFlow/handleOneOffFunction.js"; import { handleMultiAttachFlow } from "../attach/attachFunctions/multiAttach/handleMultiAttachFlow.js"; @@ -17,14 +22,16 @@ export const handleCreateInvoiceCheckout = async ({ req, res, attachParams, + attachBody, config, branch, }: { req: any; res?: any; attachParams: AttachParams; + attachBody: AttachBody; config: AttachConfig; - branch?: AttachBranch; + branch: AttachBranch; }) => { // if one off const { stripeCli } = attachParams; @@ -36,6 +43,8 @@ export const handleCreateInvoiceCheckout = async ({ req, res, attachParams, + attachBody, + branch, config, }); } else if (isOneOff(attachParams.prices)) { diff --git a/server/src/internal/customers/attach/attachUtils/getAttachFunction.ts b/server/src/internal/customers/attach/attachUtils/getAttachFunction.ts index 793813d12..1f06e5ee8 100644 --- a/server/src/internal/customers/attach/attachUtils/getAttachFunction.ts +++ b/server/src/internal/customers/attach/attachUtils/getAttachFunction.ts @@ -210,6 +210,8 @@ export const runAttachFunction = async ({ req, res, attachParams, + attachBody, + branch, config, }); } @@ -220,7 +222,9 @@ export const runAttachFunction = async ({ req, res, attachParams, + attachBody, config, + branch, }); } return await handleCreateCheckout({ diff --git a/server/src/internal/customers/attach/checkout/handleCheckout.ts b/server/src/internal/customers/attach/checkout/handleCheckout.ts index 331f288ae..4810617c3 100644 --- a/server/src/internal/customers/attach/checkout/handleCheckout.ts +++ b/server/src/internal/customers/attach/checkout/handleCheckout.ts @@ -133,6 +133,8 @@ export const handleCheckout = (req: any, res: any) => const result = await handleCreateInvoiceCheckout({ req, attachParams, + attachBody, + branch, config, }); diff --git a/server/src/internal/orgs/handlers/handleInvite.ts b/server/src/internal/orgs/handlers/handleInvite.ts deleted file mode 100644 index ff1d3e4d9..000000000 --- a/server/src/internal/orgs/handlers/handleInvite.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { sendInvitationEmail } from "@/internal/emails/sendInvitationEmail.js"; -import { auth } from "@/utils/auth.js"; -import { - handleFrontendReqError, - handleRequestError, -} from "@/utils/errorUtils.js"; -import { ExtendedRequest, ExtendedResponse } from "@/utils/models/Request.js"; -import { user, orgJoinRequests, member } from "@autumn/shared"; -import { eq, and } from "drizzle-orm"; -import { Request, Response } from "express"; -import { generateId } from "@/utils/genUtils.js"; - -export const handleInvite = async ( - req: ExtendedRequest, - res: ExtendedResponse -) => { - try { - const { email, role } = req.body; - const { org, db, userId } = req; - - // const emailUser = await db.query.user.findFirst({ - // where: eq(user.email, email), - // }); - - // if (emailUser) { - // // Check if user is already a member - // const existingMember = await db.query.member.findFirst({ - // where: and( - // eq(member.organizationId, org.id), - // eq(member.userId, emailUser.id) - // ), - // }); - - // if (existingMember) { - // return res.status(400).send({ - // message: "User is already a member of this organization", - // }); - // } - - // // Check if there's already a pending join request - // const existingRequest = await db.query.orgJoinRequests.findFirst({ - // where: and( - // eq(orgJoinRequests.organizationId, org.id), - // eq(orgJoinRequests.userId, emailUser.id), - // eq(orgJoinRequests.status, "pending") - // ), - // }); - - // if (existingRequest) { - // return res.status(400).send({ - // message: "User already has a pending invitation to this organization", - // }); - // } - - // // Create a join request instead of auto-adding - // const joinRequestId = generateId("join_req"); - // const expiresAt = new Date(); - // expiresAt.setDate(expiresAt.getDate() + 7); // Expires in 7 days - - // await db.insert(orgJoinRequests).values({ - // id: joinRequestId, - // organizationId: org.id, - // userId: emailUser.id, - // inviterId: userId, - // role: role, - // status: "pending", - // createdAt: new Date(), - // updatedAt: new Date(), - // expiresAt: expiresAt, - // }); - - // res.status(200).send({ - // message: "Invitation sent to user.", - // }); - // return; - // } - - res.status(202).send({ - message: "Send invitation to user", - }); - } catch (error) { - handleFrontendReqError({ - req, - res, - error, - action: "handleInvite", - }); - } -}; diff --git a/server/src/internal/orgs/orgRouter.ts b/server/src/internal/orgs/orgRouter.ts index 3b2f2de79..8f8010592 100644 --- a/server/src/internal/orgs/orgRouter.ts +++ b/server/src/internal/orgs/orgRouter.ts @@ -1,27 +1,12 @@ import express, { Router } from "express"; -import Stripe from "stripe"; - -import RecaseError, { handleRequestError } from "@/utils/errorUtils.js"; -import { encryptData } from "@/utils/encryptUtils.js"; - -import { ErrCode } from "@/errors/errCodes.js"; - -import { - checkKeyValid, - createWebhookEndpoint, -} from "@/external/stripe/stripeOnboardingUtils.js"; - -import { OrgService } from "./OrgService.js"; -import { createStripeCli } from "@/external/stripe/utils.js"; -import { AppEnv, Organization } from "@autumn/shared"; -import { nullish } from "@/utils/genUtils.js"; -import { clearOrgCache } from "./orgUtils/clearOrgCache.js"; -import { createOrgResponse } from "./orgUtils.js"; import { handleGetOrgMembers, handleRemoveMember, } from "./handlers/handleGetOrgMembers.js"; -import { handleInvite } from "./handlers/handleInvite.js"; + +import { OrgService } from "./OrgService.js"; +import { handleRequestError } from "@/utils/errorUtils.js"; +import { createOrgResponse } from "./orgUtils.js"; import { handleGetUploadUrl } from "./handlers/handleGetUploadUrl.js"; import { handleDeleteOrg } from "./handlers/handleDeleteOrg.js"; import { handleGetInvites } from "./handlers/handleGetInvites.js"; @@ -32,7 +17,6 @@ export const orgRouter: Router = express.Router(); orgRouter.get("/members", handleGetOrgMembers); orgRouter.post("/remove-member", handleRemoveMember); orgRouter.get("/upload_url", handleGetUploadUrl); -orgRouter.post("/invite", handleInvite as any); orgRouter.get("/invites", handleGetInvites as any); orgRouter.delete("", handleDeleteOrg as any); diff --git a/server/src/internal/products/productUtils.ts b/server/src/internal/products/productUtils.ts index cb751aaca..92a896b0f 100644 --- a/server/src/internal/products/productUtils.ts +++ b/server/src/internal/products/productUtils.ts @@ -465,20 +465,20 @@ export const copyProduct = async ({ }); } - await initProductInStripe({ - db, - org, - env: toEnv, - logger, - product: { - ...newProduct, - prices: newPrices, - entitlements: getEntsWithFeature({ - ents: newEntitlements, - features: toFeatures, - }), - }, - }); + // await initProductInStripe({ + // db, + // org, + // env: toEnv, + // logger, + // product: { + // ...newProduct, + // prices: newPrices, + // entitlements: getEntsWithFeature({ + // ents: newEntitlements, + // features: toFeatures, + // }), + // }, + // }); }; export const isOneOff = (prices: Price[]) => {