From e7c42b6cce238c5c04b34cdfd157e1241d91508e Mon Sep 17 00:00:00 2001 From: Pablo Mendez Date: Tue, 19 Sep 2023 12:21:17 +0200 Subject: [PATCH] update eventbus imports --- .../dappmanager/src/api/routes/dataSend.ts | 2 +- .../src/api/routes/notificationSend.ts | 2 +- packages/dappmanager/src/api/startHttpApi.ts | 2 +- packages/dappmanager/src/api/subscriptions.ts | 2 +- .../dappmanager/src/calls/ethicalMetrics.ts | 2 +- .../dappmanager/src/calls/fetchDirectory.ts | 2 +- .../dappmanager/src/calls/fetchRegistry.ts | 2 +- .../src/calls/newFeatureStatusSet.ts | 2 +- .../src/calls/notificationsTest.ts | 2 +- .../src/calls/packageGettingStartedToggle.ts | 2 +- .../dappmanager/src/calls/packageRemove.ts | 2 +- .../dappmanager/src/calls/packageRestart.ts | 2 +- .../src/calls/packageRestartVolumes.ts | 2 +- .../src/calls/packageSentDataDelete.ts | 2 +- .../src/calls/packageSetEnvironment.ts | 2 +- .../src/calls/packageSetPortMappings.ts | 2 +- .../dappmanager/src/calls/packageStartStop.ts | 2 +- .../dappmanager/src/calls/seedPhraseSet.ts | 2 +- packages/dappmanager/src/calls/setStaticIp.ts | 2 +- packages/dappmanager/src/calls/telegram.ts | 2 +- .../dappmanager/src/calls/volumeRemove.ts | 2 +- .../src/daemons/autoUpdates/index.ts | 2 +- .../autoUpdates/sendUpdateNotification.ts | 2 +- .../daemons/autoUpdates/updateMyPackages.ts | 2 +- .../autoUpdates/updateSystemPackages.ts | 2 +- .../src/daemons/diskUsage/index.ts | 2 +- .../dappmanager/src/daemons/dyndns/index.ts | 2 +- .../src/daemons/ethMultiClient/index.ts | 2 +- .../src/daemons/ethicalMetrics/index.ts | 2 +- .../src/daemons/natRenewal/index.ts | 2 +- .../dappmanager/src/daemons/nsupdate/index.ts | 2 +- .../src/daemons/stakerConfig/index.ts | 2 +- .../src/daemons/telegramBot/index.ts | 2 +- packages/dappmanager/src/db/ethClient.ts | 2 +- packages/dappmanager/src/eventBus.ts | 100 ------------------ packages/dappmanager/src/index.ts | 2 +- packages/dappmanager/src/initializeDb.ts | 2 +- .../src/modules/ethClient/ethereumClient.ts | 2 +- .../modules/ethClient/syncedNotification.ts | 2 +- .../src/modules/installer/afterInstall.ts | 2 +- .../setDefaultEthicalMetricsEmail.ts | 2 +- .../stakerConfig/get/getStakerConfig.ts | 2 +- packages/dappmanager/src/startDappmanager.ts | 2 +- .../dappmanager/src/utils/autoUpdateHelper.ts | 2 +- packages/dappmanager/src/utils/logUi.ts | 2 +- 45 files changed, 44 insertions(+), 144 deletions(-) delete mode 100644 packages/dappmanager/src/eventBus.ts diff --git a/packages/dappmanager/src/api/routes/dataSend.ts b/packages/dappmanager/src/api/routes/dataSend.ts index e88ef1ffb..4d59a26f7 100644 --- a/packages/dappmanager/src/api/routes/dataSend.ts +++ b/packages/dappmanager/src/api/routes/dataSend.ts @@ -1,5 +1,5 @@ import * as db from "../../db/index.js"; -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { HttpError, wrapHandler } from "../utils.js"; import { getDnpFromIp } from "./sign.js"; diff --git a/packages/dappmanager/src/api/routes/notificationSend.ts b/packages/dappmanager/src/api/routes/notificationSend.ts index 2a6ac7025..2a3041cc8 100644 --- a/packages/dappmanager/src/api/routes/notificationSend.ts +++ b/packages/dappmanager/src/api/routes/notificationSend.ts @@ -1,5 +1,5 @@ import { getDnpFromIp } from "./sign.js"; -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { HttpError, wrapHandler } from "../utils.js"; /** diff --git a/packages/dappmanager/src/api/startHttpApi.ts b/packages/dappmanager/src/api/startHttpApi.ts index 464f07de0..b67ed1b15 100644 --- a/packages/dappmanager/src/api/startHttpApi.ts +++ b/packages/dappmanager/src/api/startHttpApi.ts @@ -19,7 +19,7 @@ import { } from "./sessions/index.js"; import { mapSubscriptionsToEventBus } from "./subscriptions.js"; import { Logs } from "@dappnode/logger"; -import { EventBus } from "../eventBus.js"; +import { EventBus } from "@dappnode/eventbus"; import { Routes, RpcPayload, diff --git a/packages/dappmanager/src/api/subscriptions.ts b/packages/dappmanager/src/api/subscriptions.ts index dc1bf0f95..2e0543693 100644 --- a/packages/dappmanager/src/api/subscriptions.ts +++ b/packages/dappmanager/src/api/subscriptions.ts @@ -1,4 +1,4 @@ -import { EventBus } from "../eventBus.js"; +import { EventBus } from "@dappnode/eventbus"; import { Routes, Subscriptions } from "@dappnode/common"; export function mapSubscriptionsToEventBus( diff --git a/packages/dappmanager/src/calls/ethicalMetrics.ts b/packages/dappmanager/src/calls/ethicalMetrics.ts index cb2bbfdc6..24d7839e0 100644 --- a/packages/dappmanager/src/calls/ethicalMetrics.ts +++ b/packages/dappmanager/src/calls/ethicalMetrics.ts @@ -1,5 +1,5 @@ import { EthicalMetricsConfig } from "@dappnode/common"; -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { listPackageNoThrow } from "../modules/docker/list/listPackages.js"; import { packageRestart } from "./packageRestart.js"; import * as db from "../db/index.js"; diff --git a/packages/dappmanager/src/calls/fetchDirectory.ts b/packages/dappmanager/src/calls/fetchDirectory.ts index e67c7f040..3c38f7039 100644 --- a/packages/dappmanager/src/calls/fetchDirectory.ts +++ b/packages/dappmanager/src/calls/fetchDirectory.ts @@ -1,4 +1,4 @@ -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { DirectoryItem, DirectoryItemOk } from "@dappnode/common"; import { logs } from "@dappnode/logger"; import { listPackages } from "../modules/docker/list/index.js"; diff --git a/packages/dappmanager/src/calls/fetchRegistry.ts b/packages/dappmanager/src/calls/fetchRegistry.ts index 65e813c7d..2f0864d43 100644 --- a/packages/dappmanager/src/calls/fetchRegistry.ts +++ b/packages/dappmanager/src/calls/fetchRegistry.ts @@ -1,7 +1,7 @@ import { getEthersProvider } from "../modules/ethClient/index.js"; import { ReleaseFetcher } from "../modules/release/index.js"; import { listPackages } from "../modules/docker/list/index.js"; -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { throttle } from "lodash-es"; import { NoImageForArchError } from "../modules/release/errors.js"; import { logs } from "@dappnode/logger"; diff --git a/packages/dappmanager/src/calls/newFeatureStatusSet.ts b/packages/dappmanager/src/calls/newFeatureStatusSet.ts index 8205bcf12..248264b4f 100644 --- a/packages/dappmanager/src/calls/newFeatureStatusSet.ts +++ b/packages/dappmanager/src/calls/newFeatureStatusSet.ts @@ -1,5 +1,5 @@ import * as db from "../db/index.js"; -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { NewFeatureId, NewFeatureStatus } from "@dappnode/common"; /** diff --git a/packages/dappmanager/src/calls/notificationsTest.ts b/packages/dappmanager/src/calls/notificationsTest.ts index 3246d5b39..322bc789d 100644 --- a/packages/dappmanager/src/calls/notificationsTest.ts +++ b/packages/dappmanager/src/calls/notificationsTest.ts @@ -1,4 +1,4 @@ -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { PackageNotification, NotificationType } from "@dappnode/common"; /** * Adds a notification to be shown the UI. diff --git a/packages/dappmanager/src/calls/packageGettingStartedToggle.ts b/packages/dappmanager/src/calls/packageGettingStartedToggle.ts index afb7087fe..30dea0c84 100644 --- a/packages/dappmanager/src/calls/packageGettingStartedToggle.ts +++ b/packages/dappmanager/src/calls/packageGettingStartedToggle.ts @@ -1,5 +1,5 @@ import * as db from "../db/index.js"; -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; /** * Toggles the visibility of a getting started block diff --git a/packages/dappmanager/src/calls/packageRemove.ts b/packages/dappmanager/src/calls/packageRemove.ts index e4cd4762a..4e1fe6275 100644 --- a/packages/dappmanager/src/calls/packageRemove.ts +++ b/packages/dappmanager/src/calls/packageRemove.ts @@ -1,5 +1,5 @@ import fs from "fs"; -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { params } from "@dappnode/params"; import { dockerComposeDown } from "../modules/docker/compose/index.js"; import { diff --git a/packages/dappmanager/src/calls/packageRestart.ts b/packages/dappmanager/src/calls/packageRestart.ts index 780cdbbe7..65289cf89 100644 --- a/packages/dappmanager/src/calls/packageRestart.ts +++ b/packages/dappmanager/src/calls/packageRestart.ts @@ -1,6 +1,6 @@ import fs from "fs"; import { params } from "@dappnode/params"; -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import * as getPath from "../utils/getPath.js"; import { dockerContainerRestart } from "../modules/docker/index.js"; import { listPackage } from "../modules/docker/list/index.js"; diff --git a/packages/dappmanager/src/calls/packageRestartVolumes.ts b/packages/dappmanager/src/calls/packageRestartVolumes.ts index e85d7d74d..b1a5ca596 100644 --- a/packages/dappmanager/src/calls/packageRestartVolumes.ts +++ b/packages/dappmanager/src/calls/packageRestartVolumes.ts @@ -1,6 +1,6 @@ import fs from "fs"; import { removeNamedVolume } from "../modules/docker/removeNamedVolume.js"; -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { params } from "@dappnode/params"; import { logs } from "@dappnode/logger"; import * as getPath from "../utils/getPath.js"; diff --git a/packages/dappmanager/src/calls/packageSentDataDelete.ts b/packages/dappmanager/src/calls/packageSentDataDelete.ts index 996e32823..5a345153a 100644 --- a/packages/dappmanager/src/calls/packageSentDataDelete.ts +++ b/packages/dappmanager/src/calls/packageSentDataDelete.ts @@ -1,5 +1,5 @@ import * as db from "../db/index.js"; -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; /** * Delete package sent data key diff --git a/packages/dappmanager/src/calls/packageSetEnvironment.ts b/packages/dappmanager/src/calls/packageSetEnvironment.ts index 32d66f000..e5c86c217 100644 --- a/packages/dappmanager/src/calls/packageSetEnvironment.ts +++ b/packages/dappmanager/src/calls/packageSetEnvironment.ts @@ -1,4 +1,4 @@ -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { listPackage } from "../modules/docker/list/index.js"; import { ComposeFileEditor } from "../modules/compose/editor.js"; import { diff --git a/packages/dappmanager/src/calls/packageSetPortMappings.ts b/packages/dappmanager/src/calls/packageSetPortMappings.ts index 48f25a9c9..493851937 100644 --- a/packages/dappmanager/src/calls/packageSetPortMappings.ts +++ b/packages/dappmanager/src/calls/packageSetPortMappings.ts @@ -1,4 +1,4 @@ -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { params } from "@dappnode/params"; import { listPackage } from "../modules/docker/list/index.js"; import { ComposeFileEditor } from "../modules/compose/editor.js"; diff --git a/packages/dappmanager/src/calls/packageStartStop.ts b/packages/dappmanager/src/calls/packageStartStop.ts index b647eaa22..0b3e6b640 100644 --- a/packages/dappmanager/src/calls/packageStartStop.ts +++ b/packages/dappmanager/src/calls/packageStartStop.ts @@ -3,7 +3,7 @@ import { dockerContainerStop, dockerContainerStart } from "../modules/docker/index.js"; -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { params } from "@dappnode/params"; import { getServicesSharingPid } from "../utils/pid.js"; import { ComposeFileEditor } from "../modules/compose/editor.js"; diff --git a/packages/dappmanager/src/calls/seedPhraseSet.ts b/packages/dappmanager/src/calls/seedPhraseSet.ts index 5b33718a5..c6acabd28 100644 --- a/packages/dappmanager/src/calls/seedPhraseSet.ts +++ b/packages/dappmanager/src/calls/seedPhraseSet.ts @@ -1,7 +1,7 @@ import { storePrivateKeyFromSeed } from "../utils/seedPhrase.js"; import { decrypt } from "../utils/publickeyEncryption.js"; import * as db from "../db/index.js"; -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { params } from "@dappnode/params"; const adminPublicKey = params.ADMIN_NACL_PUBLIC_KEY; diff --git a/packages/dappmanager/src/calls/setStaticIp.ts b/packages/dappmanager/src/calls/setStaticIp.ts index dd85db66b..a3edc5291 100644 --- a/packages/dappmanager/src/calls/setStaticIp.ts +++ b/packages/dappmanager/src/calls/setStaticIp.ts @@ -1,6 +1,6 @@ import * as db from "../db/index.js"; import * as dyndns from "../modules/dyndns/index.js"; -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { logs } from "@dappnode/logger"; /** diff --git a/packages/dappmanager/src/calls/telegram.ts b/packages/dappmanager/src/calls/telegram.ts index ae8844d4e..7a8705c68 100644 --- a/packages/dappmanager/src/calls/telegram.ts +++ b/packages/dappmanager/src/calls/telegram.ts @@ -1,5 +1,5 @@ import * as db from "../db/index.js"; -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; /** * Returns the status of the telegram bot diff --git a/packages/dappmanager/src/calls/volumeRemove.ts b/packages/dappmanager/src/calls/volumeRemove.ts index 19e7cf770..302abb980 100644 --- a/packages/dappmanager/src/calls/volumeRemove.ts +++ b/packages/dappmanager/src/calls/volumeRemove.ts @@ -1,5 +1,5 @@ import { removeNamedVolume } from "../modules/docker/removeNamedVolume.js"; -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; /** * Removes a docker volume by name diff --git a/packages/dappmanager/src/daemons/autoUpdates/index.ts b/packages/dappmanager/src/daemons/autoUpdates/index.ts index 2ddb38878..b042e629d 100644 --- a/packages/dappmanager/src/daemons/autoUpdates/index.ts +++ b/packages/dappmanager/src/daemons/autoUpdates/index.ts @@ -1,5 +1,5 @@ import { params } from "@dappnode/params"; -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { ReleaseFetcher } from "../../modules/release/index.js"; import { listPackages } from "../../modules/docker/list/index.js"; import { diff --git a/packages/dappmanager/src/daemons/autoUpdates/sendUpdateNotification.ts b/packages/dappmanager/src/daemons/autoUpdates/sendUpdateNotification.ts index 76aa8773a..ecd2b46c0 100644 --- a/packages/dappmanager/src/daemons/autoUpdates/sendUpdateNotification.ts +++ b/packages/dappmanager/src/daemons/autoUpdates/sendUpdateNotification.ts @@ -1,7 +1,7 @@ import { valid, lte } from "semver"; import { params } from "@dappnode/params"; import * as db from "../../db/index.js"; -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { ReleaseFetcher } from "../../modules/release/index.js"; import { prettyDnpName } from "../../utils/format.js"; import { CoreUpdateDataAvailable } from "@dappnode/common"; diff --git a/packages/dappmanager/src/daemons/autoUpdates/updateMyPackages.ts b/packages/dappmanager/src/daemons/autoUpdates/updateMyPackages.ts index af4449ecb..f5ea1c538 100644 --- a/packages/dappmanager/src/daemons/autoUpdates/updateMyPackages.ts +++ b/packages/dappmanager/src/daemons/autoUpdates/updateMyPackages.ts @@ -1,7 +1,7 @@ import { valid, lte } from "semver"; import { params } from "@dappnode/params"; import { listPackages } from "../../modules/docker/list/index.js"; -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { ReleaseFetcher } from "../../modules/release/index.js"; import { packageInstall } from "../../calls/index.js"; import { logs } from "@dappnode/logger"; diff --git a/packages/dappmanager/src/daemons/autoUpdates/updateSystemPackages.ts b/packages/dappmanager/src/daemons/autoUpdates/updateSystemPackages.ts index ca094a280..074771994 100644 --- a/packages/dappmanager/src/daemons/autoUpdates/updateSystemPackages.ts +++ b/packages/dappmanager/src/daemons/autoUpdates/updateSystemPackages.ts @@ -1,4 +1,4 @@ -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { params } from "@dappnode/params"; import { isUpdateDelayCompleted, diff --git a/packages/dappmanager/src/daemons/diskUsage/index.ts b/packages/dappmanager/src/daemons/diskUsage/index.ts index 2d7402125..1c638c479 100644 --- a/packages/dappmanager/src/daemons/diskUsage/index.ts +++ b/packages/dappmanager/src/daemons/diskUsage/index.ts @@ -1,7 +1,7 @@ import * as db from "../../db/index.js"; import shellExec from "../../utils/shell.js"; import { params } from "@dappnode/params"; -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { logs } from "@dappnode/logger"; import { runAtMostEvery } from "../../utils/asyncFlows.js"; import { prettyDnpName } from "../../utils/format.js"; diff --git a/packages/dappmanager/src/daemons/dyndns/index.ts b/packages/dappmanager/src/daemons/dyndns/index.ts index 29d3b7c50..eb71dc401 100644 --- a/packages/dappmanager/src/daemons/dyndns/index.ts +++ b/packages/dappmanager/src/daemons/dyndns/index.ts @@ -1,4 +1,4 @@ -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { params } from "@dappnode/params"; import * as db from "../../db/index.js"; import updateIp from "../../modules/dyndns/updateIp.js"; diff --git a/packages/dappmanager/src/daemons/ethMultiClient/index.ts b/packages/dappmanager/src/daemons/ethMultiClient/index.ts index b17bc51a0..1891c2f54 100644 --- a/packages/dappmanager/src/daemons/ethMultiClient/index.ts +++ b/packages/dappmanager/src/daemons/ethMultiClient/index.ts @@ -1,5 +1,5 @@ import * as db from "../../db/index.js"; -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { params } from "@dappnode/params"; import { packageInstall } from "../../calls/index.js"; import { listPackageNoThrow } from "../../modules/docker/list/index.js"; diff --git a/packages/dappmanager/src/daemons/ethicalMetrics/index.ts b/packages/dappmanager/src/daemons/ethicalMetrics/index.ts index c3c159f8c..f74931cdf 100644 --- a/packages/dappmanager/src/daemons/ethicalMetrics/index.ts +++ b/packages/dappmanager/src/daemons/ethicalMetrics/index.ts @@ -1,4 +1,4 @@ -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { params } from "@dappnode/params"; import { runOnlyOneSequentially } from "../../utils/asyncFlows.js"; import { runAtMostEvery } from "../../utils/asyncFlows.js"; diff --git a/packages/dappmanager/src/daemons/natRenewal/index.ts b/packages/dappmanager/src/daemons/natRenewal/index.ts index 964096f1d..8fd5b4e80 100644 --- a/packages/dappmanager/src/daemons/natRenewal/index.ts +++ b/packages/dappmanager/src/daemons/natRenewal/index.ts @@ -1,5 +1,5 @@ import * as upnpc from "../../modules/upnpc/index.js"; -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { params } from "@dappnode/params"; import * as db from "../../db/index.js"; import getPortsToOpen from "./getPortsToOpen.js"; diff --git a/packages/dappmanager/src/daemons/nsupdate/index.ts b/packages/dappmanager/src/daemons/nsupdate/index.ts index 3dc4c5d63..08dca9336 100644 --- a/packages/dappmanager/src/daemons/nsupdate/index.ts +++ b/packages/dappmanager/src/daemons/nsupdate/index.ts @@ -1,5 +1,5 @@ import retry from "async-retry"; -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import * as db from "../../db/index.js"; import { params } from "@dappnode/params"; import { listContainers } from "../../modules/docker/list/index.js"; diff --git a/packages/dappmanager/src/daemons/stakerConfig/index.ts b/packages/dappmanager/src/daemons/stakerConfig/index.ts index 6689cc59e..3bfe0b04d 100644 --- a/packages/dappmanager/src/daemons/stakerConfig/index.ts +++ b/packages/dappmanager/src/daemons/stakerConfig/index.ts @@ -1,4 +1,4 @@ -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import * as db from "../../db/index.js"; import { logs } from "@dappnode/logger"; import { pickStakerItemData } from "../../modules/stakerConfig/utils.js"; diff --git a/packages/dappmanager/src/daemons/telegramBot/index.ts b/packages/dappmanager/src/daemons/telegramBot/index.ts index de8d8fbfb..61b8a7791 100644 --- a/packages/dappmanager/src/daemons/telegramBot/index.ts +++ b/packages/dappmanager/src/daemons/telegramBot/index.ts @@ -1,5 +1,5 @@ import * as db from "../../db/index.js"; -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { logs } from "@dappnode/logger"; import { runOnlyOneSequentially } from "../../utils/asyncFlows.js"; import { formatNotification } from "./formatNotification.js"; diff --git a/packages/dappmanager/src/db/ethClient.ts b/packages/dappmanager/src/db/ethClient.ts index c44f9878c..32c039a1a 100644 --- a/packages/dappmanager/src/db/ethClient.ts +++ b/packages/dappmanager/src/db/ethClient.ts @@ -1,7 +1,7 @@ import { dbCache, dbMain } from "./dbFactory.js"; import { EthClientSyncedNotificationStatus } from "../types.js"; import { EthClientInstallStatus } from "../modules/ethClient/types.js"; -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { EthClientTarget, EthClientRemote, diff --git a/packages/dappmanager/src/eventBus.ts b/packages/dappmanager/src/eventBus.ts deleted file mode 100644 index 0dacf723e..000000000 --- a/packages/dappmanager/src/eventBus.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { EventEmitter } from "events"; -import { logs } from "@dappnode/logger"; -import { mapValues } from "lodash-es"; -import { - ChainData, - InstalledPackageData, - ProgressLog, - UserActionLog, - PackageNotification, - DirectoryItem -} from "@dappnode/common"; - -interface EventTypes { - chainData: ChainData[]; - directory: DirectoryItem[]; - registry: DirectoryItem[]; - logUi: ProgressLog; - logUserAction: UserActionLog; - notification: PackageNotification; - packages: InstalledPackageData[]; - packagesModified: { dnpNames: string[]; removed?: boolean }; - // Events without arguments - telegramStatusChanged: void; - initializedDb: void; - requestAutoUpdateData: void; - requestChainData: void; - requestDevices: void; - requestPackages: void; - requestSystemInfo: void; - runEthClientInstaller: { useCheckpointSync?: boolean }; - runEthicalMetricsInstaller: void; - runNatRenewal: void; - runStakerCacheUpdate: { dnpName: string }; -} - -const eventBusData: { [P in keyof EventTypes]: Record } = { - chainData: {}, - directory: {}, - registry: {}, - logUi: {}, - logUserAction: {}, - notification: {}, - packages: {}, - packagesModified: {}, - // Events without arguments - telegramStatusChanged: {}, - initializedDb: {}, - requestAutoUpdateData: {}, - requestChainData: {}, - requestDevices: {}, - requestPackages: {}, - requestSystemInfo: {}, - runEthClientInstaller: {}, - runEthicalMetricsInstaller: {}, - runNatRenewal: {}, - runStakerCacheUpdate: {} -}; - -const eventEmitter = new EventEmitter(); - -type GetEventBus = { - [P in keyof T]: { - on: ( - listener: T[P] extends void - ? () => void | Promise - : (arg: T[P]) => void | Promise - ) => void; - emit: T[P] extends void ? () => void : (arg: T[P]) => void; - }; -}; - -export type EventBus = GetEventBus; - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -type EventArg = any; - -export const eventBus: EventBus = mapValues(eventBusData, (_, eventName) => ({ - on: (listener: (...args: EventArg[]) => void | Promise): void => { - eventEmitter.on(eventName, async (...args: EventArg[]) => { - /** - * Always run listeners within a try/catch block - * Note: This syntax captures errors for sync and async listeners - * Note: Error parsing `e.stack || e.message || e` is necessary - * because there has been instances where the error captured - * didn't had the stack property - */ - try { - await listener(...args); - } catch (e) { - logs.error( - `Error on event '${eventName}': ${e.stack || e.message || e}` - ); - } - }); - }, - - emit: (...args: EventArg[]): void => { - eventEmitter.emit(eventName, ...args); - } -})); diff --git a/packages/dappmanager/src/index.ts b/packages/dappmanager/src/index.ts index f84c56bd8..628156f09 100644 --- a/packages/dappmanager/src/index.ts +++ b/packages/dappmanager/src/index.ts @@ -1,5 +1,5 @@ import * as db from "./db/index.js"; -import { eventBus } from "./eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import initializeDb from "./initializeDb.js"; import { createGlobalEnvsEnvFile } from "./modules/globalEnvs.js"; import { generateKeyPair } from "./utils/publickeyEncryption.js"; diff --git a/packages/dappmanager/src/initializeDb.ts b/packages/dappmanager/src/initializeDb.ts index bc9a2478d..5bd12593a 100644 --- a/packages/dappmanager/src/initializeDb.ts +++ b/packages/dappmanager/src/initializeDb.ts @@ -1,5 +1,5 @@ import * as db from "./db/index.js"; -import { eventBus } from "./eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import * as dyndns from "./modules/dyndns/index.js"; import getDappmanagerImage from "./utils/getDappmanagerImage.js"; import getServerName from "./utils/getServerName.js"; diff --git a/packages/dappmanager/src/modules/ethClient/ethereumClient.ts b/packages/dappmanager/src/modules/ethClient/ethereumClient.ts index 9ceee1a73..8b29e3f07 100644 --- a/packages/dappmanager/src/modules/ethClient/ethereumClient.ts +++ b/packages/dappmanager/src/modules/ethClient/ethereumClient.ts @@ -1,7 +1,7 @@ import { isEqual } from "lodash-es"; import { Eth2ClientTarget, EthClientRemote } from "@dappnode/common"; import * as db from "../../db/index.js"; -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { logs } from "@dappnode/logger"; import { getConsensusUserSettings } from "../stakerConfig/utils.js"; import { packageGet } from "../../calls/packageGet.js"; diff --git a/packages/dappmanager/src/modules/ethClient/syncedNotification.ts b/packages/dappmanager/src/modules/ethClient/syncedNotification.ts index 00279ccc6..77e9ed269 100644 --- a/packages/dappmanager/src/modules/ethClient/syncedNotification.ts +++ b/packages/dappmanager/src/modules/ethClient/syncedNotification.ts @@ -1,5 +1,5 @@ import * as db from "../../db/index.js"; -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { Eth2ClientTarget, EthClientStatus } from "@dappnode/common"; /** diff --git a/packages/dappmanager/src/modules/installer/afterInstall.ts b/packages/dappmanager/src/modules/installer/afterInstall.ts index 24cbf7e31..d334436e4 100644 --- a/packages/dappmanager/src/modules/installer/afterInstall.ts +++ b/packages/dappmanager/src/modules/installer/afterInstall.ts @@ -1,4 +1,4 @@ -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { flagPackagesAreNotInstalling } from "./packageIsInstalling.js"; /** diff --git a/packages/dappmanager/src/modules/migrations/setDefaultEthicalMetricsEmail.ts b/packages/dappmanager/src/modules/migrations/setDefaultEthicalMetricsEmail.ts index 4034b594f..790923ab4 100644 --- a/packages/dappmanager/src/modules/migrations/setDefaultEthicalMetricsEmail.ts +++ b/packages/dappmanager/src/modules/migrations/setDefaultEthicalMetricsEmail.ts @@ -3,7 +3,7 @@ import { listPackageNoThrow } from "../docker/list/index.js"; import { ethicalMetricsDnpName } from "../ethicalMetrics/index.js"; import * as db from "../../db/index.js"; import { ComposeFileEditor } from "../compose/editor.js"; -import { eventBus } from "../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; /** * Gets the email env from the ethical metrics package (if exists) and sets it diff --git a/packages/dappmanager/src/modules/stakerConfig/get/getStakerConfig.ts b/packages/dappmanager/src/modules/stakerConfig/get/getStakerConfig.ts index 359a1b2e4..7309803b1 100644 --- a/packages/dappmanager/src/modules/stakerConfig/get/getStakerConfig.ts +++ b/packages/dappmanager/src/modules/stakerConfig/get/getStakerConfig.ts @@ -20,7 +20,7 @@ import { getBeaconServiceName, pickStakerItemData } from "../utils.js"; import { Network } from "@dappnode/types"; import { getStakerDnpNamesByNetwork } from "./getStakerDnpNamesByNetwork.js"; import { getStakerConfigByNetwork } from "../index.js"; -import { eventBus } from "../../../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import * as db from "../../../db/index.js"; /** diff --git a/packages/dappmanager/src/startDappmanager.ts b/packages/dappmanager/src/startDappmanager.ts index 0919e2706..a206cf7ce 100644 --- a/packages/dappmanager/src/startDappmanager.ts +++ b/packages/dappmanager/src/startDappmanager.ts @@ -5,7 +5,7 @@ import { AdminPasswordDbParams } from "./api/auth/adminPasswordDb.js"; import { Logs } from "@dappnode/logger"; -import { EventBus } from "./eventBus.js"; +import { EventBus } from "@dappnode/eventbus"; import { LoggerMiddleware, Routes } from "@dappnode/common"; import { DeviceCalls } from "./calls/device/index.js"; import { SshCalls } from "./calls/ssh/index.js"; diff --git a/packages/dappmanager/src/utils/autoUpdateHelper.ts b/packages/dappmanager/src/utils/autoUpdateHelper.ts index 5786dc619..6a0f5382c 100644 --- a/packages/dappmanager/src/utils/autoUpdateHelper.ts +++ b/packages/dappmanager/src/utils/autoUpdateHelper.ts @@ -1,6 +1,6 @@ import * as db from "../db/index.js"; import { params } from "@dappnode/params"; -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { pick, omit } from "lodash-es"; import { isVersionIdUpdated } from "./coreVersionId.js"; import { diff --git a/packages/dappmanager/src/utils/logUi.ts b/packages/dappmanager/src/utils/logUi.ts index 93a29a6e5..3c5fd3803 100644 --- a/packages/dappmanager/src/utils/logUi.ts +++ b/packages/dappmanager/src/utils/logUi.ts @@ -1,4 +1,4 @@ -import { eventBus } from "../eventBus.js"; +import { eventBus } from "@dappnode/eventbus"; import { ProgressLog } from "@dappnode/common"; import { logs } from "@dappnode/logger";