feat(FN-4750): complete Step 1 — unionize settings diff keys

Fusion-Task-Id: FN-4750
Fusion-Task-Lineage: 54b3e35f-ef34-469a-aa9f-6d7fe9e79f27
This commit is contained in:
Fusion (runfusion.ai)
2026-05-16 10:13:42 -07:00
committed by gsxdsm
parent d6895b7d3f
commit 61e14fd230

View File

@@ -5,6 +5,26 @@ import { getFusionAuthPath } from "../auth-paths.js";
import { fetchFromRemoteNode, readStoredAuthProvidersFromDisk, toProviderAuthEntries } from "./register-settings-sync-helpers.js";
import type { ApiRouteRegistrar } from "./types.js";
function computeSettingsDiff(
remoteSettings: { global?: Record<string, unknown>; project?: Record<string, unknown> },
localGlobalSettings: Record<string, unknown>,
localProjectSettings: Record<string, unknown>,
): { global: string[]; project: string[] } {
const globalKeys = Array.from(new Set([
...Object.keys(remoteSettings.global ?? {}),
...Object.keys(localGlobalSettings ?? {}),
]));
const projectKeys = Array.from(new Set([
...Object.keys(remoteSettings.project ?? {}),
...Object.keys(localProjectSettings ?? {}),
]));
return {
global: globalKeys.filter((key) => JSON.stringify(remoteSettings.global?.[key]) !== JSON.stringify(localGlobalSettings[key])),
project: projectKeys.filter((key) => JSON.stringify(remoteSettings.project?.[key]) !== JSON.stringify(localProjectSettings[key])),
};
}
export const registerSettingsSyncRoutes: ApiRouteRegistrar = (ctx) => {
const { router, store, emitAuthSyncAuditLog, rethrowAsApiError } = ctx;
@@ -155,11 +175,10 @@ export const registerSettingsSyncRoutes: ApiRouteRegistrar = (ctx) => {
const localGlobalSettings = await store.getGlobalSettingsStore().getSettings();
// Compute diff: field names that differ between local and remote
const diffGlobal = Object.keys(remoteSettings.global || {}).filter(
(key) => JSON.stringify(remoteSettings.global?.[key]) !== JSON.stringify(localGlobalSettings[key as keyof typeof localGlobalSettings]),
);
const diffProject = Object.keys(remoteSettings.project || {}).filter(
(key) => JSON.stringify(remoteSettings.project?.[key]) !== JSON.stringify(localProjectSettings.project?.[key as keyof typeof localProjectSettings.project]),
const { global: diffGlobal, project: diffProject } = computeSettingsDiff(
remoteSettings,
localGlobalSettings as Record<string, unknown>,
localProjectSettings.project as Record<string, unknown>,
);
await central.close();
@@ -268,12 +287,13 @@ export const registerSettingsSyncRoutes: ApiRouteRegistrar = (ctx) => {
// Compute diff
const rs = remoteSettings;
diffGlobal = Object.keys(rs.global || {}).filter(
(key) => JSON.stringify(rs.global?.[key]) !== JSON.stringify(localGlobalSettings[key as keyof typeof localGlobalSettings]),
);
diffProject = Object.keys(rs.project || {}).filter(
(key) => JSON.stringify(rs.project?.[key]) !== JSON.stringify(localProjectSettings.project?.[key as keyof typeof localProjectSettings.project]),
const diff = computeSettingsDiff(
rs,
localGlobalSettings as Record<string, unknown>,
localProjectSettings.project as Record<string, unknown>,
);
diffGlobal = diff.global;
diffProject = diff.project;
} catch {
// Remote unreachable - diff will be empty arrays
}