super-productivity/electron/electronAPI.d.ts
Johannes Millan 95d3b212bc
fix(electron): gate Jira IPC behind a one-shot capability (#9008)
* docs(plugins): add microsoft 365 calendar provider plan

* fix(jira): gate Electron requests behind one-shot capability

Claim privileged Jira IPC before plugin startup and return responses through invoke instead of a broadcast event. Keep arbitrary HTTP(S) Jira hosts supported while rejecting redirects and bounding request resources.

* fix(jira): enforce Electron request capability

Bind privileged Jira IPC to a main-issued renderer-document token and strip raw Electron events from renderer callbacks. Scope image authentication by origin, base path, and resource type while preserving safe redirects and legacy configurations.

* fix(electron): handle payload-only IPC lifecycle

Clear Jira image authentication before replacement and when a new renderer document claims the capability. Parse before-close IDs from payload-only events so pending sync and finish-day hooks can complete.

* fix(electron): address Jira IPC capability review findings

- electron.effects: read ANY_FILE_DOWNLOADED payload at [0] after the
  payload-only IPC refactor (was [1], now undefined -> TypeError on every
  download); guard against a malformed payload
- jira-capability: rotate the token on re-register so a renderer reload
  that reuses the WebFrameMain object is not permanently locked out of
  Jira; invalidates any stale token
- document that the one-shot consumption order, not the bypassable
  main-frame check, is the real capability boundary
- jira-electron-bridge: skip the no-op clearImgHeaders IPC round-trip
  when image auth was never set up (non-Jira detail-panel open/close)
- jira-api: route a synchronous _toElectronRequestInit throw through
  _handleResponse instead of leaking a dangling request-log entry

* test(electron): cover ANY_FILE_DOWNLOADED payload parsing

Extract parseDownloadedFilePayload from ElectronEffects and add a
regression spec pinning the payload-only shape ([file], not [event,
file]) that caused a TypeError on every download. Hardened against
non-array input surfaced by the new test.

* fix(electron): restore Node ambient globals for frontend build
2026-07-14 21:02:27 +02:00

260 lines
7.6 KiB
TypeScript

// This file is pulled into the frontend TS program (via src/app/core/window-ea.d.ts).
// That program sets `types: []`, so it has no ambient Node globals of its own and
// relied on the now-removed `import { IpcRendererEvent } from 'electron'` here to
// transitively supply them. Several frontend/shared modules still probe Node globals
// guarded at runtime (get-dist-channel's `process`/`NodeJS`, generate-client-id's
// `process`, create-task-placeholder's `NodeJS.Timeout`, user-profile's `require`),
// so re-expose them explicitly instead of by accident.
/// <reference types="node" />
import {
GlobalConfigState,
TakeABreakConfig,
TaskWidgetConfig,
} from '../src/app/features/config/global-config.model';
import { KeyboardConfig } from './shared-with-frontend/keyboard-config.model';
import { AppDataCompleteLegacy } from '../src/app/imex/sync/sync.model';
import { Task } from '../src/app/features/tasks/task.model';
import { LocalBackupMeta } from '../src/app/imex/local-backup/local-backup.model';
import { AppDataComplete } from '../src/app/op-log/model/model-config';
import { PluginNodeExecutionElectronApi } from './shared-with-frontend/plugin-node-execution.model';
import {
LocalRestApiRequestPayload,
LocalRestApiResponsePayload,
} from './shared-with-frontend/local-rest-api.model';
import { ElectronDistChannel } from './shared-with-frontend/get-dist-channel';
import { JiraElectronApi } from './shared-with-frontend/jira-request.model';
export interface ElectronAPI {
on(channel: string, listener: (...args: unknown[]) => void): void;
// SYNC
// ----
getDistChannel(): ElectronDistChannel | null;
// INVOKE
// ------
getUserDataPath(): Promise<string>;
getBackupPath(): Promise<string>;
checkBackupAvailable(): Promise<false | LocalBackupMeta>;
loadBackupData(backupPath: string): Promise<string>;
fileSyncSave(args: {
relativePath: string;
localRev: string | null;
dataStr: string;
}): Promise<string | Error>;
fileSyncLoad(args: {
relativePath: string;
localRev: string | null;
}): Promise<{ rev: string; dataStr: string | undefined } | Error>;
fileSyncRemove(args: { relativePath: string }): Promise<unknown | Error>;
fileSyncListFiles(args: { relativePath?: string }): Promise<string[] | Error>;
checkDirExists(args: { relativePath?: string }): Promise<true | Error>;
/**
* Opens the native folder picker for the sync folder. Resolves to:
* - `string`: the canonicalized, persisted folder path on success
* - `undefined`: the user cancelled the picker
* - `Error`: the pick succeeded but main could not canonicalize/persist it
* (e.g. the folder was deleted between pick and commit, EACCES, or the
* folder lives inside the app's private dir). Nothing is persisted in
* this case; the renderer must treat it as a failure, not a picked path.
*/
pickDirectory(): Promise<string | Error | undefined>;
/**
* Returns the main-owned sync folder path for display, or null if not yet
* configured. The renderer must not pass this value back to file-sync IPCs
* — those take only the relative path; main resolves against its own copy.
*/
getSyncFolderPath(): Promise<string | null>;
showOpenDialog(options: {
properties: string[];
title?: string;
defaultPath?: string;
filters?: { name: string; extensions: string[] }[];
}): Promise<string[] | undefined>;
/**
* Open the native image picker, copy the chosen file into the main-owned
* cache, and return an opaque id. The renderer never holds the absolute
* path. Returns null when the user cancels and a safe Error when the picked
* file fails validation/import. Old cached images are not deleted here,
* because the surrounding config save may still fail or be cancelled.
*/
imagePickAndImport(): Promise<{ id: string; mimeType: string } | null | Error>;
/**
* Resolve a cached image id to a `data:` URL the renderer can use as a
* CSS background. Returns null when the id is unknown or the file
* disappeared.
*/
imageCacheGetDataUrl(id: string): Promise<string | null>;
// checkDirExists(dirPath: string): Promise<true | Error>;
// STANDARD
// --------
setZoomFactor(zoomFactor: number): void;
getZoomFactor(): number;
openPath(path: string): void;
openExternalUrl(url: string): void;
saveFileDialog(
filename: string,
data: string,
): Promise<{ success: boolean; path?: string }>;
shareNative(payload: {
text?: string;
url?: string;
title?: string;
files?: string[];
}): Promise<{ success: boolean; error?: string }>;
isLinux(): boolean;
isGnomeDesktop(): boolean;
isGnomeWayland(): boolean;
isMacOS(): boolean;
isAppleSilicon(): boolean;
isSnap(): boolean;
isFlatpak(): boolean;
// CLIPBOARD IMAGES
// ----------------
saveClipboardImage(
basePath: string,
fileName: string,
base64Data: string,
mimeType: string,
): Promise<string>;
loadClipboardImage(
basePath: string,
imageId: string,
): Promise<{ base64: string; mimeType: string } | null>;
deleteClipboardImage(basePath: string, imageId: string): Promise<boolean>;
listClipboardImages(
basePath: string,
): Promise<{ id: string; mimeType: string; createdAt: number; size: number }[]>;
getClipboardImagePath(basePath: string, imageId: string): Promise<string | null>;
getClipboardFilePaths(): Promise<string[]>;
copyClipboardImageFile(
basePath: string,
filePath: string,
): Promise<{
id: string;
mimeType: string;
size: number;
createdAt: number;
} | null>;
readClipboardImage(basePath: string): Promise<{
id: string;
mimeType: string;
size: number;
createdAt: number;
} | null>;
getPathForFile(file: File): string | null;
// SEND
// ----
reloadMainWin(): void;
openDevTools(): void;
showEmojiPanel(): void;
relaunch(): void;
exit(exitCode: number): void;
shutdownNow(): void;
flashFrame(): void;
showOrFocus(): void;
lockScreen(): void;
informAboutAppReady(): void;
scheduleRegisterBeforeClose(id: string): void;
unscheduleRegisterBeforeClose(id: string): void;
setDoneRegisterBeforeClose(id: string): void;
setProgressBar(args: {
progress: number;
progressBarMode: 'normal' | 'pause' | 'none';
}): void;
sendAppSettingsToElectron(globalCfg: GlobalConfigState): void;
sendSettingsUpdate(globalCfg: GlobalConfigState): void;
updateTaskWidgetSettings(cfg: TaskWidgetConfig): void;
updateTitleBarDarkMode(isDarkMode: boolean): void;
registerGlobalShortcuts(keyboardConfig: KeyboardConfig): void;
showFullScreenBlocker(args: { msg?: string; takeABreakCfg: TakeABreakConfig }): void;
backupAppData(args: {
data: AppDataCompleteLegacy | AppDataComplete;
maxBackupFiles?: number | null;
}): void;
updateCurrentTask(
task: Task | null,
isPomodoroEnabled: boolean,
currentPomodoroSessionTime: number,
isFocusModeEnabled?: boolean,
currentFocusSessionTime?: number,
focusModeMode?: string,
);
updateTodayTasks(
tasks: { id: string; title: string; timeEstimate: number; timeSpent: number }[],
): void;
onSwitchTask(listener: (taskId: string) => void): void;
consumeJiraApi(): JiraElectronApi | null;
consumePluginNodeExecutionApi(): PluginNodeExecutionElectronApi | null;
// Plugin OAuth
pluginOAuthPrepare(port?: number): Promise<{ port: number }>;
pluginOAuthStart(url: string): void;
onPluginOAuthCb(
listener: (data: { code?: string; error?: string; state?: string }) => void,
): void;
onLocalRestApiRequest(listener: (payload: LocalRestApiRequestPayload) => void): void;
sendLocalRestApiResponse(payload: LocalRestApiResponsePayload): void;
}