merged PRs

This commit is contained in:
John Yeo
2025-09-05 15:29:23 -07:00
parent 39c06c6ddc
commit 5a9ecd29b1
7 changed files with 36 additions and 126 deletions

View File

@@ -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 \

View File

@@ -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)) {

View File

@@ -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({

View File

@@ -133,6 +133,8 @@ export const handleCheckout = (req: any, res: any) =>
const result = await handleCreateInvoiceCheckout({
req,
attachParams,
attachBody,
branch,
config,
});

View File

@@ -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",
});
}
};

View File

@@ -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);

View File

@@ -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[]) => {