Skip to content

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

feat: add waituntil for sending notifications

Marc Seitz6f3a30d8efbc
diff --git a/lib/api/notification-helper.ts b/lib/api/notification-helper.ts
index 9171d197..c9f58543 100644
--- a/lib/api/notification-helper.ts
+++ b/lib/api/notification-helper.ts
@@ -2,39 +2,39 @@ import { getTriggerClient } from "@/trigger";
import { log } from "@/lib/utils";
+// TODO: cleanup after removing trigger for this
+
export default async function sendNotification({ viewId }: { viewId: string }) {
- const client = getTriggerClient();
+ // const client = getTriggerClient();
- if (!client) {
- /** If client does not exist, use fetch to send notifications */
- return await fetch(
- `${process.env.NEXTAUTH_URL}/api/jobs/send-notification`,
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Bearer ${process.env.INTERNAL_API_KEY}`,
- },
- body: JSON.stringify({ viewId: viewId }),
- },
- )
- .then(() => {})
- .catch((error) => {
- log({
- message: `Failed to fetch notifications job in _/api/views_ route. \n\n Error: ${error} \n\n*Metadata*: \`{viewId: ${viewId}}\``,
type: "error",
- mention: true,
- });
+ // if (!client) {
+ /** If client does not exist, use fetch to send notifications */
+ return await fetch(`${process.env.NEXTAUTH_URL}/api/jobs/send-notification`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${process.env.INTERNAL_API_KEY}`,
+ },
+ body: JSON.stringify({ viewId: viewId }),
+ })
+ .then(() => {})
+ .catch((error) => {
+ log({
+ message: `Failed to fetch notifications job in _/api/views_ route. \n\n Error: ${error} \n\n*Metadata*: \`{viewId: ${viewId}}\``,
+ type: "error",
+ mention: true,
});
- }
+ });
+ // }
- /** If client exists, use trigger to send notifications */
- return await client.sendEvent({
- name: "link.viewed",
- payload: {
- viewId: viewId,
- },
- });
+ // /** If client exists, use trigger to send notifications */
+ // return await client.sendEvent({
+ // name: "link.viewed",
+ // payload: {
+ // viewId: viewId,
+ // },
+ // });
}
export async function sendViewerInvitation({
diff --git a/next.config.mjs b/next.config.mjs
index 4acb293b..f89c70dd 100644
--- a/next.config.mjs
+++ b/next.config.mjs
@@ -8,6 +8,7 @@ const nextConfig = {
},
transpilePackages: ["@trigger.dev/react"],
skipTrailingSlashRedirect: true,
+ supportsResponseStreaming: true,
experimental: {
outputFileTracingIncludes: {
"/api/mupdf/*": ["./node_modules/mupdf/lib/*.wasm"],
diff --git a/package-lock.json b/package-lock.json
index e1cd0e2f..198bec53 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -52,6 +52,7 @@
"@upstash/redis": "^1.30.1",
"@vercel/analytics": "^1.2.2",
"@vercel/blob": "^0.22.3",
+ "@vercel/functions": "^1.0.2",
"ai": "^2.2.37",
"autoprefixer": "^10.4.19",
"base-x": "^4.0.0",
@@ -5601,6 +5602,14 @@
"node": ">=4"
}
},
+ "node_modules/@vercel/functions": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/@vercel/functions/-/functions-1.0.2.tgz",
+ "integrity": "sha512-j3udyHOv/05Y8o3WQ/ANMWa1aYagsY5B3ouImiwgYsz5z4CBUHTY5dk74oQAXYr+bgoVDpdDlmxkpnxGzKEdLQ==",
+ "engines": {
+ "node": ">= 16"
+ }
+ },
"node_modules/@vue/compiler-core": {
"version": "3.3.9",
"resolved": "https://registry.npmjs.org/@vue/compiler-core/-/compiler-core-3.3.9.tgz",
diff --git a/package.json b/package.json
index 15deddd4..bcfc2dba 100644
--- a/package.json
+++ b/package.json
@@ -61,6 +61,7 @@
"@upstash/redis": "^1.30.1",
"@vercel/analytics": "^1.2.2",
"@vercel/blob": "^0.22.3",
+ "@vercel/functions": "^1.0.2",
"ai": "^2.2.37",
"autoprefixer": "^10.4.19",
"base-x": "^4.0.0",
diff --git a/pages/api/views.ts b/pages/api/views.ts
index fa9fb061..d568ce5c 100644
--- a/pages/api/views.ts
+++ b/pages/api/views.ts
@@ -1,5 +1,7 @@
import { NextApiRequest, NextApiResponse } from "next";
+import { waitUntil } from "@vercel/functions";
+
import sendNotification from "@/lib/api/notification-helper";
import { sendVerificationEmail } from "@/lib/emails/send-email-verification";
import { getFile } from "@/lib/files/get-file";
@@ -269,7 +271,7 @@ export default async function handle(
if (link.enableNotification) {
console.time("sendemail");
- await sendNotification({ viewId: newView.id });
+ waitUntil(sendNotification({ viewId: newView.id }));
console.timeEnd("sendemail");
}