fix backend service user identity forwarding
This commit is contained in:
+1
-1
@@ -12,7 +12,7 @@
|
||||
"test:curator-static": "tsx scripts/curator-static-registry.test.ts",
|
||||
"test:curator-reconcile": "tsx scripts/curator-persisted-reconcile.test.ts",
|
||||
"test:onboarding-read": "tsx scripts/onboarding-rev10-read.test.ts",
|
||||
"test:user-profile": "tsx scripts/user-profile.test.ts",
|
||||
"test:interview-user-identity": "tsx scripts/interview-user-identity.test.ts",
|
||||
"test:ws-ticket": "tsx scripts/ws-ticket.test.ts",
|
||||
"start": "node dist/index.js",
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { interviewService } from "../src/services/product-service-clients.js";
|
||||
|
||||
const originalFetch = globalThis.fetch;
|
||||
const requests: Array<{ url: string; headers: Headers; body: string }> = [];
|
||||
|
||||
globalThis.fetch = async (input, init) => {
|
||||
const request = new Request(input, init);
|
||||
requests.push({
|
||||
url: request.url,
|
||||
headers: request.headers,
|
||||
body: await request.text(),
|
||||
});
|
||||
return new Response("{}", { status: 200, headers: { "content-type": "application/json" } });
|
||||
};
|
||||
|
||||
try {
|
||||
await interviewService.configure({ user_id: "user_from_payload" }, "user_canonical");
|
||||
await interviewService.preview({ user_id: "user_from_payload" }, "user_canonical");
|
||||
await interviewService.editQuestions({ session_id: "session-1", questions: ["q1"] }, "user_canonical");
|
||||
await interviewService.approve("session-1", "user_canonical");
|
||||
|
||||
assert.equal(requests.length, 4);
|
||||
for (const request of requests) {
|
||||
assert.equal(request.headers.get("x-growqr-user"), "user_canonical");
|
||||
assert.match(request.headers.get("authorization") ?? "", /^Bearer /);
|
||||
}
|
||||
console.log("interview user identity forwarding: all assertions passed");
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
+14
-8
@@ -904,7 +904,7 @@ export function serviceRoutes(options: { skipAuth?: boolean } = {}) {
|
||||
const body = await c.req.json<JsonObject>();
|
||||
const mission = missionFromRequest(c.req.raw, body);
|
||||
const payload = await buildPersonalizedConfigurePayload(c.req.raw, body, userId);
|
||||
const result = await interviewService.configure(payload).catch(serviceErrorResponse);
|
||||
const result = await interviewService.configure(payload, userId).catch(serviceErrorResponse);
|
||||
const resultObj = result as Record<string, unknown>;
|
||||
const taskId = curatorTaskIdFromRequest(c.req.raw, body);
|
||||
const orchestration = orchestrationFromMission(mission, taskId);
|
||||
@@ -921,12 +921,15 @@ export function serviceRoutes(options: { skipAuth?: boolean } = {}) {
|
||||
app.post("/interview/preview", async (c) => {
|
||||
const body = await c.req.json<JsonObject>();
|
||||
const payload = await buildPersonalizedConfigurePayload(c.req.raw, body, c.get("userId"));
|
||||
return c.json(await interviewService.preview(payload));
|
||||
return c.json(await interviewService.preview(payload, c.get("userId")));
|
||||
});
|
||||
app.post("/interview/questions", async (c) => {
|
||||
const body = await c.req.json<{ session_id: string; questions: Array<JsonObject | string> }>();
|
||||
return c.json(await interviewService.editQuestions(body, c.get("userId")));
|
||||
});
|
||||
app.post("/interview/questions", async (c) => c.json(await interviewService.editQuestions(await c.req.json())));
|
||||
app.post("/interview/approve", async (c) => {
|
||||
const body = await c.req.json<{ session_id: string }>();
|
||||
return c.json(await interviewService.approve(body.session_id));
|
||||
return c.json(await interviewService.approve(body.session_id, c.get("userId")));
|
||||
});
|
||||
app.post("/interview/assignments", async (c) => c.json(await interviewService.createAssignments(await c.req.json())));
|
||||
app.get("/interview/assignments", async (c) => c.json(await interviewService.listAssignments(c.req.query("email") ?? "", c.req.query("status") ?? "pending", Number(c.req.query("limit") ?? 20))));
|
||||
@@ -983,7 +986,7 @@ export function serviceRoutes(options: { skipAuth?: boolean } = {}) {
|
||||
const body = await c.req.json<JsonObject>();
|
||||
const mission = missionFromRequest(c.req.raw, body);
|
||||
const payload = await buildPersonalizedRoleplayConfigurePayload(c.req.raw, body, userId);
|
||||
const result = await roleplayService.configure(payload).catch(serviceErrorResponse);
|
||||
const result = await roleplayService.configure(payload, userId).catch(serviceErrorResponse);
|
||||
const resultObj = result as Record<string, unknown>;
|
||||
const taskId = curatorTaskIdFromRequest(c.req.raw, body);
|
||||
const orchestration = orchestrationFromMission(mission, taskId);
|
||||
@@ -1000,12 +1003,15 @@ export function serviceRoutes(options: { skipAuth?: boolean } = {}) {
|
||||
app.post("/roleplay/preview", async (c) => {
|
||||
const body = await c.req.json<JsonObject>();
|
||||
const payload = await buildPersonalizedRoleplayConfigurePayload(c.req.raw, body, c.get("userId"));
|
||||
return c.json(await roleplayService.preview(payload));
|
||||
return c.json(await roleplayService.preview(payload, c.get("userId")));
|
||||
});
|
||||
app.post("/roleplay/questions", async (c) => {
|
||||
const body = await c.req.json<{ session_id: string; questions: Array<JsonObject | string> }>();
|
||||
return c.json(await roleplayService.editQuestions(body, c.get("userId")));
|
||||
});
|
||||
app.post("/roleplay/questions", async (c) => c.json(await roleplayService.editQuestions(await c.req.json())));
|
||||
app.post("/roleplay/approve", async (c) => {
|
||||
const body = await c.req.json<{ session_id: string }>();
|
||||
return c.json(await roleplayService.approve(body.session_id));
|
||||
return c.json(await roleplayService.approve(body.session_id, c.get("userId")));
|
||||
});
|
||||
app.post("/roleplay/assignments", async (c) => c.json(await roleplayService.createAssignments(await c.req.json())));
|
||||
app.get("/roleplay/assignments", async (c) => c.json(await roleplayService.listAssignments(c.req.query("email") ?? "", c.req.query("status") ?? "pending", Number(c.req.query("limit") ?? 20))));
|
||||
|
||||
@@ -60,12 +60,14 @@ export const interviewService = {
|
||||
serviceJson(config.interviewServiceUrl, `/api/v1/interviews/page-state?${new URLSearchParams({ user_id: userId })}`, {
|
||||
headers: userHeader(userId),
|
||||
}),
|
||||
configure: (payload: JsonObject) => serviceJson(config.interviewServiceUrl, "/api/v1/configure", { body: payload, timeoutMs: INTERACTIVE_SERVICE_TIMEOUT_MS }),
|
||||
preview: (payload: JsonObject) => serviceJson(config.interviewServiceUrl, "/api/v1/configure/preview", { body: payload, timeoutMs: INTERACTIVE_SERVICE_TIMEOUT_MS }),
|
||||
editQuestions: (payload: { session_id: string; questions: Array<JsonObject | string> }) =>
|
||||
serviceJson(config.interviewServiceUrl, "/api/v1/configure/questions", { body: payload, timeoutMs: INTERACTIVE_SERVICE_TIMEOUT_MS }),
|
||||
approve: (sessionId: string) =>
|
||||
serviceJson(config.interviewServiceUrl, "/api/v1/configure/approve", { body: { session_id: sessionId }, timeoutMs: INTERACTIVE_SERVICE_TIMEOUT_MS }),
|
||||
configure: (payload: JsonObject, userId?: string) =>
|
||||
serviceJson(config.interviewServiceUrl, "/api/v1/configure", { body: payload, headers: userHeader(userId), timeoutMs: INTERACTIVE_SERVICE_TIMEOUT_MS }),
|
||||
preview: (payload: JsonObject, userId?: string) =>
|
||||
serviceJson(config.interviewServiceUrl, "/api/v1/configure/preview", { body: payload, headers: userHeader(userId), timeoutMs: INTERACTIVE_SERVICE_TIMEOUT_MS }),
|
||||
editQuestions: (payload: { session_id: string; questions: Array<JsonObject | string> }, userId?: string) =>
|
||||
serviceJson(config.interviewServiceUrl, "/api/v1/configure/questions", { body: payload, headers: userHeader(userId), timeoutMs: INTERACTIVE_SERVICE_TIMEOUT_MS }),
|
||||
approve: (sessionId: string, userId?: string) =>
|
||||
serviceJson(config.interviewServiceUrl, "/api/v1/configure/approve", { body: { session_id: sessionId }, headers: userHeader(userId), timeoutMs: INTERACTIVE_SERVICE_TIMEOUT_MS }),
|
||||
createAssignments: (payload: { organization_id: string; role: string; round: "warm_up" | "behavioral" | "technical"; assignee_emails: string[] }) =>
|
||||
serviceJson(config.interviewServiceUrl, "/api/v1/interviews/assignments", { body: payload }),
|
||||
listAssignments: (email: string, status = "pending", limit = 20) =>
|
||||
@@ -107,12 +109,12 @@ export const roleplayService = {
|
||||
serviceJson(config.roleplayServiceUrl, `/api/v1/roleplays/page-state?${new URLSearchParams({ user_id: userId })}`, {
|
||||
headers: userHeader(userId),
|
||||
}),
|
||||
configure: (payload: JsonObject) => serviceJson(config.roleplayServiceUrl, "/api/v1/roleplays/configure", { body: payload, timeoutMs: INTERACTIVE_SERVICE_TIMEOUT_MS }),
|
||||
preview: (payload: JsonObject) => serviceJson(config.roleplayServiceUrl, "/api/v1/roleplays/configure/preview", { body: payload, timeoutMs: INTERACTIVE_SERVICE_TIMEOUT_MS }),
|
||||
editQuestions: (payload: { session_id: string; questions: Array<JsonObject | string> }) =>
|
||||
serviceJson(config.roleplayServiceUrl, "/api/v1/roleplays/configure/questions", { body: payload, timeoutMs: INTERACTIVE_SERVICE_TIMEOUT_MS }),
|
||||
approve: (sessionId: string) =>
|
||||
serviceJson(config.roleplayServiceUrl, "/api/v1/roleplays/configure/approve", { body: { session_id: sessionId }, timeoutMs: INTERACTIVE_SERVICE_TIMEOUT_MS }),
|
||||
configure: (payload: JsonObject, userId?: string) => serviceJson(config.roleplayServiceUrl, "/api/v1/roleplays/configure", { body: payload, headers: userHeader(userId), timeoutMs: INTERACTIVE_SERVICE_TIMEOUT_MS }),
|
||||
preview: (payload: JsonObject, userId?: string) => serviceJson(config.roleplayServiceUrl, "/api/v1/roleplays/configure/preview", { body: payload, headers: userHeader(userId), timeoutMs: INTERACTIVE_SERVICE_TIMEOUT_MS }),
|
||||
editQuestions: (payload: { session_id: string; questions: Array<JsonObject | string> }, userId?: string) =>
|
||||
serviceJson(config.roleplayServiceUrl, "/api/v1/roleplays/configure/questions", { body: payload, headers: userHeader(userId), timeoutMs: INTERACTIVE_SERVICE_TIMEOUT_MS }),
|
||||
approve: (sessionId: string, userId?: string) =>
|
||||
serviceJson(config.roleplayServiceUrl, "/api/v1/roleplays/configure/approve", { body: { session_id: sessionId }, headers: userHeader(userId), timeoutMs: INTERACTIVE_SERVICE_TIMEOUT_MS }),
|
||||
createAssignments: (payload: { organization_id: string; name: string; scenario: string; assignee_emails: string[] }) =>
|
||||
serviceJson(config.roleplayServiceUrl, "/api/v1/roleplays/assignments", { body: payload }),
|
||||
listAssignments: (email: string, status = "pending", limit = 20) =>
|
||||
|
||||
Reference in New Issue
Block a user