@ledgerhq/live-cli 24.10.2 → 24.10.3-nightly.1

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.
Files changed (153) hide show
  1. package/lib/cli.js +33 -63
  2. package/lib/cli.js.map +1 -1
  3. package/lib/commands/blockchain/bot.js +7 -7
  4. package/lib/commands/blockchain/bot.js.map +1 -1
  5. package/lib/commands/blockchain/botPortfolio.js +22 -26
  6. package/lib/commands/blockchain/botPortfolio.js.map +1 -1
  7. package/lib/commands/blockchain/botTransfer.js +219 -392
  8. package/lib/commands/blockchain/botTransfer.js.map +1 -1
  9. package/lib/commands/blockchain/broadcast.js +11 -42
  10. package/lib/commands/blockchain/broadcast.js.map +1 -1
  11. package/lib/commands/blockchain/confirmOp.js +12 -52
  12. package/lib/commands/blockchain/confirmOp.js.map +1 -1
  13. package/lib/commands/blockchain/derivation.js +31 -33
  14. package/lib/commands/blockchain/derivation.js.map +1 -1
  15. package/lib/commands/blockchain/estimateMaxSpendable.js +27 -56
  16. package/lib/commands/blockchain/estimateMaxSpendable.js.map +1 -1
  17. package/lib/commands/blockchain/generateTestScanAccounts.js +29 -37
  18. package/lib/commands/blockchain/generateTestScanAccounts.js.map +1 -1
  19. package/lib/commands/blockchain/generateTestTransaction.js +70 -96
  20. package/lib/commands/blockchain/generateTestTransaction.js.map +1 -1
  21. package/lib/commands/blockchain/getAddress.js +20 -24
  22. package/lib/commands/blockchain/getAddress.js.map +1 -1
  23. package/lib/commands/blockchain/getTransactionStatus.js +31 -69
  24. package/lib/commands/blockchain/getTransactionStatus.js.map +1 -1
  25. package/lib/commands/blockchain/receive.js +14 -42
  26. package/lib/commands/blockchain/receive.js.map +1 -1
  27. package/lib/commands/blockchain/satstack.js +30 -33
  28. package/lib/commands/blockchain/satstack.js.map +1 -1
  29. package/lib/commands/blockchain/satstackStatus.js +4 -5
  30. package/lib/commands/blockchain/satstackStatus.js.map +1 -1
  31. package/lib/commands/blockchain/scanDescriptors.js +8 -14
  32. package/lib/commands/blockchain/scanDescriptors.js.map +1 -1
  33. package/lib/commands/blockchain/send.js +61 -90
  34. package/lib/commands/blockchain/send.js.map +1 -1
  35. package/lib/commands/blockchain/signMessage.d.ts +1 -1
  36. package/lib/commands/blockchain/signMessage.js +15 -40
  37. package/lib/commands/blockchain/signMessage.js.map +1 -1
  38. package/lib/commands/blockchain/sync.js +27 -120
  39. package/lib/commands/blockchain/sync.js.map +1 -1
  40. package/lib/commands/blockchain/testDetectOpCollision.js +15 -48
  41. package/lib/commands/blockchain/testDetectOpCollision.js.map +1 -1
  42. package/lib/commands/blockchain/testGetTrustedInputFromTxHash.js +37 -86
  43. package/lib/commands/blockchain/testGetTrustedInputFromTxHash.js.map +1 -1
  44. package/lib/commands/device/app.js +42 -76
  45. package/lib/commands/device/app.js.map +1 -1
  46. package/lib/commands/device/appUninstallAll.d.ts +1 -1
  47. package/lib/commands/device/appUninstallAll.js +22 -29
  48. package/lib/commands/device/appUninstallAll.js.map +1 -1
  49. package/lib/commands/device/appsCheckAllAppVersions.js +208 -361
  50. package/lib/commands/device/appsCheckAllAppVersions.js.map +1 -1
  51. package/lib/commands/device/appsInstallAll.js +15 -24
  52. package/lib/commands/device/appsInstallAll.js.map +1 -1
  53. package/lib/commands/device/appsUpdateTestAll.js +69 -80
  54. package/lib/commands/device/appsUpdateTestAll.js.map +1 -1
  55. package/lib/commands/device/cleanSpeculos.js +4 -4
  56. package/lib/commands/device/cleanSpeculos.js.map +1 -1
  57. package/lib/commands/device/customLockScreenFetch.js +37 -84
  58. package/lib/commands/device/customLockScreenFetch.js.map +1 -1
  59. package/lib/commands/device/customLockScreenFetchAndRestore.js +46 -110
  60. package/lib/commands/device/customLockScreenFetchAndRestore.js.map +1 -1
  61. package/lib/commands/device/customLockScreenFetchHash.js +5 -7
  62. package/lib/commands/device/customLockScreenFetchHash.js.map +1 -1
  63. package/lib/commands/device/customLockScreenLoad.js +25 -72
  64. package/lib/commands/device/customLockScreenLoad.js.map +1 -1
  65. package/lib/commands/device/customLockScreenRemove.js +5 -7
  66. package/lib/commands/device/customLockScreenRemove.js.map +1 -1
  67. package/lib/commands/device/devDeviceAppsScenario.js +33 -65
  68. package/lib/commands/device/devDeviceAppsScenario.js.map +1 -1
  69. package/lib/commands/device/deviceAppVersion.js +5 -8
  70. package/lib/commands/device/deviceAppVersion.js.map +1 -1
  71. package/lib/commands/device/deviceInfo.js +5 -8
  72. package/lib/commands/device/deviceInfo.js.map +1 -1
  73. package/lib/commands/device/deviceSDKFirmwareUpdate.js +22 -68
  74. package/lib/commands/device/deviceSDKFirmwareUpdate.js.map +1 -1
  75. package/lib/commands/device/deviceSDKGetBatteryStatuses.js +7 -8
  76. package/lib/commands/device/deviceSDKGetBatteryStatuses.js.map +1 -1
  77. package/lib/commands/device/deviceSDKGetDeviceInfo.js +6 -7
  78. package/lib/commands/device/deviceSDKGetDeviceInfo.js.map +1 -1
  79. package/lib/commands/device/deviceSDKToggleOnboardingEarlyCheck.js +8 -9
  80. package/lib/commands/device/deviceSDKToggleOnboardingEarlyCheck.js.map +1 -1
  81. package/lib/commands/device/deviceVersion.js +5 -8
  82. package/lib/commands/device/deviceVersion.js.map +1 -1
  83. package/lib/commands/device/discoverDevices.js +15 -50
  84. package/lib/commands/device/discoverDevices.js.map +1 -1
  85. package/lib/commands/device/firmwareRepair.js +3 -6
  86. package/lib/commands/device/firmwareRepair.js.map +1 -1
  87. package/lib/commands/device/firmwareUpdate.js +63 -123
  88. package/lib/commands/device/firmwareUpdate.js.map +1 -1
  89. package/lib/commands/device/genuineCheck.js +7 -12
  90. package/lib/commands/device/genuineCheck.js.map +1 -1
  91. package/lib/commands/device/getBatteryStatus.js +5 -9
  92. package/lib/commands/device/getBatteryStatus.js.map +1 -1
  93. package/lib/commands/device/getDeviceRunningMode.js +7 -10
  94. package/lib/commands/device/getDeviceRunningMode.js.map +1 -1
  95. package/lib/commands/device/i18n.js +27 -79
  96. package/lib/commands/device/i18n.js.map +1 -1
  97. package/lib/commands/device/listApps.d.ts +1 -1
  98. package/lib/commands/device/listApps.js +7 -12
  99. package/lib/commands/device/listApps.js.map +1 -1
  100. package/lib/commands/device/managerListApps.js +21 -28
  101. package/lib/commands/device/managerListApps.js.map +1 -1
  102. package/lib/commands/device/proxy.js +242 -350
  103. package/lib/commands/device/proxy.js.map +1 -1
  104. package/lib/commands/device/reinstallConfigurationConsent.js +36 -126
  105. package/lib/commands/device/reinstallConfigurationConsent.js.map +1 -1
  106. package/lib/commands/device/repl.js +5 -10
  107. package/lib/commands/device/repl.js.map +1 -1
  108. package/lib/commands/device/speculosList.js +12 -58
  109. package/lib/commands/device/speculosList.js.map +1 -1
  110. package/lib/commands/live/balanceHistory.js +44 -79
  111. package/lib/commands/live/balanceHistory.js.map +1 -1
  112. package/lib/commands/live/countervalues.js +111 -207
  113. package/lib/commands/live/countervalues.js.map +1 -1
  114. package/lib/commands/live/envs.js +4 -6
  115. package/lib/commands/live/envs.js.map +1 -1
  116. package/lib/commands/live/exportAccounts.js +30 -56
  117. package/lib/commands/live/exportAccounts.js.map +1 -1
  118. package/lib/commands/live/ledgerKeyRingProtocol.d.ts +1 -1
  119. package/lib/commands/live/ledgerKeyRingProtocol.js +63 -103
  120. package/lib/commands/live/ledgerKeyRingProtocol.js.map +1 -1
  121. package/lib/commands/live/ledgerSync.js +20 -60
  122. package/lib/commands/live/ledgerSync.js.map +1 -1
  123. package/lib/commands/live/liveData.js +34 -60
  124. package/lib/commands/live/liveData.js.map +1 -1
  125. package/lib/commands/live/portfolio.js +68 -98
  126. package/lib/commands/live/portfolio.js.map +1 -1
  127. package/lib/commands/live/synchronousOnboarding.js +6 -9
  128. package/lib/commands/live/synchronousOnboarding.js.map +1 -1
  129. package/lib/commands/live/user.js +4 -4
  130. package/lib/commands/live/user.js.map +1 -1
  131. package/lib/commands/live/version.js +2 -4
  132. package/lib/commands/live/version.js.map +1 -1
  133. package/lib/commands/ptx/swap.d.ts.map +1 -1
  134. package/lib/commands/ptx/swap.js +194 -280
  135. package/lib/commands/ptx/swap.js.map +1 -1
  136. package/lib/commands-index.d.ts +9 -9
  137. package/lib/commands-index.js +64 -64
  138. package/lib/commands-index.js.map +1 -1
  139. package/lib/live-common-setup-base.js +28 -48
  140. package/lib/live-common-setup-base.js.map +1 -1
  141. package/lib/live-common-setup.js +66 -123
  142. package/lib/live-common-setup.js.map +1 -1
  143. package/lib/qr.js +6 -10
  144. package/lib/qr.js.map +1 -1
  145. package/lib/scan.js +84 -92
  146. package/lib/scan.js.map +1 -1
  147. package/lib/signedOperation.js +6 -6
  148. package/lib/signedOperation.js.map +1 -1
  149. package/lib/stream.js +57 -68
  150. package/lib/stream.js.map +1 -1
  151. package/lib/transaction.js +60 -142
  152. package/lib/transaction.js.map +1 -1
  153. package/package.json +7 -7
@@ -1,132 +1,60 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __read = (this && this.__read) || function (o, n) {
39
- var m = typeof Symbol === "function" && o[Symbol.iterator];
40
- if (!m) return o;
41
- var i = m.call(o), r, ar = [], e;
42
- try {
43
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
44
- }
45
- catch (error) { e = { error: error }; }
46
- finally {
47
- try {
48
- if (r && !r.done && (m = i["return"])) m.call(i);
49
- }
50
- finally { if (e) throw e.error; }
51
- }
52
- return ar;
53
- };
54
- var __values = (this && this.__values) || function(o) {
55
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
56
- if (m) return m.call(o);
57
- if (o && typeof o.length === "number") return {
58
- next: function () {
59
- if (o && i >= o.length) o = void 0;
60
- return { value: o && o[i++], done: !o };
61
- }
62
- };
63
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
64
- };
65
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
66
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
67
- if (ar || !(i in from)) {
68
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
69
- ar[i] = from[i];
70
- }
71
- }
72
- return to.concat(ar || Array.prototype.slice.call(from));
73
- };
74
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
75
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
76
4
  };
77
5
  Object.defineProperty(exports, "__esModule", { value: true });
78
6
  /* eslint-disable no-console */
79
- var invariant_1 = __importDefault(require("invariant"));
80
- var fs_1 = __importDefault(require("fs"));
81
- var rxjs_1 = require("rxjs");
82
- var operators_1 = require("rxjs/operators");
83
- var deviceAccess_1 = require("@ledgerhq/live-common/hw/deviceAccess");
84
- var getDeviceInfo_1 = __importDefault(require("@ledgerhq/live-common/hw/getDeviceInfo"));
85
- var api_1 = __importDefault(require("@ledgerhq/live-common/manager/api"));
86
- var network_1 = __importDefault(require("@ledgerhq/live-network/network"));
87
- var installApp_1 = __importDefault(require("@ledgerhq/live-common/hw/installApp"));
88
- var uninstallApp_1 = __importDefault(require("@ledgerhq/live-common/hw/uninstallApp"));
89
- var index_1 = require("@ledgerhq/live-common/apps/index");
90
- var listAppsUseCase_1 = require("@ledgerhq/live-common/device/use-cases/listAppsUseCase");
91
- var execWithTransport_1 = require("@ledgerhq/live-common/device/use-cases/execWithTransport");
92
- var promise_1 = require("@ledgerhq/live-common/promise");
93
- var live_env_1 = require("@ledgerhq/live-env");
94
- var polyfill_1 = require("@ledgerhq/live-common/apps/polyfill");
95
- var scan_1 = require("../../scan");
96
- var blacklistApps = ["Fido U2F", "Security Key"];
97
- var MemoFile = /** @class */ (function () {
98
- function MemoFile(file) {
7
+ const invariant_1 = __importDefault(require("invariant"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const rxjs_1 = require("rxjs");
10
+ const operators_1 = require("rxjs/operators");
11
+ const deviceAccess_1 = require("@ledgerhq/live-common/hw/deviceAccess");
12
+ const getDeviceInfo_1 = __importDefault(require("@ledgerhq/live-common/hw/getDeviceInfo"));
13
+ const api_1 = __importDefault(require("@ledgerhq/live-common/manager/api"));
14
+ const network_1 = __importDefault(require("@ledgerhq/live-network/network"));
15
+ const installApp_1 = __importDefault(require("@ledgerhq/live-common/hw/installApp"));
16
+ const uninstallApp_1 = __importDefault(require("@ledgerhq/live-common/hw/uninstallApp"));
17
+ const index_1 = require("@ledgerhq/live-common/apps/index");
18
+ const listAppsUseCase_1 = require("@ledgerhq/live-common/device/use-cases/listAppsUseCase");
19
+ const execWithTransport_1 = require("@ledgerhq/live-common/device/use-cases/execWithTransport");
20
+ const promise_1 = require("@ledgerhq/live-common/promise");
21
+ const live_env_1 = require("@ledgerhq/live-env");
22
+ const polyfill_1 = require("@ledgerhq/live-common/apps/polyfill");
23
+ const scan_1 = require("../../scan");
24
+ const blacklistApps = ["Fido U2F", "Security Key"];
25
+ class MemoFile {
26
+ file;
27
+ constructor(file) {
99
28
  this.file = file;
100
29
  }
101
- MemoFile.prototype.readResults = function () {
102
- var _this = this;
103
- return new Promise(function (resolve, reject) {
104
- fs_1.default.readFile(_this.file, "utf8", function (err, data) {
30
+ readResults() {
31
+ return new Promise((resolve, reject) => {
32
+ fs_1.default.readFile(this.file, "utf8", (err, data) => {
105
33
  if (err)
106
34
  return reject(err);
107
35
  resolve(data
108
36
  .split("\n")
109
- .map(function (line) {
110
- var _a = __read(line.split(":").map(function (s) { return s.trim(); })), versionIdStr = _a[0], appPath = _a[1], status = _a[2], rest = _a.slice(3);
111
- var error = rest.join(": ");
112
- var versionId = parseInt(versionIdStr, 10);
37
+ .map((line) => {
38
+ const [versionIdStr, appPath, status, ...rest] = line.split(":").map(s => s.trim());
39
+ const error = rest.join(": ");
40
+ const versionId = parseInt(versionIdStr, 10);
113
41
  if (isNaN(versionId) || !isFinite(versionId) || versionId <= 0) {
114
42
  return;
115
43
  }
116
44
  if (versionId && appPath) {
117
45
  if (status === "OK") {
118
46
  return {
119
- versionId: versionId,
120
- appPath: appPath,
47
+ versionId,
48
+ appPath,
121
49
  status: "OK",
122
50
  };
123
51
  }
124
52
  else if (status === "KO" && typeof error === "string") {
125
53
  return {
126
- versionId: versionId,
127
- appPath: appPath,
54
+ versionId,
55
+ appPath,
128
56
  status: "KO",
129
- error: error,
57
+ error,
130
58
  };
131
59
  }
132
60
  }
@@ -134,148 +62,98 @@ var MemoFile = /** @class */ (function () {
134
62
  .filter(Boolean));
135
63
  });
136
64
  });
137
- };
138
- MemoFile.prototype.writeResults = function (results) {
139
- var _this = this;
140
- var data = results
65
+ }
66
+ writeResults(results) {
67
+ const data = results
141
68
  .slice(0)
142
- .sort(function (a, b) {
143
- return 1000000 * a.status.localeCompare(b.status) +
144
- 100000 * a.appPath.localeCompare(b.appPath) +
145
- (a.versionId - b.versionId);
146
- })
147
- .map(function (result) {
148
- return [
149
- result.versionId,
150
- result.appPath,
151
- result.status,
152
- result.status === "KO" ? result.error : "",
153
- ].join(": ");
154
- })
69
+ .sort((a, b) => 1000000 * a.status.localeCompare(b.status) +
70
+ 100000 * a.appPath.localeCompare(b.appPath) +
71
+ (a.versionId - b.versionId))
72
+ .map(result => [
73
+ result.versionId,
74
+ result.appPath,
75
+ result.status,
76
+ result.status === "KO" ? result.error : "",
77
+ ].join(": "))
155
78
  .join("\n");
156
- return new Promise(function (resolve, reject) {
157
- fs_1.default.writeFile(_this.file, data, "utf8", function (err) {
79
+ return new Promise((resolve, reject) => {
80
+ fs_1.default.writeFile(this.file, data, "utf8", err => {
158
81
  if (err)
159
82
  reject(err);
160
83
  else
161
84
  resolve();
162
85
  });
163
86
  });
164
- };
165
- return MemoFile;
166
- }());
167
- var results = [];
168
- var memoFile;
169
- var getAPIDeviceVersionIds = function (deviceInfo) { return __awaiter(void 0, void 0, void 0, function () {
170
- var targetId, data, all, data_1, data_1_1, device, _a, _b, deviceVersion;
171
- var e_1, _c, e_2, _d;
172
- return __generator(this, function (_e) {
173
- switch (_e.label) {
174
- case 0:
175
- targetId = String(deviceInfo.targetId);
176
- return [4 /*yield*/, (0, network_1.default)({
177
- method: "GET",
178
- url: "".concat((0, live_env_1.getEnv)("MANAGER_API_BASE"), "/devices"),
179
- })];
180
- case 1:
181
- data = (_e.sent()).data;
182
- all = [];
183
- try {
184
- for (data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
185
- device = data_1_1.value;
186
- try {
187
- for (_a = (e_2 = void 0, __values(device.device_versions)), _b = _a.next(); !_b.done; _b = _a.next()) {
188
- deviceVersion = _b.value;
189
- if (deviceVersion.target_id === targetId) {
190
- all.push(deviceVersion.id);
191
- }
192
- }
193
- }
194
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
195
- finally {
196
- try {
197
- if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
198
- }
199
- finally { if (e_2) throw e_2.error; }
200
- }
201
- }
202
- }
203
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
204
- finally {
205
- try {
206
- if (data_1_1 && !data_1_1.done && (_c = data_1.return)) _c.call(data_1);
207
- }
208
- finally { if (e_1) throw e_1.error; }
209
- }
210
- return [2 /*return*/, all];
211
- }
87
+ }
88
+ }
89
+ let results = [];
90
+ let memoFile;
91
+ const getAPIDeviceVersionIds = async (deviceInfo) => {
92
+ const targetId = String(deviceInfo.targetId);
93
+ const { data } = await (0, network_1.default)({
94
+ method: "GET",
95
+ url: `${(0, live_env_1.getEnv)("MANAGER_API_BASE")}/devices`,
212
96
  });
213
- }); };
214
- var compatibleAppVersion = function (v, deviceVersionIds, deviceModel, deviceInfo) {
215
- return v.providers.includes(1) &&
216
- deviceVersionIds.some(function (id) { return v.device_versions.includes(id); }) && // heuristic to see if app is compatible...
217
- v.firmware.startsWith(deviceModel.id.toLowerCase() + "/" + deviceInfo.version);
218
- };
219
- var findCandidates = function (deviceModel, applications, deviceInfo) { return __awaiter(void 0, void 0, void 0, function () {
220
- var deviceVersionIds, candidates;
221
- return __generator(this, function (_a) {
222
- switch (_a.label) {
223
- case 0:
224
- console.log(deviceInfo);
225
- return [4 /*yield*/, getAPIDeviceVersionIds(deviceInfo)];
226
- case 1:
227
- deviceVersionIds = _a.sent();
228
- if (!deviceVersionIds.length)
229
- throw new Error("unknown device version plugged");
230
- candidates = applications
231
- .filter(function (a) { return !blacklistApps.includes(a.name); })
232
- .flatMap(function (app) {
233
- var deps = (0, polyfill_1.getDependencies)(app.name);
234
- return app.application_versions
235
- .filter(function (v) { return compatibleAppVersion(v, deviceVersionIds, deviceModel, deviceInfo); })
236
- .map(function (version) {
237
- return {
238
- app: app,
239
- version: version,
240
- installQueue: __spreadArray(__spreadArray([], __read(deps
241
- .map(function (name) {
242
- var depApp = applications.find(function (a) { return a.name === name; });
243
- return depApp
244
- ? depApp.application_versions.find(function (v) {
245
- return compatibleAppVersion(v, deviceVersionIds, deviceModel, deviceInfo) &&
246
- v.version === version.version;
247
- })
248
- : null;
249
- })
250
- .filter(Boolean)), false), [
251
- version,
252
- ], false),
253
- };
254
- });
255
- });
256
- if (process.env.RANDOM_APPS_ORDER) {
257
- candidates.sort(function () { return Math.random() - 0.5; });
258
- }
259
- return [2 /*return*/, candidates];
97
+ const all = [];
98
+ for (const device of data) {
99
+ for (const deviceVersion of device.device_versions) {
100
+ if (deviceVersion.target_id === targetId) {
101
+ all.push(deviceVersion.id);
102
+ }
260
103
  }
261
- });
262
- }); };
263
- var installCandidate = function (t, deviceInfo, candidate) {
264
- return rxjs_1.concat.apply(void 0, __spreadArray([], __read(candidate.installQueue.flatMap(function (app) { return [
265
- (0, rxjs_1.defer)(function () { return (0, promise_1.delay)((0, live_env_1.getEnv)("MANAGER_INSTALL_DELAY")); }),
266
- (0, rxjs_1.defer)(function () { return (0, installApp_1.default)(t, deviceInfo.targetId, app); }),
267
- ]; })), false));
104
+ }
105
+ return all;
268
106
  };
269
- var uninstallCandidate = function (t, deviceInfo, candidate) {
270
- return rxjs_1.concat.apply(void 0, __spreadArray([], __read(candidate.installQueue
271
- .slice(0)
272
- .reverse()
273
- .flatMap(function (app) { return [
274
- (0, rxjs_1.defer)(function () { return (0, promise_1.delay)((0, live_env_1.getEnv)("MANAGER_INSTALL_DELAY")); }),
275
- (0, rxjs_1.defer)(function () { return (0, uninstallApp_1.default)(t, deviceInfo.targetId, app); }),
276
- ]; })), false));
107
+ const compatibleAppVersion = (v, deviceVersionIds, deviceModel, deviceInfo) => v.providers.includes(1) &&
108
+ deviceVersionIds.some(id => v.device_versions.includes(id)) && // heuristic to see if app is compatible...
109
+ v.firmware.startsWith(deviceModel.id.toLowerCase() + "/" + deviceInfo.version);
110
+ const findCandidates = async (deviceModel, applications, deviceInfo) => {
111
+ console.log(deviceInfo);
112
+ const deviceVersionIds = await getAPIDeviceVersionIds(deviceInfo);
113
+ if (!deviceVersionIds.length)
114
+ throw new Error("unknown device version plugged");
115
+ const candidates = applications
116
+ .filter(a => !blacklistApps.includes(a.name))
117
+ .flatMap(app => {
118
+ const deps = (0, polyfill_1.getDependencies)(app.name);
119
+ return app.application_versions
120
+ .filter(v => compatibleAppVersion(v, deviceVersionIds, deviceModel, deviceInfo))
121
+ .map(version => {
122
+ return {
123
+ app,
124
+ version,
125
+ installQueue: [
126
+ ...deps
127
+ .map(name => {
128
+ const depApp = applications.find(a => a.name === name);
129
+ return depApp
130
+ ? depApp.application_versions.find(v => compatibleAppVersion(v, deviceVersionIds, deviceModel, deviceInfo) &&
131
+ v.version === version.version)
132
+ : null;
133
+ })
134
+ .filter(Boolean),
135
+ version,
136
+ ],
137
+ };
138
+ });
139
+ });
140
+ if (process.env.RANDOM_APPS_ORDER) {
141
+ candidates.sort(() => Math.random() - 0.5);
142
+ }
143
+ return candidates;
277
144
  };
278
- var getCandidateName = function (candidate) {
145
+ const installCandidate = (t, deviceInfo, candidate) => (0, rxjs_1.concat)(...candidate.installQueue.flatMap(app => [
146
+ (0, rxjs_1.defer)(() => (0, promise_1.delay)((0, live_env_1.getEnv)("MANAGER_INSTALL_DELAY"))),
147
+ (0, rxjs_1.defer)(() => (0, installApp_1.default)(t, deviceInfo.targetId, app)),
148
+ ]));
149
+ const uninstallCandidate = (t, deviceInfo, candidate) => (0, rxjs_1.concat)(...candidate.installQueue
150
+ .slice(0)
151
+ .reverse()
152
+ .flatMap(app => [
153
+ (0, rxjs_1.defer)(() => (0, promise_1.delay)((0, live_env_1.getEnv)("MANAGER_INSTALL_DELAY"))),
154
+ (0, rxjs_1.defer)(() => (0, uninstallApp_1.default)(t, deviceInfo.targetId, app)),
155
+ ]));
156
+ const getCandidateName = (candidate) => {
279
157
  return (candidate.version.name +
280
158
  " " +
281
159
  candidate.version.version +
@@ -283,14 +161,14 @@ var getCandidateName = function (candidate) {
283
161
  candidate.version.firmware +
284
162
  ")");
285
163
  };
286
- var lastResult;
287
- var checkInstalled = function (installed, candidate) {
288
- var name = getCandidateName(candidate);
289
- var ins = installed.find(function (i) { return i.name === candidate.version.name || i.hash === candidate.version.hash; });
290
- var result;
164
+ let lastResult;
165
+ const checkInstalled = (installed, candidate) => {
166
+ const name = getCandidateName(candidate);
167
+ const ins = installed.find((i) => i.name === candidate.version.name || i.hash === candidate.version.hash);
168
+ let result;
291
169
  if (!ins) {
292
170
  if (installed.length > 0) {
293
- var message = " list apps don't find installed app? Found these: " + JSON.stringify(installed);
171
+ const message = " list apps don't find installed app? Found these: " + JSON.stringify(installed);
294
172
  result = {
295
173
  versionId: candidate.version.id,
296
174
  appPath: candidate.version.firmware,
@@ -308,8 +186,8 @@ var checkInstalled = function (installed, candidate) {
308
186
  }
309
187
  }
310
188
  else {
311
- var hashMatches = ins.hash === candidate.version.hash;
312
- var hasBytes = !!candidate.version.bytes;
189
+ const hashMatches = ins.hash === candidate.version.hash;
190
+ const hasBytes = !!candidate.version.bytes;
313
191
  if (hashMatches && hasBytes) {
314
192
  result = {
315
193
  versionId: candidate.version.id,
@@ -319,7 +197,7 @@ var checkInstalled = function (installed, candidate) {
319
197
  console.log("OK " + name);
320
198
  }
321
199
  else {
322
- var message = (hashMatches
200
+ const message = (hashMatches
323
201
  ? ""
324
202
  : " have BAD HASH. API have " + candidate.version.hash + " but device have " + ins.hash) +
325
203
  (hasBytes ? "" : " DOES NOT have bytes defined!");
@@ -332,25 +210,23 @@ var checkInstalled = function (installed, candidate) {
332
210
  console.error("FAIL " + name + message);
333
211
  }
334
212
  }
335
- results = results.filter(function (r) { return r.versionId !== result.versionId; }).concat(result);
213
+ results = results.filter(r => r.versionId !== result.versionId).concat(result);
336
214
  if (memoFile) {
337
215
  return (0, rxjs_1.from)(memoFile.writeResults(results)).pipe((0, operators_1.ignoreElements)());
338
216
  }
339
217
  return rxjs_1.EMPTY;
340
218
  };
341
- var wipeAll = function (t, deviceInfo) {
342
- return (0, listAppsUseCase_1.listAppsUseCase)(t, deviceInfo).pipe((0, operators_1.filter)(function (e) { return e.type === "result"; }), (0, operators_1.map)(function (e) { return e.result; }), (0, operators_1.mergeMap)(function (listAppsResult) {
343
- var exec = (0, execWithTransport_1.execWithTransport)(t);
344
- var s = (0, index_1.initState)(listAppsResult);
345
- s = (0, index_1.reducer)(s, {
346
- type: "wipe",
347
- });
348
- if (s.uninstallQueue.length) {
349
- console.log("Uninstall " + s.uninstallQueue.length + " app(s)");
350
- }
351
- return (0, index_1.runAll)(s, exec);
352
- }));
353
- };
219
+ const wipeAll = (t, deviceInfo) => (0, listAppsUseCase_1.listAppsUseCase)(t, deviceInfo).pipe((0, operators_1.filter)(e => e.type === "result"), (0, operators_1.map)((e) => e.result), (0, operators_1.mergeMap)(listAppsResult => {
220
+ const exec = (0, execWithTransport_1.execWithTransport)(t);
221
+ let s = (0, index_1.initState)(listAppsResult);
222
+ s = (0, index_1.reducer)(s, {
223
+ type: "wipe",
224
+ });
225
+ if (s.uninstallQueue.length) {
226
+ console.log("Uninstall " + s.uninstallQueue.length + " app(s)");
227
+ }
228
+ return (0, index_1.runAll)(s, exec);
229
+ }));
354
230
  exports.default = {
355
231
  description: "install/uninstall all possible apps available on our API to check all is good (even old app versions)",
356
232
  args: [
@@ -361,110 +237,81 @@ exports.default = {
361
237
  desc: "a file to memorize the previously saved result so we don't run again from the start",
362
238
  },
363
239
  ],
364
- job: function (_a) {
365
- var device = _a.device, memo = _a.memo;
366
- return (0, deviceAccess_1.withDevice)(device || "")(function (t) {
367
- return (0, rxjs_1.from)(Promise.all([(0, getDeviceInfo_1.default)(t), api_1.default.listApps()]).then(function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
368
- var deviceModel, candidates, candidatesErrors, candidatesNew, all;
369
- var _c = __read(_b, 2), deviceInfo = _c[0], applications = _c[1];
370
- return __generator(this, function (_d) {
371
- switch (_d.label) {
372
- case 0:
373
- deviceModel = t.deviceModel;
374
- (0, invariant_1.default)(deviceModel, "device model mandatory");
375
- return [4 /*yield*/, findCandidates(deviceModel, applications, deviceInfo)];
376
- case 1:
377
- candidates = _d.sent();
378
- candidatesErrors = [];
379
- candidatesNew = __spreadArray([], __read(candidates), false);
380
- if (!memo) return [3 /*break*/, 3];
381
- memoFile = new MemoFile(memo);
382
- return [4 /*yield*/, memoFile.readResults()];
383
- case 2:
384
- results = _d.sent();
385
- candidatesErrors = [];
386
- candidatesNew = [];
387
- candidates.forEach(function (c) {
388
- var result = results.find(function (r) { return r.versionId === c.version.id; });
389
- if (process.env.VERBOSE_CANDIDATE) {
390
- console.log(c.version.id, c.version.firmware, result
391
- ? "result was " +
392
- result.status +
393
- (result.status === "KO" ? " " + result.error : "")
394
- : "");
395
- }
396
- if (result) {
397
- if (result.status === "KO") {
398
- candidatesErrors.push(c);
399
- }
400
- }
401
- else {
402
- candidatesNew.push(c);
403
- }
404
- });
405
- _d.label = 3;
406
- case 3:
407
- all = __spreadArray(__spreadArray([], __read(candidatesNew), false), __read(candidatesErrors), false);
408
- if (candidates.length) {
409
- console.log(((100 * (candidates.length - candidatesNew.length)) / candidates.length).toFixed(0) +
410
- "% of apps versions tested. (" +
411
- candidates.length +
412
- " in total. " +
413
- candidatesNew.length +
414
- " new. " +
415
- candidatesErrors.length +
416
- " errors)");
417
- }
418
- else {
419
- console.log("No apps candidate found");
420
- }
421
- return [2 /*return*/, [deviceInfo, all]];
240
+ job: ({ device, memo }) => (0, deviceAccess_1.withDevice)(device || "")(t => {
241
+ return (0, rxjs_1.from)(Promise.all([(0, getDeviceInfo_1.default)(t), api_1.default.listApps()]).then(async ([deviceInfo, applications]) => {
242
+ const { deviceModel } = t;
243
+ (0, invariant_1.default)(deviceModel, "device model mandatory");
244
+ const candidates = await findCandidates(deviceModel, applications, deviceInfo);
245
+ let candidatesErrors = [];
246
+ let candidatesNew = [...candidates];
247
+ if (memo) {
248
+ memoFile = new MemoFile(memo);
249
+ results = await memoFile.readResults();
250
+ candidatesErrors = [];
251
+ candidatesNew = [];
252
+ candidates.forEach(c => {
253
+ const result = results.find(r => r.versionId === c.version.id);
254
+ if (process.env.VERBOSE_CANDIDATE) {
255
+ console.log(c.version.id, c.version.firmware, result
256
+ ? "result was " +
257
+ result.status +
258
+ (result.status === "KO" ? " " + result.error : "")
259
+ : "");
260
+ }
261
+ if (result) {
262
+ if (result.status === "KO") {
263
+ candidatesErrors.push(c);
264
+ }
265
+ }
266
+ else {
267
+ candidatesNew.push(c);
422
268
  }
423
269
  });
424
- }); })).pipe((0, operators_1.mergeMap)(function (_a) {
425
- var _b = __read(_a, 2), deviceInfo = _b[0], candidates = _b[1];
426
- return (0, rxjs_1.concat)(wipeAll(t, deviceInfo).pipe((0, operators_1.ignoreElements)()), (0, rxjs_1.of)([deviceInfo, candidates]));
427
- }), (0, operators_1.mergeMap)(function (_a) {
428
- var _b = __read(_a, 2), deviceInfo = _b[0], candidates = _b[1];
429
- return candidates.reduce(function (acc, candidate) {
430
- return (0, rxjs_1.concat)(acc, (0, rxjs_1.defer)(function () {
431
- return installCandidate(t, deviceInfo, candidate).pipe((0, operators_1.ignoreElements)(), (0, operators_1.catchError)(function (e) {
432
- var result = {
433
- versionId: candidate.version.id,
434
- appPath: candidate.version.firmware,
435
- status: "KO",
436
- error: "FAILED installing, got " + String(e.message),
437
- };
438
- lastResult = result;
439
- results = results
440
- .filter(function (r) { return r.versionId !== result.versionId; })
441
- .concat(result);
442
- console.error("FAILED installing " + getCandidateName(candidate), e);
443
- if (memoFile) {
444
- return (0, rxjs_1.from)(memoFile.writeResults(results)).pipe((0, operators_1.ignoreElements)());
445
- }
446
- return rxjs_1.EMPTY;
447
- }));
448
- }), (0, rxjs_1.defer)(function () { return (0, promise_1.delay)(3000); }).pipe((0, operators_1.ignoreElements)()), (0, rxjs_1.defer)(function () {
449
- return (0, rxjs_1.from)(new Promise(function (resolve, reject) {
450
- api_1.default.listInstalledApps(t, {
451
- targetId: deviceInfo.targetId,
452
- perso: "perso_11",
453
- }).subscribe({
454
- next: function (e) {
455
- if (e.type === "result") {
456
- resolve(e.payload);
457
- }
458
- },
459
- error: reject,
460
- });
461
- })).pipe((0, operators_1.mergeMap)(function (installed) {
462
- return (0, rxjs_1.concat)(checkInstalled(installed, candidate), uninstallCandidate(t, deviceInfo, candidate)).pipe((0, operators_1.ignoreElements)());
463
- }));
464
- }));
465
- }, rxjs_1.EMPTY);
466
- }));
467
- });
468
- },
270
+ }
271
+ const all = [...candidatesNew, ...candidatesErrors];
272
+ if (candidates.length) {
273
+ console.log(((100 * (candidates.length - candidatesNew.length)) / candidates.length).toFixed(0) +
274
+ "% of apps versions tested. (" +
275
+ candidates.length +
276
+ " in total. " +
277
+ candidatesNew.length +
278
+ " new. " +
279
+ candidatesErrors.length +
280
+ " errors)");
281
+ }
282
+ else {
283
+ console.log("No apps candidate found");
284
+ }
285
+ return [deviceInfo, all];
286
+ })).pipe((0, operators_1.mergeMap)(([deviceInfo, candidates]) => (0, rxjs_1.concat)(wipeAll(t, deviceInfo).pipe((0, operators_1.ignoreElements)()), (0, rxjs_1.of)([deviceInfo, candidates]))), (0, operators_1.mergeMap)(([deviceInfo, candidates]) => candidates.reduce((acc, candidate) => (0, rxjs_1.concat)(acc, (0, rxjs_1.defer)(() => installCandidate(t, deviceInfo, candidate).pipe((0, operators_1.ignoreElements)(), (0, operators_1.catchError)(e => {
287
+ const result = {
288
+ versionId: candidate.version.id,
289
+ appPath: candidate.version.firmware,
290
+ status: "KO",
291
+ error: "FAILED installing, got " + String(e.message),
292
+ };
293
+ lastResult = result;
294
+ results = results
295
+ .filter(r => r.versionId !== result.versionId)
296
+ .concat(result);
297
+ console.error("FAILED installing " + getCandidateName(candidate), e);
298
+ if (memoFile) {
299
+ return (0, rxjs_1.from)(memoFile.writeResults(results)).pipe((0, operators_1.ignoreElements)());
300
+ }
301
+ return rxjs_1.EMPTY;
302
+ }))), (0, rxjs_1.defer)(() => (0, promise_1.delay)(3000)).pipe((0, operators_1.ignoreElements)()), (0, rxjs_1.defer)(() => (0, rxjs_1.from)(new Promise((resolve, reject) => {
303
+ api_1.default.listInstalledApps(t, {
304
+ targetId: deviceInfo.targetId,
305
+ perso: "perso_11",
306
+ }).subscribe({
307
+ next: e => {
308
+ if (e.type === "result") {
309
+ resolve(e.payload);
310
+ }
311
+ },
312
+ error: reject,
313
+ });
314
+ })).pipe((0, operators_1.mergeMap)(installed => (0, rxjs_1.concat)(checkInstalled(installed, candidate), uninstallCandidate(t, deviceInfo, candidate)).pipe((0, operators_1.ignoreElements)()))))), rxjs_1.EMPTY)));
315
+ }),
469
316
  };
470
317
  //# sourceMappingURL=appsCheckAllAppVersions.js.map