Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: add logging for trials

Marc Seitz4bbaf708f2e4
diff --git a/lib/utils.ts b/lib/utils.ts
index 236a2986..7bfe616e 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -61,6 +61,32 @@ export async function fetcher<JSON = any>(
return res.json();
}
+export const logStore = async ({ object }: { object: any }) => {
+ /* If in development or env variable not set, log to the console */
+ if (
+ process.env.NODE_ENV === "development" ||
+ !process.env.PPMK_STORE_WEBHOOK_URL
+ ) {
+ console.log(object);
+ return;
+ }
+
+ try {
+ if (process.env.PPMK_STORE_WEBHOOK_URL) {
+ return await fetch(process.env.PPMK_STORE_WEBHOOK_URL, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(object),
+ });
+ }
+ } catch (e) {
+ console.error("Error logging store:", e);
+ return;
+ }
+};
+
export const log = async ({
message,
type,
diff --git a/pages/api/teams/[teamId]/datarooms/trial.ts b/pages/api/teams/[teamId]/datarooms/trial.ts
index 32835f02..aeefceb0 100644
--- a/pages/api/teams/[teamId]/datarooms/trial.ts
+++ b/pages/api/teams/[teamId]/datarooms/trial.ts
@@ -13,7 +13,7 @@ import {
sendDataroomTrialInfoEmailTask,
} from "@/lib/trigger/send-scheduled-email";
import { CustomUser } from "@/lib/types";
-import { log } from "@/lib/utils";
+import { log, logStore } from "@/lib/utils";
export const config = {
// in order to enable `waitUntil` function
@@ -83,6 +83,18 @@ export default async function handle(
mention: true,
});
+ await logStore({
+ object: {
+ teamId: teamId,
+ email: email,
+ fullName: fullName,
+ companyName: companyName,
+ useCase: useCase,
+ companySize: companySize,
+ tools: tools,
+ },
+ });
+
await prisma.team.update({
where: { id: teamId },
data: {