@hylid/call 0.0.90011603928-dev.7 → 0.0.90011615662-dev.2
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 +45 -229
- package/package.json +3 -3
package/lib/webCall.js
CHANGED
|
@@ -1,122 +1,5 @@
|
|
|
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';
|
|
117
1
|
export var alipayJSBridge = function alipayJSBridge(cb) {
|
|
118
|
-
|
|
119
|
-
if (window.AlipayJSBridge || window.atomicsdk) return cb();
|
|
2
|
+
if (window.AlipayJSBridge) return cb();
|
|
120
3
|
document.addEventListener('AlipayJSBridgeReady', function () {
|
|
121
4
|
return cb();
|
|
122
5
|
}, false);
|
|
@@ -126,53 +9,19 @@ export function webCall(apiName, options, config) {
|
|
|
126
9
|
var _a = (config || {}).type,
|
|
127
10
|
type = _a === void 0 ? 'async' : _a;
|
|
128
11
|
if (type === 'async') {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
// 出境服务存在此通信方法再调用
|
|
138
|
-
// @ts-ignore
|
|
139
|
-
window.atomicsdk.invokeMethod({
|
|
140
|
-
appMethod: apiName,
|
|
141
|
-
jsMethod: "",
|
|
142
|
-
data: options || {} // 参数对象
|
|
143
|
-
}).then(function (res) {
|
|
144
|
-
var _a = options || {},
|
|
145
|
-
success = _a.success,
|
|
146
|
-
fail = _a.fail,
|
|
147
|
-
complete = _a.complete;
|
|
148
|
-
if (res.error || res.errorCode) {
|
|
149
|
-
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
150
|
-
} else {
|
|
151
|
-
success === null || success === void 0 ? void 0 : success(res);
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
// @ts-ignore
|
|
155
|
-
} else if (window[apiName]) {
|
|
156
|
-
// @ts-ignore
|
|
157
|
-
window[apiName](options);
|
|
12
|
+
window.AlipayJSBridge.call(apiName, options, function (res) {
|
|
13
|
+
var _a = options || {},
|
|
14
|
+
success = _a.success,
|
|
15
|
+
fail = _a.fail,
|
|
16
|
+
complete = _a.complete;
|
|
17
|
+
// 兼容 worldfirst 安卓端报错,后续客户端统一字段后删除
|
|
18
|
+
if (res.error || res.errorCode) {
|
|
19
|
+
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
158
20
|
} else {
|
|
159
|
-
|
|
21
|
+
success === null || success === void 0 ? void 0 : success(res);
|
|
160
22
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
var _a = options || {},
|
|
164
|
-
success = _a.success,
|
|
165
|
-
fail = _a.fail,
|
|
166
|
-
complete = _a.complete;
|
|
167
|
-
// 兼容 worldfirst 安卓端报错,后续客户端统一字段后删除
|
|
168
|
-
if (res.error || res.errorCode) {
|
|
169
|
-
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
170
|
-
} else {
|
|
171
|
-
success === null || success === void 0 ? void 0 : success(res);
|
|
172
|
-
}
|
|
173
|
-
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
174
|
-
});
|
|
175
|
-
}
|
|
23
|
+
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
24
|
+
});
|
|
176
25
|
}
|
|
177
26
|
if (type === 'callback') {
|
|
178
27
|
window.AlipayJSBridge.call(apiName, options);
|
|
@@ -180,73 +29,40 @@ export function webCall(apiName, options, config) {
|
|
|
180
29
|
});
|
|
181
30
|
}
|
|
182
31
|
export function webCallAsync(apiName, options, config) {
|
|
183
|
-
var _this = this;
|
|
184
32
|
return new Promise(function (resolve, reject) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (window[apiName]) {
|
|
219
|
-
// @ts-ignore
|
|
220
|
-
window[apiName](options);
|
|
221
|
-
} else {
|
|
222
|
-
throw new Error('webCallAsync Error: apiName not found');
|
|
223
|
-
}
|
|
224
|
-
_c.label = 3;
|
|
225
|
-
case 3:
|
|
226
|
-
return [3 /*break*/, 5];
|
|
227
|
-
case 4:
|
|
228
|
-
window.AlipayJSBridge.call(apiName, options, function (res) {
|
|
229
|
-
var _a = options || {},
|
|
230
|
-
success = _a.success,
|
|
231
|
-
fail = _a.fail,
|
|
232
|
-
complete = _a.complete;
|
|
233
|
-
if (timer) {
|
|
234
|
-
clearTimeout(timer);
|
|
235
|
-
}
|
|
236
|
-
if (res === null || res === void 0 ? void 0 : res.error) {
|
|
237
|
-
reject(res);
|
|
238
|
-
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
239
|
-
} else {
|
|
240
|
-
resolve(res);
|
|
241
|
-
success === null || success === void 0 ? void 0 : success(res);
|
|
242
|
-
}
|
|
243
|
-
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
244
|
-
});
|
|
245
|
-
_c.label = 5;
|
|
246
|
-
case 5:
|
|
247
|
-
return [2 /*return*/];
|
|
248
|
-
}
|
|
249
|
-
});
|
|
33
|
+
var _a = options || {},
|
|
34
|
+
success = _a.success,
|
|
35
|
+
fail = _a.fail,
|
|
36
|
+
complete = _a.complete;
|
|
37
|
+
var _b = (config || {}).timeout,
|
|
38
|
+
timeout = _b === void 0 ? 20000 : _b;
|
|
39
|
+
var timer;
|
|
40
|
+
if (timeout > 0) {
|
|
41
|
+
timer = setTimeout(function () {
|
|
42
|
+
var err = {
|
|
43
|
+
error: -101,
|
|
44
|
+
errorMessage: "[".concat(apiName, "]: Timeout")
|
|
45
|
+
};
|
|
46
|
+
reject(err);
|
|
47
|
+
fail === null || fail === void 0 ? void 0 : fail(err);
|
|
48
|
+
}, timeout);
|
|
49
|
+
}
|
|
50
|
+
window.AlipayJSBridge.call(apiName, options, function (res) {
|
|
51
|
+
var _a = options || {},
|
|
52
|
+
success = _a.success,
|
|
53
|
+
fail = _a.fail,
|
|
54
|
+
complete = _a.complete;
|
|
55
|
+
if (timer) {
|
|
56
|
+
clearTimeout(timer);
|
|
57
|
+
}
|
|
58
|
+
if (res === null || res === void 0 ? void 0 : res.error) {
|
|
59
|
+
reject(res);
|
|
60
|
+
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
61
|
+
} else {
|
|
62
|
+
resolve(res);
|
|
63
|
+
success === null || success === void 0 ? void 0 : success(res);
|
|
64
|
+
}
|
|
65
|
+
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
250
66
|
});
|
|
251
67
|
});
|
|
252
68
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hylid/call",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.90011615662-dev.2",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib"
|
|
7
7
|
],
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@hylid/env": "^0.0.
|
|
10
|
-
"@hylid/types": "^0.0.
|
|
9
|
+
"@hylid/env": "^0.0.90011615662-dev.2",
|
|
10
|
+
"@hylid/types": "^0.0.90011615662-dev.2"
|
|
11
11
|
},
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|