mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-29 18:19:44 -05:00
:electron: Removing node-fetch and updating root ca impl for more support (#3782)
* updating root ca impl to use node env variable for more support * release notes * removing node-fetch * clean up * error message * Update 3782.md
This commit is contained in:
@@ -15,6 +15,8 @@ import {
|
||||
UtilityProcess,
|
||||
OpenDialogSyncOptions,
|
||||
SaveDialogOptions,
|
||||
Env,
|
||||
ForkOptions,
|
||||
} from 'electron';
|
||||
import { copy, exists, remove } from 'fs-extra';
|
||||
import promiseRetry from 'promise-retry';
|
||||
@@ -56,11 +58,49 @@ if (isDev) {
|
||||
process.traceProcessWarnings = true;
|
||||
}
|
||||
|
||||
function createBackgroundProcess() {
|
||||
async function loadGlobalPrefs() {
|
||||
let state: { [key: string]: unknown } | undefined = undefined;
|
||||
try {
|
||||
state = JSON.parse(
|
||||
fs.readFileSync(
|
||||
path.join(process.env.ACTUAL_DATA_DIR!, 'global-store.json'),
|
||||
'utf8',
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
console.info('Could not load global state - using defaults'); // This could be the first time running the app - no global-store.json
|
||||
state = {};
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
async function createBackgroundProcess() {
|
||||
const globalPrefs = await loadGlobalPrefs(); // ensures we have the latest settings - even when restarting the server
|
||||
let envVariables: Env = {
|
||||
...process.env, // required
|
||||
};
|
||||
|
||||
if (globalPrefs?.['server-self-signed-cert']) {
|
||||
envVariables = {
|
||||
...envVariables,
|
||||
NODE_EXTRA_CA_CERTS: globalPrefs?.['server-self-signed-cert'], // add self signed cert to env - fetch can pick it up
|
||||
};
|
||||
}
|
||||
|
||||
let forkOptions: ForkOptions = {
|
||||
stdio: 'pipe',
|
||||
env: envVariables,
|
||||
};
|
||||
|
||||
if (isDev) {
|
||||
forkOptions = { ...forkOptions, execArgv: ['--inspect'] };
|
||||
}
|
||||
|
||||
serverProcess = utilityProcess.fork(
|
||||
__dirname + '/server.js',
|
||||
['--subprocess', app.getVersion()],
|
||||
isDev ? { execArgv: ['--inspect'], stdio: 'pipe' } : { stdio: 'pipe' },
|
||||
forkOptions,
|
||||
);
|
||||
|
||||
serverProcess.stdout?.on('data', (chunk: Buffer) => {
|
||||
|
||||
@@ -87,7 +87,6 @@
|
||||
"dependencies": {
|
||||
"better-sqlite3": "^9.6.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"node-fetch": "^2.7.0",
|
||||
"promise-retry": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
// @ts-strict-ignore
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
global.fetch = fetch;
|
||||
|
||||
const lazyLoadBackend = async (isDev: boolean) => {
|
||||
if (process.env.lootCoreScript === undefined) {
|
||||
throw new Error(
|
||||
'The environment variable `lootCoreScript` is not defined. Please define it to point to the server bundle.',
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const bundle = await import(process.env.lootCoreScript);
|
||||
bundle.initApp(isDev);
|
||||
} catch (error) {
|
||||
console.error('Failed to init the server bundle:', error);
|
||||
throw new Error(`Failed to init the server bundle: ${error.message}`);
|
||||
throw new Error(`Failed to init the server bundle: ${error}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
"md5": "^2.3.0",
|
||||
"memoize-one": "^6.0.0",
|
||||
"mitt": "^3.0.1",
|
||||
"node-fetch": "^2.7.0",
|
||||
"reselect": "^4.1.8",
|
||||
"slash": "3.0.0",
|
||||
"throttleit": "^1.0.1",
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
// @ts-strict-ignore
|
||||
import nodeFetch from 'node-fetch';
|
||||
|
||||
export const fetch = async (
|
||||
input: RequestInfo | URL,
|
||||
options?: RequestInit,
|
||||
) => {
|
||||
try {
|
||||
return await nodeFetch(input, {
|
||||
return await globalThis.fetch(input, {
|
||||
...options,
|
||||
headers: {
|
||||
...options?.headers,
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// @ts-strict-ignore
|
||||
import './polyfills';
|
||||
import https from 'https';
|
||||
import tls from 'tls';
|
||||
|
||||
import * as injectAPI from '@actual-app/api/injected';
|
||||
import * as CRDT from '@actual-app/crdt';
|
||||
@@ -2234,23 +2232,6 @@ export async function initApp(isDev, socketName) {
|
||||
}
|
||||
}
|
||||
|
||||
const selfSignedCertPath = await asyncStorage.getItem(
|
||||
'server-self-signed-cert',
|
||||
);
|
||||
|
||||
if (selfSignedCertPath) {
|
||||
try {
|
||||
const selfSignedCert = await fs.readFile(selfSignedCertPath);
|
||||
https.globalAgent.options.ca = [...tls.rootCertificates, selfSignedCert];
|
||||
} catch (error) {
|
||||
console.error(
|
||||
'Unable to add the self signed certificate, removing its reference',
|
||||
error,
|
||||
);
|
||||
await asyncStorage.removeItem('server-self-signed-cert');
|
||||
}
|
||||
}
|
||||
|
||||
const url = await asyncStorage.getItem('server-url');
|
||||
|
||||
if (!url) {
|
||||
|
||||
@@ -28,7 +28,7 @@ module.exports = {
|
||||
'pegjs',
|
||||
],
|
||||
},
|
||||
externals: ['better-sqlite3', 'node-fetch'],
|
||||
externals: ['better-sqlite3'],
|
||||
plugins: [
|
||||
new webpack.IgnorePlugin({
|
||||
resourceRegExp: /original-fs/,
|
||||
|
||||
6
upcoming-release-notes/3782.md
Normal file
6
upcoming-release-notes/3782.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Maintenance
|
||||
authors: [MikesGlitch]
|
||||
---
|
||||
|
||||
Removing node-fetch from the Desktop app and updating self signed certificate implementation
|
||||
40
yarn.lock
40
yarn.lock
@@ -8633,7 +8633,6 @@ __metadata:
|
||||
electron: "npm:30.0.6"
|
||||
electron-builder: "npm:24.13.3"
|
||||
fs-extra: "npm:^11.2.0"
|
||||
node-fetch: "npm:^2.7.0"
|
||||
promise-retry: "npm:^2.0.1"
|
||||
typescript: "npm:^5.5.4"
|
||||
languageName: unknown
|
||||
@@ -13336,7 +13335,6 @@ __metadata:
|
||||
memoize-one: "npm:^6.0.0"
|
||||
mitt: "npm:^3.0.1"
|
||||
mockdate: "npm:^3.0.5"
|
||||
node-fetch: "npm:^2.7.0"
|
||||
npm-run-all: "npm:^4.1.5"
|
||||
path-browserify: "npm:^1.0.1"
|
||||
peggy: "npm:3.0.2"
|
||||
@@ -14542,20 +14540,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"node-fetch@npm:^2.7.0":
|
||||
version: 2.7.0
|
||||
resolution: "node-fetch@npm:2.7.0"
|
||||
dependencies:
|
||||
whatwg-url: "npm:^5.0.0"
|
||||
peerDependencies:
|
||||
encoding: ^0.1.0
|
||||
peerDependenciesMeta:
|
||||
encoding:
|
||||
optional: true
|
||||
checksum: 10/b24f8a3dc937f388192e59bcf9d0857d7b6940a2496f328381641cb616efccc9866e89ec43f2ec956bbd6c3d3ee05524ce77fe7b29ccd34692b3a16f237d6676
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"node-fetch@npm:^3.3.2":
|
||||
version: 3.3.2
|
||||
resolution: "node-fetch@npm:3.3.2"
|
||||
@@ -18233,13 +18217,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"tr46@npm:~0.0.3":
|
||||
version: 0.0.3
|
||||
resolution: "tr46@npm:0.0.3"
|
||||
checksum: 10/8f1f5aa6cb232f9e1bdc86f485f916b7aa38caee8a778b378ffec0b70d9307873f253f5cbadbe2955ece2ac5c83d0dc14a77513166ccd0a0c7fe197e21396695
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"trampa@npm:^1.0.0":
|
||||
version: 1.0.1
|
||||
resolution: "trampa@npm:1.0.1"
|
||||
@@ -19357,13 +19334,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"webidl-conversions@npm:^3.0.0":
|
||||
version: 3.0.1
|
||||
resolution: "webidl-conversions@npm:3.0.1"
|
||||
checksum: 10/b65b9f8d6854572a84a5c69615152b63371395f0c5dcd6729c45789052296df54314db2bc3e977df41705eacb8bc79c247cee139a63fa695192f95816ed528ad
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"webidl-conversions@npm:^4.0.2":
|
||||
version: 4.0.2
|
||||
resolution: "webidl-conversions@npm:4.0.2"
|
||||
@@ -19509,16 +19479,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"whatwg-url@npm:^5.0.0":
|
||||
version: 5.0.0
|
||||
resolution: "whatwg-url@npm:5.0.0"
|
||||
dependencies:
|
||||
tr46: "npm:~0.0.3"
|
||||
webidl-conversions: "npm:^3.0.0"
|
||||
checksum: 10/f95adbc1e80820828b45cc671d97da7cd5e4ef9deb426c31bcd5ab00dc7103042291613b3ef3caec0a2335ed09e0d5ed026c940755dbb6d404e2b27f940fdf07
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"whatwg-url@npm:^7.0.0":
|
||||
version: 7.1.0
|
||||
resolution: "whatwg-url@npm:7.1.0"
|
||||
|
||||
Reference in New Issue
Block a user