@onekeyfe/hd-web-sdk 0.1.12 → 0.1.13

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.
@@ -4785,92 +4785,6 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
4785
4785
  }
4786
4786
  }
4787
4787
 
4788
- const colors = {
4789
- '@onekey/connect': 'color: #f4a742; background: #000;',
4790
- IFrame: 'color: #f4a742; background: #000;',
4791
- Core: 'color: #f4a742; background: #000;',
4792
- DescriptorStream: 'color: #77ab59; background: #000;',
4793
- DeviceList: 'color: #77ab59; background: #000;',
4794
- Device: 'color: #bada55; background: #000;',
4795
- DeviceCommands: 'color: #bada55; background: #000;',
4796
- DeviceConnector: 'color: #bada55; background: #000;',
4797
- Transport: 'color: #ffb6c1; background: #000;'
4798
- };
4799
- const MAX_ENTRIES = 100;
4800
-
4801
- class Log$6 {
4802
- constructor(prefix, enabled) {
4803
- this.prefix = prefix;
4804
- this.enabled = enabled;
4805
- this.messages = [];
4806
- this.css = typeof window !== 'undefined' && colors[prefix] ? colors[prefix] : '';
4807
- }
4808
-
4809
- addMessage(level, prefix, ...args) {
4810
- this.messages.push({
4811
- level,
4812
- prefix,
4813
- message: args,
4814
- timestamp: new Date().getTime()
4815
- });
4816
-
4817
- if (this.messages.length > MAX_ENTRIES) {
4818
- this.messages.shift();
4819
- }
4820
- }
4821
-
4822
- log(...args) {
4823
- this.addMessage('log', this.prefix, ...args);
4824
-
4825
- if (this.enabled) {
4826
- console.log(this.prefix, ...args);
4827
- }
4828
- }
4829
-
4830
- error(...args) {
4831
- this.addMessage('error', this.prefix, ...args);
4832
-
4833
- if (this.enabled) {
4834
- console.error(this.prefix, ...args);
4835
- }
4836
- }
4837
-
4838
- warn(...args) {
4839
- this.addMessage('warn', this.prefix, ...args);
4840
-
4841
- if (this.enabled) {
4842
- console.warn(this.prefix, ...args);
4843
- }
4844
- }
4845
-
4846
- debug(...args) {
4847
- this.addMessage('debug', this.prefix, ...args);
4848
-
4849
- if (this.enabled) {
4850
- if (this.css) {
4851
- console.log(`%c${this.prefix}`, this.css, ...args);
4852
- } else {
4853
- console.log(this.prefix, ...args);
4854
- }
4855
- }
4856
- }
4857
-
4858
- }
4859
-
4860
- const _logs = {};
4861
-
4862
- const initLog = (prefix, enabled) => {
4863
- const instance = new Log$6(prefix, !!enabled);
4864
- _logs[prefix] = instance;
4865
- return instance;
4866
- };
4867
-
4868
- const enableLog = enabled => {
4869
- Object.keys(_logs).forEach(key => {
4870
- _logs[key].enabled = !!enabled;
4871
- });
4872
- };
4873
-
4874
4788
  const httpRequest$1 = (url, type = 'text') => __awaiter(void 0, void 0, void 0, function* () {
4875
4789
  const response = yield axios__default["default"].request({
4876
4790
  url,
@@ -14034,7 +13948,7 @@ DataManager.getTransportStatus = localVersion => {
14034
13948
  return isLatest ? 'valid' : 'outdated';
14035
13949
  };
14036
13950
 
14037
- const Log$5 = initLog('Transport');
13951
+ const Log$5 = hdShared.initLog('Transport');
14038
13952
 
14039
13953
  class TransportManager {
14040
13954
  static load() {
@@ -14240,11 +14154,11 @@ const assertType = (res, resType) => {
14240
14154
  const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
14241
14155
 
14242
14156
  if (!splitResTypes.includes(res.type)) {
14243
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `assertType: Response of unexpected type: ${res.type}. Should be ${resType}`);
14157
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ResponseUnexpectTypeError, `assertType: Response of unexpected type: ${res.type}. Should be ${resType}`);
14244
14158
  }
14245
14159
  };
14246
14160
 
14247
- const Log$4 = initLog('DeviceCommands');
14161
+ const Log$4 = hdShared.initLog('DeviceCommands');
14248
14162
 
14249
14163
  class DeviceCommands {
14250
14164
  constructor(device, mainId) {
@@ -14268,8 +14182,10 @@ class DeviceCommands {
14268
14182
  }
14269
14183
 
14270
14184
  call(type, msg = {}) {
14185
+ var _a, _b;
14186
+
14271
14187
  return __awaiter(this, void 0, void 0, function* () {
14272
- console.log('[DeviceCommands] [call] Sending', type, this.transport);
14188
+ console.log('[DeviceCommands] [call] Sending', type);
14273
14189
 
14274
14190
  try {
14275
14191
  const promise = this.transport.call(this.mainId, type, msg);
@@ -14279,6 +14195,14 @@ class DeviceCommands {
14279
14195
  return res;
14280
14196
  } catch (error) {
14281
14197
  Log$4.debug('[DeviceCommands] [call] Received error', error);
14198
+
14199
+ if (((_b = (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) === 'device disconnected during action') {
14200
+ return {
14201
+ type: 'BridgeNetworkError',
14202
+ message: {}
14203
+ };
14204
+ }
14205
+
14282
14206
  throw error;
14283
14207
  }
14284
14208
  });
@@ -14296,7 +14220,16 @@ class DeviceCommands {
14296
14220
  assertType(response, resType);
14297
14221
  } catch (error) {
14298
14222
  console.log('DeviceCommands typedcall error: ', error);
14299
- throw error;
14223
+
14224
+ if (error instanceof hdShared.HardwareError) {
14225
+ if (error.errorCode === hdShared.HardwareErrorCode.ResponseUnexpectTypeError) {
14226
+ if (error.message.indexOf('BridgeNetworkError') > -1) {
14227
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeNetworkError);
14228
+ }
14229
+ }
14230
+ } else {
14231
+ throw error;
14232
+ }
14300
14233
  }
14301
14234
 
14302
14235
  return response;
@@ -14413,12 +14346,11 @@ const UI_REQUEST = {
14413
14346
  FIRMWARE_NOT_INSTALLED: 'ui-device_firmware_not_installed',
14414
14347
  NOT_USE_ONEKEY_DEVICE: 'ui-device_please_use_onekey_device'
14415
14348
  };
14416
- const VERSION = '1.0.0-alpha.1';
14417
- const DEFAULT_DOMAIN = `https://hardware-sdk.onekey.so/`;
14349
+ const DEFAULT_DOMAIN = `https://jssdk.onekey.so/`;
14418
14350
  const DEFAULT_PRIORITY = 2;
14419
14351
  const initialSettings = {
14420
14352
  configSrc: './data/config.json',
14421
- version: VERSION,
14353
+ version: '',
14422
14354
  debug: false,
14423
14355
  priority: DEFAULT_PRIORITY,
14424
14356
  trustedHost: false,
@@ -14515,7 +14447,7 @@ const parseRunOptions = options => {
14515
14447
  return options;
14516
14448
  };
14517
14449
 
14518
- const Log$3 = initLog('Device');
14450
+ const Log$3 = hdShared.initLog('Device');
14519
14451
 
14520
14452
  class Device extends events.exports {
14521
14453
  constructor(descriptor) {
@@ -14877,7 +14809,7 @@ class Device extends events.exports {
14877
14809
  }
14878
14810
 
14879
14811
  const cacheDeviceMap = new Map();
14880
- const Log$2 = initLog('DeviceList');
14812
+ const Log$2 = hdShared.initLog('DeviceList');
14881
14813
 
14882
14814
  class DeviceList extends events.exports {
14883
14815
  constructor() {
@@ -18674,7 +18606,7 @@ const resolveAfter = (msec, value) => new Promise(resolve => {
18674
18606
  setTimeout(resolve, msec, value);
18675
18607
  });
18676
18608
 
18677
- const Log$1 = initLog('DeviceConnector');
18609
+ const Log$1 = hdShared.initLog('DeviceConnector');
18678
18610
 
18679
18611
  const getDiff = (current, descriptors) => {
18680
18612
  const env = DataManager.getSettings('env');
@@ -18830,7 +18762,7 @@ class DeviceConnector {
18830
18762
 
18831
18763
  }
18832
18764
 
18833
- const Log = initLog('Core');
18765
+ const Log = hdShared.initLog('Core');
18834
18766
 
18835
18767
  let _core;
18836
18768
 
@@ -18936,7 +18868,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18936
18868
 
18937
18869
  try {
18938
18870
  const response = yield method.run();
18939
- Log.debug('Call API - Inner Method Run: ', device);
18871
+ Log.debug('Call API - Inner Method Run: ');
18940
18872
  messageResponse = createResponseMessage(method.responseID, true, response);
18941
18873
  _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.resolve(messageResponse);
18942
18874
  } catch (error) {
@@ -19195,7 +19127,7 @@ const init = (settings, Transport) => __awaiter(void 0, void 0, void 0, function
19195
19127
  Log.error('DataManager.load error');
19196
19128
  }
19197
19129
 
19198
- enableLog(DataManager.getSettings('debug'));
19130
+ hdShared.enableLog(DataManager.getSettings('debug'));
19199
19131
  initCore();
19200
19132
  initConnector();
19201
19133
  return _core;
@@ -19220,6 +19152,18 @@ const HardwareSdk = ({
19220
19152
  cancel
19221
19153
  });
19222
19154
 
19155
+ Object.defineProperty(exports, "yI", ({
19156
+ enumerable: true,
19157
+ get: function () {
19158
+ return hdShared.enableLog;
19159
+ }
19160
+ }));
19161
+ Object.defineProperty(exports, "KR", ({
19162
+ enumerable: true,
19163
+ get: function () {
19164
+ return hdShared.initLog;
19165
+ }
19166
+ }));
19223
19167
  __webpack_unused_export__ = ({
19224
19168
  enumerable: true,
19225
19169
  get: function () {
@@ -19245,7 +19189,6 @@ __webpack_unused_export__ = createResponseMessage;
19245
19189
  __webpack_unused_export__ = createUiMessage;
19246
19190
  __webpack_unused_export__ = createUiResponse;
19247
19191
  exports.ZP = HardwareSdk;
19248
- exports.yI = enableLog;
19249
19192
  __webpack_unused_export__ = getDeviceLabel;
19250
19193
  __webpack_unused_export__ = getDeviceType;
19251
19194
  __webpack_unused_export__ = getDeviceTypeByBleName;
@@ -19257,7 +19200,6 @@ __webpack_unused_export__ = getScriptType;
19257
19200
  __webpack_unused_export__ = getTimeStamp;
19258
19201
  __webpack_unused_export__ = httpRequest;
19259
19202
  __webpack_unused_export__ = init;
19260
- exports.KR = initLog;
19261
19203
  __webpack_unused_export__ = isValidVersionArray;
19262
19204
  __webpack_unused_export__ = isValidVersionString;
19263
19205
  __webpack_unused_export__ = normalizeVersionArray;
@@ -20445,7 +20387,9 @@ const HardwareErrorCode = {
20445
20387
  PinInvalid: 801,
20446
20388
  PinCancelled: 802,
20447
20389
  ActionCancelled: 803,
20448
- FirmwareError: 804
20390
+ FirmwareError: 804,
20391
+ ResponseUnexpectTypeError: 805,
20392
+ BridgeNetworkError: 806
20449
20393
  };
20450
20394
  const HardwareErrorCodeMessage = {
20451
20395
  [HardwareErrorCode.UnknownError]: 'Unknown error occurred. Check message property.',
@@ -20486,7 +20430,9 @@ const HardwareErrorCodeMessage = {
20486
20430
  [HardwareErrorCode.PinInvalid]: 'Pin invalid',
20487
20431
  [HardwareErrorCode.PinCancelled]: 'Pin cancelled',
20488
20432
  [HardwareErrorCode.ActionCancelled]: 'Action cancelled by user',
20489
- [HardwareErrorCode.FirmwareError]: 'Firmware installation failed'
20433
+ [HardwareErrorCode.FirmwareError]: 'Firmware installation failed',
20434
+ [HardwareErrorCode.ResponseUnexpectTypeError]: 'Response type is not expected',
20435
+ [HardwareErrorCode.BridgeNetworkError]: 'Bridge network error'
20490
20436
  };
20491
20437
 
20492
20438
  const TypedError = (hardwareError, message) => {
@@ -20526,13 +20472,137 @@ var HardwareError$1 = /*#__PURE__*/Object.freeze({
20526
20472
  TypedError: TypedError,
20527
20473
  serializeError: serializeError
20528
20474
  });
20475
+ const MAX_ENTRIES = 100;
20476
+
20477
+ class Log {
20478
+ constructor(prefix, enabled, logger) {
20479
+ this.prefix = prefix;
20480
+ this.enabled = enabled;
20481
+ this.messages = [];
20482
+
20483
+ if (logger) {
20484
+ this.logger = logger;
20485
+ }
20486
+ }
20487
+
20488
+ addMessage(level, prefix, ...args) {
20489
+ this.messages.push({
20490
+ level,
20491
+ prefix,
20492
+ message: args,
20493
+ timestamp: new Date().getTime()
20494
+ });
20495
+
20496
+ if (this.messages.length > MAX_ENTRIES) {
20497
+ this.messages.shift();
20498
+ }
20499
+ }
20500
+
20501
+ log(...args) {
20502
+ this.addMessage('log', this.prefix, ...args);
20503
+
20504
+ if (!this.enabled) {
20505
+ return;
20506
+ }
20507
+
20508
+ if (this.logger) {
20509
+ this.logger.info(this.prefix, ...args);
20510
+ } else {
20511
+ console.log(this.prefix, ...args);
20512
+ }
20513
+ }
20514
+
20515
+ error(...args) {
20516
+ this.addMessage('error', this.prefix, ...args);
20517
+
20518
+ if (!this.enabled) {
20519
+ return;
20520
+ }
20521
+
20522
+ if (this.logger) {
20523
+ this.logger.error(this.prefix, ...args);
20524
+ } else {
20525
+ console.error(this.prefix, ...args);
20526
+ }
20527
+ }
20528
+
20529
+ warn(...args) {
20530
+ this.addMessage('warn', this.prefix, ...args);
20531
+
20532
+ if (!this.enabled) {
20533
+ return;
20534
+ }
20535
+
20536
+ if (this.logger) {
20537
+ this.logger.warn(this.prefix, ...args);
20538
+ } else {
20539
+ console.warn(this.prefix, ...args);
20540
+ }
20541
+ }
20542
+
20543
+ debug(...args) {
20544
+ this.addMessage('debug', this.prefix, ...args);
20545
+
20546
+ if (!this.enabled) {
20547
+ return;
20548
+ }
20549
+
20550
+ if (this.logger) {
20551
+ this.logger.debug(this.prefix, ...args);
20552
+ } else {
20553
+ console.log(this.prefix, ...args);
20554
+ }
20555
+ }
20556
+
20557
+ }
20558
+
20559
+ const _logs = {};
20560
+
20561
+ const initLog = (prefix, enabled, logger) => {
20562
+ const instance = new Log(prefix, !!enabled, logger);
20563
+ _logs[prefix] = instance;
20564
+ return instance;
20565
+ };
20566
+
20567
+ const enableLog = enabled => {
20568
+ Object.keys(_logs).forEach(key => {
20569
+ _logs[key].enabled = !!enabled;
20570
+ });
20571
+ };
20572
+
20573
+ const setOutsideLogger = logger => {
20574
+ Object.keys(_logs).forEach(key => {
20575
+ _logs[key].logger = logger;
20576
+ });
20577
+ };
20578
+
20579
+ const enableLogByPrefix = (prefix, enabled) => {
20580
+ if (_logs[prefix]) {
20581
+ _logs[prefix].enabled = enabled;
20582
+ }
20583
+ };
20584
+
20585
+ const getLog = () => {
20586
+ let logs = [];
20587
+ Object.keys(_logs).forEach(key => {
20588
+ logs = logs.concat(_logs[key].messages);
20589
+ });
20590
+ logs.sort((a, b) => a.timestamp - b.timestamp);
20591
+ return logs;
20592
+ };
20593
+
20529
20594
  exports.ERRORS = HardwareError$1;
20530
20595
  exports.HardwareError = HardwareError;
20531
20596
  exports.HardwareErrorCode = HardwareErrorCode;
20532
20597
  exports.HardwareErrorCodeMessage = HardwareErrorCodeMessage;
20533
20598
  exports.TypedError = TypedError;
20534
20599
  exports.createDeferred = createDeferred;
20600
+ exports.enableLog = enableLog;
20601
+ exports.enableLogByPrefix = enableLogByPrefix;
20602
+ exports.getLog = getLog;
20603
+ exports.initLog = initLog;
20535
20604
  exports.serializeError = serializeError;
20605
+ exports.setOutsideLogger = setOutsideLogger;
20536
20606
 
20537
20607
  /***/ }),
20538
20608
 
@@ -45675,7 +45745,9 @@ const src_init = async settings => {
45675
45745
  window.addEventListener('unload', src_dispose);
45676
45746
 
45677
45747
  try {
45678
- await init(_settings);
45748
+ await init({ ..._settings,
45749
+ version: "0.1.13"
45750
+ });
45679
45751
  return true;
45680
45752
  } catch (e) {
45681
45753
  console.log('init error: ', e);