@ledgerhq/live-cli 24.10.3-nightly.4 → 24.11.0-next.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.
Files changed (152) hide show
  1. package/lib/cli.js +63 -33
  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 +26 -22
  6. package/lib/commands/blockchain/botPortfolio.js.map +1 -1
  7. package/lib/commands/blockchain/botTransfer.js +392 -219
  8. package/lib/commands/blockchain/botTransfer.js.map +1 -1
  9. package/lib/commands/blockchain/broadcast.js +42 -11
  10. package/lib/commands/blockchain/broadcast.js.map +1 -1
  11. package/lib/commands/blockchain/confirmOp.js +52 -12
  12. package/lib/commands/blockchain/confirmOp.js.map +1 -1
  13. package/lib/commands/blockchain/derivation.js +33 -31
  14. package/lib/commands/blockchain/derivation.js.map +1 -1
  15. package/lib/commands/blockchain/estimateMaxSpendable.js +56 -27
  16. package/lib/commands/blockchain/estimateMaxSpendable.js.map +1 -1
  17. package/lib/commands/blockchain/generateTestScanAccounts.js +37 -29
  18. package/lib/commands/blockchain/generateTestScanAccounts.js.map +1 -1
  19. package/lib/commands/blockchain/generateTestTransaction.js +96 -70
  20. package/lib/commands/blockchain/generateTestTransaction.js.map +1 -1
  21. package/lib/commands/blockchain/getAddress.js +24 -20
  22. package/lib/commands/blockchain/getAddress.js.map +1 -1
  23. package/lib/commands/blockchain/getTransactionStatus.js +69 -31
  24. package/lib/commands/blockchain/getTransactionStatus.js.map +1 -1
  25. package/lib/commands/blockchain/receive.js +42 -14
  26. package/lib/commands/blockchain/receive.js.map +1 -1
  27. package/lib/commands/blockchain/satstack.js +33 -30
  28. package/lib/commands/blockchain/satstack.js.map +1 -1
  29. package/lib/commands/blockchain/satstackStatus.js +5 -4
  30. package/lib/commands/blockchain/satstackStatus.js.map +1 -1
  31. package/lib/commands/blockchain/scanDescriptors.js +14 -8
  32. package/lib/commands/blockchain/scanDescriptors.js.map +1 -1
  33. package/lib/commands/blockchain/send.js +90 -61
  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 +40 -15
  37. package/lib/commands/blockchain/signMessage.js.map +1 -1
  38. package/lib/commands/blockchain/sync.js +120 -27
  39. package/lib/commands/blockchain/sync.js.map +1 -1
  40. package/lib/commands/blockchain/testDetectOpCollision.js +48 -15
  41. package/lib/commands/blockchain/testDetectOpCollision.js.map +1 -1
  42. package/lib/commands/blockchain/testGetTrustedInputFromTxHash.js +86 -37
  43. package/lib/commands/blockchain/testGetTrustedInputFromTxHash.js.map +1 -1
  44. package/lib/commands/device/app.js +76 -42
  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 +29 -22
  48. package/lib/commands/device/appUninstallAll.js.map +1 -1
  49. package/lib/commands/device/appsCheckAllAppVersions.js +361 -208
  50. package/lib/commands/device/appsCheckAllAppVersions.js.map +1 -1
  51. package/lib/commands/device/appsInstallAll.js +24 -15
  52. package/lib/commands/device/appsInstallAll.js.map +1 -1
  53. package/lib/commands/device/appsUpdateTestAll.js +80 -69
  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 +84 -37
  58. package/lib/commands/device/customLockScreenFetch.js.map +1 -1
  59. package/lib/commands/device/customLockScreenFetchAndRestore.js +110 -46
  60. package/lib/commands/device/customLockScreenFetchAndRestore.js.map +1 -1
  61. package/lib/commands/device/customLockScreenFetchHash.js +7 -5
  62. package/lib/commands/device/customLockScreenFetchHash.js.map +1 -1
  63. package/lib/commands/device/customLockScreenLoad.js +72 -25
  64. package/lib/commands/device/customLockScreenLoad.js.map +1 -1
  65. package/lib/commands/device/customLockScreenRemove.js +7 -5
  66. package/lib/commands/device/customLockScreenRemove.js.map +1 -1
  67. package/lib/commands/device/devDeviceAppsScenario.js +65 -33
  68. package/lib/commands/device/devDeviceAppsScenario.js.map +1 -1
  69. package/lib/commands/device/deviceAppVersion.js +8 -5
  70. package/lib/commands/device/deviceAppVersion.js.map +1 -1
  71. package/lib/commands/device/deviceInfo.js +8 -5
  72. package/lib/commands/device/deviceInfo.js.map +1 -1
  73. package/lib/commands/device/deviceSDKFirmwareUpdate.js +68 -22
  74. package/lib/commands/device/deviceSDKFirmwareUpdate.js.map +1 -1
  75. package/lib/commands/device/deviceSDKGetBatteryStatuses.js +8 -7
  76. package/lib/commands/device/deviceSDKGetBatteryStatuses.js.map +1 -1
  77. package/lib/commands/device/deviceSDKGetDeviceInfo.js +7 -6
  78. package/lib/commands/device/deviceSDKGetDeviceInfo.js.map +1 -1
  79. package/lib/commands/device/deviceSDKToggleOnboardingEarlyCheck.js +9 -8
  80. package/lib/commands/device/deviceSDKToggleOnboardingEarlyCheck.js.map +1 -1
  81. package/lib/commands/device/deviceVersion.js +8 -5
  82. package/lib/commands/device/deviceVersion.js.map +1 -1
  83. package/lib/commands/device/discoverDevices.js +50 -15
  84. package/lib/commands/device/discoverDevices.js.map +1 -1
  85. package/lib/commands/device/firmwareRepair.js +6 -3
  86. package/lib/commands/device/firmwareRepair.js.map +1 -1
  87. package/lib/commands/device/firmwareUpdate.js +123 -63
  88. package/lib/commands/device/firmwareUpdate.js.map +1 -1
  89. package/lib/commands/device/genuineCheck.js +12 -7
  90. package/lib/commands/device/genuineCheck.js.map +1 -1
  91. package/lib/commands/device/getBatteryStatus.js +9 -5
  92. package/lib/commands/device/getBatteryStatus.js.map +1 -1
  93. package/lib/commands/device/getDeviceRunningMode.js +10 -7
  94. package/lib/commands/device/getDeviceRunningMode.js.map +1 -1
  95. package/lib/commands/device/i18n.js +79 -27
  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 +12 -7
  99. package/lib/commands/device/listApps.js.map +1 -1
  100. package/lib/commands/device/managerListApps.js +28 -21
  101. package/lib/commands/device/managerListApps.js.map +1 -1
  102. package/lib/commands/device/proxy.js +350 -242
  103. package/lib/commands/device/proxy.js.map +1 -1
  104. package/lib/commands/device/reinstallConfigurationConsent.js +126 -36
  105. package/lib/commands/device/reinstallConfigurationConsent.js.map +1 -1
  106. package/lib/commands/device/repl.js +10 -5
  107. package/lib/commands/device/repl.js.map +1 -1
  108. package/lib/commands/device/speculosList.js +58 -12
  109. package/lib/commands/device/speculosList.js.map +1 -1
  110. package/lib/commands/live/balanceHistory.js +79 -44
  111. package/lib/commands/live/balanceHistory.js.map +1 -1
  112. package/lib/commands/live/countervalues.js +207 -111
  113. package/lib/commands/live/countervalues.js.map +1 -1
  114. package/lib/commands/live/envs.js +6 -4
  115. package/lib/commands/live/envs.js.map +1 -1
  116. package/lib/commands/live/exportAccounts.js +56 -30
  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 +103 -63
  120. package/lib/commands/live/ledgerKeyRingProtocol.js.map +1 -1
  121. package/lib/commands/live/ledgerSync.js +60 -20
  122. package/lib/commands/live/ledgerSync.js.map +1 -1
  123. package/lib/commands/live/liveData.js +60 -34
  124. package/lib/commands/live/liveData.js.map +1 -1
  125. package/lib/commands/live/portfolio.js +98 -68
  126. package/lib/commands/live/portfolio.js.map +1 -1
  127. package/lib/commands/live/synchronousOnboarding.js +9 -6
  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 +4 -2
  132. package/lib/commands/live/version.js.map +1 -1
  133. package/lib/commands/ptx/swap.js +282 -194
  134. package/lib/commands/ptx/swap.js.map +1 -1
  135. package/lib/commands-index.d.ts +9 -9
  136. package/lib/commands-index.js +64 -64
  137. package/lib/commands-index.js.map +1 -1
  138. package/lib/live-common-setup-base.js +48 -26
  139. package/lib/live-common-setup-base.js.map +1 -1
  140. package/lib/live-common-setup.js +123 -66
  141. package/lib/live-common-setup.js.map +1 -1
  142. package/lib/qr.js +10 -6
  143. package/lib/qr.js.map +1 -1
  144. package/lib/scan.js +92 -84
  145. package/lib/scan.js.map +1 -1
  146. package/lib/signedOperation.js +6 -6
  147. package/lib/signedOperation.js.map +1 -1
  148. package/lib/stream.js +68 -57
  149. package/lib/stream.js.map +1 -1
  150. package/lib/transaction.js +142 -60
  151. package/lib/transaction.js.map +1 -1
  152. package/package.json +9 -9
@@ -1,60 +1,132 @@
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
+ };
2
74
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
75
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
76
  };
5
77
  Object.defineProperty(exports, "__esModule", { value: true });
6
78
  /* eslint-disable no-console */
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) {
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) {
28
99
  this.file = file;
29
100
  }
30
- readResults() {
31
- return new Promise((resolve, reject) => {
32
- fs_1.default.readFile(this.file, "utf8", (err, data) => {
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) {
33
105
  if (err)
34
106
  return reject(err);
35
107
  resolve(data
36
108
  .split("\n")
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);
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);
41
113
  if (isNaN(versionId) || !isFinite(versionId) || versionId <= 0) {
42
114
  return;
43
115
  }
44
116
  if (versionId && appPath) {
45
117
  if (status === "OK") {
46
118
  return {
47
- versionId,
48
- appPath,
119
+ versionId: versionId,
120
+ appPath: appPath,
49
121
  status: "OK",
50
122
  };
51
123
  }
52
124
  else if (status === "KO" && typeof error === "string") {
53
125
  return {
54
- versionId,
55
- appPath,
126
+ versionId: versionId,
127
+ appPath: appPath,
56
128
  status: "KO",
57
- error,
129
+ error: error,
58
130
  };
59
131
  }
60
132
  }
@@ -62,98 +134,148 @@ class MemoFile {
62
134
  .filter(Boolean));
63
135
  });
64
136
  });
65
- }
66
- writeResults(results) {
67
- const data = results
137
+ };
138
+ MemoFile.prototype.writeResults = function (results) {
139
+ var _this = this;
140
+ var data = results
68
141
  .slice(0)
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(": "))
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
+ })
78
155
  .join("\n");
79
- return new Promise((resolve, reject) => {
80
- fs_1.default.writeFile(this.file, data, "utf8", err => {
156
+ return new Promise(function (resolve, reject) {
157
+ fs_1.default.writeFile(_this.file, data, "utf8", function (err) {
81
158
  if (err)
82
159
  reject(err);
83
160
  else
84
161
  resolve();
85
162
  });
86
163
  });
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`,
96
- });
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
- }
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];
103
211
  }
104
- }
105
- return all;
212
+ });
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);
106
218
  };
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
- });
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];
260
+ }
139
261
  });
140
- if (process.env.RANDOM_APPS_ORDER) {
141
- candidates.sort(() => Math.random() - 0.5);
142
- }
143
- return candidates;
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));
268
+ };
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));
144
277
  };
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) => {
278
+ var getCandidateName = function (candidate) {
157
279
  return (candidate.version.name +
158
280
  " " +
159
281
  candidate.version.version +
@@ -161,14 +283,14 @@ const getCandidateName = (candidate) => {
161
283
  candidate.version.firmware +
162
284
  ")");
163
285
  };
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;
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;
169
291
  if (!ins) {
170
292
  if (installed.length > 0) {
171
- const message = " list apps don't find installed app? Found these: " + JSON.stringify(installed);
293
+ var message = " list apps don't find installed app? Found these: " + JSON.stringify(installed);
172
294
  result = {
173
295
  versionId: candidate.version.id,
174
296
  appPath: candidate.version.firmware,
@@ -186,8 +308,8 @@ const checkInstalled = (installed, candidate) => {
186
308
  }
187
309
  }
188
310
  else {
189
- const hashMatches = ins.hash === candidate.version.hash;
190
- const hasBytes = !!candidate.version.bytes;
311
+ var hashMatches = ins.hash === candidate.version.hash;
312
+ var hasBytes = !!candidate.version.bytes;
191
313
  if (hashMatches && hasBytes) {
192
314
  result = {
193
315
  versionId: candidate.version.id,
@@ -197,7 +319,7 @@ const checkInstalled = (installed, candidate) => {
197
319
  console.log("OK " + name);
198
320
  }
199
321
  else {
200
- const message = (hashMatches
322
+ var message = (hashMatches
201
323
  ? ""
202
324
  : " have BAD HASH. API have " + candidate.version.hash + " but device have " + ins.hash) +
203
325
  (hasBytes ? "" : " DOES NOT have bytes defined!");
@@ -210,23 +332,25 @@ const checkInstalled = (installed, candidate) => {
210
332
  console.error("FAIL " + name + message);
211
333
  }
212
334
  }
213
- results = results.filter(r => r.versionId !== result.versionId).concat(result);
335
+ results = results.filter(function (r) { return r.versionId !== result.versionId; }).concat(result);
214
336
  if (memoFile) {
215
337
  return (0, rxjs_1.from)(memoFile.writeResults(results)).pipe((0, operators_1.ignoreElements)());
216
338
  }
217
339
  return rxjs_1.EMPTY;
218
340
  };
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
- }));
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
+ };
230
354
  exports.default = {
231
355
  description: "install/uninstall all possible apps available on our API to check all is good (even old app versions)",
232
356
  args: [
@@ -237,81 +361,110 @@ exports.default = {
237
361
  desc: "a file to memorize the previously saved result so we don't run again from the start",
238
362
  },
239
363
  ],
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);
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]];
268
422
  }
269
423
  });
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
- }),
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
+ },
316
469
  };
317
470
  //# sourceMappingURL=appsCheckAllAppVersions.js.map