@verdocs/web-sdk 1.4.7 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/VerdocsEndpoint-5e6dd8ef.js +4780 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/verdocs-auth.cjs.entry.js +32 -19
- package/dist/cjs/verdocs-dropdown_12.cjs.entry.js +15 -11
- package/dist/cjs/verdocs-kba-dialog.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-ok-dialog.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-quick-functions.cjs.entry.js +5 -0
- package/dist/cjs/verdocs-search-activity_2.cjs.entry.js +40 -35
- package/dist/cjs/verdocs-search.cjs.entry.js +6 -1
- package/dist/cjs/verdocs-sign.cjs.entry.js +26 -161
- package/dist/cjs/verdocs-web-sdk.cjs.js +1 -1
- package/dist/collection/components/dialogs/verdocs-kba-dialog/verdocs-kba-dialog.css +1 -1
- package/dist/collection/components/dialogs/verdocs-ok-dialog/verdocs-ok-dialog.css +1 -1
- package/dist/collection/components/elements/verdocs-quick-functions/verdocs-quick-functions.js +31 -1
- package/dist/collection/components/elements/verdocs-search-activity/verdocs-search-activity.js +30 -6
- package/dist/collection/components/elements/verdocs-search-box/verdocs-search-box.js +26 -0
- package/dist/collection/components/embeds/verdocs-auth/verdocs-auth.css +1 -4
- package/dist/collection/components/embeds/verdocs-auth/verdocs-auth.js +35 -17
- package/dist/collection/components/embeds/verdocs-search/verdocs-search.js +36 -6
- package/dist/collection/components/embeds/verdocs-sign/verdocs-sign.css +27 -26
- package/dist/collection/components/embeds/verdocs-sign/verdocs-sign.js +40 -23
- package/dist/collection/components/embeds/verdocs-sign/verdocs-sign.stories.js +2 -2
- package/dist/collection/components/embeds/verdocs-view/verdocs-view.js +26 -0
- package/dist/components/VerdocsEndpoint.js +4766 -0
- package/dist/components/verdocs-auth.js +33 -18
- package/dist/components/verdocs-kba-dialog.js +1 -1
- package/dist/components/verdocs-ok-dialog2.js +1 -1
- package/dist/components/verdocs-quick-functions.js +8 -1
- package/dist/components/verdocs-search-activity2.js +37 -34
- package/dist/components/verdocs-search-box2.js +6 -0
- package/dist/components/verdocs-search.js +9 -2
- package/dist/components/verdocs-sign.js +27 -162
- package/dist/components/verdocs-view2.js +6 -1
- package/dist/custom-elements.json +830 -0
- package/dist/docs.json +117 -3
- package/dist/esm/VerdocsEndpoint-30e1b6ec.js +4766 -0
- package/dist/esm/loader.js +1 -1
- package/dist/esm/verdocs-auth.entry.js +32 -19
- package/dist/esm/verdocs-dropdown_12.entry.js +5 -1
- package/dist/esm/verdocs-kba-dialog.entry.js +1 -1
- package/dist/esm/verdocs-ok-dialog.entry.js +1 -1
- package/dist/esm/verdocs-quick-functions.entry.js +5 -0
- package/dist/esm/verdocs-search-activity_2.entry.js +40 -35
- package/dist/esm/verdocs-search.entry.js +6 -1
- package/dist/esm/verdocs-sign.entry.js +26 -161
- package/dist/esm/verdocs-web-sdk.js +1 -1
- package/dist/esm-es5/VerdocsEndpoint-30e1b6ec.js +7 -0
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/verdocs-auth.entry.js +1 -1
- package/dist/esm-es5/verdocs-dropdown_12.entry.js +2 -2
- package/dist/esm-es5/verdocs-kba-dialog.entry.js +1 -1
- package/dist/esm-es5/verdocs-ok-dialog.entry.js +1 -1
- package/dist/esm-es5/verdocs-quick-functions.entry.js +1 -1
- package/dist/esm-es5/verdocs-search-activity_2.entry.js +1 -1
- package/dist/esm-es5/verdocs-search.entry.js +1 -1
- package/dist/esm-es5/verdocs-sign.entry.js +1 -1
- package/dist/esm-es5/verdocs-web-sdk.js +1 -1
- package/dist/types/components/elements/verdocs-quick-functions/verdocs-quick-functions.d.ts +5 -0
- package/dist/types/components/elements/verdocs-search-activity/verdocs-search-activity.d.ts +5 -0
- package/dist/types/components/elements/verdocs-search-box/verdocs-search-box.d.ts +5 -0
- package/dist/types/components/embeds/verdocs-auth/verdocs-auth.d.ts +7 -4
- package/dist/types/components/embeds/verdocs-search/verdocs-search.d.ts +5 -0
- package/dist/types/components/embeds/verdocs-sign/verdocs-sign.d.ts +6 -3
- package/dist/types/components/embeds/verdocs-view/verdocs-view.d.ts +5 -0
- package/dist/types/components.d.ts +57 -0
- package/dist/verdocs-web-sdk/{p-ed5baeb4.entry.js → p-064453c3.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-06f38046.js +1 -0
- package/dist/verdocs-web-sdk/p-16d62a51.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-1b4e04b7.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-1ea3b9d3.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-30cc8818.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-0353c423.entry.js → p-32ad1014.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-4d80d044.system.js +7 -0
- package/dist/verdocs-web-sdk/{p-432c3151.system.entry.js → p-81fc0196.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-8276345a.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-88a300c5.system.js +1 -1
- package/dist/verdocs-web-sdk/p-9139a76d.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-a87069d5.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-aa9fc574.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-c29c2cf8.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-4368df79.system.entry.js → p-c4d03ff9.system.entry.js} +2 -2
- package/dist/verdocs-web-sdk/{p-a1143ddb.entry.js → p-d522de7d.entry.js} +2 -2
- package/dist/verdocs-web-sdk/{p-e2e643c5.system.entry.js → p-e4ba14dc.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-f6a53928.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/verdocs-web-sdk.esm.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/Auth-4ec35ac7.js +0 -97
- package/dist/cjs/Token-ac80819a.js +0 -2331
- package/dist/cjs/buffer-es6-bc8199b1.js +0 -2018
- package/dist/components/Auth.js +0 -92
- package/dist/components/Token.js +0 -2325
- package/dist/components/buffer-es6.js +0 -2010
- package/dist/esm/Auth-15cd42a8.js +0 -92
- package/dist/esm/Token-ce37bd9d.js +0 -2325
- package/dist/esm/buffer-es6-136673c8.js +0 -2010
- package/dist/esm-es5/Auth-15cd42a8.js +0 -1
- package/dist/esm-es5/Token-ce37bd9d.js +0 -1
- package/dist/esm-es5/buffer-es6-136673c8.js +0 -7
- package/dist/verdocs-web-sdk/p-0c0b4a10.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-2b57857d.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-2c161242.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-39633a02.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-5dfd73f9.system.js +0 -7
- package/dist/verdocs-web-sdk/p-69ef22bd.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-737b2e99.js +0 -1
- package/dist/verdocs-web-sdk/p-8730dc92.system.js +0 -1
- package/dist/verdocs-web-sdk/p-a7cfe6fc.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-b9164c4b.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-cec13589.system.js +0 -1
- package/dist/verdocs-web-sdk/p-e6e2894e.js +0 -1
- package/dist/verdocs-web-sdk/p-ea6d6dc7.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-ef932a87.js +0 -1
- package/dist/verdocs-web-sdk/p-f0e6fde0.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-fd853e54.system.entry.js +0 -1
|
@@ -0,0 +1,4780 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const global$1 = (typeof global !== "undefined" ? global :
|
|
4
|
+
typeof self !== "undefined" ? self :
|
|
5
|
+
typeof window !== "undefined" ? window : {});
|
|
6
|
+
|
|
7
|
+
var lookup = [];
|
|
8
|
+
var revLookup = [];
|
|
9
|
+
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
|
|
10
|
+
var inited = false;
|
|
11
|
+
function init () {
|
|
12
|
+
inited = true;
|
|
13
|
+
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
14
|
+
for (var i = 0, len = code.length; i < len; ++i) {
|
|
15
|
+
lookup[i] = code[i];
|
|
16
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
revLookup['-'.charCodeAt(0)] = 62;
|
|
20
|
+
revLookup['_'.charCodeAt(0)] = 63;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function toByteArray (b64) {
|
|
24
|
+
if (!inited) {
|
|
25
|
+
init();
|
|
26
|
+
}
|
|
27
|
+
var i, j, l, tmp, placeHolders, arr;
|
|
28
|
+
var len = b64.length;
|
|
29
|
+
|
|
30
|
+
if (len % 4 > 0) {
|
|
31
|
+
throw new Error('Invalid string. Length must be a multiple of 4')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// the number of equal signs (place holders)
|
|
35
|
+
// if there are two placeholders, than the two characters before it
|
|
36
|
+
// represent one byte
|
|
37
|
+
// if there is only one, then the three characters before it represent 2 bytes
|
|
38
|
+
// this is just a cheap hack to not do indexOf twice
|
|
39
|
+
placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
|
|
40
|
+
|
|
41
|
+
// base64 is 4/3 + up to two characters of the original data
|
|
42
|
+
arr = new Arr(len * 3 / 4 - placeHolders);
|
|
43
|
+
|
|
44
|
+
// if there are placeholders, only get up to the last complete 4 chars
|
|
45
|
+
l = placeHolders > 0 ? len - 4 : len;
|
|
46
|
+
|
|
47
|
+
var L = 0;
|
|
48
|
+
|
|
49
|
+
for (i = 0, j = 0; i < l; i += 4, j += 3) {
|
|
50
|
+
tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)];
|
|
51
|
+
arr[L++] = (tmp >> 16) & 0xFF;
|
|
52
|
+
arr[L++] = (tmp >> 8) & 0xFF;
|
|
53
|
+
arr[L++] = tmp & 0xFF;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (placeHolders === 2) {
|
|
57
|
+
tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
|
|
58
|
+
arr[L++] = tmp & 0xFF;
|
|
59
|
+
} else if (placeHolders === 1) {
|
|
60
|
+
tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2);
|
|
61
|
+
arr[L++] = (tmp >> 8) & 0xFF;
|
|
62
|
+
arr[L++] = tmp & 0xFF;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return arr
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function tripletToBase64 (num) {
|
|
69
|
+
return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function encodeChunk (uint8, start, end) {
|
|
73
|
+
var tmp;
|
|
74
|
+
var output = [];
|
|
75
|
+
for (var i = start; i < end; i += 3) {
|
|
76
|
+
tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
|
|
77
|
+
output.push(tripletToBase64(tmp));
|
|
78
|
+
}
|
|
79
|
+
return output.join('')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function fromByteArray (uint8) {
|
|
83
|
+
if (!inited) {
|
|
84
|
+
init();
|
|
85
|
+
}
|
|
86
|
+
var tmp;
|
|
87
|
+
var len = uint8.length;
|
|
88
|
+
var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
|
|
89
|
+
var output = '';
|
|
90
|
+
var parts = [];
|
|
91
|
+
var maxChunkLength = 16383; // must be multiple of 3
|
|
92
|
+
|
|
93
|
+
// go through the array every three bytes, we'll deal with trailing stuff later
|
|
94
|
+
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
|
95
|
+
parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// pad the end with zeros, but make sure to not forget the extra bytes
|
|
99
|
+
if (extraBytes === 1) {
|
|
100
|
+
tmp = uint8[len - 1];
|
|
101
|
+
output += lookup[tmp >> 2];
|
|
102
|
+
output += lookup[(tmp << 4) & 0x3F];
|
|
103
|
+
output += '==';
|
|
104
|
+
} else if (extraBytes === 2) {
|
|
105
|
+
tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
|
|
106
|
+
output += lookup[tmp >> 10];
|
|
107
|
+
output += lookup[(tmp >> 4) & 0x3F];
|
|
108
|
+
output += lookup[(tmp << 2) & 0x3F];
|
|
109
|
+
output += '=';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
parts.push(output);
|
|
113
|
+
|
|
114
|
+
return parts.join('')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function read (buffer, offset, isLE, mLen, nBytes) {
|
|
118
|
+
var e, m;
|
|
119
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
120
|
+
var eMax = (1 << eLen) - 1;
|
|
121
|
+
var eBias = eMax >> 1;
|
|
122
|
+
var nBits = -7;
|
|
123
|
+
var i = isLE ? (nBytes - 1) : 0;
|
|
124
|
+
var d = isLE ? -1 : 1;
|
|
125
|
+
var s = buffer[offset + i];
|
|
126
|
+
|
|
127
|
+
i += d;
|
|
128
|
+
|
|
129
|
+
e = s & ((1 << (-nBits)) - 1);
|
|
130
|
+
s >>= (-nBits);
|
|
131
|
+
nBits += eLen;
|
|
132
|
+
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
|
|
133
|
+
|
|
134
|
+
m = e & ((1 << (-nBits)) - 1);
|
|
135
|
+
e >>= (-nBits);
|
|
136
|
+
nBits += mLen;
|
|
137
|
+
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
|
|
138
|
+
|
|
139
|
+
if (e === 0) {
|
|
140
|
+
e = 1 - eBias;
|
|
141
|
+
} else if (e === eMax) {
|
|
142
|
+
return m ? NaN : ((s ? -1 : 1) * Infinity)
|
|
143
|
+
} else {
|
|
144
|
+
m = m + Math.pow(2, mLen);
|
|
145
|
+
e = e - eBias;
|
|
146
|
+
}
|
|
147
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function write (buffer, value, offset, isLE, mLen, nBytes) {
|
|
151
|
+
var e, m, c;
|
|
152
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
153
|
+
var eMax = (1 << eLen) - 1;
|
|
154
|
+
var eBias = eMax >> 1;
|
|
155
|
+
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
|
|
156
|
+
var i = isLE ? 0 : (nBytes - 1);
|
|
157
|
+
var d = isLE ? 1 : -1;
|
|
158
|
+
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
|
159
|
+
|
|
160
|
+
value = Math.abs(value);
|
|
161
|
+
|
|
162
|
+
if (isNaN(value) || value === Infinity) {
|
|
163
|
+
m = isNaN(value) ? 1 : 0;
|
|
164
|
+
e = eMax;
|
|
165
|
+
} else {
|
|
166
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
167
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
168
|
+
e--;
|
|
169
|
+
c *= 2;
|
|
170
|
+
}
|
|
171
|
+
if (e + eBias >= 1) {
|
|
172
|
+
value += rt / c;
|
|
173
|
+
} else {
|
|
174
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
175
|
+
}
|
|
176
|
+
if (value * c >= 2) {
|
|
177
|
+
e++;
|
|
178
|
+
c /= 2;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (e + eBias >= eMax) {
|
|
182
|
+
m = 0;
|
|
183
|
+
e = eMax;
|
|
184
|
+
} else if (e + eBias >= 1) {
|
|
185
|
+
m = (value * c - 1) * Math.pow(2, mLen);
|
|
186
|
+
e = e + eBias;
|
|
187
|
+
} else {
|
|
188
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
189
|
+
e = 0;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
|
194
|
+
|
|
195
|
+
e = (e << mLen) | m;
|
|
196
|
+
eLen += mLen;
|
|
197
|
+
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
|
198
|
+
|
|
199
|
+
buffer[offset + i - d] |= s * 128;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
var toString$1 = {}.toString;
|
|
203
|
+
|
|
204
|
+
var isArray$1 = Array.isArray || function (arr) {
|
|
205
|
+
return toString$1.call(arr) == '[object Array]';
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/*!
|
|
209
|
+
* The buffer module from node.js, for the browser.
|
|
210
|
+
*
|
|
211
|
+
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
|
|
212
|
+
* @license MIT
|
|
213
|
+
*/
|
|
214
|
+
|
|
215
|
+
var INSPECT_MAX_BYTES = 50;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
|
219
|
+
* === true Use Uint8Array implementation (fastest)
|
|
220
|
+
* === false Use Object implementation (most compatible, even IE6)
|
|
221
|
+
*
|
|
222
|
+
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
|
223
|
+
* Opera 11.6+, iOS 4.2+.
|
|
224
|
+
*
|
|
225
|
+
* Due to various browser bugs, sometimes the Object implementation will be used even
|
|
226
|
+
* when the browser supports typed arrays.
|
|
227
|
+
*
|
|
228
|
+
* Note:
|
|
229
|
+
*
|
|
230
|
+
* - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
|
|
231
|
+
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
|
|
232
|
+
*
|
|
233
|
+
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
|
|
234
|
+
*
|
|
235
|
+
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
|
|
236
|
+
* incorrect length in some situations.
|
|
237
|
+
|
|
238
|
+
* We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
|
|
239
|
+
* get the Object implementation, which is slower but behaves correctly.
|
|
240
|
+
*/
|
|
241
|
+
Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined
|
|
242
|
+
? global$1.TYPED_ARRAY_SUPPORT
|
|
243
|
+
: true;
|
|
244
|
+
|
|
245
|
+
function kMaxLength () {
|
|
246
|
+
return Buffer.TYPED_ARRAY_SUPPORT
|
|
247
|
+
? 0x7fffffff
|
|
248
|
+
: 0x3fffffff
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function createBuffer (that, length) {
|
|
252
|
+
if (kMaxLength() < length) {
|
|
253
|
+
throw new RangeError('Invalid typed array length')
|
|
254
|
+
}
|
|
255
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
256
|
+
// Return an augmented `Uint8Array` instance, for best performance
|
|
257
|
+
that = new Uint8Array(length);
|
|
258
|
+
that.__proto__ = Buffer.prototype;
|
|
259
|
+
} else {
|
|
260
|
+
// Fallback: Return an object instance of the Buffer class
|
|
261
|
+
if (that === null) {
|
|
262
|
+
that = new Buffer(length);
|
|
263
|
+
}
|
|
264
|
+
that.length = length;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return that
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* The Buffer constructor returns instances of `Uint8Array` that have their
|
|
272
|
+
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
|
273
|
+
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
|
274
|
+
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
|
275
|
+
* returns a single octet.
|
|
276
|
+
*
|
|
277
|
+
* The `Uint8Array` prototype remains unmodified.
|
|
278
|
+
*/
|
|
279
|
+
|
|
280
|
+
function Buffer (arg, encodingOrOffset, length) {
|
|
281
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
|
|
282
|
+
return new Buffer(arg, encodingOrOffset, length)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Common case.
|
|
286
|
+
if (typeof arg === 'number') {
|
|
287
|
+
if (typeof encodingOrOffset === 'string') {
|
|
288
|
+
throw new Error(
|
|
289
|
+
'If encoding is specified then the first argument must be a string'
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
return allocUnsafe(this, arg)
|
|
293
|
+
}
|
|
294
|
+
return from(this, arg, encodingOrOffset, length)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
Buffer.poolSize = 8192; // not used by this implementation
|
|
298
|
+
|
|
299
|
+
// TODO: Legacy, not needed anymore. Remove in next major version.
|
|
300
|
+
Buffer._augment = function (arr) {
|
|
301
|
+
arr.__proto__ = Buffer.prototype;
|
|
302
|
+
return arr
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
function from (that, value, encodingOrOffset, length) {
|
|
306
|
+
if (typeof value === 'number') {
|
|
307
|
+
throw new TypeError('"value" argument must not be a number')
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
|
|
311
|
+
return fromArrayBuffer(that, value, encodingOrOffset, length)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (typeof value === 'string') {
|
|
315
|
+
return fromString(that, value, encodingOrOffset)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return fromObject(that, value)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
|
|
323
|
+
* if value is a number.
|
|
324
|
+
* Buffer.from(str[, encoding])
|
|
325
|
+
* Buffer.from(array)
|
|
326
|
+
* Buffer.from(buffer)
|
|
327
|
+
* Buffer.from(arrayBuffer[, byteOffset[, length]])
|
|
328
|
+
**/
|
|
329
|
+
Buffer.from = function (value, encodingOrOffset, length) {
|
|
330
|
+
return from(null, value, encodingOrOffset, length)
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
334
|
+
Buffer.prototype.__proto__ = Uint8Array.prototype;
|
|
335
|
+
Buffer.__proto__ = Uint8Array;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function assertSize (size) {
|
|
339
|
+
if (typeof size !== 'number') {
|
|
340
|
+
throw new TypeError('"size" argument must be a number')
|
|
341
|
+
} else if (size < 0) {
|
|
342
|
+
throw new RangeError('"size" argument must not be negative')
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function alloc (that, size, fill, encoding) {
|
|
347
|
+
assertSize(size);
|
|
348
|
+
if (size <= 0) {
|
|
349
|
+
return createBuffer(that, size)
|
|
350
|
+
}
|
|
351
|
+
if (fill !== undefined) {
|
|
352
|
+
// Only pay attention to encoding if it's a string. This
|
|
353
|
+
// prevents accidentally sending in a number that would
|
|
354
|
+
// be interpretted as a start offset.
|
|
355
|
+
return typeof encoding === 'string'
|
|
356
|
+
? createBuffer(that, size).fill(fill, encoding)
|
|
357
|
+
: createBuffer(that, size).fill(fill)
|
|
358
|
+
}
|
|
359
|
+
return createBuffer(that, size)
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Creates a new filled Buffer instance.
|
|
364
|
+
* alloc(size[, fill[, encoding]])
|
|
365
|
+
**/
|
|
366
|
+
Buffer.alloc = function (size, fill, encoding) {
|
|
367
|
+
return alloc(null, size, fill, encoding)
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
function allocUnsafe (that, size) {
|
|
371
|
+
assertSize(size);
|
|
372
|
+
that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
|
|
373
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT) {
|
|
374
|
+
for (var i = 0; i < size; ++i) {
|
|
375
|
+
that[i] = 0;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return that
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
|
383
|
+
* */
|
|
384
|
+
Buffer.allocUnsafe = function (size) {
|
|
385
|
+
return allocUnsafe(null, size)
|
|
386
|
+
};
|
|
387
|
+
/**
|
|
388
|
+
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
|
389
|
+
*/
|
|
390
|
+
Buffer.allocUnsafeSlow = function (size) {
|
|
391
|
+
return allocUnsafe(null, size)
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
function fromString (that, string, encoding) {
|
|
395
|
+
if (typeof encoding !== 'string' || encoding === '') {
|
|
396
|
+
encoding = 'utf8';
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (!Buffer.isEncoding(encoding)) {
|
|
400
|
+
throw new TypeError('"encoding" must be a valid string encoding')
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
var length = byteLength(string, encoding) | 0;
|
|
404
|
+
that = createBuffer(that, length);
|
|
405
|
+
|
|
406
|
+
var actual = that.write(string, encoding);
|
|
407
|
+
|
|
408
|
+
if (actual !== length) {
|
|
409
|
+
// Writing a hex string, for example, that contains invalid characters will
|
|
410
|
+
// cause everything after the first invalid character to be ignored. (e.g.
|
|
411
|
+
// 'abxxcd' will be treated as 'ab')
|
|
412
|
+
that = that.slice(0, actual);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return that
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function fromArrayLike (that, array) {
|
|
419
|
+
var length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
420
|
+
that = createBuffer(that, length);
|
|
421
|
+
for (var i = 0; i < length; i += 1) {
|
|
422
|
+
that[i] = array[i] & 255;
|
|
423
|
+
}
|
|
424
|
+
return that
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function fromArrayBuffer (that, array, byteOffset, length) {
|
|
428
|
+
|
|
429
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
430
|
+
throw new RangeError('\'offset\' is out of bounds')
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (array.byteLength < byteOffset + (length || 0)) {
|
|
434
|
+
throw new RangeError('\'length\' is out of bounds')
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (byteOffset === undefined && length === undefined) {
|
|
438
|
+
array = new Uint8Array(array);
|
|
439
|
+
} else if (length === undefined) {
|
|
440
|
+
array = new Uint8Array(array, byteOffset);
|
|
441
|
+
} else {
|
|
442
|
+
array = new Uint8Array(array, byteOffset, length);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
446
|
+
// Return an augmented `Uint8Array` instance, for best performance
|
|
447
|
+
that = array;
|
|
448
|
+
that.__proto__ = Buffer.prototype;
|
|
449
|
+
} else {
|
|
450
|
+
// Fallback: Return an object instance of the Buffer class
|
|
451
|
+
that = fromArrayLike(that, array);
|
|
452
|
+
}
|
|
453
|
+
return that
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function fromObject (that, obj) {
|
|
457
|
+
if (internalIsBuffer(obj)) {
|
|
458
|
+
var len = checked(obj.length) | 0;
|
|
459
|
+
that = createBuffer(that, len);
|
|
460
|
+
|
|
461
|
+
if (that.length === 0) {
|
|
462
|
+
return that
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
obj.copy(that, 0, 0, len);
|
|
466
|
+
return that
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
if (obj) {
|
|
470
|
+
if ((typeof ArrayBuffer !== 'undefined' &&
|
|
471
|
+
obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
|
|
472
|
+
if (typeof obj.length !== 'number' || isnan(obj.length)) {
|
|
473
|
+
return createBuffer(that, 0)
|
|
474
|
+
}
|
|
475
|
+
return fromArrayLike(that, obj)
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
if (obj.type === 'Buffer' && isArray$1(obj.data)) {
|
|
479
|
+
return fromArrayLike(that, obj.data)
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function checked (length) {
|
|
487
|
+
// Note: cannot use `length < kMaxLength()` here because that fails when
|
|
488
|
+
// length is NaN (which is otherwise coerced to zero.)
|
|
489
|
+
if (length >= kMaxLength()) {
|
|
490
|
+
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
|
491
|
+
'size: 0x' + kMaxLength().toString(16) + ' bytes')
|
|
492
|
+
}
|
|
493
|
+
return length | 0
|
|
494
|
+
}
|
|
495
|
+
Buffer.isBuffer = isBuffer$1;
|
|
496
|
+
function internalIsBuffer (b) {
|
|
497
|
+
return !!(b != null && b._isBuffer)
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
Buffer.compare = function compare (a, b) {
|
|
501
|
+
if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
|
|
502
|
+
throw new TypeError('Arguments must be Buffers')
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
if (a === b) return 0
|
|
506
|
+
|
|
507
|
+
var x = a.length;
|
|
508
|
+
var y = b.length;
|
|
509
|
+
|
|
510
|
+
for (var i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
511
|
+
if (a[i] !== b[i]) {
|
|
512
|
+
x = a[i];
|
|
513
|
+
y = b[i];
|
|
514
|
+
break
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
if (x < y) return -1
|
|
519
|
+
if (y < x) return 1
|
|
520
|
+
return 0
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
Buffer.isEncoding = function isEncoding (encoding) {
|
|
524
|
+
switch (String(encoding).toLowerCase()) {
|
|
525
|
+
case 'hex':
|
|
526
|
+
case 'utf8':
|
|
527
|
+
case 'utf-8':
|
|
528
|
+
case 'ascii':
|
|
529
|
+
case 'latin1':
|
|
530
|
+
case 'binary':
|
|
531
|
+
case 'base64':
|
|
532
|
+
case 'ucs2':
|
|
533
|
+
case 'ucs-2':
|
|
534
|
+
case 'utf16le':
|
|
535
|
+
case 'utf-16le':
|
|
536
|
+
return true
|
|
537
|
+
default:
|
|
538
|
+
return false
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
Buffer.concat = function concat (list, length) {
|
|
543
|
+
if (!isArray$1(list)) {
|
|
544
|
+
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (list.length === 0) {
|
|
548
|
+
return Buffer.alloc(0)
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
var i;
|
|
552
|
+
if (length === undefined) {
|
|
553
|
+
length = 0;
|
|
554
|
+
for (i = 0; i < list.length; ++i) {
|
|
555
|
+
length += list[i].length;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
var buffer = Buffer.allocUnsafe(length);
|
|
560
|
+
var pos = 0;
|
|
561
|
+
for (i = 0; i < list.length; ++i) {
|
|
562
|
+
var buf = list[i];
|
|
563
|
+
if (!internalIsBuffer(buf)) {
|
|
564
|
+
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
565
|
+
}
|
|
566
|
+
buf.copy(buffer, pos);
|
|
567
|
+
pos += buf.length;
|
|
568
|
+
}
|
|
569
|
+
return buffer
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
function byteLength (string, encoding) {
|
|
573
|
+
if (internalIsBuffer(string)) {
|
|
574
|
+
return string.length
|
|
575
|
+
}
|
|
576
|
+
if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
|
|
577
|
+
(ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
|
|
578
|
+
return string.byteLength
|
|
579
|
+
}
|
|
580
|
+
if (typeof string !== 'string') {
|
|
581
|
+
string = '' + string;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
var len = string.length;
|
|
585
|
+
if (len === 0) return 0
|
|
586
|
+
|
|
587
|
+
// Use a for loop to avoid recursion
|
|
588
|
+
var loweredCase = false;
|
|
589
|
+
for (;;) {
|
|
590
|
+
switch (encoding) {
|
|
591
|
+
case 'ascii':
|
|
592
|
+
case 'latin1':
|
|
593
|
+
case 'binary':
|
|
594
|
+
return len
|
|
595
|
+
case 'utf8':
|
|
596
|
+
case 'utf-8':
|
|
597
|
+
case undefined:
|
|
598
|
+
return utf8ToBytes(string).length
|
|
599
|
+
case 'ucs2':
|
|
600
|
+
case 'ucs-2':
|
|
601
|
+
case 'utf16le':
|
|
602
|
+
case 'utf-16le':
|
|
603
|
+
return len * 2
|
|
604
|
+
case 'hex':
|
|
605
|
+
return len >>> 1
|
|
606
|
+
case 'base64':
|
|
607
|
+
return base64ToBytes(string).length
|
|
608
|
+
default:
|
|
609
|
+
if (loweredCase) return utf8ToBytes(string).length // assume utf8
|
|
610
|
+
encoding = ('' + encoding).toLowerCase();
|
|
611
|
+
loweredCase = true;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
Buffer.byteLength = byteLength;
|
|
616
|
+
|
|
617
|
+
function slowToString (encoding, start, end) {
|
|
618
|
+
var loweredCase = false;
|
|
619
|
+
|
|
620
|
+
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
|
|
621
|
+
// property of a typed array.
|
|
622
|
+
|
|
623
|
+
// This behaves neither like String nor Uint8Array in that we set start/end
|
|
624
|
+
// to their upper/lower bounds if the value passed is out of range.
|
|
625
|
+
// undefined is handled specially as per ECMA-262 6th Edition,
|
|
626
|
+
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
|
627
|
+
if (start === undefined || start < 0) {
|
|
628
|
+
start = 0;
|
|
629
|
+
}
|
|
630
|
+
// Return early if start > this.length. Done here to prevent potential uint32
|
|
631
|
+
// coercion fail below.
|
|
632
|
+
if (start > this.length) {
|
|
633
|
+
return ''
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (end === undefined || end > this.length) {
|
|
637
|
+
end = this.length;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
if (end <= 0) {
|
|
641
|
+
return ''
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// Force coersion to uint32. This will also coerce falsey/NaN values to 0.
|
|
645
|
+
end >>>= 0;
|
|
646
|
+
start >>>= 0;
|
|
647
|
+
|
|
648
|
+
if (end <= start) {
|
|
649
|
+
return ''
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
if (!encoding) encoding = 'utf8';
|
|
653
|
+
|
|
654
|
+
while (true) {
|
|
655
|
+
switch (encoding) {
|
|
656
|
+
case 'hex':
|
|
657
|
+
return hexSlice(this, start, end)
|
|
658
|
+
|
|
659
|
+
case 'utf8':
|
|
660
|
+
case 'utf-8':
|
|
661
|
+
return utf8Slice(this, start, end)
|
|
662
|
+
|
|
663
|
+
case 'ascii':
|
|
664
|
+
return asciiSlice(this, start, end)
|
|
665
|
+
|
|
666
|
+
case 'latin1':
|
|
667
|
+
case 'binary':
|
|
668
|
+
return latin1Slice(this, start, end)
|
|
669
|
+
|
|
670
|
+
case 'base64':
|
|
671
|
+
return base64Slice(this, start, end)
|
|
672
|
+
|
|
673
|
+
case 'ucs2':
|
|
674
|
+
case 'ucs-2':
|
|
675
|
+
case 'utf16le':
|
|
676
|
+
case 'utf-16le':
|
|
677
|
+
return utf16leSlice(this, start, end)
|
|
678
|
+
|
|
679
|
+
default:
|
|
680
|
+
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
681
|
+
encoding = (encoding + '').toLowerCase();
|
|
682
|
+
loweredCase = true;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
|
|
688
|
+
// Buffer instances.
|
|
689
|
+
Buffer.prototype._isBuffer = true;
|
|
690
|
+
|
|
691
|
+
function swap (b, n, m) {
|
|
692
|
+
var i = b[n];
|
|
693
|
+
b[n] = b[m];
|
|
694
|
+
b[m] = i;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
Buffer.prototype.swap16 = function swap16 () {
|
|
698
|
+
var len = this.length;
|
|
699
|
+
if (len % 2 !== 0) {
|
|
700
|
+
throw new RangeError('Buffer size must be a multiple of 16-bits')
|
|
701
|
+
}
|
|
702
|
+
for (var i = 0; i < len; i += 2) {
|
|
703
|
+
swap(this, i, i + 1);
|
|
704
|
+
}
|
|
705
|
+
return this
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
Buffer.prototype.swap32 = function swap32 () {
|
|
709
|
+
var len = this.length;
|
|
710
|
+
if (len % 4 !== 0) {
|
|
711
|
+
throw new RangeError('Buffer size must be a multiple of 32-bits')
|
|
712
|
+
}
|
|
713
|
+
for (var i = 0; i < len; i += 4) {
|
|
714
|
+
swap(this, i, i + 3);
|
|
715
|
+
swap(this, i + 1, i + 2);
|
|
716
|
+
}
|
|
717
|
+
return this
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
Buffer.prototype.swap64 = function swap64 () {
|
|
721
|
+
var len = this.length;
|
|
722
|
+
if (len % 8 !== 0) {
|
|
723
|
+
throw new RangeError('Buffer size must be a multiple of 64-bits')
|
|
724
|
+
}
|
|
725
|
+
for (var i = 0; i < len; i += 8) {
|
|
726
|
+
swap(this, i, i + 7);
|
|
727
|
+
swap(this, i + 1, i + 6);
|
|
728
|
+
swap(this, i + 2, i + 5);
|
|
729
|
+
swap(this, i + 3, i + 4);
|
|
730
|
+
}
|
|
731
|
+
return this
|
|
732
|
+
};
|
|
733
|
+
|
|
734
|
+
Buffer.prototype.toString = function toString () {
|
|
735
|
+
var length = this.length | 0;
|
|
736
|
+
if (length === 0) return ''
|
|
737
|
+
if (arguments.length === 0) return utf8Slice(this, 0, length)
|
|
738
|
+
return slowToString.apply(this, arguments)
|
|
739
|
+
};
|
|
740
|
+
|
|
741
|
+
Buffer.prototype.equals = function equals (b) {
|
|
742
|
+
if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
|
743
|
+
if (this === b) return true
|
|
744
|
+
return Buffer.compare(this, b) === 0
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
Buffer.prototype.inspect = function inspect () {
|
|
748
|
+
var str = '';
|
|
749
|
+
var max = INSPECT_MAX_BYTES;
|
|
750
|
+
if (this.length > 0) {
|
|
751
|
+
str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
|
|
752
|
+
if (this.length > max) str += ' ... ';
|
|
753
|
+
}
|
|
754
|
+
return '<Buffer ' + str + '>'
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
|
758
|
+
if (!internalIsBuffer(target)) {
|
|
759
|
+
throw new TypeError('Argument must be a Buffer')
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
if (start === undefined) {
|
|
763
|
+
start = 0;
|
|
764
|
+
}
|
|
765
|
+
if (end === undefined) {
|
|
766
|
+
end = target ? target.length : 0;
|
|
767
|
+
}
|
|
768
|
+
if (thisStart === undefined) {
|
|
769
|
+
thisStart = 0;
|
|
770
|
+
}
|
|
771
|
+
if (thisEnd === undefined) {
|
|
772
|
+
thisEnd = this.length;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
776
|
+
throw new RangeError('out of range index')
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
if (thisStart >= thisEnd && start >= end) {
|
|
780
|
+
return 0
|
|
781
|
+
}
|
|
782
|
+
if (thisStart >= thisEnd) {
|
|
783
|
+
return -1
|
|
784
|
+
}
|
|
785
|
+
if (start >= end) {
|
|
786
|
+
return 1
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
start >>>= 0;
|
|
790
|
+
end >>>= 0;
|
|
791
|
+
thisStart >>>= 0;
|
|
792
|
+
thisEnd >>>= 0;
|
|
793
|
+
|
|
794
|
+
if (this === target) return 0
|
|
795
|
+
|
|
796
|
+
var x = thisEnd - thisStart;
|
|
797
|
+
var y = end - start;
|
|
798
|
+
var len = Math.min(x, y);
|
|
799
|
+
|
|
800
|
+
var thisCopy = this.slice(thisStart, thisEnd);
|
|
801
|
+
var targetCopy = target.slice(start, end);
|
|
802
|
+
|
|
803
|
+
for (var i = 0; i < len; ++i) {
|
|
804
|
+
if (thisCopy[i] !== targetCopy[i]) {
|
|
805
|
+
x = thisCopy[i];
|
|
806
|
+
y = targetCopy[i];
|
|
807
|
+
break
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
if (x < y) return -1
|
|
812
|
+
if (y < x) return 1
|
|
813
|
+
return 0
|
|
814
|
+
};
|
|
815
|
+
|
|
816
|
+
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
|
|
817
|
+
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
|
|
818
|
+
//
|
|
819
|
+
// Arguments:
|
|
820
|
+
// - buffer - a Buffer to search
|
|
821
|
+
// - val - a string, Buffer, or number
|
|
822
|
+
// - byteOffset - an index into `buffer`; will be clamped to an int32
|
|
823
|
+
// - encoding - an optional encoding, relevant is val is a string
|
|
824
|
+
// - dir - true for indexOf, false for lastIndexOf
|
|
825
|
+
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
|
826
|
+
// Empty buffer means no match
|
|
827
|
+
if (buffer.length === 0) return -1
|
|
828
|
+
|
|
829
|
+
// Normalize byteOffset
|
|
830
|
+
if (typeof byteOffset === 'string') {
|
|
831
|
+
encoding = byteOffset;
|
|
832
|
+
byteOffset = 0;
|
|
833
|
+
} else if (byteOffset > 0x7fffffff) {
|
|
834
|
+
byteOffset = 0x7fffffff;
|
|
835
|
+
} else if (byteOffset < -0x80000000) {
|
|
836
|
+
byteOffset = -0x80000000;
|
|
837
|
+
}
|
|
838
|
+
byteOffset = +byteOffset; // Coerce to Number.
|
|
839
|
+
if (isNaN(byteOffset)) {
|
|
840
|
+
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
|
841
|
+
byteOffset = dir ? 0 : (buffer.length - 1);
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// Normalize byteOffset: negative offsets start from the end of the buffer
|
|
845
|
+
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
|
|
846
|
+
if (byteOffset >= buffer.length) {
|
|
847
|
+
if (dir) return -1
|
|
848
|
+
else byteOffset = buffer.length - 1;
|
|
849
|
+
} else if (byteOffset < 0) {
|
|
850
|
+
if (dir) byteOffset = 0;
|
|
851
|
+
else return -1
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// Normalize val
|
|
855
|
+
if (typeof val === 'string') {
|
|
856
|
+
val = Buffer.from(val, encoding);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// Finally, search either indexOf (if dir is true) or lastIndexOf
|
|
860
|
+
if (internalIsBuffer(val)) {
|
|
861
|
+
// Special case: looking for empty string/buffer always fails
|
|
862
|
+
if (val.length === 0) {
|
|
863
|
+
return -1
|
|
864
|
+
}
|
|
865
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
|
866
|
+
} else if (typeof val === 'number') {
|
|
867
|
+
val = val & 0xFF; // Search for a byte value [0-255]
|
|
868
|
+
if (Buffer.TYPED_ARRAY_SUPPORT &&
|
|
869
|
+
typeof Uint8Array.prototype.indexOf === 'function') {
|
|
870
|
+
if (dir) {
|
|
871
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
|
872
|
+
} else {
|
|
873
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
throw new TypeError('val must be string, number or Buffer')
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
|
883
|
+
var indexSize = 1;
|
|
884
|
+
var arrLength = arr.length;
|
|
885
|
+
var valLength = val.length;
|
|
886
|
+
|
|
887
|
+
if (encoding !== undefined) {
|
|
888
|
+
encoding = String(encoding).toLowerCase();
|
|
889
|
+
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
|
890
|
+
encoding === 'utf16le' || encoding === 'utf-16le') {
|
|
891
|
+
if (arr.length < 2 || val.length < 2) {
|
|
892
|
+
return -1
|
|
893
|
+
}
|
|
894
|
+
indexSize = 2;
|
|
895
|
+
arrLength /= 2;
|
|
896
|
+
valLength /= 2;
|
|
897
|
+
byteOffset /= 2;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
function read (buf, i) {
|
|
902
|
+
if (indexSize === 1) {
|
|
903
|
+
return buf[i]
|
|
904
|
+
} else {
|
|
905
|
+
return buf.readUInt16BE(i * indexSize)
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
var i;
|
|
910
|
+
if (dir) {
|
|
911
|
+
var foundIndex = -1;
|
|
912
|
+
for (i = byteOffset; i < arrLength; i++) {
|
|
913
|
+
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
914
|
+
if (foundIndex === -1) foundIndex = i;
|
|
915
|
+
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
|
916
|
+
} else {
|
|
917
|
+
if (foundIndex !== -1) i -= i - foundIndex;
|
|
918
|
+
foundIndex = -1;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
} else {
|
|
922
|
+
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
923
|
+
for (i = byteOffset; i >= 0; i--) {
|
|
924
|
+
var found = true;
|
|
925
|
+
for (var j = 0; j < valLength; j++) {
|
|
926
|
+
if (read(arr, i + j) !== read(val, j)) {
|
|
927
|
+
found = false;
|
|
928
|
+
break
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
if (found) return i
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
return -1
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
|
939
|
+
return this.indexOf(val, byteOffset, encoding) !== -1
|
|
940
|
+
};
|
|
941
|
+
|
|
942
|
+
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
|
943
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
|
944
|
+
};
|
|
945
|
+
|
|
946
|
+
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
|
947
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
|
948
|
+
};
|
|
949
|
+
|
|
950
|
+
function hexWrite (buf, string, offset, length) {
|
|
951
|
+
offset = Number(offset) || 0;
|
|
952
|
+
var remaining = buf.length - offset;
|
|
953
|
+
if (!length) {
|
|
954
|
+
length = remaining;
|
|
955
|
+
} else {
|
|
956
|
+
length = Number(length);
|
|
957
|
+
if (length > remaining) {
|
|
958
|
+
length = remaining;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// must be an even number of digits
|
|
963
|
+
var strLen = string.length;
|
|
964
|
+
if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
|
|
965
|
+
|
|
966
|
+
if (length > strLen / 2) {
|
|
967
|
+
length = strLen / 2;
|
|
968
|
+
}
|
|
969
|
+
for (var i = 0; i < length; ++i) {
|
|
970
|
+
var parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
971
|
+
if (isNaN(parsed)) return i
|
|
972
|
+
buf[offset + i] = parsed;
|
|
973
|
+
}
|
|
974
|
+
return i
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
function utf8Write (buf, string, offset, length) {
|
|
978
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
function asciiWrite (buf, string, offset, length) {
|
|
982
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length)
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
function latin1Write (buf, string, offset, length) {
|
|
986
|
+
return asciiWrite(buf, string, offset, length)
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
function base64Write (buf, string, offset, length) {
|
|
990
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length)
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
function ucs2Write (buf, string, offset, length) {
|
|
994
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
Buffer.prototype.write = function write (string, offset, length, encoding) {
|
|
998
|
+
// Buffer#write(string)
|
|
999
|
+
if (offset === undefined) {
|
|
1000
|
+
encoding = 'utf8';
|
|
1001
|
+
length = this.length;
|
|
1002
|
+
offset = 0;
|
|
1003
|
+
// Buffer#write(string, encoding)
|
|
1004
|
+
} else if (length === undefined && typeof offset === 'string') {
|
|
1005
|
+
encoding = offset;
|
|
1006
|
+
length = this.length;
|
|
1007
|
+
offset = 0;
|
|
1008
|
+
// Buffer#write(string, offset[, length][, encoding])
|
|
1009
|
+
} else if (isFinite(offset)) {
|
|
1010
|
+
offset = offset | 0;
|
|
1011
|
+
if (isFinite(length)) {
|
|
1012
|
+
length = length | 0;
|
|
1013
|
+
if (encoding === undefined) encoding = 'utf8';
|
|
1014
|
+
} else {
|
|
1015
|
+
encoding = length;
|
|
1016
|
+
length = undefined;
|
|
1017
|
+
}
|
|
1018
|
+
// legacy write(string, encoding, offset, length) - remove in v0.13
|
|
1019
|
+
} else {
|
|
1020
|
+
throw new Error(
|
|
1021
|
+
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
|
1022
|
+
)
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
var remaining = this.length - offset;
|
|
1026
|
+
if (length === undefined || length > remaining) length = remaining;
|
|
1027
|
+
|
|
1028
|
+
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
|
1029
|
+
throw new RangeError('Attempt to write outside buffer bounds')
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
if (!encoding) encoding = 'utf8';
|
|
1033
|
+
|
|
1034
|
+
var loweredCase = false;
|
|
1035
|
+
for (;;) {
|
|
1036
|
+
switch (encoding) {
|
|
1037
|
+
case 'hex':
|
|
1038
|
+
return hexWrite(this, string, offset, length)
|
|
1039
|
+
|
|
1040
|
+
case 'utf8':
|
|
1041
|
+
case 'utf-8':
|
|
1042
|
+
return utf8Write(this, string, offset, length)
|
|
1043
|
+
|
|
1044
|
+
case 'ascii':
|
|
1045
|
+
return asciiWrite(this, string, offset, length)
|
|
1046
|
+
|
|
1047
|
+
case 'latin1':
|
|
1048
|
+
case 'binary':
|
|
1049
|
+
return latin1Write(this, string, offset, length)
|
|
1050
|
+
|
|
1051
|
+
case 'base64':
|
|
1052
|
+
// Warning: maxLength not taken into account in base64Write
|
|
1053
|
+
return base64Write(this, string, offset, length)
|
|
1054
|
+
|
|
1055
|
+
case 'ucs2':
|
|
1056
|
+
case 'ucs-2':
|
|
1057
|
+
case 'utf16le':
|
|
1058
|
+
case 'utf-16le':
|
|
1059
|
+
return ucs2Write(this, string, offset, length)
|
|
1060
|
+
|
|
1061
|
+
default:
|
|
1062
|
+
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
1063
|
+
encoding = ('' + encoding).toLowerCase();
|
|
1064
|
+
loweredCase = true;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
};
|
|
1068
|
+
|
|
1069
|
+
Buffer.prototype.toJSON = function toJSON () {
|
|
1070
|
+
return {
|
|
1071
|
+
type: 'Buffer',
|
|
1072
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1075
|
+
|
|
1076
|
+
function base64Slice (buf, start, end) {
|
|
1077
|
+
if (start === 0 && end === buf.length) {
|
|
1078
|
+
return fromByteArray(buf)
|
|
1079
|
+
} else {
|
|
1080
|
+
return fromByteArray(buf.slice(start, end))
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
function utf8Slice (buf, start, end) {
|
|
1085
|
+
end = Math.min(buf.length, end);
|
|
1086
|
+
var res = [];
|
|
1087
|
+
|
|
1088
|
+
var i = start;
|
|
1089
|
+
while (i < end) {
|
|
1090
|
+
var firstByte = buf[i];
|
|
1091
|
+
var codePoint = null;
|
|
1092
|
+
var bytesPerSequence = (firstByte > 0xEF) ? 4
|
|
1093
|
+
: (firstByte > 0xDF) ? 3
|
|
1094
|
+
: (firstByte > 0xBF) ? 2
|
|
1095
|
+
: 1;
|
|
1096
|
+
|
|
1097
|
+
if (i + bytesPerSequence <= end) {
|
|
1098
|
+
var secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
1099
|
+
|
|
1100
|
+
switch (bytesPerSequence) {
|
|
1101
|
+
case 1:
|
|
1102
|
+
if (firstByte < 0x80) {
|
|
1103
|
+
codePoint = firstByte;
|
|
1104
|
+
}
|
|
1105
|
+
break
|
|
1106
|
+
case 2:
|
|
1107
|
+
secondByte = buf[i + 1];
|
|
1108
|
+
if ((secondByte & 0xC0) === 0x80) {
|
|
1109
|
+
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
|
|
1110
|
+
if (tempCodePoint > 0x7F) {
|
|
1111
|
+
codePoint = tempCodePoint;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
break
|
|
1115
|
+
case 3:
|
|
1116
|
+
secondByte = buf[i + 1];
|
|
1117
|
+
thirdByte = buf[i + 2];
|
|
1118
|
+
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
|
1119
|
+
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
|
|
1120
|
+
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
|
1121
|
+
codePoint = tempCodePoint;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
break
|
|
1125
|
+
case 4:
|
|
1126
|
+
secondByte = buf[i + 1];
|
|
1127
|
+
thirdByte = buf[i + 2];
|
|
1128
|
+
fourthByte = buf[i + 3];
|
|
1129
|
+
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
|
1130
|
+
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
|
|
1131
|
+
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
|
1132
|
+
codePoint = tempCodePoint;
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
if (codePoint === null) {
|
|
1139
|
+
// we did not generate a valid codePoint so insert a
|
|
1140
|
+
// replacement char (U+FFFD) and advance only 1 byte
|
|
1141
|
+
codePoint = 0xFFFD;
|
|
1142
|
+
bytesPerSequence = 1;
|
|
1143
|
+
} else if (codePoint > 0xFFFF) {
|
|
1144
|
+
// encode to utf16 (surrogate pair dance)
|
|
1145
|
+
codePoint -= 0x10000;
|
|
1146
|
+
res.push(codePoint >>> 10 & 0x3FF | 0xD800);
|
|
1147
|
+
codePoint = 0xDC00 | codePoint & 0x3FF;
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
res.push(codePoint);
|
|
1151
|
+
i += bytesPerSequence;
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
return decodeCodePointsArray(res)
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
|
1158
|
+
// the lowest limit is Chrome, with 0x10000 args.
|
|
1159
|
+
// We go 1 magnitude less, for safety
|
|
1160
|
+
var MAX_ARGUMENTS_LENGTH = 0x1000;
|
|
1161
|
+
|
|
1162
|
+
function decodeCodePointsArray (codePoints) {
|
|
1163
|
+
var len = codePoints.length;
|
|
1164
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
1165
|
+
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
// Decode in chunks to avoid "call stack size exceeded".
|
|
1169
|
+
var res = '';
|
|
1170
|
+
var i = 0;
|
|
1171
|
+
while (i < len) {
|
|
1172
|
+
res += String.fromCharCode.apply(
|
|
1173
|
+
String,
|
|
1174
|
+
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
1175
|
+
);
|
|
1176
|
+
}
|
|
1177
|
+
return res
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
function asciiSlice (buf, start, end) {
|
|
1181
|
+
var ret = '';
|
|
1182
|
+
end = Math.min(buf.length, end);
|
|
1183
|
+
|
|
1184
|
+
for (var i = start; i < end; ++i) {
|
|
1185
|
+
ret += String.fromCharCode(buf[i] & 0x7F);
|
|
1186
|
+
}
|
|
1187
|
+
return ret
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
function latin1Slice (buf, start, end) {
|
|
1191
|
+
var ret = '';
|
|
1192
|
+
end = Math.min(buf.length, end);
|
|
1193
|
+
|
|
1194
|
+
for (var i = start; i < end; ++i) {
|
|
1195
|
+
ret += String.fromCharCode(buf[i]);
|
|
1196
|
+
}
|
|
1197
|
+
return ret
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
function hexSlice (buf, start, end) {
|
|
1201
|
+
var len = buf.length;
|
|
1202
|
+
|
|
1203
|
+
if (!start || start < 0) start = 0;
|
|
1204
|
+
if (!end || end < 0 || end > len) end = len;
|
|
1205
|
+
|
|
1206
|
+
var out = '';
|
|
1207
|
+
for (var i = start; i < end; ++i) {
|
|
1208
|
+
out += toHex(buf[i]);
|
|
1209
|
+
}
|
|
1210
|
+
return out
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
function utf16leSlice (buf, start, end) {
|
|
1214
|
+
var bytes = buf.slice(start, end);
|
|
1215
|
+
var res = '';
|
|
1216
|
+
for (var i = 0; i < bytes.length; i += 2) {
|
|
1217
|
+
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
|
|
1218
|
+
}
|
|
1219
|
+
return res
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
Buffer.prototype.slice = function slice (start, end) {
|
|
1223
|
+
var len = this.length;
|
|
1224
|
+
start = ~~start;
|
|
1225
|
+
end = end === undefined ? len : ~~end;
|
|
1226
|
+
|
|
1227
|
+
if (start < 0) {
|
|
1228
|
+
start += len;
|
|
1229
|
+
if (start < 0) start = 0;
|
|
1230
|
+
} else if (start > len) {
|
|
1231
|
+
start = len;
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
if (end < 0) {
|
|
1235
|
+
end += len;
|
|
1236
|
+
if (end < 0) end = 0;
|
|
1237
|
+
} else if (end > len) {
|
|
1238
|
+
end = len;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
if (end < start) end = start;
|
|
1242
|
+
|
|
1243
|
+
var newBuf;
|
|
1244
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1245
|
+
newBuf = this.subarray(start, end);
|
|
1246
|
+
newBuf.__proto__ = Buffer.prototype;
|
|
1247
|
+
} else {
|
|
1248
|
+
var sliceLen = end - start;
|
|
1249
|
+
newBuf = new Buffer(sliceLen, undefined);
|
|
1250
|
+
for (var i = 0; i < sliceLen; ++i) {
|
|
1251
|
+
newBuf[i] = this[i + start];
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
return newBuf
|
|
1256
|
+
};
|
|
1257
|
+
|
|
1258
|
+
/*
|
|
1259
|
+
* Need to make sure that buffer isn't trying to write out of bounds.
|
|
1260
|
+
*/
|
|
1261
|
+
function checkOffset (offset, ext, length) {
|
|
1262
|
+
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
|
1263
|
+
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
|
1267
|
+
offset = offset | 0;
|
|
1268
|
+
byteLength = byteLength | 0;
|
|
1269
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
1270
|
+
|
|
1271
|
+
var val = this[offset];
|
|
1272
|
+
var mul = 1;
|
|
1273
|
+
var i = 0;
|
|
1274
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
1275
|
+
val += this[offset + i] * mul;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
return val
|
|
1279
|
+
};
|
|
1280
|
+
|
|
1281
|
+
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
|
1282
|
+
offset = offset | 0;
|
|
1283
|
+
byteLength = byteLength | 0;
|
|
1284
|
+
if (!noAssert) {
|
|
1285
|
+
checkOffset(offset, byteLength, this.length);
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
var val = this[offset + --byteLength];
|
|
1289
|
+
var mul = 1;
|
|
1290
|
+
while (byteLength > 0 && (mul *= 0x100)) {
|
|
1291
|
+
val += this[offset + --byteLength] * mul;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
return val
|
|
1295
|
+
};
|
|
1296
|
+
|
|
1297
|
+
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
|
1298
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1299
|
+
return this[offset]
|
|
1300
|
+
};
|
|
1301
|
+
|
|
1302
|
+
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
|
1303
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1304
|
+
return this[offset] | (this[offset + 1] << 8)
|
|
1305
|
+
};
|
|
1306
|
+
|
|
1307
|
+
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
|
1308
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1309
|
+
return (this[offset] << 8) | this[offset + 1]
|
|
1310
|
+
};
|
|
1311
|
+
|
|
1312
|
+
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
|
1313
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1314
|
+
|
|
1315
|
+
return ((this[offset]) |
|
|
1316
|
+
(this[offset + 1] << 8) |
|
|
1317
|
+
(this[offset + 2] << 16)) +
|
|
1318
|
+
(this[offset + 3] * 0x1000000)
|
|
1319
|
+
};
|
|
1320
|
+
|
|
1321
|
+
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
|
1322
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1323
|
+
|
|
1324
|
+
return (this[offset] * 0x1000000) +
|
|
1325
|
+
((this[offset + 1] << 16) |
|
|
1326
|
+
(this[offset + 2] << 8) |
|
|
1327
|
+
this[offset + 3])
|
|
1328
|
+
};
|
|
1329
|
+
|
|
1330
|
+
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
|
|
1331
|
+
offset = offset | 0;
|
|
1332
|
+
byteLength = byteLength | 0;
|
|
1333
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
1334
|
+
|
|
1335
|
+
var val = this[offset];
|
|
1336
|
+
var mul = 1;
|
|
1337
|
+
var i = 0;
|
|
1338
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
1339
|
+
val += this[offset + i] * mul;
|
|
1340
|
+
}
|
|
1341
|
+
mul *= 0x80;
|
|
1342
|
+
|
|
1343
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
1344
|
+
|
|
1345
|
+
return val
|
|
1346
|
+
};
|
|
1347
|
+
|
|
1348
|
+
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
|
|
1349
|
+
offset = offset | 0;
|
|
1350
|
+
byteLength = byteLength | 0;
|
|
1351
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
1352
|
+
|
|
1353
|
+
var i = byteLength;
|
|
1354
|
+
var mul = 1;
|
|
1355
|
+
var val = this[offset + --i];
|
|
1356
|
+
while (i > 0 && (mul *= 0x100)) {
|
|
1357
|
+
val += this[offset + --i] * mul;
|
|
1358
|
+
}
|
|
1359
|
+
mul *= 0x80;
|
|
1360
|
+
|
|
1361
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
1362
|
+
|
|
1363
|
+
return val
|
|
1364
|
+
};
|
|
1365
|
+
|
|
1366
|
+
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
|
|
1367
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1368
|
+
if (!(this[offset] & 0x80)) return (this[offset])
|
|
1369
|
+
return ((0xff - this[offset] + 1) * -1)
|
|
1370
|
+
};
|
|
1371
|
+
|
|
1372
|
+
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
|
1373
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1374
|
+
var val = this[offset] | (this[offset + 1] << 8);
|
|
1375
|
+
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
1376
|
+
};
|
|
1377
|
+
|
|
1378
|
+
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
|
1379
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1380
|
+
var val = this[offset + 1] | (this[offset] << 8);
|
|
1381
|
+
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
1382
|
+
};
|
|
1383
|
+
|
|
1384
|
+
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
|
1385
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1386
|
+
|
|
1387
|
+
return (this[offset]) |
|
|
1388
|
+
(this[offset + 1] << 8) |
|
|
1389
|
+
(this[offset + 2] << 16) |
|
|
1390
|
+
(this[offset + 3] << 24)
|
|
1391
|
+
};
|
|
1392
|
+
|
|
1393
|
+
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
|
1394
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1395
|
+
|
|
1396
|
+
return (this[offset] << 24) |
|
|
1397
|
+
(this[offset + 1] << 16) |
|
|
1398
|
+
(this[offset + 2] << 8) |
|
|
1399
|
+
(this[offset + 3])
|
|
1400
|
+
};
|
|
1401
|
+
|
|
1402
|
+
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
|
1403
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1404
|
+
return read(this, offset, true, 23, 4)
|
|
1405
|
+
};
|
|
1406
|
+
|
|
1407
|
+
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
|
1408
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1409
|
+
return read(this, offset, false, 23, 4)
|
|
1410
|
+
};
|
|
1411
|
+
|
|
1412
|
+
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
|
1413
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1414
|
+
return read(this, offset, true, 52, 8)
|
|
1415
|
+
};
|
|
1416
|
+
|
|
1417
|
+
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
|
1418
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1419
|
+
return read(this, offset, false, 52, 8)
|
|
1420
|
+
};
|
|
1421
|
+
|
|
1422
|
+
function checkInt (buf, value, offset, ext, max, min) {
|
|
1423
|
+
if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
|
1424
|
+
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
|
1425
|
+
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
|
1429
|
+
value = +value;
|
|
1430
|
+
offset = offset | 0;
|
|
1431
|
+
byteLength = byteLength | 0;
|
|
1432
|
+
if (!noAssert) {
|
|
1433
|
+
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
1434
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
var mul = 1;
|
|
1438
|
+
var i = 0;
|
|
1439
|
+
this[offset] = value & 0xFF;
|
|
1440
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
1441
|
+
this[offset + i] = (value / mul) & 0xFF;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
return offset + byteLength
|
|
1445
|
+
};
|
|
1446
|
+
|
|
1447
|
+
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
|
1448
|
+
value = +value;
|
|
1449
|
+
offset = offset | 0;
|
|
1450
|
+
byteLength = byteLength | 0;
|
|
1451
|
+
if (!noAssert) {
|
|
1452
|
+
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
1453
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
var i = byteLength - 1;
|
|
1457
|
+
var mul = 1;
|
|
1458
|
+
this[offset + i] = value & 0xFF;
|
|
1459
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
|
1460
|
+
this[offset + i] = (value / mul) & 0xFF;
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
return offset + byteLength
|
|
1464
|
+
};
|
|
1465
|
+
|
|
1466
|
+
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
|
1467
|
+
value = +value;
|
|
1468
|
+
offset = offset | 0;
|
|
1469
|
+
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
|
|
1470
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
|
|
1471
|
+
this[offset] = (value & 0xff);
|
|
1472
|
+
return offset + 1
|
|
1473
|
+
};
|
|
1474
|
+
|
|
1475
|
+
function objectWriteUInt16 (buf, value, offset, littleEndian) {
|
|
1476
|
+
if (value < 0) value = 0xffff + value + 1;
|
|
1477
|
+
for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
|
|
1478
|
+
buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
|
|
1479
|
+
(littleEndian ? i : 1 - i) * 8;
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
|
|
1484
|
+
value = +value;
|
|
1485
|
+
offset = offset | 0;
|
|
1486
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
1487
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1488
|
+
this[offset] = (value & 0xff);
|
|
1489
|
+
this[offset + 1] = (value >>> 8);
|
|
1490
|
+
} else {
|
|
1491
|
+
objectWriteUInt16(this, value, offset, true);
|
|
1492
|
+
}
|
|
1493
|
+
return offset + 2
|
|
1494
|
+
};
|
|
1495
|
+
|
|
1496
|
+
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
|
1497
|
+
value = +value;
|
|
1498
|
+
offset = offset | 0;
|
|
1499
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
1500
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1501
|
+
this[offset] = (value >>> 8);
|
|
1502
|
+
this[offset + 1] = (value & 0xff);
|
|
1503
|
+
} else {
|
|
1504
|
+
objectWriteUInt16(this, value, offset, false);
|
|
1505
|
+
}
|
|
1506
|
+
return offset + 2
|
|
1507
|
+
};
|
|
1508
|
+
|
|
1509
|
+
function objectWriteUInt32 (buf, value, offset, littleEndian) {
|
|
1510
|
+
if (value < 0) value = 0xffffffff + value + 1;
|
|
1511
|
+
for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
|
|
1512
|
+
buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
|
|
1517
|
+
value = +value;
|
|
1518
|
+
offset = offset | 0;
|
|
1519
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
1520
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1521
|
+
this[offset + 3] = (value >>> 24);
|
|
1522
|
+
this[offset + 2] = (value >>> 16);
|
|
1523
|
+
this[offset + 1] = (value >>> 8);
|
|
1524
|
+
this[offset] = (value & 0xff);
|
|
1525
|
+
} else {
|
|
1526
|
+
objectWriteUInt32(this, value, offset, true);
|
|
1527
|
+
}
|
|
1528
|
+
return offset + 4
|
|
1529
|
+
};
|
|
1530
|
+
|
|
1531
|
+
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
|
|
1532
|
+
value = +value;
|
|
1533
|
+
offset = offset | 0;
|
|
1534
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
1535
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1536
|
+
this[offset] = (value >>> 24);
|
|
1537
|
+
this[offset + 1] = (value >>> 16);
|
|
1538
|
+
this[offset + 2] = (value >>> 8);
|
|
1539
|
+
this[offset + 3] = (value & 0xff);
|
|
1540
|
+
} else {
|
|
1541
|
+
objectWriteUInt32(this, value, offset, false);
|
|
1542
|
+
}
|
|
1543
|
+
return offset + 4
|
|
1544
|
+
};
|
|
1545
|
+
|
|
1546
|
+
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
|
1547
|
+
value = +value;
|
|
1548
|
+
offset = offset | 0;
|
|
1549
|
+
if (!noAssert) {
|
|
1550
|
+
var limit = Math.pow(2, 8 * byteLength - 1);
|
|
1551
|
+
|
|
1552
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
var i = 0;
|
|
1556
|
+
var mul = 1;
|
|
1557
|
+
var sub = 0;
|
|
1558
|
+
this[offset] = value & 0xFF;
|
|
1559
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
1560
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
1561
|
+
sub = 1;
|
|
1562
|
+
}
|
|
1563
|
+
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
return offset + byteLength
|
|
1567
|
+
};
|
|
1568
|
+
|
|
1569
|
+
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
|
1570
|
+
value = +value;
|
|
1571
|
+
offset = offset | 0;
|
|
1572
|
+
if (!noAssert) {
|
|
1573
|
+
var limit = Math.pow(2, 8 * byteLength - 1);
|
|
1574
|
+
|
|
1575
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
var i = byteLength - 1;
|
|
1579
|
+
var mul = 1;
|
|
1580
|
+
var sub = 0;
|
|
1581
|
+
this[offset + i] = value & 0xFF;
|
|
1582
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
|
1583
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
1584
|
+
sub = 1;
|
|
1585
|
+
}
|
|
1586
|
+
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
return offset + byteLength
|
|
1590
|
+
};
|
|
1591
|
+
|
|
1592
|
+
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
|
1593
|
+
value = +value;
|
|
1594
|
+
offset = offset | 0;
|
|
1595
|
+
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
|
|
1596
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
|
|
1597
|
+
if (value < 0) value = 0xff + value + 1;
|
|
1598
|
+
this[offset] = (value & 0xff);
|
|
1599
|
+
return offset + 1
|
|
1600
|
+
};
|
|
1601
|
+
|
|
1602
|
+
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
|
1603
|
+
value = +value;
|
|
1604
|
+
offset = offset | 0;
|
|
1605
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
|
|
1606
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1607
|
+
this[offset] = (value & 0xff);
|
|
1608
|
+
this[offset + 1] = (value >>> 8);
|
|
1609
|
+
} else {
|
|
1610
|
+
objectWriteUInt16(this, value, offset, true);
|
|
1611
|
+
}
|
|
1612
|
+
return offset + 2
|
|
1613
|
+
};
|
|
1614
|
+
|
|
1615
|
+
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
|
1616
|
+
value = +value;
|
|
1617
|
+
offset = offset | 0;
|
|
1618
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
|
|
1619
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1620
|
+
this[offset] = (value >>> 8);
|
|
1621
|
+
this[offset + 1] = (value & 0xff);
|
|
1622
|
+
} else {
|
|
1623
|
+
objectWriteUInt16(this, value, offset, false);
|
|
1624
|
+
}
|
|
1625
|
+
return offset + 2
|
|
1626
|
+
};
|
|
1627
|
+
|
|
1628
|
+
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
|
1629
|
+
value = +value;
|
|
1630
|
+
offset = offset | 0;
|
|
1631
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
|
|
1632
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1633
|
+
this[offset] = (value & 0xff);
|
|
1634
|
+
this[offset + 1] = (value >>> 8);
|
|
1635
|
+
this[offset + 2] = (value >>> 16);
|
|
1636
|
+
this[offset + 3] = (value >>> 24);
|
|
1637
|
+
} else {
|
|
1638
|
+
objectWriteUInt32(this, value, offset, true);
|
|
1639
|
+
}
|
|
1640
|
+
return offset + 4
|
|
1641
|
+
};
|
|
1642
|
+
|
|
1643
|
+
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
|
1644
|
+
value = +value;
|
|
1645
|
+
offset = offset | 0;
|
|
1646
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
|
|
1647
|
+
if (value < 0) value = 0xffffffff + value + 1;
|
|
1648
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1649
|
+
this[offset] = (value >>> 24);
|
|
1650
|
+
this[offset + 1] = (value >>> 16);
|
|
1651
|
+
this[offset + 2] = (value >>> 8);
|
|
1652
|
+
this[offset + 3] = (value & 0xff);
|
|
1653
|
+
} else {
|
|
1654
|
+
objectWriteUInt32(this, value, offset, false);
|
|
1655
|
+
}
|
|
1656
|
+
return offset + 4
|
|
1657
|
+
};
|
|
1658
|
+
|
|
1659
|
+
function checkIEEE754 (buf, value, offset, ext, max, min) {
|
|
1660
|
+
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
1661
|
+
if (offset < 0) throw new RangeError('Index out of range')
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
|
1665
|
+
if (!noAssert) {
|
|
1666
|
+
checkIEEE754(buf, value, offset, 4);
|
|
1667
|
+
}
|
|
1668
|
+
write(buf, value, offset, littleEndian, 23, 4);
|
|
1669
|
+
return offset + 4
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
|
1673
|
+
return writeFloat(this, value, offset, true, noAssert)
|
|
1674
|
+
};
|
|
1675
|
+
|
|
1676
|
+
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
|
1677
|
+
return writeFloat(this, value, offset, false, noAssert)
|
|
1678
|
+
};
|
|
1679
|
+
|
|
1680
|
+
function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
|
1681
|
+
if (!noAssert) {
|
|
1682
|
+
checkIEEE754(buf, value, offset, 8);
|
|
1683
|
+
}
|
|
1684
|
+
write(buf, value, offset, littleEndian, 52, 8);
|
|
1685
|
+
return offset + 8
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
|
1689
|
+
return writeDouble(this, value, offset, true, noAssert)
|
|
1690
|
+
};
|
|
1691
|
+
|
|
1692
|
+
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
|
1693
|
+
return writeDouble(this, value, offset, false, noAssert)
|
|
1694
|
+
};
|
|
1695
|
+
|
|
1696
|
+
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
|
1697
|
+
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
|
1698
|
+
if (!start) start = 0;
|
|
1699
|
+
if (!end && end !== 0) end = this.length;
|
|
1700
|
+
if (targetStart >= target.length) targetStart = target.length;
|
|
1701
|
+
if (!targetStart) targetStart = 0;
|
|
1702
|
+
if (end > 0 && end < start) end = start;
|
|
1703
|
+
|
|
1704
|
+
// Copy 0 bytes; we're done
|
|
1705
|
+
if (end === start) return 0
|
|
1706
|
+
if (target.length === 0 || this.length === 0) return 0
|
|
1707
|
+
|
|
1708
|
+
// Fatal error conditions
|
|
1709
|
+
if (targetStart < 0) {
|
|
1710
|
+
throw new RangeError('targetStart out of bounds')
|
|
1711
|
+
}
|
|
1712
|
+
if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
|
|
1713
|
+
if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
|
1714
|
+
|
|
1715
|
+
// Are we oob?
|
|
1716
|
+
if (end > this.length) end = this.length;
|
|
1717
|
+
if (target.length - targetStart < end - start) {
|
|
1718
|
+
end = target.length - targetStart + start;
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
var len = end - start;
|
|
1722
|
+
var i;
|
|
1723
|
+
|
|
1724
|
+
if (this === target && start < targetStart && targetStart < end) {
|
|
1725
|
+
// descending copy from end
|
|
1726
|
+
for (i = len - 1; i >= 0; --i) {
|
|
1727
|
+
target[i + targetStart] = this[i + start];
|
|
1728
|
+
}
|
|
1729
|
+
} else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1730
|
+
// ascending copy from start
|
|
1731
|
+
for (i = 0; i < len; ++i) {
|
|
1732
|
+
target[i + targetStart] = this[i + start];
|
|
1733
|
+
}
|
|
1734
|
+
} else {
|
|
1735
|
+
Uint8Array.prototype.set.call(
|
|
1736
|
+
target,
|
|
1737
|
+
this.subarray(start, start + len),
|
|
1738
|
+
targetStart
|
|
1739
|
+
);
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
return len
|
|
1743
|
+
};
|
|
1744
|
+
|
|
1745
|
+
// Usage:
|
|
1746
|
+
// buffer.fill(number[, offset[, end]])
|
|
1747
|
+
// buffer.fill(buffer[, offset[, end]])
|
|
1748
|
+
// buffer.fill(string[, offset[, end]][, encoding])
|
|
1749
|
+
Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
|
1750
|
+
// Handle string cases:
|
|
1751
|
+
if (typeof val === 'string') {
|
|
1752
|
+
if (typeof start === 'string') {
|
|
1753
|
+
encoding = start;
|
|
1754
|
+
start = 0;
|
|
1755
|
+
end = this.length;
|
|
1756
|
+
} else if (typeof end === 'string') {
|
|
1757
|
+
encoding = end;
|
|
1758
|
+
end = this.length;
|
|
1759
|
+
}
|
|
1760
|
+
if (val.length === 1) {
|
|
1761
|
+
var code = val.charCodeAt(0);
|
|
1762
|
+
if (code < 256) {
|
|
1763
|
+
val = code;
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
if (encoding !== undefined && typeof encoding !== 'string') {
|
|
1767
|
+
throw new TypeError('encoding must be a string')
|
|
1768
|
+
}
|
|
1769
|
+
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
|
1770
|
+
throw new TypeError('Unknown encoding: ' + encoding)
|
|
1771
|
+
}
|
|
1772
|
+
} else if (typeof val === 'number') {
|
|
1773
|
+
val = val & 255;
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
// Invalid ranges are not set to a default, so can range check early.
|
|
1777
|
+
if (start < 0 || this.length < start || this.length < end) {
|
|
1778
|
+
throw new RangeError('Out of range index')
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
if (end <= start) {
|
|
1782
|
+
return this
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
start = start >>> 0;
|
|
1786
|
+
end = end === undefined ? this.length : end >>> 0;
|
|
1787
|
+
|
|
1788
|
+
if (!val) val = 0;
|
|
1789
|
+
|
|
1790
|
+
var i;
|
|
1791
|
+
if (typeof val === 'number') {
|
|
1792
|
+
for (i = start; i < end; ++i) {
|
|
1793
|
+
this[i] = val;
|
|
1794
|
+
}
|
|
1795
|
+
} else {
|
|
1796
|
+
var bytes = internalIsBuffer(val)
|
|
1797
|
+
? val
|
|
1798
|
+
: utf8ToBytes(new Buffer(val, encoding).toString());
|
|
1799
|
+
var len = bytes.length;
|
|
1800
|
+
for (i = 0; i < end - start; ++i) {
|
|
1801
|
+
this[i + start] = bytes[i % len];
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1805
|
+
return this
|
|
1806
|
+
};
|
|
1807
|
+
|
|
1808
|
+
// HELPER FUNCTIONS
|
|
1809
|
+
// ================
|
|
1810
|
+
|
|
1811
|
+
var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
|
|
1812
|
+
|
|
1813
|
+
function base64clean (str) {
|
|
1814
|
+
// Node strips out invalid characters like \n and \t from the string, base64-js does not
|
|
1815
|
+
str = stringtrim(str).replace(INVALID_BASE64_RE, '');
|
|
1816
|
+
// Node converts strings with length < 2 to ''
|
|
1817
|
+
if (str.length < 2) return ''
|
|
1818
|
+
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
|
1819
|
+
while (str.length % 4 !== 0) {
|
|
1820
|
+
str = str + '=';
|
|
1821
|
+
}
|
|
1822
|
+
return str
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
function stringtrim (str) {
|
|
1826
|
+
if (str.trim) return str.trim()
|
|
1827
|
+
return str.replace(/^\s+|\s+$/g, '')
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
function toHex (n) {
|
|
1831
|
+
if (n < 16) return '0' + n.toString(16)
|
|
1832
|
+
return n.toString(16)
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
function utf8ToBytes (string, units) {
|
|
1836
|
+
units = units || Infinity;
|
|
1837
|
+
var codePoint;
|
|
1838
|
+
var length = string.length;
|
|
1839
|
+
var leadSurrogate = null;
|
|
1840
|
+
var bytes = [];
|
|
1841
|
+
|
|
1842
|
+
for (var i = 0; i < length; ++i) {
|
|
1843
|
+
codePoint = string.charCodeAt(i);
|
|
1844
|
+
|
|
1845
|
+
// is surrogate component
|
|
1846
|
+
if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
|
1847
|
+
// last char was a lead
|
|
1848
|
+
if (!leadSurrogate) {
|
|
1849
|
+
// no lead yet
|
|
1850
|
+
if (codePoint > 0xDBFF) {
|
|
1851
|
+
// unexpected trail
|
|
1852
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
1853
|
+
continue
|
|
1854
|
+
} else if (i + 1 === length) {
|
|
1855
|
+
// unpaired lead
|
|
1856
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
1857
|
+
continue
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
// valid lead
|
|
1861
|
+
leadSurrogate = codePoint;
|
|
1862
|
+
|
|
1863
|
+
continue
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1866
|
+
// 2 leads in a row
|
|
1867
|
+
if (codePoint < 0xDC00) {
|
|
1868
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
1869
|
+
leadSurrogate = codePoint;
|
|
1870
|
+
continue
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
// valid surrogate pair
|
|
1874
|
+
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
|
|
1875
|
+
} else if (leadSurrogate) {
|
|
1876
|
+
// valid bmp char, but last char was a lead
|
|
1877
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
leadSurrogate = null;
|
|
1881
|
+
|
|
1882
|
+
// encode utf8
|
|
1883
|
+
if (codePoint < 0x80) {
|
|
1884
|
+
if ((units -= 1) < 0) break
|
|
1885
|
+
bytes.push(codePoint);
|
|
1886
|
+
} else if (codePoint < 0x800) {
|
|
1887
|
+
if ((units -= 2) < 0) break
|
|
1888
|
+
bytes.push(
|
|
1889
|
+
codePoint >> 0x6 | 0xC0,
|
|
1890
|
+
codePoint & 0x3F | 0x80
|
|
1891
|
+
);
|
|
1892
|
+
} else if (codePoint < 0x10000) {
|
|
1893
|
+
if ((units -= 3) < 0) break
|
|
1894
|
+
bytes.push(
|
|
1895
|
+
codePoint >> 0xC | 0xE0,
|
|
1896
|
+
codePoint >> 0x6 & 0x3F | 0x80,
|
|
1897
|
+
codePoint & 0x3F | 0x80
|
|
1898
|
+
);
|
|
1899
|
+
} else if (codePoint < 0x110000) {
|
|
1900
|
+
if ((units -= 4) < 0) break
|
|
1901
|
+
bytes.push(
|
|
1902
|
+
codePoint >> 0x12 | 0xF0,
|
|
1903
|
+
codePoint >> 0xC & 0x3F | 0x80,
|
|
1904
|
+
codePoint >> 0x6 & 0x3F | 0x80,
|
|
1905
|
+
codePoint & 0x3F | 0x80
|
|
1906
|
+
);
|
|
1907
|
+
} else {
|
|
1908
|
+
throw new Error('Invalid code point')
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
return bytes
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
function asciiToBytes (str) {
|
|
1916
|
+
var byteArray = [];
|
|
1917
|
+
for (var i = 0; i < str.length; ++i) {
|
|
1918
|
+
// Node's code seems to be doing this and not & 0x7F..
|
|
1919
|
+
byteArray.push(str.charCodeAt(i) & 0xFF);
|
|
1920
|
+
}
|
|
1921
|
+
return byteArray
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
function utf16leToBytes (str, units) {
|
|
1925
|
+
var c, hi, lo;
|
|
1926
|
+
var byteArray = [];
|
|
1927
|
+
for (var i = 0; i < str.length; ++i) {
|
|
1928
|
+
if ((units -= 2) < 0) break
|
|
1929
|
+
|
|
1930
|
+
c = str.charCodeAt(i);
|
|
1931
|
+
hi = c >> 8;
|
|
1932
|
+
lo = c % 256;
|
|
1933
|
+
byteArray.push(lo);
|
|
1934
|
+
byteArray.push(hi);
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
return byteArray
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
|
|
1941
|
+
function base64ToBytes (str) {
|
|
1942
|
+
return toByteArray(base64clean(str))
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
function blitBuffer (src, dst, offset, length) {
|
|
1946
|
+
for (var i = 0; i < length; ++i) {
|
|
1947
|
+
if ((i + offset >= dst.length) || (i >= src.length)) break
|
|
1948
|
+
dst[i + offset] = src[i];
|
|
1949
|
+
}
|
|
1950
|
+
return i
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
function isnan (val) {
|
|
1954
|
+
return val !== val // eslint-disable-line no-self-compare
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
|
|
1958
|
+
// the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
|
|
1959
|
+
// The _isBuffer check is for Safari 5-7 support, because it's missing
|
|
1960
|
+
// Object.prototype.constructor. Remove this eventually
|
|
1961
|
+
function isBuffer$1(obj) {
|
|
1962
|
+
return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
function isFastBuffer (obj) {
|
|
1966
|
+
return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
// For Node v0.10 support. Remove this eventually.
|
|
1970
|
+
function isSlowBuffer (obj) {
|
|
1971
|
+
return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
/* tslint:disable:no-bitwise */
|
|
1975
|
+
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
1976
|
+
// Regular expression to check formal correctness of base64 encoded strings
|
|
1977
|
+
var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
|
1978
|
+
/**
|
|
1979
|
+
* Simplified, Node/Browser-safe alternative to atob() for base64 decoding.
|
|
1980
|
+
* Modified from https://github.com/MaxArt2501/base64-js/blob/master/base64.js
|
|
1981
|
+
*/
|
|
1982
|
+
var AtoB = function (str) {
|
|
1983
|
+
// atob can work with strings with whitespaces, even inside the encoded part,
|
|
1984
|
+
// but only \t, \n, \f, \r and ' ', which can be stripped.
|
|
1985
|
+
str = String(str).replace(/[\t\n\f\r ]+/g, '');
|
|
1986
|
+
if (!b64re.test(str))
|
|
1987
|
+
throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
|
|
1988
|
+
// Adding the padding if missing, for semplicity
|
|
1989
|
+
str += '=='.slice(2 - (str.length & 3));
|
|
1990
|
+
var bitmap;
|
|
1991
|
+
var result = '';
|
|
1992
|
+
var r1;
|
|
1993
|
+
var r2;
|
|
1994
|
+
var i = 0;
|
|
1995
|
+
for (; i < str.length;) {
|
|
1996
|
+
bitmap =
|
|
1997
|
+
(b64.indexOf(str.charAt(i++)) << 18) |
|
|
1998
|
+
(b64.indexOf(str.charAt(i++)) << 12) |
|
|
1999
|
+
((r1 = b64.indexOf(str.charAt(i++))) << 6) |
|
|
2000
|
+
(r2 = b64.indexOf(str.charAt(i++)));
|
|
2001
|
+
result +=
|
|
2002
|
+
r1 === 64
|
|
2003
|
+
? String.fromCharCode((bitmap >> 16) & 255)
|
|
2004
|
+
: r2 === 64
|
|
2005
|
+
? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255)
|
|
2006
|
+
: String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255, bitmap & 255);
|
|
2007
|
+
}
|
|
2008
|
+
return result;
|
|
2009
|
+
};
|
|
2010
|
+
/**
|
|
2011
|
+
* Decode the body of a JWT. This helper may allow front-end applications to avoid a dependency on `jsonwebtoken` in
|
|
2012
|
+
* many cases. Note that this should only be used for true JWTs. Opaque tokens will cause this to throw.
|
|
2013
|
+
*/
|
|
2014
|
+
var decodeJWTBody = function (token) { return JSON.parse(AtoB((token || '').split('.')[1] || '')); };
|
|
2015
|
+
/**
|
|
2016
|
+
* Decode the body of an Verdocs access token. Note that raw tokens contain namespaced fields, e.g.
|
|
2017
|
+
* `https://verdocs.com/profile_id`. To make these tokens easier to use in front-end code, this name-spacing
|
|
2018
|
+
* will be removed. Note that user and signing sessions have different access token formats. The calling
|
|
2019
|
+
* application should distinguish between the two based on the context of the authenticated session, or by
|
|
2020
|
+
* the presence of the `document_id` field, which will only be present for signing sessions.
|
|
2021
|
+
*/
|
|
2022
|
+
var decodeAccessTokenBody = function (token) {
|
|
2023
|
+
var decoded;
|
|
2024
|
+
try {
|
|
2025
|
+
decoded = decodeJWTBody(token);
|
|
2026
|
+
if (decoded === null) {
|
|
2027
|
+
return null;
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
catch (e) {
|
|
2031
|
+
return null;
|
|
2032
|
+
}
|
|
2033
|
+
Object.keys(decoded).forEach(function (key) {
|
|
2034
|
+
if (typeof key === 'string' && key.startsWith('https://verdocs.com/')) {
|
|
2035
|
+
decoded[key.replace('https://verdocs.com/', '')] = decoded[key];
|
|
2036
|
+
delete decoded[key];
|
|
2037
|
+
}
|
|
2038
|
+
});
|
|
2039
|
+
return decoded;
|
|
2040
|
+
};
|
|
2041
|
+
|
|
2042
|
+
var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2043
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
2044
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
2045
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
2046
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
2047
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
2048
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2049
|
+
});
|
|
2050
|
+
};
|
|
2051
|
+
var __generator$1 = (undefined && undefined.__generator) || function (thisArg, body) {
|
|
2052
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
2053
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
2054
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
2055
|
+
function step(op) {
|
|
2056
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
2057
|
+
while (_) try {
|
|
2058
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
2059
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
2060
|
+
switch (op[0]) {
|
|
2061
|
+
case 0: case 1: t = op; break;
|
|
2062
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
2063
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
2064
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
2065
|
+
default:
|
|
2066
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
2067
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
2068
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
2069
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
2070
|
+
if (t[2]) _.ops.pop();
|
|
2071
|
+
_.trys.pop(); continue;
|
|
2072
|
+
}
|
|
2073
|
+
op = body.call(thisArg, _);
|
|
2074
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
2075
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
2076
|
+
}
|
|
2077
|
+
};
|
|
2078
|
+
/**
|
|
2079
|
+
* Get a summary of currently active documents.
|
|
2080
|
+
*
|
|
2081
|
+
* ```typescript
|
|
2082
|
+
* import {Documents} from '@verdocs/js-sdk/Documents';
|
|
2083
|
+
*
|
|
2084
|
+
* const {action_required, completed, waiting_on_others} = await Documents.getSummary();
|
|
2085
|
+
* ```
|
|
2086
|
+
*/
|
|
2087
|
+
var getSummary = function (endpoint, page) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2088
|
+
return __generator$1(this, function (_a) {
|
|
2089
|
+
return [2 /*return*/, endpoint.api //
|
|
2090
|
+
.post('/documents/summary', { page: page })
|
|
2091
|
+
.then(function (r) { return r.data; })];
|
|
2092
|
+
});
|
|
2093
|
+
}); };
|
|
2094
|
+
/**
|
|
2095
|
+
* Search for documents matching various criteria.
|
|
2096
|
+
*
|
|
2097
|
+
* ```typescript
|
|
2098
|
+
* import {Documents} from '@verdocs/js-sdk/Documents';
|
|
2099
|
+
*
|
|
2100
|
+
* const {result, page, total} = await Documents.search({ ... });
|
|
2101
|
+
* ```
|
|
2102
|
+
*/
|
|
2103
|
+
var searchDocuments = function (endpoint, params) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2104
|
+
return __generator$1(this, function (_a) {
|
|
2105
|
+
return [2 /*return*/, endpoint.api //
|
|
2106
|
+
.post('/documents/search', params)
|
|
2107
|
+
.then(function (r) { return r.data; })];
|
|
2108
|
+
});
|
|
2109
|
+
}); };
|
|
2110
|
+
/**
|
|
2111
|
+
* Get a signing session for a Document.
|
|
2112
|
+
*/
|
|
2113
|
+
var getSigningSession = function (endpoint, params) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2114
|
+
return __generator$1(this, function (_a) {
|
|
2115
|
+
return [2 /*return*/, endpoint.api //
|
|
2116
|
+
.get("/documents/".concat(params.documentId, "/recipients/").concat(encodeURIComponent(params.roleId), "/invitation/").concat(params.inviteCode))
|
|
2117
|
+
.then(function (r) {
|
|
2118
|
+
var _a, _b;
|
|
2119
|
+
// Avoiding a jsonwebtoken dependency here - we don't actually need the whole library
|
|
2120
|
+
var signerToken = ((_a = r.headers) === null || _a === void 0 ? void 0 : _a.signer_token) || '';
|
|
2121
|
+
var session = decodeAccessTokenBody(signerToken);
|
|
2122
|
+
endpoint.setToken((_b = r.headers) === null || _b === void 0 ? void 0 : _b.signer_token);
|
|
2123
|
+
return { recipient: r.data, session: session, signerToken: signerToken };
|
|
2124
|
+
})];
|
|
2125
|
+
});
|
|
2126
|
+
}); };
|
|
2127
|
+
/**
|
|
2128
|
+
* Get the list of recipients for a Document.
|
|
2129
|
+
*/
|
|
2130
|
+
var getDocumentRecipients = function (endpoint, documentId) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2131
|
+
return __generator$1(this, function (_a) {
|
|
2132
|
+
return [2 /*return*/, endpoint.api //
|
|
2133
|
+
.get("/documents/".concat(documentId, "/recipients"))
|
|
2134
|
+
.then(function (r) { return r.data; })];
|
|
2135
|
+
});
|
|
2136
|
+
}); };
|
|
2137
|
+
/**
|
|
2138
|
+
* Get all metadata for a Document.
|
|
2139
|
+
*/
|
|
2140
|
+
var getDocument = function (endpoint, documentId) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2141
|
+
return __generator$1(this, function (_a) {
|
|
2142
|
+
return [2 /*return*/, endpoint.api //
|
|
2143
|
+
.get("/documents/".concat(documentId))
|
|
2144
|
+
.then(function (r) { return r.data; })];
|
|
2145
|
+
});
|
|
2146
|
+
}); };
|
|
2147
|
+
/**
|
|
2148
|
+
* Get (binary download) a file attached to a Document.
|
|
2149
|
+
*/
|
|
2150
|
+
var getDocumentFile = function (endpoint, documentId, envelopeDocumentId) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2151
|
+
return __generator$1(this, function (_a) {
|
|
2152
|
+
return [2 /*return*/, endpoint.api //
|
|
2153
|
+
.get("/documents/".concat(documentId, "/envelope_documents/").concat(envelopeDocumentId, "?file=true"), {
|
|
2154
|
+
responseType: 'arraybuffer',
|
|
2155
|
+
})
|
|
2156
|
+
.then(function (r) { return Buffer.from(r.data, 'binary').toString('base64'); })];
|
|
2157
|
+
});
|
|
2158
|
+
}); };
|
|
2159
|
+
/**
|
|
2160
|
+
* Update a Document field. Typically called during the signing process as a Recipient fills in fields.
|
|
2161
|
+
*/
|
|
2162
|
+
var updateDocumentField = function (endpoint, documentId, fieldName, value) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2163
|
+
return __generator$1(this, function (_a) {
|
|
2164
|
+
return [2 /*return*/, endpoint.api //
|
|
2165
|
+
.put("/documents/".concat(documentId, "/fields/").concat(fieldName), value)
|
|
2166
|
+
.then(function (r) { return r.data; })];
|
|
2167
|
+
});
|
|
2168
|
+
}); };
|
|
2169
|
+
/**
|
|
2170
|
+
* Update a Document signature field. Signature fields are ID-driven. Call `Document.createSignature()` first to create a
|
|
2171
|
+
* signature for a Recipient, then call `Documents.updateDocumentFieldSignature()` to attach it to a field.
|
|
2172
|
+
*/
|
|
2173
|
+
var updateDocumentFieldSignature = function (endpoint, documentId, fieldName, signatureId) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2174
|
+
return __generator$1(this, function (_a) {
|
|
2175
|
+
return [2 /*return*/, endpoint.api //
|
|
2176
|
+
.put("/documents/".concat(documentId, "/fields/").concat(fieldName, "/signature/").concat(signatureId))
|
|
2177
|
+
.then(function (r) { return r.data; })];
|
|
2178
|
+
});
|
|
2179
|
+
}); };
|
|
2180
|
+
|
|
2181
|
+
const Documents$1 = /*#__PURE__*/Object.freeze({
|
|
2182
|
+
__proto__: null,
|
|
2183
|
+
getSummary: getSummary,
|
|
2184
|
+
searchDocuments: searchDocuments,
|
|
2185
|
+
getSigningSession: getSigningSession,
|
|
2186
|
+
getDocumentRecipients: getDocumentRecipients,
|
|
2187
|
+
getDocument: getDocument,
|
|
2188
|
+
getDocumentFile: getDocumentFile,
|
|
2189
|
+
updateDocumentField: updateDocumentField,
|
|
2190
|
+
updateDocumentFieldSignature: updateDocumentFieldSignature
|
|
2191
|
+
});
|
|
2192
|
+
|
|
2193
|
+
var __assign = (undefined && undefined.__assign) || function () {
|
|
2194
|
+
__assign = Object.assign || function(t) {
|
|
2195
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
2196
|
+
s = arguments[i];
|
|
2197
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
2198
|
+
t[p] = s[p];
|
|
2199
|
+
}
|
|
2200
|
+
return t;
|
|
2201
|
+
};
|
|
2202
|
+
return __assign.apply(this, arguments);
|
|
2203
|
+
};
|
|
2204
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2205
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
2206
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
2207
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
2208
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
2209
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
2210
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2211
|
+
});
|
|
2212
|
+
};
|
|
2213
|
+
var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
|
|
2214
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
2215
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
2216
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
2217
|
+
function step(op) {
|
|
2218
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
2219
|
+
while (_) try {
|
|
2220
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
2221
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
2222
|
+
switch (op[0]) {
|
|
2223
|
+
case 0: case 1: t = op; break;
|
|
2224
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
2225
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
2226
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
2227
|
+
default:
|
|
2228
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
2229
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
2230
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
2231
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
2232
|
+
if (t[2]) _.ops.pop();
|
|
2233
|
+
_.trys.pop(); continue;
|
|
2234
|
+
}
|
|
2235
|
+
op = body.call(thisArg, _);
|
|
2236
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
2237
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
2238
|
+
}
|
|
2239
|
+
};
|
|
2240
|
+
/**
|
|
2241
|
+
* Update a recipient's status block
|
|
2242
|
+
*/
|
|
2243
|
+
var updateRecipientStatus = function (endpoint, documentId, roleName, action, params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2244
|
+
return __generator(this, function (_a) {
|
|
2245
|
+
return [2 /*return*/, endpoint.api //
|
|
2246
|
+
.put("/documents/".concat(documentId, "/recipients/").concat(roleName), __assign({ role_name: roleName, action: action }, (params || {})))
|
|
2247
|
+
.then(function (r) { return r.data; })];
|
|
2248
|
+
});
|
|
2249
|
+
}); };
|
|
2250
|
+
|
|
2251
|
+
const Recipients = /*#__PURE__*/Object.freeze({
|
|
2252
|
+
__proto__: null,
|
|
2253
|
+
updateRecipientStatus: updateRecipientStatus
|
|
2254
|
+
});
|
|
2255
|
+
|
|
2256
|
+
/**
|
|
2257
|
+
* Create a signature block. In a typical signing workflow, the user is asked at the beginning of the process to "adopt"
|
|
2258
|
+
* a signature block to be used for all signature fields in the document. Thus, this is typically called one time to
|
|
2259
|
+
* create and store a signature block. Thereafter, the ID of the signature block may be re-used for each signature field
|
|
2260
|
+
* to be "stamped" by the user.
|
|
2261
|
+
*/
|
|
2262
|
+
var createSignature = function (endpoint, name, signature) {
|
|
2263
|
+
var data = new FormData();
|
|
2264
|
+
data.append('signature', signature, name);
|
|
2265
|
+
return endpoint.api //
|
|
2266
|
+
.post("/signatures", data)
|
|
2267
|
+
.then(function (r) { return r.data; });
|
|
2268
|
+
};
|
|
2269
|
+
/**
|
|
2270
|
+
* Get the availbable signatures for a user.
|
|
2271
|
+
*/
|
|
2272
|
+
var getSignatures = function (endpoint) {
|
|
2273
|
+
return endpoint.api //
|
|
2274
|
+
.get('/signatures')
|
|
2275
|
+
.then(function (r) { return r.data; });
|
|
2276
|
+
};
|
|
2277
|
+
/**
|
|
2278
|
+
* Get a user's signature by ID.
|
|
2279
|
+
*/
|
|
2280
|
+
var getSignature = function (endpoint, signatureId) {
|
|
2281
|
+
return endpoint.api //
|
|
2282
|
+
.get("/signatures/".concat(signatureId))
|
|
2283
|
+
.then(function (r) { return r.data; });
|
|
2284
|
+
};
|
|
2285
|
+
/**
|
|
2286
|
+
* Delete a user's signature.
|
|
2287
|
+
*/
|
|
2288
|
+
var deleteSignature = function (endpoint, signatureId) {
|
|
2289
|
+
return endpoint.api //
|
|
2290
|
+
.delete("/signatures/".concat(signatureId))
|
|
2291
|
+
.then(function (r) { return r.data; });
|
|
2292
|
+
};
|
|
2293
|
+
|
|
2294
|
+
const Signatures = /*#__PURE__*/Object.freeze({
|
|
2295
|
+
__proto__: null,
|
|
2296
|
+
createSignature: createSignature,
|
|
2297
|
+
getSignatures: getSignatures,
|
|
2298
|
+
getSignature: getSignature,
|
|
2299
|
+
deleteSignature: deleteSignature
|
|
2300
|
+
});
|
|
2301
|
+
|
|
2302
|
+
/**
|
|
2303
|
+
* Create an initials block. In a typical signing workflow, the user is asked at the beginning of the process to "adopt"
|
|
2304
|
+
* an initials block to be used for all initials fields in the document. Thus, this is typically called one time to
|
|
2305
|
+
* create and store an initials block. Thereafter, the ID of the initials block may be re-used for each initials field
|
|
2306
|
+
* to be "stamped" by the user.
|
|
2307
|
+
*/
|
|
2308
|
+
var createInitials = function (endpoint, name, initials) {
|
|
2309
|
+
var data = new FormData();
|
|
2310
|
+
data.append('initial', initials, name);
|
|
2311
|
+
return endpoint.api //
|
|
2312
|
+
.post("/initials", data)
|
|
2313
|
+
.then(function (r) { return r.data; });
|
|
2314
|
+
};
|
|
2315
|
+
|
|
2316
|
+
const Initials = /*#__PURE__*/Object.freeze({
|
|
2317
|
+
__proto__: null,
|
|
2318
|
+
createInitials: createInitials
|
|
2319
|
+
});
|
|
2320
|
+
|
|
2321
|
+
const Types = /*#__PURE__*/Object.freeze({
|
|
2322
|
+
__proto__: null
|
|
2323
|
+
});
|
|
2324
|
+
|
|
2325
|
+
const Documents = /*#__PURE__*/Object.freeze({
|
|
2326
|
+
__proto__: null,
|
|
2327
|
+
Documents: Documents$1,
|
|
2328
|
+
Recipients: Recipients,
|
|
2329
|
+
Signatures: Signatures,
|
|
2330
|
+
Initials: Initials,
|
|
2331
|
+
Types: Types
|
|
2332
|
+
});
|
|
2333
|
+
|
|
2334
|
+
var TemplatePermissions;
|
|
2335
|
+
(function (TemplatePermissions) {
|
|
2336
|
+
TemplatePermissions["TEMPLATE_CREATOR_CREATE_PUBLIC"] = "template:creator:create:public";
|
|
2337
|
+
TemplatePermissions["TEMPLATE_CREATOR_CREATE_ORG"] = "template:creator:create:org";
|
|
2338
|
+
TemplatePermissions["TEMPLATE_CREATOR_CREATE_PERSONAL"] = "template:creator:create:personal";
|
|
2339
|
+
TemplatePermissions["TEMPLATE_CREATOR_DELETE"] = "template:creator:delete";
|
|
2340
|
+
TemplatePermissions["TEMPLATE_CREATOR_VISIBILITY"] = "template:creator:visibility";
|
|
2341
|
+
TemplatePermissions["TEMPLATE_MEMBER_READ"] = "template:member:read";
|
|
2342
|
+
TemplatePermissions["TEMPLATE_MEMBER_WRITE"] = "template:member:write";
|
|
2343
|
+
TemplatePermissions["TEMPLATE_MEMBER_DELETE"] = "template:member:delete";
|
|
2344
|
+
TemplatePermissions["TEMPLATE_MEMBER_VISIBILITY"] = "template:member:visibility";
|
|
2345
|
+
})(TemplatePermissions || (TemplatePermissions = {}));
|
|
2346
|
+
var TemplateSenderTypes;
|
|
2347
|
+
(function (TemplateSenderTypes) {
|
|
2348
|
+
TemplateSenderTypes["CREATOR"] = "creator";
|
|
2349
|
+
TemplateSenderTypes["ORGANIZATION_MEMBER"] = "organization_member";
|
|
2350
|
+
TemplateSenderTypes["ORGANIZATION_MEMBER_AS_CREATOR"] = "organization_member_as_creator";
|
|
2351
|
+
TemplateSenderTypes["EVERYONE"] = "everyone";
|
|
2352
|
+
TemplateSenderTypes["EVERYONE_AS_CREATOR"] = "everyone_as_creator";
|
|
2353
|
+
})(TemplateSenderTypes || (TemplateSenderTypes = {}));
|
|
2354
|
+
var TemplateActions;
|
|
2355
|
+
(function (TemplateActions) {
|
|
2356
|
+
TemplateActions["CREATE_PERSONAL"] = "create_personal";
|
|
2357
|
+
TemplateActions["CREATE_ORG"] = "create_org";
|
|
2358
|
+
TemplateActions["CREATE_PUBLIC"] = "create_public";
|
|
2359
|
+
TemplateActions["READ"] = "read";
|
|
2360
|
+
TemplateActions["WRITE"] = "write";
|
|
2361
|
+
TemplateActions["DELETE"] = "delete";
|
|
2362
|
+
TemplateActions["CHANGE_VISIBILITY_PERSONAL"] = "change_visibility_personal";
|
|
2363
|
+
TemplateActions["CHANGE_VISIBILITY_ORG"] = "change_visibility_org";
|
|
2364
|
+
TemplateActions["CHANGE_VISIBILITY_PUBLIC"] = "change_visibility_public";
|
|
2365
|
+
})(TemplateActions || (TemplateActions = {}));
|
|
2366
|
+
var SortOptions;
|
|
2367
|
+
(function (SortOptions) {
|
|
2368
|
+
SortOptions["CREATED_AT"] = "created_at";
|
|
2369
|
+
SortOptions["UPDATED_AT"] = "updated_at";
|
|
2370
|
+
SortOptions["NAME"] = "name";
|
|
2371
|
+
SortOptions["LAST_USED_AT"] = "last_used_at";
|
|
2372
|
+
SortOptions["COUNTER"] = "counter";
|
|
2373
|
+
SortOptions["STAR_COUNTER"] = "star_counter";
|
|
2374
|
+
})(SortOptions || (SortOptions = {}));
|
|
2375
|
+
|
|
2376
|
+
var bind = function bind(fn, thisArg) {
|
|
2377
|
+
return function wrap() {
|
|
2378
|
+
var args = new Array(arguments.length);
|
|
2379
|
+
for (var i = 0; i < args.length; i++) {
|
|
2380
|
+
args[i] = arguments[i];
|
|
2381
|
+
}
|
|
2382
|
+
return fn.apply(thisArg, args);
|
|
2383
|
+
};
|
|
2384
|
+
};
|
|
2385
|
+
|
|
2386
|
+
// utils is a library of generic helper functions non-specific to axios
|
|
2387
|
+
|
|
2388
|
+
var toString = Object.prototype.toString;
|
|
2389
|
+
|
|
2390
|
+
// eslint-disable-next-line func-names
|
|
2391
|
+
var kindOf = (function(cache) {
|
|
2392
|
+
// eslint-disable-next-line func-names
|
|
2393
|
+
return function(thing) {
|
|
2394
|
+
var str = toString.call(thing);
|
|
2395
|
+
return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
|
|
2396
|
+
};
|
|
2397
|
+
})(Object.create(null));
|
|
2398
|
+
|
|
2399
|
+
function kindOfTest(type) {
|
|
2400
|
+
type = type.toLowerCase();
|
|
2401
|
+
return function isKindOf(thing) {
|
|
2402
|
+
return kindOf(thing) === type;
|
|
2403
|
+
};
|
|
2404
|
+
}
|
|
2405
|
+
|
|
2406
|
+
/**
|
|
2407
|
+
* Determine if a value is an Array
|
|
2408
|
+
*
|
|
2409
|
+
* @param {Object} val The value to test
|
|
2410
|
+
* @returns {boolean} True if value is an Array, otherwise false
|
|
2411
|
+
*/
|
|
2412
|
+
function isArray(val) {
|
|
2413
|
+
return Array.isArray(val);
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2416
|
+
/**
|
|
2417
|
+
* Determine if a value is undefined
|
|
2418
|
+
*
|
|
2419
|
+
* @param {Object} val The value to test
|
|
2420
|
+
* @returns {boolean} True if the value is undefined, otherwise false
|
|
2421
|
+
*/
|
|
2422
|
+
function isUndefined(val) {
|
|
2423
|
+
return typeof val === 'undefined';
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
/**
|
|
2427
|
+
* Determine if a value is a Buffer
|
|
2428
|
+
*
|
|
2429
|
+
* @param {Object} val The value to test
|
|
2430
|
+
* @returns {boolean} True if value is a Buffer, otherwise false
|
|
2431
|
+
*/
|
|
2432
|
+
function isBuffer(val) {
|
|
2433
|
+
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
|
|
2434
|
+
&& typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);
|
|
2435
|
+
}
|
|
2436
|
+
|
|
2437
|
+
/**
|
|
2438
|
+
* Determine if a value is an ArrayBuffer
|
|
2439
|
+
*
|
|
2440
|
+
* @function
|
|
2441
|
+
* @param {Object} val The value to test
|
|
2442
|
+
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
|
2443
|
+
*/
|
|
2444
|
+
var isArrayBuffer = kindOfTest('ArrayBuffer');
|
|
2445
|
+
|
|
2446
|
+
|
|
2447
|
+
/**
|
|
2448
|
+
* Determine if a value is a view on an ArrayBuffer
|
|
2449
|
+
*
|
|
2450
|
+
* @param {Object} val The value to test
|
|
2451
|
+
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
|
2452
|
+
*/
|
|
2453
|
+
function isArrayBufferView(val) {
|
|
2454
|
+
var result;
|
|
2455
|
+
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
|
|
2456
|
+
result = ArrayBuffer.isView(val);
|
|
2457
|
+
} else {
|
|
2458
|
+
result = (val) && (val.buffer) && (isArrayBuffer(val.buffer));
|
|
2459
|
+
}
|
|
2460
|
+
return result;
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
/**
|
|
2464
|
+
* Determine if a value is a String
|
|
2465
|
+
*
|
|
2466
|
+
* @param {Object} val The value to test
|
|
2467
|
+
* @returns {boolean} True if value is a String, otherwise false
|
|
2468
|
+
*/
|
|
2469
|
+
function isString(val) {
|
|
2470
|
+
return typeof val === 'string';
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
/**
|
|
2474
|
+
* Determine if a value is a Number
|
|
2475
|
+
*
|
|
2476
|
+
* @param {Object} val The value to test
|
|
2477
|
+
* @returns {boolean} True if value is a Number, otherwise false
|
|
2478
|
+
*/
|
|
2479
|
+
function isNumber(val) {
|
|
2480
|
+
return typeof val === 'number';
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2483
|
+
/**
|
|
2484
|
+
* Determine if a value is an Object
|
|
2485
|
+
*
|
|
2486
|
+
* @param {Object} val The value to test
|
|
2487
|
+
* @returns {boolean} True if value is an Object, otherwise false
|
|
2488
|
+
*/
|
|
2489
|
+
function isObject(val) {
|
|
2490
|
+
return val !== null && typeof val === 'object';
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
/**
|
|
2494
|
+
* Determine if a value is a plain Object
|
|
2495
|
+
*
|
|
2496
|
+
* @param {Object} val The value to test
|
|
2497
|
+
* @return {boolean} True if value is a plain Object, otherwise false
|
|
2498
|
+
*/
|
|
2499
|
+
function isPlainObject(val) {
|
|
2500
|
+
if (kindOf(val) !== 'object') {
|
|
2501
|
+
return false;
|
|
2502
|
+
}
|
|
2503
|
+
|
|
2504
|
+
var prototype = Object.getPrototypeOf(val);
|
|
2505
|
+
return prototype === null || prototype === Object.prototype;
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
/**
|
|
2509
|
+
* Determine if a value is a Date
|
|
2510
|
+
*
|
|
2511
|
+
* @function
|
|
2512
|
+
* @param {Object} val The value to test
|
|
2513
|
+
* @returns {boolean} True if value is a Date, otherwise false
|
|
2514
|
+
*/
|
|
2515
|
+
var isDate = kindOfTest('Date');
|
|
2516
|
+
|
|
2517
|
+
/**
|
|
2518
|
+
* Determine if a value is a File
|
|
2519
|
+
*
|
|
2520
|
+
* @function
|
|
2521
|
+
* @param {Object} val The value to test
|
|
2522
|
+
* @returns {boolean} True if value is a File, otherwise false
|
|
2523
|
+
*/
|
|
2524
|
+
var isFile = kindOfTest('File');
|
|
2525
|
+
|
|
2526
|
+
/**
|
|
2527
|
+
* Determine if a value is a Blob
|
|
2528
|
+
*
|
|
2529
|
+
* @function
|
|
2530
|
+
* @param {Object} val The value to test
|
|
2531
|
+
* @returns {boolean} True if value is a Blob, otherwise false
|
|
2532
|
+
*/
|
|
2533
|
+
var isBlob = kindOfTest('Blob');
|
|
2534
|
+
|
|
2535
|
+
/**
|
|
2536
|
+
* Determine if a value is a FileList
|
|
2537
|
+
*
|
|
2538
|
+
* @function
|
|
2539
|
+
* @param {Object} val The value to test
|
|
2540
|
+
* @returns {boolean} True if value is a File, otherwise false
|
|
2541
|
+
*/
|
|
2542
|
+
var isFileList = kindOfTest('FileList');
|
|
2543
|
+
|
|
2544
|
+
/**
|
|
2545
|
+
* Determine if a value is a Function
|
|
2546
|
+
*
|
|
2547
|
+
* @param {Object} val The value to test
|
|
2548
|
+
* @returns {boolean} True if value is a Function, otherwise false
|
|
2549
|
+
*/
|
|
2550
|
+
function isFunction(val) {
|
|
2551
|
+
return toString.call(val) === '[object Function]';
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2554
|
+
/**
|
|
2555
|
+
* Determine if a value is a Stream
|
|
2556
|
+
*
|
|
2557
|
+
* @param {Object} val The value to test
|
|
2558
|
+
* @returns {boolean} True if value is a Stream, otherwise false
|
|
2559
|
+
*/
|
|
2560
|
+
function isStream(val) {
|
|
2561
|
+
return isObject(val) && isFunction(val.pipe);
|
|
2562
|
+
}
|
|
2563
|
+
|
|
2564
|
+
/**
|
|
2565
|
+
* Determine if a value is a FormData
|
|
2566
|
+
*
|
|
2567
|
+
* @param {Object} thing The value to test
|
|
2568
|
+
* @returns {boolean} True if value is an FormData, otherwise false
|
|
2569
|
+
*/
|
|
2570
|
+
function isFormData(thing) {
|
|
2571
|
+
var pattern = '[object FormData]';
|
|
2572
|
+
return thing && (
|
|
2573
|
+
(typeof FormData === 'function' && thing instanceof FormData) ||
|
|
2574
|
+
toString.call(thing) === pattern ||
|
|
2575
|
+
(isFunction(thing.toString) && thing.toString() === pattern)
|
|
2576
|
+
);
|
|
2577
|
+
}
|
|
2578
|
+
|
|
2579
|
+
/**
|
|
2580
|
+
* Determine if a value is a URLSearchParams object
|
|
2581
|
+
* @function
|
|
2582
|
+
* @param {Object} val The value to test
|
|
2583
|
+
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
|
2584
|
+
*/
|
|
2585
|
+
var isURLSearchParams = kindOfTest('URLSearchParams');
|
|
2586
|
+
|
|
2587
|
+
/**
|
|
2588
|
+
* Trim excess whitespace off the beginning and end of a string
|
|
2589
|
+
*
|
|
2590
|
+
* @param {String} str The String to trim
|
|
2591
|
+
* @returns {String} The String freed of excess whitespace
|
|
2592
|
+
*/
|
|
2593
|
+
function trim(str) {
|
|
2594
|
+
return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '');
|
|
2595
|
+
}
|
|
2596
|
+
|
|
2597
|
+
/**
|
|
2598
|
+
* Determine if we're running in a standard browser environment
|
|
2599
|
+
*
|
|
2600
|
+
* This allows axios to run in a web worker, and react-native.
|
|
2601
|
+
* Both environments support XMLHttpRequest, but not fully standard globals.
|
|
2602
|
+
*
|
|
2603
|
+
* web workers:
|
|
2604
|
+
* typeof window -> undefined
|
|
2605
|
+
* typeof document -> undefined
|
|
2606
|
+
*
|
|
2607
|
+
* react-native:
|
|
2608
|
+
* navigator.product -> 'ReactNative'
|
|
2609
|
+
* nativescript
|
|
2610
|
+
* navigator.product -> 'NativeScript' or 'NS'
|
|
2611
|
+
*/
|
|
2612
|
+
function isStandardBrowserEnv() {
|
|
2613
|
+
if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' ||
|
|
2614
|
+
navigator.product === 'NativeScript' ||
|
|
2615
|
+
navigator.product === 'NS')) {
|
|
2616
|
+
return false;
|
|
2617
|
+
}
|
|
2618
|
+
return (
|
|
2619
|
+
typeof window !== 'undefined' &&
|
|
2620
|
+
typeof document !== 'undefined'
|
|
2621
|
+
);
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
/**
|
|
2625
|
+
* Iterate over an Array or an Object invoking a function for each item.
|
|
2626
|
+
*
|
|
2627
|
+
* If `obj` is an Array callback will be called passing
|
|
2628
|
+
* the value, index, and complete array for each item.
|
|
2629
|
+
*
|
|
2630
|
+
* If 'obj' is an Object callback will be called passing
|
|
2631
|
+
* the value, key, and complete object for each property.
|
|
2632
|
+
*
|
|
2633
|
+
* @param {Object|Array} obj The object to iterate
|
|
2634
|
+
* @param {Function} fn The callback to invoke for each item
|
|
2635
|
+
*/
|
|
2636
|
+
function forEach(obj, fn) {
|
|
2637
|
+
// Don't bother if no value provided
|
|
2638
|
+
if (obj === null || typeof obj === 'undefined') {
|
|
2639
|
+
return;
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
// Force an array if not already something iterable
|
|
2643
|
+
if (typeof obj !== 'object') {
|
|
2644
|
+
/*eslint no-param-reassign:0*/
|
|
2645
|
+
obj = [obj];
|
|
2646
|
+
}
|
|
2647
|
+
|
|
2648
|
+
if (isArray(obj)) {
|
|
2649
|
+
// Iterate over array values
|
|
2650
|
+
for (var i = 0, l = obj.length; i < l; i++) {
|
|
2651
|
+
fn.call(null, obj[i], i, obj);
|
|
2652
|
+
}
|
|
2653
|
+
} else {
|
|
2654
|
+
// Iterate over object keys
|
|
2655
|
+
for (var key in obj) {
|
|
2656
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
2657
|
+
fn.call(null, obj[key], key, obj);
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
|
|
2663
|
+
/**
|
|
2664
|
+
* Accepts varargs expecting each argument to be an object, then
|
|
2665
|
+
* immutably merges the properties of each object and returns result.
|
|
2666
|
+
*
|
|
2667
|
+
* When multiple objects contain the same key the later object in
|
|
2668
|
+
* the arguments list will take precedence.
|
|
2669
|
+
*
|
|
2670
|
+
* Example:
|
|
2671
|
+
*
|
|
2672
|
+
* ```js
|
|
2673
|
+
* var result = merge({foo: 123}, {foo: 456});
|
|
2674
|
+
* console.log(result.foo); // outputs 456
|
|
2675
|
+
* ```
|
|
2676
|
+
*
|
|
2677
|
+
* @param {Object} obj1 Object to merge
|
|
2678
|
+
* @returns {Object} Result of all merge properties
|
|
2679
|
+
*/
|
|
2680
|
+
function merge(/* obj1, obj2, obj3, ... */) {
|
|
2681
|
+
var result = {};
|
|
2682
|
+
function assignValue(val, key) {
|
|
2683
|
+
if (isPlainObject(result[key]) && isPlainObject(val)) {
|
|
2684
|
+
result[key] = merge(result[key], val);
|
|
2685
|
+
} else if (isPlainObject(val)) {
|
|
2686
|
+
result[key] = merge({}, val);
|
|
2687
|
+
} else if (isArray(val)) {
|
|
2688
|
+
result[key] = val.slice();
|
|
2689
|
+
} else {
|
|
2690
|
+
result[key] = val;
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
2695
|
+
forEach(arguments[i], assignValue);
|
|
2696
|
+
}
|
|
2697
|
+
return result;
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2700
|
+
/**
|
|
2701
|
+
* Extends object a by mutably adding to it the properties of object b.
|
|
2702
|
+
*
|
|
2703
|
+
* @param {Object} a The object to be extended
|
|
2704
|
+
* @param {Object} b The object to copy properties from
|
|
2705
|
+
* @param {Object} thisArg The object to bind function to
|
|
2706
|
+
* @return {Object} The resulting value of object a
|
|
2707
|
+
*/
|
|
2708
|
+
function extend(a, b, thisArg) {
|
|
2709
|
+
forEach(b, function assignValue(val, key) {
|
|
2710
|
+
if (thisArg && typeof val === 'function') {
|
|
2711
|
+
a[key] = bind(val, thisArg);
|
|
2712
|
+
} else {
|
|
2713
|
+
a[key] = val;
|
|
2714
|
+
}
|
|
2715
|
+
});
|
|
2716
|
+
return a;
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
/**
|
|
2720
|
+
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
|
2721
|
+
*
|
|
2722
|
+
* @param {string} content with BOM
|
|
2723
|
+
* @return {string} content value without BOM
|
|
2724
|
+
*/
|
|
2725
|
+
function stripBOM(content) {
|
|
2726
|
+
if (content.charCodeAt(0) === 0xFEFF) {
|
|
2727
|
+
content = content.slice(1);
|
|
2728
|
+
}
|
|
2729
|
+
return content;
|
|
2730
|
+
}
|
|
2731
|
+
|
|
2732
|
+
/**
|
|
2733
|
+
* Inherit the prototype methods from one constructor into another
|
|
2734
|
+
* @param {function} constructor
|
|
2735
|
+
* @param {function} superConstructor
|
|
2736
|
+
* @param {object} [props]
|
|
2737
|
+
* @param {object} [descriptors]
|
|
2738
|
+
*/
|
|
2739
|
+
|
|
2740
|
+
function inherits(constructor, superConstructor, props, descriptors) {
|
|
2741
|
+
constructor.prototype = Object.create(superConstructor.prototype, descriptors);
|
|
2742
|
+
constructor.prototype.constructor = constructor;
|
|
2743
|
+
props && Object.assign(constructor.prototype, props);
|
|
2744
|
+
}
|
|
2745
|
+
|
|
2746
|
+
/**
|
|
2747
|
+
* Resolve object with deep prototype chain to a flat object
|
|
2748
|
+
* @param {Object} sourceObj source object
|
|
2749
|
+
* @param {Object} [destObj]
|
|
2750
|
+
* @param {Function} [filter]
|
|
2751
|
+
* @returns {Object}
|
|
2752
|
+
*/
|
|
2753
|
+
|
|
2754
|
+
function toFlatObject(sourceObj, destObj, filter) {
|
|
2755
|
+
var props;
|
|
2756
|
+
var i;
|
|
2757
|
+
var prop;
|
|
2758
|
+
var merged = {};
|
|
2759
|
+
|
|
2760
|
+
destObj = destObj || {};
|
|
2761
|
+
|
|
2762
|
+
do {
|
|
2763
|
+
props = Object.getOwnPropertyNames(sourceObj);
|
|
2764
|
+
i = props.length;
|
|
2765
|
+
while (i-- > 0) {
|
|
2766
|
+
prop = props[i];
|
|
2767
|
+
if (!merged[prop]) {
|
|
2768
|
+
destObj[prop] = sourceObj[prop];
|
|
2769
|
+
merged[prop] = true;
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
sourceObj = Object.getPrototypeOf(sourceObj);
|
|
2773
|
+
} while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
|
2774
|
+
|
|
2775
|
+
return destObj;
|
|
2776
|
+
}
|
|
2777
|
+
|
|
2778
|
+
/*
|
|
2779
|
+
* determines whether a string ends with the characters of a specified string
|
|
2780
|
+
* @param {String} str
|
|
2781
|
+
* @param {String} searchString
|
|
2782
|
+
* @param {Number} [position= 0]
|
|
2783
|
+
* @returns {boolean}
|
|
2784
|
+
*/
|
|
2785
|
+
function endsWith(str, searchString, position) {
|
|
2786
|
+
str = String(str);
|
|
2787
|
+
if (position === undefined || position > str.length) {
|
|
2788
|
+
position = str.length;
|
|
2789
|
+
}
|
|
2790
|
+
position -= searchString.length;
|
|
2791
|
+
var lastIndex = str.indexOf(searchString, position);
|
|
2792
|
+
return lastIndex !== -1 && lastIndex === position;
|
|
2793
|
+
}
|
|
2794
|
+
|
|
2795
|
+
|
|
2796
|
+
/**
|
|
2797
|
+
* Returns new array from array like object
|
|
2798
|
+
* @param {*} [thing]
|
|
2799
|
+
* @returns {Array}
|
|
2800
|
+
*/
|
|
2801
|
+
function toArray(thing) {
|
|
2802
|
+
if (!thing) return null;
|
|
2803
|
+
var i = thing.length;
|
|
2804
|
+
if (isUndefined(i)) return null;
|
|
2805
|
+
var arr = new Array(i);
|
|
2806
|
+
while (i-- > 0) {
|
|
2807
|
+
arr[i] = thing[i];
|
|
2808
|
+
}
|
|
2809
|
+
return arr;
|
|
2810
|
+
}
|
|
2811
|
+
|
|
2812
|
+
// eslint-disable-next-line func-names
|
|
2813
|
+
var isTypedArray = (function(TypedArray) {
|
|
2814
|
+
// eslint-disable-next-line func-names
|
|
2815
|
+
return function(thing) {
|
|
2816
|
+
return TypedArray && thing instanceof TypedArray;
|
|
2817
|
+
};
|
|
2818
|
+
})(typeof Uint8Array !== 'undefined' && Object.getPrototypeOf(Uint8Array));
|
|
2819
|
+
|
|
2820
|
+
var utils = {
|
|
2821
|
+
isArray: isArray,
|
|
2822
|
+
isArrayBuffer: isArrayBuffer,
|
|
2823
|
+
isBuffer: isBuffer,
|
|
2824
|
+
isFormData: isFormData,
|
|
2825
|
+
isArrayBufferView: isArrayBufferView,
|
|
2826
|
+
isString: isString,
|
|
2827
|
+
isNumber: isNumber,
|
|
2828
|
+
isObject: isObject,
|
|
2829
|
+
isPlainObject: isPlainObject,
|
|
2830
|
+
isUndefined: isUndefined,
|
|
2831
|
+
isDate: isDate,
|
|
2832
|
+
isFile: isFile,
|
|
2833
|
+
isBlob: isBlob,
|
|
2834
|
+
isFunction: isFunction,
|
|
2835
|
+
isStream: isStream,
|
|
2836
|
+
isURLSearchParams: isURLSearchParams,
|
|
2837
|
+
isStandardBrowserEnv: isStandardBrowserEnv,
|
|
2838
|
+
forEach: forEach,
|
|
2839
|
+
merge: merge,
|
|
2840
|
+
extend: extend,
|
|
2841
|
+
trim: trim,
|
|
2842
|
+
stripBOM: stripBOM,
|
|
2843
|
+
inherits: inherits,
|
|
2844
|
+
toFlatObject: toFlatObject,
|
|
2845
|
+
kindOf: kindOf,
|
|
2846
|
+
kindOfTest: kindOfTest,
|
|
2847
|
+
endsWith: endsWith,
|
|
2848
|
+
toArray: toArray,
|
|
2849
|
+
isTypedArray: isTypedArray,
|
|
2850
|
+
isFileList: isFileList
|
|
2851
|
+
};
|
|
2852
|
+
|
|
2853
|
+
function encode(val) {
|
|
2854
|
+
return encodeURIComponent(val).
|
|
2855
|
+
replace(/%3A/gi, ':').
|
|
2856
|
+
replace(/%24/g, '$').
|
|
2857
|
+
replace(/%2C/gi, ',').
|
|
2858
|
+
replace(/%20/g, '+').
|
|
2859
|
+
replace(/%5B/gi, '[').
|
|
2860
|
+
replace(/%5D/gi, ']');
|
|
2861
|
+
}
|
|
2862
|
+
|
|
2863
|
+
/**
|
|
2864
|
+
* Build a URL by appending params to the end
|
|
2865
|
+
*
|
|
2866
|
+
* @param {string} url The base of the url (e.g., http://www.google.com)
|
|
2867
|
+
* @param {object} [params] The params to be appended
|
|
2868
|
+
* @returns {string} The formatted url
|
|
2869
|
+
*/
|
|
2870
|
+
var buildURL = function buildURL(url, params, paramsSerializer) {
|
|
2871
|
+
/*eslint no-param-reassign:0*/
|
|
2872
|
+
if (!params) {
|
|
2873
|
+
return url;
|
|
2874
|
+
}
|
|
2875
|
+
|
|
2876
|
+
var serializedParams;
|
|
2877
|
+
if (paramsSerializer) {
|
|
2878
|
+
serializedParams = paramsSerializer(params);
|
|
2879
|
+
} else if (utils.isURLSearchParams(params)) {
|
|
2880
|
+
serializedParams = params.toString();
|
|
2881
|
+
} else {
|
|
2882
|
+
var parts = [];
|
|
2883
|
+
|
|
2884
|
+
utils.forEach(params, function serialize(val, key) {
|
|
2885
|
+
if (val === null || typeof val === 'undefined') {
|
|
2886
|
+
return;
|
|
2887
|
+
}
|
|
2888
|
+
|
|
2889
|
+
if (utils.isArray(val)) {
|
|
2890
|
+
key = key + '[]';
|
|
2891
|
+
} else {
|
|
2892
|
+
val = [val];
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
utils.forEach(val, function parseValue(v) {
|
|
2896
|
+
if (utils.isDate(v)) {
|
|
2897
|
+
v = v.toISOString();
|
|
2898
|
+
} else if (utils.isObject(v)) {
|
|
2899
|
+
v = JSON.stringify(v);
|
|
2900
|
+
}
|
|
2901
|
+
parts.push(encode(key) + '=' + encode(v));
|
|
2902
|
+
});
|
|
2903
|
+
});
|
|
2904
|
+
|
|
2905
|
+
serializedParams = parts.join('&');
|
|
2906
|
+
}
|
|
2907
|
+
|
|
2908
|
+
if (serializedParams) {
|
|
2909
|
+
var hashmarkIndex = url.indexOf('#');
|
|
2910
|
+
if (hashmarkIndex !== -1) {
|
|
2911
|
+
url = url.slice(0, hashmarkIndex);
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2914
|
+
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
|
|
2915
|
+
}
|
|
2916
|
+
|
|
2917
|
+
return url;
|
|
2918
|
+
};
|
|
2919
|
+
|
|
2920
|
+
function InterceptorManager() {
|
|
2921
|
+
this.handlers = [];
|
|
2922
|
+
}
|
|
2923
|
+
|
|
2924
|
+
/**
|
|
2925
|
+
* Add a new interceptor to the stack
|
|
2926
|
+
*
|
|
2927
|
+
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
|
2928
|
+
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
|
2929
|
+
*
|
|
2930
|
+
* @return {Number} An ID used to remove interceptor later
|
|
2931
|
+
*/
|
|
2932
|
+
InterceptorManager.prototype.use = function use(fulfilled, rejected, options) {
|
|
2933
|
+
this.handlers.push({
|
|
2934
|
+
fulfilled: fulfilled,
|
|
2935
|
+
rejected: rejected,
|
|
2936
|
+
synchronous: options ? options.synchronous : false,
|
|
2937
|
+
runWhen: options ? options.runWhen : null
|
|
2938
|
+
});
|
|
2939
|
+
return this.handlers.length - 1;
|
|
2940
|
+
};
|
|
2941
|
+
|
|
2942
|
+
/**
|
|
2943
|
+
* Remove an interceptor from the stack
|
|
2944
|
+
*
|
|
2945
|
+
* @param {Number} id The ID that was returned by `use`
|
|
2946
|
+
*/
|
|
2947
|
+
InterceptorManager.prototype.eject = function eject(id) {
|
|
2948
|
+
if (this.handlers[id]) {
|
|
2949
|
+
this.handlers[id] = null;
|
|
2950
|
+
}
|
|
2951
|
+
};
|
|
2952
|
+
|
|
2953
|
+
/**
|
|
2954
|
+
* Iterate over all the registered interceptors
|
|
2955
|
+
*
|
|
2956
|
+
* This method is particularly useful for skipping over any
|
|
2957
|
+
* interceptors that may have become `null` calling `eject`.
|
|
2958
|
+
*
|
|
2959
|
+
* @param {Function} fn The function to call for each interceptor
|
|
2960
|
+
*/
|
|
2961
|
+
InterceptorManager.prototype.forEach = function forEach(fn) {
|
|
2962
|
+
utils.forEach(this.handlers, function forEachHandler(h) {
|
|
2963
|
+
if (h !== null) {
|
|
2964
|
+
fn(h);
|
|
2965
|
+
}
|
|
2966
|
+
});
|
|
2967
|
+
};
|
|
2968
|
+
|
|
2969
|
+
var InterceptorManager_1 = InterceptorManager;
|
|
2970
|
+
|
|
2971
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
2972
|
+
|
|
2973
|
+
function getDefaultExportFromCjs (x) {
|
|
2974
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
2975
|
+
}
|
|
2976
|
+
|
|
2977
|
+
function createCommonjsModule(fn, basedir, module) {
|
|
2978
|
+
return module = {
|
|
2979
|
+
path: basedir,
|
|
2980
|
+
exports: {},
|
|
2981
|
+
require: function (path, base) {
|
|
2982
|
+
return commonjsRequire();
|
|
2983
|
+
}
|
|
2984
|
+
}, fn(module, module.exports), module.exports;
|
|
2985
|
+
}
|
|
2986
|
+
|
|
2987
|
+
function getAugmentedNamespace(n) {
|
|
2988
|
+
if (n.__esModule) return n;
|
|
2989
|
+
var a = Object.defineProperty({}, '__esModule', {value: true});
|
|
2990
|
+
Object.keys(n).forEach(function (k) {
|
|
2991
|
+
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
2992
|
+
Object.defineProperty(a, k, d.get ? d : {
|
|
2993
|
+
enumerable: true,
|
|
2994
|
+
get: function () {
|
|
2995
|
+
return n[k];
|
|
2996
|
+
}
|
|
2997
|
+
});
|
|
2998
|
+
});
|
|
2999
|
+
return a;
|
|
3000
|
+
}
|
|
3001
|
+
|
|
3002
|
+
function commonjsRequire () {
|
|
3003
|
+
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
|
3004
|
+
}
|
|
3005
|
+
|
|
3006
|
+
// for now just expose the builtin process global from node.js
|
|
3007
|
+
var process_1 = commonjsGlobal.process;
|
|
3008
|
+
|
|
3009
|
+
var normalizeHeaderName = function normalizeHeaderName(headers, normalizedName) {
|
|
3010
|
+
utils.forEach(headers, function processHeader(value, name) {
|
|
3011
|
+
if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {
|
|
3012
|
+
headers[normalizedName] = value;
|
|
3013
|
+
delete headers[name];
|
|
3014
|
+
}
|
|
3015
|
+
});
|
|
3016
|
+
};
|
|
3017
|
+
|
|
3018
|
+
/**
|
|
3019
|
+
* Create an Error with the specified message, config, error code, request and response.
|
|
3020
|
+
*
|
|
3021
|
+
* @param {string} message The error message.
|
|
3022
|
+
* @param {string} [code] The error code (for example, 'ECONNABORTED').
|
|
3023
|
+
* @param {Object} [config] The config.
|
|
3024
|
+
* @param {Object} [request] The request.
|
|
3025
|
+
* @param {Object} [response] The response.
|
|
3026
|
+
* @returns {Error} The created error.
|
|
3027
|
+
*/
|
|
3028
|
+
function AxiosError(message, code, config, request, response) {
|
|
3029
|
+
Error.call(this);
|
|
3030
|
+
this.message = message;
|
|
3031
|
+
this.name = 'AxiosError';
|
|
3032
|
+
code && (this.code = code);
|
|
3033
|
+
config && (this.config = config);
|
|
3034
|
+
request && (this.request = request);
|
|
3035
|
+
response && (this.response = response);
|
|
3036
|
+
}
|
|
3037
|
+
|
|
3038
|
+
utils.inherits(AxiosError, Error, {
|
|
3039
|
+
toJSON: function toJSON() {
|
|
3040
|
+
return {
|
|
3041
|
+
// Standard
|
|
3042
|
+
message: this.message,
|
|
3043
|
+
name: this.name,
|
|
3044
|
+
// Microsoft
|
|
3045
|
+
description: this.description,
|
|
3046
|
+
number: this.number,
|
|
3047
|
+
// Mozilla
|
|
3048
|
+
fileName: this.fileName,
|
|
3049
|
+
lineNumber: this.lineNumber,
|
|
3050
|
+
columnNumber: this.columnNumber,
|
|
3051
|
+
stack: this.stack,
|
|
3052
|
+
// Axios
|
|
3053
|
+
config: this.config,
|
|
3054
|
+
code: this.code,
|
|
3055
|
+
status: this.response && this.response.status ? this.response.status : null
|
|
3056
|
+
};
|
|
3057
|
+
}
|
|
3058
|
+
});
|
|
3059
|
+
|
|
3060
|
+
var prototype = AxiosError.prototype;
|
|
3061
|
+
var descriptors = {};
|
|
3062
|
+
|
|
3063
|
+
[
|
|
3064
|
+
'ERR_BAD_OPTION_VALUE',
|
|
3065
|
+
'ERR_BAD_OPTION',
|
|
3066
|
+
'ECONNABORTED',
|
|
3067
|
+
'ETIMEDOUT',
|
|
3068
|
+
'ERR_NETWORK',
|
|
3069
|
+
'ERR_FR_TOO_MANY_REDIRECTS',
|
|
3070
|
+
'ERR_DEPRECATED',
|
|
3071
|
+
'ERR_BAD_RESPONSE',
|
|
3072
|
+
'ERR_BAD_REQUEST',
|
|
3073
|
+
'ERR_CANCELED'
|
|
3074
|
+
// eslint-disable-next-line func-names
|
|
3075
|
+
].forEach(function(code) {
|
|
3076
|
+
descriptors[code] = {value: code};
|
|
3077
|
+
});
|
|
3078
|
+
|
|
3079
|
+
Object.defineProperties(AxiosError, descriptors);
|
|
3080
|
+
Object.defineProperty(prototype, 'isAxiosError', {value: true});
|
|
3081
|
+
|
|
3082
|
+
// eslint-disable-next-line func-names
|
|
3083
|
+
AxiosError.from = function(error, code, config, request, response, customProps) {
|
|
3084
|
+
var axiosError = Object.create(prototype);
|
|
3085
|
+
|
|
3086
|
+
utils.toFlatObject(error, axiosError, function filter(obj) {
|
|
3087
|
+
return obj !== Error.prototype;
|
|
3088
|
+
});
|
|
3089
|
+
|
|
3090
|
+
AxiosError.call(axiosError, error.message, code, config, request, response);
|
|
3091
|
+
|
|
3092
|
+
axiosError.name = error.name;
|
|
3093
|
+
|
|
3094
|
+
customProps && Object.assign(axiosError, customProps);
|
|
3095
|
+
|
|
3096
|
+
return axiosError;
|
|
3097
|
+
};
|
|
3098
|
+
|
|
3099
|
+
var AxiosError_1 = AxiosError;
|
|
3100
|
+
|
|
3101
|
+
var transitional = {
|
|
3102
|
+
silentJSONParsing: true,
|
|
3103
|
+
forcedJSONParsing: true,
|
|
3104
|
+
clarifyTimeoutError: false
|
|
3105
|
+
};
|
|
3106
|
+
|
|
3107
|
+
/**
|
|
3108
|
+
* Convert a data object to FormData
|
|
3109
|
+
* @param {Object} obj
|
|
3110
|
+
* @param {?Object} [formData]
|
|
3111
|
+
* @returns {Object}
|
|
3112
|
+
**/
|
|
3113
|
+
|
|
3114
|
+
function toFormData(obj, formData) {
|
|
3115
|
+
// eslint-disable-next-line no-param-reassign
|
|
3116
|
+
formData = formData || new FormData();
|
|
3117
|
+
|
|
3118
|
+
var stack = [];
|
|
3119
|
+
|
|
3120
|
+
function convertValue(value) {
|
|
3121
|
+
if (value === null) return '';
|
|
3122
|
+
|
|
3123
|
+
if (utils.isDate(value)) {
|
|
3124
|
+
return value.toISOString();
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
if (utils.isArrayBuffer(value) || utils.isTypedArray(value)) {
|
|
3128
|
+
return typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
|
|
3129
|
+
}
|
|
3130
|
+
|
|
3131
|
+
return value;
|
|
3132
|
+
}
|
|
3133
|
+
|
|
3134
|
+
function build(data, parentKey) {
|
|
3135
|
+
if (utils.isPlainObject(data) || utils.isArray(data)) {
|
|
3136
|
+
if (stack.indexOf(data) !== -1) {
|
|
3137
|
+
throw Error('Circular reference detected in ' + parentKey);
|
|
3138
|
+
}
|
|
3139
|
+
|
|
3140
|
+
stack.push(data);
|
|
3141
|
+
|
|
3142
|
+
utils.forEach(data, function each(value, key) {
|
|
3143
|
+
if (utils.isUndefined(value)) return;
|
|
3144
|
+
var fullKey = parentKey ? parentKey + '.' + key : key;
|
|
3145
|
+
var arr;
|
|
3146
|
+
|
|
3147
|
+
if (value && !parentKey && typeof value === 'object') {
|
|
3148
|
+
if (utils.endsWith(key, '{}')) {
|
|
3149
|
+
// eslint-disable-next-line no-param-reassign
|
|
3150
|
+
value = JSON.stringify(value);
|
|
3151
|
+
} else if (utils.endsWith(key, '[]') && (arr = utils.toArray(value))) {
|
|
3152
|
+
// eslint-disable-next-line func-names
|
|
3153
|
+
arr.forEach(function(el) {
|
|
3154
|
+
!utils.isUndefined(el) && formData.append(fullKey, convertValue(el));
|
|
3155
|
+
});
|
|
3156
|
+
return;
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
|
|
3160
|
+
build(value, fullKey);
|
|
3161
|
+
});
|
|
3162
|
+
|
|
3163
|
+
stack.pop();
|
|
3164
|
+
} else {
|
|
3165
|
+
formData.append(parentKey, convertValue(data));
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
|
|
3169
|
+
build(obj);
|
|
3170
|
+
|
|
3171
|
+
return formData;
|
|
3172
|
+
}
|
|
3173
|
+
|
|
3174
|
+
var toFormData_1 = toFormData;
|
|
3175
|
+
|
|
3176
|
+
/**
|
|
3177
|
+
* Resolve or reject a Promise based on response status.
|
|
3178
|
+
*
|
|
3179
|
+
* @param {Function} resolve A function that resolves the promise.
|
|
3180
|
+
* @param {Function} reject A function that rejects the promise.
|
|
3181
|
+
* @param {object} response The response.
|
|
3182
|
+
*/
|
|
3183
|
+
var settle = function settle(resolve, reject, response) {
|
|
3184
|
+
var validateStatus = response.config.validateStatus;
|
|
3185
|
+
if (!response.status || !validateStatus || validateStatus(response.status)) {
|
|
3186
|
+
resolve(response);
|
|
3187
|
+
} else {
|
|
3188
|
+
reject(new AxiosError_1(
|
|
3189
|
+
'Request failed with status code ' + response.status,
|
|
3190
|
+
[AxiosError_1.ERR_BAD_REQUEST, AxiosError_1.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
|
|
3191
|
+
response.config,
|
|
3192
|
+
response.request,
|
|
3193
|
+
response
|
|
3194
|
+
));
|
|
3195
|
+
}
|
|
3196
|
+
};
|
|
3197
|
+
|
|
3198
|
+
var cookies = (
|
|
3199
|
+
utils.isStandardBrowserEnv() ?
|
|
3200
|
+
|
|
3201
|
+
// Standard browser envs support document.cookie
|
|
3202
|
+
(function standardBrowserEnv() {
|
|
3203
|
+
return {
|
|
3204
|
+
write: function write(name, value, expires, path, domain, secure) {
|
|
3205
|
+
var cookie = [];
|
|
3206
|
+
cookie.push(name + '=' + encodeURIComponent(value));
|
|
3207
|
+
|
|
3208
|
+
if (utils.isNumber(expires)) {
|
|
3209
|
+
cookie.push('expires=' + new Date(expires).toGMTString());
|
|
3210
|
+
}
|
|
3211
|
+
|
|
3212
|
+
if (utils.isString(path)) {
|
|
3213
|
+
cookie.push('path=' + path);
|
|
3214
|
+
}
|
|
3215
|
+
|
|
3216
|
+
if (utils.isString(domain)) {
|
|
3217
|
+
cookie.push('domain=' + domain);
|
|
3218
|
+
}
|
|
3219
|
+
|
|
3220
|
+
if (secure === true) {
|
|
3221
|
+
cookie.push('secure');
|
|
3222
|
+
}
|
|
3223
|
+
|
|
3224
|
+
document.cookie = cookie.join('; ');
|
|
3225
|
+
},
|
|
3226
|
+
|
|
3227
|
+
read: function read(name) {
|
|
3228
|
+
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
|
3229
|
+
return (match ? decodeURIComponent(match[3]) : null);
|
|
3230
|
+
},
|
|
3231
|
+
|
|
3232
|
+
remove: function remove(name) {
|
|
3233
|
+
this.write(name, '', Date.now() - 86400000);
|
|
3234
|
+
}
|
|
3235
|
+
};
|
|
3236
|
+
})() :
|
|
3237
|
+
|
|
3238
|
+
// Non standard browser env (web workers, react-native) lack needed support.
|
|
3239
|
+
(function nonStandardBrowserEnv() {
|
|
3240
|
+
return {
|
|
3241
|
+
write: function write() {},
|
|
3242
|
+
read: function read() { return null; },
|
|
3243
|
+
remove: function remove() {}
|
|
3244
|
+
};
|
|
3245
|
+
})()
|
|
3246
|
+
);
|
|
3247
|
+
|
|
3248
|
+
/**
|
|
3249
|
+
* Determines whether the specified URL is absolute
|
|
3250
|
+
*
|
|
3251
|
+
* @param {string} url The URL to test
|
|
3252
|
+
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
|
3253
|
+
*/
|
|
3254
|
+
var isAbsoluteURL = function isAbsoluteURL(url) {
|
|
3255
|
+
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
|
3256
|
+
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
|
3257
|
+
// by any combination of letters, digits, plus, period, or hyphen.
|
|
3258
|
+
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
|
3259
|
+
};
|
|
3260
|
+
|
|
3261
|
+
/**
|
|
3262
|
+
* Creates a new URL by combining the specified URLs
|
|
3263
|
+
*
|
|
3264
|
+
* @param {string} baseURL The base URL
|
|
3265
|
+
* @param {string} relativeURL The relative URL
|
|
3266
|
+
* @returns {string} The combined URL
|
|
3267
|
+
*/
|
|
3268
|
+
var combineURLs = function combineURLs(baseURL, relativeURL) {
|
|
3269
|
+
return relativeURL
|
|
3270
|
+
? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
|
3271
|
+
: baseURL;
|
|
3272
|
+
};
|
|
3273
|
+
|
|
3274
|
+
/**
|
|
3275
|
+
* Creates a new URL by combining the baseURL with the requestedURL,
|
|
3276
|
+
* only when the requestedURL is not already an absolute URL.
|
|
3277
|
+
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
|
3278
|
+
*
|
|
3279
|
+
* @param {string} baseURL The base URL
|
|
3280
|
+
* @param {string} requestedURL Absolute or relative URL to combine
|
|
3281
|
+
* @returns {string} The combined full path
|
|
3282
|
+
*/
|
|
3283
|
+
var buildFullPath = function buildFullPath(baseURL, requestedURL) {
|
|
3284
|
+
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
|
3285
|
+
return combineURLs(baseURL, requestedURL);
|
|
3286
|
+
}
|
|
3287
|
+
return requestedURL;
|
|
3288
|
+
};
|
|
3289
|
+
|
|
3290
|
+
// Headers whose duplicates are ignored by node
|
|
3291
|
+
// c.f. https://nodejs.org/api/http.html#http_message_headers
|
|
3292
|
+
var ignoreDuplicateOf = [
|
|
3293
|
+
'age', 'authorization', 'content-length', 'content-type', 'etag',
|
|
3294
|
+
'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
|
|
3295
|
+
'last-modified', 'location', 'max-forwards', 'proxy-authorization',
|
|
3296
|
+
'referer', 'retry-after', 'user-agent'
|
|
3297
|
+
];
|
|
3298
|
+
|
|
3299
|
+
/**
|
|
3300
|
+
* Parse headers into an object
|
|
3301
|
+
*
|
|
3302
|
+
* ```
|
|
3303
|
+
* Date: Wed, 27 Aug 2014 08:58:49 GMT
|
|
3304
|
+
* Content-Type: application/json
|
|
3305
|
+
* Connection: keep-alive
|
|
3306
|
+
* Transfer-Encoding: chunked
|
|
3307
|
+
* ```
|
|
3308
|
+
*
|
|
3309
|
+
* @param {String} headers Headers needing to be parsed
|
|
3310
|
+
* @returns {Object} Headers parsed into an object
|
|
3311
|
+
*/
|
|
3312
|
+
var parseHeaders = function parseHeaders(headers) {
|
|
3313
|
+
var parsed = {};
|
|
3314
|
+
var key;
|
|
3315
|
+
var val;
|
|
3316
|
+
var i;
|
|
3317
|
+
|
|
3318
|
+
if (!headers) { return parsed; }
|
|
3319
|
+
|
|
3320
|
+
utils.forEach(headers.split('\n'), function parser(line) {
|
|
3321
|
+
i = line.indexOf(':');
|
|
3322
|
+
key = utils.trim(line.substr(0, i)).toLowerCase();
|
|
3323
|
+
val = utils.trim(line.substr(i + 1));
|
|
3324
|
+
|
|
3325
|
+
if (key) {
|
|
3326
|
+
if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
|
|
3327
|
+
return;
|
|
3328
|
+
}
|
|
3329
|
+
if (key === 'set-cookie') {
|
|
3330
|
+
parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
|
|
3331
|
+
} else {
|
|
3332
|
+
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
|
3333
|
+
}
|
|
3334
|
+
}
|
|
3335
|
+
});
|
|
3336
|
+
|
|
3337
|
+
return parsed;
|
|
3338
|
+
};
|
|
3339
|
+
|
|
3340
|
+
var isURLSameOrigin = (
|
|
3341
|
+
utils.isStandardBrowserEnv() ?
|
|
3342
|
+
|
|
3343
|
+
// Standard browser envs have full support of the APIs needed to test
|
|
3344
|
+
// whether the request URL is of the same origin as current location.
|
|
3345
|
+
(function standardBrowserEnv() {
|
|
3346
|
+
var msie = /(msie|trident)/i.test(navigator.userAgent);
|
|
3347
|
+
var urlParsingNode = document.createElement('a');
|
|
3348
|
+
var originURL;
|
|
3349
|
+
|
|
3350
|
+
/**
|
|
3351
|
+
* Parse a URL to discover it's components
|
|
3352
|
+
*
|
|
3353
|
+
* @param {String} url The URL to be parsed
|
|
3354
|
+
* @returns {Object}
|
|
3355
|
+
*/
|
|
3356
|
+
function resolveURL(url) {
|
|
3357
|
+
var href = url;
|
|
3358
|
+
|
|
3359
|
+
if (msie) {
|
|
3360
|
+
// IE needs attribute set twice to normalize properties
|
|
3361
|
+
urlParsingNode.setAttribute('href', href);
|
|
3362
|
+
href = urlParsingNode.href;
|
|
3363
|
+
}
|
|
3364
|
+
|
|
3365
|
+
urlParsingNode.setAttribute('href', href);
|
|
3366
|
+
|
|
3367
|
+
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
|
3368
|
+
return {
|
|
3369
|
+
href: urlParsingNode.href,
|
|
3370
|
+
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
|
3371
|
+
host: urlParsingNode.host,
|
|
3372
|
+
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
|
3373
|
+
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
|
3374
|
+
hostname: urlParsingNode.hostname,
|
|
3375
|
+
port: urlParsingNode.port,
|
|
3376
|
+
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
|
|
3377
|
+
urlParsingNode.pathname :
|
|
3378
|
+
'/' + urlParsingNode.pathname
|
|
3379
|
+
};
|
|
3380
|
+
}
|
|
3381
|
+
|
|
3382
|
+
originURL = resolveURL(window.location.href);
|
|
3383
|
+
|
|
3384
|
+
/**
|
|
3385
|
+
* Determine if a URL shares the same origin as the current location
|
|
3386
|
+
*
|
|
3387
|
+
* @param {String} requestURL The URL to test
|
|
3388
|
+
* @returns {boolean} True if URL shares the same origin, otherwise false
|
|
3389
|
+
*/
|
|
3390
|
+
return function isURLSameOrigin(requestURL) {
|
|
3391
|
+
var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
|
|
3392
|
+
return (parsed.protocol === originURL.protocol &&
|
|
3393
|
+
parsed.host === originURL.host);
|
|
3394
|
+
};
|
|
3395
|
+
})() :
|
|
3396
|
+
|
|
3397
|
+
// Non standard browser envs (web workers, react-native) lack needed support.
|
|
3398
|
+
(function nonStandardBrowserEnv() {
|
|
3399
|
+
return function isURLSameOrigin() {
|
|
3400
|
+
return true;
|
|
3401
|
+
};
|
|
3402
|
+
})()
|
|
3403
|
+
);
|
|
3404
|
+
|
|
3405
|
+
/**
|
|
3406
|
+
* A `CanceledError` is an object that is thrown when an operation is canceled.
|
|
3407
|
+
*
|
|
3408
|
+
* @class
|
|
3409
|
+
* @param {string=} message The message.
|
|
3410
|
+
*/
|
|
3411
|
+
function CanceledError(message) {
|
|
3412
|
+
// eslint-disable-next-line no-eq-null,eqeqeq
|
|
3413
|
+
AxiosError_1.call(this, message == null ? 'canceled' : message, AxiosError_1.ERR_CANCELED);
|
|
3414
|
+
this.name = 'CanceledError';
|
|
3415
|
+
}
|
|
3416
|
+
|
|
3417
|
+
utils.inherits(CanceledError, AxiosError_1, {
|
|
3418
|
+
__CANCEL__: true
|
|
3419
|
+
});
|
|
3420
|
+
|
|
3421
|
+
var CanceledError_1 = CanceledError;
|
|
3422
|
+
|
|
3423
|
+
var parseProtocol = function parseProtocol(url) {
|
|
3424
|
+
var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
|
3425
|
+
return match && match[1] || '';
|
|
3426
|
+
};
|
|
3427
|
+
|
|
3428
|
+
var xhr = function xhrAdapter(config) {
|
|
3429
|
+
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
|
3430
|
+
var requestData = config.data;
|
|
3431
|
+
var requestHeaders = config.headers;
|
|
3432
|
+
var responseType = config.responseType;
|
|
3433
|
+
var onCanceled;
|
|
3434
|
+
function done() {
|
|
3435
|
+
if (config.cancelToken) {
|
|
3436
|
+
config.cancelToken.unsubscribe(onCanceled);
|
|
3437
|
+
}
|
|
3438
|
+
|
|
3439
|
+
if (config.signal) {
|
|
3440
|
+
config.signal.removeEventListener('abort', onCanceled);
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
3443
|
+
|
|
3444
|
+
if (utils.isFormData(requestData) && utils.isStandardBrowserEnv()) {
|
|
3445
|
+
delete requestHeaders['Content-Type']; // Let the browser set it
|
|
3446
|
+
}
|
|
3447
|
+
|
|
3448
|
+
var request = new XMLHttpRequest();
|
|
3449
|
+
|
|
3450
|
+
// HTTP basic authentication
|
|
3451
|
+
if (config.auth) {
|
|
3452
|
+
var username = config.auth.username || '';
|
|
3453
|
+
var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
|
|
3454
|
+
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
|
3455
|
+
}
|
|
3456
|
+
|
|
3457
|
+
var fullPath = buildFullPath(config.baseURL, config.url);
|
|
3458
|
+
|
|
3459
|
+
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
|
|
3460
|
+
|
|
3461
|
+
// Set the request timeout in MS
|
|
3462
|
+
request.timeout = config.timeout;
|
|
3463
|
+
|
|
3464
|
+
function onloadend() {
|
|
3465
|
+
if (!request) {
|
|
3466
|
+
return;
|
|
3467
|
+
}
|
|
3468
|
+
// Prepare the response
|
|
3469
|
+
var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
|
|
3470
|
+
var responseData = !responseType || responseType === 'text' || responseType === 'json' ?
|
|
3471
|
+
request.responseText : request.response;
|
|
3472
|
+
var response = {
|
|
3473
|
+
data: responseData,
|
|
3474
|
+
status: request.status,
|
|
3475
|
+
statusText: request.statusText,
|
|
3476
|
+
headers: responseHeaders,
|
|
3477
|
+
config: config,
|
|
3478
|
+
request: request
|
|
3479
|
+
};
|
|
3480
|
+
|
|
3481
|
+
settle(function _resolve(value) {
|
|
3482
|
+
resolve(value);
|
|
3483
|
+
done();
|
|
3484
|
+
}, function _reject(err) {
|
|
3485
|
+
reject(err);
|
|
3486
|
+
done();
|
|
3487
|
+
}, response);
|
|
3488
|
+
|
|
3489
|
+
// Clean up request
|
|
3490
|
+
request = null;
|
|
3491
|
+
}
|
|
3492
|
+
|
|
3493
|
+
if ('onloadend' in request) {
|
|
3494
|
+
// Use onloadend if available
|
|
3495
|
+
request.onloadend = onloadend;
|
|
3496
|
+
} else {
|
|
3497
|
+
// Listen for ready state to emulate onloadend
|
|
3498
|
+
request.onreadystatechange = function handleLoad() {
|
|
3499
|
+
if (!request || request.readyState !== 4) {
|
|
3500
|
+
return;
|
|
3501
|
+
}
|
|
3502
|
+
|
|
3503
|
+
// The request errored out and we didn't get a response, this will be
|
|
3504
|
+
// handled by onerror instead
|
|
3505
|
+
// With one exception: request that using file: protocol, most browsers
|
|
3506
|
+
// will return status as 0 even though it's a successful request
|
|
3507
|
+
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
|
|
3508
|
+
return;
|
|
3509
|
+
}
|
|
3510
|
+
// readystate handler is calling before onerror or ontimeout handlers,
|
|
3511
|
+
// so we should call onloadend on the next 'tick'
|
|
3512
|
+
setTimeout(onloadend);
|
|
3513
|
+
};
|
|
3514
|
+
}
|
|
3515
|
+
|
|
3516
|
+
// Handle browser request cancellation (as opposed to a manual cancellation)
|
|
3517
|
+
request.onabort = function handleAbort() {
|
|
3518
|
+
if (!request) {
|
|
3519
|
+
return;
|
|
3520
|
+
}
|
|
3521
|
+
|
|
3522
|
+
reject(new AxiosError_1('Request aborted', AxiosError_1.ECONNABORTED, config, request));
|
|
3523
|
+
|
|
3524
|
+
// Clean up request
|
|
3525
|
+
request = null;
|
|
3526
|
+
};
|
|
3527
|
+
|
|
3528
|
+
// Handle low level network errors
|
|
3529
|
+
request.onerror = function handleError() {
|
|
3530
|
+
// Real errors are hidden from us by the browser
|
|
3531
|
+
// onerror should only fire if it's a network error
|
|
3532
|
+
reject(new AxiosError_1('Network Error', AxiosError_1.ERR_NETWORK, config, request, request));
|
|
3533
|
+
|
|
3534
|
+
// Clean up request
|
|
3535
|
+
request = null;
|
|
3536
|
+
};
|
|
3537
|
+
|
|
3538
|
+
// Handle timeout
|
|
3539
|
+
request.ontimeout = function handleTimeout() {
|
|
3540
|
+
var timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
|
|
3541
|
+
var transitional$1 = config.transitional || transitional;
|
|
3542
|
+
if (config.timeoutErrorMessage) {
|
|
3543
|
+
timeoutErrorMessage = config.timeoutErrorMessage;
|
|
3544
|
+
}
|
|
3545
|
+
reject(new AxiosError_1(
|
|
3546
|
+
timeoutErrorMessage,
|
|
3547
|
+
transitional$1.clarifyTimeoutError ? AxiosError_1.ETIMEDOUT : AxiosError_1.ECONNABORTED,
|
|
3548
|
+
config,
|
|
3549
|
+
request));
|
|
3550
|
+
|
|
3551
|
+
// Clean up request
|
|
3552
|
+
request = null;
|
|
3553
|
+
};
|
|
3554
|
+
|
|
3555
|
+
// Add xsrf header
|
|
3556
|
+
// This is only done if running in a standard browser environment.
|
|
3557
|
+
// Specifically not if we're in a web worker, or react-native.
|
|
3558
|
+
if (utils.isStandardBrowserEnv()) {
|
|
3559
|
+
// Add xsrf header
|
|
3560
|
+
var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ?
|
|
3561
|
+
cookies.read(config.xsrfCookieName) :
|
|
3562
|
+
undefined;
|
|
3563
|
+
|
|
3564
|
+
if (xsrfValue) {
|
|
3565
|
+
requestHeaders[config.xsrfHeaderName] = xsrfValue;
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
|
|
3569
|
+
// Add headers to the request
|
|
3570
|
+
if ('setRequestHeader' in request) {
|
|
3571
|
+
utils.forEach(requestHeaders, function setRequestHeader(val, key) {
|
|
3572
|
+
if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
|
|
3573
|
+
// Remove Content-Type if data is undefined
|
|
3574
|
+
delete requestHeaders[key];
|
|
3575
|
+
} else {
|
|
3576
|
+
// Otherwise add header to the request
|
|
3577
|
+
request.setRequestHeader(key, val);
|
|
3578
|
+
}
|
|
3579
|
+
});
|
|
3580
|
+
}
|
|
3581
|
+
|
|
3582
|
+
// Add withCredentials to request if needed
|
|
3583
|
+
if (!utils.isUndefined(config.withCredentials)) {
|
|
3584
|
+
request.withCredentials = !!config.withCredentials;
|
|
3585
|
+
}
|
|
3586
|
+
|
|
3587
|
+
// Add responseType to request if needed
|
|
3588
|
+
if (responseType && responseType !== 'json') {
|
|
3589
|
+
request.responseType = config.responseType;
|
|
3590
|
+
}
|
|
3591
|
+
|
|
3592
|
+
// Handle progress if needed
|
|
3593
|
+
if (typeof config.onDownloadProgress === 'function') {
|
|
3594
|
+
request.addEventListener('progress', config.onDownloadProgress);
|
|
3595
|
+
}
|
|
3596
|
+
|
|
3597
|
+
// Not all browsers support upload events
|
|
3598
|
+
if (typeof config.onUploadProgress === 'function' && request.upload) {
|
|
3599
|
+
request.upload.addEventListener('progress', config.onUploadProgress);
|
|
3600
|
+
}
|
|
3601
|
+
|
|
3602
|
+
if (config.cancelToken || config.signal) {
|
|
3603
|
+
// Handle cancellation
|
|
3604
|
+
// eslint-disable-next-line func-names
|
|
3605
|
+
onCanceled = function(cancel) {
|
|
3606
|
+
if (!request) {
|
|
3607
|
+
return;
|
|
3608
|
+
}
|
|
3609
|
+
reject(!cancel || (cancel && cancel.type) ? new CanceledError_1() : cancel);
|
|
3610
|
+
request.abort();
|
|
3611
|
+
request = null;
|
|
3612
|
+
};
|
|
3613
|
+
|
|
3614
|
+
config.cancelToken && config.cancelToken.subscribe(onCanceled);
|
|
3615
|
+
if (config.signal) {
|
|
3616
|
+
config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
|
|
3617
|
+
}
|
|
3618
|
+
}
|
|
3619
|
+
|
|
3620
|
+
if (!requestData) {
|
|
3621
|
+
requestData = null;
|
|
3622
|
+
}
|
|
3623
|
+
|
|
3624
|
+
var protocol = parseProtocol(fullPath);
|
|
3625
|
+
|
|
3626
|
+
if (protocol && [ 'http', 'https', 'file' ].indexOf(protocol) === -1) {
|
|
3627
|
+
reject(new AxiosError_1('Unsupported protocol ' + protocol + ':', AxiosError_1.ERR_BAD_REQUEST, config));
|
|
3628
|
+
return;
|
|
3629
|
+
}
|
|
3630
|
+
|
|
3631
|
+
|
|
3632
|
+
// Send the request
|
|
3633
|
+
request.send(requestData);
|
|
3634
|
+
});
|
|
3635
|
+
};
|
|
3636
|
+
|
|
3637
|
+
// eslint-disable-next-line strict
|
|
3638
|
+
var _null = null;
|
|
3639
|
+
|
|
3640
|
+
var DEFAULT_CONTENT_TYPE = {
|
|
3641
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
3642
|
+
};
|
|
3643
|
+
|
|
3644
|
+
function setContentTypeIfUnset(headers, value) {
|
|
3645
|
+
if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
|
|
3646
|
+
headers['Content-Type'] = value;
|
|
3647
|
+
}
|
|
3648
|
+
}
|
|
3649
|
+
|
|
3650
|
+
function getDefaultAdapter() {
|
|
3651
|
+
var adapter;
|
|
3652
|
+
if (typeof XMLHttpRequest !== 'undefined') {
|
|
3653
|
+
// For browsers use XHR adapter
|
|
3654
|
+
adapter = xhr;
|
|
3655
|
+
} else if (typeof process_1 !== 'undefined' && Object.prototype.toString.call(process_1) === '[object process]') {
|
|
3656
|
+
// For node use HTTP adapter
|
|
3657
|
+
adapter = xhr;
|
|
3658
|
+
}
|
|
3659
|
+
return adapter;
|
|
3660
|
+
}
|
|
3661
|
+
|
|
3662
|
+
function stringifySafely(rawValue, parser, encoder) {
|
|
3663
|
+
if (utils.isString(rawValue)) {
|
|
3664
|
+
try {
|
|
3665
|
+
(parser || JSON.parse)(rawValue);
|
|
3666
|
+
return utils.trim(rawValue);
|
|
3667
|
+
} catch (e) {
|
|
3668
|
+
if (e.name !== 'SyntaxError') {
|
|
3669
|
+
throw e;
|
|
3670
|
+
}
|
|
3671
|
+
}
|
|
3672
|
+
}
|
|
3673
|
+
|
|
3674
|
+
return (encoder || JSON.stringify)(rawValue);
|
|
3675
|
+
}
|
|
3676
|
+
|
|
3677
|
+
var defaults = {
|
|
3678
|
+
|
|
3679
|
+
transitional: transitional,
|
|
3680
|
+
|
|
3681
|
+
adapter: getDefaultAdapter(),
|
|
3682
|
+
|
|
3683
|
+
transformRequest: [function transformRequest(data, headers) {
|
|
3684
|
+
normalizeHeaderName(headers, 'Accept');
|
|
3685
|
+
normalizeHeaderName(headers, 'Content-Type');
|
|
3686
|
+
|
|
3687
|
+
if (utils.isFormData(data) ||
|
|
3688
|
+
utils.isArrayBuffer(data) ||
|
|
3689
|
+
utils.isBuffer(data) ||
|
|
3690
|
+
utils.isStream(data) ||
|
|
3691
|
+
utils.isFile(data) ||
|
|
3692
|
+
utils.isBlob(data)
|
|
3693
|
+
) {
|
|
3694
|
+
return data;
|
|
3695
|
+
}
|
|
3696
|
+
if (utils.isArrayBufferView(data)) {
|
|
3697
|
+
return data.buffer;
|
|
3698
|
+
}
|
|
3699
|
+
if (utils.isURLSearchParams(data)) {
|
|
3700
|
+
setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
|
|
3701
|
+
return data.toString();
|
|
3702
|
+
}
|
|
3703
|
+
|
|
3704
|
+
var isObjectPayload = utils.isObject(data);
|
|
3705
|
+
var contentType = headers && headers['Content-Type'];
|
|
3706
|
+
|
|
3707
|
+
var isFileList;
|
|
3708
|
+
|
|
3709
|
+
if ((isFileList = utils.isFileList(data)) || (isObjectPayload && contentType === 'multipart/form-data')) {
|
|
3710
|
+
var _FormData = this.env && this.env.FormData;
|
|
3711
|
+
return toFormData_1(isFileList ? {'files[]': data} : data, _FormData && new _FormData());
|
|
3712
|
+
} else if (isObjectPayload || contentType === 'application/json') {
|
|
3713
|
+
setContentTypeIfUnset(headers, 'application/json');
|
|
3714
|
+
return stringifySafely(data);
|
|
3715
|
+
}
|
|
3716
|
+
|
|
3717
|
+
return data;
|
|
3718
|
+
}],
|
|
3719
|
+
|
|
3720
|
+
transformResponse: [function transformResponse(data) {
|
|
3721
|
+
var transitional = this.transitional || defaults.transitional;
|
|
3722
|
+
var silentJSONParsing = transitional && transitional.silentJSONParsing;
|
|
3723
|
+
var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
|
|
3724
|
+
var strictJSONParsing = !silentJSONParsing && this.responseType === 'json';
|
|
3725
|
+
|
|
3726
|
+
if (strictJSONParsing || (forcedJSONParsing && utils.isString(data) && data.length)) {
|
|
3727
|
+
try {
|
|
3728
|
+
return JSON.parse(data);
|
|
3729
|
+
} catch (e) {
|
|
3730
|
+
if (strictJSONParsing) {
|
|
3731
|
+
if (e.name === 'SyntaxError') {
|
|
3732
|
+
throw AxiosError_1.from(e, AxiosError_1.ERR_BAD_RESPONSE, this, null, this.response);
|
|
3733
|
+
}
|
|
3734
|
+
throw e;
|
|
3735
|
+
}
|
|
3736
|
+
}
|
|
3737
|
+
}
|
|
3738
|
+
|
|
3739
|
+
return data;
|
|
3740
|
+
}],
|
|
3741
|
+
|
|
3742
|
+
/**
|
|
3743
|
+
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
|
3744
|
+
* timeout is not created.
|
|
3745
|
+
*/
|
|
3746
|
+
timeout: 0,
|
|
3747
|
+
|
|
3748
|
+
xsrfCookieName: 'XSRF-TOKEN',
|
|
3749
|
+
xsrfHeaderName: 'X-XSRF-TOKEN',
|
|
3750
|
+
|
|
3751
|
+
maxContentLength: -1,
|
|
3752
|
+
maxBodyLength: -1,
|
|
3753
|
+
|
|
3754
|
+
env: {
|
|
3755
|
+
FormData: _null
|
|
3756
|
+
},
|
|
3757
|
+
|
|
3758
|
+
validateStatus: function validateStatus(status) {
|
|
3759
|
+
return status >= 200 && status < 300;
|
|
3760
|
+
},
|
|
3761
|
+
|
|
3762
|
+
headers: {
|
|
3763
|
+
common: {
|
|
3764
|
+
'Accept': 'application/json, text/plain, */*'
|
|
3765
|
+
}
|
|
3766
|
+
}
|
|
3767
|
+
};
|
|
3768
|
+
|
|
3769
|
+
utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
|
|
3770
|
+
defaults.headers[method] = {};
|
|
3771
|
+
});
|
|
3772
|
+
|
|
3773
|
+
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
|
3774
|
+
defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
|
|
3775
|
+
});
|
|
3776
|
+
|
|
3777
|
+
var defaults_1 = defaults;
|
|
3778
|
+
|
|
3779
|
+
/**
|
|
3780
|
+
* Transform the data for a request or a response
|
|
3781
|
+
*
|
|
3782
|
+
* @param {Object|String} data The data to be transformed
|
|
3783
|
+
* @param {Array} headers The headers for the request or response
|
|
3784
|
+
* @param {Array|Function} fns A single function or Array of functions
|
|
3785
|
+
* @returns {*} The resulting transformed data
|
|
3786
|
+
*/
|
|
3787
|
+
var transformData = function transformData(data, headers, fns) {
|
|
3788
|
+
var context = this || defaults_1;
|
|
3789
|
+
/*eslint no-param-reassign:0*/
|
|
3790
|
+
utils.forEach(fns, function transform(fn) {
|
|
3791
|
+
data = fn.call(context, data, headers);
|
|
3792
|
+
});
|
|
3793
|
+
|
|
3794
|
+
return data;
|
|
3795
|
+
};
|
|
3796
|
+
|
|
3797
|
+
var isCancel = function isCancel(value) {
|
|
3798
|
+
return !!(value && value.__CANCEL__);
|
|
3799
|
+
};
|
|
3800
|
+
|
|
3801
|
+
/**
|
|
3802
|
+
* Throws a `CanceledError` if cancellation has been requested.
|
|
3803
|
+
*/
|
|
3804
|
+
function throwIfCancellationRequested(config) {
|
|
3805
|
+
if (config.cancelToken) {
|
|
3806
|
+
config.cancelToken.throwIfRequested();
|
|
3807
|
+
}
|
|
3808
|
+
|
|
3809
|
+
if (config.signal && config.signal.aborted) {
|
|
3810
|
+
throw new CanceledError_1();
|
|
3811
|
+
}
|
|
3812
|
+
}
|
|
3813
|
+
|
|
3814
|
+
/**
|
|
3815
|
+
* Dispatch a request to the server using the configured adapter.
|
|
3816
|
+
*
|
|
3817
|
+
* @param {object} config The config that is to be used for the request
|
|
3818
|
+
* @returns {Promise} The Promise to be fulfilled
|
|
3819
|
+
*/
|
|
3820
|
+
var dispatchRequest = function dispatchRequest(config) {
|
|
3821
|
+
throwIfCancellationRequested(config);
|
|
3822
|
+
|
|
3823
|
+
// Ensure headers exist
|
|
3824
|
+
config.headers = config.headers || {};
|
|
3825
|
+
|
|
3826
|
+
// Transform request data
|
|
3827
|
+
config.data = transformData.call(
|
|
3828
|
+
config,
|
|
3829
|
+
config.data,
|
|
3830
|
+
config.headers,
|
|
3831
|
+
config.transformRequest
|
|
3832
|
+
);
|
|
3833
|
+
|
|
3834
|
+
// Flatten headers
|
|
3835
|
+
config.headers = utils.merge(
|
|
3836
|
+
config.headers.common || {},
|
|
3837
|
+
config.headers[config.method] || {},
|
|
3838
|
+
config.headers
|
|
3839
|
+
);
|
|
3840
|
+
|
|
3841
|
+
utils.forEach(
|
|
3842
|
+
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
|
3843
|
+
function cleanHeaderConfig(method) {
|
|
3844
|
+
delete config.headers[method];
|
|
3845
|
+
}
|
|
3846
|
+
);
|
|
3847
|
+
|
|
3848
|
+
var adapter = config.adapter || defaults_1.adapter;
|
|
3849
|
+
|
|
3850
|
+
return adapter(config).then(function onAdapterResolution(response) {
|
|
3851
|
+
throwIfCancellationRequested(config);
|
|
3852
|
+
|
|
3853
|
+
// Transform response data
|
|
3854
|
+
response.data = transformData.call(
|
|
3855
|
+
config,
|
|
3856
|
+
response.data,
|
|
3857
|
+
response.headers,
|
|
3858
|
+
config.transformResponse
|
|
3859
|
+
);
|
|
3860
|
+
|
|
3861
|
+
return response;
|
|
3862
|
+
}, function onAdapterRejection(reason) {
|
|
3863
|
+
if (!isCancel(reason)) {
|
|
3864
|
+
throwIfCancellationRequested(config);
|
|
3865
|
+
|
|
3866
|
+
// Transform response data
|
|
3867
|
+
if (reason && reason.response) {
|
|
3868
|
+
reason.response.data = transformData.call(
|
|
3869
|
+
config,
|
|
3870
|
+
reason.response.data,
|
|
3871
|
+
reason.response.headers,
|
|
3872
|
+
config.transformResponse
|
|
3873
|
+
);
|
|
3874
|
+
}
|
|
3875
|
+
}
|
|
3876
|
+
|
|
3877
|
+
return Promise.reject(reason);
|
|
3878
|
+
});
|
|
3879
|
+
};
|
|
3880
|
+
|
|
3881
|
+
/**
|
|
3882
|
+
* Config-specific merge-function which creates a new config-object
|
|
3883
|
+
* by merging two configuration objects together.
|
|
3884
|
+
*
|
|
3885
|
+
* @param {Object} config1
|
|
3886
|
+
* @param {Object} config2
|
|
3887
|
+
* @returns {Object} New object resulting from merging config2 to config1
|
|
3888
|
+
*/
|
|
3889
|
+
var mergeConfig = function mergeConfig(config1, config2) {
|
|
3890
|
+
// eslint-disable-next-line no-param-reassign
|
|
3891
|
+
config2 = config2 || {};
|
|
3892
|
+
var config = {};
|
|
3893
|
+
|
|
3894
|
+
function getMergedValue(target, source) {
|
|
3895
|
+
if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
|
|
3896
|
+
return utils.merge(target, source);
|
|
3897
|
+
} else if (utils.isPlainObject(source)) {
|
|
3898
|
+
return utils.merge({}, source);
|
|
3899
|
+
} else if (utils.isArray(source)) {
|
|
3900
|
+
return source.slice();
|
|
3901
|
+
}
|
|
3902
|
+
return source;
|
|
3903
|
+
}
|
|
3904
|
+
|
|
3905
|
+
// eslint-disable-next-line consistent-return
|
|
3906
|
+
function mergeDeepProperties(prop) {
|
|
3907
|
+
if (!utils.isUndefined(config2[prop])) {
|
|
3908
|
+
return getMergedValue(config1[prop], config2[prop]);
|
|
3909
|
+
} else if (!utils.isUndefined(config1[prop])) {
|
|
3910
|
+
return getMergedValue(undefined, config1[prop]);
|
|
3911
|
+
}
|
|
3912
|
+
}
|
|
3913
|
+
|
|
3914
|
+
// eslint-disable-next-line consistent-return
|
|
3915
|
+
function valueFromConfig2(prop) {
|
|
3916
|
+
if (!utils.isUndefined(config2[prop])) {
|
|
3917
|
+
return getMergedValue(undefined, config2[prop]);
|
|
3918
|
+
}
|
|
3919
|
+
}
|
|
3920
|
+
|
|
3921
|
+
// eslint-disable-next-line consistent-return
|
|
3922
|
+
function defaultToConfig2(prop) {
|
|
3923
|
+
if (!utils.isUndefined(config2[prop])) {
|
|
3924
|
+
return getMergedValue(undefined, config2[prop]);
|
|
3925
|
+
} else if (!utils.isUndefined(config1[prop])) {
|
|
3926
|
+
return getMergedValue(undefined, config1[prop]);
|
|
3927
|
+
}
|
|
3928
|
+
}
|
|
3929
|
+
|
|
3930
|
+
// eslint-disable-next-line consistent-return
|
|
3931
|
+
function mergeDirectKeys(prop) {
|
|
3932
|
+
if (prop in config2) {
|
|
3933
|
+
return getMergedValue(config1[prop], config2[prop]);
|
|
3934
|
+
} else if (prop in config1) {
|
|
3935
|
+
return getMergedValue(undefined, config1[prop]);
|
|
3936
|
+
}
|
|
3937
|
+
}
|
|
3938
|
+
|
|
3939
|
+
var mergeMap = {
|
|
3940
|
+
'url': valueFromConfig2,
|
|
3941
|
+
'method': valueFromConfig2,
|
|
3942
|
+
'data': valueFromConfig2,
|
|
3943
|
+
'baseURL': defaultToConfig2,
|
|
3944
|
+
'transformRequest': defaultToConfig2,
|
|
3945
|
+
'transformResponse': defaultToConfig2,
|
|
3946
|
+
'paramsSerializer': defaultToConfig2,
|
|
3947
|
+
'timeout': defaultToConfig2,
|
|
3948
|
+
'timeoutMessage': defaultToConfig2,
|
|
3949
|
+
'withCredentials': defaultToConfig2,
|
|
3950
|
+
'adapter': defaultToConfig2,
|
|
3951
|
+
'responseType': defaultToConfig2,
|
|
3952
|
+
'xsrfCookieName': defaultToConfig2,
|
|
3953
|
+
'xsrfHeaderName': defaultToConfig2,
|
|
3954
|
+
'onUploadProgress': defaultToConfig2,
|
|
3955
|
+
'onDownloadProgress': defaultToConfig2,
|
|
3956
|
+
'decompress': defaultToConfig2,
|
|
3957
|
+
'maxContentLength': defaultToConfig2,
|
|
3958
|
+
'maxBodyLength': defaultToConfig2,
|
|
3959
|
+
'beforeRedirect': defaultToConfig2,
|
|
3960
|
+
'transport': defaultToConfig2,
|
|
3961
|
+
'httpAgent': defaultToConfig2,
|
|
3962
|
+
'httpsAgent': defaultToConfig2,
|
|
3963
|
+
'cancelToken': defaultToConfig2,
|
|
3964
|
+
'socketPath': defaultToConfig2,
|
|
3965
|
+
'responseEncoding': defaultToConfig2,
|
|
3966
|
+
'validateStatus': mergeDirectKeys
|
|
3967
|
+
};
|
|
3968
|
+
|
|
3969
|
+
utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
|
|
3970
|
+
var merge = mergeMap[prop] || mergeDeepProperties;
|
|
3971
|
+
var configValue = merge(prop);
|
|
3972
|
+
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
|
3973
|
+
});
|
|
3974
|
+
|
|
3975
|
+
return config;
|
|
3976
|
+
};
|
|
3977
|
+
|
|
3978
|
+
var data = {
|
|
3979
|
+
"version": "0.27.2"
|
|
3980
|
+
};
|
|
3981
|
+
|
|
3982
|
+
var VERSION = data.version;
|
|
3983
|
+
|
|
3984
|
+
|
|
3985
|
+
var validators$1 = {};
|
|
3986
|
+
|
|
3987
|
+
// eslint-disable-next-line func-names
|
|
3988
|
+
['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach(function(type, i) {
|
|
3989
|
+
validators$1[type] = function validator(thing) {
|
|
3990
|
+
return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
|
|
3991
|
+
};
|
|
3992
|
+
});
|
|
3993
|
+
|
|
3994
|
+
var deprecatedWarnings = {};
|
|
3995
|
+
|
|
3996
|
+
/**
|
|
3997
|
+
* Transitional option validator
|
|
3998
|
+
* @param {function|boolean?} validator - set to false if the transitional option has been removed
|
|
3999
|
+
* @param {string?} version - deprecated version / removed since version
|
|
4000
|
+
* @param {string?} message - some message with additional info
|
|
4001
|
+
* @returns {function}
|
|
4002
|
+
*/
|
|
4003
|
+
validators$1.transitional = function transitional(validator, version, message) {
|
|
4004
|
+
function formatMessage(opt, desc) {
|
|
4005
|
+
return '[Axios v' + VERSION + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : '');
|
|
4006
|
+
}
|
|
4007
|
+
|
|
4008
|
+
// eslint-disable-next-line func-names
|
|
4009
|
+
return function(value, opt, opts) {
|
|
4010
|
+
if (validator === false) {
|
|
4011
|
+
throw new AxiosError_1(
|
|
4012
|
+
formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')),
|
|
4013
|
+
AxiosError_1.ERR_DEPRECATED
|
|
4014
|
+
);
|
|
4015
|
+
}
|
|
4016
|
+
|
|
4017
|
+
if (version && !deprecatedWarnings[opt]) {
|
|
4018
|
+
deprecatedWarnings[opt] = true;
|
|
4019
|
+
// eslint-disable-next-line no-console
|
|
4020
|
+
console.warn(
|
|
4021
|
+
formatMessage(
|
|
4022
|
+
opt,
|
|
4023
|
+
' has been deprecated since v' + version + ' and will be removed in the near future'
|
|
4024
|
+
)
|
|
4025
|
+
);
|
|
4026
|
+
}
|
|
4027
|
+
|
|
4028
|
+
return validator ? validator(value, opt, opts) : true;
|
|
4029
|
+
};
|
|
4030
|
+
};
|
|
4031
|
+
|
|
4032
|
+
/**
|
|
4033
|
+
* Assert object's properties type
|
|
4034
|
+
* @param {object} options
|
|
4035
|
+
* @param {object} schema
|
|
4036
|
+
* @param {boolean?} allowUnknown
|
|
4037
|
+
*/
|
|
4038
|
+
|
|
4039
|
+
function assertOptions(options, schema, allowUnknown) {
|
|
4040
|
+
if (typeof options !== 'object') {
|
|
4041
|
+
throw new AxiosError_1('options must be an object', AxiosError_1.ERR_BAD_OPTION_VALUE);
|
|
4042
|
+
}
|
|
4043
|
+
var keys = Object.keys(options);
|
|
4044
|
+
var i = keys.length;
|
|
4045
|
+
while (i-- > 0) {
|
|
4046
|
+
var opt = keys[i];
|
|
4047
|
+
var validator = schema[opt];
|
|
4048
|
+
if (validator) {
|
|
4049
|
+
var value = options[opt];
|
|
4050
|
+
var result = value === undefined || validator(value, opt, options);
|
|
4051
|
+
if (result !== true) {
|
|
4052
|
+
throw new AxiosError_1('option ' + opt + ' must be ' + result, AxiosError_1.ERR_BAD_OPTION_VALUE);
|
|
4053
|
+
}
|
|
4054
|
+
continue;
|
|
4055
|
+
}
|
|
4056
|
+
if (allowUnknown !== true) {
|
|
4057
|
+
throw new AxiosError_1('Unknown option ' + opt, AxiosError_1.ERR_BAD_OPTION);
|
|
4058
|
+
}
|
|
4059
|
+
}
|
|
4060
|
+
}
|
|
4061
|
+
|
|
4062
|
+
var validator = {
|
|
4063
|
+
assertOptions: assertOptions,
|
|
4064
|
+
validators: validators$1
|
|
4065
|
+
};
|
|
4066
|
+
|
|
4067
|
+
var validators = validator.validators;
|
|
4068
|
+
/**
|
|
4069
|
+
* Create a new instance of Axios
|
|
4070
|
+
*
|
|
4071
|
+
* @param {Object} instanceConfig The default config for the instance
|
|
4072
|
+
*/
|
|
4073
|
+
function Axios(instanceConfig) {
|
|
4074
|
+
this.defaults = instanceConfig;
|
|
4075
|
+
this.interceptors = {
|
|
4076
|
+
request: new InterceptorManager_1(),
|
|
4077
|
+
response: new InterceptorManager_1()
|
|
4078
|
+
};
|
|
4079
|
+
}
|
|
4080
|
+
|
|
4081
|
+
/**
|
|
4082
|
+
* Dispatch a request
|
|
4083
|
+
*
|
|
4084
|
+
* @param {Object} config The config specific for this request (merged with this.defaults)
|
|
4085
|
+
*/
|
|
4086
|
+
Axios.prototype.request = function request(configOrUrl, config) {
|
|
4087
|
+
/*eslint no-param-reassign:0*/
|
|
4088
|
+
// Allow for axios('example/url'[, config]) a la fetch API
|
|
4089
|
+
if (typeof configOrUrl === 'string') {
|
|
4090
|
+
config = config || {};
|
|
4091
|
+
config.url = configOrUrl;
|
|
4092
|
+
} else {
|
|
4093
|
+
config = configOrUrl || {};
|
|
4094
|
+
}
|
|
4095
|
+
|
|
4096
|
+
config = mergeConfig(this.defaults, config);
|
|
4097
|
+
|
|
4098
|
+
// Set config.method
|
|
4099
|
+
if (config.method) {
|
|
4100
|
+
config.method = config.method.toLowerCase();
|
|
4101
|
+
} else if (this.defaults.method) {
|
|
4102
|
+
config.method = this.defaults.method.toLowerCase();
|
|
4103
|
+
} else {
|
|
4104
|
+
config.method = 'get';
|
|
4105
|
+
}
|
|
4106
|
+
|
|
4107
|
+
var transitional = config.transitional;
|
|
4108
|
+
|
|
4109
|
+
if (transitional !== undefined) {
|
|
4110
|
+
validator.assertOptions(transitional, {
|
|
4111
|
+
silentJSONParsing: validators.transitional(validators.boolean),
|
|
4112
|
+
forcedJSONParsing: validators.transitional(validators.boolean),
|
|
4113
|
+
clarifyTimeoutError: validators.transitional(validators.boolean)
|
|
4114
|
+
}, false);
|
|
4115
|
+
}
|
|
4116
|
+
|
|
4117
|
+
// filter out skipped interceptors
|
|
4118
|
+
var requestInterceptorChain = [];
|
|
4119
|
+
var synchronousRequestInterceptors = true;
|
|
4120
|
+
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
|
4121
|
+
if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
|
|
4122
|
+
return;
|
|
4123
|
+
}
|
|
4124
|
+
|
|
4125
|
+
synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
|
4126
|
+
|
|
4127
|
+
requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
|
4128
|
+
});
|
|
4129
|
+
|
|
4130
|
+
var responseInterceptorChain = [];
|
|
4131
|
+
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
|
4132
|
+
responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
|
4133
|
+
});
|
|
4134
|
+
|
|
4135
|
+
var promise;
|
|
4136
|
+
|
|
4137
|
+
if (!synchronousRequestInterceptors) {
|
|
4138
|
+
var chain = [dispatchRequest, undefined];
|
|
4139
|
+
|
|
4140
|
+
Array.prototype.unshift.apply(chain, requestInterceptorChain);
|
|
4141
|
+
chain = chain.concat(responseInterceptorChain);
|
|
4142
|
+
|
|
4143
|
+
promise = Promise.resolve(config);
|
|
4144
|
+
while (chain.length) {
|
|
4145
|
+
promise = promise.then(chain.shift(), chain.shift());
|
|
4146
|
+
}
|
|
4147
|
+
|
|
4148
|
+
return promise;
|
|
4149
|
+
}
|
|
4150
|
+
|
|
4151
|
+
|
|
4152
|
+
var newConfig = config;
|
|
4153
|
+
while (requestInterceptorChain.length) {
|
|
4154
|
+
var onFulfilled = requestInterceptorChain.shift();
|
|
4155
|
+
var onRejected = requestInterceptorChain.shift();
|
|
4156
|
+
try {
|
|
4157
|
+
newConfig = onFulfilled(newConfig);
|
|
4158
|
+
} catch (error) {
|
|
4159
|
+
onRejected(error);
|
|
4160
|
+
break;
|
|
4161
|
+
}
|
|
4162
|
+
}
|
|
4163
|
+
|
|
4164
|
+
try {
|
|
4165
|
+
promise = dispatchRequest(newConfig);
|
|
4166
|
+
} catch (error) {
|
|
4167
|
+
return Promise.reject(error);
|
|
4168
|
+
}
|
|
4169
|
+
|
|
4170
|
+
while (responseInterceptorChain.length) {
|
|
4171
|
+
promise = promise.then(responseInterceptorChain.shift(), responseInterceptorChain.shift());
|
|
4172
|
+
}
|
|
4173
|
+
|
|
4174
|
+
return promise;
|
|
4175
|
+
};
|
|
4176
|
+
|
|
4177
|
+
Axios.prototype.getUri = function getUri(config) {
|
|
4178
|
+
config = mergeConfig(this.defaults, config);
|
|
4179
|
+
var fullPath = buildFullPath(config.baseURL, config.url);
|
|
4180
|
+
return buildURL(fullPath, config.params, config.paramsSerializer);
|
|
4181
|
+
};
|
|
4182
|
+
|
|
4183
|
+
// Provide aliases for supported request methods
|
|
4184
|
+
utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
|
|
4185
|
+
/*eslint func-names:0*/
|
|
4186
|
+
Axios.prototype[method] = function(url, config) {
|
|
4187
|
+
return this.request(mergeConfig(config || {}, {
|
|
4188
|
+
method: method,
|
|
4189
|
+
url: url,
|
|
4190
|
+
data: (config || {}).data
|
|
4191
|
+
}));
|
|
4192
|
+
};
|
|
4193
|
+
});
|
|
4194
|
+
|
|
4195
|
+
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
|
4196
|
+
/*eslint func-names:0*/
|
|
4197
|
+
|
|
4198
|
+
function generateHTTPMethod(isForm) {
|
|
4199
|
+
return function httpMethod(url, data, config) {
|
|
4200
|
+
return this.request(mergeConfig(config || {}, {
|
|
4201
|
+
method: method,
|
|
4202
|
+
headers: isForm ? {
|
|
4203
|
+
'Content-Type': 'multipart/form-data'
|
|
4204
|
+
} : {},
|
|
4205
|
+
url: url,
|
|
4206
|
+
data: data
|
|
4207
|
+
}));
|
|
4208
|
+
};
|
|
4209
|
+
}
|
|
4210
|
+
|
|
4211
|
+
Axios.prototype[method] = generateHTTPMethod();
|
|
4212
|
+
|
|
4213
|
+
Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
|
4214
|
+
});
|
|
4215
|
+
|
|
4216
|
+
var Axios_1 = Axios;
|
|
4217
|
+
|
|
4218
|
+
/**
|
|
4219
|
+
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
|
4220
|
+
*
|
|
4221
|
+
* @class
|
|
4222
|
+
* @param {Function} executor The executor function.
|
|
4223
|
+
*/
|
|
4224
|
+
function CancelToken(executor) {
|
|
4225
|
+
if (typeof executor !== 'function') {
|
|
4226
|
+
throw new TypeError('executor must be a function.');
|
|
4227
|
+
}
|
|
4228
|
+
|
|
4229
|
+
var resolvePromise;
|
|
4230
|
+
|
|
4231
|
+
this.promise = new Promise(function promiseExecutor(resolve) {
|
|
4232
|
+
resolvePromise = resolve;
|
|
4233
|
+
});
|
|
4234
|
+
|
|
4235
|
+
var token = this;
|
|
4236
|
+
|
|
4237
|
+
// eslint-disable-next-line func-names
|
|
4238
|
+
this.promise.then(function(cancel) {
|
|
4239
|
+
if (!token._listeners) return;
|
|
4240
|
+
|
|
4241
|
+
var i;
|
|
4242
|
+
var l = token._listeners.length;
|
|
4243
|
+
|
|
4244
|
+
for (i = 0; i < l; i++) {
|
|
4245
|
+
token._listeners[i](cancel);
|
|
4246
|
+
}
|
|
4247
|
+
token._listeners = null;
|
|
4248
|
+
});
|
|
4249
|
+
|
|
4250
|
+
// eslint-disable-next-line func-names
|
|
4251
|
+
this.promise.then = function(onfulfilled) {
|
|
4252
|
+
var _resolve;
|
|
4253
|
+
// eslint-disable-next-line func-names
|
|
4254
|
+
var promise = new Promise(function(resolve) {
|
|
4255
|
+
token.subscribe(resolve);
|
|
4256
|
+
_resolve = resolve;
|
|
4257
|
+
}).then(onfulfilled);
|
|
4258
|
+
|
|
4259
|
+
promise.cancel = function reject() {
|
|
4260
|
+
token.unsubscribe(_resolve);
|
|
4261
|
+
};
|
|
4262
|
+
|
|
4263
|
+
return promise;
|
|
4264
|
+
};
|
|
4265
|
+
|
|
4266
|
+
executor(function cancel(message) {
|
|
4267
|
+
if (token.reason) {
|
|
4268
|
+
// Cancellation has already been requested
|
|
4269
|
+
return;
|
|
4270
|
+
}
|
|
4271
|
+
|
|
4272
|
+
token.reason = new CanceledError_1(message);
|
|
4273
|
+
resolvePromise(token.reason);
|
|
4274
|
+
});
|
|
4275
|
+
}
|
|
4276
|
+
|
|
4277
|
+
/**
|
|
4278
|
+
* Throws a `CanceledError` if cancellation has been requested.
|
|
4279
|
+
*/
|
|
4280
|
+
CancelToken.prototype.throwIfRequested = function throwIfRequested() {
|
|
4281
|
+
if (this.reason) {
|
|
4282
|
+
throw this.reason;
|
|
4283
|
+
}
|
|
4284
|
+
};
|
|
4285
|
+
|
|
4286
|
+
/**
|
|
4287
|
+
* Subscribe to the cancel signal
|
|
4288
|
+
*/
|
|
4289
|
+
|
|
4290
|
+
CancelToken.prototype.subscribe = function subscribe(listener) {
|
|
4291
|
+
if (this.reason) {
|
|
4292
|
+
listener(this.reason);
|
|
4293
|
+
return;
|
|
4294
|
+
}
|
|
4295
|
+
|
|
4296
|
+
if (this._listeners) {
|
|
4297
|
+
this._listeners.push(listener);
|
|
4298
|
+
} else {
|
|
4299
|
+
this._listeners = [listener];
|
|
4300
|
+
}
|
|
4301
|
+
};
|
|
4302
|
+
|
|
4303
|
+
/**
|
|
4304
|
+
* Unsubscribe from the cancel signal
|
|
4305
|
+
*/
|
|
4306
|
+
|
|
4307
|
+
CancelToken.prototype.unsubscribe = function unsubscribe(listener) {
|
|
4308
|
+
if (!this._listeners) {
|
|
4309
|
+
return;
|
|
4310
|
+
}
|
|
4311
|
+
var index = this._listeners.indexOf(listener);
|
|
4312
|
+
if (index !== -1) {
|
|
4313
|
+
this._listeners.splice(index, 1);
|
|
4314
|
+
}
|
|
4315
|
+
};
|
|
4316
|
+
|
|
4317
|
+
/**
|
|
4318
|
+
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
|
4319
|
+
* cancels the `CancelToken`.
|
|
4320
|
+
*/
|
|
4321
|
+
CancelToken.source = function source() {
|
|
4322
|
+
var cancel;
|
|
4323
|
+
var token = new CancelToken(function executor(c) {
|
|
4324
|
+
cancel = c;
|
|
4325
|
+
});
|
|
4326
|
+
return {
|
|
4327
|
+
token: token,
|
|
4328
|
+
cancel: cancel
|
|
4329
|
+
};
|
|
4330
|
+
};
|
|
4331
|
+
|
|
4332
|
+
var CancelToken_1 = CancelToken;
|
|
4333
|
+
|
|
4334
|
+
/**
|
|
4335
|
+
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
|
4336
|
+
*
|
|
4337
|
+
* Common use case would be to use `Function.prototype.apply`.
|
|
4338
|
+
*
|
|
4339
|
+
* ```js
|
|
4340
|
+
* function f(x, y, z) {}
|
|
4341
|
+
* var args = [1, 2, 3];
|
|
4342
|
+
* f.apply(null, args);
|
|
4343
|
+
* ```
|
|
4344
|
+
*
|
|
4345
|
+
* With `spread` this example can be re-written.
|
|
4346
|
+
*
|
|
4347
|
+
* ```js
|
|
4348
|
+
* spread(function(x, y, z) {})([1, 2, 3]);
|
|
4349
|
+
* ```
|
|
4350
|
+
*
|
|
4351
|
+
* @param {Function} callback
|
|
4352
|
+
* @returns {Function}
|
|
4353
|
+
*/
|
|
4354
|
+
var spread = function spread(callback) {
|
|
4355
|
+
return function wrap(arr) {
|
|
4356
|
+
return callback.apply(null, arr);
|
|
4357
|
+
};
|
|
4358
|
+
};
|
|
4359
|
+
|
|
4360
|
+
/**
|
|
4361
|
+
* Determines whether the payload is an error thrown by Axios
|
|
4362
|
+
*
|
|
4363
|
+
* @param {*} payload The value to test
|
|
4364
|
+
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
|
4365
|
+
*/
|
|
4366
|
+
var isAxiosError = function isAxiosError(payload) {
|
|
4367
|
+
return utils.isObject(payload) && (payload.isAxiosError === true);
|
|
4368
|
+
};
|
|
4369
|
+
|
|
4370
|
+
/**
|
|
4371
|
+
* Create an instance of Axios
|
|
4372
|
+
*
|
|
4373
|
+
* @param {Object} defaultConfig The default config for the instance
|
|
4374
|
+
* @return {Axios} A new instance of Axios
|
|
4375
|
+
*/
|
|
4376
|
+
function createInstance(defaultConfig) {
|
|
4377
|
+
var context = new Axios_1(defaultConfig);
|
|
4378
|
+
var instance = bind(Axios_1.prototype.request, context);
|
|
4379
|
+
|
|
4380
|
+
// Copy axios.prototype to instance
|
|
4381
|
+
utils.extend(instance, Axios_1.prototype, context);
|
|
4382
|
+
|
|
4383
|
+
// Copy context to instance
|
|
4384
|
+
utils.extend(instance, context);
|
|
4385
|
+
|
|
4386
|
+
// Factory for creating new instances
|
|
4387
|
+
instance.create = function create(instanceConfig) {
|
|
4388
|
+
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
|
4389
|
+
};
|
|
4390
|
+
|
|
4391
|
+
return instance;
|
|
4392
|
+
}
|
|
4393
|
+
|
|
4394
|
+
// Create the default instance to be exported
|
|
4395
|
+
var axios$1 = createInstance(defaults_1);
|
|
4396
|
+
|
|
4397
|
+
// Expose Axios class to allow class inheritance
|
|
4398
|
+
axios$1.Axios = Axios_1;
|
|
4399
|
+
|
|
4400
|
+
// Expose Cancel & CancelToken
|
|
4401
|
+
axios$1.CanceledError = CanceledError_1;
|
|
4402
|
+
axios$1.CancelToken = CancelToken_1;
|
|
4403
|
+
axios$1.isCancel = isCancel;
|
|
4404
|
+
axios$1.VERSION = data.version;
|
|
4405
|
+
axios$1.toFormData = toFormData_1;
|
|
4406
|
+
|
|
4407
|
+
// Expose AxiosError class
|
|
4408
|
+
axios$1.AxiosError = AxiosError_1;
|
|
4409
|
+
|
|
4410
|
+
// alias for CanceledError for backward compatibility
|
|
4411
|
+
axios$1.Cancel = axios$1.CanceledError;
|
|
4412
|
+
|
|
4413
|
+
// Expose all/spread
|
|
4414
|
+
axios$1.all = function all(promises) {
|
|
4415
|
+
return Promise.all(promises);
|
|
4416
|
+
};
|
|
4417
|
+
axios$1.spread = spread;
|
|
4418
|
+
|
|
4419
|
+
// Expose isAxiosError
|
|
4420
|
+
axios$1.isAxiosError = isAxiosError;
|
|
4421
|
+
|
|
4422
|
+
var axios_1 = axios$1;
|
|
4423
|
+
|
|
4424
|
+
// Allow use of default import syntax in TypeScript
|
|
4425
|
+
var _default = axios$1;
|
|
4426
|
+
axios_1.default = _default;
|
|
4427
|
+
|
|
4428
|
+
var axios = axios_1;
|
|
4429
|
+
|
|
4430
|
+
// This file provides a polyfill for managing globals in both NodeJS and browser environments. This is
|
|
4431
|
+
// an anti-pattern we'd hoped to avoid, but we have several projects dependending on one common library
|
|
4432
|
+
// (this js-sdk) and we want that library to provide a common endpoint to all callers (so authentication
|
|
4433
|
+
// tokens only need to be tracked in one place). The trouble is, one of those libraries is based on
|
|
4434
|
+
// StencilJS and is compiling its modules into Web Components. Because of how module resolution works,
|
|
4435
|
+
// when those Components load js-sdk they get a separate instance. Without messy options like having to
|
|
4436
|
+
// pass raw data from the caller to each Component, or pass around references to a common Endpoint, they
|
|
4437
|
+
// have no way to access authenticated sessions unless we make the Endpoint a true global.
|
|
4438
|
+
//
|
|
4439
|
+
// @credit https://github.com/medikoo/es5-ext/blob/master/global.js
|
|
4440
|
+
// @credit https://mathiasbynens.be/notes/globalthis
|
|
4441
|
+
var naiveFallback = function () {
|
|
4442
|
+
if (typeof self === 'object' && self)
|
|
4443
|
+
return self;
|
|
4444
|
+
if (typeof window === 'object' && window)
|
|
4445
|
+
return window;
|
|
4446
|
+
throw new Error('Unable to resolve global `this`');
|
|
4447
|
+
};
|
|
4448
|
+
var globalThis_1 = (function () {
|
|
4449
|
+
if (this)
|
|
4450
|
+
return this;
|
|
4451
|
+
// Unexpected strict mode (may happen if e.g. bundled into ESM module)
|
|
4452
|
+
// Fallback to standard globalThis if available
|
|
4453
|
+
if (typeof globalThis === 'object' && globalThis)
|
|
4454
|
+
return globalThis;
|
|
4455
|
+
// Thanks @mathiasbynens -> https://mathiasbynens.be/notes/globalthis
|
|
4456
|
+
// In all ES5+ engines global object inherits from Object.prototype
|
|
4457
|
+
// (if you approached one that doesn't please report)
|
|
4458
|
+
try {
|
|
4459
|
+
Object.defineProperty(Object.prototype, '__global__', {
|
|
4460
|
+
get: function () {
|
|
4461
|
+
return this;
|
|
4462
|
+
},
|
|
4463
|
+
configurable: true,
|
|
4464
|
+
});
|
|
4465
|
+
}
|
|
4466
|
+
catch (error) {
|
|
4467
|
+
// Unfortunate case of updates to Object.prototype being restricted
|
|
4468
|
+
// via preventExtensions, seal or freeze
|
|
4469
|
+
return naiveFallback();
|
|
4470
|
+
}
|
|
4471
|
+
try {
|
|
4472
|
+
// Safari case (window.__global__ works, but __global__ does not)
|
|
4473
|
+
if (!__global__)
|
|
4474
|
+
return naiveFallback();
|
|
4475
|
+
return __global__;
|
|
4476
|
+
}
|
|
4477
|
+
finally {
|
|
4478
|
+
delete Object.prototype.__global__;
|
|
4479
|
+
}
|
|
4480
|
+
})();
|
|
4481
|
+
|
|
4482
|
+
var requestLogger = function (r) {
|
|
4483
|
+
// tslint:disable-next-line
|
|
4484
|
+
console.debug("[JS-SDK] ".concat(r.method.toUpperCase(), " ").concat(r.baseURL).concat(r.url), r.data ? JSON.stringify(r.data) : '');
|
|
4485
|
+
return r;
|
|
4486
|
+
};
|
|
4487
|
+
/**
|
|
4488
|
+
* VerdocsEndpoint is a class wrapper for a specific connection and authorization context for calling the Verdocs APIs.
|
|
4489
|
+
* Endpoints can be used for isolated session tasks.
|
|
4490
|
+
*
|
|
4491
|
+
* For instance, ephemeral signing sessions may be created independently of a caller's status as an authenticated user.
|
|
4492
|
+
* In that case, an Endpoint can be created and authenticated, used for calls related to signing operations, then
|
|
4493
|
+
* discarded once signing is complete.
|
|
4494
|
+
*
|
|
4495
|
+
* Note that endpoint configuration functions return the instance, so they can be chained, e.g.
|
|
4496
|
+
*
|
|
4497
|
+
* ```typescript
|
|
4498
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
4499
|
+
*
|
|
4500
|
+
* const endpoint = new VerdocsEndpoint();
|
|
4501
|
+
* endpoint
|
|
4502
|
+
* .setSessionType('signing')
|
|
4503
|
+
* .logRequests(true)
|
|
4504
|
+
* .setClientID('1234)
|
|
4505
|
+
* .setTimeout(5000);
|
|
4506
|
+
* ```
|
|
4507
|
+
*/
|
|
4508
|
+
var VerdocsEndpoint = /** @class */ (function () {
|
|
4509
|
+
/**
|
|
4510
|
+
* Create a new VerdocsEndpoint to call Verdocs platform services.
|
|
4511
|
+
*
|
|
4512
|
+
* ```typescript
|
|
4513
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
4514
|
+
* const endpoint = new VerdocsEndpoint();
|
|
4515
|
+
* ```
|
|
4516
|
+
*/
|
|
4517
|
+
function VerdocsEndpoint(options) {
|
|
4518
|
+
this.environment = 'verdocs';
|
|
4519
|
+
this.sessionType = 'user';
|
|
4520
|
+
this.baseURL = 'https://api.verdocs.com';
|
|
4521
|
+
this.clientID = 'not-set';
|
|
4522
|
+
this.timeout = 3000;
|
|
4523
|
+
this.token = null;
|
|
4524
|
+
this.nextListenerId = 0;
|
|
4525
|
+
this.sessionListeners = new Map();
|
|
4526
|
+
this.requestLoggerId = null;
|
|
4527
|
+
/**
|
|
4528
|
+
* The current user session, or null if not authenticated. May be either a User or Signing session. If set, the
|
|
4529
|
+
* presence of the `document_id` field can be used to differentiate the types. Only signing sessions are associated
|
|
4530
|
+
* with Documents.
|
|
4531
|
+
*/
|
|
4532
|
+
this.session = null;
|
|
4533
|
+
this.Documents = Documents;
|
|
4534
|
+
this.baseURL = (options === null || options === void 0 ? void 0 : options.baseURL) || 'https://api.verdocs.com';
|
|
4535
|
+
this.timeout = (options === null || options === void 0 ? void 0 : options.timeout) || 3000;
|
|
4536
|
+
this.environment = (options === null || options === void 0 ? void 0 : options.environment) || 'verdocs';
|
|
4537
|
+
this.sessionType = (options === null || options === void 0 ? void 0 : options.sessionType) || 'user';
|
|
4538
|
+
this.clientID = (options === null || options === void 0 ? void 0 : options.clientID) || 'not-set';
|
|
4539
|
+
this.api = axios.create({ baseURL: this.baseURL, timeout: this.timeout });
|
|
4540
|
+
}
|
|
4541
|
+
VerdocsEndpoint.prototype.setDefault = function () {
|
|
4542
|
+
globalThis_1[ENDPOINT_KEY] = this;
|
|
4543
|
+
};
|
|
4544
|
+
VerdocsEndpoint.getDefault = function () {
|
|
4545
|
+
return globalThis_1[ENDPOINT_KEY];
|
|
4546
|
+
};
|
|
4547
|
+
/**
|
|
4548
|
+
* Get the current environment.
|
|
4549
|
+
*/
|
|
4550
|
+
VerdocsEndpoint.prototype.getEnvironment = function () {
|
|
4551
|
+
return this.environment;
|
|
4552
|
+
};
|
|
4553
|
+
/**
|
|
4554
|
+
* Get the current session type.
|
|
4555
|
+
*/
|
|
4556
|
+
VerdocsEndpoint.prototype.getSessionType = function () {
|
|
4557
|
+
return this.sessionType;
|
|
4558
|
+
};
|
|
4559
|
+
/**
|
|
4560
|
+
* Get the current base URL. This should rarely be anything other than 'https://api.verdocs.com'.
|
|
4561
|
+
*/
|
|
4562
|
+
VerdocsEndpoint.prototype.getBaseURL = function () {
|
|
4563
|
+
return this.baseURL;
|
|
4564
|
+
};
|
|
4565
|
+
/**
|
|
4566
|
+
* Get the current client ID, if set.
|
|
4567
|
+
*/
|
|
4568
|
+
VerdocsEndpoint.prototype.getClientID = function () {
|
|
4569
|
+
return this.clientID;
|
|
4570
|
+
};
|
|
4571
|
+
/**
|
|
4572
|
+
* Get the current timeout.
|
|
4573
|
+
*/
|
|
4574
|
+
VerdocsEndpoint.prototype.getTimeout = function () {
|
|
4575
|
+
return this.timeout;
|
|
4576
|
+
};
|
|
4577
|
+
/**
|
|
4578
|
+
* Get the current session, if any.
|
|
4579
|
+
*/
|
|
4580
|
+
VerdocsEndpoint.prototype.getSession = function () {
|
|
4581
|
+
return this.session;
|
|
4582
|
+
};
|
|
4583
|
+
/**
|
|
4584
|
+
* Set the operating environment. This should rarely be anything other than 'verdocs'.
|
|
4585
|
+
*
|
|
4586
|
+
* ```typescript
|
|
4587
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
4588
|
+
*
|
|
4589
|
+
* const endpoint = new VerdocsEndpoint();
|
|
4590
|
+
* endpoint.setEnvironment('verdocs-stage');
|
|
4591
|
+
* ```
|
|
4592
|
+
*/
|
|
4593
|
+
VerdocsEndpoint.prototype.setEnvironment = function (environment) {
|
|
4594
|
+
this.environment = environment;
|
|
4595
|
+
return this;
|
|
4596
|
+
};
|
|
4597
|
+
/**
|
|
4598
|
+
* Set the session type. In general this should be done immediately when the endpoint is created. Changing the
|
|
4599
|
+
* session type may be done at any time, but may have unintended consequences if the endpoint is shared between
|
|
4600
|
+
* multiple widgets.
|
|
4601
|
+
*
|
|
4602
|
+
* Changing the session type will clear/reload the action session. This may trigger notifications to session state
|
|
4603
|
+
* observers. Apps that use observers to trigger UI updates such as logging the user out should be prepared to
|
|
4604
|
+
* handle this event.
|
|
4605
|
+
*
|
|
4606
|
+
* ```typescript
|
|
4607
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
4608
|
+
*
|
|
4609
|
+
* const endpoint = new VerdocsEndpoint();
|
|
4610
|
+
* endpoint.setEnvironment('verdocs-stage');
|
|
4611
|
+
* ```
|
|
4612
|
+
*/
|
|
4613
|
+
VerdocsEndpoint.prototype.setSessionType = function (sessionType) {
|
|
4614
|
+
this.sessionType = sessionType;
|
|
4615
|
+
return this;
|
|
4616
|
+
};
|
|
4617
|
+
/**
|
|
4618
|
+
* Set the base URL for API calls. Should be called only upon direction from Verdocs Customer Solutions Engineering.
|
|
4619
|
+
*
|
|
4620
|
+
* ```typescript
|
|
4621
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
4622
|
+
*
|
|
4623
|
+
* const endpoint = new VerdocsEndpoint();
|
|
4624
|
+
* endpoint.setBaseURL('https://api.verdocs.com');
|
|
4625
|
+
* ```
|
|
4626
|
+
*/
|
|
4627
|
+
VerdocsEndpoint.prototype.setBaseURL = function (url) {
|
|
4628
|
+
this.api.defaults.baseURL = url;
|
|
4629
|
+
return this;
|
|
4630
|
+
};
|
|
4631
|
+
/**
|
|
4632
|
+
* Set the Client ID for Verdocs API calls.
|
|
4633
|
+
*
|
|
4634
|
+
* ```typescript
|
|
4635
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
4636
|
+
*
|
|
4637
|
+
* const endpoint = new VerdocsEndpoint();
|
|
4638
|
+
* endpoint.setClientID('1234);
|
|
4639
|
+
* ```
|
|
4640
|
+
*/
|
|
4641
|
+
VerdocsEndpoint.prototype.setClientID = function (clientID) {
|
|
4642
|
+
this.clientID = clientID;
|
|
4643
|
+
this.api.defaults.headers.common['X-Client-ID'] = clientID;
|
|
4644
|
+
return this;
|
|
4645
|
+
};
|
|
4646
|
+
/**
|
|
4647
|
+
* Set the timeout for API calls in milliseconds. 2000-4000ms is recommended for most purposes. 3000ms is the default.
|
|
4648
|
+
*
|
|
4649
|
+
* ```typescript
|
|
4650
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
4651
|
+
*
|
|
4652
|
+
* const endpoint = new VerdocsEndpoint();
|
|
4653
|
+
* endpoint.setTimeout(3000);
|
|
4654
|
+
* ```
|
|
4655
|
+
*/
|
|
4656
|
+
VerdocsEndpoint.prototype.setTimeout = function (timeout) {
|
|
4657
|
+
this.timeout = timeout;
|
|
4658
|
+
this.api.defaults.timeout = timeout;
|
|
4659
|
+
return this;
|
|
4660
|
+
};
|
|
4661
|
+
/**
|
|
4662
|
+
* Enable or disable request logging. This may expose sensitive data in the console log, so it should only be used for debugging.
|
|
4663
|
+
*
|
|
4664
|
+
* ```typescript
|
|
4665
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
4666
|
+
*
|
|
4667
|
+
* const endpoint = new VerdocsEndpoint();
|
|
4668
|
+
* endpoint.logRequests(true);
|
|
4669
|
+
* ```
|
|
4670
|
+
*/
|
|
4671
|
+
VerdocsEndpoint.prototype.logRequests = function (enable) {
|
|
4672
|
+
if (enable && this.requestLoggerId === null) {
|
|
4673
|
+
this.requestLoggerId = this.api.interceptors.request.use(requestLogger);
|
|
4674
|
+
}
|
|
4675
|
+
else if (!enable && this.requestLoggerId !== null) {
|
|
4676
|
+
this.api.interceptors.request.eject(this.requestLoggerId);
|
|
4677
|
+
}
|
|
4678
|
+
return this;
|
|
4679
|
+
};
|
|
4680
|
+
/**
|
|
4681
|
+
* Set the authorization token that will be used for Verdocs API calls. This will also set the session metadata
|
|
4682
|
+
* and notify any listeners of the new data.
|
|
4683
|
+
*
|
|
4684
|
+
* If this Endpoint will be used for non-default purposes (e.g. signing, or in an alternate environment) those
|
|
4685
|
+
* settings should be made before calling this. Sessions are persisted to localStorage, and the environment and
|
|
4686
|
+
* type become part of the storage key.
|
|
4687
|
+
*
|
|
4688
|
+
* ```typescript
|
|
4689
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
4690
|
+
*
|
|
4691
|
+
* const endpoint = new VerdocsEndpoint();
|
|
4692
|
+
* endpoint.setToken(accessToken);
|
|
4693
|
+
* ```
|
|
4694
|
+
*/
|
|
4695
|
+
VerdocsEndpoint.prototype.setToken = function (token) {
|
|
4696
|
+
if (!token) {
|
|
4697
|
+
return this.clearSession();
|
|
4698
|
+
}
|
|
4699
|
+
var session = decodeAccessTokenBody(token);
|
|
4700
|
+
if (session === null || (session.exp && session.exp * 1000 < new Date().getTime())) {
|
|
4701
|
+
return this.clearSession();
|
|
4702
|
+
}
|
|
4703
|
+
this.token = token;
|
|
4704
|
+
this.session = session;
|
|
4705
|
+
this.api.defaults.headers.common.Authorization = "Bearer ".concat(token);
|
|
4706
|
+
localStorage.setItem(this.sessionStorageKey(), token);
|
|
4707
|
+
this.notifySessionListeners();
|
|
4708
|
+
return this;
|
|
4709
|
+
};
|
|
4710
|
+
VerdocsEndpoint.prototype.sessionStorageKey = function () {
|
|
4711
|
+
return "verdocs-session-".concat(this.getSessionType(), "-").concat(this.getEnvironment());
|
|
4712
|
+
};
|
|
4713
|
+
/**
|
|
4714
|
+
* Clear the active session.
|
|
4715
|
+
*/
|
|
4716
|
+
VerdocsEndpoint.prototype.clearSession = function () {
|
|
4717
|
+
localStorage.removeItem(this.sessionStorageKey());
|
|
4718
|
+
delete this.api.defaults.headers.common.Authorization;
|
|
4719
|
+
this.session = null;
|
|
4720
|
+
this.token = null;
|
|
4721
|
+
this.notifySessionListeners();
|
|
4722
|
+
return this;
|
|
4723
|
+
};
|
|
4724
|
+
VerdocsEndpoint.prototype.notifySessionListeners = function () {
|
|
4725
|
+
var _this = this;
|
|
4726
|
+
this.sessionListeners.forEach(function (listener) {
|
|
4727
|
+
try {
|
|
4728
|
+
listener(_this, _this.session);
|
|
4729
|
+
}
|
|
4730
|
+
catch (e) {
|
|
4731
|
+
// NOOP
|
|
4732
|
+
}
|
|
4733
|
+
});
|
|
4734
|
+
};
|
|
4735
|
+
/**
|
|
4736
|
+
* Subscribe to session state change events.
|
|
4737
|
+
*/
|
|
4738
|
+
VerdocsEndpoint.prototype.onSessionChanged = function (listener) {
|
|
4739
|
+
var _this = this;
|
|
4740
|
+
// There's no value in randomizing this, a simple counter is fine
|
|
4741
|
+
this.nextListenerId++;
|
|
4742
|
+
var listenerSymbol = Symbol.for('' + this.nextListenerId);
|
|
4743
|
+
this.sessionListeners.set(listenerSymbol, listener);
|
|
4744
|
+
return function () {
|
|
4745
|
+
_this.sessionListeners.delete(listenerSymbol);
|
|
4746
|
+
};
|
|
4747
|
+
};
|
|
4748
|
+
/**
|
|
4749
|
+
* Load a persisted session from localStorage. Typically called once after the endpoint is configured when the app
|
|
4750
|
+
* or component starts.
|
|
4751
|
+
*/
|
|
4752
|
+
VerdocsEndpoint.prototype.loadSession = function () {
|
|
4753
|
+
var token = localStorage.getItem(this.sessionStorageKey());
|
|
4754
|
+
if (!token) {
|
|
4755
|
+
return this.clearSession();
|
|
4756
|
+
}
|
|
4757
|
+
return this.setToken(token);
|
|
4758
|
+
};
|
|
4759
|
+
return VerdocsEndpoint;
|
|
4760
|
+
}());
|
|
4761
|
+
// @credit https://derickbailey.com/2016/03/09/creating-a-true-singleton-in-node-js-with-es6-symbols/
|
|
4762
|
+
// Also see globalThis for comments about why we're doing this in the first place.
|
|
4763
|
+
var ENDPOINT_KEY = Symbol.for('verdocs-default-endpoint');
|
|
4764
|
+
if (!globalThis_1[ENDPOINT_KEY]) {
|
|
4765
|
+
globalThis_1[ENDPOINT_KEY] = new VerdocsEndpoint();
|
|
4766
|
+
}
|
|
4767
|
+
|
|
4768
|
+
exports.Buffer = Buffer;
|
|
4769
|
+
exports.VerdocsEndpoint = VerdocsEndpoint;
|
|
4770
|
+
exports.commonjsGlobal = commonjsGlobal;
|
|
4771
|
+
exports.commonjsRequire = commonjsRequire;
|
|
4772
|
+
exports.createCommonjsModule = createCommonjsModule;
|
|
4773
|
+
exports.getAugmentedNamespace = getAugmentedNamespace;
|
|
4774
|
+
exports.getDefaultExportFromCjs = getDefaultExportFromCjs;
|
|
4775
|
+
exports.getDocument = getDocument;
|
|
4776
|
+
exports.getDocumentFile = getDocumentFile;
|
|
4777
|
+
exports.getSigningSession = getSigningSession;
|
|
4778
|
+
exports.process_1 = process_1;
|
|
4779
|
+
exports.updateDocumentField = updateDocumentField;
|
|
4780
|
+
exports.updateRecipientStatus = updateRecipientStatus;
|