hunter-open-sdk 2.0.0-beta.3 → 2.0.0-beta.30
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/lib/abilities/activate/index.js +51 -0
- package/lib/abilities/activate/worker.js +19 -0
- package/lib/abilities/erase/index.js +51 -0
- package/lib/abilities/erase/worker.js +19 -0
- package/lib/abilities/eventManager/index.js +347 -0
- package/lib/abilities/getAndroidReport/index.js +60 -0
- package/lib/abilities/getAndroidReport/worker.js +21 -0
- package/lib/abilities/getAndroidSn/index.js +187 -0
- package/lib/abilities/getGeneralReport/index.js +75 -0
- package/lib/abilities/getGeneralReport/worker.js +38 -0
- package/lib/abilities/getSaaSReport/index.js +51 -0
- package/lib/abilities/getSaaSReport/worker.js +21 -0
- package/lib/abilities/getUltimateReport/index.js +59 -0
- package/lib/abilities/getUltimateReport/worker.js +21 -0
- package/lib/abilities/installApp/index.js +51 -0
- package/lib/abilities/installApp/worker.js +19 -0
- package/lib/abilities/reboot/index.js +51 -0
- package/lib/abilities/reboot/worker.js +19 -0
- package/lib/abilities/shutdown/index.js +51 -0
- package/lib/abilities/shutdown/worker.js +19 -0
- package/lib/abilities/skip/index.js +51 -0
- package/lib/abilities/skip/worker.js +19 -0
- package/lib/constants/index.js +28 -0
- package/lib/events/driver/command.js +8 -9
- package/lib/events/driver/winDriver.js +123 -189
- package/lib/helper/deviceHelper.js +19 -37
- package/lib/index.d.ts +70 -0
- package/lib/index.js +115 -13
- package/lib/index.mjs +2 -0
- package/lib/resources/dll/{libinspectionkit_x64_0.1.0.dll → libinspectionkit_x64_0.6.1.dll} +0 -0
- package/lib/resources/{mac/libinspectionkit_arm64_0.1.0.dylib → dylib/libinspectionkit_amd64_0.6.1.dylib} +0 -0
- package/lib/resources/dylib/libinspectionkit_arm64_0.6.1.dylib +0 -0
- package/lib/resources/version.online +1 -1
- package/lib/utils/utils.ability.js +9 -0
- package/lib/utils/utils.command.js +8 -9
- package/lib/utils/utils.common.js +26 -0
- package/lib/utils/{utils.js → utils.env.js} +19 -18
- package/lib/utils/utils.global.js +70 -89
- package/lib/utils/utils.initDll.js +16 -14
- package/lib/utils/utils.path.js +56 -7
- package/lib/utils/utils.process.js +35 -0
- package/lib/utils/utils.sn.js +41 -56
- package/lib/utils/utils.worker.js +32 -0
- package/package.json +15 -8
- package/lib/events/driver/service.js +0 -47
- package/lib/getAndroidSn/index.js +0 -228
- package/lib/getGeneralReport/index.js +0 -76
- package/lib/getGeneralReport/worker.js +0 -20
- package/lib/getSaaSReport/index.js +0 -76
- package/lib/getSaaSReport/worker.js +0 -20
- package/lib/registerEvent/index.js +0 -427
- package/lib/resources/mac/libinspectionkit_amd64_0.1.0.dylib +0 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export interface CallbackResult {
|
|
2
|
+
data: {
|
|
3
|
+
eventName: string
|
|
4
|
+
eventCode: number
|
|
5
|
+
udid?: string
|
|
6
|
+
eventContent?: string
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface SnCallbackResult {
|
|
11
|
+
data: {
|
|
12
|
+
eventName: string
|
|
13
|
+
eventCode: number
|
|
14
|
+
eventContent?: { SN: string; brand: string }
|
|
15
|
+
message?: string
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface GetGeneralReportOptions {
|
|
20
|
+
useMultiWorker?: boolean
|
|
21
|
+
poolSize?: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type EventCallback = (result: CallbackResult) => void
|
|
25
|
+
export type SnCallback = (result: SnCallbackResult) => void
|
|
26
|
+
export type ReportCallback = (result: any) => void
|
|
27
|
+
|
|
28
|
+
export declare function registerEvent(params: string, callback: EventCallback): Promise<void>
|
|
29
|
+
export declare function unregisterEvent(): void
|
|
30
|
+
export declare function registerGetAndroidSn(params: any, callback: SnCallback): void
|
|
31
|
+
export declare function unregisterGetAndroidSn(): void
|
|
32
|
+
export declare function getSaaSReport(params: any, callback?: ReportCallback): void
|
|
33
|
+
export interface AndroidReportParams {
|
|
34
|
+
imei: string
|
|
35
|
+
brandCode: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export declare function getGeneralReport(params: any, callback?: ReportCallback, options?: GetGeneralReportOptions): void
|
|
39
|
+
export interface UltimateReportParams {
|
|
40
|
+
udid: string
|
|
41
|
+
simpleReportId?: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export declare function getAndroidReport(params: AndroidReportParams, callback?: ReportCallback): void
|
|
45
|
+
export declare function getUltimateReport(params: UltimateReportParams, callback?: ReportCallback): void
|
|
46
|
+
export declare function erase(params: any, callback?: ReportCallback): void
|
|
47
|
+
export declare function activate(params: any, callback?: ReportCallback): void
|
|
48
|
+
export declare function skip(params: any, callback?: ReportCallback): void
|
|
49
|
+
export declare function reboot(params: any, callback?: ReportCallback): void
|
|
50
|
+
export declare function shutdown(params: any, callback?: ReportCallback): void
|
|
51
|
+
export declare function installApp(params: any, callback?: ReportCallback): void
|
|
52
|
+
|
|
53
|
+
declare const sdk: {
|
|
54
|
+
registerEvent: typeof registerEvent
|
|
55
|
+
unregisterEvent: typeof unregisterEvent
|
|
56
|
+
registerGetAndroidSn: typeof registerGetAndroidSn
|
|
57
|
+
unregisterGetAndroidSn: typeof unregisterGetAndroidSn
|
|
58
|
+
getSaaSReport: typeof getSaaSReport
|
|
59
|
+
getGeneralReport: typeof getGeneralReport
|
|
60
|
+
getAndroidReport: typeof getAndroidReport
|
|
61
|
+
getUltimateReport: typeof getUltimateReport
|
|
62
|
+
erase: typeof erase
|
|
63
|
+
activate: typeof activate
|
|
64
|
+
skip: typeof skip
|
|
65
|
+
reboot: typeof reboot
|
|
66
|
+
shutdown: typeof shutdown
|
|
67
|
+
installApp: typeof installApp
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default sdk
|
package/lib/index.js
CHANGED
|
@@ -3,23 +3,125 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "activate", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _activate.activate;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
Object.defineProperty(exports, "erase", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _erase.erase;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "getAndroidReport", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _getAndroidReport.getAndroidReport;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "getGeneralReport", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _getGeneralReport.getGeneralReport;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "getSaaSReport", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () {
|
|
34
|
+
return _getSaaSReport.getSaaSReport;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "getUltimateReport", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return _getUltimateReport.getUltimateReport;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(exports, "installApp", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _installApp.installApp;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(exports, "reboot", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function () {
|
|
52
|
+
return _reboot.reboot;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(exports, "registerEvent", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function () {
|
|
58
|
+
return _eventManager.registerEvent;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(exports, "registerGetAndroidSn", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function () {
|
|
64
|
+
return _getAndroidSn.registerGetAndroidSn;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(exports, "shutdown", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function () {
|
|
70
|
+
return _shutdown.shutdown;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(exports, "skip", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
get: function () {
|
|
76
|
+
return _skip.skip;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(exports, "unregisterEvent", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
get: function () {
|
|
82
|
+
return _eventManager.unregisterEvent;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
Object.defineProperty(exports, "unregisterGetAndroidSn", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get: function () {
|
|
88
|
+
return _getAndroidSn.unregisterGetAndroidSn;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
var _getAndroidSn = require("./abilities/getAndroidSn");
|
|
92
|
+
var _eventManager = require("./abilities/eventManager");
|
|
93
|
+
var _getSaaSReport = require("./abilities/getSaaSReport");
|
|
94
|
+
var _getGeneralReport = require("./abilities/getGeneralReport");
|
|
95
|
+
var _getAndroidReport = require("./abilities/getAndroidReport");
|
|
96
|
+
var _getUltimateReport = require("./abilities/getUltimateReport");
|
|
97
|
+
var _erase = require("./abilities/erase");
|
|
98
|
+
var _activate = require("./abilities/activate");
|
|
99
|
+
var _skip = require("./abilities/skip");
|
|
100
|
+
var _reboot = require("./abilities/reboot");
|
|
101
|
+
var _shutdown = require("./abilities/shutdown");
|
|
102
|
+
var _installApp = require("./abilities/installApp");
|
|
103
|
+
var Sentry = _interopRequireWildcard(require("@sentry/browser"));
|
|
104
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
105
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
106
|
+
// 初始化 Sentry 用于错误捕获
|
|
12
107
|
Sentry.init({
|
|
13
|
-
dsn:
|
|
108
|
+
dsn: 'https://8a5296c59083430fbac0756f56ddbf5d@sentry.zhuanzhuan.com/2300',
|
|
14
109
|
tracesSampleRate: 1.0
|
|
15
110
|
});
|
|
16
111
|
console.log('Sentry initialized');
|
|
17
|
-
// 初始化
|
|
18
112
|
var _default = exports.default = {
|
|
19
|
-
registerEvent:
|
|
20
|
-
unregisterEvent:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
113
|
+
registerEvent: _eventManager.registerEvent,
|
|
114
|
+
unregisterEvent: _eventManager.unregisterEvent,
|
|
115
|
+
registerGetAndroidSn: _getAndroidSn.registerGetAndroidSn,
|
|
116
|
+
unregisterGetAndroidSn: _getAndroidSn.unregisterGetAndroidSn,
|
|
117
|
+
getSaaSReport: _getSaaSReport.getSaaSReport,
|
|
118
|
+
getGeneralReport: _getGeneralReport.getGeneralReport,
|
|
119
|
+
getAndroidReport: _getAndroidReport.getAndroidReport,
|
|
120
|
+
getUltimateReport: _getUltimateReport.getUltimateReport,
|
|
121
|
+
erase: _erase.erase,
|
|
122
|
+
activate: _activate.activate,
|
|
123
|
+
skip: _skip.skip,
|
|
124
|
+
reboot: _reboot.reboot,
|
|
125
|
+
shutdown: _shutdown.shutdown,
|
|
126
|
+
installApp: _installApp.installApp
|
|
25
127
|
};
|
package/lib/index.mjs
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1
|
|
1
|
+
0.6.1
|
|
@@ -4,29 +4,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.command = command;
|
|
7
|
-
|
|
8
|
-
function command(cmd) {
|
|
9
|
-
var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : './';
|
|
7
|
+
const exec = require('child_process').exec;
|
|
8
|
+
function command(cmd, path = './') {
|
|
10
9
|
// 任何你期望执行的cmd命令,ls都可以
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
let cmdStr1 = cmd;
|
|
11
|
+
let cmdPath = path;
|
|
13
12
|
// 子进程名称
|
|
14
|
-
|
|
13
|
+
let workerProcess;
|
|
15
14
|
runExec(cmdStr1);
|
|
16
15
|
function runExec(cmdStr) {
|
|
17
16
|
workerProcess = exec(cmdStr, {
|
|
18
17
|
cwd: cmdPath
|
|
19
18
|
});
|
|
20
19
|
// 打印正常的后台可执行程序输出
|
|
21
|
-
workerProcess.stdout.on('data',
|
|
20
|
+
workerProcess.stdout.on('data', data => {
|
|
22
21
|
console.log('stdout: ' + data);
|
|
23
22
|
});
|
|
24
23
|
// 打印错误的后台可执行程序输出
|
|
25
|
-
workerProcess.stderr.on('data',
|
|
24
|
+
workerProcess.stderr.on('data', data => {
|
|
26
25
|
console.log('stderr: ' + data);
|
|
27
26
|
});
|
|
28
27
|
// 退出之后的输出
|
|
29
|
-
workerProcess.on('close',
|
|
28
|
+
workerProcess.on('close', code => {
|
|
30
29
|
console.log('out code:' + code);
|
|
31
30
|
});
|
|
32
31
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parsePayload = parsePayload;
|
|
7
|
+
exports.sleep = void 0;
|
|
8
|
+
const sleep = () => {
|
|
9
|
+
return new Promise(resolve => {
|
|
10
|
+
setTimeout(() => {
|
|
11
|
+
resolve();
|
|
12
|
+
}, 1000);
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// 解析参数
|
|
17
|
+
exports.sleep = sleep;
|
|
18
|
+
function parsePayload(params) {
|
|
19
|
+
let oParams = typeof params === 'string' ? JSON.parse(params) : params;
|
|
20
|
+
const payloadParams = oParams.params ?? oParams;
|
|
21
|
+
const payloadBiz = oParams.biz ?? oParams;
|
|
22
|
+
return {
|
|
23
|
+
params: typeof payloadParams === 'object' ? JSON.stringify(payloadParams) : payloadParams,
|
|
24
|
+
biz: typeof payloadBiz === 'object' ? JSON.stringify(payloadBiz) : payloadBiz
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -3,17 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
6
|
+
exports.isWin = exports.isProd = exports.isMac = exports.isLinux = exports.isDev = exports.isArm64 = exports.isAmd64 = void 0;
|
|
7
|
+
const isMac = () => {
|
|
8
8
|
return process.platform === 'darwin';
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
exports.isMac = isMac;
|
|
11
|
+
const isWin = () => {
|
|
11
12
|
return process.platform === 'win32';
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
+
exports.isWin = isWin;
|
|
15
|
+
const isLinux = () => {
|
|
14
16
|
return process.platform === 'linux';
|
|
15
17
|
};
|
|
16
|
-
|
|
18
|
+
exports.isLinux = isLinux;
|
|
19
|
+
const isDev = () => {
|
|
17
20
|
// 检查 NODE_ENV 是否为 development
|
|
18
21
|
if (process.env.NODE_ENV === 'development') {
|
|
19
22
|
return true;
|
|
@@ -30,24 +33,22 @@ var isDev = exports.isDev = function isDev() {
|
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
// 检查是否在 Electron 主进程中,且没有打包
|
|
33
|
-
if (process.type === 'browser' && !process.resourcesPath.includes('app.asar')) {
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
+
// if (process.type === 'browser' && !process.resourcesPath.includes('app.asar')) {
|
|
37
|
+
// return true
|
|
38
|
+
// }
|
|
39
|
+
|
|
36
40
|
return false;
|
|
37
41
|
};
|
|
38
|
-
|
|
42
|
+
exports.isDev = isDev;
|
|
43
|
+
const isProd = () => {
|
|
39
44
|
return process.env.NODE_ENV === 'production';
|
|
40
45
|
};
|
|
41
|
-
|
|
46
|
+
exports.isProd = isProd;
|
|
47
|
+
const isArm64 = () => {
|
|
42
48
|
return process.arch === 'arm64';
|
|
43
49
|
};
|
|
44
|
-
|
|
50
|
+
exports.isArm64 = isArm64;
|
|
51
|
+
const isAmd64 = () => {
|
|
45
52
|
return process.arch === 'x64';
|
|
46
53
|
};
|
|
47
|
-
|
|
48
|
-
return new Promise(function (resolve) {
|
|
49
|
-
setTimeout(function () {
|
|
50
|
-
resolve();
|
|
51
|
-
}, 2000);
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
+
exports.isAmd64 = isAmd64;
|
|
@@ -3,18 +3,22 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.abilityCallKit = abilityCallKit;
|
|
7
|
+
exports.setGlobalProperty = exports.hasGlobalProperty = exports.getHunterInspectionKit = exports.getGlobalProperty = exports.getGlobalObject = exports.deleteGlobalProperty = exports.callHunterInspectionKit = void 0;
|
|
7
8
|
var _utils = require("../utils/utils.initDll");
|
|
9
|
+
var Sentry = _interopRequireWildcard(require("@sentry/browser"));
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
8
12
|
/**
|
|
9
13
|
* 全局对象兼容性处理工具
|
|
10
14
|
* 兼容Electron主进程(global)和渲染进程(window)环境
|
|
11
15
|
*/
|
|
12
|
-
|
|
16
|
+
|
|
13
17
|
/**
|
|
14
18
|
* 获取全局对象
|
|
15
19
|
* @returns {Object} 全局对象
|
|
16
20
|
*/
|
|
17
|
-
|
|
21
|
+
const getGlobalObject = () => {
|
|
18
22
|
if (typeof global !== 'undefined') {
|
|
19
23
|
return global;
|
|
20
24
|
}
|
|
@@ -30,8 +34,9 @@ var getGlobalObject = exports.getGlobalObject = function getGlobalObject() {
|
|
|
30
34
|
* @param {string} key 属性名
|
|
31
35
|
* @param {any} value 属性值
|
|
32
36
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
exports.getGlobalObject = getGlobalObject;
|
|
38
|
+
const setGlobalProperty = (key, value) => {
|
|
39
|
+
const globalObj = getGlobalObject();
|
|
35
40
|
globalObj[key] = value;
|
|
36
41
|
};
|
|
37
42
|
|
|
@@ -41,9 +46,9 @@ var setGlobalProperty = exports.setGlobalProperty = function setGlobalProperty(k
|
|
|
41
46
|
* @param {any} defaultValue 默认值
|
|
42
47
|
* @returns {any} 属性值
|
|
43
48
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
exports.setGlobalProperty = setGlobalProperty;
|
|
50
|
+
const getGlobalProperty = (key, defaultValue = undefined) => {
|
|
51
|
+
const globalObj = getGlobalObject();
|
|
47
52
|
return globalObj[key] !== undefined ? globalObj[key] : defaultValue;
|
|
48
53
|
};
|
|
49
54
|
|
|
@@ -52,8 +57,9 @@ var getGlobalProperty = exports.getGlobalProperty = function getGlobalProperty(k
|
|
|
52
57
|
* @param {string} key 属性名
|
|
53
58
|
* @returns {boolean} 是否存在
|
|
54
59
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
exports.getGlobalProperty = getGlobalProperty;
|
|
61
|
+
const hasGlobalProperty = key => {
|
|
62
|
+
const globalObj = getGlobalObject();
|
|
57
63
|
return key in globalObj;
|
|
58
64
|
};
|
|
59
65
|
|
|
@@ -61,8 +67,9 @@ var hasGlobalProperty = exports.hasGlobalProperty = function hasGlobalProperty(k
|
|
|
61
67
|
* 删除全局属性
|
|
62
68
|
* @param {string} key 属性名
|
|
63
69
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
exports.hasGlobalProperty = hasGlobalProperty;
|
|
71
|
+
const deleteGlobalProperty = key => {
|
|
72
|
+
const globalObj = getGlobalObject();
|
|
66
73
|
delete globalObj[key];
|
|
67
74
|
};
|
|
68
75
|
|
|
@@ -70,8 +77,9 @@ var deleteGlobalProperty = exports.deleteGlobalProperty = function deleteGlobalP
|
|
|
70
77
|
* 安全地获取HunterInspectionKit对象
|
|
71
78
|
* @returns {Object|null} HunterInspectionKit对象,如果不存在则返回null
|
|
72
79
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
exports.deleteGlobalProperty = deleteGlobalProperty;
|
|
81
|
+
const getHunterInspectionKit = willInit => {
|
|
82
|
+
const kit = getGlobalProperty('HunterInspectionKit');
|
|
75
83
|
if (!kit) {
|
|
76
84
|
!willInit && console.warn('HunterInspectionKit未初始化,请先调用 initHunterInspectionKit() 函数');
|
|
77
85
|
return null;
|
|
@@ -85,110 +93,83 @@ var getHunterInspectionKit = exports.getHunterInspectionKit = function getHunter
|
|
|
85
93
|
* @param {...any} args 参数
|
|
86
94
|
* @returns {any|null} 方法返回值,如果调用失败则返回null
|
|
87
95
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
96
|
+
exports.getHunterInspectionKit = getHunterInspectionKit;
|
|
97
|
+
const callHunterInspectionKit = (methodName, ...args) => {
|
|
98
|
+
let kit = getHunterInspectionKit(true);
|
|
90
99
|
if (!kit) {
|
|
91
100
|
(0, _utils.initHunterInspectionKit)();
|
|
92
101
|
kit = getHunterInspectionKit(false);
|
|
93
102
|
}
|
|
94
103
|
if (!kit || typeof kit[methodName] !== 'function') {
|
|
95
|
-
console.error(
|
|
96
|
-
Sentry.captureException(
|
|
104
|
+
console.error(`HunterInspectionKit.${methodName}方法不存在或未初始化`);
|
|
105
|
+
Sentry.captureException(`HunterInspectionKit.${methodName}方法不存在或未初始化`);
|
|
97
106
|
return null;
|
|
98
107
|
}
|
|
99
108
|
try {
|
|
100
|
-
|
|
101
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
102
|
-
args[_key - 1] = arguments[_key];
|
|
103
|
-
}
|
|
104
|
-
return (_kit = kit)[methodName].apply(_kit, args);
|
|
109
|
+
return kit[methodName](...args);
|
|
105
110
|
} catch (error) {
|
|
106
|
-
console.error(
|
|
107
|
-
Sentry.captureException(
|
|
111
|
+
console.error(`调用HunterInspectionKit.${methodName}失败:`, error);
|
|
112
|
+
Sentry.captureException(`调用HunterInspectionKit.${methodName}失败:`, error);
|
|
108
113
|
return null;
|
|
109
114
|
}
|
|
110
115
|
};
|
|
111
116
|
|
|
112
117
|
/**
|
|
113
|
-
*
|
|
114
|
-
* @param {
|
|
115
|
-
* @
|
|
118
|
+
* 调用HunterInspectionKit的方法
|
|
119
|
+
* @param {string} cmd 方法名
|
|
120
|
+
* @param {Object} payload 参数对象
|
|
121
|
+
* @returns {Object} 执行结果对象
|
|
116
122
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
Message = reportResObj.Message;
|
|
126
|
-
if (Code == 0 && Data) {
|
|
127
|
-
return {
|
|
128
|
-
type: 'getGeneralReportSuccess',
|
|
129
|
-
data: {
|
|
130
|
-
code: 0,
|
|
131
|
-
data: Data,
|
|
132
|
-
message: '获取报告成功'
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
123
|
+
exports.callHunterInspectionKit = callHunterInspectionKit;
|
|
124
|
+
function abilityCallKit(cmd, payload) {
|
|
125
|
+
console.log(`调用【${cmd}】方法,参数:`, JSON.stringify(payload));
|
|
126
|
+
const {
|
|
127
|
+
biz = "",
|
|
128
|
+
params
|
|
129
|
+
} = payload;
|
|
130
|
+
if (!params) {
|
|
136
131
|
return {
|
|
137
|
-
type: '
|
|
138
|
-
|
|
132
|
+
type: 'fail',
|
|
133
|
+
payload: {
|
|
139
134
|
code: -1,
|
|
140
135
|
data: {},
|
|
141
|
-
message:
|
|
136
|
+
message: `调用【${cmd}】方法缺少必要参数`
|
|
142
137
|
}
|
|
143
138
|
};
|
|
144
139
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
data: {
|
|
148
|
-
code: -1,
|
|
149
|
-
data: {},
|
|
150
|
-
message: '获取报告失败'
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* 获取general报告
|
|
157
|
-
* @param {Object} params 参数
|
|
158
|
-
* @returns {Object} 报告结果
|
|
159
|
-
*/
|
|
160
|
-
var getSaaSReportCallKit = exports.getSaaSReportCallKit = function getSaaSReportCallKit(params) {
|
|
161
|
-
var reportRes = callHunterInspectionKit('InspectionKit', params, 'saas_report', params);
|
|
162
|
-
if (reportRes) {
|
|
163
|
-
var reportResObj = JSON.parse(reportRes);
|
|
164
|
-
var Code = reportResObj.Code,
|
|
165
|
-
Data = reportResObj.Data,
|
|
166
|
-
Message = reportResObj.Message;
|
|
167
|
-
if (Code == 0 && Data) {
|
|
168
|
-
return {
|
|
169
|
-
type: 'getSaaSReportSuccess',
|
|
170
|
-
data: {
|
|
171
|
-
code: 0,
|
|
172
|
-
data: Data,
|
|
173
|
-
message: '获取SaaS报告成功'
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
}
|
|
140
|
+
const res = callHunterInspectionKit('InspectionKit', biz, cmd, params);
|
|
141
|
+
if (!res) {
|
|
177
142
|
return {
|
|
178
|
-
type: '
|
|
179
|
-
|
|
143
|
+
type: 'fail',
|
|
144
|
+
payload: {
|
|
180
145
|
code: -1,
|
|
181
146
|
data: {},
|
|
182
|
-
message:
|
|
147
|
+
message: `【${cmd}】方法执行失败`
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const resObj = JSON.parse(res);
|
|
152
|
+
const {
|
|
153
|
+
Code,
|
|
154
|
+
Data,
|
|
155
|
+
Message
|
|
156
|
+
} = resObj;
|
|
157
|
+
if (Code == 0) {
|
|
158
|
+
return {
|
|
159
|
+
type: 'success',
|
|
160
|
+
payload: {
|
|
161
|
+
code: 0,
|
|
162
|
+
data: Data,
|
|
163
|
+
message: `【${cmd}】方法执行成功`
|
|
183
164
|
}
|
|
184
165
|
};
|
|
185
166
|
}
|
|
186
167
|
return {
|
|
187
|
-
type: '
|
|
188
|
-
|
|
168
|
+
type: 'fail',
|
|
169
|
+
payload: {
|
|
189
170
|
code: -1,
|
|
190
171
|
data: {},
|
|
191
|
-
message:
|
|
172
|
+
message: Message || `【${cmd}】方法执行失败`
|
|
192
173
|
}
|
|
193
174
|
};
|
|
194
|
-
}
|
|
175
|
+
}
|