aboutsummaryrefslogtreecommitdiffstats
path: root/apps/workers/trpc.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-04-27 00:02:20 +0100
committerGitHub <noreply@github.com>2025-04-27 00:02:20 +0100
commit136f126296af65f50da598d084d1485c0e40437a (patch)
tree2725c7932ebbcb9b48b5af98eb9b72329a400260 /apps/workers/trpc.ts
parentca47be7fe7be128f459c37614a04902a873fe289 (diff)
downloadkarakeep-136f126296af65f50da598d084d1485c0e40437a.tar.zst
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
Diffstat (limited to 'apps/workers/trpc.ts')
-rw-r--r--apps/workers/trpc.ts21
1 files changed, 15 insertions, 6 deletions
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<AuthedContext> {
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));
}