From 32aeb848bf4a1a8f79d071bb65d936f2b2abb12a Mon Sep 17 00:00:00 2001 From: Pablo Mendez Date: Tue, 19 Sep 2023 10:13:48 +0200 Subject: [PATCH] update utils import --- packages/dappmanager/package.json | 2 + .../src/api/auth/adminPasswordDb.ts | 2 +- .../dappmanager/src/api/auth/sessionAuth.ts | 2 +- .../dappmanager/src/api/sessions/secret.ts | 2 +- packages/dappmanager/src/db/dbFactory.ts | 2 +- packages/dappmanager/src/logUserAction.ts | 2 +- .../compose/setDappnodeComposeDefaults.ts | 3 +- .../dappmanager/src/modules/compose/verify.ts | 8 +++- ...witchEthClientIfOpenethereumOrGethLight.ts | 20 ++++++++- packages/dappmanager/src/params.ts | 42 ------------------- yarn.lock | 22 ++++++++++ 11 files changed, 56 insertions(+), 51 deletions(-) diff --git a/packages/dappmanager/package.json b/packages/dappmanager/package.json index ca62407df..eed62d779 100644 --- a/packages/dappmanager/package.json +++ b/packages/dappmanager/package.json @@ -21,6 +21,8 @@ }, "license": "GPL-3.0", "dependencies": { + "@dappnode/params": "^0.1.0", + "@dappnode/utils": "^0.1.0", "@dappnode/common": "^0.1.0", "@dappnode/schemas": "^0.1.7", "@dappnode/toolkit": "^0.1.19", diff --git a/packages/dappmanager/src/api/auth/adminPasswordDb.ts b/packages/dappmanager/src/api/auth/adminPasswordDb.ts index e768a35db..5a418e2a8 100644 --- a/packages/dappmanager/src/api/auth/adminPasswordDb.ts +++ b/packages/dappmanager/src/api/auth/adminPasswordDb.ts @@ -1,5 +1,5 @@ import bcrypt from "bcryptjs"; -import { JsonFileDb } from "../../utils/fileDb.js"; +import { JsonFileDb } from "@dappnode/utils"; import { getRandomAlphanumericToken } from "../../utils/token.js"; export enum AdminPasswordDbError { diff --git a/packages/dappmanager/src/api/auth/sessionAuth.ts b/packages/dappmanager/src/api/auth/sessionAuth.ts index 891cf88b1..c971a6d88 100644 --- a/packages/dappmanager/src/api/auth/sessionAuth.ts +++ b/packages/dappmanager/src/api/auth/sessionAuth.ts @@ -1,5 +1,5 @@ import { Request } from "express"; -import { PlainTextFileDb } from "../../utils/fileDb.js"; +import { PlainTextFileDb } from "@dappnode/utils"; import { getRandomAlphanumericToken } from "../../utils/token.js"; import { wrapHandler } from "../utils.js"; import { SessionData, SessionsManager } from "../sessions/index.js"; diff --git a/packages/dappmanager/src/api/sessions/secret.ts b/packages/dappmanager/src/api/sessions/secret.ts index 960d2cfbc..b7dedf940 100644 --- a/packages/dappmanager/src/api/sessions/secret.ts +++ b/packages/dappmanager/src/api/sessions/secret.ts @@ -1,5 +1,5 @@ import crypto from "crypto"; -import { PlainTextFileDb } from "../../utils/fileDb.js"; +import { PlainTextFileDb } from "@dappnode/utils"; export class SessionsSecretDb { private filedb: PlainTextFileDb; diff --git a/packages/dappmanager/src/db/dbFactory.ts b/packages/dappmanager/src/db/dbFactory.ts index 8073355b4..7d957575f 100644 --- a/packages/dappmanager/src/db/dbFactory.ts +++ b/packages/dappmanager/src/db/dbFactory.ts @@ -1,6 +1,6 @@ import * as validate from "../utils/validate.js"; import { logs } from "../logs.js"; -import { JsonFileDb } from "../utils/fileDb.js"; +import { JsonFileDb } from "@dappnode/utils"; import params from "../params.js"; /** diff --git a/packages/dappmanager/src/logUserAction.ts b/packages/dappmanager/src/logUserAction.ts index a0239868a..a4d77621c 100644 --- a/packages/dappmanager/src/logUserAction.ts +++ b/packages/dappmanager/src/logUserAction.ts @@ -2,7 +2,7 @@ import { eventBus } from "./eventBus.js"; import params from "./params.js"; import { UserActionLog } from "@dappnode/common"; import { logSafeObjects } from "./utils/logs.js"; -import { JsonFileDb } from "./utils/fileDb.js"; +import { JsonFileDb } from "@dappnode/utils"; import { logs } from "./logs.js"; /** diff --git a/packages/dappmanager/src/modules/compose/setDappnodeComposeDefaults.ts b/packages/dappmanager/src/modules/compose/setDappnodeComposeDefaults.ts index 91eb062d1..e6456d8ea 100644 --- a/packages/dappmanager/src/modules/compose/setDappnodeComposeDefaults.ts +++ b/packages/dappmanager/src/modules/compose/setDappnodeComposeDefaults.ts @@ -1,5 +1,6 @@ import { mapValues, toPairs, sortBy, fromPairs, pick } from "lodash-es"; -import params, { getContainerName } from "../../params.js"; +import { getContainerName } from "@dappnode/utils"; +import { params } from "@dappnode/params"; import { getIsCore } from "../manifest/getIsCore.js"; import { cleanCompose } from "./clean.js"; import { parseEnvironment } from "./environment.js"; diff --git a/packages/dappmanager/src/modules/compose/verify.ts b/packages/dappmanager/src/modules/compose/verify.ts index a601a8560..902d5cac9 100644 --- a/packages/dappmanager/src/modules/compose/verify.ts +++ b/packages/dappmanager/src/modules/compose/verify.ts @@ -1,8 +1,12 @@ -import { maxPortNumber } from "../../params.js"; import { Compose } from "@dappnode/types"; -import { applyRecursivelyToStringValues } from "../../utils/objects.js"; +import { applyRecursivelyToStringValues } from "@dappnode/utils"; import { parsePortMappings } from "./ports.js"; +// Docker params +// Max port number (included) Otherwise it fails with +// Cannot create container for service ipfs.dnp.dappnode.eth: invalid port specification: "65536" +const maxPortNumber = 65535; + export function verifyCompose(compose: Compose): void { for (const serviceName in compose.services) { const service = compose.services[serviceName]; diff --git a/packages/dappmanager/src/modules/migrations/switchEthClientIfOpenethereumOrGethLight.ts b/packages/dappmanager/src/modules/migrations/switchEthClientIfOpenethereumOrGethLight.ts index d3f9e6254..649ea47d3 100644 --- a/packages/dappmanager/src/modules/migrations/switchEthClientIfOpenethereumOrGethLight.ts +++ b/packages/dappmanager/src/modules/migrations/switchEthClientIfOpenethereumOrGethLight.ts @@ -3,7 +3,25 @@ import { listPackageNoThrow } from "../docker/list/index.js"; import { logs } from "../../logs.js"; import { EthClientTarget } from "@dappnode/common"; import { packageGet } from "../../calls/index.js"; -import { ethClientData } from "../../params.js"; +import { EthClientTargetPackage, UserSettings } from "@dappnode/common"; + +/** + * Link between an ethClientTarget keyword and its pacakge information + * Declared above to use stronger typings + */ +const ethClientData: { + [P in EthClientTargetPackage]: { + dnpName: string; // "geth.dnp.dappnode.eth" + url?: string; // Only provide a URL if it's not "http://geth.dappnode:8545" + version?: string; + userSettings?: UserSettings; + }; +} = { + geth: { dnpName: "geth.dnp.dappnode.eth" }, + nethermind: { dnpName: "nethermind.public.dappnode.eth" }, + besu: { dnpName: "besu.public.dappnode.eth" }, + erigon: { dnpName: "erigon.dnp.dappnode.eth" } +}; /** * Switches ethClientTarget in the following preference order: geth > nethermind > remote diff --git a/packages/dappmanager/src/params.ts b/packages/dappmanager/src/params.ts index 6cb2978f4..1671239c4 100644 --- a/packages/dappmanager/src/params.ts +++ b/packages/dappmanager/src/params.ts @@ -1,6 +1,4 @@ import path from "path"; -import { EthClientTargetPackage, UserSettings } from "@dappnode/common"; -import { getContainerDomain } from "@dappnode/types"; const devMode = process.env.LOG_LEVEL === "DEV_MODE"; @@ -342,43 +340,3 @@ if (devMode) { } export default params; - -// Docker params -// Max port number (included) Otherwise it fails with -// Cannot create container for service ipfs.dnp.dappnode.eth: invalid port specification: "65536" -export const maxPortNumber = 65535; - -/** - * Link between an ethClientTarget keyword and its pacakge information - * Declared above to use stronger typings - */ -export const ethClientData: { - [P in EthClientTargetPackage]: { - dnpName: string; // "geth.dnp.dappnode.eth" - url?: string; // Only provide a URL if it's not "http://geth.dappnode:8545" - version?: string; - userSettings?: UserSettings; - }; -} = { - geth: { dnpName: "geth.dnp.dappnode.eth" }, - nethermind: { dnpName: "nethermind.public.dappnode.eth" }, - besu: { dnpName: "besu.public.dappnode.eth" }, - erigon: { dnpName: "erigon.dnp.dappnode.eth" } -}; - -// Naming - -export const getContainerName = ({ - dnpName, - serviceName, - isCore -}: { - dnpName: string; - serviceName: string; - isCore: boolean; -}): string => - // Note: _PREFIX variables already end with the character "-" - [ - isCore ? params.CONTAINER_CORE_NAME_PREFIX : params.CONTAINER_NAME_PREFIX, - getContainerDomain({ dnpName, serviceName }) - ].join(""); diff --git a/yarn.lock b/yarn.lock index 9252bb4b2..3f44f749f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1349,6 +1349,11 @@ resolved "https://registry.yarnpkg.com/@dappnode/types/-/types-0.1.25.tgz#b9b08abfbf839e2c03b3407064d10cf52c7a2d6e" integrity sha512-+5gdP5IAtv7hpesZWmHDFGJlH39ZmAfhm/Yi+oXJ7hSpVPJJCWjsm5uRPtZ5TVXemEhKO2qwn9mhXOs71yDqWw== +"@dappnode/types@^0.1.26": + version "0.1.26" + resolved "https://registry.yarnpkg.com/@dappnode/types/-/types-0.1.26.tgz#c75fc25cb831f2026a5f9f928f51ba6f71451ce1" + integrity sha512-SzKAXzXrdEDy8SEoy2e7aENH/kobzW4HM749823pQ4Dgrht2tH4Rg3nBWYz3w37uzj6hAj+mIcAKMTe6yMEuig== + "@emotion/is-prop-valid@^0.8.1": version "0.8.8" resolved "https://registry.yarnpkg.com/@emotion/is-prop-valid/-/is-prop-valid-0.8.8.tgz#db28b1c4368a259b60a97311d6a952d4fd01ac1a" @@ -3534,6 +3539,13 @@ dependencies: "@types/lodash" "*" +"@types/lodash-es@^4.17.9": + version "4.17.9" + resolved "https://registry.yarnpkg.com/@types/lodash-es/-/lodash-es-4.17.9.tgz#49dbe5112e23c54f2b387d860b7d03028ce170c2" + integrity sha512-ZTcmhiI3NNU7dEvWLZJkzG6ao49zOIjEgIE0RgV7wbPxU0f2xT3VSAHw2gmst8swH6V0YkLRGp4qPlX/6I90MQ== + dependencies: + "@types/lodash" "*" + "@types/lodash@*": version "4.14.196" resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.196.tgz#a7c3d6fc52d8d71328b764e28e080b4169ec7a95" @@ -3639,6 +3651,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-18.17.1.tgz#84c32903bf3a09f7878c391d31ff08f6fe7d8335" integrity sha512-xlR1jahfizdplZYRU59JlUx9uzF1ARa8jbhM11ccpCJya8kvos5jwdm2ZAgxSCwOl0fq21svP18EVwPBXMQudw== +"@types/node@^20.6.2": + version "20.6.2" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.6.2.tgz#a065925409f59657022e9063275cd0b9bd7e1b12" + integrity sha512-Y+/1vGBHV/cYk6OI1Na/LHzwnlNCAfU3ZNGrc1LdRe/LAIbdDPTTv/HU3M7yXN448aTVDq3eKRm2cg7iKLb8gw== + "@types/normalize-package-data@^2.4.0": version "2.4.1" resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301" @@ -16373,6 +16390,11 @@ typescript@^5.1.6: resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274" integrity sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA== +typescript@^5.2.2: + version "5.2.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.2.2.tgz#5ebb5e5a5b75f085f22bc3f8460fba308310fa78" + integrity sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w== + typescript@~4.8.2: version "4.8.4" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6"