@ledgerhq/vault-cli 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
 
2
- > @ledgerhq/vault-cli@2.0.0 build /home/runner/work/vault-ts/vault-ts/apps/cli
2
+ > @ledgerhq/vault-cli@2.1.0 build /home/runner/work/vault-ts/vault-ts/apps/cli
3
3
  > tsup && chmod +x bin/index.js
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -10,9 +10,9 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  CJS Build start
13
- ESM bin/index.mjs 146.68 KB
14
- ESM bin/index.mjs.map 277.63 KB
15
- ESM ⚡️ Build success in 706ms
16
- CJS bin/index.js 148.33 KB
17
- CJS bin/index.js.map 241.32 KB
18
- CJS ⚡️ Build success in 711ms
13
+ ESM bin/index.mjs 148.05 KB
14
+ ESM bin/index.mjs.map 280.24 KB
15
+ ESM ⚡️ Build success in 691ms
16
+ CJS bin/index.js 150.00 KB
17
+ CJS bin/index.js.map 243.45 KB
18
+ CJS ⚡️ Build success in 700ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @ledgerhq/vault-cli
2
2
 
3
+ ## 2.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c8b6804: feat(onboarding): VG-25117 try to deduce cid/selfs/token from minivault instance
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [25931d6]
12
+ - @ledgerhq/vault-common@2.0.1
13
+
3
14
  ## 2.0.0
4
15
 
5
16
  ### Major Changes
package/bin/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- "use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ "use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __getOwnPropNames = Object.getOwnPropertyNames;
3
3
  var __commonJS = (cb, mod) => function __require() {
4
4
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
5
5
  };
@@ -9,7 +9,7 @@ var require_package = __commonJS({
9
9
  "package.json"(exports, module) {
10
10
  module.exports = {
11
11
  name: "@ledgerhq/vault-cli",
12
- version: "2.0.0",
12
+ version: "2.1.0",
13
13
  description: "A various utility command-line for Vault development",
14
14
  homepage: "https://github.com/LedgerHQ/vault-ts",
15
15
  license: "BSD-2-Clause",
@@ -2112,6 +2112,7 @@ var FORMAT_OPTION = {
2112
2112
  };
2113
2113
 
2114
2114
  // src/revault-compat.ts
2115
+ var _get = require('lodash/get'); var _get2 = _interopRequireDefault(_get);
2115
2116
  var REVAULT_ONBOARDING_OPTIONS = [
2116
2117
  {
2117
2118
  name: "compartmentId",
@@ -2134,19 +2135,44 @@ var REVAULT_ONBOARDING_OPTIONS = [
2134
2135
  description: "{black.bgGreen.bold NEW } The target revault API URL to use for the onboarding"
2135
2136
  }
2136
2137
  ];
2137
- function extractRevaultOnboardingOptions(maybeOptions) {
2138
- if (!maybeOptions) return;
2139
- const revaultApiUrl = maybeOptions.minivaultURL ? (
2140
- /* istanbul ignore next */
2141
- `${maybeOptions.minivaultURL}/api`
2142
- ) : maybeOptions.revaultApiUrl;
2143
- if (maybeOptions.compartmentId !== void 0 && revaultApiUrl !== void 0 && maybeOptions.revaultRootAuthToken !== void 0 && maybeOptions.hsmScriptsVersion !== void 0) {
2144
- return {
2145
- compartmentId: maybeOptions.compartmentId,
2146
- hsmScriptsVersion: maybeOptions.hsmScriptsVersion,
2147
- revaultApiUrl,
2148
- revaultRootAuthToken: maybeOptions.revaultRootAuthToken
2149
- };
2138
+ function extractMinivaultUrlFromGate(gate) {
2139
+ const match = gate.match(/(https?:\/\/[^.]+\.minivault\..*)\//);
2140
+ if (match) {
2141
+ return match[1];
2142
+ }
2143
+ }
2144
+ function getInstanceNameFromMinivaultUrl(minivaultUrl) {
2145
+ const match = minivaultUrl.match(/https?:\/\/([^.]+)\.minivault\..*/);
2146
+ const instanceName = match && match[1];
2147
+ if (!instanceName) {
2148
+ throw new Error(`Could not extract instance name from minivault URL: ${minivaultUrl}`);
2149
+ }
2150
+ return instanceName;
2151
+ }
2152
+ async function extractRevaultOnboardingOptions(maybeOptions) {
2153
+ let compartmentId = maybeOptions.compartmentId;
2154
+ let revaultRootAuthToken = maybeOptions.revaultRootAuthToken;
2155
+ let revaultApiUrl = maybeOptions.revaultApiUrl;
2156
+ let hsmScriptsVersion = maybeOptions.hsmScriptsVersion;
2157
+ if (compartmentId === void 0 || revaultRootAuthToken === void 0 || revaultApiUrl === void 0 || hsmScriptsVersion === void 0) {
2158
+ let minivaultURL = maybeOptions.minivaultURL;
2159
+ const gate = maybeOptions.gate;
2160
+ if (minivaultURL === void 0 && gate !== void 0) {
2161
+ minivaultURL = extractMinivaultUrlFromGate(gate);
2162
+ }
2163
+ if (minivaultURL !== void 0) {
2164
+ const remoteUrl = minivaultURL.replace(/https:\/\/[^.]+/, "https://remote");
2165
+ const instanceName = getInstanceNameFromMinivaultUrl(minivaultURL);
2166
+ const instanceValuesResponse = await fetch(`${remoteUrl}/api/instances/${instanceName}`);
2167
+ const instanceValues = await instanceValuesResponse.json();
2168
+ compartmentId = _nullishCoalesce(compartmentId, () => ( _get2.default.call(void 0, instanceValues, "values.hsm.compartmentID")));
2169
+ hsmScriptsVersion = _nullishCoalesce(hsmScriptsVersion, () => ( _get2.default.call(void 0, instanceValues, "values.gate.hsmScriptsVersion")));
2170
+ revaultApiUrl = _nullishCoalesce(revaultApiUrl, () => ( `${minivaultURL}/api`));
2171
+ revaultRootAuthToken = _nullishCoalesce(revaultRootAuthToken, () => ( "root-auth-token"));
2172
+ }
2173
+ }
2174
+ if (compartmentId !== void 0 && revaultApiUrl !== void 0 && revaultRootAuthToken !== void 0 && hsmScriptsVersion !== void 0) {
2175
+ return { compartmentId, hsmScriptsVersion, revaultApiUrl, revaultRootAuthToken };
2150
2176
  }
2151
2177
  }
2152
2178
 
@@ -2373,7 +2399,7 @@ var bake_default = {
2373
2399
  await _vaultcommon.bakeManifest.call(void 0, manifest, pool, {
2374
2400
  logger: logger_default,
2375
2401
  twoStepsRequest,
2376
- revaultOnboarding: extractRevaultOnboardingOptions(options2)
2402
+ revaultOnboarding: await extractRevaultOnboardingOptions(options2)
2377
2403
  });
2378
2404
  break;
2379
2405
  } catch (err) {
@@ -4352,7 +4378,7 @@ var onboard_default = {
4352
4378
  {
4353
4379
  logger: logger_default,
4354
4380
  untilStep,
4355
- revaultOnboarding: extractRevaultOnboardingOptions(options2)
4381
+ revaultOnboarding: await extractRevaultOnboardingOptions(options2)
4356
4382
  }
4357
4383
  );
4358
4384
  }