diff options
author | Sebastian <sebasjm@gmail.com> | 2022-09-05 10:04:56 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-09-05 13:04:31 -0300 |
commit | e0e33a88db7641775de16f5425bfc08e461a4f75 (patch) | |
tree | 678c656c07e0940706d71c06a5bb6650fee2a8c8 /packages/taler-wallet-core | |
parent | 4a0512884d27f9cf576af00f5a58191b1d189188 (diff) |
adding informantion about the service worker version on the setting page
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r-- | packages/taler-wallet-core/rollup.config.js | 24 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 17 |
2 files changed, 41 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/rollup.config.js b/packages/taler-wallet-core/rollup.config.js index 3b6eff3a6..c6cd3ccef 100644 --- a/packages/taler-wallet-core/rollup.config.js +++ b/packages/taler-wallet-core/rollup.config.js @@ -5,6 +5,17 @@ import json from "@rollup/plugin-json"; import builtins from "builtin-modules"; import pkg from "./package.json"; import sourcemaps from "rollup-plugin-sourcemaps"; +import replace from '@rollup/plugin-replace'; +import path from "path" +import fs from "fs" + +const BASE = process.cwd() + +let GIT_ROOT = BASE +while (!fs.existsSync(path.join(GIT_ROOT, '.git')) && GIT_ROOT !== '/') { + GIT_ROOT = path.join(GIT_ROOT, '../') +} +const GIT_HASH = GIT_ROOT === '/' ? undefined : git_hash() const nodeEntryPoint = { input: "lib/index.node.js", @@ -21,6 +32,10 @@ const nodeEntryPoint = { }), sourcemaps(), + replace({ + '__VERSION__': `"${pkg.version}"`, + '__GIT_HASH__': `"${GIT_HASH}"`, + }), commonjs({ include: [/node_modules/, /dist/], @@ -61,3 +76,12 @@ const browserEntryPoint = { }; export default [nodeEntryPoint, browserEntryPoint]; + +function git_hash() { + const rev = fs.readFileSync(path.join(GIT_ROOT, '.git', 'HEAD')).toString().trim().split(/.*[: ]/).slice(-1)[0]; + if (rev.indexOf('/') === -1) { + return rev; + } else { + return fs.readFileSync(path.join(GIT_ROOT, '.git', rev)).toString().trim(); + } +} diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index b3fee6bff..688985521 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -86,6 +86,7 @@ import { TalerErrorCode, URL, WalletNotification, + WalletCoreVersion, } from "@gnu-taler/taler-util"; import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js"; import { @@ -206,6 +207,7 @@ import { } from "./util/promiseUtils.js"; import { DbAccess, GetReadWriteAccess } from "./util/query.js"; import { TimerAPI, TimerGroup } from "./util/timer.js"; +import { WALLET_BANK_INTEGRATION_PROTOCOL_VERSION, WALLET_EXCHANGE_PROTOCOL_VERSION, WALLET_MERCHANT_PROTOCOL_VERSION } from "./versions.js"; import { WalletCoreApiClient } from "./wallet-api-types.js"; const builtinAuditors: AuditorTrustRecord[] = [ @@ -714,6 +716,11 @@ export async function getClientFromWalletState( return client; } +declare const __VERSION__: string; +declare const __GIT_HASH__: string; + +const VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "dev"; +const GIT_HASH = typeof __GIT_HASH__ !== "undefined" ? __GIT_HASH__ : undefined; /** * Implementation of the "wallet-core" API. */ @@ -1064,6 +1071,16 @@ async function dispatchRequestInternal( await acceptPeerPullPayment(ws, req); return {}; } + case "getVersion": { + const version: WalletCoreVersion = { + hash: GIT_HASH, + version: VERSION, + exchange: WALLET_EXCHANGE_PROTOCOL_VERSION, + merchant: WALLET_MERCHANT_PROTOCOL_VERSION, + bank: WALLET_BANK_INTEGRATION_PROTOCOL_VERSION, + } + return version; + } } throw TalerError.fromDetail( TalerErrorCode.WALLET_CORE_API_OPERATION_UNKNOWN, |