@onekeyfe/cross-inpage-provider-core 0.0.6 → 0.0.7-alpha.3
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/README.md +1 -1
- package/dist/JsBridgeBase.d.ts +1 -1
- package/dist/JsBridgeBase.js +9 -4
- package/dist/JsBridgeSimple.d.ts +10 -0
- package/dist/JsBridgeSimple.js +19 -0
- package/dist/ProviderBase.d.ts +1 -1
- package/dist/ProviderBase.js +5 -3
- package/dist/cjs/JsBridgeBase.js +8 -3
- package/dist/cjs/JsBridgeSimple.js +22 -0
- package/dist/cjs/ProviderBase.js +4 -2
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/injectJsBridge.js +1 -1
- package/dist/cjs/injectedProviderReceiveHandler.js +3 -2
- package/dist/cjs/loggers.js +12 -1
- package/dist/cjs/versionInfo.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/injectJsBridge.js +1 -1
- package/dist/injectedProviderReceiveHandler.js +3 -2
- package/dist/loggers.d.ts +2 -1
- package/dist/loggers.js +11 -1
- package/dist/versionInfo.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
#
|
|
1
|
+
# cross-inpage-provider
|
package/dist/JsBridgeBase.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import EventEmitter from 'eventemitter3';
|
|
|
2
2
|
import { IInjectedProviderNamesStrings, IJsBridgeConfig, IJsBridgeMessagePayload, IJsonRpcResponse, IDebugLogger } from '@onekeyfe/cross-inpage-provider-types';
|
|
3
3
|
declare function isLegacyExtMessage(payload: unknown): boolean;
|
|
4
4
|
declare abstract class JsBridgeBase extends EventEmitter {
|
|
5
|
-
|
|
5
|
+
constructor(config?: IJsBridgeConfig);
|
|
6
6
|
protected isExtUi: boolean;
|
|
7
7
|
protected isInjected: boolean;
|
|
8
8
|
protected sendAsString: boolean;
|
package/dist/JsBridgeBase.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import EventEmitter from 'eventemitter3';
|
|
11
11
|
import isPlainObject from 'lodash/isPlainObject';
|
|
12
12
|
import isString from 'lodash/isString';
|
|
13
|
-
import { appDebugLogger } from './loggers';
|
|
13
|
+
import { appDebugLogger, consoleErrorInDev } from './loggers';
|
|
14
14
|
import { IJsBridgeMessageTypes, } from '@onekeyfe/cross-inpage-provider-types';
|
|
15
15
|
import { web3Errors } from '@onekeyfe/cross-inpage-provider-errors';
|
|
16
16
|
import versionInfo from './versionInfo';
|
|
@@ -80,7 +80,12 @@ class JsBridgeBase extends EventEmitter {
|
|
|
80
80
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
81
81
|
this.on(BRIDGE_EVENTS.message, this.globalOnMessage);
|
|
82
82
|
}
|
|
83
|
-
this.on(BRIDGE_EVENTS.error, (error) =>
|
|
83
|
+
this.on(BRIDGE_EVENTS.error, (error) => {
|
|
84
|
+
var _a;
|
|
85
|
+
consoleErrorInDev('JsBridge ERROR: ', error, {
|
|
86
|
+
code: (_a = error) === null || _a === void 0 ? void 0 : _a.code,
|
|
87
|
+
});
|
|
88
|
+
});
|
|
84
89
|
this.rejectExpiredCallbacks();
|
|
85
90
|
}
|
|
86
91
|
attachProviderInstance(provider) {
|
|
@@ -242,7 +247,7 @@ class JsBridgeBase extends EventEmitter {
|
|
|
242
247
|
return;
|
|
243
248
|
}
|
|
244
249
|
if (!payload.origin && !this.isInjected) {
|
|
245
|
-
|
|
250
|
+
consoleErrorInDev((_a = this === null || this === void 0 ? void 0 : this.constructor) === null || _a === void 0 ? void 0 : _a.name, '[payload.origin] is missing.', this);
|
|
246
251
|
throw new Error('JsBridge ERROR: receive message [payload.origin] is required.');
|
|
247
252
|
}
|
|
248
253
|
if (!payload.internal && !payload.scope) {
|
|
@@ -299,7 +304,7 @@ class JsBridgeBase extends EventEmitter {
|
|
|
299
304
|
request(info) {
|
|
300
305
|
const { data, remoteId, scope } = info;
|
|
301
306
|
if (data === undefined) {
|
|
302
|
-
console.warn('JsBridge ERROR:
|
|
307
|
+
console.warn('JsBridge ERROR: data required. Call like `bridge.request({ data: {...} });`');
|
|
303
308
|
}
|
|
304
309
|
return this.send({
|
|
305
310
|
type: IJsBridgeMessageTypes.REQUEST,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IJsBridgeMessagePayload } from '@onekeyfe/cross-inpage-provider-types';
|
|
2
|
+
import { JsBridgeBase } from './JsBridgeBase';
|
|
3
|
+
declare class JsBridgeSimple extends JsBridgeBase {
|
|
4
|
+
sendAsString: boolean;
|
|
5
|
+
isInjected: boolean;
|
|
6
|
+
private remote;
|
|
7
|
+
sendPayload(payload: IJsBridgeMessagePayload | string): void;
|
|
8
|
+
setRemote(remote: JsBridgeBase): void;
|
|
9
|
+
}
|
|
10
|
+
export { JsBridgeSimple };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { JsBridgeBase } from './JsBridgeBase';
|
|
2
|
+
class JsBridgeSimple extends JsBridgeBase {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.sendAsString = true;
|
|
6
|
+
this.isInjected = true;
|
|
7
|
+
this.remote = null;
|
|
8
|
+
}
|
|
9
|
+
sendPayload(payload) {
|
|
10
|
+
if (!this.remote) {
|
|
11
|
+
throw new Error('JsBridgeSimple ERROR: remote not set.');
|
|
12
|
+
}
|
|
13
|
+
this.remote.receive(payload);
|
|
14
|
+
}
|
|
15
|
+
setRemote(remote) {
|
|
16
|
+
this.remote = remote;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export { JsBridgeSimple };
|
package/dist/ProviderBase.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare type ConnectWalletInfo = {
|
|
|
21
21
|
providerState: unknown;
|
|
22
22
|
};
|
|
23
23
|
declare abstract class ProviderBase extends EventEmitter {
|
|
24
|
-
|
|
24
|
+
constructor(config: IInpageProviderConfig);
|
|
25
25
|
configDebugLogger(config: DebugLoggerConfig): void;
|
|
26
26
|
getConnectWalletInfo({ timeout }?: {
|
|
27
27
|
timeout?: number | undefined;
|
package/dist/ProviderBase.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import EventEmitter from 'eventemitter3';
|
|
11
11
|
import isFunction from 'lodash/isFunction';
|
|
12
12
|
import siteMetadata from './siteMetadata';
|
|
13
|
-
import { fakeLogger, fakeDebugLogger } from './loggers';
|
|
13
|
+
import { fakeLogger, fakeDebugLogger, consoleErrorInDev } from './loggers';
|
|
14
14
|
import versionInfo from './versionInfo';
|
|
15
15
|
const METHODS = {
|
|
16
16
|
wallet_getConnectWalletInfo: 'wallet_getConnectWalletInfo',
|
|
@@ -30,6 +30,7 @@ class ProviderBase extends EventEmitter {
|
|
|
30
30
|
this.config = config;
|
|
31
31
|
this.bridge = config.bridge;
|
|
32
32
|
this.logger = config.logger || fakeLogger;
|
|
33
|
+
// TODO init this.debugLogger first, and enable debug config after extension connect
|
|
33
34
|
this.debugLogger = ((_a = this.bridge) === null || _a === void 0 ? void 0 : _a.debugLogger) || fakeDebugLogger;
|
|
34
35
|
(_c = (_b = this.bridge) === null || _b === void 0 ? void 0 : _b.debugLogger) === null || _c === void 0 ? void 0 : _c._attachExternalLogger(this.logger);
|
|
35
36
|
setTimeout(() => {
|
|
@@ -58,7 +59,7 @@ class ProviderBase extends EventEmitter {
|
|
|
58
59
|
window.$onekey.$debugLogger = debugLogger;
|
|
59
60
|
}
|
|
60
61
|
catch (error) {
|
|
61
|
-
|
|
62
|
+
consoleErrorInDev('configDebugLogger ERROR:', error);
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
getConnectWalletInfo({ timeout = 3000 } = {}) {
|
|
@@ -93,7 +94,8 @@ class ProviderBase extends EventEmitter {
|
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
catch (err) {
|
|
96
|
-
|
|
97
|
+
// TODO wallet not installed, timeout ERROR
|
|
98
|
+
consoleErrorInDev('getConnectWalletInfo: ERROR', err);
|
|
97
99
|
resolve(null);
|
|
98
100
|
}
|
|
99
101
|
finally {
|
package/dist/cjs/JsBridgeBase.js
CHANGED
|
@@ -87,7 +87,12 @@ class JsBridgeBase extends eventemitter3_1.default {
|
|
|
87
87
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
88
88
|
this.on(BRIDGE_EVENTS.message, this.globalOnMessage);
|
|
89
89
|
}
|
|
90
|
-
this.on(BRIDGE_EVENTS.error, (error) =>
|
|
90
|
+
this.on(BRIDGE_EVENTS.error, (error) => {
|
|
91
|
+
var _a;
|
|
92
|
+
(0, loggers_1.consoleErrorInDev)('JsBridge ERROR: ', error, {
|
|
93
|
+
code: (_a = error) === null || _a === void 0 ? void 0 : _a.code,
|
|
94
|
+
});
|
|
95
|
+
});
|
|
91
96
|
this.rejectExpiredCallbacks();
|
|
92
97
|
}
|
|
93
98
|
attachProviderInstance(provider) {
|
|
@@ -249,7 +254,7 @@ class JsBridgeBase extends eventemitter3_1.default {
|
|
|
249
254
|
return;
|
|
250
255
|
}
|
|
251
256
|
if (!payload.origin && !this.isInjected) {
|
|
252
|
-
|
|
257
|
+
(0, loggers_1.consoleErrorInDev)((_a = this === null || this === void 0 ? void 0 : this.constructor) === null || _a === void 0 ? void 0 : _a.name, '[payload.origin] is missing.', this);
|
|
253
258
|
throw new Error('JsBridge ERROR: receive message [payload.origin] is required.');
|
|
254
259
|
}
|
|
255
260
|
if (!payload.internal && !payload.scope) {
|
|
@@ -306,7 +311,7 @@ class JsBridgeBase extends eventemitter3_1.default {
|
|
|
306
311
|
request(info) {
|
|
307
312
|
const { data, remoteId, scope } = info;
|
|
308
313
|
if (data === undefined) {
|
|
309
|
-
console.warn('JsBridge ERROR:
|
|
314
|
+
console.warn('JsBridge ERROR: data required. Call like `bridge.request({ data: {...} });`');
|
|
310
315
|
}
|
|
311
316
|
return this.send({
|
|
312
317
|
type: cross_inpage_provider_types_1.IJsBridgeMessageTypes.REQUEST,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsBridgeSimple = void 0;
|
|
4
|
+
const JsBridgeBase_1 = require("./JsBridgeBase");
|
|
5
|
+
class JsBridgeSimple extends JsBridgeBase_1.JsBridgeBase {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.sendAsString = true;
|
|
9
|
+
this.isInjected = true;
|
|
10
|
+
this.remote = null;
|
|
11
|
+
}
|
|
12
|
+
sendPayload(payload) {
|
|
13
|
+
if (!this.remote) {
|
|
14
|
+
throw new Error('JsBridgeSimple ERROR: remote not set.');
|
|
15
|
+
}
|
|
16
|
+
this.remote.receive(payload);
|
|
17
|
+
}
|
|
18
|
+
setRemote(remote) {
|
|
19
|
+
this.remote = remote;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.JsBridgeSimple = JsBridgeSimple;
|
package/dist/cjs/ProviderBase.js
CHANGED
|
@@ -36,6 +36,7 @@ class ProviderBase extends eventemitter3_1.default {
|
|
|
36
36
|
this.config = config;
|
|
37
37
|
this.bridge = config.bridge;
|
|
38
38
|
this.logger = config.logger || loggers_1.fakeLogger;
|
|
39
|
+
// TODO init this.debugLogger first, and enable debug config after extension connect
|
|
39
40
|
this.debugLogger = ((_a = this.bridge) === null || _a === void 0 ? void 0 : _a.debugLogger) || loggers_1.fakeDebugLogger;
|
|
40
41
|
(_c = (_b = this.bridge) === null || _b === void 0 ? void 0 : _b.debugLogger) === null || _c === void 0 ? void 0 : _c._attachExternalLogger(this.logger);
|
|
41
42
|
setTimeout(() => {
|
|
@@ -64,7 +65,7 @@ class ProviderBase extends eventemitter3_1.default {
|
|
|
64
65
|
window.$onekey.$debugLogger = debugLogger;
|
|
65
66
|
}
|
|
66
67
|
catch (error) {
|
|
67
|
-
|
|
68
|
+
(0, loggers_1.consoleErrorInDev)('configDebugLogger ERROR:', error);
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
getConnectWalletInfo({ timeout = 3000 } = {}) {
|
|
@@ -99,7 +100,8 @@ class ProviderBase extends eventemitter3_1.default {
|
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
catch (err) {
|
|
102
|
-
|
|
103
|
+
// TODO wallet not installed, timeout ERROR
|
|
104
|
+
(0, loggers_1.consoleErrorInDev)('getConnectWalletInfo: ERROR', err);
|
|
103
105
|
resolve(null);
|
|
104
106
|
}
|
|
105
107
|
finally {
|
package/dist/cjs/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __exportStar(require("./ProviderBase"), exports);
|
|
|
31
31
|
__exportStar(require("./loggers"), exports);
|
|
32
32
|
__exportStar(require("./injectJsBridge"), exports);
|
|
33
33
|
__exportStar(require("./injectedProviderReceiveHandler"), exports);
|
|
34
|
+
__exportStar(require("./JsBridgeSimple"), exports);
|
|
34
35
|
const consts = __importStar(require("./consts"));
|
|
35
36
|
exports.consts = consts;
|
|
36
37
|
const injectedFactory_1 = __importDefault(require("./injectedFactory"));
|
|
@@ -16,7 +16,7 @@ function injectJsBridge(bridgeCreator) {
|
|
|
16
16
|
if (!((_a = window === null || window === void 0 ? void 0 : window.$onekey) === null || _a === void 0 ? void 0 : _a.jsBridge)) {
|
|
17
17
|
window.$onekey = window.$onekey || {};
|
|
18
18
|
window.$onekey.jsBridge = bridgeCreator();
|
|
19
|
-
if (localStorage.getItem(consts_1.DEBUG_LOGGER_STORAGE_KEY)) {
|
|
19
|
+
if (typeof localStorage !== 'undefined' && localStorage.getItem(consts_1.DEBUG_LOGGER_STORAGE_KEY)) {
|
|
20
20
|
console.log('===== jsBridge injected success! >>>>> ', performance.now());
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.injectedProviderReceiveHandler = void 0;
|
|
4
|
+
const loggers_1 = require("./loggers");
|
|
4
5
|
function injectedProviderReceiveHandler(payload, bridge) {
|
|
5
6
|
// ethereum, solana, conflux
|
|
6
7
|
const providerHub = (bridge === null || bridge === void 0 ? void 0 : bridge.providersHub) || window.$onekey;
|
|
7
8
|
const providerName = payload.scope;
|
|
8
9
|
const payloadData = payload.data;
|
|
9
10
|
if (!providerName) {
|
|
10
|
-
|
|
11
|
+
(0, loggers_1.consoleErrorInDev)('providerName (scope) is required in injectedProviderReceiveHandler.');
|
|
11
12
|
return;
|
|
12
13
|
}
|
|
13
14
|
const providers = []
|
|
14
15
|
.concat(providerHub[providerName])
|
|
15
16
|
.filter(Boolean);
|
|
16
17
|
if (!providers || !providers.length) {
|
|
17
|
-
|
|
18
|
+
(0, loggers_1.consoleErrorInDev)(`[${providerName}] provider is NOT injected to document or bridge.`);
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
20
21
|
// emit events to injected provider
|
package/dist/cjs/loggers.js
CHANGED
|
@@ -3,11 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fakeLogger = exports.appDebugLogger = exports.fakeDebugLogger = void 0;
|
|
6
|
+
exports.consoleErrorInDev = exports.fakeLogger = exports.appDebugLogger = exports.fakeDebugLogger = void 0;
|
|
7
7
|
// @ts-ignore
|
|
8
8
|
const debug_1 = __importDefault(require("./debug"));
|
|
9
|
+
const consts_1 = require("./consts");
|
|
9
10
|
// enable debugLogger:
|
|
10
11
|
// localStorage.setItem('$$ONEKEY_DEBUG_LOGGER', '*');
|
|
12
|
+
function consoleErrorInDev(...args) {
|
|
13
|
+
const loggerConfig = typeof localStorage !== 'undefined' && localStorage.getItem(consts_1.DEBUG_LOGGER_STORAGE_KEY);
|
|
14
|
+
if (process.env.NODE_ENV !== 'production' || loggerConfig) {
|
|
15
|
+
console.error(...args);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.consoleErrorInDev = consoleErrorInDev;
|
|
11
19
|
const fakeLogger = {
|
|
12
20
|
// @ts-ignore
|
|
13
21
|
_isFakeLogger: true,
|
|
@@ -38,6 +46,9 @@ class FakeDebugLogger {
|
|
|
38
46
|
this.providerBase = this._createExternalLog('providerBase >>');
|
|
39
47
|
this.extInjected = this._createExternalLog('extInjected >>');
|
|
40
48
|
this.extContentScripts = this._createExternalLog('extContentScripts >>');
|
|
49
|
+
this.webview = this._createExternalLog('webview >>');
|
|
50
|
+
this.desktopInjected = this._createExternalLog('desktopInjected >>');
|
|
51
|
+
this.ethereum = this._createExternalLog('ethereum >>');
|
|
41
52
|
}
|
|
42
53
|
_attachExternalLogger(logger) {
|
|
43
54
|
if (logger) {
|
package/dist/cjs/versionInfo.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from './ProviderBase';
|
|
|
3
3
|
export * from './loggers';
|
|
4
4
|
export * from './injectJsBridge';
|
|
5
5
|
export * from './injectedProviderReceiveHandler';
|
|
6
|
+
export * from './JsBridgeSimple';
|
|
6
7
|
import * as consts from './consts';
|
|
7
8
|
export { consts };
|
|
8
9
|
import injectedFactory from './injectedFactory';
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export * from './ProviderBase';
|
|
|
3
3
|
export * from './loggers';
|
|
4
4
|
export * from './injectJsBridge';
|
|
5
5
|
export * from './injectedProviderReceiveHandler';
|
|
6
|
+
export * from './JsBridgeSimple';
|
|
6
7
|
import * as consts from './consts';
|
|
7
8
|
export { consts };
|
|
8
9
|
import injectedFactory from './injectedFactory';
|
package/dist/injectJsBridge.js
CHANGED
|
@@ -13,7 +13,7 @@ function injectJsBridge(bridgeCreator) {
|
|
|
13
13
|
if (!((_a = window === null || window === void 0 ? void 0 : window.$onekey) === null || _a === void 0 ? void 0 : _a.jsBridge)) {
|
|
14
14
|
window.$onekey = window.$onekey || {};
|
|
15
15
|
window.$onekey.jsBridge = bridgeCreator();
|
|
16
|
-
if (localStorage.getItem(DEBUG_LOGGER_STORAGE_KEY)) {
|
|
16
|
+
if (typeof localStorage !== 'undefined' && localStorage.getItem(DEBUG_LOGGER_STORAGE_KEY)) {
|
|
17
17
|
console.log('===== jsBridge injected success! >>>>> ', performance.now());
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import { consoleErrorInDev } from './loggers';
|
|
1
2
|
function injectedProviderReceiveHandler(payload, bridge) {
|
|
2
3
|
// ethereum, solana, conflux
|
|
3
4
|
const providerHub = (bridge === null || bridge === void 0 ? void 0 : bridge.providersHub) || window.$onekey;
|
|
4
5
|
const providerName = payload.scope;
|
|
5
6
|
const payloadData = payload.data;
|
|
6
7
|
if (!providerName) {
|
|
7
|
-
|
|
8
|
+
consoleErrorInDev('providerName (scope) is required in injectedProviderReceiveHandler.');
|
|
8
9
|
return;
|
|
9
10
|
}
|
|
10
11
|
const providers = []
|
|
11
12
|
.concat(providerHub[providerName])
|
|
12
13
|
.filter(Boolean);
|
|
13
14
|
if (!providers || !providers.length) {
|
|
14
|
-
|
|
15
|
+
consoleErrorInDev(`[${providerName}] provider is NOT injected to document or bridge.`);
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
17
18
|
// emit events to injected provider
|
package/dist/loggers.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IDebugLogger, ConsoleLike } from '@onekeyfe/cross-inpage-provider-types';
|
|
2
|
+
declare function consoleErrorInDev(...args: unknown[]): void;
|
|
2
3
|
declare const fakeLogger: ConsoleLike;
|
|
3
4
|
declare const fakeDebugLogger: IDebugLogger;
|
|
4
5
|
declare const appDebugLogger: IDebugLogger;
|
|
5
|
-
export { fakeDebugLogger, appDebugLogger, fakeLogger };
|
|
6
|
+
export { fakeDebugLogger, appDebugLogger, fakeLogger, consoleErrorInDev };
|
package/dist/loggers.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
2
|
import createDebugAsync from './debug';
|
|
3
|
+
import { DEBUG_LOGGER_STORAGE_KEY } from './consts';
|
|
3
4
|
// enable debugLogger:
|
|
4
5
|
// localStorage.setItem('$$ONEKEY_DEBUG_LOGGER', '*');
|
|
6
|
+
function consoleErrorInDev(...args) {
|
|
7
|
+
const loggerConfig = typeof localStorage !== 'undefined' && localStorage.getItem(DEBUG_LOGGER_STORAGE_KEY);
|
|
8
|
+
if (process.env.NODE_ENV !== 'production' || loggerConfig) {
|
|
9
|
+
console.error(...args);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
5
12
|
const fakeLogger = {
|
|
6
13
|
// @ts-ignore
|
|
7
14
|
_isFakeLogger: true,
|
|
@@ -31,6 +38,9 @@ class FakeDebugLogger {
|
|
|
31
38
|
this.providerBase = this._createExternalLog('providerBase >>');
|
|
32
39
|
this.extInjected = this._createExternalLog('extInjected >>');
|
|
33
40
|
this.extContentScripts = this._createExternalLog('extContentScripts >>');
|
|
41
|
+
this.webview = this._createExternalLog('webview >>');
|
|
42
|
+
this.desktopInjected = this._createExternalLog('desktopInjected >>');
|
|
43
|
+
this.ethereum = this._createExternalLog('ethereum >>');
|
|
34
44
|
}
|
|
35
45
|
_attachExternalLogger(logger) {
|
|
36
46
|
if (logger) {
|
|
@@ -73,4 +83,4 @@ class AppDebugLogger extends FakeDebugLogger {
|
|
|
73
83
|
// TODO merge FakeDebugLogger and AppDebugLogger to single class
|
|
74
84
|
const fakeDebugLogger = new FakeDebugLogger();
|
|
75
85
|
const appDebugLogger = new AppDebugLogger();
|
|
76
|
-
export { fakeDebugLogger, appDebugLogger, fakeLogger };
|
|
86
|
+
export { fakeDebugLogger, appDebugLogger, fakeLogger, consoleErrorInDev };
|
package/dist/versionInfo.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/cross-inpage-provider-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7-alpha.3",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"cross-inpage-provider"
|
|
6
6
|
],
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"build-version-info": "node ./scripts/buildVersionInfo.js"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@onekeyfe/cross-inpage-provider-errors": "^0.0.
|
|
33
|
-
"@onekeyfe/cross-inpage-provider-types": "^0.0.
|
|
32
|
+
"@onekeyfe/cross-inpage-provider-errors": "^0.0.7-alpha.3",
|
|
33
|
+
"@onekeyfe/cross-inpage-provider-types": "^0.0.7-alpha.3",
|
|
34
34
|
"eventemitter3": "^4.0.7",
|
|
35
35
|
"lodash": "^4.17.21",
|
|
36
36
|
"ms": "^2.1.3"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "ff317617a1d5d8d1bc7f6957dcd6e27117192c64"
|
|
39
39
|
}
|