Skip to content

Commit b42063e

Browse files
committed
fix(insights): grant service auth website scope
1 parent 699f3d4 commit b42063e

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

apps/insights/src/generation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { AppContext } from "@databuddy/ai/config/context";
2-
import { createServiceAuth } from "@databuddy/rpc";
32
import {
43
ANTHROPIC_CACHE_1H,
54
createModelFromId,
@@ -38,6 +37,7 @@ import {
3837
} from "./persistence";
3938
import { reflectAndRank } from "./reflection";
4039
import { resolveInsightsForWebsite } from "./resolution";
40+
import { createInsightsServiceAuth } from "./service-auth";
4141
import {
4242
buildInvestigationPrompt,
4343
buildSystemPrompt,
@@ -314,7 +314,7 @@ async function runInsightsAgent(params: {
314314
timezone: params.config.timezone,
315315
currentDateTime: new Date().toISOString(),
316316
chatId: `insights:${params.organizationId}:${params.websiteId}`,
317-
serviceAuth: createServiceAuth(params.organizationId, ["read:data"]),
317+
serviceAuth: createInsightsServiceAuth(params.organizationId),
318318
};
319319

320320
const collected: ParsedInsight[] = [];
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, expect, it, mock } from "bun:test";
2+
3+
const mockCreateServiceAuth = mock((organizationId: string, scopes: string[]) => ({
4+
apiKey: { organizationId, scopes },
5+
session: null,
6+
}));
7+
8+
mock.module("@databuddy/rpc", () => ({
9+
createServiceAuth: mockCreateServiceAuth,
10+
}));
11+
12+
const { createInsightsServiceAuth, INSIGHTS_SERVICE_AUTH_SCOPES } = await import(
13+
"./service-auth"
14+
);
15+
16+
describe("createInsightsServiceAuth", () => {
17+
it("grants read data and website management scopes to insights agents", () => {
18+
const auth = createInsightsServiceAuth("org_1");
19+
20+
expect(auth.apiKey?.organizationId).toBe("org_1");
21+
expect(auth.apiKey?.scopes).toEqual(["read:data", "manage:websites"]);
22+
expect(INSIGHTS_SERVICE_AUTH_SCOPES).toEqual([
23+
"read:data",
24+
"manage:websites",
25+
]);
26+
});
27+
});

apps/insights/src/service-auth.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { createServiceAuth } from "@databuddy/rpc";
2+
3+
export const INSIGHTS_SERVICE_AUTH_SCOPES = [
4+
"read:data",
5+
"manage:websites",
6+
] as const;
7+
8+
export function createInsightsServiceAuth(organizationId: string) {
9+
return createServiceAuth(organizationId, [...INSIGHTS_SERVICE_AUTH_SCOPES]);
10+
}

0 commit comments

Comments
 (0)