@onekeyfe/hd-core 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.
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data/config.d.ts +2 -0
- package/dist/data/config.d.ts.map +1 -0
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/index.d.ts +2 -22
- package/dist/index.js +34 -88
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/core/index.ts +2 -3
- package/src/data/config.ts +1 -0
- package/src/data-manager/connectSettings.ts +2 -2
- package/src/device/DeviceCommands.ts +19 -5
- package/src/utils/index.ts +1 -1
- package/dist/data/version.d.ts +0 -3
- package/dist/data/version.d.ts.map +0 -1
- package/dist/utils/logger.d.ts +0 -24
- package/dist/utils/logger.d.ts.map +0 -1
- package/src/data/version.ts +0 -3
- package/src/utils/logger.ts +0 -113
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAQlC,OAAO,EACL,WAAW,EAYZ,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,UAAU,CAAC;AAE7D,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAkBxD,eAAO,MAAM,OAAO,YAAmB,WAAW,iBA4JjD,CAAC;AA+DF,eAAO,MAAM,MAAM,0CAalB,CAAC;AAuEF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IACtC,aAAa,CAAC,OAAO,EAAE,WAAW;IA+BxC,OAAO;CAGR;AAED,eAAO,MAAM,QAAQ,YAGpB,CAAC;AAEF,eAAO,MAAM,aAAa,uBAGzB,CAAC;AAMF,eAAO,MAAM,IAAI,aAAoB,eAAe,aAAa,GAAG,8BAgBnE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/data/config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,6BAA6B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceCommands.d.ts","sourceRoot":"","sources":["../../src/device/DeviceCommands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAIlE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGvC,aAAK,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;AACxC,aAAK,UAAU,GAAG,MAAM,WAAW,CAAC;AACpC,oBAAY,oBAAoB,CAAC,CAAC,SAAS,UAAU,IAAI;IACvD,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;CACzB,CAAC;AACF,aAAK,oBAAoB,GAAG;KACzB,CAAC,IAAI,MAAM,WAAW,GAAG,oBAAoB,CAAC,CAAC,CAAC;CAClD,CAAC;AACF,oBAAY,sBAAsB,GAAG,oBAAoB,CAAC,MAAM,WAAW,CAAC,CAAC;AAE7E,oBAAY,wBAAwB,GAAG;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAcF,qBAAa,cAAc;IACzB,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,SAAS,CAAC;IAErB,MAAM,EAAE,MAAM,CAAC;IAEf,QAAQ,EAAE,OAAO,CAAC;IAElB,WAAW,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAE9C,kBAAkB,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;gBAE/B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAO1C,OAAO;IAUD,IAAI,CACR,IAAI,EAAE,UAAU,EAChB,GAAG,GAAE,sBAAsB,CAAC,SAAS,CAAM,GAC1C,OAAO,CAAC,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"DeviceCommands.d.ts","sourceRoot":"","sources":["../../src/device/DeviceCommands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAIlE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGvC,aAAK,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;AACxC,aAAK,UAAU,GAAG,MAAM,WAAW,CAAC;AACpC,oBAAY,oBAAoB,CAAC,CAAC,SAAS,UAAU,IAAI;IACvD,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;CACzB,CAAC;AACF,aAAK,oBAAoB,GAAG;KACzB,CAAC,IAAI,MAAM,WAAW,GAAG,oBAAoB,CAAC,CAAC,CAAC;CAClD,CAAC;AACF,oBAAY,sBAAsB,GAAG,oBAAoB,CAAC,MAAM,WAAW,CAAC,CAAC;AAE7E,oBAAY,wBAAwB,GAAG;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAcF,qBAAa,cAAc;IACzB,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,SAAS,CAAC;IAErB,MAAM,EAAE,MAAM,CAAC;IAEf,QAAQ,EAAE,OAAO,CAAC;IAElB,WAAW,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAE9C,kBAAkB,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;gBAE/B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAO1C,OAAO;IAUD,IAAI,CACR,IAAI,EAAE,UAAU,EAChB,GAAG,GAAE,sBAAsB,CAAC,SAAS,CAAM,GAC1C,OAAO,CAAC,sBAAsB,CAAC;IAkBlC,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EAAE,EACpD,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,CAAC,EACV,GAAG,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAE3C,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EAClD,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,CAAC,EACV,GAAG,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAuC7B,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,sBAAsB,CAAC,SAAS,CAAC;IAK3E,kBAAkB,CAAC,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAkFhF,UAAU,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,oBAAoB;CAuBhD;AAED,oBAAY,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as _onekeyfe_hd_transport from '@onekeyfe/hd-transport';
|
|
|
3
3
|
import { Messages, EthereumPublicKey, EthereumMessageSignature, Success as Success$1, Address, MultisigRedeemScriptType, InputScriptType, PublicKey, MessageSignature, PrevInput, TxOutputBinType, TxInput, TxOutputType, TxInputType, RecoveryDeviceType, SafetyCheckLevel, StarcoinAddress as StarcoinAddress$1, StarcoinPublicKey as StarcoinPublicKey$1, StarcoinMessageSignature, StarcoinSignedTx, NEMAddress as NEMAddress$1, NEMSignedTx, SolanaAddress as SolanaAddress$1, SolanaSignedTx as SolanaSignedTx$1, StellarAddress as StellarAddress$1, StellarSignedTx, CipheredKeyValue as CipheredKeyValue$1, Transport, OneKeyDeviceInfo } from '@onekeyfe/hd-transport';
|
|
4
4
|
export { Messages as PROTO } from '@onekeyfe/hd-transport';
|
|
5
5
|
import { Deferred } from '@onekeyfe/hd-shared';
|
|
6
|
+
export { enableLog, initLog } from '@onekeyfe/hd-shared';
|
|
6
7
|
|
|
7
8
|
interface CommonParams {
|
|
8
9
|
keepSession?: boolean;
|
|
@@ -1242,27 +1243,6 @@ declare class Core extends EventEmitter {
|
|
|
1242
1243
|
}
|
|
1243
1244
|
declare const init: (settings: ConnectSettings, Transport: any) => Promise<Core | undefined>;
|
|
1244
1245
|
|
|
1245
|
-
declare type LogMessage = {
|
|
1246
|
-
level: string;
|
|
1247
|
-
prefix: string;
|
|
1248
|
-
message: any[];
|
|
1249
|
-
timestamp: number;
|
|
1250
|
-
};
|
|
1251
|
-
declare class Log {
|
|
1252
|
-
prefix: string;
|
|
1253
|
-
enabled: boolean;
|
|
1254
|
-
css: string;
|
|
1255
|
-
messages: LogMessage[];
|
|
1256
|
-
constructor(prefix: string, enabled: boolean);
|
|
1257
|
-
addMessage(level: string, prefix: string, ...args: any[]): void;
|
|
1258
|
-
log(...args: any[]): void;
|
|
1259
|
-
error(...args: any[]): void;
|
|
1260
|
-
warn(...args: any[]): void;
|
|
1261
|
-
debug(...args: any[]): void;
|
|
1262
|
-
}
|
|
1263
|
-
declare const initLog: (prefix: string, enabled?: boolean | undefined) => Log;
|
|
1264
|
-
declare const enableLog: (enabled?: boolean | undefined) => void;
|
|
1265
|
-
|
|
1266
1246
|
declare const httpRequest: (url: string, type: string) => any;
|
|
1267
1247
|
declare const getTimeStamp: () => number;
|
|
1268
1248
|
|
|
@@ -1319,4 +1299,4 @@ declare class DataManager {
|
|
|
1319
1299
|
|
|
1320
1300
|
declare const HardwareSdk: ({ init, call, dispose, eventEmitter, uiResponse, cancel, }: InjectApi) => CoreApi;
|
|
1321
1301
|
|
|
1322
|
-
export { AccountAddress, AccountAddresses, AssetsMap, BTCAddress, BTCGetAddressParams, BTCGetPublicKeyParams, BTCPublicKey, BTCSignMessageParams, BTCSignTransactionParams, BTCVerifyMessageParams, CORE_EVENT, CallMethod, CallMethodAnyResponse, CallMethodKeys, CallMethodPayload, CallMethodResponse, CallMethodUnion, CipheredKeyValue, CipheredKeyValueParams, CommonParams, ConnectSettings, Core, CoreApi, CoreMessage, DEFAULT_PRIORITY, DEVICE, DEVICE_EVENT, DataManager, Device$1 as Device, DeviceButtonRequest, DeviceButtonRequestPayload, DeviceChangePinParams, DeviceEvent, DeviceEventListenerFn, DeviceEventMessage, DeviceFirmwareRange, DeviceFlagsParams, DeviceMode, DeviceRecoveryParams, DeviceResetParams, DeviceSettingsParams, DeviceStatus, DeviceTypeMap, DeviceVerifyParams, DeviceVerifySignature, EVMAccessList, EVMAddress, EVMGetAddressParams, EVMGetPublicKeyParams, EVMPublicKey, EVMSignMessageEIP712Params, EVMSignMessageParams, EVMSignTransactionParams, EVMSignTypedDataParams, EVMSignedTx, EVMTransaction, EVMTransactionEIP1559, EVMVerifyMessageParams, EthereumSignTypedDataMessage, EthereumSignTypedDataTypeProperty, EthereumSignTypedDataTypes, Features, FirmwareProgress, FirmwareRange, FirmwareRelease, IBLEFirmwareReleaseInfo, IDeviceBLEFirmwareStatus, IDeviceFirmwareStatus, IDeviceModel, IDeviceType, IFRAME, IFirmwareReleaseInfo, IFrameBridge, IFrameCallMessage, IFrameCancelMessage, IFrameEvent, IFrameEventMessage, IFrameInit, ILocale, ITransportStatus, IVersionArray, KnownDevice, MajorVersion, MethodResponseMessage, NEMAddress, NEMAggregateModificationTransaction, NEMGetAddressParams, NEMImportanceTransaction, NEMMosaic, NEMMosaicCreationTransaction, NEMMultisigTransaction, NEMProvisionNamespaceTransaction, NEMSignTransactionParams, NEMSupplyChangeTransaction, NEMTransaction, NEMTransferTransaction, Params, PostMessageEvent, RESPONSE_EVENT, RefTransaction, ReleaseInfo, RemoteConfigResponse, Response, SearchDevice, SignedTransaction, SolanaAddress, SolanaGetAddressParams, SolanaSignTransactionParams, SolanaSignedTx, StarcoinAddress, StarcoinGetAddressParams, StarcoinGetPublicKeyParams, StarcoinPublicKey, StarcoinSignMessageParams, StarcoinSignTransactionParams, StarcoinVerifyMessageParams, StellarAddress, StellarAsset, StellarGetAddressParams, StellarOperation, StellarSignTransactionParams, StellarTransaction, StrictFeatures, Success, TransactionOptions, TransportReleaseStatus, UI_EVENT, UI_REQUEST, UI_RESPONSE, UiEvent, UiEventMessage, UiPromise, UiPromiseResponse, UiRequestButton, UiRequestDeviceAction, UiRequestWithoutPayload, UiResponseEvent, UiResponseMessage, UiResponsePin, UnavailableCapabilities, UnavailableCapability, Unsuccessful, VersionArray, corsValidator, createDeviceMessage, createErrorMessage, createIFrameMessage, createResponseMessage, createUiMessage, createUiResponse, HardwareSdk as default,
|
|
1302
|
+
export { AccountAddress, AccountAddresses, AssetsMap, BTCAddress, BTCGetAddressParams, BTCGetPublicKeyParams, BTCPublicKey, BTCSignMessageParams, BTCSignTransactionParams, BTCVerifyMessageParams, CORE_EVENT, CallMethod, CallMethodAnyResponse, CallMethodKeys, CallMethodPayload, CallMethodResponse, CallMethodUnion, CipheredKeyValue, CipheredKeyValueParams, CommonParams, ConnectSettings, Core, CoreApi, CoreMessage, DEFAULT_PRIORITY, DEVICE, DEVICE_EVENT, DataManager, Device$1 as Device, DeviceButtonRequest, DeviceButtonRequestPayload, DeviceChangePinParams, DeviceEvent, DeviceEventListenerFn, DeviceEventMessage, DeviceFirmwareRange, DeviceFlagsParams, DeviceMode, DeviceRecoveryParams, DeviceResetParams, DeviceSettingsParams, DeviceStatus, DeviceTypeMap, DeviceVerifyParams, DeviceVerifySignature, EVMAccessList, EVMAddress, EVMGetAddressParams, EVMGetPublicKeyParams, EVMPublicKey, EVMSignMessageEIP712Params, EVMSignMessageParams, EVMSignTransactionParams, EVMSignTypedDataParams, EVMSignedTx, EVMTransaction, EVMTransactionEIP1559, EVMVerifyMessageParams, EthereumSignTypedDataMessage, EthereumSignTypedDataTypeProperty, EthereumSignTypedDataTypes, Features, FirmwareProgress, FirmwareRange, FirmwareRelease, IBLEFirmwareReleaseInfo, IDeviceBLEFirmwareStatus, IDeviceFirmwareStatus, IDeviceModel, IDeviceType, IFRAME, IFirmwareReleaseInfo, IFrameBridge, IFrameCallMessage, IFrameCancelMessage, IFrameEvent, IFrameEventMessage, IFrameInit, ILocale, ITransportStatus, IVersionArray, KnownDevice, MajorVersion, MethodResponseMessage, NEMAddress, NEMAggregateModificationTransaction, NEMGetAddressParams, NEMImportanceTransaction, NEMMosaic, NEMMosaicCreationTransaction, NEMMultisigTransaction, NEMProvisionNamespaceTransaction, NEMSignTransactionParams, NEMSupplyChangeTransaction, NEMTransaction, NEMTransferTransaction, Params, PostMessageEvent, RESPONSE_EVENT, RefTransaction, ReleaseInfo, RemoteConfigResponse, Response, SearchDevice, SignedTransaction, SolanaAddress, SolanaGetAddressParams, SolanaSignTransactionParams, SolanaSignedTx, StarcoinAddress, StarcoinGetAddressParams, StarcoinGetPublicKeyParams, StarcoinPublicKey, StarcoinSignMessageParams, StarcoinSignTransactionParams, StarcoinVerifyMessageParams, StellarAddress, StellarAsset, StellarGetAddressParams, StellarOperation, StellarSignTransactionParams, StellarTransaction, StrictFeatures, Success, TransactionOptions, TransportReleaseStatus, UI_EVENT, UI_REQUEST, UI_RESPONSE, UiEvent, UiEventMessage, UiPromise, UiPromiseResponse, UiRequestButton, UiRequestDeviceAction, UiRequestWithoutPayload, UiResponseEvent, UiResponseMessage, UiResponsePin, UnavailableCapabilities, UnavailableCapability, Unsuccessful, VersionArray, corsValidator, createDeviceMessage, createErrorMessage, createIFrameMessage, createResponseMessage, createUiMessage, createUiResponse, HardwareSdk as default, getDeviceLabel, getDeviceType, getDeviceTypeByBleName, getDeviceTypeByDeviceId, getDeviceUUID, getEnv, getHDPath, getScriptType, getTimeStamp, httpRequest, init as initCore, isValidVersionArray, isValidVersionString, normalizeVersionArray, parseConnectSettings, parseMessage, patchFeatures, safeThrowError, versionCompare, versionSplit };
|
package/dist/index.js
CHANGED
|
@@ -610,78 +610,6 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
|
610
610
|
}
|
|
611
611
|
}
|
|
612
612
|
|
|
613
|
-
const colors = {
|
|
614
|
-
'@onekey/connect': 'color: #f4a742; background: #000;',
|
|
615
|
-
IFrame: 'color: #f4a742; background: #000;',
|
|
616
|
-
Core: 'color: #f4a742; background: #000;',
|
|
617
|
-
DescriptorStream: 'color: #77ab59; background: #000;',
|
|
618
|
-
DeviceList: 'color: #77ab59; background: #000;',
|
|
619
|
-
Device: 'color: #bada55; background: #000;',
|
|
620
|
-
DeviceCommands: 'color: #bada55; background: #000;',
|
|
621
|
-
DeviceConnector: 'color: #bada55; background: #000;',
|
|
622
|
-
Transport: 'color: #ffb6c1; background: #000;',
|
|
623
|
-
};
|
|
624
|
-
const MAX_ENTRIES = 100;
|
|
625
|
-
class Log$6 {
|
|
626
|
-
constructor(prefix, enabled) {
|
|
627
|
-
this.prefix = prefix;
|
|
628
|
-
this.enabled = enabled;
|
|
629
|
-
this.messages = [];
|
|
630
|
-
this.css = typeof window !== 'undefined' && colors[prefix] ? colors[prefix] : '';
|
|
631
|
-
}
|
|
632
|
-
addMessage(level, prefix, ...args) {
|
|
633
|
-
this.messages.push({
|
|
634
|
-
level,
|
|
635
|
-
prefix,
|
|
636
|
-
message: args,
|
|
637
|
-
timestamp: new Date().getTime(),
|
|
638
|
-
});
|
|
639
|
-
if (this.messages.length > MAX_ENTRIES) {
|
|
640
|
-
this.messages.shift();
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
log(...args) {
|
|
644
|
-
this.addMessage('log', this.prefix, ...args);
|
|
645
|
-
if (this.enabled) {
|
|
646
|
-
console.log(this.prefix, ...args);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
error(...args) {
|
|
650
|
-
this.addMessage('error', this.prefix, ...args);
|
|
651
|
-
if (this.enabled) {
|
|
652
|
-
console.error(this.prefix, ...args);
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
warn(...args) {
|
|
656
|
-
this.addMessage('warn', this.prefix, ...args);
|
|
657
|
-
if (this.enabled) {
|
|
658
|
-
console.warn(this.prefix, ...args);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
debug(...args) {
|
|
662
|
-
this.addMessage('debug', this.prefix, ...args);
|
|
663
|
-
if (this.enabled) {
|
|
664
|
-
if (this.css) {
|
|
665
|
-
console.log(`%c${this.prefix}`, this.css, ...args);
|
|
666
|
-
}
|
|
667
|
-
else {
|
|
668
|
-
console.log(this.prefix, ...args);
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
const _logs = {};
|
|
674
|
-
const initLog = (prefix, enabled) => {
|
|
675
|
-
const instance = new Log$6(prefix, !!enabled);
|
|
676
|
-
_logs[prefix] = instance;
|
|
677
|
-
return instance;
|
|
678
|
-
};
|
|
679
|
-
const enableLog = (enabled) => {
|
|
680
|
-
Object.keys(_logs).forEach(key => {
|
|
681
|
-
_logs[key].enabled = !!enabled;
|
|
682
|
-
});
|
|
683
|
-
};
|
|
684
|
-
|
|
685
613
|
const httpRequest$1 = (url, type = 'text') => __awaiter(void 0, void 0, void 0, function* () {
|
|
686
614
|
const response = yield axios__default["default"].request({
|
|
687
615
|
url,
|
|
@@ -9850,7 +9778,7 @@ DataManager.getTransportStatus = (localVersion) => {
|
|
|
9850
9778
|
return isLatest ? 'valid' : 'outdated';
|
|
9851
9779
|
};
|
|
9852
9780
|
|
|
9853
|
-
const Log$5 = initLog('Transport');
|
|
9781
|
+
const Log$5 = hdShared.initLog('Transport');
|
|
9854
9782
|
class TransportManager {
|
|
9855
9783
|
static load() {
|
|
9856
9784
|
console.log('transport manager load');
|
|
@@ -10024,10 +9952,10 @@ const createDeviceMessage = (type, payload) => ({
|
|
|
10024
9952
|
const assertType = (res, resType) => {
|
|
10025
9953
|
const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
|
|
10026
9954
|
if (!splitResTypes.includes(res.type)) {
|
|
10027
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.
|
|
9955
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ResponseUnexpectTypeError, `assertType: Response of unexpected type: ${res.type}. Should be ${resType}`);
|
|
10028
9956
|
}
|
|
10029
9957
|
};
|
|
10030
|
-
const Log$4 = initLog('DeviceCommands');
|
|
9958
|
+
const Log$4 = hdShared.initLog('DeviceCommands');
|
|
10031
9959
|
class DeviceCommands {
|
|
10032
9960
|
constructor(device, mainId) {
|
|
10033
9961
|
this.device = device;
|
|
@@ -10045,8 +9973,9 @@ class DeviceCommands {
|
|
|
10045
9973
|
(_b = (_a = this.transport).cancel) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
10046
9974
|
}
|
|
10047
9975
|
call(type, msg = {}) {
|
|
9976
|
+
var _a, _b;
|
|
10048
9977
|
return __awaiter(this, void 0, void 0, function* () {
|
|
10049
|
-
console.log('[DeviceCommands] [call] Sending', type
|
|
9978
|
+
console.log('[DeviceCommands] [call] Sending', type);
|
|
10050
9979
|
try {
|
|
10051
9980
|
const promise = this.transport.call(this.mainId, type, msg);
|
|
10052
9981
|
this.callPromise = promise;
|
|
@@ -10056,6 +9985,9 @@ class DeviceCommands {
|
|
|
10056
9985
|
}
|
|
10057
9986
|
catch (error) {
|
|
10058
9987
|
Log$4.debug('[DeviceCommands] [call] Received error', error);
|
|
9988
|
+
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') {
|
|
9989
|
+
return { type: 'BridgeNetworkError', message: {} };
|
|
9990
|
+
}
|
|
10059
9991
|
throw error;
|
|
10060
9992
|
}
|
|
10061
9993
|
});
|
|
@@ -10071,7 +10003,16 @@ class DeviceCommands {
|
|
|
10071
10003
|
}
|
|
10072
10004
|
catch (error) {
|
|
10073
10005
|
console.log('DeviceCommands typedcall error: ', error);
|
|
10074
|
-
|
|
10006
|
+
if (error instanceof hdShared.HardwareError) {
|
|
10007
|
+
if (error.errorCode === hdShared.HardwareErrorCode.ResponseUnexpectTypeError) {
|
|
10008
|
+
if (error.message.indexOf('BridgeNetworkError') > -1) {
|
|
10009
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeNetworkError);
|
|
10010
|
+
}
|
|
10011
|
+
}
|
|
10012
|
+
}
|
|
10013
|
+
else {
|
|
10014
|
+
throw error;
|
|
10015
|
+
}
|
|
10075
10016
|
}
|
|
10076
10017
|
return response;
|
|
10077
10018
|
});
|
|
@@ -10166,13 +10107,12 @@ const UI_REQUEST = {
|
|
|
10166
10107
|
NOT_USE_ONEKEY_DEVICE: 'ui-device_please_use_onekey_device',
|
|
10167
10108
|
};
|
|
10168
10109
|
|
|
10169
|
-
const
|
|
10170
|
-
const DEFAULT_DOMAIN = `https://hardware-sdk.onekey.so/`;
|
|
10110
|
+
const DEFAULT_DOMAIN = `https://jssdk.onekey.so/`;
|
|
10171
10111
|
|
|
10172
10112
|
const DEFAULT_PRIORITY = 2;
|
|
10173
10113
|
const initialSettings = {
|
|
10174
10114
|
configSrc: './data/config.json',
|
|
10175
|
-
version:
|
|
10115
|
+
version: '',
|
|
10176
10116
|
debug: false,
|
|
10177
10117
|
priority: DEFAULT_PRIORITY,
|
|
10178
10118
|
trustedHost: false,
|
|
@@ -10258,7 +10198,7 @@ const parseRunOptions = (options) => {
|
|
|
10258
10198
|
options = {};
|
|
10259
10199
|
return options;
|
|
10260
10200
|
};
|
|
10261
|
-
const Log$3 = initLog('Device');
|
|
10201
|
+
const Log$3 = hdShared.initLog('Device');
|
|
10262
10202
|
class Device extends events.exports {
|
|
10263
10203
|
constructor(descriptor) {
|
|
10264
10204
|
super();
|
|
@@ -10564,7 +10504,7 @@ class Device extends events.exports {
|
|
|
10564
10504
|
}
|
|
10565
10505
|
|
|
10566
10506
|
const cacheDeviceMap = new Map();
|
|
10567
|
-
const Log$2 = initLog('DeviceList');
|
|
10507
|
+
const Log$2 = hdShared.initLog('DeviceList');
|
|
10568
10508
|
class DeviceList extends events.exports {
|
|
10569
10509
|
constructor() {
|
|
10570
10510
|
super(...arguments);
|
|
@@ -13316,7 +13256,7 @@ const resolveAfter = (msec, value) => new Promise(resolve => {
|
|
|
13316
13256
|
setTimeout(resolve, msec, value);
|
|
13317
13257
|
});
|
|
13318
13258
|
|
|
13319
|
-
const Log$1 = initLog('DeviceConnector');
|
|
13259
|
+
const Log$1 = hdShared.initLog('DeviceConnector');
|
|
13320
13260
|
const getDiff = (current, descriptors) => {
|
|
13321
13261
|
const env = DataManager.getSettings('env');
|
|
13322
13262
|
if (env === 'react-native') {
|
|
@@ -13455,7 +13395,7 @@ class DeviceConnector {
|
|
|
13455
13395
|
}
|
|
13456
13396
|
}
|
|
13457
13397
|
|
|
13458
|
-
const Log = initLog('Core');
|
|
13398
|
+
const Log = hdShared.initLog('Core');
|
|
13459
13399
|
let _core;
|
|
13460
13400
|
let _deviceList;
|
|
13461
13401
|
let _connector;
|
|
@@ -13542,7 +13482,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
13542
13482
|
}
|
|
13543
13483
|
try {
|
|
13544
13484
|
const response = yield method.run();
|
|
13545
|
-
Log.debug('Call API - Inner Method Run: '
|
|
13485
|
+
Log.debug('Call API - Inner Method Run: ');
|
|
13546
13486
|
messageResponse = createResponseMessage(method.responseID, true, response);
|
|
13547
13487
|
_callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.resolve(messageResponse);
|
|
13548
13488
|
}
|
|
@@ -13741,7 +13681,7 @@ const init = (settings, Transport) => __awaiter(void 0, void 0, void 0, function
|
|
|
13741
13681
|
catch (_b) {
|
|
13742
13682
|
Log.error('DataManager.load error');
|
|
13743
13683
|
}
|
|
13744
|
-
enableLog(DataManager.getSettings('debug'));
|
|
13684
|
+
hdShared.enableLog(DataManager.getSettings('debug'));
|
|
13745
13685
|
initCore();
|
|
13746
13686
|
initConnector();
|
|
13747
13687
|
return _core;
|
|
@@ -13760,6 +13700,14 @@ const HardwareSdk = ({ init, call, dispose, eventEmitter, uiResponse, cancel, })
|
|
|
13760
13700
|
cancel,
|
|
13761
13701
|
});
|
|
13762
13702
|
|
|
13703
|
+
Object.defineProperty(exports, 'enableLog', {
|
|
13704
|
+
enumerable: true,
|
|
13705
|
+
get: function () { return hdShared.enableLog; }
|
|
13706
|
+
});
|
|
13707
|
+
Object.defineProperty(exports, 'initLog', {
|
|
13708
|
+
enumerable: true,
|
|
13709
|
+
get: function () { return hdShared.initLog; }
|
|
13710
|
+
});
|
|
13763
13711
|
Object.defineProperty(exports, 'PROTO', {
|
|
13764
13712
|
enumerable: true,
|
|
13765
13713
|
get: function () { return hdTransport.Messages; }
|
|
@@ -13783,7 +13731,6 @@ exports.createResponseMessage = createResponseMessage;
|
|
|
13783
13731
|
exports.createUiMessage = createUiMessage;
|
|
13784
13732
|
exports.createUiResponse = createUiResponse;
|
|
13785
13733
|
exports["default"] = HardwareSdk;
|
|
13786
|
-
exports.enableLog = enableLog;
|
|
13787
13734
|
exports.getDeviceLabel = getDeviceLabel;
|
|
13788
13735
|
exports.getDeviceType = getDeviceType;
|
|
13789
13736
|
exports.getDeviceTypeByBleName = getDeviceTypeByBleName;
|
|
@@ -13795,7 +13742,6 @@ exports.getScriptType = getScriptType;
|
|
|
13795
13742
|
exports.getTimeStamp = getTimeStamp;
|
|
13796
13743
|
exports.httpRequest = httpRequest;
|
|
13797
13744
|
exports.initCore = init;
|
|
13798
|
-
exports.initLog = initLog;
|
|
13799
13745
|
exports.isValidVersionArray = isValidVersionArray;
|
|
13800
13746
|
exports.isValidVersionString = isValidVersionString;
|
|
13801
13747
|
exports.normalizeVersionArray = normalizeVersionArray;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEzD,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "^0.1.
|
|
29
|
-
"@onekeyfe/hd-transport": "^0.1.
|
|
28
|
+
"@onekeyfe/hd-shared": "^0.1.13",
|
|
29
|
+
"@onekeyfe/hd-transport": "^0.1.13",
|
|
30
30
|
"axios": "^0.27.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"js-sha256": "^0.9.0",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"@types/parse-uri": "^1.0.0",
|
|
38
38
|
"@types/semver": "^7.3.9"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "f69fd0696e38efbc838848fb361cb900043bb2ec"
|
|
41
41
|
}
|
package/src/core/index.ts
CHANGED
|
@@ -6,8 +6,7 @@ import { Device, DeviceEvents } from '../device/Device';
|
|
|
6
6
|
import { DeviceList } from '../device/DeviceList';
|
|
7
7
|
import { findMethod } from '../api/utils';
|
|
8
8
|
import { DataManager } from '../data-manager';
|
|
9
|
-
import { enableLog } from '../utils
|
|
10
|
-
import { initLog } from '../utils';
|
|
9
|
+
import { initLog, enableLog } from '../utils';
|
|
11
10
|
import {
|
|
12
11
|
CoreMessage,
|
|
13
12
|
createResponseMessage,
|
|
@@ -162,7 +161,7 @@ export const callAPI = async (message: CoreMessage) => {
|
|
|
162
161
|
|
|
163
162
|
try {
|
|
164
163
|
const response: object = await method.run();
|
|
165
|
-
Log.debug('Call API - Inner Method Run: '
|
|
164
|
+
Log.debug('Call API - Inner Method Run: ');
|
|
166
165
|
messageResponse = createResponseMessage(method.responseID, true, response);
|
|
167
166
|
_callPromise?.resolve(messageResponse);
|
|
168
167
|
} catch (error) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_DOMAIN = `https://jssdk.onekey.so/`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable vars-on-top */
|
|
2
2
|
|
|
3
3
|
import type { ConnectSettings } from '../types';
|
|
4
|
-
import {
|
|
4
|
+
import { DEFAULT_DOMAIN } from '../data/config';
|
|
5
5
|
|
|
6
6
|
export const DEFAULT_PRIORITY = 2;
|
|
7
7
|
|
|
@@ -13,7 +13,7 @@ declare global {
|
|
|
13
13
|
|
|
14
14
|
const initialSettings: ConnectSettings = {
|
|
15
15
|
configSrc: './data/config.json', // constant
|
|
16
|
-
version:
|
|
16
|
+
version: '', // constant
|
|
17
17
|
debug: false,
|
|
18
18
|
priority: DEFAULT_PRIORITY,
|
|
19
19
|
trustedHost: false,
|
|
@@ -26,7 +26,7 @@ const assertType = (res: DefaultMessageResponse, resType: string | string[]) =>
|
|
|
26
26
|
const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
|
|
27
27
|
if (!splitResTypes.includes(res.type)) {
|
|
28
28
|
throw ERRORS.TypedError(
|
|
29
|
-
HardwareErrorCode.
|
|
29
|
+
HardwareErrorCode.ResponseUnexpectTypeError,
|
|
30
30
|
`assertType: Response of unexpected type: ${res.type}. Should be ${resType as string}`
|
|
31
31
|
);
|
|
32
32
|
}
|
|
@@ -68,7 +68,7 @@ export class DeviceCommands {
|
|
|
68
68
|
type: MessageKey,
|
|
69
69
|
msg: DefaultMessageResponse['message'] = {}
|
|
70
70
|
): Promise<DefaultMessageResponse> {
|
|
71
|
-
console.log('[DeviceCommands] [call] Sending', type
|
|
71
|
+
console.log('[DeviceCommands] [call] Sending', type);
|
|
72
72
|
|
|
73
73
|
try {
|
|
74
74
|
const promise = this.transport.call(this.mainId, type, msg) as any;
|
|
@@ -78,6 +78,9 @@ export class DeviceCommands {
|
|
|
78
78
|
return res;
|
|
79
79
|
} catch (error) {
|
|
80
80
|
Log.debug('[DeviceCommands] [call] Received error', error);
|
|
81
|
+
if (error?.response?.data?.error === 'device disconnected during action') {
|
|
82
|
+
return { type: 'BridgeNetworkError', message: {} } as any;
|
|
83
|
+
}
|
|
81
84
|
throw error;
|
|
82
85
|
}
|
|
83
86
|
}
|
|
@@ -112,10 +115,21 @@ export class DeviceCommands {
|
|
|
112
115
|
} catch (error) {
|
|
113
116
|
// handle possible race condition
|
|
114
117
|
// Bridge may have some unread message in buffer, read it
|
|
115
|
-
// await this.transport.read(this.mainId);
|
|
116
|
-
|
|
118
|
+
// await this.transport.read?.(this.mainId);
|
|
119
|
+
|
|
117
120
|
console.log('DeviceCommands typedcall error: ', error);
|
|
118
|
-
|
|
121
|
+
|
|
122
|
+
// throw bridge network error
|
|
123
|
+
if (error instanceof HardwareError) {
|
|
124
|
+
if (error.errorCode === HardwareErrorCode.ResponseUnexpectTypeError) {
|
|
125
|
+
if (error.message.indexOf('BridgeNetworkError') > -1) {
|
|
126
|
+
throw ERRORS.TypedError(HardwareErrorCode.BridgeNetworkError);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
// throw error anyway, next call should be resolved properly// throw error anyway, next call should be resolved properly
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
119
133
|
}
|
|
120
134
|
return response;
|
|
121
135
|
}
|
package/src/utils/index.ts
CHANGED
package/dist/data/version.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/data/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,kBAAkB,CAAC;AAEvC,eAAO,MAAM,cAAc,oCAAoC,CAAC"}
|
package/dist/utils/logger.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
declare type LogMessage = {
|
|
2
|
-
level: string;
|
|
3
|
-
prefix: string;
|
|
4
|
-
message: any[];
|
|
5
|
-
timestamp: number;
|
|
6
|
-
};
|
|
7
|
-
declare class Log {
|
|
8
|
-
prefix: string;
|
|
9
|
-
enabled: boolean;
|
|
10
|
-
css: string;
|
|
11
|
-
messages: LogMessage[];
|
|
12
|
-
constructor(prefix: string, enabled: boolean);
|
|
13
|
-
addMessage(level: string, prefix: string, ...args: any[]): void;
|
|
14
|
-
log(...args: any[]): void;
|
|
15
|
-
error(...args: any[]): void;
|
|
16
|
-
warn(...args: any[]): void;
|
|
17
|
-
debug(...args: any[]): void;
|
|
18
|
-
}
|
|
19
|
-
export declare const initLog: (prefix: string, enabled?: boolean | undefined) => Log;
|
|
20
|
-
export declare const enableLog: (enabled?: boolean | undefined) => void;
|
|
21
|
-
export declare const enableLogByPrefix: (prefix: string, enabled: boolean) => void;
|
|
22
|
-
export declare const getLog: () => LogMessage[];
|
|
23
|
-
export {};
|
|
24
|
-
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAeA,aAAK,UAAU,GAAG;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,GAAG,EAAE,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAIF,cAAM,GAAG;IACP,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,EAAE,OAAO,CAAC;IAEjB,GAAG,EAAE,MAAM,CAAC;IAEZ,QAAQ,EAAE,UAAU,EAAE,CAAC;gBAEX,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAO5C,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE;IAYxD,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAOlB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAOpB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAOnB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;CAUrB;AAID,eAAO,MAAM,OAAO,WAAY,MAAM,uCAIrC,CAAC;AAEF,eAAO,MAAM,SAAS,yCAIrB,CAAC;AAEF,eAAO,MAAM,iBAAiB,WAAY,MAAM,WAAW,OAAO,SAIjE,CAAC;AAEF,eAAO,MAAM,MAAM,oBAOlB,CAAC"}
|
package/src/data/version.ts
DELETED
package/src/utils/logger.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
const colors: Record<string, string> = {
|
|
2
|
-
// orange, api related
|
|
3
|
-
'@onekey/connect': 'color: #f4a742; background: #000;',
|
|
4
|
-
IFrame: 'color: #f4a742; background: #000;',
|
|
5
|
-
Core: 'color: #f4a742; background: #000;',
|
|
6
|
-
// green, device related
|
|
7
|
-
DescriptorStream: 'color: #77ab59; background: #000;',
|
|
8
|
-
DeviceList: 'color: #77ab59; background: #000;',
|
|
9
|
-
Device: 'color: #bada55; background: #000;',
|
|
10
|
-
DeviceCommands: 'color: #bada55; background: #000;',
|
|
11
|
-
DeviceConnector: 'color: #bada55; background: #000;',
|
|
12
|
-
// red, data-manager related
|
|
13
|
-
Transport: 'color: #ffb6c1; background: #000;',
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type LogMessage = {
|
|
17
|
-
level: string;
|
|
18
|
-
prefix: string;
|
|
19
|
-
message: any[];
|
|
20
|
-
timestamp: number;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const MAX_ENTRIES = 100;
|
|
24
|
-
|
|
25
|
-
class Log {
|
|
26
|
-
prefix: string;
|
|
27
|
-
|
|
28
|
-
enabled: boolean;
|
|
29
|
-
|
|
30
|
-
css: string;
|
|
31
|
-
|
|
32
|
-
messages: LogMessage[];
|
|
33
|
-
|
|
34
|
-
constructor(prefix: string, enabled: boolean) {
|
|
35
|
-
this.prefix = prefix;
|
|
36
|
-
this.enabled = enabled;
|
|
37
|
-
this.messages = [];
|
|
38
|
-
this.css = typeof window !== 'undefined' && colors[prefix] ? colors[prefix] : '';
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
addMessage(level: string, prefix: string, ...args: any[]) {
|
|
42
|
-
this.messages.push({
|
|
43
|
-
level,
|
|
44
|
-
prefix,
|
|
45
|
-
message: args,
|
|
46
|
-
timestamp: new Date().getTime(),
|
|
47
|
-
});
|
|
48
|
-
if (this.messages.length > MAX_ENTRIES) {
|
|
49
|
-
this.messages.shift();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
log(...args: any[]) {
|
|
54
|
-
this.addMessage('log', this.prefix, ...args);
|
|
55
|
-
if (this.enabled) {
|
|
56
|
-
console.log(this.prefix, ...args);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
error(...args: any[]) {
|
|
61
|
-
this.addMessage('error', this.prefix, ...args);
|
|
62
|
-
if (this.enabled) {
|
|
63
|
-
console.error(this.prefix, ...args);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
warn(...args: any[]) {
|
|
68
|
-
this.addMessage('warn', this.prefix, ...args);
|
|
69
|
-
if (this.enabled) {
|
|
70
|
-
console.warn(this.prefix, ...args);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
debug(...args: any[]) {
|
|
75
|
-
this.addMessage('debug', this.prefix, ...args);
|
|
76
|
-
if (this.enabled) {
|
|
77
|
-
if (this.css) {
|
|
78
|
-
console.log(`%c${this.prefix}`, this.css, ...args);
|
|
79
|
-
} else {
|
|
80
|
-
console.log(this.prefix, ...args);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const _logs: { [k: string]: Log } = {};
|
|
87
|
-
|
|
88
|
-
export const initLog = (prefix: string, enabled?: boolean) => {
|
|
89
|
-
const instance = new Log(prefix, !!enabled);
|
|
90
|
-
_logs[prefix] = instance;
|
|
91
|
-
return instance;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export const enableLog = (enabled?: boolean) => {
|
|
95
|
-
Object.keys(_logs).forEach(key => {
|
|
96
|
-
_logs[key].enabled = !!enabled;
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export const enableLogByPrefix = (prefix: string, enabled: boolean) => {
|
|
101
|
-
if (_logs[prefix]) {
|
|
102
|
-
_logs[prefix].enabled = enabled;
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
export const getLog = () => {
|
|
107
|
-
let logs: LogMessage[] = [];
|
|
108
|
-
Object.keys(_logs).forEach(key => {
|
|
109
|
-
logs = logs.concat(_logs[key].messages);
|
|
110
|
-
});
|
|
111
|
-
logs.sort((a, b) => a.timestamp - b.timestamp);
|
|
112
|
-
return logs;
|
|
113
|
-
};
|