@alipay/ams-checkout 1.3.1-dev → 1.3.1

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.
Files changed (57) hide show
  1. package/dist/umd/ams-checkout.min.js +1 -1
  2. package/package.json +1 -54
  3. package/dist/esm/config/index.d.ts +0 -22
  4. package/dist/esm/config/index.js +0 -69
  5. package/dist/esm/constant/index.d.ts +0 -135
  6. package/dist/esm/constant/index.js +0 -135
  7. package/dist/esm/core/component/index.d.ts +0 -17
  8. package/dist/esm/core/component/index.js +0 -127
  9. package/dist/esm/core/drop-in/index.d.ts +0 -29
  10. package/dist/esm/core/drop-in/index.js +0 -104
  11. package/dist/esm/core/instance/index.d.ts +0 -67
  12. package/dist/esm/core/instance/index.js +0 -276
  13. package/dist/esm/image/cta.svg +0 -9
  14. package/dist/esm/index.d.ts +0 -22
  15. package/dist/esm/plugin/component/cashierApp.d.ts +0 -24
  16. package/dist/esm/plugin/component/cashierApp.js +0 -140
  17. package/dist/esm/plugin/component/component.style.d.ts +0 -8
  18. package/dist/esm/plugin/component/component.style.js +0 -15
  19. package/dist/esm/plugin/component/index.d.ts +0 -101
  20. package/dist/esm/plugin/component/index.js +0 -875
  21. package/dist/esm/plugin/drop-in/index.d.ts +0 -73
  22. package/dist/esm/plugin/drop-in/index.js +0 -323
  23. package/dist/esm/request/index.d.ts +0 -15
  24. package/dist/esm/request/index.js +0 -145
  25. package/dist/esm/request/utils.d.ts +0 -28
  26. package/dist/esm/request/utils.js +0 -59
  27. package/dist/esm/service/index.d.ts +0 -2
  28. package/dist/esm/service/index.js +0 -40
  29. package/dist/esm/types/index.d.ts +0 -194
  30. package/dist/esm/types/index.js +0 -94
  31. package/dist/esm/util/createIframeNode.d.ts +0 -5
  32. package/dist/esm/util/createIframeNode.js +0 -35
  33. package/dist/esm/util/get.d.ts +0 -25
  34. package/dist/esm/util/get.js +0 -145
  35. package/dist/esm/util/index.d.ts +0 -53
  36. package/dist/esm/util/index.js +0 -235
  37. package/dist/esm/util/intl-callapp/es/browser.d.ts +0 -21
  38. package/dist/esm/util/intl-callapp/es/browser.js +0 -42
  39. package/dist/esm/util/intl-callapp/es/evoke.d.ts +0 -13
  40. package/dist/esm/util/intl-callapp/es/evoke.js +0 -39
  41. package/dist/esm/util/intl-callapp/es/generate.d.ts +0 -29
  42. package/dist/esm/util/intl-callapp/es/generate.js +0 -44
  43. package/dist/esm/util/intl-callapp/es/index.d.ts +0 -43
  44. package/dist/esm/util/intl-callapp/es/index.js +0 -298
  45. package/dist/esm/util/intl-callapp/es/main.d.ts +0 -41
  46. package/dist/esm/util/intl-callapp/es/main.js +0 -305
  47. package/dist/esm/util/intl-callapp/es/openWallet.d.ts +0 -15
  48. package/dist/esm/util/intl-callapp/es/openWallet.js +0 -197
  49. package/dist/esm/util/intl-callapp/es/types.d.ts +0 -46
  50. package/dist/esm/util/intl-callapp/es/types.js +0 -1
  51. package/dist/esm/util/intl-callapp/es/utils/config.d.ts +0 -24
  52. package/dist/esm/util/intl-callapp/es/utils/config.js +0 -57
  53. package/dist/esm/util/intl-callapp/es/utils/index.d.ts +0 -15
  54. package/dist/esm/util/intl-callapp/es/utils/index.js +0 -98
  55. package/dist/esm/util/mock.d.ts +0 -1
  56. package/dist/esm/util/mock.js +0 -4
  57. /package/{dist/esm → esm}/index.js +0 -0
@@ -1,73 +0,0 @@
1
- import type AMSCheckout from '../../core/instance';
2
- import type { createPaymentParams, eventPlayload } from '../../types';
3
- export default class CheckoutApp {
4
- app: any;
5
- paymentMethodsResult: any;
6
- appDomain: string;
7
- AMSSDK: AMSCheckout;
8
- private _render;
9
- private _selector;
10
- private _version;
11
- constructor();
12
- /**
13
- * @description When SDK registers plug-ins, it is a required function to receive SDK instances
14
- */
15
- applyPlugin(AMSSDK: AMSCheckout): void;
16
- /**
17
- * @description Set the rendering capability of the cashier plug-in. Different technology stacks have some differences in the packaging and use of rendering functions
18
- */
19
- setRender(createIframeNode: (context: CheckoutApp, renderParams: {
20
- selector: string | HTMLElement;
21
- }) => Promise<void>): void;
22
- /**
23
- * @description High order function of rendering capability
24
- */
25
- render(renderParams: createPaymentParams): Promise<void>;
26
- /**
27
- * @description Cancel listening and destroy the dom
28
- */
29
- logoutPlugin(): void;
30
- /**
31
- * @description Create app
32
- */
33
- private _createApp;
34
- private _getIframeUrl;
35
- /**
36
- * @description Create iframe
37
- */
38
- private _createIframe;
39
- /**
40
- * @description Get iftame id
41
- */
42
- private _getIframeId;
43
- _listener(e: any): void;
44
- /**
45
- * @description Initialize subscription iframe message
46
- */
47
- _addEventListener(): void;
48
- _removeEventListener(): void;
49
- /**
50
- * @description Processing messages from iframe
51
- */
52
- _handleAppMessage(data: eventPlayload): void;
53
- /**
54
- * @description Send message to SDK
55
- */
56
- _dispatchToSDK(data: eventPlayload): void;
57
- /**
58
- * @description Send message to iframe
59
- */
60
- _dispatchToApp(data: eventPlayload): void;
61
- /**
62
- * @description Subscribe to messages from SDK
63
- */
64
- _subscribeFromSDK(): void;
65
- /**
66
- * @description Send rendering events to iframe
67
- */
68
- _renderPaymentMethods(paymentResult: any): void;
69
- /**
70
- * @description Send the post submission processing event, and the cashier applies the consumption result
71
- */
72
- _handleRequestPayment(data: eventPlayload): void;
73
- }
@@ -1,323 +0,0 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
- /**
9
- * Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
10
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
- * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
12
- * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
13
- */
14
- import { BASEPLUGINID, ERRORMESSAGE, EVENT } from "../../constant";
15
- import { messageName } from "../../types";
16
- import { getOrigin, getType, getViewPort, isDom, isJsonString, serialize } from "../../util";
17
- var getServerPath = function getServerPath() {
18
- var _environment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'prod';
19
- var version = arguments.length > 1 ? arguments[1] : undefined;
20
- var host = '';
21
- switch (_environment) {
22
- case 'dev':
23
- host = "http://page.alipay.net/page/antom-web-checkout/src/drop-in-app/index.".concat(version, ".html");
24
- break;
25
- case 'sandbox':
26
- host = "https://pre.ac.alipay.com/page/antom-web-checkout/src/drop-in-app/index.".concat(version, ".html");
27
- break;
28
- case 'prod':
29
- host = "https://ac.alipay.com/page/antom-web-checkout/src/drop-in-app/index.".concat(version, ".html");
30
- break;
31
- default:
32
- host = "https://ac.alipay.com/page/antom-web-checkout/src/drop-in-app/index.".concat(version, ".html");
33
- break;
34
- }
35
- return host;
36
- };
37
- var getServerHost = function getServerHost(_environment, version) {
38
- var reg = /^https?:\/\/([^/<>\s]+\.?)*/;
39
- var macth = reg.exec(getServerPath(_environment, version));
40
- return macth && macth[0] || '';
41
- };
42
- var CheckoutApp = /*#__PURE__*/function () {
43
- function CheckoutApp() {
44
- _classCallCheck(this, CheckoutApp);
45
- _defineProperty(this, "app", void 0);
46
- _defineProperty(this, "paymentMethodsResult", void 0);
47
- _defineProperty(this, "appDomain", void 0);
48
- _defineProperty(this, "AMSSDK", void 0);
49
- _defineProperty(this, "_render", void 0);
50
- _defineProperty(this, "_selector", void 0);
51
- _defineProperty(this, "_version", void 0);
52
- this._version = '1.0.0';
53
- this._render = function () {
54
- return Promise.resolve();
55
- };
56
- }
57
- /**
58
- * @description When SDK registers plug-ins, it is a required function to receive SDK instances
59
- */
60
- _createClass(CheckoutApp, [{
61
- key: "applyPlugin",
62
- value: function applyPlugin(AMSSDK) {
63
- this.AMSSDK = AMSSDK;
64
- this._subscribeFromSDK();
65
- // Subscribe to messages from iframe
66
- this._addEventListener();
67
- this.appDomain = getServerHost(this.AMSSDK.options.env.environment, this._version);
68
- this.app = this._createApp();
69
- }
70
- /**
71
- * @description Set the rendering capability of the cashier plug-in. Different technology stacks have some differences in the packaging and use of rendering functions
72
- */
73
- }, {
74
- key: "setRender",
75
- value: function setRender(createIframeNode) {
76
- this._render = createIframeNode;
77
- }
78
- /**
79
- * @description High order function of rendering capability
80
- */
81
- }, {
82
- key: "render",
83
- value: function render(renderParams) {
84
- this.paymentMethodsResult = renderParams.paymentMethodsResult;
85
- this._selector = renderParams.selector;
86
- this.app.src = this._getIframeUrl((renderParams === null || renderParams === void 0 ? void 0 : renderParams.appearance) || {});
87
- return this._render(this, {
88
- selector: renderParams.selector
89
- });
90
- }
91
- /**
92
- * @description Cancel listening and destroy the dom
93
- */
94
- }, {
95
- key: "logoutPlugin",
96
- value: function logoutPlugin() {
97
- try {
98
- this.app = null;
99
- this._removeEventListener();
100
- var dorpinDom = null;
101
- if (getType(this._selector) === 'string') {
102
- dorpinDom = document.querySelector(this._selector);
103
- }
104
- if (isDom(this._selector)) {
105
- dorpinDom = this._selector;
106
- }
107
- if (dorpinDom) dorpinDom.innerHTML = '';
108
- // eslint-disable-next-line no-empty
109
- } catch (error) {}
110
- }
111
- /**
112
- * @description Create app
113
- */
114
- }, {
115
- key: "_createApp",
116
- value: function _createApp() {
117
- var iframe;
118
- try {
119
- iframe = this._createIframe();
120
- } catch (error) {
121
- this._dispatchToSDK({
122
- name: messageName.APP_TO_SDK,
123
- instanceId: this.AMSSDK._instanceId,
124
- context: {
125
- event: 'onError',
126
- data: Object.assign({}, ERRORMESSAGE.SDK_COMPATIBILITY_ISSUES.FAILED_TO_CREATE_IFRAME, {
127
- stack: error
128
- })
129
- }
130
- });
131
- return;
132
- }
133
- if (!!window.postMessage !== true) {
134
- this._dispatchToSDK({
135
- name: messageName.APP_TO_SDK,
136
- instanceId: this.AMSSDK._instanceId,
137
- context: {
138
- event: 'onError',
139
- data: ERRORMESSAGE.SDK_COMPATIBILITY_ISSUES.BROWSER_NOT_SUPPORT_POSTMESSAGE
140
- }
141
- });
142
- return;
143
- }
144
- return iframe;
145
- }
146
- }, {
147
- key: "_getIframeUrl",
148
- value: function _getIframeUrl(appearance) {
149
- var path = getServerPath(this.AMSSDK.options.env.environment, this._version);
150
- var scale = getViewPort('initial-scale') || 1;
151
- var instanceId = this.AMSSDK._instanceId;
152
- var urlParams = Object.assign({
153
- locale: this.AMSSDK.options.locale,
154
- scale: scale,
155
- merchantDomain: window.btoa(getOrigin()),
156
- instanceId: instanceId
157
- }, appearance);
158
- var locationSearch = serialize(urlParams);
159
- return "".concat(path, "?").concat(locationSearch);
160
- }
161
- /**
162
- * @description Create iframe
163
- */
164
- }, {
165
- key: "_createIframe",
166
- value: function _createIframe() {
167
- var iframe = document.createElement('iframe');
168
- var iframeId = this._getIframeId(this.AMSSDK.options.mode);
169
- iframe.id = iframeId;
170
- iframe.style.height = '100%';
171
- iframe.style.width = '100%';
172
- iframe.style.border = '0';
173
- iframe.style.overflow = 'hidden';
174
- return iframe;
175
- }
176
- /**
177
- * @description Get iftame id
178
- */
179
- }, {
180
- key: "_getIframeId",
181
- value: function _getIframeId(UIMode) {
182
- var id = 'checkout-dropin';
183
- switch (UIMode) {
184
- case 'DROPIN':
185
- id = 'checkout-dropin';
186
- break;
187
- case 'COMPONENT':
188
- id = 'checkout-component';
189
- break;
190
- }
191
- return id;
192
- }
193
- }, {
194
- key: "_listener",
195
- value: function _listener(e) {
196
- if (e.origin !== this.appDomain) {
197
- return;
198
- }
199
- var isJson = isJsonString(e.data);
200
- if (isJson) {
201
- var data = JSON.parse(e.data);
202
- if (data.name !== messageName.APP_TO_SDK && data.name !== messageName.APP_TO_APP || data.instanceId !== this.AMSSDK._instanceId) {
203
- return;
204
- }
205
- this._handleAppMessage(data);
206
- } else {
207
- console.warn(ERRORMESSAGE.NOT_JSON_FORMAT);
208
- this._dispatchToSDK({
209
- name: messageName.APP_TO_SDK,
210
- instanceId: this.AMSSDK._instanceId,
211
- context: {
212
- event: 'onError',
213
- data: ERRORMESSAGE.NOT_JSON_FORMAT
214
- }
215
- });
216
- }
217
- }
218
- /**
219
- * @description Initialize subscription iframe message
220
- */
221
- }, {
222
- key: "_addEventListener",
223
- value: function _addEventListener() {
224
- this._removeEventListener();
225
- window.addEventListener('message', this._listener.bind(this));
226
- }
227
- }, {
228
- key: "_removeEventListener",
229
- value: function _removeEventListener() {
230
- window.removeEventListener('message', this._listener.bind(this));
231
- }
232
- /**
233
- * @description Processing messages from iframe
234
- */
235
- }, {
236
- key: "_handleAppMessage",
237
- value: function _handleAppMessage(data) {
238
- var eventKeyMap = [EVENT.error.name, EVENT.ready.name, EVENT.launch.name, EVENT.redirect.name, EVENT.sizeChanged.name, 'onPaymentMethodsSelected', EVENT.log.name];
239
- if (!eventKeyMap.includes(data.context.event)) {
240
- return;
241
- }
242
- if (data.context.event === 'onLaunch') {
243
- this._renderPaymentMethods(this.paymentMethodsResult);
244
- }
245
- if (data.context.event === 'onSizeChanged') {
246
- this.app.style.height = "".concat(data.context.data.height, "px");
247
- this.app.style.width = '100%';
248
- this.app.style.border = '0';
249
- this.app.style.overflow = 'hidden';
250
- }
251
- if (data.context.event === 'onPaymentMethodsSelected') data.context.event = 'onPaymentMethodSelected';
252
- // The plug-in communicates with the sdk after processing
253
- this._dispatchToSDK(data);
254
- }
255
- /**
256
- * @description Send message to SDK
257
- */
258
- }, {
259
- key: "_dispatchToSDK",
260
- value: function _dispatchToSDK(data) {
261
- var _data = Object.assign({
262
- name: messageName.APP_TO_SDK,
263
- mode: this.AMSSDK.options.mode,
264
- appId: BASEPLUGINID,
265
- instanceId: this.AMSSDK._instanceId
266
- }, data);
267
- this.AMSSDK.eventCenter.emit("".concat(BASEPLUGINID, "-").concat(data.context.event), _data);
268
- }
269
- /**
270
- * @description Send message to iframe
271
- */
272
- }, {
273
- key: "_dispatchToApp",
274
- value: function _dispatchToApp(data) {
275
- if (this.app && this.app.contentWindow) {
276
- this.app.contentWindow.postMessage(JSON.stringify(data), this.appDomain);
277
- }
278
- }
279
- /**
280
- * @description Subscribe to messages from SDK
281
- */
282
- }, {
283
- key: "_subscribeFromSDK",
284
- value: function _subscribeFromSDK() {
285
- var eventKeyMap = {
286
- handleRequestPayment: this._handleRequestPayment
287
- };
288
- for (var key in eventKeyMap) {
289
- // eslint-disable-next-line no-prototype-builtins
290
- if (eventKeyMap.hasOwnProperty(key)) {
291
- this.AMSSDK.eventCenter.on("".concat(BASEPLUGINID, "-").concat(key), eventKeyMap[key].bind(this));
292
- }
293
- }
294
- }
295
- /**
296
- * @description Send rendering events to iframe
297
- */
298
- }, {
299
- key: "_renderPaymentMethods",
300
- value: function _renderPaymentMethods(paymentResult) {
301
- this._dispatchToApp({
302
- name: messageName.SDK_TO_APP,
303
- mode: this.AMSSDK.options.mode,
304
- appId: BASEPLUGINID,
305
- instanceId: this.AMSSDK._instanceId,
306
- context: {
307
- event: 'renderPaymentMethods',
308
- data: paymentResult
309
- }
310
- });
311
- }
312
- /**
313
- * @description Send the post submission processing event, and the cashier applies the consumption result
314
- */
315
- }, {
316
- key: "_handleRequestPayment",
317
- value: function _handleRequestPayment(data) {
318
- this._dispatchToApp(data);
319
- }
320
- }]);
321
- return CheckoutApp;
322
- }();
323
- export { CheckoutApp as default };
@@ -1,15 +0,0 @@
1
- /**
2
- * Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
- * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
6
- * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
7
- */
8
- import { RequestConfig } from '../types';
9
- /**
10
- *
11
- * @param requestData 请求参数
12
- * @param options 请求配置
13
- * @example request({ name: 'test' }, { operation-type: 'xxx.xxx.xxx' })
14
- */
15
- export declare function request(requestData: Record<string, any> | undefined, options: RequestConfig): Promise<any>;
@@ -1,145 +0,0 @@
1
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
2
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
3
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
9
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
10
- /**
11
- * Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
12
- *
13
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
14
- * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
15
- * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
16
- */
17
-
18
- import { appId, hostSignMap, lightSandboxMap, requestHost, sofaId, tntInstId } from "../config";
19
- import { ERROR } from "../types";
20
- import { get } from "../util/get";
21
- import axios from 'axios';
22
- import json from "../../package.json";
23
- import { device, fomatGetwayError, isPC, queryParse, safeJson } from "../util";
24
- var _queryParse = queryParse(),
25
- _sandbox = _queryParse._sandbox;
26
- function requestInstance(options) {
27
- var _objectSpread2, _options$timeout, _options$withCredenti;
28
- var date = new Date(); // 获取当前时间
29
- var timestamp = date.getTime(); // 获取时间戳
30
- var utcTimestamp = timestamp + date.getTimezoneOffset() * 60 * 1000; // 获取 UTC 时间戳
31
- var env = options.env || 'prod';
32
- var lightSandboxConfig = lightSandboxMap(options['Operation-Type'], env); // light_sandbox
33
-
34
- var baseURL = options.baseURL || lightSandboxConfig.baseURL || hostSignMap(options === null || options === void 0 ? void 0 : options.hostSign, env) || requestHost[env];
35
- var _headers = _objectSpread((_objectSpread2 = {
36
- appId: lightSandboxConfig.appId || appId,
37
- workspaceId: options.env === 'pre' ? 'pre' : 'default'
38
- }, _defineProperty(_objectSpread2, "x-cors-".concat(appId.toLowerCase(), "-default"), '1'), _defineProperty(_objectSpread2, "version", '2.0'), _defineProperty(_objectSpread2, 'sofa-group-name', lightSandboxConfig.sofaId || sofaId), _defineProperty(_objectSpread2, 'Operation-Type', lightSandboxConfig['Operation-Type'] || options['Operation-Type'] || ''), _defineProperty(_objectSpread2, 'Client-Time', utcTimestamp), _defineProperty(_objectSpread2, "tntInstId", tntInstId), _defineProperty(_objectSpread2, 'sdk-version', json.version || ''), _objectSpread2), options.headers);
39
- // sandbox 影子链路
40
- if (_sandbox === 'true' || env === 'sandbox') {
41
- _headers['load-test'] = true;
42
- _headers.sofaPenAttrs = 'instMock=O&loadMode=2';
43
- }
44
- if (env !== 'dev') delete _headers['sofa-group-name'];
45
- var instance = axios.create({
46
- baseURL: baseURL,
47
- timeout: (_options$timeout = options.timeout) !== null && _options$timeout !== void 0 ? _options$timeout : 15000,
48
- headers: _headers,
49
- withCredentials: (_options$withCredenti = options.withCredentials) !== null && _options$withCredenti !== void 0 ? _options$withCredenti : true,
50
- method: 'POST'
51
- });
52
- return instance.request;
53
- }
54
-
55
- /**
56
- *
57
- * @param requestData 请求参数
58
- * @param options 请求配置
59
- * @example request({ name: 'test' }, { operation-type: 'xxx.xxx.xxx' })
60
- */
61
- export function request(_x, _x2) {
62
- return _request.apply(this, arguments);
63
- }
64
- function _request() {
65
- _request = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(requestData, options) {
66
- var myRequest, startTime, envInfo, _navigator, _data, _yield$myRequest, data, headers, resData, traceId, handleGetWayError, _error$message, _error, timeoutCode, errorCode;
67
- return _regeneratorRuntime().wrap(function _callee$(_context) {
68
- while (1) switch (_context.prev = _context.next) {
69
- case 0:
70
- myRequest = requestInstance(options);
71
- startTime = Date.now();
72
- envInfo = {
73
- terminalType: isPC() ? 'WEB' : 'WAP',
74
- browserInfo: {
75
- browserJavaScriptEnabled: true,
76
- browserLanguage: navigator.language,
77
- browserUserAgent: navigator.userAgent,
78
- browserColorDepth: screen.colorDepth
79
- },
80
- locale: window._amsSdkLanguage || 'en_US',
81
- deviceLanguage: navigator.language,
82
- screenWidth: screen.width,
83
- screenHeight: screen.height,
84
- timeZoneOffset: new Date().getTimezoneOffset()
85
- };
86
- try {
87
- envInfo.browserInfo.browserJavaEnabled = ((_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.javaEnabled()) || false;
88
- // eslint-disable-next-line no-empty
89
- } catch (error) {}
90
- if (envInfo.terminalType === 'WAP') envInfo.osType = device.iOS ? 'IOS' : 'ANDROID';
91
- _data = options.needEnvInfo ? [_objectSpread(_objectSpread({}, requestData), {}, {
92
- envInfo: envInfo,
93
- extParams: {
94
- refUrl: window.location.href
95
- }
96
- })] : [requestData];
97
- _context.prev = 6;
98
- _context.next = 9;
99
- return myRequest({
100
- data: _data
101
- });
102
- case 9:
103
- _yield$myRequest = _context.sent;
104
- data = _yield$myRequest.data;
105
- headers = _yield$myRequest.headers;
106
- resData = data || {};
107
- traceId = get(headers, 'Mgw-TraceId') || get(headers, 'mgw-traceid', '');
108
- resData.traceId = traceId || '';
109
- handleGetWayError = fomatGetwayError(headers, traceId);
110
- if (!(handleGetWayError !== null && handleGetWayError !== void 0 && handleGetWayError.errorCode)) {
111
- _context.next = 18;
112
- break;
113
- }
114
- throw new Error(JSON.stringify({
115
- errorMessage: (resData === null || resData === void 0 ? void 0 : resData.errorMessage) || (handleGetWayError === null || handleGetWayError === void 0 ? void 0 : handleGetWayError.errorMessage),
116
- errorCode: handleGetWayError === null || handleGetWayError === void 0 ? void 0 : handleGetWayError.errorCode,
117
- success: false
118
- }));
119
- case 18:
120
- return _context.abrupt("return", resData);
121
- case 21:
122
- _context.prev = 21;
123
- _context.t0 = _context["catch"](6);
124
- // eslint-disable-next-line no-console
125
- console.log('request error', _context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message);
126
- _error = safeJson(_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message, {
127
- success: false,
128
- errorCode: ERROR.SYSTEM,
129
- errorMessage: ''
130
- });
131
- timeoutCode = _context.t0 !== null && _context.t0 !== void 0 && (_error$message = _context.t0.message) !== null && _error$message !== void 0 && _error$message.includes('timeout') ? ERROR.TIMEOUT : '';
132
- errorCode = (_error === null || _error === void 0 ? void 0 : _error.errorCode) || timeoutCode;
133
- return _context.abrupt("return", {
134
- success: false,
135
- errorCode: errorCode,
136
- errorMessage: ''
137
- });
138
- case 28:
139
- case "end":
140
- return _context.stop();
141
- }
142
- }, _callee, null, [[6, 21]]);
143
- }));
144
- return _request.apply(this, arguments);
145
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
- * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
6
- * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
7
- */
8
- import { ERROR } from '../types';
9
- export declare const safeJson: (data: any, obj: any) => any;
10
- export declare const fomatGetwayError: (headers: Record<string, any>, traceId: string) => {
11
- success: boolean;
12
- traceId: string;
13
- errorCode: ERROR;
14
- resultStatus: any;
15
- errorMessage?: undefined;
16
- result?: undefined;
17
- } | {
18
- success: boolean;
19
- traceId: string;
20
- errorCode: ERROR;
21
- errorMessage: string;
22
- result: {
23
- resultStatus: any;
24
- tips: string;
25
- memo: string;
26
- };
27
- resultStatus: any;
28
- } | null;