@onekeyfe/cross-inpage-provider-core 0.0.4 → 0.0.7-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/JsBridgeBase.d.ts +1 -1
- package/dist/JsBridgeBase.js +11 -5
- package/dist/ProviderBase.d.ts +2 -1
- package/dist/ProviderBase.js +7 -3
- package/dist/cjs/JsBridgeBase.js +10 -4
- package/dist/cjs/ProviderBase.js +6 -2
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/injectJsBridge.js +1 -1
- package/dist/cjs/injectedProviderReceiveHandler.js +3 -2
- package/dist/cjs/loggers.js +30 -6
- package/dist/cjs/versionInfo.js +8 -0
- 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 +29 -6
- package/dist/versionInfo.d.ts +5 -0
- package/dist/versionInfo.js +6 -0
- package/package.json +7 -6
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,9 +10,10 @@ 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
|
+
import versionInfo from './versionInfo';
|
|
16
17
|
function isLegacyExtMessage(payload) {
|
|
17
18
|
const payloadObj = payload;
|
|
18
19
|
return (Boolean(payloadObj.name) &&
|
|
@@ -63,6 +64,7 @@ class JsBridgeBase extends EventEmitter {
|
|
|
63
64
|
// noop
|
|
64
65
|
}
|
|
65
66
|
});
|
|
67
|
+
this.version = versionInfo.version;
|
|
66
68
|
this.remoteInfo = {
|
|
67
69
|
origin: '',
|
|
68
70
|
remoteId: '',
|
|
@@ -74,12 +76,16 @@ class JsBridgeBase extends EventEmitter {
|
|
|
74
76
|
this.callbacksExpireTimeout = (_a = config.timeout) !== null && _a !== void 0 ? _a : 60 * 1000;
|
|
75
77
|
this.debugLogger = config.debugLogger || appDebugLogger;
|
|
76
78
|
this.sendAsString = (_b = config.sendAsString) !== null && _b !== void 0 ? _b : this.sendAsString;
|
|
77
|
-
this.version = process.env.VERSION || '';
|
|
78
79
|
if (this.config.receiveHandler) {
|
|
79
80
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
80
81
|
this.on(BRIDGE_EVENTS.message, this.globalOnMessage);
|
|
81
82
|
}
|
|
82
|
-
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
|
+
});
|
|
83
89
|
this.rejectExpiredCallbacks();
|
|
84
90
|
}
|
|
85
91
|
attachProviderInstance(provider) {
|
|
@@ -241,7 +247,7 @@ class JsBridgeBase extends EventEmitter {
|
|
|
241
247
|
return;
|
|
242
248
|
}
|
|
243
249
|
if (!payload.origin && !this.isInjected) {
|
|
244
|
-
|
|
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);
|
|
245
251
|
throw new Error('JsBridge ERROR: receive message [payload.origin] is required.');
|
|
246
252
|
}
|
|
247
253
|
if (!payload.internal && !payload.scope) {
|
|
@@ -298,7 +304,7 @@ class JsBridgeBase extends EventEmitter {
|
|
|
298
304
|
request(info) {
|
|
299
305
|
const { data, remoteId, scope } = info;
|
|
300
306
|
if (data === undefined) {
|
|
301
|
-
console.warn('JsBridge ERROR:
|
|
307
|
+
console.warn('JsBridge ERROR: data required. Call like `bridge.request({ data: {...} });`');
|
|
302
308
|
}
|
|
303
309
|
return this.send({
|
|
304
310
|
type: IJsBridgeMessageTypes.REQUEST,
|
package/dist/ProviderBase.d.ts
CHANGED
|
@@ -21,11 +21,12 @@ 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;
|
|
28
28
|
}): Promise<ConnectWalletInfo | null>;
|
|
29
|
+
version: string;
|
|
29
30
|
isOneKey: boolean;
|
|
30
31
|
protected abstract providerName: IInjectedProviderNamesStrings;
|
|
31
32
|
protected readonly config: IInpageProviderConfig;
|
package/dist/ProviderBase.js
CHANGED
|
@@ -10,7 +10,8 @@ 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
|
+
import versionInfo from './versionInfo';
|
|
14
15
|
const METHODS = {
|
|
15
16
|
wallet_getConnectWalletInfo: 'wallet_getConnectWalletInfo',
|
|
16
17
|
wallet_sendSiteMetadata: 'wallet_sendSiteMetadata',
|
|
@@ -19,6 +20,7 @@ class ProviderBase extends EventEmitter {
|
|
|
19
20
|
constructor(config) {
|
|
20
21
|
var _a, _b, _c;
|
|
21
22
|
super();
|
|
23
|
+
this.version = versionInfo.version;
|
|
22
24
|
this.isOneKey = true;
|
|
23
25
|
this.debugLogger = fakeDebugLogger;
|
|
24
26
|
this.logger = fakeLogger;
|
|
@@ -28,6 +30,7 @@ class ProviderBase extends EventEmitter {
|
|
|
28
30
|
this.config = config;
|
|
29
31
|
this.bridge = config.bridge;
|
|
30
32
|
this.logger = config.logger || fakeLogger;
|
|
33
|
+
// TODO init this.debugLogger first, and enable debug config after extension connect
|
|
31
34
|
this.debugLogger = ((_a = this.bridge) === null || _a === void 0 ? void 0 : _a.debugLogger) || fakeDebugLogger;
|
|
32
35
|
(_c = (_b = this.bridge) === null || _b === void 0 ? void 0 : _b.debugLogger) === null || _c === void 0 ? void 0 : _c._attachExternalLogger(this.logger);
|
|
33
36
|
setTimeout(() => {
|
|
@@ -56,7 +59,7 @@ class ProviderBase extends EventEmitter {
|
|
|
56
59
|
window.$onekey.$debugLogger = debugLogger;
|
|
57
60
|
}
|
|
58
61
|
catch (error) {
|
|
59
|
-
|
|
62
|
+
consoleErrorInDev('configDebugLogger ERROR:', error);
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
65
|
getConnectWalletInfo({ timeout = 3000 } = {}) {
|
|
@@ -91,7 +94,8 @@ class ProviderBase extends EventEmitter {
|
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
catch (err) {
|
|
94
|
-
|
|
97
|
+
// TODO wallet not installed, timeout ERROR
|
|
98
|
+
consoleErrorInDev('getConnectWalletInfo: ERROR', err);
|
|
95
99
|
resolve(null);
|
|
96
100
|
}
|
|
97
101
|
finally {
|
package/dist/cjs/JsBridgeBase.js
CHANGED
|
@@ -19,6 +19,7 @@ const isString_1 = __importDefault(require("lodash/isString"));
|
|
|
19
19
|
const loggers_1 = require("./loggers");
|
|
20
20
|
const cross_inpage_provider_types_1 = require("@onekeyfe/cross-inpage-provider-types");
|
|
21
21
|
const cross_inpage_provider_errors_1 = require("@onekeyfe/cross-inpage-provider-errors");
|
|
22
|
+
const versionInfo_1 = __importDefault(require("./versionInfo"));
|
|
22
23
|
function isLegacyExtMessage(payload) {
|
|
23
24
|
const payloadObj = payload;
|
|
24
25
|
return (Boolean(payloadObj.name) &&
|
|
@@ -70,6 +71,7 @@ class JsBridgeBase extends eventemitter3_1.default {
|
|
|
70
71
|
// noop
|
|
71
72
|
}
|
|
72
73
|
});
|
|
74
|
+
this.version = versionInfo_1.default.version;
|
|
73
75
|
this.remoteInfo = {
|
|
74
76
|
origin: '',
|
|
75
77
|
remoteId: '',
|
|
@@ -81,12 +83,16 @@ class JsBridgeBase extends eventemitter3_1.default {
|
|
|
81
83
|
this.callbacksExpireTimeout = (_a = config.timeout) !== null && _a !== void 0 ? _a : 60 * 1000;
|
|
82
84
|
this.debugLogger = config.debugLogger || loggers_1.appDebugLogger;
|
|
83
85
|
this.sendAsString = (_b = config.sendAsString) !== null && _b !== void 0 ? _b : this.sendAsString;
|
|
84
|
-
this.version = process.env.VERSION || '';
|
|
85
86
|
if (this.config.receiveHandler) {
|
|
86
87
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
87
88
|
this.on(BRIDGE_EVENTS.message, this.globalOnMessage);
|
|
88
89
|
}
|
|
89
|
-
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
|
+
});
|
|
90
96
|
this.rejectExpiredCallbacks();
|
|
91
97
|
}
|
|
92
98
|
attachProviderInstance(provider) {
|
|
@@ -248,7 +254,7 @@ class JsBridgeBase extends eventemitter3_1.default {
|
|
|
248
254
|
return;
|
|
249
255
|
}
|
|
250
256
|
if (!payload.origin && !this.isInjected) {
|
|
251
|
-
|
|
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);
|
|
252
258
|
throw new Error('JsBridge ERROR: receive message [payload.origin] is required.');
|
|
253
259
|
}
|
|
254
260
|
if (!payload.internal && !payload.scope) {
|
|
@@ -305,7 +311,7 @@ class JsBridgeBase extends eventemitter3_1.default {
|
|
|
305
311
|
request(info) {
|
|
306
312
|
const { data, remoteId, scope } = info;
|
|
307
313
|
if (data === undefined) {
|
|
308
|
-
console.warn('JsBridge ERROR:
|
|
314
|
+
console.warn('JsBridge ERROR: data required. Call like `bridge.request({ data: {...} });`');
|
|
309
315
|
}
|
|
310
316
|
return this.send({
|
|
311
317
|
type: cross_inpage_provider_types_1.IJsBridgeMessageTypes.REQUEST,
|
package/dist/cjs/ProviderBase.js
CHANGED
|
@@ -17,6 +17,7 @@ const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
|
17
17
|
const isFunction_1 = __importDefault(require("lodash/isFunction"));
|
|
18
18
|
const siteMetadata_1 = __importDefault(require("./siteMetadata"));
|
|
19
19
|
const loggers_1 = require("./loggers");
|
|
20
|
+
const versionInfo_1 = __importDefault(require("./versionInfo"));
|
|
20
21
|
const METHODS = {
|
|
21
22
|
wallet_getConnectWalletInfo: 'wallet_getConnectWalletInfo',
|
|
22
23
|
wallet_sendSiteMetadata: 'wallet_sendSiteMetadata',
|
|
@@ -25,6 +26,7 @@ class ProviderBase extends eventemitter3_1.default {
|
|
|
25
26
|
constructor(config) {
|
|
26
27
|
var _a, _b, _c;
|
|
27
28
|
super();
|
|
29
|
+
this.version = versionInfo_1.default.version;
|
|
28
30
|
this.isOneKey = true;
|
|
29
31
|
this.debugLogger = loggers_1.fakeDebugLogger;
|
|
30
32
|
this.logger = loggers_1.fakeLogger;
|
|
@@ -34,6 +36,7 @@ class ProviderBase extends eventemitter3_1.default {
|
|
|
34
36
|
this.config = config;
|
|
35
37
|
this.bridge = config.bridge;
|
|
36
38
|
this.logger = config.logger || loggers_1.fakeLogger;
|
|
39
|
+
// TODO init this.debugLogger first, and enable debug config after extension connect
|
|
37
40
|
this.debugLogger = ((_a = this.bridge) === null || _a === void 0 ? void 0 : _a.debugLogger) || loggers_1.fakeDebugLogger;
|
|
38
41
|
(_c = (_b = this.bridge) === null || _b === void 0 ? void 0 : _b.debugLogger) === null || _c === void 0 ? void 0 : _c._attachExternalLogger(this.logger);
|
|
39
42
|
setTimeout(() => {
|
|
@@ -62,7 +65,7 @@ class ProviderBase extends eventemitter3_1.default {
|
|
|
62
65
|
window.$onekey.$debugLogger = debugLogger;
|
|
63
66
|
}
|
|
64
67
|
catch (error) {
|
|
65
|
-
|
|
68
|
+
(0, loggers_1.consoleErrorInDev)('configDebugLogger ERROR:', error);
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
71
|
getConnectWalletInfo({ timeout = 3000 } = {}) {
|
|
@@ -97,7 +100,8 @@ class ProviderBase extends eventemitter3_1.default {
|
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
102
|
catch (err) {
|
|
100
|
-
|
|
103
|
+
// TODO wallet not installed, timeout ERROR
|
|
104
|
+
(0, loggers_1.consoleErrorInDev)('getConnectWalletInfo: ERROR', err);
|
|
101
105
|
resolve(null);
|
|
102
106
|
}
|
|
103
107
|
finally {
|
package/dist/cjs/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
25
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.siteMetadata = exports.injectedFactory = exports.consts = void 0;
|
|
28
|
+
exports.versionInfo = exports.siteMetadata = exports.injectedFactory = exports.consts = void 0;
|
|
29
29
|
__exportStar(require("./JsBridgeBase"), exports);
|
|
30
30
|
__exportStar(require("./ProviderBase"), exports);
|
|
31
31
|
__exportStar(require("./loggers"), exports);
|
|
@@ -37,3 +37,5 @@ const injectedFactory_1 = __importDefault(require("./injectedFactory"));
|
|
|
37
37
|
exports.injectedFactory = injectedFactory_1.default;
|
|
38
38
|
const siteMetadata_1 = __importDefault(require("./siteMetadata"));
|
|
39
39
|
exports.siteMetadata = siteMetadata_1.default;
|
|
40
|
+
var versionInfo_1 = require("./versionInfo");
|
|
41
|
+
Object.defineProperty(exports, "versionInfo", { enumerable: true, get: function () { return __importDefault(versionInfo_1).default; } });
|
|
@@ -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,22 @@ 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;
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
|
+
exports.consoleErrorInDev = exports.fakeLogger = exports.appDebugLogger = exports.fakeDebugLogger = void 0;
|
|
8
7
|
// @ts-ignore
|
|
9
8
|
const debug_1 = __importDefault(require("./debug"));
|
|
9
|
+
const consts_1 = require("./consts");
|
|
10
|
+
// enable debugLogger:
|
|
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;
|
|
10
19
|
const fakeLogger = {
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
_isFakeLogger: true,
|
|
11
22
|
log: (...args) => undefined,
|
|
12
23
|
warn: (...args) => undefined,
|
|
13
24
|
error: (...args) => undefined,
|
|
@@ -35,6 +46,8 @@ class FakeDebugLogger {
|
|
|
35
46
|
this.providerBase = this._createExternalLog('providerBase >>');
|
|
36
47
|
this.extInjected = this._createExternalLog('extInjected >>');
|
|
37
48
|
this.extContentScripts = this._createExternalLog('extContentScripts >>');
|
|
49
|
+
this.webview = this._createExternalLog('webview >>');
|
|
50
|
+
this.desktopInjected = this._createExternalLog('desktopInjected >>');
|
|
38
51
|
}
|
|
39
52
|
_attachExternalLogger(logger) {
|
|
40
53
|
if (logger) {
|
|
@@ -48,22 +61,33 @@ class FakeDebugLogger {
|
|
|
48
61
|
class AppDebugLogger extends FakeDebugLogger {
|
|
49
62
|
constructor() {
|
|
50
63
|
super();
|
|
64
|
+
this._debugInstanceCreatedMap = {};
|
|
51
65
|
void (0, debug_1.default)().then((debug) => (this._debug = debug));
|
|
52
66
|
}
|
|
53
67
|
_createDebugInstance(name) {
|
|
68
|
+
if (this._debugInstanceCreatedMap[name]) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this._debugInstanceCreatedMap[name] = true;
|
|
54
72
|
if (name && this._debug && typeof this._debug === 'function') {
|
|
55
73
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
|
|
56
|
-
const
|
|
57
|
-
//
|
|
74
|
+
const _debugLog = this._debug(name);
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
const _originLog = this[name];
|
|
58
77
|
// @ts-ignore
|
|
59
78
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
|
|
60
79
|
this[name] = (...args) => {
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-
|
|
62
|
-
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
81
|
+
_debugLog(...args);
|
|
82
|
+
if (_originLog && typeof _originLog === 'function') {
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
84
|
+
_originLog(...args);
|
|
85
|
+
}
|
|
63
86
|
};
|
|
64
87
|
}
|
|
65
88
|
}
|
|
66
89
|
}
|
|
90
|
+
// TODO merge FakeDebugLogger and AppDebugLogger to single class
|
|
67
91
|
const fakeDebugLogger = new FakeDebugLogger();
|
|
68
92
|
exports.fakeDebugLogger = fakeDebugLogger;
|
|
69
93
|
const appDebugLogger = new AppDebugLogger();
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
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,17 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
1
|
// @ts-ignore
|
|
3
2
|
import createDebugAsync from './debug';
|
|
3
|
+
import { DEBUG_LOGGER_STORAGE_KEY } from './consts';
|
|
4
|
+
// enable debugLogger:
|
|
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
|
+
}
|
|
4
12
|
const fakeLogger = {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
_isFakeLogger: true,
|
|
5
15
|
log: (...args) => undefined,
|
|
6
16
|
warn: (...args) => undefined,
|
|
7
17
|
error: (...args) => undefined,
|
|
@@ -28,6 +38,8 @@ class FakeDebugLogger {
|
|
|
28
38
|
this.providerBase = this._createExternalLog('providerBase >>');
|
|
29
39
|
this.extInjected = this._createExternalLog('extInjected >>');
|
|
30
40
|
this.extContentScripts = this._createExternalLog('extContentScripts >>');
|
|
41
|
+
this.webview = this._createExternalLog('webview >>');
|
|
42
|
+
this.desktopInjected = this._createExternalLog('desktopInjected >>');
|
|
31
43
|
}
|
|
32
44
|
_attachExternalLogger(logger) {
|
|
33
45
|
if (logger) {
|
|
@@ -41,22 +53,33 @@ class FakeDebugLogger {
|
|
|
41
53
|
class AppDebugLogger extends FakeDebugLogger {
|
|
42
54
|
constructor() {
|
|
43
55
|
super();
|
|
56
|
+
this._debugInstanceCreatedMap = {};
|
|
44
57
|
void createDebugAsync().then((debug) => (this._debug = debug));
|
|
45
58
|
}
|
|
46
59
|
_createDebugInstance(name) {
|
|
60
|
+
if (this._debugInstanceCreatedMap[name]) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this._debugInstanceCreatedMap[name] = true;
|
|
47
64
|
if (name && this._debug && typeof this._debug === 'function') {
|
|
48
65
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
|
|
49
|
-
const
|
|
50
|
-
//
|
|
66
|
+
const _debugLog = this._debug(name);
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
const _originLog = this[name];
|
|
51
69
|
// @ts-ignore
|
|
52
70
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
|
|
53
71
|
this[name] = (...args) => {
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-
|
|
55
|
-
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
73
|
+
_debugLog(...args);
|
|
74
|
+
if (_originLog && typeof _originLog === 'function') {
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
76
|
+
_originLog(...args);
|
|
77
|
+
}
|
|
56
78
|
};
|
|
57
79
|
}
|
|
58
80
|
}
|
|
59
81
|
}
|
|
82
|
+
// TODO merge FakeDebugLogger and AppDebugLogger to single class
|
|
60
83
|
const fakeDebugLogger = new FakeDebugLogger();
|
|
61
84
|
const appDebugLogger = new AppDebugLogger();
|
|
62
|
-
export { fakeDebugLogger, appDebugLogger, fakeLogger };
|
|
85
|
+
export { fakeDebugLogger, appDebugLogger, fakeLogger, consoleErrorInDev };
|
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.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"cross-inpage-provider"
|
|
6
6
|
],
|
|
@@ -24,15 +24,16 @@
|
|
|
24
24
|
"main": "./dist/cjs/index.js",
|
|
25
25
|
"scripts": {
|
|
26
26
|
"prebuild": "rm -rf dist",
|
|
27
|
-
"build": "tsc && tsc --project tsconfig.cjs.json",
|
|
28
|
-
"start": "tsc --watch"
|
|
27
|
+
"build": "yarn build-version-info && tsc && tsc --project tsconfig.cjs.json",
|
|
28
|
+
"start": "tsc --watch",
|
|
29
|
+
"build-version-info": "node ./scripts/buildVersionInfo.js"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@onekeyfe/cross-inpage-provider-errors": "^0.0.
|
|
32
|
-
"@onekeyfe/cross-inpage-provider-types": "^0.0.
|
|
32
|
+
"@onekeyfe/cross-inpage-provider-errors": "^0.0.7-alpha.0",
|
|
33
|
+
"@onekeyfe/cross-inpage-provider-types": "^0.0.7-alpha.0",
|
|
33
34
|
"eventemitter3": "^4.0.7",
|
|
34
35
|
"lodash": "^4.17.21",
|
|
35
36
|
"ms": "^2.1.3"
|
|
36
37
|
},
|
|
37
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "e163439202ef5f85319d7dc9bc7c18ee7d6a0b7b"
|
|
38
39
|
}
|