@hylid/call 6.3.1 → 6.4.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/lib/webCall.js +228 -45
- package/package.json +3 -3
package/lib/webCall.js
CHANGED
|
@@ -1,5 +1,122 @@
|
|
|
1
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) {
|
|
3
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
+
resolve(value);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) {
|
|
9
|
+
try {
|
|
10
|
+
step(generator.next(value));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
reject(e);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function rejected(value) {
|
|
16
|
+
try {
|
|
17
|
+
step(generator["throw"](value));
|
|
18
|
+
} catch (e) {
|
|
19
|
+
reject(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function step(result) {
|
|
23
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
24
|
+
}
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
29
|
+
var _ = {
|
|
30
|
+
label: 0,
|
|
31
|
+
sent: function sent() {
|
|
32
|
+
if (t[0] & 1) throw t[1];
|
|
33
|
+
return t[1];
|
|
34
|
+
},
|
|
35
|
+
trys: [],
|
|
36
|
+
ops: []
|
|
37
|
+
},
|
|
38
|
+
f,
|
|
39
|
+
y,
|
|
40
|
+
t,
|
|
41
|
+
g;
|
|
42
|
+
return g = {
|
|
43
|
+
next: verb(0),
|
|
44
|
+
"throw": verb(1),
|
|
45
|
+
"return": verb(2)
|
|
46
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
47
|
+
return this;
|
|
48
|
+
}), g;
|
|
49
|
+
function verb(n) {
|
|
50
|
+
return function (v) {
|
|
51
|
+
return step([n, v]);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function step(op) {
|
|
55
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
56
|
+
while (_) try {
|
|
57
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
58
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
59
|
+
switch (op[0]) {
|
|
60
|
+
case 0:
|
|
61
|
+
case 1:
|
|
62
|
+
t = op;
|
|
63
|
+
break;
|
|
64
|
+
case 4:
|
|
65
|
+
_.label++;
|
|
66
|
+
return {
|
|
67
|
+
value: op[1],
|
|
68
|
+
done: false
|
|
69
|
+
};
|
|
70
|
+
case 5:
|
|
71
|
+
_.label++;
|
|
72
|
+
y = op[1];
|
|
73
|
+
op = [0];
|
|
74
|
+
continue;
|
|
75
|
+
case 7:
|
|
76
|
+
op = _.ops.pop();
|
|
77
|
+
_.trys.pop();
|
|
78
|
+
continue;
|
|
79
|
+
default:
|
|
80
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
81
|
+
_ = 0;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
85
|
+
_.label = op[1];
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
89
|
+
_.label = t[1];
|
|
90
|
+
t = op;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
if (t && _.label < t[2]) {
|
|
94
|
+
_.label = t[2];
|
|
95
|
+
_.ops.push(op);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (t[2]) _.ops.pop();
|
|
99
|
+
_.trys.pop();
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
op = body.call(thisArg, _);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
op = [6, e];
|
|
105
|
+
y = 0;
|
|
106
|
+
} finally {
|
|
107
|
+
f = t = 0;
|
|
108
|
+
}
|
|
109
|
+
if (op[0] & 5) throw op[1];
|
|
110
|
+
return {
|
|
111
|
+
value: op[0] ? op[1] : void 0,
|
|
112
|
+
done: true
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
import { CLIENT, client } from '@hylid/env';
|
|
1
117
|
export var alipayJSBridge = function alipayJSBridge(cb) {
|
|
2
|
-
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
if (window.AlipayJSBridge || window.atomicsdk) return cb();
|
|
3
120
|
document.addEventListener('AlipayJSBridgeReady', function () {
|
|
4
121
|
return cb();
|
|
5
122
|
}, false);
|
|
@@ -9,19 +126,52 @@ export function webCall(apiName, options, config) {
|
|
|
9
126
|
var _a = (config || {}).type,
|
|
10
127
|
type = _a === void 0 ? 'async' : _a;
|
|
11
128
|
if (type === 'async') {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
|
|
129
|
+
if (client === CLIENT.HUAWEI_ATOMIC) {
|
|
130
|
+
// @ts-ignore
|
|
131
|
+
var isAtomicFn = window.atomicsdk.invokeMethod({
|
|
132
|
+
appMethod: 'canIUse',
|
|
133
|
+
data: apiName
|
|
134
|
+
});
|
|
135
|
+
if (isAtomicFn) {
|
|
136
|
+
// 出境服务存在此通信方法再调用
|
|
137
|
+
// @ts-ignore
|
|
138
|
+
window.atomicsdk.invokeMethod({
|
|
139
|
+
appMethod: apiName,
|
|
140
|
+
jsMethod: "",
|
|
141
|
+
data: options || {} // 参数对象
|
|
142
|
+
}).then(function (res) {
|
|
143
|
+
var _a = options || {},
|
|
144
|
+
success = _a.success,
|
|
145
|
+
fail = _a.fail,
|
|
146
|
+
complete = _a.complete;
|
|
147
|
+
if (res.error || res.errorCode) {
|
|
148
|
+
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
149
|
+
} else {
|
|
150
|
+
success === null || success === void 0 ? void 0 : success(res);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
} else if (window[apiName]) {
|
|
155
|
+
// @ts-ignore
|
|
156
|
+
window[apiName](options);
|
|
20
157
|
} else {
|
|
21
|
-
|
|
158
|
+
throw new Error('webCall Error: apiName not found');
|
|
22
159
|
}
|
|
23
|
-
|
|
24
|
-
|
|
160
|
+
} else {
|
|
161
|
+
window.AlipayJSBridge.call(apiName, options, function (res) {
|
|
162
|
+
var _a = options || {},
|
|
163
|
+
success = _a.success,
|
|
164
|
+
fail = _a.fail,
|
|
165
|
+
complete = _a.complete;
|
|
166
|
+
// 兼容 worldfirst 安卓端报错,后续客户端统一字段后删除
|
|
167
|
+
if (res.error || res.errorCode) {
|
|
168
|
+
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
169
|
+
} else {
|
|
170
|
+
success === null || success === void 0 ? void 0 : success(res);
|
|
171
|
+
}
|
|
172
|
+
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
25
175
|
}
|
|
26
176
|
if (type === 'callback') {
|
|
27
177
|
window.AlipayJSBridge.call(apiName, options);
|
|
@@ -29,40 +179,73 @@ export function webCall(apiName, options, config) {
|
|
|
29
179
|
});
|
|
30
180
|
}
|
|
31
181
|
export function webCallAsync(apiName, options, config) {
|
|
182
|
+
var _this = this;
|
|
32
183
|
return new Promise(function (resolve, reject) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
184
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
185
|
+
var _a, success, fail, complete, _b, timeout, timer, isAtomicFn, result;
|
|
186
|
+
return __generator(this, function (_c) {
|
|
187
|
+
switch (_c.label) {
|
|
188
|
+
case 0:
|
|
189
|
+
_a = options || {}, success = _a.success, fail = _a.fail, complete = _a.complete;
|
|
190
|
+
_b = (config || {}).timeout, timeout = _b === void 0 ? 20000 : _b;
|
|
191
|
+
if (timeout > 0) {
|
|
192
|
+
timer = setTimeout(function () {
|
|
193
|
+
var err = {
|
|
194
|
+
error: -101,
|
|
195
|
+
errorMessage: "[".concat(apiName, "]: Timeout")
|
|
196
|
+
};
|
|
197
|
+
reject(err);
|
|
198
|
+
fail === null || fail === void 0 ? void 0 : fail(err);
|
|
199
|
+
}, timeout);
|
|
200
|
+
}
|
|
201
|
+
if (!(client === CLIENT.HUAWEI_ATOMIC)) return [3 /*break*/, 4];
|
|
202
|
+
isAtomicFn = window.atomicsdk.invokeMethod({
|
|
203
|
+
appMethod: 'canIUse',
|
|
204
|
+
data: apiName
|
|
205
|
+
});
|
|
206
|
+
if (!isAtomicFn) return [3 /*break*/, 2];
|
|
207
|
+
return [4 /*yield*/, window.atomicsdk.invokeMethod({
|
|
208
|
+
appMethod: apiName,
|
|
209
|
+
jsMethod: "",
|
|
210
|
+
data: options || {} // 参数对象
|
|
211
|
+
})];
|
|
212
|
+
case 1:
|
|
213
|
+
result = _c.sent();
|
|
214
|
+
resolve(result);
|
|
215
|
+
return [3 /*break*/, 3];
|
|
216
|
+
case 2:
|
|
217
|
+
if (window[apiName]) {
|
|
218
|
+
// @ts-ignore
|
|
219
|
+
window[apiName](options);
|
|
220
|
+
} else {
|
|
221
|
+
throw new Error('webCallAsync Error: apiName not found');
|
|
222
|
+
}
|
|
223
|
+
_c.label = 3;
|
|
224
|
+
case 3:
|
|
225
|
+
return [3 /*break*/, 5];
|
|
226
|
+
case 4:
|
|
227
|
+
window.AlipayJSBridge.call(apiName, options, function (res) {
|
|
228
|
+
var _a = options || {},
|
|
229
|
+
success = _a.success,
|
|
230
|
+
fail = _a.fail,
|
|
231
|
+
complete = _a.complete;
|
|
232
|
+
if (timer) {
|
|
233
|
+
clearTimeout(timer);
|
|
234
|
+
}
|
|
235
|
+
if (res === null || res === void 0 ? void 0 : res.error) {
|
|
236
|
+
reject(res);
|
|
237
|
+
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
238
|
+
} else {
|
|
239
|
+
resolve(res);
|
|
240
|
+
success === null || success === void 0 ? void 0 : success(res);
|
|
241
|
+
}
|
|
242
|
+
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
243
|
+
});
|
|
244
|
+
_c.label = 5;
|
|
245
|
+
case 5:
|
|
246
|
+
return [2 /*return*/];
|
|
247
|
+
}
|
|
248
|
+
});
|
|
66
249
|
});
|
|
67
250
|
});
|
|
68
251
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hylid/call",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib"
|
|
7
7
|
],
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@hylid/env": "^6.
|
|
10
|
-
"@hylid/types": "^6.
|
|
9
|
+
"@hylid/env": "^6.4.0",
|
|
10
|
+
"@hylid/types": "^6.4.0"
|
|
11
11
|
},
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|