Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
Merge branch 'main' into refactor/analytics
Marc Seitza42ef24af97c
diff --cc pages/api/views.tsindex e1a9da59,e68c3d26..cb534503--- a/pages/api/views.ts+++ b/pages/api/views.ts@@@ -1,7 -1,7 +1,6 @@@import { NextApiRequest, NextApiResponse } from "next";import prisma from "@/lib/prisma";import { checkPassword, log } from "@/lib/utils";- import { client } from "@/trigger";-import { trackAnalytics } from "@/lib/analytics";import { newId } from "@/lib/id-helper";import { sendVerificationEmail } from "@/lib/emails/send-email-verification";import { getFile } from "@/lib/files/get-file";@@@ -238,13 -243,45 +242,32 @@@ export default async function handleconsole.timeEnd("get-file");}- // TODO: cannot identify user because session is not available- // await identifyUser((session.user as CustomUser).id);- // await analytics.identify();- console.time("track-analytics");- await trackAnalytics({- event: "Link Viewed",- linkId: linkId,- documentId: documentId,- viewerId: newView.id,- viewerEmail: email,- });- console.timeEnd("track-analytics");-if (link.enableNotification) {- // trigger link viewed event to trigger send-notification jobconsole.time("sendemail");- await client.sendEvent({- name: "link.viewed",- payload: { viewId: newView.id },- });+ sendViewedDocumentEmail({+ ownerId: ownerId,+ documentId,+ documentName: documentName,+ viewerEmail: email,+ })+ .then((res) => {+ if (!res.success) {+ log({+ message: `Failed to send email in _/api/views_ route for linkId: ${linkId}. \n\n Error: ${res.error} \n\n*Metadata*: \`{ownerId: ${ownerId}, viewId: ${newView.id}}\``,+ type: "error",+ mention: true,+ });+ }+ })+ .catch((error) => {+ // This catch block will only be triggered if there's an uncaught exception in sendViewedDocumentEmail.+ // Given the refactored design, it's less likely to be used, but it's good practice to keep it for catching unexpected errors.+ log({+ message: `Unexpected error in _/api/views_ route for ${linkId}. \n\n Error: ${error} \n\n*Metadata*: \`{ownerId: ${ownerId}, viewId: ${newView.id}}\``,+ type: "error",+ mention: true,+ });+ });console.timeEnd("sendemail");}