@onekeyfe/hd-core 0.1.0 → 0.1.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.
@@ -1,6 +1,13 @@
1
1
  import { BaseMethod } from './BaseMethod';
2
2
  export default class CheckBLEFirmwareRelease extends BaseMethod {
3
3
  init(): void;
4
- run(): Promise<"valid" | "outdated" | "required" | "unknown" | "none"> | Promise<null>;
4
+ run(): Promise<null> | Promise<{
5
+ status: import("..").IDeviceBLEFirmwareStatus;
6
+ changelog: {
7
+ "zh-CN": string;
8
+ "en-US": string;
9
+ }[];
10
+ release: import("..").IBLEFirmwareReleaseInfo;
11
+ }>;
5
12
  }
6
13
  //# sourceMappingURL=CheckBLEFirmwareRelease.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CheckBLEFirmwareRelease.d.ts","sourceRoot":"","sources":["../../src/api/CheckBLEFirmwareRelease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK1C,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,UAAU;IAC7D,IAAI;IAIJ,GAAG;CAOJ"}
1
+ {"version":3,"file":"CheckBLEFirmwareRelease.d.ts","sourceRoot":"","sources":["../../src/api/CheckBLEFirmwareRelease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK1C,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,UAAU;IAC7D,IAAI;IAIJ,GAAG;;;;;;;;CAaJ"}
@@ -1,6 +1,13 @@
1
1
  import { BaseMethod } from './BaseMethod';
2
2
  export default class CheckFirmwareRelease extends BaseMethod {
3
3
  init(): void;
4
- run(): Promise<"valid" | "outdated" | "required" | "unknown" | "none"> | Promise<null>;
4
+ run(): Promise<{
5
+ status: import("..").IDeviceFirmwareStatus;
6
+ changelog: {
7
+ "zh-CN": string;
8
+ "en-US": string;
9
+ }[];
10
+ release: import("..").IFirmwareReleaseInfo;
11
+ }> | Promise<null>;
5
12
  }
6
13
  //# sourceMappingURL=CheckFirmwareRelease.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CheckFirmwareRelease.d.ts","sourceRoot":"","sources":["../../src/api/CheckFirmwareRelease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,UAAU;IAC1D,IAAI;IAEJ,GAAG;CAOJ"}
1
+ {"version":3,"file":"CheckFirmwareRelease.d.ts","sourceRoot":"","sources":["../../src/api/CheckFirmwareRelease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,UAAU;IAC1D,IAAI;IAEJ,GAAG;;;;;;;;CAaJ"}
@@ -7,7 +7,17 @@ export default class DataManager {
7
7
  default: JSON;
8
8
  };
9
9
  static getFirmwareStatus: (features: Features) => IDeviceFirmwareStatus;
10
+ static getFirmwareChangelog: (features: Features) => {
11
+ "zh-CN": string;
12
+ "en-US": string;
13
+ }[];
14
+ static getFirmwareLeatestRelease: (features: Features) => import("../types").IFirmwareReleaseInfo;
10
15
  static getBLEFirmwareStatus: (features: Features) => IDeviceBLEFirmwareStatus;
16
+ static getBleFirmwareChangelog: (features: Features) => {
17
+ "zh-CN": string;
18
+ "en-US": string;
19
+ }[];
20
+ static getBleFirmwareLeatestRelease: (features: Features) => import("../types").IBLEFirmwareReleaseInfo;
11
21
  static getTransportStatus: (localVersion: string) => ITransportStatus;
12
22
  static load(settings: ConnectSettings): Promise<void>;
13
23
  static getProtobufMessages(): JSON;
@@ -1 +1 @@
1
- {"version":3,"file":"DataManager.d.ts","sourceRoot":"","sources":["../../src/data-manager/DataManager.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,SAAS,EAET,QAAQ,EACR,qBAAqB,EACrB,wBAAwB,EACxB,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAElB,MAAM,CAAC,OAAO,OAAO,WAAW;IAC9B,MAAM,CAAC,SAAS,EAAE,aAAa,CAiB7B;IAEF,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAQ;IAEvC,MAAM,CAAC,QAAQ,EAAE,eAAe,CAAC;IAEjC,MAAM,CAAC,QAAQ,EAAE;QAAE,OAAO,EAAE,IAAI,CAAA;KAAE,CAEhC;IAEF,MAAM,CAAC,iBAAiB,aAAc,QAAQ,KAAG,qBAAqB,CA2BpE;IAEF,MAAM,CAAC,oBAAoB,aAAc,QAAQ,KAAG,wBAAwB,CAyB1E;IAEF,MAAM,CAAC,kBAAkB,iBAAkB,MAAM,KAAG,gBAAgB,CAKlE;WAEW,IAAI,CAAC,QAAQ,EAAE,eAAe;IAoB3C,MAAM,CAAC,mBAAmB;IAI1B,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,SAAS,GAAG,eAAe;IAEpD,MAAM,CAAC,WAAW,CAAC,CAAC,SAAS,MAAM,eAAe,EAAE,GAAG,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC;CAShF"}
1
+ {"version":3,"file":"DataManager.d.ts","sourceRoot":"","sources":["../../src/data-manager/DataManager.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,SAAS,EAET,QAAQ,EACR,qBAAqB,EACrB,wBAAwB,EACxB,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAGlB,MAAM,CAAC,OAAO,OAAO,WAAW;IAC9B,MAAM,CAAC,SAAS,EAAE,aAAa,CAiB7B;IAEF,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAQ;IAEvC,MAAM,CAAC,QAAQ,EAAE,eAAe,CAAC;IAEjC,MAAM,CAAC,QAAQ,EAAE;QAAE,OAAO,EAAE,IAAI,CAAA;KAAE,CAEhC;IAEF,MAAM,CAAC,iBAAiB,aAAc,QAAQ,KAAG,qBAAqB,CAcpE;IAEF,MAAM,CAAC,oBAAoB,aAAc,QAAQ;;;QAc/C;IAEF,MAAM,CAAC,yBAAyB,aAAc,QAAQ,6CAIpD;IAEF,MAAM,CAAC,oBAAoB,aAAc,QAAQ,KAAG,wBAAwB,CAY1E;IAEF,MAAM,CAAC,uBAAuB,aAAc,QAAQ;;;QAWlD;IAEF,MAAM,CAAC,4BAA4B,aAAc,QAAQ,gDAIvD;IAEF,MAAM,CAAC,kBAAkB,iBAAkB,MAAM,KAAG,gBAAgB,CAKlE;WAEW,IAAI,CAAC,QAAQ,EAAE,eAAe;IAoB3C,MAAM,CAAC,mBAAmB;IAI1B,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,SAAS,GAAG,eAAe;IAEpD,MAAM,CAAC,WAAW,CAAC,CAAC,SAAS,MAAM,eAAe,EAAE,GAAG,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC;CAShF"}
package/dist/index.d.ts CHANGED
@@ -213,11 +213,27 @@ declare function searchDevices(): Response<SearchDevice[]>;
213
213
 
214
214
  declare function getFeatures(connectId?: string): Response<Features>;
215
215
 
216
- declare function checkFirmwareRelease(connectId?: string): Response<IDeviceFirmwareStatus>;
216
+ declare type FirmwareRelease$1 = {
217
+ status: IDeviceFirmwareStatus;
218
+ changelog: {
219
+ 'en-US': string;
220
+ 'zh-CN': string;
221
+ }[];
222
+ release: IFirmwareReleaseInfo;
223
+ };
224
+ declare function checkFirmwareRelease(connectId?: string): Response<FirmwareRelease$1>;
217
225
 
218
226
  declare function init$1(settings: Partial<ConnectSettings>): Promise<boolean>;
219
227
 
220
- declare function checkBLEFirmwareRelease(connectId?: string): Response<IDeviceFirmwareStatus>;
228
+ declare type BleFirmwareRelease = {
229
+ status: IDeviceBLEFirmwareStatus;
230
+ changelog: {
231
+ 'zh-CN': string;
232
+ 'en-US': string;
233
+ }[];
234
+ release: IBLEFirmwareReleaseInfo;
235
+ };
236
+ declare function checkBLEFirmwareRelease(connectId?: string): Response<BleFirmwareRelease>;
221
237
 
222
238
  interface FirmwareRange {
223
239
  '1': {
@@ -1350,7 +1366,17 @@ declare class DataManager {
1350
1366
  default: JSON;
1351
1367
  };
1352
1368
  static getFirmwareStatus: (features: Features) => IDeviceFirmwareStatus;
1369
+ static getFirmwareChangelog: (features: Features) => {
1370
+ "zh-CN": string;
1371
+ "en-US": string;
1372
+ }[];
1373
+ static getFirmwareLeatestRelease: (features: Features) => IFirmwareReleaseInfo;
1353
1374
  static getBLEFirmwareStatus: (features: Features) => IDeviceBLEFirmwareStatus;
1375
+ static getBleFirmwareChangelog: (features: Features) => {
1376
+ "zh-CN": string;
1377
+ "en-US": string;
1378
+ }[];
1379
+ static getBleFirmwareLeatestRelease: (features: Features) => IBLEFirmwareReleaseInfo;
1354
1380
  static getTransportStatus: (localVersion: string) => ITransportStatus;
1355
1381
  static load(settings: ConnectSettings): Promise<void>;
1356
1382
  static getProtobufMessages(): JSON;
package/dist/index.js CHANGED
@@ -9754,6 +9754,21 @@ var MessagesJSON = {
9754
9754
  nested: nested
9755
9755
  };
9756
9756
 
9757
+ const getReleaseStatus = (releases, currentVersion) => {
9758
+ const newVersions = releases.filter(r => semver__default["default"].gt(r.version.join('.'), currentVersion));
9759
+ if (newVersions.length === 0) {
9760
+ return 'valid';
9761
+ }
9762
+ if (newVersions.some(r => r.required)) {
9763
+ return 'required';
9764
+ }
9765
+ return 'outdated';
9766
+ };
9767
+ const getReleaseChangelog = (releases, currentVersion) => {
9768
+ const newVersions = releases.filter(r => semver__default["default"].gt(r.version.join('.'), currentVersion));
9769
+ return newVersions.map(r => r.changelog);
9770
+ };
9771
+
9757
9772
  var _a;
9758
9773
  class DataManager {
9759
9774
  static load(settings) {
@@ -9821,17 +9836,26 @@ DataManager.getFirmwareStatus = (features) => {
9821
9836
  return 'unknown';
9822
9837
  }
9823
9838
  const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.firmware) !== null && _c !== void 0 ? _c : [];
9824
- const latestFirmware = targetDeviceConfigList[targetDeviceConfigList.length - 1];
9825
- if (!latestFirmware)
9826
- return 'valid';
9827
- const latestVersion = latestFirmware.version.join('.');
9828
9839
  const currentVersion = deviceFirmwareVersion.join('.');
9829
- if (semver__default["default"].gt(latestVersion, currentVersion)) {
9830
- if (latestFirmware.required)
9831
- return 'required';
9832
- return 'outdated';
9840
+ return getReleaseStatus(targetDeviceConfigList, currentVersion);
9841
+ };
9842
+ DataManager.getFirmwareChangelog = (features) => {
9843
+ var _b, _c;
9844
+ const deviceType = getDeviceType(features);
9845
+ const deviceFirmwareVersion = getDeviceFirmwareVersion(features);
9846
+ if (features.firmware_present === false ||
9847
+ (deviceType === 'classic' && features.bootloader_mode)) {
9848
+ return [];
9833
9849
  }
9834
- return 'valid';
9850
+ const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.firmware) !== null && _c !== void 0 ? _c : [];
9851
+ const currentVersion = deviceFirmwareVersion.join('.');
9852
+ return getReleaseChangelog(targetDeviceConfigList, currentVersion);
9853
+ };
9854
+ DataManager.getFirmwareLeatestRelease = (features) => {
9855
+ var _b, _c;
9856
+ const deviceType = getDeviceType(features);
9857
+ const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.firmware) !== null && _c !== void 0 ? _c : [];
9858
+ return targetDeviceConfigList[targetDeviceConfigList.length - 1];
9835
9859
  };
9836
9860
  DataManager.getBLEFirmwareStatus = (features) => {
9837
9861
  var _b, _c;
@@ -9841,17 +9865,25 @@ DataManager.getBLEFirmwareStatus = (features) => {
9841
9865
  return 'none';
9842
9866
  }
9843
9867
  const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.ble) !== null && _c !== void 0 ? _c : [];
9844
- const latestBLEFirmware = targetDeviceConfigList[targetDeviceConfigList.length - 1];
9845
- if (!latestBLEFirmware)
9846
- return 'valid';
9847
- const latestVersion = latestBLEFirmware.version.join('.');
9848
9868
  const currentVersion = deviceBLEFirmwareVersion.join('.');
9849
- if (semver__default["default"].gt(latestVersion, currentVersion)) {
9850
- if (latestBLEFirmware.required)
9851
- return 'required';
9852
- return 'outdated';
9869
+ return getReleaseStatus(targetDeviceConfigList, currentVersion);
9870
+ };
9871
+ DataManager.getBleFirmwareChangelog = (features) => {
9872
+ var _b, _c;
9873
+ const deviceType = getDeviceType(features);
9874
+ const deviceBLEFirmwareVersion = getDeviceBLEFirmwareVersion(features);
9875
+ if (!deviceBLEFirmwareVersion) {
9876
+ return [];
9853
9877
  }
9854
- return 'valid';
9878
+ const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.ble) !== null && _c !== void 0 ? _c : [];
9879
+ const currentVersion = deviceBLEFirmwareVersion.join('.');
9880
+ return getReleaseChangelog(targetDeviceConfigList, currentVersion);
9881
+ };
9882
+ DataManager.getBleFirmwareLeatestRelease = (features) => {
9883
+ var _b, _c;
9884
+ const deviceType = getDeviceType(features);
9885
+ const targetDeviceConfigList = (_c = (_b = _a.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.ble) !== null && _c !== void 0 ? _c : [];
9886
+ return targetDeviceConfigList[targetDeviceConfigList.length - 1];
9855
9887
  };
9856
9888
  DataManager.getTransportStatus = (localVersion) => {
9857
9889
  var _b, _c;
@@ -11562,7 +11594,13 @@ class CheckFirmwareRelease extends BaseMethod {
11562
11594
  run() {
11563
11595
  if (this.device.features) {
11564
11596
  const firmwareStatus = DataManager.getFirmwareStatus(this.device.features);
11565
- return Promise.resolve(firmwareStatus);
11597
+ const changelog = DataManager.getFirmwareChangelog(this.device.features);
11598
+ const release = DataManager.getFirmwareLeatestRelease(this.device.features);
11599
+ return Promise.resolve({
11600
+ status: firmwareStatus,
11601
+ changelog,
11602
+ release,
11603
+ });
11566
11604
  }
11567
11605
  return Promise.resolve(null);
11568
11606
  }
@@ -11575,7 +11613,13 @@ class CheckBLEFirmwareRelease extends BaseMethod {
11575
11613
  run() {
11576
11614
  if (this.device.features) {
11577
11615
  const firmwareStatus = DataManager.getBLEFirmwareStatus(this.device.features);
11578
- return Promise.resolve(firmwareStatus);
11616
+ const changelog = DataManager.getBleFirmwareChangelog(this.device.features);
11617
+ const release = DataManager.getBleFirmwareLeatestRelease(this.device.features);
11618
+ return Promise.resolve({
11619
+ status: firmwareStatus,
11620
+ changelog,
11621
+ release,
11622
+ });
11579
11623
  }
11580
11624
  return Promise.resolve(null);
11581
11625
  }
@@ -1,4 +1,14 @@
1
1
  import type { Response } from '../params';
2
- import type { IDeviceFirmwareStatus } from '../device';
3
- export declare function checkBLEFirmwareRelease(connectId?: string): Response<IDeviceFirmwareStatus>;
2
+ import type { IDeviceBLEFirmwareStatus } from '../device';
3
+ import { IBLEFirmwareReleaseInfo } from '../settings';
4
+ declare type BleFirmwareRelease = {
5
+ status: IDeviceBLEFirmwareStatus;
6
+ changelog: {
7
+ 'zh-CN': string;
8
+ 'en-US': string;
9
+ }[];
10
+ release: IBLEFirmwareReleaseInfo;
11
+ };
12
+ export declare function checkBLEFirmwareRelease(connectId?: string): Response<BleFirmwareRelease>;
13
+ export {};
4
14
  //# sourceMappingURL=checkBLEFirmwareRelease.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkBLEFirmwareRelease.d.ts","sourceRoot":"","sources":["../../../src/types/api/checkBLEFirmwareRelease.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAC7C,SAAS,CAAC,EAAE,MAAM,GACjB,QAAQ,CAAC,qBAAqB,CAAC,CAAC"}
1
+ {"version":3,"file":"checkBLEFirmwareRelease.d.ts","sourceRoot":"","sources":["../../../src/types/api/checkBLEFirmwareRelease.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,aAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,wBAAwB,CAAC;IACjC,SAAS,EAAE;QACT,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;KACjB,EAAE,CAAC;IACJ,OAAO,EAAE,uBAAuB,CAAC;CAClC,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,kBAAkB,CAAC,CAAC"}
@@ -1,4 +1,14 @@
1
1
  import type { Response } from '../params';
2
2
  import type { IDeviceFirmwareStatus } from '../device';
3
- export declare function checkFirmwareRelease(connectId?: string): Response<IDeviceFirmwareStatus>;
3
+ import { IFirmwareReleaseInfo } from '../settings';
4
+ declare type FirmwareRelease = {
5
+ status: IDeviceFirmwareStatus;
6
+ changelog: {
7
+ 'en-US': string;
8
+ 'zh-CN': string;
9
+ }[];
10
+ release: IFirmwareReleaseInfo;
11
+ };
12
+ export declare function checkFirmwareRelease(connectId?: string): Response<FirmwareRelease>;
13
+ export {};
4
14
  //# sourceMappingURL=checkFirmwareRelease.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkFirmwareRelease.d.ts","sourceRoot":"","sources":["../../../src/types/api/checkFirmwareRelease.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,qBAAqB,CAAC,CAAC"}
1
+ {"version":3,"file":"checkFirmwareRelease.d.ts","sourceRoot":"","sources":["../../../src/types/api/checkFirmwareRelease.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,aAAK,eAAe,GAAG;IACrB,MAAM,EAAE,qBAAqB,CAAC;IAC9B,SAAS,EAAE;QACT,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;KACjB,EAAE,CAAC;IACJ,OAAO,EAAE,oBAAoB,CAAC;CAC/B,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { IBLEFirmwareReleaseInfo, IDeviceFirmwareStatus, IFirmwareReleaseInfo } from '../types';
2
+ export declare const getReleaseStatus: (releases: (IFirmwareReleaseInfo | IBLEFirmwareReleaseInfo)[], currentVersion: string) => IDeviceFirmwareStatus;
3
+ export declare const getReleaseChangelog: (releases: (IFirmwareReleaseInfo | IBLEFirmwareReleaseInfo)[], currentVersion: string) => IFirmwareReleaseInfo['changelog'][];
4
+ //# sourceMappingURL=release.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"release.d.ts","sourceRoot":"","sources":["../../src/utils/release.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEhG,eAAO,MAAM,gBAAgB,aACjB,CAAC,oBAAoB,GAAG,uBAAuB,CAAC,EAAE,kBAC5C,MAAM,KACrB,qBASF,CAAC;AAEF,eAAO,MAAM,mBAAmB,aACpB,CAAC,oBAAoB,GAAG,uBAAuB,CAAC,EAAE,kBAC5C,MAAM,KACrB,oBAAoB,CAAC,WAAW,CAAC,EAGnC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "> TODO: description",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -25,7 +25,7 @@
25
25
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@onekeyfe/hd-transport": "^0.1.0",
28
+ "@onekeyfe/hd-transport": "^0.1.1",
29
29
  "axios": "^0.27.2",
30
30
  "bignumber.js": "^9.0.2",
31
31
  "parse-uri": "^1.0.7",
@@ -35,5 +35,5 @@
35
35
  "@types/parse-uri": "^1.0.0",
36
36
  "@types/semver": "^7.3.9"
37
37
  },
38
- "gitHead": "d50dc424865150391b7249d1010ee75dc2074a7e"
38
+ "gitHead": "006c48af97498aad26719d9839979ecc2c55aea6"
39
39
  }
@@ -11,7 +11,13 @@ export default class CheckBLEFirmwareRelease extends BaseMethod {
11
11
  run() {
12
12
  if (this.device.features) {
13
13
  const firmwareStatus = DataManager.getBLEFirmwareStatus(this.device.features);
14
- return Promise.resolve(firmwareStatus);
14
+ const changelog = DataManager.getBleFirmwareChangelog(this.device.features);
15
+ const release = DataManager.getBleFirmwareLeatestRelease(this.device.features);
16
+ return Promise.resolve({
17
+ status: firmwareStatus,
18
+ changelog,
19
+ release,
20
+ });
15
21
  }
16
22
  return Promise.resolve(null);
17
23
  }
@@ -8,7 +8,13 @@ export default class CheckFirmwareRelease extends BaseMethod {
8
8
  run() {
9
9
  if (this.device.features) {
10
10
  const firmwareStatus = DataManager.getFirmwareStatus(this.device.features);
11
- return Promise.resolve(firmwareStatus);
11
+ const changelog = DataManager.getFirmwareChangelog(this.device.features);
12
+ const release = DataManager.getFirmwareLeatestRelease(this.device.features);
13
+ return Promise.resolve({
14
+ status: firmwareStatus,
15
+ changelog,
16
+ release,
17
+ });
12
18
  }
13
19
  return Promise.resolve(null);
14
20
  }
@@ -18,6 +18,7 @@ import type {
18
18
  IDeviceBLEFirmwareStatus,
19
19
  ITransportStatus,
20
20
  } from '../types';
21
+ import { getReleaseChangelog, getReleaseStatus } from '../utils/release';
21
22
 
22
23
  export default class DataManager {
23
24
  static deviceMap: DeviceTypeMap = {
@@ -59,21 +60,30 @@ export default class DataManager {
59
60
  }
60
61
 
61
62
  const targetDeviceConfigList = this.deviceMap[deviceType]?.firmware ?? [];
62
- const latestFirmware = targetDeviceConfigList[targetDeviceConfigList.length - 1];
63
-
64
- if (!latestFirmware) return 'valid';
65
-
66
- const latestVersion = latestFirmware.version.join('.');
67
63
  const currentVersion = deviceFirmwareVersion.join('.');
64
+ return getReleaseStatus(targetDeviceConfigList, currentVersion);
65
+ };
68
66
 
69
- /** latest is greater or equal current */
70
- if (semver.gt(latestVersion, currentVersion)) {
71
- if (latestFirmware.required) return 'required';
67
+ static getFirmwareChangelog = (features: Features) => {
68
+ const deviceType = getDeviceType(features);
69
+ const deviceFirmwareVersion = getDeviceFirmwareVersion(features);
72
70
 
73
- return 'outdated';
71
+ if (
72
+ features.firmware_present === false ||
73
+ (deviceType === 'classic' && features.bootloader_mode)
74
+ ) {
75
+ return [];
74
76
  }
75
77
 
76
- return 'valid';
78
+ const targetDeviceConfigList = this.deviceMap[deviceType]?.firmware ?? [];
79
+ const currentVersion = deviceFirmwareVersion.join('.');
80
+ return getReleaseChangelog(targetDeviceConfigList, currentVersion);
81
+ };
82
+
83
+ static getFirmwareLeatestRelease = (features: Features) => {
84
+ const deviceType = getDeviceType(features);
85
+ const targetDeviceConfigList = this.deviceMap[deviceType]?.firmware ?? [];
86
+ return targetDeviceConfigList[targetDeviceConfigList.length - 1];
77
87
  };
78
88
 
79
89
  static getBLEFirmwareStatus = (features: Features): IDeviceBLEFirmwareStatus => {
@@ -86,21 +96,27 @@ export default class DataManager {
86
96
  }
87
97
 
88
98
  const targetDeviceConfigList = this.deviceMap[deviceType]?.ble ?? [];
89
- const latestBLEFirmware = targetDeviceConfigList[targetDeviceConfigList.length - 1];
90
-
91
- if (!latestBLEFirmware) return 'valid';
92
-
93
- const latestVersion = latestBLEFirmware.version.join('.');
94
99
  const currentVersion = deviceBLEFirmwareVersion.join('.');
100
+ return getReleaseStatus(targetDeviceConfigList, currentVersion);
101
+ };
95
102
 
96
- /** latest is greater or equal current */
97
- if (semver.gt(latestVersion, currentVersion)) {
98
- if (latestBLEFirmware.required) return 'required';
103
+ static getBleFirmwareChangelog = (features: Features) => {
104
+ const deviceType = getDeviceType(features);
105
+ const deviceBLEFirmwareVersion = getDeviceBLEFirmwareVersion(features);
99
106
 
100
- return 'outdated';
107
+ if (!deviceBLEFirmwareVersion) {
108
+ return [];
101
109
  }
102
110
 
103
- return 'valid';
111
+ const targetDeviceConfigList = this.deviceMap[deviceType]?.ble ?? [];
112
+ const currentVersion = deviceBLEFirmwareVersion.join('.');
113
+ return getReleaseChangelog(targetDeviceConfigList, currentVersion);
114
+ };
115
+
116
+ static getBleFirmwareLeatestRelease = (features: Features) => {
117
+ const deviceType = getDeviceType(features);
118
+ const targetDeviceConfigList = this.deviceMap[deviceType]?.ble ?? [];
119
+ return targetDeviceConfigList[targetDeviceConfigList.length - 1];
104
120
  };
105
121
 
106
122
  static getTransportStatus = (localVersion: string): ITransportStatus => {
@@ -1,6 +1,14 @@
1
1
  import type { Response } from '../params';
2
- import type { IDeviceFirmwareStatus } from '../device';
2
+ import type { IDeviceBLEFirmwareStatus } from '../device';
3
+ import { IBLEFirmwareReleaseInfo } from '../settings';
3
4
 
4
- export declare function checkBLEFirmwareRelease(
5
- connectId?: string
6
- ): Response<IDeviceFirmwareStatus>;
5
+ type BleFirmwareRelease = {
6
+ status: IDeviceBLEFirmwareStatus;
7
+ changelog: {
8
+ 'zh-CN': string;
9
+ 'en-US': string;
10
+ }[];
11
+ release: IBLEFirmwareReleaseInfo;
12
+ };
13
+
14
+ export declare function checkBLEFirmwareRelease(connectId?: string): Response<BleFirmwareRelease>;
@@ -1,4 +1,14 @@
1
1
  import type { Response } from '../params';
2
2
  import type { IDeviceFirmwareStatus } from '../device';
3
+ import { IFirmwareReleaseInfo } from '../settings';
3
4
 
4
- export declare function checkFirmwareRelease(connectId?: string): Response<IDeviceFirmwareStatus>;
5
+ type FirmwareRelease = {
6
+ status: IDeviceFirmwareStatus;
7
+ changelog: {
8
+ 'en-US': string;
9
+ 'zh-CN': string;
10
+ }[];
11
+ release: IFirmwareReleaseInfo;
12
+ };
13
+
14
+ export declare function checkFirmwareRelease(connectId?: string): Response<FirmwareRelease>;
@@ -0,0 +1,24 @@
1
+ import semver from 'semver';
2
+ import { IBLEFirmwareReleaseInfo, IDeviceFirmwareStatus, IFirmwareReleaseInfo } from '../types';
3
+
4
+ export const getReleaseStatus = (
5
+ releases: (IFirmwareReleaseInfo | IBLEFirmwareReleaseInfo)[],
6
+ currentVersion: string
7
+ ): IDeviceFirmwareStatus => {
8
+ const newVersions = releases.filter(r => semver.gt(r.version.join('.'), currentVersion));
9
+ if (newVersions.length === 0) {
10
+ return 'valid';
11
+ }
12
+ if (newVersions.some(r => r.required)) {
13
+ return 'required';
14
+ }
15
+ return 'outdated';
16
+ };
17
+
18
+ export const getReleaseChangelog = (
19
+ releases: (IFirmwareReleaseInfo | IBLEFirmwareReleaseInfo)[],
20
+ currentVersion: string
21
+ ): IFirmwareReleaseInfo['changelog'][] => {
22
+ const newVersions = releases.filter(r => semver.gt(r.version.join('.'), currentVersion));
23
+ return newVersions.map(r => r.changelog);
24
+ };