diff --git a/.vscode/settings.json b/.vscode/settings.json index 803c58a07..465ffb3f3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,11 +20,6 @@ "typescript.format.placeOpenBraceOnNewLineForFunctions": false, // Defines whether an open brace is put onto a new line for control blocks or not "typescript.format.placeOpenBraceOnNewLineForControlBlocks": false, - "typescript.preferences.autoImportFileExcludePatterns": [ - "index.*.js", - "index.ts", - "index.*.ts" - ], // Files hidden in the explorer "files.exclude": { // include the defaults from VS Code diff --git a/packages/taler-util/src/walletTypes.ts b/packages/taler-util/src/walletTypes.ts index a1fa9b439..d0765ae31 100644 --- a/packages/taler-util/src/walletTypes.ts +++ b/packages/taler-util/src/walletTypes.ts @@ -1684,6 +1684,15 @@ export interface AcceptPeerPullPaymentRequest { peerPullPaymentIncomingId: string; } +export interface SetDevModeRequest { + devModeEnabled: boolean; +} + +export const codecForSetDevModeRequest = (): Codec => + buildCodecForObject() + .property("devModeEnabled", codecForBoolean()) + .build("SetDevModeRequest"); + export interface ApplyDevExperimentRequest { devExperimentUri: string; } diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts index 6ae78bd47..941a2f28f 100644 --- a/packages/taler-wallet-cli/src/index.ts +++ b/packages/taler-wallet-cli/src/index.ts @@ -1018,6 +1018,30 @@ advancedCli }); }); +advancedCli + .subcommand("enableDevMode", "enable-dev-mode", { + help: "Enable developer mode (dangerous!)", + }) + .action(async (args) => { + await withWallet(args, async (wallet) => { + await wallet.client.call(WalletApiOperation.SetDevMode, { + devModeEnabled: true, + }); + }); + }); + +advancedCli + .subcommand("disableDevMode", "disable-dev-mode", { + help: "Disable developer mode", + }) + .action(async (args) => { + await withWallet(args, async (wallet) => { + await wallet.client.call(WalletApiOperation.SetDevMode, { + devModeEnabled: false, + }); + }); + }); + const coinPubListCodec = codecForList(codecForString()); advancedCli diff --git a/packages/taler-wallet-core/src/dev-experiments.ts b/packages/taler-wallet-core/src/dev-experiments.ts index c3167b3e4..6516db929 100644 --- a/packages/taler-wallet-core/src/dev-experiments.ts +++ b/packages/taler-wallet-core/src/dev-experiments.ts @@ -36,6 +36,35 @@ import { const logger = new Logger("dev-experiments.ts"); +export async function setDevMode( + ws: InternalWalletState, + enabled: boolean, +): Promise { + if (enabled) { + logger.info("enabling devmode"); + await ws.db + .mktx((x) => [x.config]) + .runReadWrite(async (tx) => { + tx.config.put({ + key: ConfigRecordKey.DevMode, + value: true, + }); + }); + await maybeInitDevMode(ws); + } else { + logger.info("disabling devmode"); + await ws.db + .mktx((x) => [x.config]) + .runReadWrite(async (tx) => { + tx.config.put({ + key: ConfigRecordKey.DevMode, + value: false, + }); + }); + await leaveDevMode(ws); + } +} + /** * Apply a dev experiment to the wallet database / state. */ @@ -49,32 +78,6 @@ export async function applyDevExperiment( logger.info("unable to parse dev experiment URI"); return; } - if (parsedUri.devExperimentId == "enable-devmode") { - logger.info("enabling devmode"); - await ws.db - .mktx((x) => [x.config]) - .runReadWrite(async (tx) => { - tx.config.put({ - key: ConfigRecordKey.DevMode, - value: true, - }); - }); - await maybeInitDevMode(ws); - return; - } - if (parsedUri.devExperimentId === "disable-devmode") { - logger.info("disabling devmode"); - await ws.db - .mktx((x) => [x.config]) - .runReadWrite(async (tx) => { - tx.config.put({ - key: ConfigRecordKey.DevMode, - value: false, - }); - }); - await leaveDevMode(ws); - return; - } if (!ws.devModeActive) { throw Error( "can't handle devmode URI (other than enable-devmode) unless devmode is active", diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts index cecdd1281..63d960f81 100644 --- a/packages/taler-wallet-core/src/wallet-api-types.ts +++ b/packages/taler-wallet-core/src/wallet-api-types.ts @@ -67,6 +67,7 @@ import { RecoveryLoadRequest, RetryTransactionRequest, SetCoinSuspendedRequest, + SetDevModeRequest, SetWalletDeviceIdRequest, TestPayArgs, TestPayResult, @@ -140,6 +141,7 @@ export enum WalletApiOperation { AcceptPeerPullPayment = "acceptPeerPullPayment", ClearDb = "clearDb", Recycle = "recycle", + SetDevMode = "setDevMode", ApplyDevExperiment = "applyDevExperiment", } @@ -529,6 +531,12 @@ export type ApplyDevExperimentOp = { response: {}; }; +export type SetDevModeOp = { + op: WalletApiOperation.SetDevMode; + request: SetDevModeRequest; + response: {}; +}; + /** * Run a simple integration test on a test deployment * of the exchange and merchant. @@ -676,6 +684,7 @@ export type WalletOperations = { [WalletApiOperation.ClearDb]: ClearDbOp; [WalletApiOperation.Recycle]: RecycleOp; [WalletApiOperation.ApplyDevExperiment]: ApplyDevExperimentOp; + [WalletApiOperation.SetDevMode]: SetDevModeOp; }; export type RequestType< diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 48d379931..254648064 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -94,6 +94,7 @@ import { URL, WalletCoreVersion, WalletNotification, + codecForSetDevModeRequest, } from "@gnu-taler/taler-util"; import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js"; import { @@ -111,7 +112,7 @@ import { importDb, WalletStoresV1, } from "./db.js"; -import { applyDevExperiment, maybeInitDevMode } from "./dev-experiments.js"; +import { applyDevExperiment, maybeInitDevMode, setDevMode } from "./dev-experiments.js"; import { getErrorDetailFromException, TalerError } from "./errors.js"; import { ActiveLongpollInfo, @@ -1334,6 +1335,11 @@ async function dispatchRequestInternal( await applyDevExperiment(ws, req.devExperimentUri); return {}; } + case "setDevMode": { + const req = codecForSetDevModeRequest().decode(payload); + await setDevMode(ws, req.devModeEnabled); + return {}; + } case "getVersion": { const version: WalletCoreVersion = { hash: GIT_HASH, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 23ec58a94..8e506d65f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -92,29 +92,21 @@ importers: packages/idb-bridge: specifiers: - '@rollup/plugin-commonjs': ^22.0.2 - '@rollup/plugin-json': ^4.1.0 - '@rollup/plugin-node-resolve': ^13.3.0 '@types/node': ^18.8.5 ava: ^4.3.3 esm: ^3.2.25 prettier: ^2.5.1 rimraf: ^3.0.2 - rollup: ^2.79.0 tslib: ^2.4.0 typescript: ^4.8.4 dependencies: tslib: 2.4.0 devDependencies: - '@rollup/plugin-commonjs': 22.0.2_rollup@2.79.0 - '@rollup/plugin-json': 4.1.0_rollup@2.79.0 - '@rollup/plugin-node-resolve': 13.3.0_rollup@2.79.0 '@types/node': 18.8.5 ava: 4.3.3 esm: 3.2.25 prettier: 2.5.1 rimraf: 3.0.2 - rollup: 2.79.0 typescript: 4.8.4 packages/pogen: @@ -130,29 +122,6 @@ importers: po2json: 0.4.5 typescript: 4.8.4 - packages/taler-config-lib: - specifiers: - '@types/node': ^18.8.5 - ava: ^4.3.3 - big-integer: ^1.6.51 - esbuild: ^0.14.21 - jed: ^1.1.1 - prettier: ^2.5.1 - rimraf: ^3.0.2 - tslib: ^2.4.0 - typescript: ^4.8.4 - dependencies: - big-integer: 1.6.51 - jed: 1.1.1 - tslib: 2.4.0 - devDependencies: - '@types/node': 18.8.5 - ava: 4.3.3 - esbuild: 0.14.21 - prettier: 2.5.1 - rimraf: 3.0.2 - typescript: 4.8.4 - packages/taler-util: specifiers: '@types/node': ^18.8.5 @@ -241,8 +210,6 @@ importers: po2json: ^0.4.5 prettier: ^2.5.1 rimraf: ^3.0.2 - rollup: ^2.79.0 - rollup-plugin-sourcemaps: ^0.6.3 source-map-resolve: ^0.6.0 source-map-support: ^0.5.21 tslib: ^2.4.0 @@ -274,8 +241,6 @@ importers: po2json: 0.4.5 prettier: 2.5.1 rimraf: 3.0.2 - rollup: 2.79.0 - rollup-plugin-sourcemaps: 0.6.3_n3h7ooyjwm4phuvjpg4pqirc4i source-map-resolve: 0.6.0 typedoc: 0.23.16_typescript@4.8.4 typescript: 4.8.4