Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: add novu workflows

Brad Barbin9e9829038d54
diff --git a/apps/carbon/app/components/Layout/Topbar/Notifications.tsx b/apps/carbon/app/components/Layout/Topbar/Notifications.tsx
index a82c2da12e..96d9d2f5c5 100644
--- a/apps/carbon/app/components/Layout/Topbar/Notifications.tsx
+++ b/apps/carbon/app/components/Layout/Topbar/Notifications.tsx
@@ -16,13 +16,21 @@ import {
import { formatTimeAgo } from "@carbon/utils";
import { Link } from "@remix-run/react";
import { useEffect, useState } from "react";
-import { LuBell, LuHammer, LuInbox, LuMailCheck } from "react-icons/lu";
+import {
+ LuBell,
+ LuDollarSign,
+ LuHammer,
+ LuInbox,
+ LuMailCheck,
+} from "react-icons/lu";
import {
RiProgress2Line,
RiProgress4Line,
RiProgress8Line,
} from "react-icons/ri";
import { useNotifications, useUser } from "~/hooks";
+import { usePeople } from "~/stores";
+import { path } from "~/utils/path";
function EmptyState({ description }: { description: string }) {
return (
@@ -41,15 +49,27 @@ function Notification({
description,
createdAt,
markMessageAsRead,
+ from,
onClose,
}: {
icon: React.ReactNode;
to: string;
description: string;
createdAt: string;
+ from?: string;
markMessageAsRead?: () => void;
onClose: () => void;
}) {
+ const { id: userId } = useUser();
+ const [people] = usePeople();
+ let byUser = "";
+ if (from) {
+ if (from === userId) {
+ byUser = "yourself";
+ } else {
+ byUser = people.find((p) => p.id === from)?.name ?? "";
+ }
+ }
return (
<div className="flex items-between justify-between gap-x-4 px-3 py-3 hover:bg-secondary">
<Link
@@ -63,7 +83,9 @@ function Notification({
</div>
</div>
<div>
- <p className="text-sm">{description}</p>
+ <p className="text-sm">
+ {description} {byUser && <span>by {byUser}</span>}
+ </p>
<span className="text-xs text-muted-foreground">
{formatTimeAgo(createdAt)}
</span>
@@ -85,6 +107,7 @@ function Notification({
}
function GenericNotification({
+ id,
event,
...props
}: {
@@ -92,18 +115,51 @@ function GenericNotification({
createdAt: string;
description: string;
event: NotificationEvent;
+ from?: string;
markMessageAsRead?: () => void;
onClose: () => void;
}) {
switch (event) {
case NotificationEvent.SalesRfqAssignment:
- return <Notification icon={<RiProgress2Line />} to="#" {...props} />;
+ return (
+ <Notification
+ icon={<RiProgress2Line />}
+ to={path.to.salesRfq(id)}
+ {...props}
+ />
+ );
case NotificationEvent.QuoteAssignment:
- return <Notification icon={<RiProgress4Line />} to="#" {...props} />;
+ return (
+ <Notification
+ icon={<RiProgress4Line />}
+ to={path.to.quoteDetails(id)}
+ {...props}
+ />
+ );
case NotificationEvent.SalesOrderAssignment:
- return <Notification icon={<RiProgress8Line />} to="#" {...props} />;
+ return (
+ <Notification
+ icon={<RiProgress8Line />}
+ to={path.to.salesOrderDetails(id)}
+ {...props}
+ />
+ );
case NotificationEvent.JobAssignment:
- return <Notification icon={<LuHammer />} to="#" {...props} />;
+ return (
+ <Notification
+ icon={<LuHammer />}
+ to={path.to.jobDetails(id)}
+ {...props}
+ />
+ );
+ case NotificationEvent.DigitalQuoteResponse:
+ return (
+ <Notification
+ icon={<LuDollarSign />}
+ to={path.to.quoteDetails(id)}
+ {...props}
+ />
+ );
default:
return null;
}
@@ -160,7 +216,7 @@ const Notifications = () => {
sideOffset={10}
>
<Tabs defaultValue="inbox">
- <TabsList className="w-full border-b-[1px] py-6 rounded-none">
+ <TabsList className="w-full border-b-[1px] py-6 rounded-none bg-muted/[0.5]">
<TabsTrigger value="inbox" className="font-normal">
Inbox
</TabsTrigger>
@@ -199,6 +255,7 @@ const Notifications = () => {
createdAt={notification.createdAt}
description={notification.payload.description as string}
event={notification.payload.event as NotificationEvent}
+ from={notification.payload.from as string | undefined}
markMessageAsRead={() =>
markMessageAsRead(notification._id)
}
@@ -239,6 +296,7 @@ const Notifications = () => {
createdAt={notification.createdAt}
description={notification.payload.description as string}
event={notification.payload.event as NotificationEvent}
+ from={notification.payload.from as string | undefined}
onClose={() => setOpen(false)}
/>
);
diff --git a/apps/carbon/app/components/Layout/Topbar/Topbar.tsx b/apps/carbon/app/components/Layout/Topbar/Topbar.tsx
index dbe5c228c5..80b14d2758 100644
--- a/apps/carbon/app/components/Layout/Topbar/Topbar.tsx
+++ b/apps/carbon/app/components/Layout/Topbar/Topbar.tsx
@@ -1,5 +1,5 @@
import { HStack } from "@carbon/react";
-import { usePermissions } from "~/hooks";
+import { usePermissions, useUser } from "~/hooks";
import AvatarMenu from "../../AvatarMenu";
import Breadcrumbs from "./Breadcrumbs";
import CreateMenu from "./CreateMenu";
@@ -9,6 +9,8 @@ import Search from "./Search";
const Topbar = () => {
const permissions = usePermissions();
+ const user = useUser();
+
return (
<div className="flex bg-background text-foreground border-b border-border px-4 top-0 sticky z-10 space-x-4 justify-between items-center">
<Breadcrumbs />
@@ -17,7 +19,7 @@ const Topbar = () => {
{permissions.is("employee") ? <Search /> : <div />}
<Feedback />
<CreateMenu />
- <Notifications />
+ {user.admin === true && <Notifications />}
<AvatarMenu />
</HStack>
</div>
diff --git a/apps/carbon/app/novu/workflows.ts b/apps/carbon/app/novu/workflows.ts
new file mode 100644
index 0000000000..22a3d4d4bb
--- /dev/null
+++ b/apps/carbon/app/novu/workflows.ts
@@ -0,0 +1,81 @@
+import { NotificationEvent, NotificationType } from "@carbon/notifications";
+import { workflow } from "@novu/framework";
+import { z } from "zod";
+
+const payloadSchema = z.object({
+ recordId: z.string(),
+ description: z.string(),
+ event: z.enum([
+ NotificationEvent.SalesRfqAssignment,
+ NotificationEvent.QuoteAssignment,
+ NotificationEvent.SalesOrderAssignment,
+ NotificationEvent.JobAssignment,
+ NotificationEvent.DigitalQuoteResponse,
+ ]),
+ from: z.string().optional(),
+});
+
+export const salesRfqAssignmentWorkflow = workflow(
+ NotificationEvent.SalesRfqAssignment,
+ async ({ payload, step }) => {
+ await step.inApp(NotificationType.SalesRfqAssignmentInApp, () => ({
+ body: "New Sales RFQ Assignment",
+ payload,
+ }));
+ },
+ {
+ payloadSchema,
+ }
+);
+
+export const quoteAssignmentWorkflow = workflow(
+ NotificationEvent.QuoteAssignment,
+ async ({ payload, step }) => {
+ await step.inApp(NotificationType.QuoteAssignmentInApp, () => ({
+ body: "New Quote Assignment",
+ payload,
+ }));
+ },
+ {
+ payloadSchema,
+ }
+);
+
+export const salesOrderAssignmentWorkflow = workflow(
+ NotificationEvent.SalesOrderAssignment,
+ async ({ payload, step }) => {
+ await step.inApp(NotificationType.SalesOrderAssignmentInApp, () => ({
+ body: "New Sales Order Assignment",
+ payload,
+ }));
+ },
+ {
+ payloadSchema,
+ }
+);
+
+export const jobAssignmentWorkflow = workflow(
+ NotificationEvent.JobAssignment,
+ async ({ payload, step }) => {
+ await step.inApp(NotificationType.JobAssignmentInApp, () => ({
+ body: "New Job Assignment",
+ payload,
+ }));
+ },
+ {
+ payloadSchema,
+ }
+);
+
+export const digitalQuoteResponseWorkflow = workflow(
+ NotificationEvent.DigitalQuoteResponse,
+ async ({ payload, step }) => {
+ await step.inApp(NotificationType.DigitalQuoteResponseInApp, () => ({
+ body: "New Digital Quote Response",
+ payload,
+ }));
+ },
+ {
+ payloadSchema,
+ }
+);
diff --git a/apps/carbon/app/routes/api+/assign.ts b/apps/carbon/app/routes/api+/assign.ts
index ad2b4b3dd5..1a0031b6db 100644
--- a/apps/carbon/app/routes/api+/assign.ts
+++ b/apps/carbon/app/routes/api+/assign.ts
@@ -12,7 +12,7 @@ export const config = {
};
export async function action({ request }: ActionFunctionArgs) {
- const { client, companyId } = await requirePermissions(request, {});
+ const { client, companyId, userId } = await requirePermissions(request, {});
const formData = await request.formData();
const id = formData.get("id") as string;
@@ -29,24 +29,26 @@ export async function action({ request }: ActionFunctionArgs) {
);
}
- const notificationEvent = getNotificationEvent(table);
-
- if (notificationEvent) {
- try {
- await tasks.trigger<typeof notifyTask>("notify", {
- companyId,
- documentId: id,
- event: notificationEvent,
- recipient: {
- type: "user",
- userId: assignee,
- },
- });
- } catch (err) {
- return json(
- {},
- await flash(request, error(err, "Failed to notify user"))
- );
+ if (assignee) {
+ const notificationEvent = getNotificationEvent(table);
+ if (notificationEvent) {
+ try {
+ await tasks.trigger<typeof notifyTask>("notify", {
+ companyId,
+ documentId: id,
+ event: notificationEvent,
+ recipient: {
+ type: "user",
+ userId: assignee,
+ },
+ from: userId,
+ });
+ } catch (err) {
+ return json(
+ {},
+ await flash(request, error(err, "Failed to notify user"))
+ );
+ }
}
}
diff --git a/apps/carbon/app/routes/api+/novu.ts b/apps/carbon/app/routes/api+/novu.ts
new file mode 100644
index 0000000000..2dcc61a8e5
--- /dev/null
+++ b/apps/carbon/app/routes/api+/novu.ts
@@ -0,0 +1,20 @@
+import { serve } from "@novu/framework/remix";
+import {
+ digitalQuoteResponseWorkflow,
+ jobAssignmentWorkflow,
+ quoteAssignmentWorkflow,
+ salesOrderAssignmentWorkflow,
+ salesRfqAssignmentWorkflow,
+} from "~/novu/workflows";
+
+const handler = serve({
+ workflows: [
+ salesRfqAssignmentWorkflow,
+ quoteAssignmentWorkflow,
+ salesOrderAssignmentWorkflow,
+ jobAssignmentWorkflow,
+ digitalQuoteResponseWorkflow,
+ ],
+});
+
+export { handler as action, handler as loader };
diff --git a/apps/carbon/app/routes/api+/sales.digital-quote.$id.tsx b/apps/carbon/app/routes/api+/sales.digital-quote.$id.tsx
index 7feba36dcc..48156ebb37 100644
--- a/apps/carbon/app/routes/api+/sales.digital-quote.$id.tsx
+++ b/apps/carbon/app/routes/api+/sales.digital-quote.$id.tsx
@@ -43,6 +43,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
const quote = await getQuoteByExternalId(serviceRole, id);
if (quote.error) {
+ console.error("Quote not found", quote.error);
return json({
success: false,
message: "Quote not found",
@@ -60,6 +61,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
]);
if (convert.error) {
+ console.error("Failed to convert quote to order", convert.error);
return json({
success: false,
message: "Failed to convert quote to order",
@@ -67,17 +69,24 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
if (company.error) {
+ console.error("Failed to get company", company.error);
return json({
success: false,
message: "Failed to send notification",
});
}
+ console.log(
+ digitalQuoteAcceptedBy,
+ "notificationGroup: ",
+ company.data?.digitalQuoteNotificationGroup
+ );
+
if (company.data?.digitalQuoteNotificationGroup?.length) {
try {
await tasks.trigger<typeof notifyTask>("notify", {
companyId: company.data.id,
- documentId: id,
+ documentId: quote.data.id,
event: NotificationEvent.DigitalQuoteResponse,
recipient: {
type: "group",
@@ -85,6 +94,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
},
});
} catch (err) {
+ console.error("Failed to trigger notification", err);
return json({
success: false,
message: "Failed to send notification",
diff --git a/apps/carbon/app/trigger/notify.ts b/apps/carbon/app/trigger/notify.ts
index a2699ec62c..5edfd1d692 100644
--- a/apps/carbon/app/trigger/notify.ts
+++ b/apps/carbon/app/trigger/notify.ts
@@ -2,7 +2,6 @@ import { getCarbonServiceRole, NOVU_SECRET_KEY } from "@carbon/auth";
import {
getSubscriberId,
NotificationEvent,
- NotificationType,
trigger,
triggerBulk,
type TriggerPayload,
@@ -27,31 +26,10 @@ export const notifyTask = task({
type: "group";
groupIds: string[];
};
+ from?: string;
}) => {
const client = getCarbonServiceRole();
- async function getNotificationTypesFromEvent(event: NotificationEvent) {
- switch (event) {
- case NotificationEvent.SalesRfqAssignment:
- return [NotificationType.SalesRfqAssignmentInApp];
- case NotificationEvent.QuoteAssignment:
- return [NotificationType.QuoteAssignmentInApp];
- case NotificationEvent.SalesOrderAssignment:
- return [NotificationType.SalesOrderAssignmentInApp];
- case NotificationEvent.JobAssignment:
- return [NotificationType.JobAssignmentInApp];
- case NotificationEvent.DigitalQuoteResponse:
- return [NotificationType.DigitalQuoteResponseInApp];
-
- default:
- return [];
- }
- }
-
- const notificationEvents = await getNotificationTypesFromEvent(
- payload.event
- );
-
async function getDescription(type: NotificationEvent, documentId: string) {
switch (type) {
case NotificationEvent.SalesRfqAssignment:
@@ -62,10 +40,11 @@ export const notifyTask = task({
.single();
if (salesRfq.error) {
+ console.error("Failed to get salesRfq", salesRfq.error);
throw salesRfq.error;
}
- return `Sales RFQ ${salesRfq?.data?.rfqId} assigned to you`;
+ return `RFQ ${salesRfq?.data?.rfqId} assigned to you`;
case NotificationEvent.QuoteAssignment:
const quote = await client
@@ -74,6 +53,7 @@ export const notifyTask = task({
.eq("id", documentId)
.single();
if (quote.error) {
+ console.error("Failed to get quote", quote.error);
throw quote.error;
}
return `Quote ${quote?.data?.quoteId} assigned to you`;
@@ -86,6 +66,7 @@ export const notifyTask = task({
.single();
if (salesOrder.error) {
+ console.error("Failed to get salesOrder", salesOrder.error);
throw salesOrder.error;
}
@@ -99,6 +80,7 @@ export const notifyTask = task({
.single();
if (job.error) {
+ console.error("Failed to get job", job.error);
throw job.error;
}
@@ -112,6 +94,7 @@ export const notifyTask = task({
.single();
if (digitalQuote.error) {
+ console.error("Failed to get digital quote", digitalQuote.error);
throw digitalQuote.error;
}
@@ -128,6 +111,9 @@ export const notifyTask = task({
const description = await getDescription(payload.event, payload.documentId);
if (!description) {
+ console.error(
+ `No description found for notification type ${payload.event} with documentId ${payload.documentId}`
+ );
throw new Error(
`No description found for notification type ${payload.event} with documentId ${payload.documentId}`
);
@@ -141,40 +127,44 @@ export const notifyTask = task({
.single();
if (user.error) {
+ console.error("Failed to get user", user.error);
throw user.error;
}
try {
- for await (const name of notificationEvents) {
- await trigger(novu, {
- name,
- payload: {
- recordId: payload.documentId,
- description,
- event: payload.event,
- },
- user: {
- subscriberId: getSubscriberId({
- companyId: payload.companyId,
- userId: user.data.id,
- }),
- email: user.data.email,
- fullName: user.data.fullName ?? "",
- avatarUrl: user.data.avatarUrl ?? undefined,
+ await trigger(novu, {
+ workflow: payload.event,
+ payload: {
+ recordId: payload.documentId,
+ description,
+ event: payload.event,
+ from: payload.from,
+ },
+ user: {
+ subscriberId: getSubscriberId({
companyId: payload.companyId,
- },
- });
- }
+ userId: user.data.id,
+ }),
+ email: user.data.email,
+ fullName: user.data.fullName ?? "",
+ avatarUrl: user.data.avatarUrl ?? undefined,
+ companyId: payload.companyId,
+ },
+ });
} catch (error) {
console.error("Error triggering notifications");
console.error(error);
}
} else if (payload.recipient.type === "group") {
+ console.log(
+ `triggering notification for group ${payload.recipient.groupIds}`
+ );
const userIds = await client.rpc("users_for_groups", {
groups: payload.recipient.groupIds,
});
if (userIds.error) {
+ console.error("Failed to get userIds", userIds.error);
throw userIds.error;
}
@@ -183,6 +173,9 @@ export const notifyTask = task({
!Array.isArray(userIds.data) ||
userIds.data.length === 0
) {
+ console.error(
+ `No userIds found for group ${payload.recipient.groupIds}`
+ );
return;
}
@@ -192,27 +185,26 @@ export const notifyTask = task({
.in("id", [...new Set(userIds.data as string[])]);
const notificationPayloads: TriggerPayload[] =
- users.data?.flatMap((user) => {
- return notificationEvents.map((name) => ({
- name,
- payload: {
- recordId: payload.documentId,
- description,
- event: payload.event,
- link: "#",
- },
- user: {
- subscriberId: getSubscriberId({
- companyId: payload.companyId,
- userId: user.id,
- }),
- email: user.email,
- fullName: user.fullName ?? "",
- avatarUrl: user.avatarUrl ?? undefined,
+ users.data?.map((user) => ({
+ workflow: payload.event,
+ payload: {
+ recordId: payload.documentId,
+ description,
+ event: payload.event,
+ link: "#",
+ from: payload.from,
+ },
+ user: {
+ subscriberId: getSubscriberId({
companyId: payload.companyId,
- },
- }));
- }) ?? [];
+ userId: user.id,
+ }),
+ email: user.email,
+ fullName: user.fullName ?? "",
+ avatarUrl: user.avatarUrl ?? undefined,
+ companyId: payload.companyId,
+ },
+ })) ?? [];
if (notificationPayloads.length > 0) {
try {
diff --git a/apps/carbon/package.json b/apps/carbon/package.json
index 9e807456b2..243ed9076d 100644
--- a/apps/carbon/package.json
+++ b/apps/carbon/package.json
@@ -16,7 +16,8 @@
"@internationalized/date": "^3.5.2",
"@nanostores/react": "^0.7.1",
"@novu/headless": "^2.0.0",
- "@novu/node": "^2.0.0",
+ "@novu/framework": "^2.3.0",
+ "@novu/node": "^2.0.1",
"@react-aria/i18n": "^3.11.0",
"@react-email/components": "0.0.16",
"@remix-run/dev": "~2.10.2",
@@ -112,6 +113,7 @@
"dev": "run-p dev:remix dev:trigger",
"dev:remix": "remix vite:dev",
"dev:trigger": "npx --yes [email protected] dev",
+ "dev:novu": "npx novu@latest dev --port 3000",
"lint": "TIMING=1 eslint \"app/**/*.ts*\"",
"start": "remix-serve ./build/server/index.js",
"types": "tsc"
diff --git a/package-lock.json b/package-lock.json
index 96fbf41803..02d0cea63b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -46,8 +46,9 @@
"@dnd-kit/sortable": "^8.0.0",
"@internationalized/date": "^3.5.2",
"@nanostores/react": "^0.7.1",
+ "@novu/framework": "^2.3.0",
"@novu/headless": "^2.0.0",
- "@novu/node": "^2.0.0",
+ "@novu/node": "^2.0.1",
"@react-aria/i18n": "^3.11.0",
"@react-email/components": "0.0.16",
"@remix-run/dev": "~2.10.2",
@@ -2370,6 +2371,14 @@
"url": "https://github.com/sponsors/nzakas"
}
},
+ "node_modules/@humanwhocodes/momoa": {
+ "version": "2.0.4",
+ "resolved": "https://registry.npmjs.org/@humanwhocodes/momoa/-/momoa-2.0.4.tgz",
+ "integrity": "sha512-RE815I4arJFtt+FVeU1Tgp9/Xvecacji8w/V6XtXsWWH/wz/eNkNbhb+ny/+PlVZjV0rxQpRSQKNKE3lcktHEA==",
+ "engines": {
+ "node": ">=10.10.0"
+ }
+ },
"node_modules/@humanwhocodes/object-schema": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz",
@@ -3005,6 +3014,28 @@
"url": "https://opencollective.com/js-sdsl"
}
},
+ "node_modules/@jsep-plugin/assignment": {
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/@jsep-plugin/assignment/-/assignment-1.3.0.tgz",
+ "integrity": "sha512-VVgV+CXrhbMI3aSusQyclHkenWSAm95WaiKrMxRFam3JSUiIaQjoMIw2sEs/OX4XifnqeQUN4DYbJjlA8EfktQ==",
+ "engines": {
+ "node": ">= 10.16.0"
+ },
+ "peerDependencies": {
+ "jsep": "^0.4.0||^1.0.0"
+ }
+ },
+ "node_modules/@jsep-plugin/regex": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/@jsep-plugin/regex/-/regex-1.0.4.tgz",
+ "integrity": "sha512-q7qL4Mgjs1vByCaTnDFcBnV9HS7GVPJX5vyVoCgZHNSC9rjwIlmbXG5sUuorR5ndfHAIlJ8pVStxvjXHbNvtUg==",
+ "engines": {
+ "node": ">= 10.16.0"
+ },
+ "peerDependencies": {
+ "jsep": "^0.4.0||^1.0.0"
+ }
+ },
"node_modules/@jspm/core": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@jspm/core/-/core-2.1.0.tgz",
@@ -3468,6 +3499,121 @@
"node": ">=10"
}
},
+ "node_modules/@novu/framework": {
+ "version": "2.3.0",
+ "resolved": "https://registry.npmjs.org/@novu/framework/-/framework-2.3.0.tgz",
+ "integrity": "sha512-Get/kAeiCIa7RGax3zRJqIEEfvctCUH0z1UXDMTSeefyYxphrnGA6/QQg54SES1GNtETYK/U4OGCkIT2A2NCtg==",
+ "dependencies": {
+ "@novu/shared": "^2.1.1",
+ "ajv": "^8.12.0",
+ "ajv-formats": "^2.1.1",
+ "better-ajv-errors": "^1.2.0",
+ "chalk": "^4.1.2",
+ "cross-fetch": "^4.0.0",
+ "json-schema-faker": "^0.5.6",
+ "json-schema-to-ts": "^3.0.0",
+ "liquidjs": "^10.13.1",
+ "ora": "^5.4.1",
+ "sanitize-html": "^2.13.0"
+ },
+ "peerDependencies": {
+ "@nestjs/common": ">=10.0.0",
+ "@sveltejs/kit": ">=1.27.3",
+ "@vercel/node": ">=2.15.9",
+ "aws-lambda": ">=1.0.7",
+ "express": ">=4.19.2",
+ "h3": ">=1.8.1",
+ "next": ">=12.0.0",
+ "zod": ">=3.0.0",
+ "zod-to-json-schema": ">=3.0.0"
+ },
+ "peerDependenciesMeta": {
+ "@nestjs/common": {
+ "optional": true
+ },
+ "@sveltejs/kit": {
+ "optional": true
+ },
+ "@vercel/node": {
+ "optional": true
+ },
+ "aws-lambda": {
+ "optional": true
+ },
+ "express": {
+ "optional": true
+ },
+ "fastify": {
+ "optional": true
+ },
+ "h3": {
+ "optional": true
+ },
+ "next": {
+ "optional": true
+ },
+ "zod": {
+ "optional": true
+ },
+ "zod-to-json-schema": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/@novu/framework/node_modules/ajv": {
+ "version": "8.17.1",
+ "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz",
+ "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==",
+ "dependencies": {
+ "fast-deep-equal": "^3.1.3",
+ "fast-uri": "^3.0.1",
+ "json-schema-traverse": "^1.0.0",
+ "require-from-string": "^2.0.2"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/epoberezkin"
+ }
+ },
+ "node_modules/@novu/framework/node_modules/cross-fetch": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-4.0.0.tgz",
+ "integrity": "sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==",
+ "dependencies": {
+ "node-fetch": "^2.6.12"
+ }
+ },
+ "node_modules/@novu/framework/node_modules/json-schema-to-ts": {
+ "version": "3.1.1",
+ "resolved": "https://registry.npmjs.org/json-schema-to-ts/-/json-schema-to-ts-3.1.1.tgz",
+ "integrity": "sha512-+DWg8jCJG2TEnpy7kOm/7/AxaYoaRbjVB4LFZLySZlWn8exGs3A4OLJR966cVvU26N7X9TWxl+Jsw7dzAqKT6g==",
+ "dependencies": {
+ "@babel/runtime": "^7.18.3",
+ "ts-algebra": "^2.0.0"
+ },
+ "engines": {
+ "node": ">=16"
+ }
+ },
+ "node_modules/@novu/framework/node_modules/node-fetch": {
+ "version": "2.7.0",
+ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
+ "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
+ "dependencies": {
+ "whatwg-url": "^5.0.0"
+ },
+ "engines": {
+ "node": "4.x || >=6.0.0"
+ },
+ "peerDependencies": {
+ "encoding": "^0.1.0"
+ },
+ "peerDependenciesMeta": {
+ "encoding": {
+ "optional": true
+ }
+ }
+ },
"node_modules/@novu/headless": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@novu/headless/-/headless-2.0.0.tgz",
@@ -11962,6 +12108,22 @@
"url": "https://github.com/sponsors/epoberezkin"
}
},
+ "node_modules/ajv-formats": {
+ "version": "2.1.1",
+ "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz",
+ "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==",
+ "dependencies": {
+ "ajv": "^8.0.0"
+ },
+ "peerDependencies": {
+ "ajv": "^8.0.0"
+ },
+ "peerDependenciesMeta": {
+ "ajv": {
+ "optional": true
+ }
+ }
+ },
"node_modules/ansi-align": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz",
@@ -12627,6 +12789,24 @@
"node": ">=10.0.0"
}
},
+ "node_modules/better-ajv-errors": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/better-ajv-errors/-/better-ajv-errors-1.2.0.tgz",
+ "integrity": "sha512-UW+IsFycygIo7bclP9h5ugkNH8EjCSgqyFB/yQ4Hqqa1OEYDtb0uFIkYE0b6+CjkgJYVM5UKI/pJPxjYe9EZlA==",
+ "dependencies": {
+ "@babel/code-frame": "^7.16.0",
+ "@humanwhocodes/momoa": "^2.0.2",
+ "chalk": "^4.1.2",
+ "jsonpointer": "^5.0.0",
+ "leven": "^3.1.0 < 4"
+ },
+ "engines": {
+ "node": ">= 12.13.0"
+ },
+ "peerDependencies": {
+ "ajv": "4.11.8 - 8"
+ }
+ },
"node_modules/bidi-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/bidi-js/-/bidi-js-1.0.3.tgz",
@@ -13038,6 +13218,11 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/call-me-maybe": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/call-me-maybe/-/call-me-maybe-1.0.2.tgz",
+ "integrity": "sha512-HpX65o1Hnr9HH25ojC1YGs7HCQLq0GCOibSaWER0eNpgJ/Z1MZv2mTc7+xh6WOPxbRVcmgbv4hGU+uSQ/2xFZQ=="
+ },
"node_modules/callsites": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz",
@@ -16840,6 +17025,11 @@
"integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==",
"peer": true
},
+ "node_modules/fast-uri": {
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.0.3.tgz",
+ "integrity": "sha512-aLrHthzCjH5He4Z2H9YZ+v6Ujb9ocRuW6ZzkJQOrTxleEijANq4v1TsaPaVG1PZcuurEzrLcWRyYBYXD5cEiaw=="
+ },
"node_modules/fastq": {
"version": "1.17.1",
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz",
@@ -17179,6 +17369,11 @@
"node": ">=0.4.x"
}
},
+ "node_modules/format-util": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/format-util/-/format-util-1.0.5.tgz",
+ "integrity": "sha512-varLbTj0e0yVyRpqQhuWV+8hlePAgaoFRhNFj50BNjEIrw1/DphHSObtqwskVCPWNgzwPoQrZAbfa/SBiicNeg=="
+ },
"node_modules/formdata-node": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-4.4.1.tgz",
@@ -20708,6 +20903,14 @@
"node": ">=10"
}
},
+ "node_modules/jsep": {
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/jsep/-/jsep-1.4.0.tgz",
+ "integrity": "sha512-B7qPcEVE3NVkmSJbaYxvv4cHkVW7DQsZz13pUMrfS8z8Q/BuShN+gcTXrUlPiGqM2/t/EEaI030bpxMqY8gMlw==",
+ "engines": {
+ "node": ">= 10.16.0"
+ }
+ },
"node_modules/jsesc": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.0.2.tgz",
@@ -20751,6 +20954,54 @@
"resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz",
"integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA=="
},
+ "node_modules/json-schema-faker": {
+ "version": "0.5.8",
+ "resolved": "https://registry.npmjs.org/json-schema-faker/-/json-schema-faker-0.5.8.tgz",
+ "integrity": "sha512-sqzPEbEDlpiH8U1tfmJHScXHy52onvMxITPsHyhe/jhS83g8TX6ruvRqt/ot1bXUPRsh7Ps1sWqJiBxIXmW5Xw==",
+ "dependencies": {
+ "json-schema-ref-parser": "^6.1.0",
+ "jsonpath-plus": "^10.1.0"
+ },
+ "bin": {
+ "jsf": "bin/gen.cjs"
+ }
+ },
+ "node_modules/json-schema-ref-parser": {
+ "version": "6.1.0",
+ "resolved": "https://registry.npmjs.org/json-schema-ref-parser/-/json-schema-ref-parser-6.1.0.tgz",
+ "integrity": "sha512-pXe9H1m6IgIpXmE5JSb8epilNTGsmTb2iPohAXpOdhqGFbQjNeHHsZxU+C8w6T81GZxSPFLeUoqDJmzxx5IGuw==",
+ "deprecated": "Please switch to @apidevtools/json-schema-ref-parser",
+ "dependencies": {
+ "call-me-maybe": "^1.0.1",
+ "js-yaml": "^3.12.1",
+ "ono": "^4.0.11"
+ }
+ },
+ "node_modules/json-schema-ref-parser/node_modules/argparse": {
+ "version": "1.0.10",
+ "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
+ "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
+ "dependencies": {
+ "sprintf-js": "~1.0.2"
+ }
+ },
+ "node_modules/json-schema-ref-parser/node_modules/js-yaml": {
+ "version": "3.14.1",
+ "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz",
+ "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==",
+ "dependencies": {
+ "argparse": "^1.0.7",
+ "esprima": "^4.0.0"
+ },
+ "bin": {
+ "js-yaml": "bin/js-yaml.js"
+ }
+ },
+ "node_modules/json-schema-ref-parser/node_modules/sprintf-js": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
+ "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g=="
+ },
"node_modules/json-schema-to-ts": {
"version": "1.6.4",
"resolved": "https://registry.npmjs.org/json-schema-to-ts/-/json-schema-to-ts-1.6.4.tgz",
@@ -20832,6 +21083,31 @@
"node >= 0.2.0"
]
},
+ "node_modules/jsonpath-plus": {
+ "version": "10.1.0",
+ "resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-10.1.0.tgz",
+ "integrity": "sha512-gHfV1IYqH8uJHYVTs8BJX1XKy2/rR93+f8QQi0xhx95aCiXn1ettYAd5T+7FU6wfqyDoX/wy0pm/fL3jOKJ9Lg==",
+ "dependencies": {
+ "@jsep-plugin/assignment": "^1.2.1",
+ "@jsep-plugin/regex": "^1.0.3",
+ "jsep": "^1.3.9"
+ },
+ "bin": {
+ "jsonpath": "bin/jsonpath-cli.js",
+ "jsonpath-plus": "bin/jsonpath-cli.js"
+ },
+ "engines": {
+ "node": ">=18.0.0"
+ }
+ },
+ "node_modules/jsonpointer": {
+ "version": "5.0.1",
+ "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-5.0.1.tgz",
+ "integrity": "sha512-p/nXbhSEcu3pZRdkW1OfJhpsVtW1gd4Wa1fnQc9YLiTfAjn0312eMKimbdIQzuZl9aa9xUGaRlP9T/CJE/ditQ==",
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
"node_modules/jsx-ast-utils": {
"version": "3.3.5",
"resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-3.3.5.tgz",
@@ -24548,6 +24824,14 @@
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.2.tgz",
"integrity": "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A=="
},
+ "node_modules/ono": {
+ "version": "4.0.11",
+ "resolved": "https://registry.npmjs.org/ono/-/ono-4.0.11.tgz",
+ "integrity": "sha512-jQ31cORBFE6td25deYeD80wxKBMj+zBmHTrVxnc6CKhx8gho6ipmWM5zj/oeoqioZ99yqBls9Z/9Nss7J26G2g==",
+ "dependencies": {
+ "format-util": "^1.0.3"
+ }
+ },
"node_modules/openai": {
"version": "4.67.3",
"resolved": "https://registry.npmjs.org/openai/-/openai-4.67.3.tgz",
@@ -25178,6 +25462,11 @@
"node": ">=6"
}
},
+ "node_modules/parse-srcset": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/parse-srcset/-/parse-srcset-1.0.2.tgz",
+ "integrity": "sha512-/2qh0lav6CmI15FzA3i/2Bzk2zCgQhGMkvhOhKNcBVQ1ldgpbfiNTVslmooUmWJcADi1f1kIeynbDRVzNlfR6Q=="
+ },
"node_modules/parse-svg-path": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/parse-svg-path/-/parse-svg-path-0.1.2.tgz",
@@ -28215,6 +28504,27 @@
"which": "bin/which"
}
},
+ "node_modules/sanitize-html": {
+ "version": "2.13.1",
+ "resolved": "https://registry.npmjs.org/sanitize-html/-/sanitize-html-2.13.1.tgz",
+ "integrity": "sha512-ZXtKq89oue4RP7abL9wp/9URJcqQNABB5GGJ2acW1sdO8JTVl92f4ygD7Yc9Ze09VAZhnt2zegeU0tbNsdcLYg==",
+ "dependencies": {
+ "deepmerge": "^4.2.2",
+ "escape-string-regexp": "^4.0.0",
+ "htmlparser2": "^8.0.0",
+ "is-plain-object": "^5.0.0",
+ "parse-srcset": "^1.0.2",
+ "postcss": "^8.3.11"
+ }
+ },
+ "node_modules/sanitize-html/node_modules/is-plain-object": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz",
+ "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==",
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
"node_modules/saxes": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/saxes/-/saxes-5.0.1.tgz",
@@ -30270,6 +30580,11 @@
"url": "https://github.com/sponsors/wooorm"
}
},
+ "node_modules/ts-algebra": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/ts-algebra/-/ts-algebra-2.0.0.tgz",
+ "integrity": "sha512-FPAhNPFMrkwz76P7cdjdmiShwMynZYN6SgOujD1urY4oNm80Ou9oMdmbR45LotcKOXoy7wSmHkRFE6Mxbrhefw=="
+ },
"node_modules/ts-interface-checker": {
"version": "0.1.13",
"resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz",
diff --git a/packages/notifications/src/index.ts b/packages/notifications/src/index.ts
index bb16c373b4..40f256e301 100644
--- a/packages/notifications/src/index.ts
+++ b/packages/notifications/src/index.ts
@@ -35,7 +35,7 @@ export type NotificationPayload = {
};
export type TriggerPayload = {
- name: NotificationType;
+ workflow: NotificationEvent;
payload: NotificationPayload;
user: TriggerUser;
replyTo?: string;
@@ -54,15 +54,8 @@ export function getSubscriberId({
export async function trigger(novu: Novu, data: TriggerPayload) {
try {
- await novu.trigger(data.name, {
- to: {
- ...data.user,
- // Prefix subscriber id with team id
- subscriberId: getSubscriberId({
- companyId: data.user.companyId,
- userId: data.user.subscriberId,
- }),
- },
+ await novu.trigger(data.workflow, {
+ to: data.user,
payload: data.payload,
tenant: data.tenant,
overrides: {
@@ -84,15 +77,8 @@ export async function triggerBulk(novu: Novu, events: TriggerPayload[]) {
try {
await novu.bulkTrigger(
events.map((data) => ({
- name: data.name,
- to: {
- ...data.user,
- // Prefix subscriber id with team id
- subscriberId: getSubscriberId({
- companyId: data.user.companyId,
- userId: data.user.subscriberId,
- }),
- },
+ name: data.workflow,
+ to: data.user,
payload: data.payload,
tenant: data.tenant,
overrides: {