From 136f126296af65f50da598d084d1485c0e40437a Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 27 Apr 2025 00:02:20 +0100 Subject: feat: Implement generic rule engine (#1318) * Add schema for the new rule engine * Add rule engine backend logic * Implement the worker logic and event firing * Implement the UI changesfor the rule engine * Ensure that when a referenced list or tag are deleted, the corresponding event/action is * Dont show smart lists in rule engine events * Add privacy validations for attached tag and list ids * Move the rules logic into a models --- packages/trpc/routers/bookmarks.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'packages/trpc/routers/bookmarks.ts') diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts index 9a1b6b0b..b9a21400 100644 --- a/packages/trpc/routers/bookmarks.ts +++ b/packages/trpc/routers/bookmarks.ts @@ -45,6 +45,7 @@ import { AssetPreprocessingQueue, LinkCrawlerQueue, OpenAIQueue, + triggerRuleEngineOnEvent, triggerSearchDeletion, triggerSearchReindex, triggerWebhook, @@ -430,6 +431,11 @@ export const bookmarksAppRouter = router({ break; } } + await triggerRuleEngineOnEvent(bookmark.id, [ + { + type: "bookmarkAdded", + }, + ]); await triggerSearchReindex(bookmark.id); await triggerWebhook(bookmark.id, "created"); return bookmark; @@ -573,6 +579,17 @@ export const bookmarksAppRouter = router({ /* includeContent: */ false, ); + if (input.favourited === true || input.archived === true) { + await triggerRuleEngineOnEvent( + input.bookmarkId, + [ + ...(input.favourited === true ? ["favourited" as const] : []), + ...(input.archived === true ? ["archived" as const] : []), + ].map((t) => ({ + type: t, + })), + ); + } // Trigger re-indexing and webhooks await triggerSearchReindex(input.bookmarkId); await triggerWebhook(input.bookmarkId, "edited"); @@ -1141,6 +1158,16 @@ export const bookmarksAppRouter = router({ ), ); + await triggerRuleEngineOnEvent(input.bookmarkId, [ + ...idsToRemove.map((t) => ({ + type: "tagRemoved" as const, + tagId: t, + })), + ...allIds.map((t) => ({ + type: "tagAdded" as const, + tagId: t, + })), + ]); await triggerSearchReindex(input.bookmarkId); await triggerWebhook(input.bookmarkId, "edited"); return { -- cgit v1.2.3-70-g09d2