@salla.sa/twilight-components 2.11.69 → 2.11.71
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/cjs/{app-globals-bd54e7cb.js → app-globals-7aa5a435.js} +2 -2
- package/dist/cjs/cart-3ecaa815.js +13 -0
- package/dist/cjs/index-1d2b3370.js +2 -2
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/salla-add-product-button.cjs.entry.js +21 -4
- package/dist/cjs/{salla-button_36.cjs.entry.js → salla-button_37.cjs.entry.js} +2605 -34
- package/dist/cjs/twilight.cjs.js +2 -2
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/salla-add-product-button/salla-add-product-button.css +2 -1
- package/dist/collection/components/salla-add-product-button/salla-add-product-button.js +59 -6
- package/dist/collection/components/salla-quick-buy/salla-quick-buy.css +10 -0
- package/dist/collection/components/salla-quick-buy/salla-quick-buy.js +326 -0
- package/dist/collection/global/app-dev.js +4 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +3 -2
- package/dist/components/salla-add-product-button.js +39 -13
- package/dist/components/salla-quick-buy.d.ts +11 -0
- package/dist/components/salla-quick-buy.js +9 -0
- package/dist/components/salla-quick-buy2.js +2612 -0
- package/dist/esm/{app-globals-ab75dc1d.js → app-globals-225364bb.js} +2 -2
- package/dist/esm/cart-8c60b447.js +11 -0
- package/dist/esm/index-f1d446ac.js +2 -2
- package/dist/esm/loader.js +2 -2
- package/dist/esm/salla-add-product-button.entry.js +21 -4
- package/dist/esm/{salla-button_36.entry.js → salla-button_37.entry.js} +2605 -35
- package/dist/esm/twilight.js +2 -2
- package/dist/esm-es5/app-globals-225364bb.js +24 -0
- package/dist/esm-es5/cart-8c60b447.js +4 -0
- package/dist/esm-es5/index-f1d446ac.js +1 -1
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/salla-add-product-button.entry.js +2 -2
- package/dist/esm-es5/salla-button_37.entry.js +53 -0
- package/dist/esm-es5/twilight.js +1 -1
- package/dist/twilight/{p-d17a8244.entry.js → p-28812dd3.entry.js} +6 -6
- package/dist/twilight/p-3c6e1a89.js +24 -0
- package/dist/twilight/{p-d16bcce2.system.entry.js → p-45b5a0f3.system.entry.js} +9 -9
- package/dist/twilight/p-4bf1c1a4.system.js +4 -0
- package/dist/twilight/p-60fb9bb5.system.js +4 -0
- package/dist/twilight/p-8a13cf01.js +4 -0
- package/dist/twilight/p-8c7b124e.system.entry.js +4 -0
- package/dist/twilight/p-91f5d041.entry.js +4 -0
- package/dist/twilight/p-f35ef1d6.system.js +24 -0
- package/dist/twilight/twilight.esm.js +1 -1
- package/dist/twilight/twilight.js +1 -1
- package/dist/types/components/salla-add-product-button/salla-add-product-button.d.ts +11 -1
- package/dist/types/components/salla-quick-buy/salla-quick-buy.d.ts +50 -0
- package/dist/types/components.d.ts +97 -0
- package/package.json +6 -5
- package/dist/esm-es5/app-globals-ab75dc1d.js +0 -24
- package/dist/esm-es5/salla-button_36.entry.js +0 -53
- package/dist/twilight/p-70aabbb8.entry.js +0 -4
- package/dist/twilight/p-c0731d21.system.js +0 -4
- package/dist/twilight/p-e211326b.system.js +0 -24
- package/dist/twilight/p-f080991b.system.entry.js +0 -4
- package/dist/twilight/p-f43fba74.js +0 -24
|
@@ -0,0 +1,2612 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Crafted with ❤ by Salla
|
|
3
|
+
*/
|
|
4
|
+
import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
|
|
5
|
+
import { d as defineCustomElement$1 } from './salla-button2.js';
|
|
6
|
+
|
|
7
|
+
const FullWallet = `<!-- Generated by IcoMoon.io -->
|
|
8
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
|
|
9
|
+
<title>full-wallet</title>
|
|
10
|
+
<path d="M29 12h-26c-0.668-0.008-1.284-0.226-1.787-0.59l0.009 0.006c-0.744-0.552-1.222-1.428-1.222-2.416 0-1.657 1.343-3 2.999-3h6c0.552 0 1 0.448 1 1s-0.448 1-1 1v0h-6c-0.552 0-1 0.448-1 1 0 0.326 0.156 0.616 0.397 0.798l0.002 0.002c0.167 0.12 0.374 0.194 0.599 0.2l0.001 0h26c0.552 0 1 0.448 1 1s-0.448 1-1 1v0zM27 12c-0.552 0-1-0.448-1-1v0-3h-3c-0.552 0-1-0.448-1-1s0.448-1 1-1v0h4c0.552 0 1 0.448 1 1v0 4c0 0.552-0.448 1-1 1v0zM29 30h-26c-1.657 0-3-1.343-3-3v0-18c0-0.552 0.448-1 1-1s1 0.448 1 1v0 18c0 0.552 0.448 1 1 1v0h25v-5c0-0.552 0.448-1 1-1s1 0.448 1 1v0 6c0 0.552-0.448 1-1 1v0zM29 18c-0.552 0-1-0.448-1-1v0-6c0-0.552 0.448-1 1-1s1 0.448 1 1v0 6c0 0.552-0.448 1-1 1v0zM31 24h-7c-2.209 0-4-1.791-4-4s1.791-4 4-4v0h7c0.552 0 1 0.448 1 1v0 6c0 0.552-0.448 1-1 1v0zM24 18c-1.105 0-2 0.895-2 2s0.895 2 2 2v0h6v-4zM25 12c-0.001 0-0.001 0-0.002 0-0.389 0-0.726-0.222-0.891-0.546l-0.003-0.006-3.552-7.106-2.306 1.152c-0.13 0.066-0.284 0.105-0.447 0.105-0.552 0-1-0.448-1-1 0-0.39 0.223-0.727 0.548-0.892l0.006-0.003 3.2-1.6c0.13-0.067 0.284-0.106 0.447-0.106 0.39 0 0.727 0.223 0.892 0.548l0.003 0.006 4 8c0.067 0.13 0.106 0.285 0.106 0.448 0 0.552-0.448 1-1 1v0zM21 12c-0.001 0-0.001 0-0.002 0-0.389 0-0.726-0.222-0.891-0.546l-0.003-0.006-3.552-7.106-15.104 7.552c-0.13 0.066-0.284 0.105-0.447 0.105-0.552 0-1-0.448-1-1 0-0.39 0.223-0.727 0.548-0.892l0.006-0.003 16-8c0.13-0.067 0.284-0.106 0.447-0.106 0.39 0 0.727 0.223 0.892 0.548l0.003 0.006 4 8c0.067 0.13 0.106 0.285 0.106 0.448 0 0.552-0.448 1-1 1-0.001 0-0.001 0-0.002 0h0z"></path>
|
|
11
|
+
</svg>
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
var bind = function bind(fn, thisArg) {
|
|
15
|
+
return function wrap() {
|
|
16
|
+
var args = new Array(arguments.length);
|
|
17
|
+
for (var i = 0; i < args.length; i++) {
|
|
18
|
+
args[i] = arguments[i];
|
|
19
|
+
}
|
|
20
|
+
return fn.apply(thisArg, args);
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// utils is a library of generic helper functions non-specific to axios
|
|
25
|
+
|
|
26
|
+
var toString = Object.prototype.toString;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Determine if a value is an Array
|
|
30
|
+
*
|
|
31
|
+
* @param {Object} val The value to test
|
|
32
|
+
* @returns {boolean} True if value is an Array, otherwise false
|
|
33
|
+
*/
|
|
34
|
+
function isArray(val) {
|
|
35
|
+
return toString.call(val) === '[object Array]';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Determine if a value is undefined
|
|
40
|
+
*
|
|
41
|
+
* @param {Object} val The value to test
|
|
42
|
+
* @returns {boolean} True if the value is undefined, otherwise false
|
|
43
|
+
*/
|
|
44
|
+
function isUndefined(val) {
|
|
45
|
+
return typeof val === 'undefined';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Determine if a value is a Buffer
|
|
50
|
+
*
|
|
51
|
+
* @param {Object} val The value to test
|
|
52
|
+
* @returns {boolean} True if value is a Buffer, otherwise false
|
|
53
|
+
*/
|
|
54
|
+
function isBuffer(val) {
|
|
55
|
+
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
|
|
56
|
+
&& typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Determine if a value is an ArrayBuffer
|
|
61
|
+
*
|
|
62
|
+
* @param {Object} val The value to test
|
|
63
|
+
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
|
64
|
+
*/
|
|
65
|
+
function isArrayBuffer(val) {
|
|
66
|
+
return toString.call(val) === '[object ArrayBuffer]';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Determine if a value is a FormData
|
|
71
|
+
*
|
|
72
|
+
* @param {Object} val The value to test
|
|
73
|
+
* @returns {boolean} True if value is an FormData, otherwise false
|
|
74
|
+
*/
|
|
75
|
+
function isFormData(val) {
|
|
76
|
+
return (typeof FormData !== 'undefined') && (val instanceof FormData);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Determine if a value is a view on an ArrayBuffer
|
|
81
|
+
*
|
|
82
|
+
* @param {Object} val The value to test
|
|
83
|
+
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
|
84
|
+
*/
|
|
85
|
+
function isArrayBufferView(val) {
|
|
86
|
+
var result;
|
|
87
|
+
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
|
|
88
|
+
result = ArrayBuffer.isView(val);
|
|
89
|
+
} else {
|
|
90
|
+
result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Determine if a value is a String
|
|
97
|
+
*
|
|
98
|
+
* @param {Object} val The value to test
|
|
99
|
+
* @returns {boolean} True if value is a String, otherwise false
|
|
100
|
+
*/
|
|
101
|
+
function isString(val) {
|
|
102
|
+
return typeof val === 'string';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Determine if a value is a Number
|
|
107
|
+
*
|
|
108
|
+
* @param {Object} val The value to test
|
|
109
|
+
* @returns {boolean} True if value is a Number, otherwise false
|
|
110
|
+
*/
|
|
111
|
+
function isNumber(val) {
|
|
112
|
+
return typeof val === 'number';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Determine if a value is an Object
|
|
117
|
+
*
|
|
118
|
+
* @param {Object} val The value to test
|
|
119
|
+
* @returns {boolean} True if value is an Object, otherwise false
|
|
120
|
+
*/
|
|
121
|
+
function isObject(val) {
|
|
122
|
+
return val !== null && typeof val === 'object';
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Determine if a value is a plain Object
|
|
127
|
+
*
|
|
128
|
+
* @param {Object} val The value to test
|
|
129
|
+
* @return {boolean} True if value is a plain Object, otherwise false
|
|
130
|
+
*/
|
|
131
|
+
function isPlainObject(val) {
|
|
132
|
+
if (toString.call(val) !== '[object Object]') {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
var prototype = Object.getPrototypeOf(val);
|
|
137
|
+
return prototype === null || prototype === Object.prototype;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Determine if a value is a Date
|
|
142
|
+
*
|
|
143
|
+
* @param {Object} val The value to test
|
|
144
|
+
* @returns {boolean} True if value is a Date, otherwise false
|
|
145
|
+
*/
|
|
146
|
+
function isDate(val) {
|
|
147
|
+
return toString.call(val) === '[object Date]';
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Determine if a value is a File
|
|
152
|
+
*
|
|
153
|
+
* @param {Object} val The value to test
|
|
154
|
+
* @returns {boolean} True if value is a File, otherwise false
|
|
155
|
+
*/
|
|
156
|
+
function isFile(val) {
|
|
157
|
+
return toString.call(val) === '[object File]';
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Determine if a value is a Blob
|
|
162
|
+
*
|
|
163
|
+
* @param {Object} val The value to test
|
|
164
|
+
* @returns {boolean} True if value is a Blob, otherwise false
|
|
165
|
+
*/
|
|
166
|
+
function isBlob(val) {
|
|
167
|
+
return toString.call(val) === '[object Blob]';
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Determine if a value is a Function
|
|
172
|
+
*
|
|
173
|
+
* @param {Object} val The value to test
|
|
174
|
+
* @returns {boolean} True if value is a Function, otherwise false
|
|
175
|
+
*/
|
|
176
|
+
function isFunction(val) {
|
|
177
|
+
return toString.call(val) === '[object Function]';
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Determine if a value is a Stream
|
|
182
|
+
*
|
|
183
|
+
* @param {Object} val The value to test
|
|
184
|
+
* @returns {boolean} True if value is a Stream, otherwise false
|
|
185
|
+
*/
|
|
186
|
+
function isStream(val) {
|
|
187
|
+
return isObject(val) && isFunction(val.pipe);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Determine if a value is a URLSearchParams object
|
|
192
|
+
*
|
|
193
|
+
* @param {Object} val The value to test
|
|
194
|
+
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
|
195
|
+
*/
|
|
196
|
+
function isURLSearchParams(val) {
|
|
197
|
+
return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Trim excess whitespace off the beginning and end of a string
|
|
202
|
+
*
|
|
203
|
+
* @param {String} str The String to trim
|
|
204
|
+
* @returns {String} The String freed of excess whitespace
|
|
205
|
+
*/
|
|
206
|
+
function trim(str) {
|
|
207
|
+
return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '');
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Determine if we're running in a standard browser environment
|
|
212
|
+
*
|
|
213
|
+
* This allows axios to run in a web worker, and react-native.
|
|
214
|
+
* Both environments support XMLHttpRequest, but not fully standard globals.
|
|
215
|
+
*
|
|
216
|
+
* web workers:
|
|
217
|
+
* typeof window -> undefined
|
|
218
|
+
* typeof document -> undefined
|
|
219
|
+
*
|
|
220
|
+
* react-native:
|
|
221
|
+
* navigator.product -> 'ReactNative'
|
|
222
|
+
* nativescript
|
|
223
|
+
* navigator.product -> 'NativeScript' or 'NS'
|
|
224
|
+
*/
|
|
225
|
+
function isStandardBrowserEnv() {
|
|
226
|
+
if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' ||
|
|
227
|
+
navigator.product === 'NativeScript' ||
|
|
228
|
+
navigator.product === 'NS')) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
return (
|
|
232
|
+
typeof window !== 'undefined' &&
|
|
233
|
+
typeof document !== 'undefined'
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Iterate over an Array or an Object invoking a function for each item.
|
|
239
|
+
*
|
|
240
|
+
* If `obj` is an Array callback will be called passing
|
|
241
|
+
* the value, index, and complete array for each item.
|
|
242
|
+
*
|
|
243
|
+
* If 'obj' is an Object callback will be called passing
|
|
244
|
+
* the value, key, and complete object for each property.
|
|
245
|
+
*
|
|
246
|
+
* @param {Object|Array} obj The object to iterate
|
|
247
|
+
* @param {Function} fn The callback to invoke for each item
|
|
248
|
+
*/
|
|
249
|
+
function forEach(obj, fn) {
|
|
250
|
+
// Don't bother if no value provided
|
|
251
|
+
if (obj === null || typeof obj === 'undefined') {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Force an array if not already something iterable
|
|
256
|
+
if (typeof obj !== 'object') {
|
|
257
|
+
/*eslint no-param-reassign:0*/
|
|
258
|
+
obj = [obj];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (isArray(obj)) {
|
|
262
|
+
// Iterate over array values
|
|
263
|
+
for (var i = 0, l = obj.length; i < l; i++) {
|
|
264
|
+
fn.call(null, obj[i], i, obj);
|
|
265
|
+
}
|
|
266
|
+
} else {
|
|
267
|
+
// Iterate over object keys
|
|
268
|
+
for (var key in obj) {
|
|
269
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
270
|
+
fn.call(null, obj[key], key, obj);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Accepts varargs expecting each argument to be an object, then
|
|
278
|
+
* immutably merges the properties of each object and returns result.
|
|
279
|
+
*
|
|
280
|
+
* When multiple objects contain the same key the later object in
|
|
281
|
+
* the arguments list will take precedence.
|
|
282
|
+
*
|
|
283
|
+
* Example:
|
|
284
|
+
*
|
|
285
|
+
* ```js
|
|
286
|
+
* var result = merge({foo: 123}, {foo: 456});
|
|
287
|
+
* console.log(result.foo); // outputs 456
|
|
288
|
+
* ```
|
|
289
|
+
*
|
|
290
|
+
* @param {Object} obj1 Object to merge
|
|
291
|
+
* @returns {Object} Result of all merge properties
|
|
292
|
+
*/
|
|
293
|
+
function merge(/* obj1, obj2, obj3, ... */) {
|
|
294
|
+
var result = {};
|
|
295
|
+
function assignValue(val, key) {
|
|
296
|
+
if (isPlainObject(result[key]) && isPlainObject(val)) {
|
|
297
|
+
result[key] = merge(result[key], val);
|
|
298
|
+
} else if (isPlainObject(val)) {
|
|
299
|
+
result[key] = merge({}, val);
|
|
300
|
+
} else if (isArray(val)) {
|
|
301
|
+
result[key] = val.slice();
|
|
302
|
+
} else {
|
|
303
|
+
result[key] = val;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
308
|
+
forEach(arguments[i], assignValue);
|
|
309
|
+
}
|
|
310
|
+
return result;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Extends object a by mutably adding to it the properties of object b.
|
|
315
|
+
*
|
|
316
|
+
* @param {Object} a The object to be extended
|
|
317
|
+
* @param {Object} b The object to copy properties from
|
|
318
|
+
* @param {Object} thisArg The object to bind function to
|
|
319
|
+
* @return {Object} The resulting value of object a
|
|
320
|
+
*/
|
|
321
|
+
function extend(a, b, thisArg) {
|
|
322
|
+
forEach(b, function assignValue(val, key) {
|
|
323
|
+
if (thisArg && typeof val === 'function') {
|
|
324
|
+
a[key] = bind(val, thisArg);
|
|
325
|
+
} else {
|
|
326
|
+
a[key] = val;
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
return a;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
|
334
|
+
*
|
|
335
|
+
* @param {string} content with BOM
|
|
336
|
+
* @return {string} content value without BOM
|
|
337
|
+
*/
|
|
338
|
+
function stripBOM(content) {
|
|
339
|
+
if (content.charCodeAt(0) === 0xFEFF) {
|
|
340
|
+
content = content.slice(1);
|
|
341
|
+
}
|
|
342
|
+
return content;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
var utils = {
|
|
346
|
+
isArray: isArray,
|
|
347
|
+
isArrayBuffer: isArrayBuffer,
|
|
348
|
+
isBuffer: isBuffer,
|
|
349
|
+
isFormData: isFormData,
|
|
350
|
+
isArrayBufferView: isArrayBufferView,
|
|
351
|
+
isString: isString,
|
|
352
|
+
isNumber: isNumber,
|
|
353
|
+
isObject: isObject,
|
|
354
|
+
isPlainObject: isPlainObject,
|
|
355
|
+
isUndefined: isUndefined,
|
|
356
|
+
isDate: isDate,
|
|
357
|
+
isFile: isFile,
|
|
358
|
+
isBlob: isBlob,
|
|
359
|
+
isFunction: isFunction,
|
|
360
|
+
isStream: isStream,
|
|
361
|
+
isURLSearchParams: isURLSearchParams,
|
|
362
|
+
isStandardBrowserEnv: isStandardBrowserEnv,
|
|
363
|
+
forEach: forEach,
|
|
364
|
+
merge: merge,
|
|
365
|
+
extend: extend,
|
|
366
|
+
trim: trim,
|
|
367
|
+
stripBOM: stripBOM
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
function encode(val) {
|
|
371
|
+
return encodeURIComponent(val).
|
|
372
|
+
replace(/%3A/gi, ':').
|
|
373
|
+
replace(/%24/g, '$').
|
|
374
|
+
replace(/%2C/gi, ',').
|
|
375
|
+
replace(/%20/g, '+').
|
|
376
|
+
replace(/%5B/gi, '[').
|
|
377
|
+
replace(/%5D/gi, ']');
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Build a URL by appending params to the end
|
|
382
|
+
*
|
|
383
|
+
* @param {string} url The base of the url (e.g., http://www.google.com)
|
|
384
|
+
* @param {object} [params] The params to be appended
|
|
385
|
+
* @returns {string} The formatted url
|
|
386
|
+
*/
|
|
387
|
+
var buildURL = function buildURL(url, params, paramsSerializer) {
|
|
388
|
+
/*eslint no-param-reassign:0*/
|
|
389
|
+
if (!params) {
|
|
390
|
+
return url;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
var serializedParams;
|
|
394
|
+
if (paramsSerializer) {
|
|
395
|
+
serializedParams = paramsSerializer(params);
|
|
396
|
+
} else if (utils.isURLSearchParams(params)) {
|
|
397
|
+
serializedParams = params.toString();
|
|
398
|
+
} else {
|
|
399
|
+
var parts = [];
|
|
400
|
+
|
|
401
|
+
utils.forEach(params, function serialize(val, key) {
|
|
402
|
+
if (val === null || typeof val === 'undefined') {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
if (utils.isArray(val)) {
|
|
407
|
+
key = key + '[]';
|
|
408
|
+
} else {
|
|
409
|
+
val = [val];
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
utils.forEach(val, function parseValue(v) {
|
|
413
|
+
if (utils.isDate(v)) {
|
|
414
|
+
v = v.toISOString();
|
|
415
|
+
} else if (utils.isObject(v)) {
|
|
416
|
+
v = JSON.stringify(v);
|
|
417
|
+
}
|
|
418
|
+
parts.push(encode(key) + '=' + encode(v));
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
serializedParams = parts.join('&');
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (serializedParams) {
|
|
426
|
+
var hashmarkIndex = url.indexOf('#');
|
|
427
|
+
if (hashmarkIndex !== -1) {
|
|
428
|
+
url = url.slice(0, hashmarkIndex);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
return url;
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
function InterceptorManager() {
|
|
438
|
+
this.handlers = [];
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Add a new interceptor to the stack
|
|
443
|
+
*
|
|
444
|
+
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
|
445
|
+
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
|
446
|
+
*
|
|
447
|
+
* @return {Number} An ID used to remove interceptor later
|
|
448
|
+
*/
|
|
449
|
+
InterceptorManager.prototype.use = function use(fulfilled, rejected, options) {
|
|
450
|
+
this.handlers.push({
|
|
451
|
+
fulfilled: fulfilled,
|
|
452
|
+
rejected: rejected,
|
|
453
|
+
synchronous: options ? options.synchronous : false,
|
|
454
|
+
runWhen: options ? options.runWhen : null
|
|
455
|
+
});
|
|
456
|
+
return this.handlers.length - 1;
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Remove an interceptor from the stack
|
|
461
|
+
*
|
|
462
|
+
* @param {Number} id The ID that was returned by `use`
|
|
463
|
+
*/
|
|
464
|
+
InterceptorManager.prototype.eject = function eject(id) {
|
|
465
|
+
if (this.handlers[id]) {
|
|
466
|
+
this.handlers[id] = null;
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Iterate over all the registered interceptors
|
|
472
|
+
*
|
|
473
|
+
* This method is particularly useful for skipping over any
|
|
474
|
+
* interceptors that may have become `null` calling `eject`.
|
|
475
|
+
*
|
|
476
|
+
* @param {Function} fn The function to call for each interceptor
|
|
477
|
+
*/
|
|
478
|
+
InterceptorManager.prototype.forEach = function forEach(fn) {
|
|
479
|
+
utils.forEach(this.handlers, function forEachHandler(h) {
|
|
480
|
+
if (h !== null) {
|
|
481
|
+
fn(h);
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
var InterceptorManager_1 = InterceptorManager;
|
|
487
|
+
|
|
488
|
+
var normalizeHeaderName = function normalizeHeaderName(headers, normalizedName) {
|
|
489
|
+
utils.forEach(headers, function processHeader(value, name) {
|
|
490
|
+
if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {
|
|
491
|
+
headers[normalizedName] = value;
|
|
492
|
+
delete headers[name];
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Update an Error with the specified config, error code, and response.
|
|
499
|
+
*
|
|
500
|
+
* @param {Error} error The error to update.
|
|
501
|
+
* @param {Object} config The config.
|
|
502
|
+
* @param {string} [code] The error code (for example, 'ECONNABORTED').
|
|
503
|
+
* @param {Object} [request] The request.
|
|
504
|
+
* @param {Object} [response] The response.
|
|
505
|
+
* @returns {Error} The error.
|
|
506
|
+
*/
|
|
507
|
+
var enhanceError = function enhanceError(error, config, code, request, response) {
|
|
508
|
+
error.config = config;
|
|
509
|
+
if (code) {
|
|
510
|
+
error.code = code;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
error.request = request;
|
|
514
|
+
error.response = response;
|
|
515
|
+
error.isAxiosError = true;
|
|
516
|
+
|
|
517
|
+
error.toJSON = function toJSON() {
|
|
518
|
+
return {
|
|
519
|
+
// Standard
|
|
520
|
+
message: this.message,
|
|
521
|
+
name: this.name,
|
|
522
|
+
// Microsoft
|
|
523
|
+
description: this.description,
|
|
524
|
+
number: this.number,
|
|
525
|
+
// Mozilla
|
|
526
|
+
fileName: this.fileName,
|
|
527
|
+
lineNumber: this.lineNumber,
|
|
528
|
+
columnNumber: this.columnNumber,
|
|
529
|
+
stack: this.stack,
|
|
530
|
+
// Axios
|
|
531
|
+
config: this.config,
|
|
532
|
+
code: this.code,
|
|
533
|
+
status: this.response && this.response.status ? this.response.status : null
|
|
534
|
+
};
|
|
535
|
+
};
|
|
536
|
+
return error;
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Create an Error with the specified message, config, error code, request and response.
|
|
541
|
+
*
|
|
542
|
+
* @param {string} message The error message.
|
|
543
|
+
* @param {Object} config The config.
|
|
544
|
+
* @param {string} [code] The error code (for example, 'ECONNABORTED').
|
|
545
|
+
* @param {Object} [request] The request.
|
|
546
|
+
* @param {Object} [response] The response.
|
|
547
|
+
* @returns {Error} The created error.
|
|
548
|
+
*/
|
|
549
|
+
var createError = function createError(message, config, code, request, response) {
|
|
550
|
+
var error = new Error(message);
|
|
551
|
+
return enhanceError(error, config, code, request, response);
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Resolve or reject a Promise based on response status.
|
|
556
|
+
*
|
|
557
|
+
* @param {Function} resolve A function that resolves the promise.
|
|
558
|
+
* @param {Function} reject A function that rejects the promise.
|
|
559
|
+
* @param {object} response The response.
|
|
560
|
+
*/
|
|
561
|
+
var settle = function settle(resolve, reject, response) {
|
|
562
|
+
var validateStatus = response.config.validateStatus;
|
|
563
|
+
if (!response.status || !validateStatus || validateStatus(response.status)) {
|
|
564
|
+
resolve(response);
|
|
565
|
+
} else {
|
|
566
|
+
reject(createError(
|
|
567
|
+
'Request failed with status code ' + response.status,
|
|
568
|
+
response.config,
|
|
569
|
+
null,
|
|
570
|
+
response.request,
|
|
571
|
+
response
|
|
572
|
+
));
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
var cookies = (
|
|
577
|
+
utils.isStandardBrowserEnv() ?
|
|
578
|
+
|
|
579
|
+
// Standard browser envs support document.cookie
|
|
580
|
+
(function standardBrowserEnv() {
|
|
581
|
+
return {
|
|
582
|
+
write: function write(name, value, expires, path, domain, secure) {
|
|
583
|
+
var cookie = [];
|
|
584
|
+
cookie.push(name + '=' + encodeURIComponent(value));
|
|
585
|
+
|
|
586
|
+
if (utils.isNumber(expires)) {
|
|
587
|
+
cookie.push('expires=' + new Date(expires).toGMTString());
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
if (utils.isString(path)) {
|
|
591
|
+
cookie.push('path=' + path);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
if (utils.isString(domain)) {
|
|
595
|
+
cookie.push('domain=' + domain);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
if (secure === true) {
|
|
599
|
+
cookie.push('secure');
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
document.cookie = cookie.join('; ');
|
|
603
|
+
},
|
|
604
|
+
|
|
605
|
+
read: function read(name) {
|
|
606
|
+
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
|
607
|
+
return (match ? decodeURIComponent(match[3]) : null);
|
|
608
|
+
},
|
|
609
|
+
|
|
610
|
+
remove: function remove(name) {
|
|
611
|
+
this.write(name, '', Date.now() - 86400000);
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
})() :
|
|
615
|
+
|
|
616
|
+
// Non standard browser env (web workers, react-native) lack needed support.
|
|
617
|
+
(function nonStandardBrowserEnv() {
|
|
618
|
+
return {
|
|
619
|
+
write: function write() {},
|
|
620
|
+
read: function read() { return null; },
|
|
621
|
+
remove: function remove() {}
|
|
622
|
+
};
|
|
623
|
+
})()
|
|
624
|
+
);
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Determines whether the specified URL is absolute
|
|
628
|
+
*
|
|
629
|
+
* @param {string} url The URL to test
|
|
630
|
+
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
|
631
|
+
*/
|
|
632
|
+
var isAbsoluteURL = function isAbsoluteURL(url) {
|
|
633
|
+
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
|
634
|
+
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
|
635
|
+
// by any combination of letters, digits, plus, period, or hyphen.
|
|
636
|
+
return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* Creates a new URL by combining the specified URLs
|
|
641
|
+
*
|
|
642
|
+
* @param {string} baseURL The base URL
|
|
643
|
+
* @param {string} relativeURL The relative URL
|
|
644
|
+
* @returns {string} The combined URL
|
|
645
|
+
*/
|
|
646
|
+
var combineURLs = function combineURLs(baseURL, relativeURL) {
|
|
647
|
+
return relativeURL
|
|
648
|
+
? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
|
649
|
+
: baseURL;
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Creates a new URL by combining the baseURL with the requestedURL,
|
|
654
|
+
* only when the requestedURL is not already an absolute URL.
|
|
655
|
+
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
|
656
|
+
*
|
|
657
|
+
* @param {string} baseURL The base URL
|
|
658
|
+
* @param {string} requestedURL Absolute or relative URL to combine
|
|
659
|
+
* @returns {string} The combined full path
|
|
660
|
+
*/
|
|
661
|
+
var buildFullPath = function buildFullPath(baseURL, requestedURL) {
|
|
662
|
+
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
|
663
|
+
return combineURLs(baseURL, requestedURL);
|
|
664
|
+
}
|
|
665
|
+
return requestedURL;
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
// Headers whose duplicates are ignored by node
|
|
669
|
+
// c.f. https://nodejs.org/api/http.html#http_message_headers
|
|
670
|
+
var ignoreDuplicateOf = [
|
|
671
|
+
'age', 'authorization', 'content-length', 'content-type', 'etag',
|
|
672
|
+
'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
|
|
673
|
+
'last-modified', 'location', 'max-forwards', 'proxy-authorization',
|
|
674
|
+
'referer', 'retry-after', 'user-agent'
|
|
675
|
+
];
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Parse headers into an object
|
|
679
|
+
*
|
|
680
|
+
* ```
|
|
681
|
+
* Date: Wed, 27 Aug 2014 08:58:49 GMT
|
|
682
|
+
* Content-Type: application/json
|
|
683
|
+
* Connection: keep-alive
|
|
684
|
+
* Transfer-Encoding: chunked
|
|
685
|
+
* ```
|
|
686
|
+
*
|
|
687
|
+
* @param {String} headers Headers needing to be parsed
|
|
688
|
+
* @returns {Object} Headers parsed into an object
|
|
689
|
+
*/
|
|
690
|
+
var parseHeaders = function parseHeaders(headers) {
|
|
691
|
+
var parsed = {};
|
|
692
|
+
var key;
|
|
693
|
+
var val;
|
|
694
|
+
var i;
|
|
695
|
+
|
|
696
|
+
if (!headers) { return parsed; }
|
|
697
|
+
|
|
698
|
+
utils.forEach(headers.split('\n'), function parser(line) {
|
|
699
|
+
i = line.indexOf(':');
|
|
700
|
+
key = utils.trim(line.substr(0, i)).toLowerCase();
|
|
701
|
+
val = utils.trim(line.substr(i + 1));
|
|
702
|
+
|
|
703
|
+
if (key) {
|
|
704
|
+
if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
if (key === 'set-cookie') {
|
|
708
|
+
parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
|
|
709
|
+
} else {
|
|
710
|
+
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
return parsed;
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
var isURLSameOrigin = (
|
|
719
|
+
utils.isStandardBrowserEnv() ?
|
|
720
|
+
|
|
721
|
+
// Standard browser envs have full support of the APIs needed to test
|
|
722
|
+
// whether the request URL is of the same origin as current location.
|
|
723
|
+
(function standardBrowserEnv() {
|
|
724
|
+
var msie = /(msie|trident)/i.test(navigator.userAgent);
|
|
725
|
+
var urlParsingNode = document.createElement('a');
|
|
726
|
+
var originURL;
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* Parse a URL to discover it's components
|
|
730
|
+
*
|
|
731
|
+
* @param {String} url The URL to be parsed
|
|
732
|
+
* @returns {Object}
|
|
733
|
+
*/
|
|
734
|
+
function resolveURL(url) {
|
|
735
|
+
var href = url;
|
|
736
|
+
|
|
737
|
+
if (msie) {
|
|
738
|
+
// IE needs attribute set twice to normalize properties
|
|
739
|
+
urlParsingNode.setAttribute('href', href);
|
|
740
|
+
href = urlParsingNode.href;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
urlParsingNode.setAttribute('href', href);
|
|
744
|
+
|
|
745
|
+
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
|
746
|
+
return {
|
|
747
|
+
href: urlParsingNode.href,
|
|
748
|
+
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
|
749
|
+
host: urlParsingNode.host,
|
|
750
|
+
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
|
751
|
+
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
|
752
|
+
hostname: urlParsingNode.hostname,
|
|
753
|
+
port: urlParsingNode.port,
|
|
754
|
+
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
|
|
755
|
+
urlParsingNode.pathname :
|
|
756
|
+
'/' + urlParsingNode.pathname
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
originURL = resolveURL(window.location.href);
|
|
761
|
+
|
|
762
|
+
/**
|
|
763
|
+
* Determine if a URL shares the same origin as the current location
|
|
764
|
+
*
|
|
765
|
+
* @param {String} requestURL The URL to test
|
|
766
|
+
* @returns {boolean} True if URL shares the same origin, otherwise false
|
|
767
|
+
*/
|
|
768
|
+
return function isURLSameOrigin(requestURL) {
|
|
769
|
+
var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
|
|
770
|
+
return (parsed.protocol === originURL.protocol &&
|
|
771
|
+
parsed.host === originURL.host);
|
|
772
|
+
};
|
|
773
|
+
})() :
|
|
774
|
+
|
|
775
|
+
// Non standard browser envs (web workers, react-native) lack needed support.
|
|
776
|
+
(function nonStandardBrowserEnv() {
|
|
777
|
+
return function isURLSameOrigin() {
|
|
778
|
+
return true;
|
|
779
|
+
};
|
|
780
|
+
})()
|
|
781
|
+
);
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* A `Cancel` is an object that is thrown when an operation is canceled.
|
|
785
|
+
*
|
|
786
|
+
* @class
|
|
787
|
+
* @param {string=} message The message.
|
|
788
|
+
*/
|
|
789
|
+
function Cancel(message) {
|
|
790
|
+
this.message = message;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
Cancel.prototype.toString = function toString() {
|
|
794
|
+
return 'Cancel' + (this.message ? ': ' + this.message : '');
|
|
795
|
+
};
|
|
796
|
+
|
|
797
|
+
Cancel.prototype.__CANCEL__ = true;
|
|
798
|
+
|
|
799
|
+
var Cancel_1 = Cancel;
|
|
800
|
+
|
|
801
|
+
var xhr = function xhrAdapter(config) {
|
|
802
|
+
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
|
803
|
+
var requestData = config.data;
|
|
804
|
+
var requestHeaders = config.headers;
|
|
805
|
+
var responseType = config.responseType;
|
|
806
|
+
var onCanceled;
|
|
807
|
+
function done() {
|
|
808
|
+
if (config.cancelToken) {
|
|
809
|
+
config.cancelToken.unsubscribe(onCanceled);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
if (config.signal) {
|
|
813
|
+
config.signal.removeEventListener('abort', onCanceled);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
if (utils.isFormData(requestData)) {
|
|
818
|
+
delete requestHeaders['Content-Type']; // Let the browser set it
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
var request = new XMLHttpRequest();
|
|
822
|
+
|
|
823
|
+
// HTTP basic authentication
|
|
824
|
+
if (config.auth) {
|
|
825
|
+
var username = config.auth.username || '';
|
|
826
|
+
var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
|
|
827
|
+
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
var fullPath = buildFullPath(config.baseURL, config.url);
|
|
831
|
+
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
|
|
832
|
+
|
|
833
|
+
// Set the request timeout in MS
|
|
834
|
+
request.timeout = config.timeout;
|
|
835
|
+
|
|
836
|
+
function onloadend() {
|
|
837
|
+
if (!request) {
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
// Prepare the response
|
|
841
|
+
var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
|
|
842
|
+
var responseData = !responseType || responseType === 'text' || responseType === 'json' ?
|
|
843
|
+
request.responseText : request.response;
|
|
844
|
+
var response = {
|
|
845
|
+
data: responseData,
|
|
846
|
+
status: request.status,
|
|
847
|
+
statusText: request.statusText,
|
|
848
|
+
headers: responseHeaders,
|
|
849
|
+
config: config,
|
|
850
|
+
request: request
|
|
851
|
+
};
|
|
852
|
+
|
|
853
|
+
settle(function _resolve(value) {
|
|
854
|
+
resolve(value);
|
|
855
|
+
done();
|
|
856
|
+
}, function _reject(err) {
|
|
857
|
+
reject(err);
|
|
858
|
+
done();
|
|
859
|
+
}, response);
|
|
860
|
+
|
|
861
|
+
// Clean up request
|
|
862
|
+
request = null;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
if ('onloadend' in request) {
|
|
866
|
+
// Use onloadend if available
|
|
867
|
+
request.onloadend = onloadend;
|
|
868
|
+
} else {
|
|
869
|
+
// Listen for ready state to emulate onloadend
|
|
870
|
+
request.onreadystatechange = function handleLoad() {
|
|
871
|
+
if (!request || request.readyState !== 4) {
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
// The request errored out and we didn't get a response, this will be
|
|
876
|
+
// handled by onerror instead
|
|
877
|
+
// With one exception: request that using file: protocol, most browsers
|
|
878
|
+
// will return status as 0 even though it's a successful request
|
|
879
|
+
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
// readystate handler is calling before onerror or ontimeout handlers,
|
|
883
|
+
// so we should call onloadend on the next 'tick'
|
|
884
|
+
setTimeout(onloadend);
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
// Handle browser request cancellation (as opposed to a manual cancellation)
|
|
889
|
+
request.onabort = function handleAbort() {
|
|
890
|
+
if (!request) {
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
reject(createError('Request aborted', config, 'ECONNABORTED', request));
|
|
895
|
+
|
|
896
|
+
// Clean up request
|
|
897
|
+
request = null;
|
|
898
|
+
};
|
|
899
|
+
|
|
900
|
+
// Handle low level network errors
|
|
901
|
+
request.onerror = function handleError() {
|
|
902
|
+
// Real errors are hidden from us by the browser
|
|
903
|
+
// onerror should only fire if it's a network error
|
|
904
|
+
reject(createError('Network Error', config, null, request));
|
|
905
|
+
|
|
906
|
+
// Clean up request
|
|
907
|
+
request = null;
|
|
908
|
+
};
|
|
909
|
+
|
|
910
|
+
// Handle timeout
|
|
911
|
+
request.ontimeout = function handleTimeout() {
|
|
912
|
+
var timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
|
|
913
|
+
var transitional = config.transitional || defaults_1.transitional;
|
|
914
|
+
if (config.timeoutErrorMessage) {
|
|
915
|
+
timeoutErrorMessage = config.timeoutErrorMessage;
|
|
916
|
+
}
|
|
917
|
+
reject(createError(
|
|
918
|
+
timeoutErrorMessage,
|
|
919
|
+
config,
|
|
920
|
+
transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
|
|
921
|
+
request));
|
|
922
|
+
|
|
923
|
+
// Clean up request
|
|
924
|
+
request = null;
|
|
925
|
+
};
|
|
926
|
+
|
|
927
|
+
// Add xsrf header
|
|
928
|
+
// This is only done if running in a standard browser environment.
|
|
929
|
+
// Specifically not if we're in a web worker, or react-native.
|
|
930
|
+
if (utils.isStandardBrowserEnv()) {
|
|
931
|
+
// Add xsrf header
|
|
932
|
+
var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ?
|
|
933
|
+
cookies.read(config.xsrfCookieName) :
|
|
934
|
+
undefined;
|
|
935
|
+
|
|
936
|
+
if (xsrfValue) {
|
|
937
|
+
requestHeaders[config.xsrfHeaderName] = xsrfValue;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
// Add headers to the request
|
|
942
|
+
if ('setRequestHeader' in request) {
|
|
943
|
+
utils.forEach(requestHeaders, function setRequestHeader(val, key) {
|
|
944
|
+
if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
|
|
945
|
+
// Remove Content-Type if data is undefined
|
|
946
|
+
delete requestHeaders[key];
|
|
947
|
+
} else {
|
|
948
|
+
// Otherwise add header to the request
|
|
949
|
+
request.setRequestHeader(key, val);
|
|
950
|
+
}
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
// Add withCredentials to request if needed
|
|
955
|
+
if (!utils.isUndefined(config.withCredentials)) {
|
|
956
|
+
request.withCredentials = !!config.withCredentials;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
// Add responseType to request if needed
|
|
960
|
+
if (responseType && responseType !== 'json') {
|
|
961
|
+
request.responseType = config.responseType;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
// Handle progress if needed
|
|
965
|
+
if (typeof config.onDownloadProgress === 'function') {
|
|
966
|
+
request.addEventListener('progress', config.onDownloadProgress);
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
// Not all browsers support upload events
|
|
970
|
+
if (typeof config.onUploadProgress === 'function' && request.upload) {
|
|
971
|
+
request.upload.addEventListener('progress', config.onUploadProgress);
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
if (config.cancelToken || config.signal) {
|
|
975
|
+
// Handle cancellation
|
|
976
|
+
// eslint-disable-next-line func-names
|
|
977
|
+
onCanceled = function(cancel) {
|
|
978
|
+
if (!request) {
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
reject(!cancel || (cancel && cancel.type) ? new Cancel_1('canceled') : cancel);
|
|
982
|
+
request.abort();
|
|
983
|
+
request = null;
|
|
984
|
+
};
|
|
985
|
+
|
|
986
|
+
config.cancelToken && config.cancelToken.subscribe(onCanceled);
|
|
987
|
+
if (config.signal) {
|
|
988
|
+
config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
if (!requestData) {
|
|
993
|
+
requestData = null;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
// Send the request
|
|
997
|
+
request.send(requestData);
|
|
998
|
+
});
|
|
999
|
+
};
|
|
1000
|
+
|
|
1001
|
+
var DEFAULT_CONTENT_TYPE = {
|
|
1002
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
1003
|
+
};
|
|
1004
|
+
|
|
1005
|
+
function setContentTypeIfUnset(headers, value) {
|
|
1006
|
+
if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
|
|
1007
|
+
headers['Content-Type'] = value;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
function getDefaultAdapter() {
|
|
1012
|
+
var adapter;
|
|
1013
|
+
if (typeof XMLHttpRequest !== 'undefined') {
|
|
1014
|
+
// For browsers use XHR adapter
|
|
1015
|
+
adapter = xhr;
|
|
1016
|
+
} else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
|
|
1017
|
+
// For node use HTTP adapter
|
|
1018
|
+
adapter = xhr;
|
|
1019
|
+
}
|
|
1020
|
+
return adapter;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
function stringifySafely(rawValue, parser, encoder) {
|
|
1024
|
+
if (utils.isString(rawValue)) {
|
|
1025
|
+
try {
|
|
1026
|
+
(parser || JSON.parse)(rawValue);
|
|
1027
|
+
return utils.trim(rawValue);
|
|
1028
|
+
} catch (e) {
|
|
1029
|
+
if (e.name !== 'SyntaxError') {
|
|
1030
|
+
throw e;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
return (encoder || JSON.stringify)(rawValue);
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
var defaults = {
|
|
1039
|
+
|
|
1040
|
+
transitional: {
|
|
1041
|
+
silentJSONParsing: true,
|
|
1042
|
+
forcedJSONParsing: true,
|
|
1043
|
+
clarifyTimeoutError: false
|
|
1044
|
+
},
|
|
1045
|
+
|
|
1046
|
+
adapter: getDefaultAdapter(),
|
|
1047
|
+
|
|
1048
|
+
transformRequest: [function transformRequest(data, headers) {
|
|
1049
|
+
normalizeHeaderName(headers, 'Accept');
|
|
1050
|
+
normalizeHeaderName(headers, 'Content-Type');
|
|
1051
|
+
|
|
1052
|
+
if (utils.isFormData(data) ||
|
|
1053
|
+
utils.isArrayBuffer(data) ||
|
|
1054
|
+
utils.isBuffer(data) ||
|
|
1055
|
+
utils.isStream(data) ||
|
|
1056
|
+
utils.isFile(data) ||
|
|
1057
|
+
utils.isBlob(data)
|
|
1058
|
+
) {
|
|
1059
|
+
return data;
|
|
1060
|
+
}
|
|
1061
|
+
if (utils.isArrayBufferView(data)) {
|
|
1062
|
+
return data.buffer;
|
|
1063
|
+
}
|
|
1064
|
+
if (utils.isURLSearchParams(data)) {
|
|
1065
|
+
setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
|
|
1066
|
+
return data.toString();
|
|
1067
|
+
}
|
|
1068
|
+
if (utils.isObject(data) || (headers && headers['Content-Type'] === 'application/json')) {
|
|
1069
|
+
setContentTypeIfUnset(headers, 'application/json');
|
|
1070
|
+
return stringifySafely(data);
|
|
1071
|
+
}
|
|
1072
|
+
return data;
|
|
1073
|
+
}],
|
|
1074
|
+
|
|
1075
|
+
transformResponse: [function transformResponse(data) {
|
|
1076
|
+
var transitional = this.transitional || defaults.transitional;
|
|
1077
|
+
var silentJSONParsing = transitional && transitional.silentJSONParsing;
|
|
1078
|
+
var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
|
|
1079
|
+
var strictJSONParsing = !silentJSONParsing && this.responseType === 'json';
|
|
1080
|
+
|
|
1081
|
+
if (strictJSONParsing || (forcedJSONParsing && utils.isString(data) && data.length)) {
|
|
1082
|
+
try {
|
|
1083
|
+
return JSON.parse(data);
|
|
1084
|
+
} catch (e) {
|
|
1085
|
+
if (strictJSONParsing) {
|
|
1086
|
+
if (e.name === 'SyntaxError') {
|
|
1087
|
+
throw enhanceError(e, this, 'E_JSON_PARSE');
|
|
1088
|
+
}
|
|
1089
|
+
throw e;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
return data;
|
|
1095
|
+
}],
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
|
1099
|
+
* timeout is not created.
|
|
1100
|
+
*/
|
|
1101
|
+
timeout: 0,
|
|
1102
|
+
|
|
1103
|
+
xsrfCookieName: 'XSRF-TOKEN',
|
|
1104
|
+
xsrfHeaderName: 'X-XSRF-TOKEN',
|
|
1105
|
+
|
|
1106
|
+
maxContentLength: -1,
|
|
1107
|
+
maxBodyLength: -1,
|
|
1108
|
+
|
|
1109
|
+
validateStatus: function validateStatus(status) {
|
|
1110
|
+
return status >= 200 && status < 300;
|
|
1111
|
+
},
|
|
1112
|
+
|
|
1113
|
+
headers: {
|
|
1114
|
+
common: {
|
|
1115
|
+
'Accept': 'application/json, text/plain, */*'
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
|
|
1120
|
+
utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
|
|
1121
|
+
defaults.headers[method] = {};
|
|
1122
|
+
});
|
|
1123
|
+
|
|
1124
|
+
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
|
1125
|
+
defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
|
|
1126
|
+
});
|
|
1127
|
+
|
|
1128
|
+
var defaults_1 = defaults;
|
|
1129
|
+
|
|
1130
|
+
/**
|
|
1131
|
+
* Transform the data for a request or a response
|
|
1132
|
+
*
|
|
1133
|
+
* @param {Object|String} data The data to be transformed
|
|
1134
|
+
* @param {Array} headers The headers for the request or response
|
|
1135
|
+
* @param {Array|Function} fns A single function or Array of functions
|
|
1136
|
+
* @returns {*} The resulting transformed data
|
|
1137
|
+
*/
|
|
1138
|
+
var transformData = function transformData(data, headers, fns) {
|
|
1139
|
+
var context = this || defaults_1;
|
|
1140
|
+
/*eslint no-param-reassign:0*/
|
|
1141
|
+
utils.forEach(fns, function transform(fn) {
|
|
1142
|
+
data = fn.call(context, data, headers);
|
|
1143
|
+
});
|
|
1144
|
+
|
|
1145
|
+
return data;
|
|
1146
|
+
};
|
|
1147
|
+
|
|
1148
|
+
var isCancel = function isCancel(value) {
|
|
1149
|
+
return !!(value && value.__CANCEL__);
|
|
1150
|
+
};
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* Throws a `Cancel` if cancellation has been requested.
|
|
1154
|
+
*/
|
|
1155
|
+
function throwIfCancellationRequested(config) {
|
|
1156
|
+
if (config.cancelToken) {
|
|
1157
|
+
config.cancelToken.throwIfRequested();
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
if (config.signal && config.signal.aborted) {
|
|
1161
|
+
throw new Cancel_1('canceled');
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
/**
|
|
1166
|
+
* Dispatch a request to the server using the configured adapter.
|
|
1167
|
+
*
|
|
1168
|
+
* @param {object} config The config that is to be used for the request
|
|
1169
|
+
* @returns {Promise} The Promise to be fulfilled
|
|
1170
|
+
*/
|
|
1171
|
+
var dispatchRequest = function dispatchRequest(config) {
|
|
1172
|
+
throwIfCancellationRequested(config);
|
|
1173
|
+
|
|
1174
|
+
// Ensure headers exist
|
|
1175
|
+
config.headers = config.headers || {};
|
|
1176
|
+
|
|
1177
|
+
// Transform request data
|
|
1178
|
+
config.data = transformData.call(
|
|
1179
|
+
config,
|
|
1180
|
+
config.data,
|
|
1181
|
+
config.headers,
|
|
1182
|
+
config.transformRequest
|
|
1183
|
+
);
|
|
1184
|
+
|
|
1185
|
+
// Flatten headers
|
|
1186
|
+
config.headers = utils.merge(
|
|
1187
|
+
config.headers.common || {},
|
|
1188
|
+
config.headers[config.method] || {},
|
|
1189
|
+
config.headers
|
|
1190
|
+
);
|
|
1191
|
+
|
|
1192
|
+
utils.forEach(
|
|
1193
|
+
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
|
1194
|
+
function cleanHeaderConfig(method) {
|
|
1195
|
+
delete config.headers[method];
|
|
1196
|
+
}
|
|
1197
|
+
);
|
|
1198
|
+
|
|
1199
|
+
var adapter = config.adapter || defaults_1.adapter;
|
|
1200
|
+
|
|
1201
|
+
return adapter(config).then(function onAdapterResolution(response) {
|
|
1202
|
+
throwIfCancellationRequested(config);
|
|
1203
|
+
|
|
1204
|
+
// Transform response data
|
|
1205
|
+
response.data = transformData.call(
|
|
1206
|
+
config,
|
|
1207
|
+
response.data,
|
|
1208
|
+
response.headers,
|
|
1209
|
+
config.transformResponse
|
|
1210
|
+
);
|
|
1211
|
+
|
|
1212
|
+
return response;
|
|
1213
|
+
}, function onAdapterRejection(reason) {
|
|
1214
|
+
if (!isCancel(reason)) {
|
|
1215
|
+
throwIfCancellationRequested(config);
|
|
1216
|
+
|
|
1217
|
+
// Transform response data
|
|
1218
|
+
if (reason && reason.response) {
|
|
1219
|
+
reason.response.data = transformData.call(
|
|
1220
|
+
config,
|
|
1221
|
+
reason.response.data,
|
|
1222
|
+
reason.response.headers,
|
|
1223
|
+
config.transformResponse
|
|
1224
|
+
);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
return Promise.reject(reason);
|
|
1229
|
+
});
|
|
1230
|
+
};
|
|
1231
|
+
|
|
1232
|
+
/**
|
|
1233
|
+
* Config-specific merge-function which creates a new config-object
|
|
1234
|
+
* by merging two configuration objects together.
|
|
1235
|
+
*
|
|
1236
|
+
* @param {Object} config1
|
|
1237
|
+
* @param {Object} config2
|
|
1238
|
+
* @returns {Object} New object resulting from merging config2 to config1
|
|
1239
|
+
*/
|
|
1240
|
+
var mergeConfig = function mergeConfig(config1, config2) {
|
|
1241
|
+
// eslint-disable-next-line no-param-reassign
|
|
1242
|
+
config2 = config2 || {};
|
|
1243
|
+
var config = {};
|
|
1244
|
+
|
|
1245
|
+
function getMergedValue(target, source) {
|
|
1246
|
+
if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
|
|
1247
|
+
return utils.merge(target, source);
|
|
1248
|
+
} else if (utils.isPlainObject(source)) {
|
|
1249
|
+
return utils.merge({}, source);
|
|
1250
|
+
} else if (utils.isArray(source)) {
|
|
1251
|
+
return source.slice();
|
|
1252
|
+
}
|
|
1253
|
+
return source;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
// eslint-disable-next-line consistent-return
|
|
1257
|
+
function mergeDeepProperties(prop) {
|
|
1258
|
+
if (!utils.isUndefined(config2[prop])) {
|
|
1259
|
+
return getMergedValue(config1[prop], config2[prop]);
|
|
1260
|
+
} else if (!utils.isUndefined(config1[prop])) {
|
|
1261
|
+
return getMergedValue(undefined, config1[prop]);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
// eslint-disable-next-line consistent-return
|
|
1266
|
+
function valueFromConfig2(prop) {
|
|
1267
|
+
if (!utils.isUndefined(config2[prop])) {
|
|
1268
|
+
return getMergedValue(undefined, config2[prop]);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
// eslint-disable-next-line consistent-return
|
|
1273
|
+
function defaultToConfig2(prop) {
|
|
1274
|
+
if (!utils.isUndefined(config2[prop])) {
|
|
1275
|
+
return getMergedValue(undefined, config2[prop]);
|
|
1276
|
+
} else if (!utils.isUndefined(config1[prop])) {
|
|
1277
|
+
return getMergedValue(undefined, config1[prop]);
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
// eslint-disable-next-line consistent-return
|
|
1282
|
+
function mergeDirectKeys(prop) {
|
|
1283
|
+
if (prop in config2) {
|
|
1284
|
+
return getMergedValue(config1[prop], config2[prop]);
|
|
1285
|
+
} else if (prop in config1) {
|
|
1286
|
+
return getMergedValue(undefined, config1[prop]);
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
var mergeMap = {
|
|
1291
|
+
'url': valueFromConfig2,
|
|
1292
|
+
'method': valueFromConfig2,
|
|
1293
|
+
'data': valueFromConfig2,
|
|
1294
|
+
'baseURL': defaultToConfig2,
|
|
1295
|
+
'transformRequest': defaultToConfig2,
|
|
1296
|
+
'transformResponse': defaultToConfig2,
|
|
1297
|
+
'paramsSerializer': defaultToConfig2,
|
|
1298
|
+
'timeout': defaultToConfig2,
|
|
1299
|
+
'timeoutMessage': defaultToConfig2,
|
|
1300
|
+
'withCredentials': defaultToConfig2,
|
|
1301
|
+
'adapter': defaultToConfig2,
|
|
1302
|
+
'responseType': defaultToConfig2,
|
|
1303
|
+
'xsrfCookieName': defaultToConfig2,
|
|
1304
|
+
'xsrfHeaderName': defaultToConfig2,
|
|
1305
|
+
'onUploadProgress': defaultToConfig2,
|
|
1306
|
+
'onDownloadProgress': defaultToConfig2,
|
|
1307
|
+
'decompress': defaultToConfig2,
|
|
1308
|
+
'maxContentLength': defaultToConfig2,
|
|
1309
|
+
'maxBodyLength': defaultToConfig2,
|
|
1310
|
+
'transport': defaultToConfig2,
|
|
1311
|
+
'httpAgent': defaultToConfig2,
|
|
1312
|
+
'httpsAgent': defaultToConfig2,
|
|
1313
|
+
'cancelToken': defaultToConfig2,
|
|
1314
|
+
'socketPath': defaultToConfig2,
|
|
1315
|
+
'responseEncoding': defaultToConfig2,
|
|
1316
|
+
'validateStatus': mergeDirectKeys
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
|
|
1320
|
+
var merge = mergeMap[prop] || mergeDeepProperties;
|
|
1321
|
+
var configValue = merge(prop);
|
|
1322
|
+
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
|
1323
|
+
});
|
|
1324
|
+
|
|
1325
|
+
return config;
|
|
1326
|
+
};
|
|
1327
|
+
|
|
1328
|
+
var data$1 = {
|
|
1329
|
+
"version": "0.23.0"
|
|
1330
|
+
};
|
|
1331
|
+
|
|
1332
|
+
var VERSION = data$1.version;
|
|
1333
|
+
|
|
1334
|
+
var validators$1 = {};
|
|
1335
|
+
|
|
1336
|
+
// eslint-disable-next-line func-names
|
|
1337
|
+
['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach(function(type, i) {
|
|
1338
|
+
validators$1[type] = function validator(thing) {
|
|
1339
|
+
return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
|
|
1340
|
+
};
|
|
1341
|
+
});
|
|
1342
|
+
|
|
1343
|
+
var deprecatedWarnings = {};
|
|
1344
|
+
|
|
1345
|
+
/**
|
|
1346
|
+
* Transitional option validator
|
|
1347
|
+
* @param {function|boolean?} validator - set to false if the transitional option has been removed
|
|
1348
|
+
* @param {string?} version - deprecated version / removed since version
|
|
1349
|
+
* @param {string?} message - some message with additional info
|
|
1350
|
+
* @returns {function}
|
|
1351
|
+
*/
|
|
1352
|
+
validators$1.transitional = function transitional(validator, version, message) {
|
|
1353
|
+
function formatMessage(opt, desc) {
|
|
1354
|
+
return '[Axios v' + VERSION + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : '');
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
// eslint-disable-next-line func-names
|
|
1358
|
+
return function(value, opt, opts) {
|
|
1359
|
+
if (validator === false) {
|
|
1360
|
+
throw new Error(formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')));
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
if (version && !deprecatedWarnings[opt]) {
|
|
1364
|
+
deprecatedWarnings[opt] = true;
|
|
1365
|
+
// eslint-disable-next-line no-console
|
|
1366
|
+
console.warn(
|
|
1367
|
+
formatMessage(
|
|
1368
|
+
opt,
|
|
1369
|
+
' has been deprecated since v' + version + ' and will be removed in the near future'
|
|
1370
|
+
)
|
|
1371
|
+
);
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
return validator ? validator(value, opt, opts) : true;
|
|
1375
|
+
};
|
|
1376
|
+
};
|
|
1377
|
+
|
|
1378
|
+
/**
|
|
1379
|
+
* Assert object's properties type
|
|
1380
|
+
* @param {object} options
|
|
1381
|
+
* @param {object} schema
|
|
1382
|
+
* @param {boolean?} allowUnknown
|
|
1383
|
+
*/
|
|
1384
|
+
|
|
1385
|
+
function assertOptions(options, schema, allowUnknown) {
|
|
1386
|
+
if (typeof options !== 'object') {
|
|
1387
|
+
throw new TypeError('options must be an object');
|
|
1388
|
+
}
|
|
1389
|
+
var keys = Object.keys(options);
|
|
1390
|
+
var i = keys.length;
|
|
1391
|
+
while (i-- > 0) {
|
|
1392
|
+
var opt = keys[i];
|
|
1393
|
+
var validator = schema[opt];
|
|
1394
|
+
if (validator) {
|
|
1395
|
+
var value = options[opt];
|
|
1396
|
+
var result = value === undefined || validator(value, opt, options);
|
|
1397
|
+
if (result !== true) {
|
|
1398
|
+
throw new TypeError('option ' + opt + ' must be ' + result);
|
|
1399
|
+
}
|
|
1400
|
+
continue;
|
|
1401
|
+
}
|
|
1402
|
+
if (allowUnknown !== true) {
|
|
1403
|
+
throw Error('Unknown option ' + opt);
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
var validator = {
|
|
1409
|
+
assertOptions: assertOptions,
|
|
1410
|
+
validators: validators$1
|
|
1411
|
+
};
|
|
1412
|
+
|
|
1413
|
+
var validators = validator.validators;
|
|
1414
|
+
/**
|
|
1415
|
+
* Create a new instance of Axios
|
|
1416
|
+
*
|
|
1417
|
+
* @param {Object} instanceConfig The default config for the instance
|
|
1418
|
+
*/
|
|
1419
|
+
function Axios(instanceConfig) {
|
|
1420
|
+
this.defaults = instanceConfig;
|
|
1421
|
+
this.interceptors = {
|
|
1422
|
+
request: new InterceptorManager_1(),
|
|
1423
|
+
response: new InterceptorManager_1()
|
|
1424
|
+
};
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
/**
|
|
1428
|
+
* Dispatch a request
|
|
1429
|
+
*
|
|
1430
|
+
* @param {Object} config The config specific for this request (merged with this.defaults)
|
|
1431
|
+
*/
|
|
1432
|
+
Axios.prototype.request = function request(config) {
|
|
1433
|
+
/*eslint no-param-reassign:0*/
|
|
1434
|
+
// Allow for axios('example/url'[, config]) a la fetch API
|
|
1435
|
+
if (typeof config === 'string') {
|
|
1436
|
+
config = arguments[1] || {};
|
|
1437
|
+
config.url = arguments[0];
|
|
1438
|
+
} else {
|
|
1439
|
+
config = config || {};
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
config = mergeConfig(this.defaults, config);
|
|
1443
|
+
|
|
1444
|
+
// Set config.method
|
|
1445
|
+
if (config.method) {
|
|
1446
|
+
config.method = config.method.toLowerCase();
|
|
1447
|
+
} else if (this.defaults.method) {
|
|
1448
|
+
config.method = this.defaults.method.toLowerCase();
|
|
1449
|
+
} else {
|
|
1450
|
+
config.method = 'get';
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
var transitional = config.transitional;
|
|
1454
|
+
|
|
1455
|
+
if (transitional !== undefined) {
|
|
1456
|
+
validator.assertOptions(transitional, {
|
|
1457
|
+
silentJSONParsing: validators.transitional(validators.boolean),
|
|
1458
|
+
forcedJSONParsing: validators.transitional(validators.boolean),
|
|
1459
|
+
clarifyTimeoutError: validators.transitional(validators.boolean)
|
|
1460
|
+
}, false);
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
// filter out skipped interceptors
|
|
1464
|
+
var requestInterceptorChain = [];
|
|
1465
|
+
var synchronousRequestInterceptors = true;
|
|
1466
|
+
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
|
1467
|
+
if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
|
|
1468
|
+
return;
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
|
1472
|
+
|
|
1473
|
+
requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
|
1474
|
+
});
|
|
1475
|
+
|
|
1476
|
+
var responseInterceptorChain = [];
|
|
1477
|
+
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
|
1478
|
+
responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
|
1479
|
+
});
|
|
1480
|
+
|
|
1481
|
+
var promise;
|
|
1482
|
+
|
|
1483
|
+
if (!synchronousRequestInterceptors) {
|
|
1484
|
+
var chain = [dispatchRequest, undefined];
|
|
1485
|
+
|
|
1486
|
+
Array.prototype.unshift.apply(chain, requestInterceptorChain);
|
|
1487
|
+
chain = chain.concat(responseInterceptorChain);
|
|
1488
|
+
|
|
1489
|
+
promise = Promise.resolve(config);
|
|
1490
|
+
while (chain.length) {
|
|
1491
|
+
promise = promise.then(chain.shift(), chain.shift());
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
return promise;
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
|
|
1498
|
+
var newConfig = config;
|
|
1499
|
+
while (requestInterceptorChain.length) {
|
|
1500
|
+
var onFulfilled = requestInterceptorChain.shift();
|
|
1501
|
+
var onRejected = requestInterceptorChain.shift();
|
|
1502
|
+
try {
|
|
1503
|
+
newConfig = onFulfilled(newConfig);
|
|
1504
|
+
} catch (error) {
|
|
1505
|
+
onRejected(error);
|
|
1506
|
+
break;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
try {
|
|
1511
|
+
promise = dispatchRequest(newConfig);
|
|
1512
|
+
} catch (error) {
|
|
1513
|
+
return Promise.reject(error);
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
while (responseInterceptorChain.length) {
|
|
1517
|
+
promise = promise.then(responseInterceptorChain.shift(), responseInterceptorChain.shift());
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
return promise;
|
|
1521
|
+
};
|
|
1522
|
+
|
|
1523
|
+
Axios.prototype.getUri = function getUri(config) {
|
|
1524
|
+
config = mergeConfig(this.defaults, config);
|
|
1525
|
+
return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
|
|
1526
|
+
};
|
|
1527
|
+
|
|
1528
|
+
// Provide aliases for supported request methods
|
|
1529
|
+
utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
|
|
1530
|
+
/*eslint func-names:0*/
|
|
1531
|
+
Axios.prototype[method] = function(url, config) {
|
|
1532
|
+
return this.request(mergeConfig(config || {}, {
|
|
1533
|
+
method: method,
|
|
1534
|
+
url: url,
|
|
1535
|
+
data: (config || {}).data
|
|
1536
|
+
}));
|
|
1537
|
+
};
|
|
1538
|
+
});
|
|
1539
|
+
|
|
1540
|
+
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
|
1541
|
+
/*eslint func-names:0*/
|
|
1542
|
+
Axios.prototype[method] = function(url, data, config) {
|
|
1543
|
+
return this.request(mergeConfig(config || {}, {
|
|
1544
|
+
method: method,
|
|
1545
|
+
url: url,
|
|
1546
|
+
data: data
|
|
1547
|
+
}));
|
|
1548
|
+
};
|
|
1549
|
+
});
|
|
1550
|
+
|
|
1551
|
+
var Axios_1 = Axios;
|
|
1552
|
+
|
|
1553
|
+
/**
|
|
1554
|
+
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
|
1555
|
+
*
|
|
1556
|
+
* @class
|
|
1557
|
+
* @param {Function} executor The executor function.
|
|
1558
|
+
*/
|
|
1559
|
+
function CancelToken(executor) {
|
|
1560
|
+
if (typeof executor !== 'function') {
|
|
1561
|
+
throw new TypeError('executor must be a function.');
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
var resolvePromise;
|
|
1565
|
+
|
|
1566
|
+
this.promise = new Promise(function promiseExecutor(resolve) {
|
|
1567
|
+
resolvePromise = resolve;
|
|
1568
|
+
});
|
|
1569
|
+
|
|
1570
|
+
var token = this;
|
|
1571
|
+
|
|
1572
|
+
// eslint-disable-next-line func-names
|
|
1573
|
+
this.promise.then(function(cancel) {
|
|
1574
|
+
if (!token._listeners) return;
|
|
1575
|
+
|
|
1576
|
+
var i;
|
|
1577
|
+
var l = token._listeners.length;
|
|
1578
|
+
|
|
1579
|
+
for (i = 0; i < l; i++) {
|
|
1580
|
+
token._listeners[i](cancel);
|
|
1581
|
+
}
|
|
1582
|
+
token._listeners = null;
|
|
1583
|
+
});
|
|
1584
|
+
|
|
1585
|
+
// eslint-disable-next-line func-names
|
|
1586
|
+
this.promise.then = function(onfulfilled) {
|
|
1587
|
+
var _resolve;
|
|
1588
|
+
// eslint-disable-next-line func-names
|
|
1589
|
+
var promise = new Promise(function(resolve) {
|
|
1590
|
+
token.subscribe(resolve);
|
|
1591
|
+
_resolve = resolve;
|
|
1592
|
+
}).then(onfulfilled);
|
|
1593
|
+
|
|
1594
|
+
promise.cancel = function reject() {
|
|
1595
|
+
token.unsubscribe(_resolve);
|
|
1596
|
+
};
|
|
1597
|
+
|
|
1598
|
+
return promise;
|
|
1599
|
+
};
|
|
1600
|
+
|
|
1601
|
+
executor(function cancel(message) {
|
|
1602
|
+
if (token.reason) {
|
|
1603
|
+
// Cancellation has already been requested
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
token.reason = new Cancel_1(message);
|
|
1608
|
+
resolvePromise(token.reason);
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
/**
|
|
1613
|
+
* Throws a `Cancel` if cancellation has been requested.
|
|
1614
|
+
*/
|
|
1615
|
+
CancelToken.prototype.throwIfRequested = function throwIfRequested() {
|
|
1616
|
+
if (this.reason) {
|
|
1617
|
+
throw this.reason;
|
|
1618
|
+
}
|
|
1619
|
+
};
|
|
1620
|
+
|
|
1621
|
+
/**
|
|
1622
|
+
* Subscribe to the cancel signal
|
|
1623
|
+
*/
|
|
1624
|
+
|
|
1625
|
+
CancelToken.prototype.subscribe = function subscribe(listener) {
|
|
1626
|
+
if (this.reason) {
|
|
1627
|
+
listener(this.reason);
|
|
1628
|
+
return;
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
if (this._listeners) {
|
|
1632
|
+
this._listeners.push(listener);
|
|
1633
|
+
} else {
|
|
1634
|
+
this._listeners = [listener];
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
|
|
1638
|
+
/**
|
|
1639
|
+
* Unsubscribe from the cancel signal
|
|
1640
|
+
*/
|
|
1641
|
+
|
|
1642
|
+
CancelToken.prototype.unsubscribe = function unsubscribe(listener) {
|
|
1643
|
+
if (!this._listeners) {
|
|
1644
|
+
return;
|
|
1645
|
+
}
|
|
1646
|
+
var index = this._listeners.indexOf(listener);
|
|
1647
|
+
if (index !== -1) {
|
|
1648
|
+
this._listeners.splice(index, 1);
|
|
1649
|
+
}
|
|
1650
|
+
};
|
|
1651
|
+
|
|
1652
|
+
/**
|
|
1653
|
+
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
|
1654
|
+
* cancels the `CancelToken`.
|
|
1655
|
+
*/
|
|
1656
|
+
CancelToken.source = function source() {
|
|
1657
|
+
var cancel;
|
|
1658
|
+
var token = new CancelToken(function executor(c) {
|
|
1659
|
+
cancel = c;
|
|
1660
|
+
});
|
|
1661
|
+
return {
|
|
1662
|
+
token: token,
|
|
1663
|
+
cancel: cancel
|
|
1664
|
+
};
|
|
1665
|
+
};
|
|
1666
|
+
|
|
1667
|
+
var CancelToken_1 = CancelToken;
|
|
1668
|
+
|
|
1669
|
+
/**
|
|
1670
|
+
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
|
1671
|
+
*
|
|
1672
|
+
* Common use case would be to use `Function.prototype.apply`.
|
|
1673
|
+
*
|
|
1674
|
+
* ```js
|
|
1675
|
+
* function f(x, y, z) {}
|
|
1676
|
+
* var args = [1, 2, 3];
|
|
1677
|
+
* f.apply(null, args);
|
|
1678
|
+
* ```
|
|
1679
|
+
*
|
|
1680
|
+
* With `spread` this example can be re-written.
|
|
1681
|
+
*
|
|
1682
|
+
* ```js
|
|
1683
|
+
* spread(function(x, y, z) {})([1, 2, 3]);
|
|
1684
|
+
* ```
|
|
1685
|
+
*
|
|
1686
|
+
* @param {Function} callback
|
|
1687
|
+
* @returns {Function}
|
|
1688
|
+
*/
|
|
1689
|
+
var spread = function spread(callback) {
|
|
1690
|
+
return function wrap(arr) {
|
|
1691
|
+
return callback.apply(null, arr);
|
|
1692
|
+
};
|
|
1693
|
+
};
|
|
1694
|
+
|
|
1695
|
+
/**
|
|
1696
|
+
* Determines whether the payload is an error thrown by Axios
|
|
1697
|
+
*
|
|
1698
|
+
* @param {*} payload The value to test
|
|
1699
|
+
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
|
1700
|
+
*/
|
|
1701
|
+
var isAxiosError = function isAxiosError(payload) {
|
|
1702
|
+
return (typeof payload === 'object') && (payload.isAxiosError === true);
|
|
1703
|
+
};
|
|
1704
|
+
|
|
1705
|
+
/**
|
|
1706
|
+
* Create an instance of Axios
|
|
1707
|
+
*
|
|
1708
|
+
* @param {Object} defaultConfig The default config for the instance
|
|
1709
|
+
* @return {Axios} A new instance of Axios
|
|
1710
|
+
*/
|
|
1711
|
+
function createInstance(defaultConfig) {
|
|
1712
|
+
var context = new Axios_1(defaultConfig);
|
|
1713
|
+
var instance = bind(Axios_1.prototype.request, context);
|
|
1714
|
+
|
|
1715
|
+
// Copy axios.prototype to instance
|
|
1716
|
+
utils.extend(instance, Axios_1.prototype, context);
|
|
1717
|
+
|
|
1718
|
+
// Copy context to instance
|
|
1719
|
+
utils.extend(instance, context);
|
|
1720
|
+
|
|
1721
|
+
// Factory for creating new instances
|
|
1722
|
+
instance.create = function create(instanceConfig) {
|
|
1723
|
+
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
|
1724
|
+
};
|
|
1725
|
+
|
|
1726
|
+
return instance;
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
// Create the default instance to be exported
|
|
1730
|
+
var axios$1 = createInstance(defaults_1);
|
|
1731
|
+
|
|
1732
|
+
// Expose Axios class to allow class inheritance
|
|
1733
|
+
axios$1.Axios = Axios_1;
|
|
1734
|
+
|
|
1735
|
+
// Expose Cancel & CancelToken
|
|
1736
|
+
axios$1.Cancel = Cancel_1;
|
|
1737
|
+
axios$1.CancelToken = CancelToken_1;
|
|
1738
|
+
axios$1.isCancel = isCancel;
|
|
1739
|
+
axios$1.VERSION = data$1.version;
|
|
1740
|
+
|
|
1741
|
+
// Expose all/spread
|
|
1742
|
+
axios$1.all = function all(promises) {
|
|
1743
|
+
return Promise.all(promises);
|
|
1744
|
+
};
|
|
1745
|
+
axios$1.spread = spread;
|
|
1746
|
+
|
|
1747
|
+
// Expose isAxiosError
|
|
1748
|
+
axios$1.isAxiosError = isAxiosError;
|
|
1749
|
+
|
|
1750
|
+
var axios_1 = axios$1;
|
|
1751
|
+
|
|
1752
|
+
// Allow use of default import syntax in TypeScript
|
|
1753
|
+
var _default = axios$1;
|
|
1754
|
+
axios_1.default = _default;
|
|
1755
|
+
|
|
1756
|
+
var axios = axios_1;
|
|
1757
|
+
|
|
1758
|
+
const Http = {
|
|
1759
|
+
request(method, url, data, successCb = null, errorCb = null) {
|
|
1760
|
+
return axios
|
|
1761
|
+
.request({url, data, method: method.toLowerCase(), responseType: 'json'})
|
|
1762
|
+
.then(successCb)
|
|
1763
|
+
.catch(errorCb);
|
|
1764
|
+
},
|
|
1765
|
+
|
|
1766
|
+
get(url, successCb = null, errorCb = null, data) {
|
|
1767
|
+
// return this.request('get', url, data, successCb, errorCb);
|
|
1768
|
+
return axios
|
|
1769
|
+
.get(url, {params: data})
|
|
1770
|
+
.then(successCb)
|
|
1771
|
+
.catch(errorCb);
|
|
1772
|
+
},
|
|
1773
|
+
|
|
1774
|
+
post(url, data, successCb = null, errorCb = null) {
|
|
1775
|
+
return this.request('post', url, data, successCb, errorCb);
|
|
1776
|
+
},
|
|
1777
|
+
|
|
1778
|
+
put(url, data, successCb = null, errorCb = null) {
|
|
1779
|
+
return this.request('put', url, data, successCb, errorCb);
|
|
1780
|
+
},
|
|
1781
|
+
|
|
1782
|
+
delete(url, data, successCb = null, errorCb = null) {
|
|
1783
|
+
return this.request('delete', url, data, successCb, errorCb);
|
|
1784
|
+
},
|
|
1785
|
+
|
|
1786
|
+
requestWithSupportAjax(url, payload, method = 'post') {
|
|
1787
|
+
return new Promise((resolve, reject) => {
|
|
1788
|
+
if (!window?.isLegacyTheme) {
|
|
1789
|
+
return this.request(method, url, payload, ({data}) => {
|
|
1790
|
+
return resolve(data);
|
|
1791
|
+
}, ({response}) => {
|
|
1792
|
+
return reject(response);
|
|
1793
|
+
})
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
/**
|
|
1797
|
+
* @deprecated to support legacy themes
|
|
1798
|
+
*/
|
|
1799
|
+
$.ajax({
|
|
1800
|
+
url: url,
|
|
1801
|
+
method: method.toUpperCase(),
|
|
1802
|
+
data: payload,
|
|
1803
|
+
async: false,
|
|
1804
|
+
success: function ({data}) {
|
|
1805
|
+
return resolve(data);
|
|
1806
|
+
},
|
|
1807
|
+
error: function ({response}) {
|
|
1808
|
+
return reject(response);
|
|
1809
|
+
}
|
|
1810
|
+
});
|
|
1811
|
+
})
|
|
1812
|
+
}
|
|
1813
|
+
};
|
|
1814
|
+
|
|
1815
|
+
const DetectOS = {
|
|
1816
|
+
options: [],
|
|
1817
|
+
header: [navigator.platform, navigator.userAgent, navigator.appVersion, navigator.vendor, window.opera],
|
|
1818
|
+
dataos: [
|
|
1819
|
+
{name: 'Windows Phone', value: 'Windows Phone', version: 'OS'},
|
|
1820
|
+
{name: 'Windows', value: 'Win', version: 'NT'},
|
|
1821
|
+
{name: 'iPhone', value: 'iPhone', version: 'OS'},
|
|
1822
|
+
{name: 'iPad', value: 'iPad', version: 'OS'},
|
|
1823
|
+
{name: 'Kindle', value: 'Silk', version: 'Silk'},
|
|
1824
|
+
{name: 'Android', value: 'Android', version: 'Android'},
|
|
1825
|
+
{name: 'PlayBook', value: 'PlayBook', version: 'OS'},
|
|
1826
|
+
{name: 'BlackBerry', value: 'BlackBerry', version: '/'},
|
|
1827
|
+
{name: 'Macintosh', value: 'Mac', version: 'OS X'},
|
|
1828
|
+
{name: 'Linux', value: 'Linux', version: 'rv'},
|
|
1829
|
+
{name: 'Palm', value: 'Palm', version: 'PalmOS'}
|
|
1830
|
+
],
|
|
1831
|
+
databrowser: [
|
|
1832
|
+
{name: 'Chrome', value: 'Chrome', version: 'Chrome'},
|
|
1833
|
+
{name: 'Firefox', value: 'Firefox', version: 'Firefox'},
|
|
1834
|
+
{name: 'Safari', value: 'Safari', version: 'Version'},
|
|
1835
|
+
{name: 'Internet Explorer', value: 'MSIE', version: 'MSIE'},
|
|
1836
|
+
{name: 'Opera', value: 'Opera', version: 'Opera'},
|
|
1837
|
+
{name: 'BlackBerry', value: 'CLDC', version: 'CLDC'},
|
|
1838
|
+
{name: 'Mozilla', value: 'Mozilla', version: 'Mozilla'}
|
|
1839
|
+
],
|
|
1840
|
+
init: function () {
|
|
1841
|
+
var agent = this.header.join(' '),
|
|
1842
|
+
os = this.matchItem(agent, this.dataos),
|
|
1843
|
+
browser = this.matchItem(agent, this.databrowser);
|
|
1844
|
+
|
|
1845
|
+
return {os: os, browser: browser};
|
|
1846
|
+
},
|
|
1847
|
+
matchItem: function (string, data) {
|
|
1848
|
+
var i = 0,
|
|
1849
|
+
j = 0,
|
|
1850
|
+
regex,
|
|
1851
|
+
regexv,
|
|
1852
|
+
match,
|
|
1853
|
+
matches,
|
|
1854
|
+
version;
|
|
1855
|
+
|
|
1856
|
+
for (i = 0; i < data.length; i += 1) {
|
|
1857
|
+
regex = new RegExp(data[i].value, 'i');
|
|
1858
|
+
match = regex.test(string);
|
|
1859
|
+
if (match) {
|
|
1860
|
+
regexv = new RegExp(data[i].version + '[- /:;]([\\d._]+)', 'i');
|
|
1861
|
+
matches = string.match(regexv);
|
|
1862
|
+
version = '';
|
|
1863
|
+
if (matches) {
|
|
1864
|
+
if (matches[1]) {
|
|
1865
|
+
matches = matches[1];
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
if (matches) {
|
|
1869
|
+
matches = matches.split(/[._]+/);
|
|
1870
|
+
for (j = 0; j < matches.length; j += 1) {
|
|
1871
|
+
if (j === 0) {
|
|
1872
|
+
version += matches[j] + '.';
|
|
1873
|
+
} else {
|
|
1874
|
+
version += matches[j];
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
} else {
|
|
1878
|
+
version = '0';
|
|
1879
|
+
}
|
|
1880
|
+
return {
|
|
1881
|
+
name: data[i].name,
|
|
1882
|
+
version: parseFloat(version)
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
return {name: 'unknown', version: 0};
|
|
1887
|
+
}
|
|
1888
|
+
};
|
|
1889
|
+
|
|
1890
|
+
window.Salla = window.Salla || {};
|
|
1891
|
+
window.Salla.Payments = window.Salla.Payments || {};
|
|
1892
|
+
|
|
1893
|
+
/**
|
|
1894
|
+
* Full Example
|
|
1895
|
+
*
|
|
1896
|
+
* Salla.event.createAndDispatch('payments::apple-pay.start-transaction', {
|
|
1897
|
+
* amount: 1000,
|
|
1898
|
+
* validateMerchant: {
|
|
1899
|
+
* url: '{{ route('cp.marketplace.cart.pay', ['cart' => $cart]) }}',
|
|
1900
|
+
* // onFailed: (response) => {
|
|
1901
|
+
* // laravel.ajax.errorHandler(response);
|
|
1902
|
+
* // this.onCancel({}, response.data.error.message);
|
|
1903
|
+
* // },
|
|
1904
|
+
* // onSuccess: (response) => {
|
|
1905
|
+
* // laravel.ajax.successHandler(response);
|
|
1906
|
+
* // }
|
|
1907
|
+
* },
|
|
1908
|
+
* authorized: {
|
|
1909
|
+
* url: '{{ route('cp.marketplace.cart.confirm', ['cart' => $cart]) }}',
|
|
1910
|
+
* // onFailed: (response) => {
|
|
1911
|
+
* // laravel.ajax.errorHandler(response);
|
|
1912
|
+
* // this.onCancel({}, response.data.error.message);
|
|
1913
|
+
* // },
|
|
1914
|
+
* // onSuccess: (response) => {
|
|
1915
|
+
* // // nothing
|
|
1916
|
+
* // }
|
|
1917
|
+
* },
|
|
1918
|
+
* // onError: function (message) {
|
|
1919
|
+
* // laravel.alert(message);
|
|
1920
|
+
* // }
|
|
1921
|
+
* });
|
|
1922
|
+
*/
|
|
1923
|
+
window.SallaApplePay = {
|
|
1924
|
+
session: null,
|
|
1925
|
+
detail: null,
|
|
1926
|
+
address_id: null,
|
|
1927
|
+
shipping_methods: [],
|
|
1928
|
+
total: undefined,
|
|
1929
|
+
request: undefined,
|
|
1930
|
+
id: undefined,
|
|
1931
|
+
init: function () {
|
|
1932
|
+
document.removeEventListener('payments::apple-pay.start-transaction', SallaApplePay.startSession);
|
|
1933
|
+
Salla.event.addEventListener('payments::apple-pay.start-transaction', SallaApplePay.startSession);
|
|
1934
|
+
},
|
|
1935
|
+
|
|
1936
|
+
initDefault: function () {
|
|
1937
|
+
if (!SallaApplePay.detail.onError) {
|
|
1938
|
+
SallaApplePay.detail.onError = function (message) {
|
|
1939
|
+
salla.notify.error(message);
|
|
1940
|
+
};
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
if (!SallaApplePay.detail.authorized.onFailed) {
|
|
1944
|
+
SallaApplePay.detail.authorized.onFailed = (response) => {
|
|
1945
|
+
salla.logger.log(JSON.stringify(response));
|
|
1946
|
+
salla.api.handleErrorResponse(response);
|
|
1947
|
+
SallaApplePay.onCancel({}, response.data.error.message);
|
|
1948
|
+
};
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
if (!SallaApplePay.detail.validateMerchant.onFailed) {
|
|
1952
|
+
SallaApplePay.detail.validateMerchant.onFailed = (response) => {
|
|
1953
|
+
salla.logger.log(JSON.stringify(response));
|
|
1954
|
+
salla.api.handleErrorResponse(response);
|
|
1955
|
+
SallaApplePay.onCancel({}, response.data.error.message);
|
|
1956
|
+
};
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
if (!SallaApplePay.detail.authorized.onSuccess) {
|
|
1960
|
+
SallaApplePay.detail.authorized.onSuccess = (response) => {
|
|
1961
|
+
salla.logger.log(JSON.stringify(response));
|
|
1962
|
+
salla.api.handleAfterResponseActions(response);
|
|
1963
|
+
};
|
|
1964
|
+
}
|
|
1965
|
+
},
|
|
1966
|
+
|
|
1967
|
+
prepareLineItems: function () {
|
|
1968
|
+
if(!SallaApplePay.detail?.items?.length){
|
|
1969
|
+
SallaApplePay.detail.items = [
|
|
1970
|
+
{
|
|
1971
|
+
label: salla.lang.get('pages.cart.items_total'),
|
|
1972
|
+
amount: SallaApplePay.detail.amount
|
|
1973
|
+
}
|
|
1974
|
+
];
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
return SallaApplePay.detail.items;
|
|
1978
|
+
},
|
|
1979
|
+
|
|
1980
|
+
prepareTotal: function () {
|
|
1981
|
+
return {
|
|
1982
|
+
// apple ask to use business name
|
|
1983
|
+
label: window.location.hostname || 'Salla',
|
|
1984
|
+
//label: salla.lang.get('pages.cart.final_total'),
|
|
1985
|
+
amount: SallaApplePay.detail.amount
|
|
1986
|
+
}
|
|
1987
|
+
},
|
|
1988
|
+
|
|
1989
|
+
startSession: async function (event) {
|
|
1990
|
+
|
|
1991
|
+
SallaApplePay.detail = event.detail || event;
|
|
1992
|
+
|
|
1993
|
+
salla.log('🍏 Pay: payments::apple-pay.start-transaction', SallaApplePay.detail);
|
|
1994
|
+
|
|
1995
|
+
SallaApplePay.initDefault();
|
|
1996
|
+
|
|
1997
|
+
let version = SallaApplePay.getApplePaySessionVersion();
|
|
1998
|
+
let supportedNetworks = SallaApplePay.detail.supportedNetworks || ['masterCard', 'visa'];
|
|
1999
|
+
|
|
2000
|
+
if (version === 5) {
|
|
2001
|
+
supportedNetworks.push('mada');
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
SallaApplePay.request = {
|
|
2005
|
+
countryCode: 'SA',
|
|
2006
|
+
supportsCouponCode: true,
|
|
2007
|
+
couponCode: '',
|
|
2008
|
+
currencyCode: SallaApplePay.detail.currency || 'SAR',
|
|
2009
|
+
requiredShippingContactFields: SallaApplePay.detail.requiredShippingContactFields ? SallaApplePay.detail.requiredShippingContactFields : [],
|
|
2010
|
+
merchantCapabilities: ['supports3DS'],
|
|
2011
|
+
supportedNetworks: supportedNetworks,
|
|
2012
|
+
supportedCountries: SallaApplePay.detail.supportedCountries || ['SA'],
|
|
2013
|
+
total: SallaApplePay.prepareTotal(),
|
|
2014
|
+
shippingContact: SallaApplePay.detail.shippingContact ? SallaApplePay.detail.shippingContact : {},
|
|
2015
|
+
shippingMethods: SallaApplePay.detail.shippingMethods && SallaApplePay.detail.shippingMethods.length ? SallaApplePay.mappingShippingMethods(event.detail.shippingMethods) : [],
|
|
2016
|
+
lineItems: SallaApplePay.prepareLineItems()
|
|
2017
|
+
};
|
|
2018
|
+
|
|
2019
|
+
salla.log('🍏 Pay: init ', SallaApplePay.request);
|
|
2020
|
+
|
|
2021
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypaymentrequest
|
|
2022
|
+
SallaApplePay.session = new ApplePaySession(version, SallaApplePay.request);
|
|
2023
|
+
|
|
2024
|
+
SallaApplePay.session.onshippingcontactselected = SallaApplePay.onShippingContactSelected;
|
|
2025
|
+
SallaApplePay.session.onshippingmethodselected = SallaApplePay.onShippingMethodSelected;
|
|
2026
|
+
SallaApplePay.session.onvalidatemerchant = SallaApplePay.onValidateMerchant;
|
|
2027
|
+
SallaApplePay.session.onpaymentauthorized = SallaApplePay.onPaymentAuthorized;
|
|
2028
|
+
SallaApplePay.session.oncancel = SallaApplePay.onCancel;
|
|
2029
|
+
SallaApplePay.session.oncouponcodechanged = SallaApplePay.oncouponcodechanged;
|
|
2030
|
+
|
|
2031
|
+
SallaApplePay.session.begin();
|
|
2032
|
+
},
|
|
2033
|
+
|
|
2034
|
+
oncouponcodechanged(event) {
|
|
2035
|
+
Salla.event.dispatch('payments::apple-pay.coupon.change', event);
|
|
2036
|
+
|
|
2037
|
+
return Http.post(SallaApplePay.detail.oncouponcodechanged.url.replace('{id}', SallaApplePay.id), {
|
|
2038
|
+
'coupon': event.couponCode,
|
|
2039
|
+
'payment_method': 'apple_pay',
|
|
2040
|
+
}, async ({data}) => {
|
|
2041
|
+
if (typeof SallaApplePay.detail.oncouponcodechanged.onSuccess === 'function') {
|
|
2042
|
+
SallaApplePay.detail.oncouponcodechanged.onSuccess(data);
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
salla.log('🍏 Pay: Coupon applied success');
|
|
2046
|
+
|
|
2047
|
+
await SallaApplePay.recalculateTotal();
|
|
2048
|
+
|
|
2049
|
+
SallaApplePay.session.completeCouponCodeChange({
|
|
2050
|
+
newTotal: SallaApplePay.prepareTotal(),
|
|
2051
|
+
newLineItems: SallaApplePay.prepareLineItems()
|
|
2052
|
+
});
|
|
2053
|
+
}, async (error) => {
|
|
2054
|
+
let response = error?.response;
|
|
2055
|
+
|
|
2056
|
+
Salla.event.dispatch('payments::apple-pay.coupon.failed', response);
|
|
2057
|
+
|
|
2058
|
+
// SallaApplePay.abortSession();
|
|
2059
|
+
if (typeof SallaApplePay.detail.oncouponcodechanged.onFailed === 'function') {
|
|
2060
|
+
SallaApplePay.detail.oncouponcodechanged.onFailed(response);
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
await SallaApplePay.recalculateTotal();
|
|
2064
|
+
|
|
2065
|
+
SallaApplePay.session.completeCouponCodeChange({
|
|
2066
|
+
newTotal: SallaApplePay.prepareTotal(),
|
|
2067
|
+
newLineItems: SallaApplePay.prepareLineItems(),
|
|
2068
|
+
errors: [new window.ApplePayError('couponCodeInvalid')]
|
|
2069
|
+
});
|
|
2070
|
+
});
|
|
2071
|
+
},
|
|
2072
|
+
|
|
2073
|
+
onCancel: (event = {}, message = null) => {
|
|
2074
|
+
SallaApplePay.detail.onError(message || salla.lang.get('pages.checkout.payment_failed'));
|
|
2075
|
+
Salla.event.createAndDispatch('payments::apple-pay.canceled', event);
|
|
2076
|
+
},
|
|
2077
|
+
|
|
2078
|
+
/**
|
|
2079
|
+
* Confirm payment after authorization.
|
|
2080
|
+
*
|
|
2081
|
+
* @param event
|
|
2082
|
+
*/
|
|
2083
|
+
onPaymentAuthorized: (event) => {
|
|
2084
|
+
salla.logger.log('🍏 Pay: onPaymentAuthorized', event.payment);
|
|
2085
|
+
|
|
2086
|
+
Salla.event.dispatch('payments::apple-pay.authorized.init', event);
|
|
2087
|
+
Http.post(SallaApplePay.detail.authorized.url.replace('{id}', SallaApplePay.id), {
|
|
2088
|
+
payment_method: 'apple_pay',
|
|
2089
|
+
applepay_token: JSON.stringify(event.payment)
|
|
2090
|
+
}, ({data}) => {
|
|
2091
|
+
Salla.event.dispatch('payments::apple-pay.authorized.success', data);
|
|
2092
|
+
|
|
2093
|
+
SallaApplePay.session.completePayment(ApplePaySession.STATUS_SUCCESS);
|
|
2094
|
+
|
|
2095
|
+
if (typeof SallaApplePay.detail.authorized.onSuccess === 'function') {
|
|
2096
|
+
SallaApplePay.detail.authorized.onSuccess(data);
|
|
2097
|
+
}
|
|
2098
|
+
}, (error) => {
|
|
2099
|
+
|
|
2100
|
+
let response = error?.response;
|
|
2101
|
+
|
|
2102
|
+
Salla.event.dispatch('payments::apple-pay.authorized.failed', response);
|
|
2103
|
+
|
|
2104
|
+
SallaApplePay.session.completePayment({
|
|
2105
|
+
status: ApplePaySession.STATUS_FAILURE,
|
|
2106
|
+
errors: [new ApplePayError("unknown", undefined, response?.data?.error?.message || response?.data?.error?.code || 'Failed to parse authorized response')]
|
|
2107
|
+
});
|
|
2108
|
+
|
|
2109
|
+
if (typeof SallaApplePay.detail.authorized.onFailed === 'function') {
|
|
2110
|
+
SallaApplePay.detail.authorized.onFailed(response);
|
|
2111
|
+
}
|
|
2112
|
+
});
|
|
2113
|
+
},
|
|
2114
|
+
|
|
2115
|
+
/**
|
|
2116
|
+
* Validate Submit.
|
|
2117
|
+
*
|
|
2118
|
+
* @param event
|
|
2119
|
+
*/
|
|
2120
|
+
onValidateMerchant: (event) => {
|
|
2121
|
+
Salla.event.dispatch('payments::apple-pay.validate-merchant.init', event);
|
|
2122
|
+
|
|
2123
|
+
Http.post(SallaApplePay.detail.validateMerchant.url.replace('{id}', SallaApplePay.id), {
|
|
2124
|
+
validation_url: event.validationURL
|
|
2125
|
+
}, ({data}) => {
|
|
2126
|
+
|
|
2127
|
+
Salla.event.dispatch('payments::apple-pay.validate-merchant.success', data);
|
|
2128
|
+
|
|
2129
|
+
if (typeof SallaApplePay.detail.validateMerchant.onSuccess === 'function') {
|
|
2130
|
+
SallaApplePay.detail.validateMerchant.onSuccess(data).then((response) => {
|
|
2131
|
+
// check if there are redirect
|
|
2132
|
+
if (response?.redirect) {
|
|
2133
|
+
window.location = response.redirect;
|
|
2134
|
+
return SallaApplePay.abortValidateMerchant(response);
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2137
|
+
SallaApplePay.session.completeMerchantValidation(data.data);
|
|
2138
|
+
}).catch((response) => {
|
|
2139
|
+
SallaApplePay.abortValidateMerchant(response);
|
|
2140
|
+
});
|
|
2141
|
+
} else {
|
|
2142
|
+
SallaApplePay.session.completeMerchantValidation(data.data);
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
}, ({response}) => {
|
|
2146
|
+
SallaApplePay.abortValidateMerchant(response);
|
|
2147
|
+
});
|
|
2148
|
+
},
|
|
2149
|
+
|
|
2150
|
+
abortValidateMerchant: (response = null) => {
|
|
2151
|
+
|
|
2152
|
+
SallaApplePay.abortSession();
|
|
2153
|
+
Salla.event.dispatch('payments::apple-pay.validate-merchant.failed', response);
|
|
2154
|
+
|
|
2155
|
+
if (typeof SallaApplePay.detail.validateMerchant.onFailed === 'function') {
|
|
2156
|
+
SallaApplePay.detail.validateMerchant.onFailed(response);
|
|
2157
|
+
}
|
|
2158
|
+
},
|
|
2159
|
+
|
|
2160
|
+
/**
|
|
2161
|
+
* Select Shipping Contact
|
|
2162
|
+
*
|
|
2163
|
+
* @param event
|
|
2164
|
+
*/
|
|
2165
|
+
onShippingContactSelected: async (event) => {
|
|
2166
|
+
salla.logger.log('🍏 Pay: onShippingContactSelected', event.shippingContact);
|
|
2167
|
+
|
|
2168
|
+
if (!SallaApplePay.detail.requiredShippingContactFields) {
|
|
2169
|
+
return;
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
// Create New Address
|
|
2173
|
+
return Http.post(SallaApplePay.detail.shippingContactSelected.url.replace('{id}', SallaApplePay.id),
|
|
2174
|
+
{
|
|
2175
|
+
'country': event.shippingContact.country,
|
|
2176
|
+
'city': event.shippingContact.locality,
|
|
2177
|
+
'local': event.shippingContact.subLocality,
|
|
2178
|
+
'description': event.shippingContact.subAdministrativeArea,
|
|
2179
|
+
'street': event.shippingContact.administrativeArea,
|
|
2180
|
+
'country_code': event.shippingContact.countryCode,
|
|
2181
|
+
'postal_code': event.shippingContact.postalCode
|
|
2182
|
+
},
|
|
2183
|
+
async ({data}) => {
|
|
2184
|
+
if (typeof SallaApplePay.detail.shippingContactSelected.onSuccess === 'function') {
|
|
2185
|
+
SallaApplePay.detail.shippingContactSelected.onSuccess(data);
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
SallaApplePay.address_id = data.data.address_id;
|
|
2189
|
+
SallaApplePay.shipping_methods = data.data.shipping_methods;
|
|
2190
|
+
|
|
2191
|
+
if (!SallaApplePay.shipping_methods || (SallaApplePay.shipping_methods && !SallaApplePay.shipping_methods.length)) {
|
|
2192
|
+
salla.logger.warn('🍏 Pay: We dont found any supported methods', data);
|
|
2193
|
+
|
|
2194
|
+
return SallaApplePay.session.completeShippingContactSelection({
|
|
2195
|
+
status: SallaApplePay.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,
|
|
2196
|
+
errors: [
|
|
2197
|
+
new window.ApplePayError('addressUnserviceable')
|
|
2198
|
+
]
|
|
2199
|
+
});
|
|
2200
|
+
}
|
|
2201
|
+
|
|
2202
|
+
try {
|
|
2203
|
+
await SallaApplePay.selectApplePayShippingMethod(SallaApplePay.shipping_methods[0]['ship_id'], SallaApplePay.shipping_methods[0]['private_ship_id']);
|
|
2204
|
+
} catch (error) {
|
|
2205
|
+
salla.logger.warn('Failed set the shipping details to api', error);
|
|
2206
|
+
|
|
2207
|
+
return SallaApplePay.session.completeShippingContactSelection({
|
|
2208
|
+
status: SallaApplePay.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,
|
|
2209
|
+
errors: [
|
|
2210
|
+
new window.ApplePayError('addressUnserviceable')
|
|
2211
|
+
]
|
|
2212
|
+
});
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2215
|
+
try {
|
|
2216
|
+
await SallaApplePay.recalculateTotal();
|
|
2217
|
+
} catch (error) {
|
|
2218
|
+
salla.logger.warn('🍏 Pay: Failed recalculate total', error);
|
|
2219
|
+
|
|
2220
|
+
return SallaApplePay.session.completeShippingContactSelection({
|
|
2221
|
+
status: SallaApplePay.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,
|
|
2222
|
+
errors: [
|
|
2223
|
+
new window.ApplePayError('addressUnserviceable')
|
|
2224
|
+
]
|
|
2225
|
+
});
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
SallaApplePay.session.completeShippingContactSelection({
|
|
2229
|
+
newTotal: SallaApplePay.prepareTotal(),
|
|
2230
|
+
newLineItems: SallaApplePay.prepareLineItems(),
|
|
2231
|
+
newShippingMethods: SallaApplePay.mappingShippingMethods(SallaApplePay.shipping_methods)
|
|
2232
|
+
});
|
|
2233
|
+
|
|
2234
|
+
}, ({response}) => {
|
|
2235
|
+
salla.logger.warn('🍏 Pay: Failed add address via api', response);
|
|
2236
|
+
|
|
2237
|
+
if (typeof SallaApplePay.detail.shippingContactSelected.onFailed === 'function') {
|
|
2238
|
+
SallaApplePay.detail.shippingContactSelected.onFailed(response);
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
// parse 422 errors
|
|
2242
|
+
let fields = response?.data?.error?.fields;
|
|
2243
|
+
|
|
2244
|
+
let errors = [];
|
|
2245
|
+
|
|
2246
|
+
if (fields?.country_code) {
|
|
2247
|
+
errors.push(new window.ApplePayError('shippingContactInvalid', 'countryCode', fields?.country_code[0]));
|
|
2248
|
+
}
|
|
2249
|
+
|
|
2250
|
+
if (fields?.city) {
|
|
2251
|
+
errors.push(new window.ApplePayError('shippingContactInvalid', 'locality', fields?.city[0]));
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
if (fields?.country) {
|
|
2255
|
+
errors.push(new window.ApplePayError('shippingContactInvalid', 'country', fields?.country[0]));
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
if (errors.length === 0 && response?.data?.error?.message) {
|
|
2259
|
+
errors.push(new window.ApplePayError('shippingContactInvalid', 'locality', response?.data?.error?.message));
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2262
|
+
SallaApplePay.session.completeShippingContactSelection({
|
|
2263
|
+
newTotal: SallaApplePay.prepareTotal(),
|
|
2264
|
+
newLineItems: SallaApplePay.prepareLineItems(),
|
|
2265
|
+
status: SallaApplePay.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,
|
|
2266
|
+
errors: errors
|
|
2267
|
+
});
|
|
2268
|
+
});
|
|
2269
|
+
},
|
|
2270
|
+
|
|
2271
|
+
/**
|
|
2272
|
+
* Select Shipping Method
|
|
2273
|
+
*
|
|
2274
|
+
* @param event
|
|
2275
|
+
*
|
|
2276
|
+
*/
|
|
2277
|
+
onShippingMethodSelected: async (event) => {
|
|
2278
|
+
salla.logger.log(event);
|
|
2279
|
+
|
|
2280
|
+
let shipping_ids = event.shippingMethod.identifier.split(',');
|
|
2281
|
+
|
|
2282
|
+
try {
|
|
2283
|
+
await SallaApplePay.selectApplePayShippingMethod(shipping_ids[0], typeof shipping_ids[1] === 'undefined' ? null : shipping_ids[1]);
|
|
2284
|
+
|
|
2285
|
+
await SallaApplePay.recalculateTotal();
|
|
2286
|
+
|
|
2287
|
+
SallaApplePay.session.completeShippingMethodSelection({
|
|
2288
|
+
newTotal: SallaApplePay.prepareTotal(),
|
|
2289
|
+
newLineItems: SallaApplePay.prepareLineItems(),
|
|
2290
|
+
});
|
|
2291
|
+
} catch (error) {
|
|
2292
|
+
salla.logger.warn('🍏 Pay: Failed set the shipping details to api', error);
|
|
2293
|
+
|
|
2294
|
+
// todo :: find a better handling for error without abort session
|
|
2295
|
+
SallaApplePay.abortSession();
|
|
2296
|
+
}
|
|
2297
|
+
},
|
|
2298
|
+
|
|
2299
|
+
|
|
2300
|
+
abortSession: () => {
|
|
2301
|
+
if (SallaApplePay.session) {
|
|
2302
|
+
SallaApplePay.session.abort();
|
|
2303
|
+
}
|
|
2304
|
+
},
|
|
2305
|
+
|
|
2306
|
+
getApplePaySessionVersion: () => {
|
|
2307
|
+
const userAgent = navigator.userAgent || navigator.vendor || window.opera;
|
|
2308
|
+
|
|
2309
|
+
if (userAgent === 'sallapp') {
|
|
2310
|
+
return 5;
|
|
2311
|
+
}
|
|
2312
|
+
|
|
2313
|
+
// can't handle custom user agent like sallapp
|
|
2314
|
+
let detection = DetectOS.init();
|
|
2315
|
+
let v = parseFloat(detection.os.version);
|
|
2316
|
+
|
|
2317
|
+
if (detection.os.name === 'Macintosh') {
|
|
2318
|
+
if (v < 10.142) {
|
|
2319
|
+
return 1;
|
|
2320
|
+
}
|
|
2321
|
+
} else {
|
|
2322
|
+
if (v < 12.11) {
|
|
2323
|
+
return 1;
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
return 5;
|
|
2328
|
+
},
|
|
2329
|
+
|
|
2330
|
+
recalculateTotal: () => {
|
|
2331
|
+
salla.logger.log('Recalculate Total');
|
|
2332
|
+
|
|
2333
|
+
return Http.requestWithSupportAjax(SallaApplePay.detail.recalculateTotal.url.replace('{id}', SallaApplePay.id),{}, 'get').then((data) => {
|
|
2334
|
+
console.log(data);
|
|
2335
|
+
// todo :: enhance response from backend
|
|
2336
|
+
SallaApplePay.detail.amount = data.data.initial_data.cart.total;
|
|
2337
|
+
SallaApplePay.detail.items = data.data.initial_data.cart.items.map((item) => {
|
|
2338
|
+
return {
|
|
2339
|
+
label: item.title,
|
|
2340
|
+
amount: item.amount === 'مجاني' ? 0 : item.amount.toString().replace('+', ''),
|
|
2341
|
+
};
|
|
2342
|
+
});
|
|
2343
|
+
|
|
2344
|
+
// lets remove last element (final total)
|
|
2345
|
+
SallaApplePay.detail.items.pop();
|
|
2346
|
+
|
|
2347
|
+
return data;
|
|
2348
|
+
}).catch((error) => {
|
|
2349
|
+
salla.logger.warn('🍏 Pay: recalculate total failed', error);
|
|
2350
|
+
|
|
2351
|
+
// general error
|
|
2352
|
+
return error?.response?.data?.message;
|
|
2353
|
+
});
|
|
2354
|
+
},
|
|
2355
|
+
|
|
2356
|
+
|
|
2357
|
+
selectApplePayShippingMethod: (company_id, private_company_id) => {
|
|
2358
|
+
salla.logger.log('🍏 Pay: select shipping method ', 'company_id : ' + company_id, 'private_company_id: ' + private_company_id);
|
|
2359
|
+
|
|
2360
|
+
return Http.requestWithSupportAjax(SallaApplePay.detail.shippingMethodSelected.url.replace('{id}', SallaApplePay.id), {
|
|
2361
|
+
address_id: SallaApplePay.address_id,
|
|
2362
|
+
company_id: company_id,
|
|
2363
|
+
private_company_id: private_company_id,
|
|
2364
|
+
payment_method: 'apple_pay'
|
|
2365
|
+
}, 'post').then(() => {
|
|
2366
|
+
if (typeof SallaApplePay.detail. shippingMethodSelected.onSuccess === 'function') {
|
|
2367
|
+
SallaApplePay.detail.shippingMethodSelected.onSuccess(data);
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
// we don't have any data in this request, lets resolve the promise
|
|
2371
|
+
return true;
|
|
2372
|
+
}).catch((error) => {
|
|
2373
|
+
salla.logger.warn('🍏 Pay: Set shipping method failed', error);
|
|
2374
|
+
|
|
2375
|
+
if (typeof SallaApplePay.detail.shippingMethodSelected.onFailed === 'function') {
|
|
2376
|
+
SallaApplePay.detail.shippingMethodSelected.onFailed(error);
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2379
|
+
// parse 422 errors
|
|
2380
|
+
let response = error?.response?.data?.error;
|
|
2381
|
+
|
|
2382
|
+
// address id is not valid
|
|
2383
|
+
if (response?.data?.fields?.address_id) {
|
|
2384
|
+
return response?.data?.fields?.address_id[0];
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2387
|
+
// general error
|
|
2388
|
+
return response?.data?.message;
|
|
2389
|
+
});
|
|
2390
|
+
},
|
|
2391
|
+
mappingShippingMethods: methods => methods.map(method => ({
|
|
2392
|
+
'label': method.shipping_title,
|
|
2393
|
+
'amount': method.enable_free_shipping ? 0 : method.ship_cost,
|
|
2394
|
+
'detail': '',
|
|
2395
|
+
'identifier': method.ship_id.toString() + (method.private_ship_id ? ',' + method.private_ship_id.toString() : '')
|
|
2396
|
+
}))
|
|
2397
|
+
};
|
|
2398
|
+
|
|
2399
|
+
if (window.ApplePaySession && ApplePaySession.canMakePayments()) {
|
|
2400
|
+
SallaApplePay.init();
|
|
2401
|
+
} else {
|
|
2402
|
+
// You can hide the Apple Pay button easy with add data-show-if-apple-pay-supported to element like <div data-show-if-apple-pay-supported>
|
|
2403
|
+
document.querySelectorAll('data-show-if-apple-pay-supported').forEach(element => element.style.display = 'none');
|
|
2404
|
+
}
|
|
2405
|
+
|
|
2406
|
+
const sallaQuickBuyCss = ".s-quick-buy-button .s-button-text{display:-ms-flexbox;display:flex}apple-pay-button{--apple-pay-button-width:100%;--apple-pay-button-height:40px;--apple-pay-button-border-radius:7px;--apple-pay-button-padding:0px 5px;--apple-pay-button-box-sizing:content-box}";
|
|
2407
|
+
|
|
2408
|
+
const SallaQuickBuy = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
2409
|
+
constructor() {
|
|
2410
|
+
super();
|
|
2411
|
+
this.__registerHost();
|
|
2412
|
+
/**
|
|
2413
|
+
* Button type.
|
|
2414
|
+
*
|
|
2415
|
+
* @type {string}
|
|
2416
|
+
* @default plain
|
|
2417
|
+
**/
|
|
2418
|
+
this.type = 'buy';
|
|
2419
|
+
/**
|
|
2420
|
+
* Product amount.
|
|
2421
|
+
*
|
|
2422
|
+
* @type {number}
|
|
2423
|
+
* @default 0
|
|
2424
|
+
**/
|
|
2425
|
+
this.amount = 0;
|
|
2426
|
+
/**
|
|
2427
|
+
* Product options, if is empty will get the data from the document.querySelector('salla-product-options[product-id="X"]')
|
|
2428
|
+
*
|
|
2429
|
+
* @type {object}
|
|
2430
|
+
* @default {}
|
|
2431
|
+
*/
|
|
2432
|
+
this.options = {};
|
|
2433
|
+
this.quickBuy = salla.lang.get('pages.products.buy_now');
|
|
2434
|
+
salla.lang.onLoaded(() => {
|
|
2435
|
+
this.quickBuy = salla.lang.get('pages.products.buy_now');
|
|
2436
|
+
});
|
|
2437
|
+
}
|
|
2438
|
+
async quickBuyHandler() {
|
|
2439
|
+
if (salla.config.isGuest()) {
|
|
2440
|
+
// todo (low) :: find a way to re-fire the method after success
|
|
2441
|
+
return salla.auth.event.dispatch('login::open');
|
|
2442
|
+
}
|
|
2443
|
+
let optionsElement = document.querySelector(`salla-product-options[product-id="${this.productId}"]`);
|
|
2444
|
+
//make sure all the required options are selected
|
|
2445
|
+
if (optionsElement && !await optionsElement.reportValidity()) {
|
|
2446
|
+
return salla.error(salla.lang.get('common.messages.required_fields'));
|
|
2447
|
+
}
|
|
2448
|
+
//use this way to get quantity too
|
|
2449
|
+
let data = this.host.getElementSallaData();
|
|
2450
|
+
// if the store doesn't have Apple Pay , just create a cart and then redirect to check out page
|
|
2451
|
+
// @ts-ignore
|
|
2452
|
+
if (!this.isApplePayActive) {
|
|
2453
|
+
// return salla.product.buyNow(this.productId, data);
|
|
2454
|
+
return salla.api.request('checkout/quick-purchase/' + this.productId, data, 'post')
|
|
2455
|
+
.then(resp => {
|
|
2456
|
+
if (resp.data.redirect) {
|
|
2457
|
+
window.location.href = resp.data.redirect;
|
|
2458
|
+
}
|
|
2459
|
+
return resp;
|
|
2460
|
+
});
|
|
2461
|
+
}
|
|
2462
|
+
data.is_applepay = true;
|
|
2463
|
+
if ('append' in data) {
|
|
2464
|
+
data.append('is_applepay', true);
|
|
2465
|
+
}
|
|
2466
|
+
// noinspection TypeScriptValidateJSTypes
|
|
2467
|
+
salla.event.dispatch('payments::apple-pay.start-transaction', {
|
|
2468
|
+
amount: this.amount,
|
|
2469
|
+
currency: this.currency,
|
|
2470
|
+
requiredShippingContactFields: this.isRequireShipping ? ['postalAddress'] : null,
|
|
2471
|
+
shippingMethods: this.isRequireShipping ? [] : null,
|
|
2472
|
+
supportedNetworks: salla.config.get('store.settings.buy_now.networks'),
|
|
2473
|
+
supportedCountries: salla.config.get('store.settings.buy_now.countries'),
|
|
2474
|
+
validateMerchant: {
|
|
2475
|
+
url: salla.url.get('checkout/applepay/validate'),
|
|
2476
|
+
onSuccess: () => {
|
|
2477
|
+
return salla.api.request('checkout/quick-purchase/' + this.productId, typeof data == 'object' ? data : undefined, 'post', {}).then(response => {
|
|
2478
|
+
var _a, _b;
|
|
2479
|
+
// if is redirect url returned for any reason, lets redirect the user to check out
|
|
2480
|
+
if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.redirect) {
|
|
2481
|
+
salla.log('🍏 Pay: create checkout success: redirect exits, go to checkout page');
|
|
2482
|
+
window.location.href = response.data.redirect.url;
|
|
2483
|
+
return response;
|
|
2484
|
+
}
|
|
2485
|
+
// the cart is not ready to complete apply pay session
|
|
2486
|
+
if (!((_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.id)) {
|
|
2487
|
+
salla.logger.warn('🍏 Pay: create checkout success: No id, or redirect');
|
|
2488
|
+
return response;
|
|
2489
|
+
}
|
|
2490
|
+
window.SallaApplePay.id = response.data.id || response.data.data.id;
|
|
2491
|
+
salla.log('🍏 Pay: create checkout success: with id #' + window.SallaApplePay.id);
|
|
2492
|
+
});
|
|
2493
|
+
}
|
|
2494
|
+
},
|
|
2495
|
+
authorized: {
|
|
2496
|
+
// submit checkout route
|
|
2497
|
+
url: salla.url.get('checkout/{id}/payments/submit'),
|
|
2498
|
+
onFailed: (response) => {
|
|
2499
|
+
var _a, _b, _c, _d;
|
|
2500
|
+
window.SallaApplePay.onCancel({}, ((_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.message) || ((_d = (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.code) || salla.lang.get('pages.checkout.payment_failed'));
|
|
2501
|
+
},
|
|
2502
|
+
onSuccess: (response) => {
|
|
2503
|
+
window.location.href = response.redirect.url;
|
|
2504
|
+
salla.log('🍏 Pay: authorized Success:: redirect to thank you page, order placed');
|
|
2505
|
+
}
|
|
2506
|
+
},
|
|
2507
|
+
shippingMethodSelected: this.isRequireShipping ? {
|
|
2508
|
+
url: salla.url.get('checkout/{id}/shipping/details'),
|
|
2509
|
+
} : null,
|
|
2510
|
+
shippingContactSelected: this.isRequireShipping ? {
|
|
2511
|
+
url: salla.url.get('checkout/{id}/address/add'),
|
|
2512
|
+
} : null,
|
|
2513
|
+
oncouponcodechanged: {
|
|
2514
|
+
url: salla.url.get('checkout/{id}/coupons')
|
|
2515
|
+
},
|
|
2516
|
+
recalculateTotal: {
|
|
2517
|
+
url: salla.url.get('checkout/{id}/payments/recalculate')
|
|
2518
|
+
},
|
|
2519
|
+
onError: function (message) {
|
|
2520
|
+
salla.log(message);
|
|
2521
|
+
salla.notify.error(message);
|
|
2522
|
+
}
|
|
2523
|
+
});
|
|
2524
|
+
}
|
|
2525
|
+
componentWillLoad() {
|
|
2526
|
+
return new Promise((resolve, reject) => {
|
|
2527
|
+
salla.onReady(async () => {
|
|
2528
|
+
var _a, _b;
|
|
2529
|
+
if (!this.currency) {
|
|
2530
|
+
this.currency = salla.config.get('user.currency_code');
|
|
2531
|
+
}
|
|
2532
|
+
if (!this.productId && salla.config.get('page.id')) {
|
|
2533
|
+
this.productId = salla.config.get('page.id');
|
|
2534
|
+
}
|
|
2535
|
+
if (window.innerWidth <= 768 && this.type !== 'plain') {
|
|
2536
|
+
this.type = 'plain';
|
|
2537
|
+
}
|
|
2538
|
+
if (!this.productId) {
|
|
2539
|
+
salla.logger.warn('🍏 Pay: Failed load the quick buy, the product id is missing');
|
|
2540
|
+
return reject();
|
|
2541
|
+
}
|
|
2542
|
+
if (!this.amount && this.productId) {
|
|
2543
|
+
await salla.product.getDetails(this.productId, []).then((response) => {
|
|
2544
|
+
var _a;
|
|
2545
|
+
this.amount = response.data.price;
|
|
2546
|
+
this.isRequireShipping = ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.is_require_shipping) || false;
|
|
2547
|
+
}).catch((error) => {
|
|
2548
|
+
salla.logger.warn('🍏 Pay: Failed load the quick buy, get the product details failed: ', error);
|
|
2549
|
+
return reject();
|
|
2550
|
+
});
|
|
2551
|
+
}
|
|
2552
|
+
if (salla.url.is_page('product.single')) {
|
|
2553
|
+
salla.product.event.onPriceUpdated(response => this.amount = response.data.price);
|
|
2554
|
+
}
|
|
2555
|
+
this.isApplePayActive = ((_a = window.ApplePaySession) === null || _a === void 0 ? void 0 : _a.canMakePayments()) && ((_b = salla.config.get('store.settings.payments')) === null || _b === void 0 ? void 0 : _b.includes('apple_pay'));
|
|
2556
|
+
let applePaySdk = document.getElementById('apple-pay-sdk');
|
|
2557
|
+
if (applePaySdk || !this.isApplePayActive) {
|
|
2558
|
+
salla.logger.warn('🍏 Pay: Skipped load apple pay because ' + (applePaySdk ? 'already loaded' : 'is not available in the browser'));
|
|
2559
|
+
resolve(true);
|
|
2560
|
+
return;
|
|
2561
|
+
}
|
|
2562
|
+
const script = document.createElement('script');
|
|
2563
|
+
script.src = 'https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js';
|
|
2564
|
+
script.setAttribute('id', 'apple-pay-sdk');
|
|
2565
|
+
script.async = true;
|
|
2566
|
+
document.body.appendChild(script);
|
|
2567
|
+
resolve(true);
|
|
2568
|
+
});
|
|
2569
|
+
});
|
|
2570
|
+
}
|
|
2571
|
+
render() {
|
|
2572
|
+
return h(Host, null, this.quickBuyButton());
|
|
2573
|
+
}
|
|
2574
|
+
quickBuyButton() {
|
|
2575
|
+
return this.isApplePayActive
|
|
2576
|
+
? h("apple-pay-button", { locale: salla.config.get('user.language_code'), onClick: () => this.quickBuyHandler(), "data-quick-purchase": "applepay", class: "s-quick-buy-apple-pay", "data-is-applepay": "1", buttonstyle: "black", type: this.type })
|
|
2577
|
+
:
|
|
2578
|
+
h("salla-button", { onClick: () => this.quickBuyHandler(), class: "s-quick-buy-button", color: "primary", fill: "outline", size: "medium", width: "wide", shape: "btn" }, h("span", { innerHTML: FullWallet }), this.quickBuy);
|
|
2579
|
+
}
|
|
2580
|
+
get host() { return this; }
|
|
2581
|
+
static get style() { return sallaQuickBuyCss; }
|
|
2582
|
+
}, [0, "salla-quick-buy", {
|
|
2583
|
+
"type": [1025],
|
|
2584
|
+
"productId": [1025, "product-id"],
|
|
2585
|
+
"amount": [1538],
|
|
2586
|
+
"currency": [1025],
|
|
2587
|
+
"options": [16],
|
|
2588
|
+
"isRequireShipping": [1028, "is-require-shipping"],
|
|
2589
|
+
"isApplePayActive": [32],
|
|
2590
|
+
"quickBuy": [32]
|
|
2591
|
+
}]);
|
|
2592
|
+
function defineCustomElement() {
|
|
2593
|
+
if (typeof customElements === "undefined") {
|
|
2594
|
+
return;
|
|
2595
|
+
}
|
|
2596
|
+
const components = ["salla-quick-buy", "salla-button"];
|
|
2597
|
+
components.forEach(tagName => { switch (tagName) {
|
|
2598
|
+
case "salla-quick-buy":
|
|
2599
|
+
if (!customElements.get(tagName)) {
|
|
2600
|
+
customElements.define(tagName, SallaQuickBuy);
|
|
2601
|
+
}
|
|
2602
|
+
break;
|
|
2603
|
+
case "salla-button":
|
|
2604
|
+
if (!customElements.get(tagName)) {
|
|
2605
|
+
defineCustomElement$1();
|
|
2606
|
+
}
|
|
2607
|
+
break;
|
|
2608
|
+
} });
|
|
2609
|
+
}
|
|
2610
|
+
defineCustomElement();
|
|
2611
|
+
|
|
2612
|
+
export { SallaQuickBuy as S, defineCustomElement as d };
|