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 --- apps/workers/trpc.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'apps/workers/trpc.ts') diff --git a/apps/workers/trpc.ts b/apps/workers/trpc.ts index 8bae287a..c5f880ad 100644 --- a/apps/workers/trpc.ts +++ b/apps/workers/trpc.ts @@ -2,15 +2,15 @@ import { eq } from "drizzle-orm"; import { db } from "@karakeep/db"; import { users } from "@karakeep/db/schema"; -import { createCallerFactory } from "@karakeep/trpc"; +import { AuthedContext, createCallerFactory } from "@karakeep/trpc"; import { appRouter } from "@karakeep/trpc/routers/_app"; /** * This is only safe to use in the context of a worker. */ -export async function buildImpersonatingTRPCClient(userId: string) { - const createCaller = createCallerFactory(appRouter); - +export async function buildImpersonatingAuthedContext( + userId: string, +): Promise { const user = await db.query.users.findFirst({ where: eq(users.id, userId), }); @@ -18,7 +18,7 @@ export async function buildImpersonatingTRPCClient(userId: string) { throw new Error("User not found"); } - return createCaller({ + return { user: { id: user.id, name: user.name, @@ -29,5 +29,14 @@ export async function buildImpersonatingTRPCClient(userId: string) { req: { ip: null, }, - }); + }; +} + +/** + * This is only safe to use in the context of a worker. + */ +export async function buildImpersonatingTRPCClient(userId: string) { + const createCaller = createCallerFactory(appRouter); + + return createCaller(await buildImpersonatingAuthedContext(userId)); } -- cgit v1.2.3-70-g09d2