Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/backend/ipc/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export const IPC_CHANNELS = {
PROTOCOL_ERROR: "protocol:error",

// Portal API
PORTAL_GET_MY_SHAVES: "portal:get-my-shaves",
PORTAL_GET_MY_PROJECTS: "portal:get-my-projects",
PORTAL_CANCEL_WORK_ITEM: "portal:cancel-work-item",

Expand Down
68 changes: 0 additions & 68 deletions src/backend/ipc/portal-handlers.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,12 @@
import https from "node:https";
import type { GetMyProjectsResponse } from "@shared/types/portal";
import { ipcMain } from "electron";
import { config } from "../config/env";
import type { IdentityServerAuthService } from "../services/auth/identity-server-auth";
import { fetchProjectSummaries, mapProjectsResponse } from "../services/portal/portal-projects";
import type { GetMyShavesResponse } from "../types";
import { formatAndReportError } from "../utils/error-utils";
import { IPC_CHANNELS } from "./channels";

export function registerPortalHandlers(identityServerAuthService: IdentityServerAuthService) {
ipcMain.handle(IPC_CHANNELS.PORTAL_GET_MY_SHAVES, async () => {
try {
const accessToken = await identityServerAuthService.getAccessToken();
if (!accessToken) {
return { success: false, error: "Failed to obtain access token" };
}

// Parse the portal API URL
const apiUrl = config.portalApiUrl();
const url = new URL(apiUrl);
const hostname = url.hostname;
const port = url.port ? parseInt(url.port, 10) : url.protocol === "https:" ? 443 : 80;
const path = `${url.pathname.replace(/\/$/, "")}/me/shaves`; // Ensure no double slashes

// Make API call to get user's shaves using HTTPS module for SSL certificate handling
const data = await new Promise<GetMyShavesResponse>((resolve, reject) => {
const options = {
hostname: hostname,
port: port,
path: path,
method: "GET",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
};

const req = https.request(options, (res) => {
let responseData = "";

res.on("data", (chunk) => {
responseData += chunk;
});

res.on("end", () => {
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
try {
const parsedData = JSON.parse(responseData);
resolve(parsedData);
} catch (error) {
reject(
new Error(
`Failed to parse JSON response: ${formatAndReportError(error, "portal_api")}`,
),
);
}
} else {
reject(new Error(`API call failed: ${res.statusCode} ${res.statusMessage}`));
}
});
});

req.on("error", (error) => {
reject(error);
});

req.end();
});

return { success: true, data };
} catch (error) {
console.error("Portal API error:", formatAndReportError(error, "portal_api"));
return { success: false, error: formatAndReportError(error, "portal_api") };
}
});

// #816: list the signed-in user's projects, sourced from the portal endpoint
// GET {portalApiUrl}/projects/summaries — the same project list the remote-prompts feature
// already consumes in production. NOTE: that endpoint is tenant/organisation-scoped (every
Expand Down
2 changes: 0 additions & 2 deletions src/backend/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ const IPC_CHANNELS = {
PROTOCOL_ERROR: "protocol:error",

// Portal API
PORTAL_GET_MY_SHAVES: "portal:get-my-shaves",
PORTAL_GET_MY_PROJECTS: "portal:get-my-projects",
PORTAL_CANCEL_WORK_ITEM: "portal:cancel-work-item",

Expand Down Expand Up @@ -385,7 +384,6 @@ const electronAPI = {
onIpcEvent<string>(IPC_CHANNELS.PROTOCOL_ERROR, callback),
},
portal: {
getMyShaves: () => ipcRenderer.invoke(IPC_CHANNELS.PORTAL_GET_MY_SHAVES),
getMyProjects: () => ipcRenderer.invoke(IPC_CHANNELS.PORTAL_GET_MY_PROJECTS),
cancelWorkItem: (workItemId: string) =>
ipcRenderer.invoke(IPC_CHANNELS.PORTAL_CANCEL_WORK_ITEM, workItemId),
Expand Down
18 changes: 0 additions & 18 deletions src/backend/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,6 @@ export enum VideoSourceType {
EXTERNAL_URL = "external_url",
}

export interface ShaveItem {
id: string;
title: string;
videoFile: VideoFile;
updatedAt: string;
createdAt: string;
shaveStatus: string;
workItemType: string;
projectName: string;
workItemUrl: string;
feedback: string | null;
videoEmbedUrl: string;
}

export interface GetMyShavesResponse {
items: ShaveItem[];
}

// Portal-projects types (#816) are shared between the backend and the UI, so per
// AGENTS.md Rule 9 they live in `@shared/types/portal`. Re-exported here for the
// backend's existing `../types` import sites.
Expand Down
6 changes: 0 additions & 6 deletions src/ui/src/services/ipc-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type {
CustomPrompt,
GetMyProjectsErrorCode,
GetMyProjectsResponse,
GetMyShavesResponse,
HealthStatusInfo,
MCPStep,
ScreenRecordingStartResult,
Expand Down Expand Up @@ -246,11 +245,6 @@ declare global {
onProtocolError: (callback: (message: string) => void) => () => void;
};
portal: {
getMyShaves: () => Promise<{
success: boolean;
data?: GetMyShavesResponse;
error?: string;
}>;
getMyProjects: () => Promise<{
success: boolean;
data?: GetMyProjectsResponse;
Expand Down
18 changes: 0 additions & 18 deletions src/ui/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +187,6 @@ export interface VideoFile {
isChromeExtension: boolean;
}

export interface ShaveItem {
id: string;
title: string;
videoFile: VideoFile;
updatedAt: string;
createdAt: string;
shaveStatus: string;
workItemType: string;
projectName: string;
workItemUrl: string;
feedback: string | null;
videoEmbedUrl: string;
}

export interface GetMyShavesResponse {
items: ShaveItem[];
}

// Portal-projects types (#816) are shared between the backend and the UI, so per
// AGENTS.md Rule 9 they live in `@shared/types/portal`. Re-exported here for the
// UI's existing `../types` import sites.
Expand Down
Loading