@verdocs/web-sdk 1.4.7 → 1.5.2

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