@nhost/nhost-js 0.3.4 → 0.3.8

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 (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -4
  3. package/dist/{cjs/clients → clients}/functions.d.ts +2 -2
  4. package/dist/{esm/clients → clients}/graphql.d.ts +2 -2
  5. package/dist/{cjs/core → core}/index.d.ts +0 -0
  6. package/dist/{esm/core → core}/nhost-client.d.ts +3 -12
  7. package/dist/index.cjs.js +4 -0
  8. package/dist/index.d.ts +4 -0
  9. package/dist/index.es.js +4471 -0
  10. package/dist/{cjs/types.d.ts → types.d.ts} +5 -5
  11. package/package.json +39 -33
  12. package/src/index.ts +6 -0
  13. package/dist/cjs/clients/functions.js +0 -113
  14. package/dist/cjs/clients/functions.js.map +0 -1
  15. package/dist/cjs/clients/graphql.d.ts +0 -15
  16. package/dist/cjs/clients/graphql.js +0 -133
  17. package/dist/cjs/clients/graphql.js.map +0 -1
  18. package/dist/cjs/core/index.js +0 -14
  19. package/dist/cjs/core/index.js.map +0 -1
  20. package/dist/cjs/core/nhost-client.d.ts +0 -28
  21. package/dist/cjs/core/nhost-client.js +0 -59
  22. package/dist/cjs/core/nhost-client.js.map +0 -1
  23. package/dist/cjs/index.d.ts +0 -1
  24. package/dist/cjs/index.js +0 -14
  25. package/dist/cjs/index.js.map +0 -1
  26. package/dist/cjs/types.js +0 -3
  27. package/dist/cjs/types.js.map +0 -1
  28. package/dist/esm/clients/functions.d.ts +0 -13
  29. package/dist/esm/clients/functions.js +0 -107
  30. package/dist/esm/clients/functions.js.map +0 -1
  31. package/dist/esm/clients/graphql.js +0 -127
  32. package/dist/esm/clients/graphql.js.map +0 -1
  33. package/dist/esm/core/index.d.ts +0 -1
  34. package/dist/esm/core/index.js +0 -2
  35. package/dist/esm/core/index.js.map +0 -1
  36. package/dist/esm/core/nhost-client.js +0 -56
  37. package/dist/esm/core/nhost-client.js.map +0 -1
  38. package/dist/esm/index.d.ts +0 -1
  39. package/dist/esm/index.js +0 -2
  40. package/dist/esm/index.js.map +0 -1
  41. package/dist/esm/types.d.ts +0 -19
  42. package/dist/esm/types.js +0 -2
  43. package/dist/esm/types.js.map +0 -1
@@ -0,0 +1,4471 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var axios$8 = { exports: {} };
21
+ var bind$8 = function bind(fn, thisArg) {
22
+ return function wrap() {
23
+ var args = new Array(arguments.length);
24
+ for (var i = 0; i < args.length; i++) {
25
+ args[i] = arguments[i];
26
+ }
27
+ return fn.apply(thisArg, args);
28
+ };
29
+ };
30
+ var bind$7 = bind$8;
31
+ var toString$2 = Object.prototype.toString;
32
+ function isArray$2(val) {
33
+ return Array.isArray(val);
34
+ }
35
+ function isUndefined$2(val) {
36
+ return typeof val === "undefined";
37
+ }
38
+ function isBuffer$2(val) {
39
+ return val !== null && !isUndefined$2(val) && val.constructor !== null && !isUndefined$2(val.constructor) && typeof val.constructor.isBuffer === "function" && val.constructor.isBuffer(val);
40
+ }
41
+ function isArrayBuffer$2(val) {
42
+ return toString$2.call(val) === "[object ArrayBuffer]";
43
+ }
44
+ function isFormData$2(val) {
45
+ return toString$2.call(val) === "[object FormData]";
46
+ }
47
+ function isArrayBufferView$2(val) {
48
+ var result;
49
+ if (typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView) {
50
+ result = ArrayBuffer.isView(val);
51
+ } else {
52
+ result = val && val.buffer && isArrayBuffer$2(val.buffer);
53
+ }
54
+ return result;
55
+ }
56
+ function isString$2(val) {
57
+ return typeof val === "string";
58
+ }
59
+ function isNumber$2(val) {
60
+ return typeof val === "number";
61
+ }
62
+ function isObject$2(val) {
63
+ return val !== null && typeof val === "object";
64
+ }
65
+ function isPlainObject$2(val) {
66
+ if (toString$2.call(val) !== "[object Object]") {
67
+ return false;
68
+ }
69
+ var prototype = Object.getPrototypeOf(val);
70
+ return prototype === null || prototype === Object.prototype;
71
+ }
72
+ function isDate$2(val) {
73
+ return toString$2.call(val) === "[object Date]";
74
+ }
75
+ function isFile$2(val) {
76
+ return toString$2.call(val) === "[object File]";
77
+ }
78
+ function isBlob$2(val) {
79
+ return toString$2.call(val) === "[object Blob]";
80
+ }
81
+ function isFunction$2(val) {
82
+ return toString$2.call(val) === "[object Function]";
83
+ }
84
+ function isStream$2(val) {
85
+ return isObject$2(val) && isFunction$2(val.pipe);
86
+ }
87
+ function isURLSearchParams$2(val) {
88
+ return toString$2.call(val) === "[object URLSearchParams]";
89
+ }
90
+ function trim$2(str) {
91
+ return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, "");
92
+ }
93
+ function isStandardBrowserEnv$2() {
94
+ if (typeof navigator !== "undefined" && (navigator.product === "ReactNative" || navigator.product === "NativeScript" || navigator.product === "NS")) {
95
+ return false;
96
+ }
97
+ return typeof window !== "undefined" && typeof document !== "undefined";
98
+ }
99
+ function forEach$2(obj, fn) {
100
+ if (obj === null || typeof obj === "undefined") {
101
+ return;
102
+ }
103
+ if (typeof obj !== "object") {
104
+ obj = [obj];
105
+ }
106
+ if (isArray$2(obj)) {
107
+ for (var i = 0, l = obj.length; i < l; i++) {
108
+ fn.call(null, obj[i], i, obj);
109
+ }
110
+ } else {
111
+ for (var key in obj) {
112
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
113
+ fn.call(null, obj[key], key, obj);
114
+ }
115
+ }
116
+ }
117
+ }
118
+ function merge$2() {
119
+ var result = {};
120
+ function assignValue(val, key) {
121
+ if (isPlainObject$2(result[key]) && isPlainObject$2(val)) {
122
+ result[key] = merge$2(result[key], val);
123
+ } else if (isPlainObject$2(val)) {
124
+ result[key] = merge$2({}, val);
125
+ } else if (isArray$2(val)) {
126
+ result[key] = val.slice();
127
+ } else {
128
+ result[key] = val;
129
+ }
130
+ }
131
+ for (var i = 0, l = arguments.length; i < l; i++) {
132
+ forEach$2(arguments[i], assignValue);
133
+ }
134
+ return result;
135
+ }
136
+ function extend$2(a, b, thisArg) {
137
+ forEach$2(b, function assignValue(val, key) {
138
+ if (thisArg && typeof val === "function") {
139
+ a[key] = bind$7(val, thisArg);
140
+ } else {
141
+ a[key] = val;
142
+ }
143
+ });
144
+ return a;
145
+ }
146
+ function stripBOM$2(content) {
147
+ if (content.charCodeAt(0) === 65279) {
148
+ content = content.slice(1);
149
+ }
150
+ return content;
151
+ }
152
+ var utils$G = {
153
+ isArray: isArray$2,
154
+ isArrayBuffer: isArrayBuffer$2,
155
+ isBuffer: isBuffer$2,
156
+ isFormData: isFormData$2,
157
+ isArrayBufferView: isArrayBufferView$2,
158
+ isString: isString$2,
159
+ isNumber: isNumber$2,
160
+ isObject: isObject$2,
161
+ isPlainObject: isPlainObject$2,
162
+ isUndefined: isUndefined$2,
163
+ isDate: isDate$2,
164
+ isFile: isFile$2,
165
+ isBlob: isBlob$2,
166
+ isFunction: isFunction$2,
167
+ isStream: isStream$2,
168
+ isURLSearchParams: isURLSearchParams$2,
169
+ isStandardBrowserEnv: isStandardBrowserEnv$2,
170
+ forEach: forEach$2,
171
+ merge: merge$2,
172
+ extend: extend$2,
173
+ trim: trim$2,
174
+ stripBOM: stripBOM$2
175
+ };
176
+ var utils$F = utils$G;
177
+ function encode$2(val) {
178
+ return encodeURIComponent(val).replace(/%3A/gi, ":").replace(/%24/g, "$").replace(/%2C/gi, ",").replace(/%20/g, "+").replace(/%5B/gi, "[").replace(/%5D/gi, "]");
179
+ }
180
+ var buildURL$8 = function buildURL(url, params, paramsSerializer) {
181
+ if (!params) {
182
+ return url;
183
+ }
184
+ var serializedParams;
185
+ if (paramsSerializer) {
186
+ serializedParams = paramsSerializer(params);
187
+ } else if (utils$F.isURLSearchParams(params)) {
188
+ serializedParams = params.toString();
189
+ } else {
190
+ var parts = [];
191
+ utils$F.forEach(params, function serialize(val, key) {
192
+ if (val === null || typeof val === "undefined") {
193
+ return;
194
+ }
195
+ if (utils$F.isArray(val)) {
196
+ key = key + "[]";
197
+ } else {
198
+ val = [val];
199
+ }
200
+ utils$F.forEach(val, function parseValue(v) {
201
+ if (utils$F.isDate(v)) {
202
+ v = v.toISOString();
203
+ } else if (utils$F.isObject(v)) {
204
+ v = JSON.stringify(v);
205
+ }
206
+ parts.push(encode$2(key) + "=" + encode$2(v));
207
+ });
208
+ });
209
+ serializedParams = parts.join("&");
210
+ }
211
+ if (serializedParams) {
212
+ var hashmarkIndex = url.indexOf("#");
213
+ if (hashmarkIndex !== -1) {
214
+ url = url.slice(0, hashmarkIndex);
215
+ }
216
+ url += (url.indexOf("?") === -1 ? "?" : "&") + serializedParams;
217
+ }
218
+ return url;
219
+ };
220
+ var utils$E = utils$G;
221
+ function InterceptorManager$5() {
222
+ this.handlers = [];
223
+ }
224
+ InterceptorManager$5.prototype.use = function use(fulfilled, rejected, options) {
225
+ this.handlers.push({
226
+ fulfilled,
227
+ rejected,
228
+ synchronous: options ? options.synchronous : false,
229
+ runWhen: options ? options.runWhen : null
230
+ });
231
+ return this.handlers.length - 1;
232
+ };
233
+ InterceptorManager$5.prototype.eject = function eject(id) {
234
+ if (this.handlers[id]) {
235
+ this.handlers[id] = null;
236
+ }
237
+ };
238
+ InterceptorManager$5.prototype.forEach = function forEach(fn) {
239
+ utils$E.forEach(this.handlers, function forEachHandler(h) {
240
+ if (h !== null) {
241
+ fn(h);
242
+ }
243
+ });
244
+ };
245
+ var InterceptorManager_1$2 = InterceptorManager$5;
246
+ var utils$D = utils$G;
247
+ var normalizeHeaderName$5 = function normalizeHeaderName(headers, normalizedName) {
248
+ utils$D.forEach(headers, function processHeader(value, name2) {
249
+ if (name2 !== normalizedName && name2.toUpperCase() === normalizedName.toUpperCase()) {
250
+ headers[normalizedName] = value;
251
+ delete headers[name2];
252
+ }
253
+ });
254
+ };
255
+ var enhanceError$8 = function enhanceError(error, config, code, request4, response) {
256
+ error.config = config;
257
+ if (code) {
258
+ error.code = code;
259
+ }
260
+ error.request = request4;
261
+ error.response = response;
262
+ error.isAxiosError = true;
263
+ error.toJSON = function toJSON() {
264
+ return {
265
+ message: this.message,
266
+ name: this.name,
267
+ description: this.description,
268
+ number: this.number,
269
+ fileName: this.fileName,
270
+ lineNumber: this.lineNumber,
271
+ columnNumber: this.columnNumber,
272
+ stack: this.stack,
273
+ config: this.config,
274
+ code: this.code,
275
+ status: this.response && this.response.status ? this.response.status : null
276
+ };
277
+ };
278
+ return error;
279
+ };
280
+ var enhanceError$7 = enhanceError$8;
281
+ var createError$8 = function createError(message, config, code, request4, response) {
282
+ var error = new Error(message);
283
+ return enhanceError$7(error, config, code, request4, response);
284
+ };
285
+ var createError$7 = createError$8;
286
+ var settle$5 = function settle(resolve, reject, response) {
287
+ var validateStatus4 = response.config.validateStatus;
288
+ if (!response.status || !validateStatus4 || validateStatus4(response.status)) {
289
+ resolve(response);
290
+ } else {
291
+ reject(createError$7("Request failed with status code " + response.status, response.config, null, response.request, response));
292
+ }
293
+ };
294
+ var utils$C = utils$G;
295
+ var cookies$5 = utils$C.isStandardBrowserEnv() ? function standardBrowserEnv() {
296
+ return {
297
+ write: function write(name2, value, expires, path, domain, secure) {
298
+ var cookie = [];
299
+ cookie.push(name2 + "=" + encodeURIComponent(value));
300
+ if (utils$C.isNumber(expires)) {
301
+ cookie.push("expires=" + new Date(expires).toGMTString());
302
+ }
303
+ if (utils$C.isString(path)) {
304
+ cookie.push("path=" + path);
305
+ }
306
+ if (utils$C.isString(domain)) {
307
+ cookie.push("domain=" + domain);
308
+ }
309
+ if (secure === true) {
310
+ cookie.push("secure");
311
+ }
312
+ document.cookie = cookie.join("; ");
313
+ },
314
+ read: function read(name2) {
315
+ var match = document.cookie.match(new RegExp("(^|;\\s*)(" + name2 + ")=([^;]*)"));
316
+ return match ? decodeURIComponent(match[3]) : null;
317
+ },
318
+ remove: function remove(name2) {
319
+ this.write(name2, "", Date.now() - 864e5);
320
+ }
321
+ };
322
+ }() : function nonStandardBrowserEnv() {
323
+ return {
324
+ write: function write() {
325
+ },
326
+ read: function read() {
327
+ return null;
328
+ },
329
+ remove: function remove() {
330
+ }
331
+ };
332
+ }();
333
+ var isAbsoluteURL$5 = function isAbsoluteURL(url) {
334
+ return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
335
+ };
336
+ var combineURLs$5 = function combineURLs(baseURL, relativeURL) {
337
+ return relativeURL ? baseURL.replace(/\/+$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
338
+ };
339
+ var isAbsoluteURL$4 = isAbsoluteURL$5;
340
+ var combineURLs$4 = combineURLs$5;
341
+ var buildFullPath$5 = function buildFullPath(baseURL, requestedURL) {
342
+ if (baseURL && !isAbsoluteURL$4(requestedURL)) {
343
+ return combineURLs$4(baseURL, requestedURL);
344
+ }
345
+ return requestedURL;
346
+ };
347
+ var utils$B = utils$G;
348
+ var ignoreDuplicateOf$2 = [
349
+ "age",
350
+ "authorization",
351
+ "content-length",
352
+ "content-type",
353
+ "etag",
354
+ "expires",
355
+ "from",
356
+ "host",
357
+ "if-modified-since",
358
+ "if-unmodified-since",
359
+ "last-modified",
360
+ "location",
361
+ "max-forwards",
362
+ "proxy-authorization",
363
+ "referer",
364
+ "retry-after",
365
+ "user-agent"
366
+ ];
367
+ var parseHeaders$5 = function parseHeaders(headers) {
368
+ var parsed = {};
369
+ var key;
370
+ var val;
371
+ var i;
372
+ if (!headers) {
373
+ return parsed;
374
+ }
375
+ utils$B.forEach(headers.split("\n"), function parser(line) {
376
+ i = line.indexOf(":");
377
+ key = utils$B.trim(line.substr(0, i)).toLowerCase();
378
+ val = utils$B.trim(line.substr(i + 1));
379
+ if (key) {
380
+ if (parsed[key] && ignoreDuplicateOf$2.indexOf(key) >= 0) {
381
+ return;
382
+ }
383
+ if (key === "set-cookie") {
384
+ parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
385
+ } else {
386
+ parsed[key] = parsed[key] ? parsed[key] + ", " + val : val;
387
+ }
388
+ }
389
+ });
390
+ return parsed;
391
+ };
392
+ var utils$A = utils$G;
393
+ var isURLSameOrigin$5 = utils$A.isStandardBrowserEnv() ? function standardBrowserEnv2() {
394
+ var msie = /(msie|trident)/i.test(navigator.userAgent);
395
+ var urlParsingNode = document.createElement("a");
396
+ var originURL;
397
+ function resolveURL(url) {
398
+ var href = url;
399
+ if (msie) {
400
+ urlParsingNode.setAttribute("href", href);
401
+ href = urlParsingNode.href;
402
+ }
403
+ urlParsingNode.setAttribute("href", href);
404
+ return {
405
+ href: urlParsingNode.href,
406
+ protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, "") : "",
407
+ host: urlParsingNode.host,
408
+ search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, "") : "",
409
+ hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, "") : "",
410
+ hostname: urlParsingNode.hostname,
411
+ port: urlParsingNode.port,
412
+ pathname: urlParsingNode.pathname.charAt(0) === "/" ? urlParsingNode.pathname : "/" + urlParsingNode.pathname
413
+ };
414
+ }
415
+ originURL = resolveURL(window.location.href);
416
+ return function isURLSameOrigin2(requestURL) {
417
+ var parsed = utils$A.isString(requestURL) ? resolveURL(requestURL) : requestURL;
418
+ return parsed.protocol === originURL.protocol && parsed.host === originURL.host;
419
+ };
420
+ }() : function nonStandardBrowserEnv2() {
421
+ return function isURLSameOrigin2() {
422
+ return true;
423
+ };
424
+ }();
425
+ function Cancel$9(message) {
426
+ this.message = message;
427
+ }
428
+ Cancel$9.prototype.toString = function toString() {
429
+ return "Cancel" + (this.message ? ": " + this.message : "");
430
+ };
431
+ Cancel$9.prototype.__CANCEL__ = true;
432
+ var Cancel_1$2 = Cancel$9;
433
+ var utils$z = utils$G;
434
+ var settle$4 = settle$5;
435
+ var cookies$4 = cookies$5;
436
+ var buildURL$7 = buildURL$8;
437
+ var buildFullPath$4 = buildFullPath$5;
438
+ var parseHeaders$4 = parseHeaders$5;
439
+ var isURLSameOrigin$4 = isURLSameOrigin$5;
440
+ var createError$6 = createError$8;
441
+ var defaults$d = defaults_1$2;
442
+ var Cancel$8 = Cancel_1$2;
443
+ var xhr$2 = function xhrAdapter(config) {
444
+ return new Promise(function dispatchXhrRequest(resolve, reject) {
445
+ var requestData = config.data;
446
+ var requestHeaders = config.headers;
447
+ var responseType = config.responseType;
448
+ var onCanceled;
449
+ function done() {
450
+ if (config.cancelToken) {
451
+ config.cancelToken.unsubscribe(onCanceled);
452
+ }
453
+ if (config.signal) {
454
+ config.signal.removeEventListener("abort", onCanceled);
455
+ }
456
+ }
457
+ if (utils$z.isFormData(requestData)) {
458
+ delete requestHeaders["Content-Type"];
459
+ }
460
+ var request4 = new XMLHttpRequest();
461
+ if (config.auth) {
462
+ var username = config.auth.username || "";
463
+ var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : "";
464
+ requestHeaders.Authorization = "Basic " + btoa(username + ":" + password);
465
+ }
466
+ var fullPath = buildFullPath$4(config.baseURL, config.url);
467
+ request4.open(config.method.toUpperCase(), buildURL$7(fullPath, config.params, config.paramsSerializer), true);
468
+ request4.timeout = config.timeout;
469
+ function onloadend() {
470
+ if (!request4) {
471
+ return;
472
+ }
473
+ var responseHeaders = "getAllResponseHeaders" in request4 ? parseHeaders$4(request4.getAllResponseHeaders()) : null;
474
+ var responseData = !responseType || responseType === "text" || responseType === "json" ? request4.responseText : request4.response;
475
+ var response = {
476
+ data: responseData,
477
+ status: request4.status,
478
+ statusText: request4.statusText,
479
+ headers: responseHeaders,
480
+ config,
481
+ request: request4
482
+ };
483
+ settle$4(function _resolve(value) {
484
+ resolve(value);
485
+ done();
486
+ }, function _reject(err) {
487
+ reject(err);
488
+ done();
489
+ }, response);
490
+ request4 = null;
491
+ }
492
+ if ("onloadend" in request4) {
493
+ request4.onloadend = onloadend;
494
+ } else {
495
+ request4.onreadystatechange = function handleLoad() {
496
+ if (!request4 || request4.readyState !== 4) {
497
+ return;
498
+ }
499
+ if (request4.status === 0 && !(request4.responseURL && request4.responseURL.indexOf("file:") === 0)) {
500
+ return;
501
+ }
502
+ setTimeout(onloadend);
503
+ };
504
+ }
505
+ request4.onabort = function handleAbort() {
506
+ if (!request4) {
507
+ return;
508
+ }
509
+ reject(createError$6("Request aborted", config, "ECONNABORTED", request4));
510
+ request4 = null;
511
+ };
512
+ request4.onerror = function handleError() {
513
+ reject(createError$6("Network Error", config, null, request4));
514
+ request4 = null;
515
+ };
516
+ request4.ontimeout = function handleTimeout() {
517
+ var timeoutErrorMessage = config.timeout ? "timeout of " + config.timeout + "ms exceeded" : "timeout exceeded";
518
+ var transitional4 = config.transitional || defaults$d.transitional;
519
+ if (config.timeoutErrorMessage) {
520
+ timeoutErrorMessage = config.timeoutErrorMessage;
521
+ }
522
+ reject(createError$6(timeoutErrorMessage, config, transitional4.clarifyTimeoutError ? "ETIMEDOUT" : "ECONNABORTED", request4));
523
+ request4 = null;
524
+ };
525
+ if (utils$z.isStandardBrowserEnv()) {
526
+ var xsrfValue = (config.withCredentials || isURLSameOrigin$4(fullPath)) && config.xsrfCookieName ? cookies$4.read(config.xsrfCookieName) : void 0;
527
+ if (xsrfValue) {
528
+ requestHeaders[config.xsrfHeaderName] = xsrfValue;
529
+ }
530
+ }
531
+ if ("setRequestHeader" in request4) {
532
+ utils$z.forEach(requestHeaders, function setRequestHeader(val, key) {
533
+ if (typeof requestData === "undefined" && key.toLowerCase() === "content-type") {
534
+ delete requestHeaders[key];
535
+ } else {
536
+ request4.setRequestHeader(key, val);
537
+ }
538
+ });
539
+ }
540
+ if (!utils$z.isUndefined(config.withCredentials)) {
541
+ request4.withCredentials = !!config.withCredentials;
542
+ }
543
+ if (responseType && responseType !== "json") {
544
+ request4.responseType = config.responseType;
545
+ }
546
+ if (typeof config.onDownloadProgress === "function") {
547
+ request4.addEventListener("progress", config.onDownloadProgress);
548
+ }
549
+ if (typeof config.onUploadProgress === "function" && request4.upload) {
550
+ request4.upload.addEventListener("progress", config.onUploadProgress);
551
+ }
552
+ if (config.cancelToken || config.signal) {
553
+ onCanceled = function(cancel) {
554
+ if (!request4) {
555
+ return;
556
+ }
557
+ reject(!cancel || cancel && cancel.type ? new Cancel$8("canceled") : cancel);
558
+ request4.abort();
559
+ request4 = null;
560
+ };
561
+ config.cancelToken && config.cancelToken.subscribe(onCanceled);
562
+ if (config.signal) {
563
+ config.signal.aborted ? onCanceled() : config.signal.addEventListener("abort", onCanceled);
564
+ }
565
+ }
566
+ if (!requestData) {
567
+ requestData = null;
568
+ }
569
+ request4.send(requestData);
570
+ });
571
+ };
572
+ var utils$y = utils$G;
573
+ var normalizeHeaderName$4 = normalizeHeaderName$5;
574
+ var enhanceError$6 = enhanceError$8;
575
+ var DEFAULT_CONTENT_TYPE$2 = {
576
+ "Content-Type": "application/x-www-form-urlencoded"
577
+ };
578
+ function setContentTypeIfUnset$2(headers, value) {
579
+ if (!utils$y.isUndefined(headers) && utils$y.isUndefined(headers["Content-Type"])) {
580
+ headers["Content-Type"] = value;
581
+ }
582
+ }
583
+ function getDefaultAdapter$2() {
584
+ var adapter;
585
+ if (typeof XMLHttpRequest !== "undefined") {
586
+ adapter = xhr$2;
587
+ } else if (typeof process !== "undefined" && Object.prototype.toString.call(process) === "[object process]") {
588
+ adapter = xhr$2;
589
+ }
590
+ return adapter;
591
+ }
592
+ function stringifySafely$2(rawValue, parser, encoder) {
593
+ if (utils$y.isString(rawValue)) {
594
+ try {
595
+ (parser || JSON.parse)(rawValue);
596
+ return utils$y.trim(rawValue);
597
+ } catch (e) {
598
+ if (e.name !== "SyntaxError") {
599
+ throw e;
600
+ }
601
+ }
602
+ }
603
+ return (encoder || JSON.stringify)(rawValue);
604
+ }
605
+ var defaults$c = {
606
+ transitional: {
607
+ silentJSONParsing: true,
608
+ forcedJSONParsing: true,
609
+ clarifyTimeoutError: false
610
+ },
611
+ adapter: getDefaultAdapter$2(),
612
+ transformRequest: [function transformRequest(data2, headers) {
613
+ normalizeHeaderName$4(headers, "Accept");
614
+ normalizeHeaderName$4(headers, "Content-Type");
615
+ if (utils$y.isFormData(data2) || utils$y.isArrayBuffer(data2) || utils$y.isBuffer(data2) || utils$y.isStream(data2) || utils$y.isFile(data2) || utils$y.isBlob(data2)) {
616
+ return data2;
617
+ }
618
+ if (utils$y.isArrayBufferView(data2)) {
619
+ return data2.buffer;
620
+ }
621
+ if (utils$y.isURLSearchParams(data2)) {
622
+ setContentTypeIfUnset$2(headers, "application/x-www-form-urlencoded;charset=utf-8");
623
+ return data2.toString();
624
+ }
625
+ if (utils$y.isObject(data2) || headers && headers["Content-Type"] === "application/json") {
626
+ setContentTypeIfUnset$2(headers, "application/json");
627
+ return stringifySafely$2(data2);
628
+ }
629
+ return data2;
630
+ }],
631
+ transformResponse: [function transformResponse(data2) {
632
+ var transitional4 = this.transitional || defaults$c.transitional;
633
+ var silentJSONParsing = transitional4 && transitional4.silentJSONParsing;
634
+ var forcedJSONParsing = transitional4 && transitional4.forcedJSONParsing;
635
+ var strictJSONParsing = !silentJSONParsing && this.responseType === "json";
636
+ if (strictJSONParsing || forcedJSONParsing && utils$y.isString(data2) && data2.length) {
637
+ try {
638
+ return JSON.parse(data2);
639
+ } catch (e) {
640
+ if (strictJSONParsing) {
641
+ if (e.name === "SyntaxError") {
642
+ throw enhanceError$6(e, this, "E_JSON_PARSE");
643
+ }
644
+ throw e;
645
+ }
646
+ }
647
+ }
648
+ return data2;
649
+ }],
650
+ timeout: 0,
651
+ xsrfCookieName: "XSRF-TOKEN",
652
+ xsrfHeaderName: "X-XSRF-TOKEN",
653
+ maxContentLength: -1,
654
+ maxBodyLength: -1,
655
+ validateStatus: function validateStatus(status) {
656
+ return status >= 200 && status < 300;
657
+ },
658
+ headers: {
659
+ common: {
660
+ "Accept": "application/json, text/plain, */*"
661
+ }
662
+ }
663
+ };
664
+ utils$y.forEach(["delete", "get", "head"], function forEachMethodNoData(method) {
665
+ defaults$c.headers[method] = {};
666
+ });
667
+ utils$y.forEach(["post", "put", "patch"], function forEachMethodWithData(method) {
668
+ defaults$c.headers[method] = utils$y.merge(DEFAULT_CONTENT_TYPE$2);
669
+ });
670
+ var defaults_1$2 = defaults$c;
671
+ var utils$x = utils$G;
672
+ var defaults$b = defaults_1$2;
673
+ var transformData$5 = function transformData(data2, headers, fns) {
674
+ var context = this || defaults$b;
675
+ utils$x.forEach(fns, function transform(fn) {
676
+ data2 = fn.call(context, data2, headers);
677
+ });
678
+ return data2;
679
+ };
680
+ var isCancel$5 = function isCancel(value) {
681
+ return !!(value && value.__CANCEL__);
682
+ };
683
+ var utils$w = utils$G;
684
+ var transformData$4 = transformData$5;
685
+ var isCancel$4 = isCancel$5;
686
+ var defaults$a = defaults_1$2;
687
+ var Cancel$7 = Cancel_1$2;
688
+ function throwIfCancellationRequested$2(config) {
689
+ if (config.cancelToken) {
690
+ config.cancelToken.throwIfRequested();
691
+ }
692
+ if (config.signal && config.signal.aborted) {
693
+ throw new Cancel$7("canceled");
694
+ }
695
+ }
696
+ var dispatchRequest$5 = function dispatchRequest(config) {
697
+ throwIfCancellationRequested$2(config);
698
+ config.headers = config.headers || {};
699
+ config.data = transformData$4.call(config, config.data, config.headers, config.transformRequest);
700
+ config.headers = utils$w.merge(config.headers.common || {}, config.headers[config.method] || {}, config.headers);
701
+ utils$w.forEach(["delete", "get", "head", "post", "put", "patch", "common"], function cleanHeaderConfig(method) {
702
+ delete config.headers[method];
703
+ });
704
+ var adapter = config.adapter || defaults$a.adapter;
705
+ return adapter(config).then(function onAdapterResolution(response) {
706
+ throwIfCancellationRequested$2(config);
707
+ response.data = transformData$4.call(config, response.data, response.headers, config.transformResponse);
708
+ return response;
709
+ }, function onAdapterRejection(reason) {
710
+ if (!isCancel$4(reason)) {
711
+ throwIfCancellationRequested$2(config);
712
+ if (reason && reason.response) {
713
+ reason.response.data = transformData$4.call(config, reason.response.data, reason.response.headers, config.transformResponse);
714
+ }
715
+ }
716
+ return Promise.reject(reason);
717
+ });
718
+ };
719
+ var utils$v = utils$G;
720
+ var mergeConfig$8 = function mergeConfig(config1, config2) {
721
+ config2 = config2 || {};
722
+ var config = {};
723
+ function getMergedValue(target, source4) {
724
+ if (utils$v.isPlainObject(target) && utils$v.isPlainObject(source4)) {
725
+ return utils$v.merge(target, source4);
726
+ } else if (utils$v.isPlainObject(source4)) {
727
+ return utils$v.merge({}, source4);
728
+ } else if (utils$v.isArray(source4)) {
729
+ return source4.slice();
730
+ }
731
+ return source4;
732
+ }
733
+ function mergeDeepProperties(prop) {
734
+ if (!utils$v.isUndefined(config2[prop])) {
735
+ return getMergedValue(config1[prop], config2[prop]);
736
+ } else if (!utils$v.isUndefined(config1[prop])) {
737
+ return getMergedValue(void 0, config1[prop]);
738
+ }
739
+ }
740
+ function valueFromConfig2(prop) {
741
+ if (!utils$v.isUndefined(config2[prop])) {
742
+ return getMergedValue(void 0, config2[prop]);
743
+ }
744
+ }
745
+ function defaultToConfig2(prop) {
746
+ if (!utils$v.isUndefined(config2[prop])) {
747
+ return getMergedValue(void 0, config2[prop]);
748
+ } else if (!utils$v.isUndefined(config1[prop])) {
749
+ return getMergedValue(void 0, config1[prop]);
750
+ }
751
+ }
752
+ function mergeDirectKeys(prop) {
753
+ if (prop in config2) {
754
+ return getMergedValue(config1[prop], config2[prop]);
755
+ } else if (prop in config1) {
756
+ return getMergedValue(void 0, config1[prop]);
757
+ }
758
+ }
759
+ var mergeMap = {
760
+ "url": valueFromConfig2,
761
+ "method": valueFromConfig2,
762
+ "data": valueFromConfig2,
763
+ "baseURL": defaultToConfig2,
764
+ "transformRequest": defaultToConfig2,
765
+ "transformResponse": defaultToConfig2,
766
+ "paramsSerializer": defaultToConfig2,
767
+ "timeout": defaultToConfig2,
768
+ "timeoutMessage": defaultToConfig2,
769
+ "withCredentials": defaultToConfig2,
770
+ "adapter": defaultToConfig2,
771
+ "responseType": defaultToConfig2,
772
+ "xsrfCookieName": defaultToConfig2,
773
+ "xsrfHeaderName": defaultToConfig2,
774
+ "onUploadProgress": defaultToConfig2,
775
+ "onDownloadProgress": defaultToConfig2,
776
+ "decompress": defaultToConfig2,
777
+ "maxContentLength": defaultToConfig2,
778
+ "maxBodyLength": defaultToConfig2,
779
+ "transport": defaultToConfig2,
780
+ "httpAgent": defaultToConfig2,
781
+ "httpsAgent": defaultToConfig2,
782
+ "cancelToken": defaultToConfig2,
783
+ "socketPath": defaultToConfig2,
784
+ "responseEncoding": defaultToConfig2,
785
+ "validateStatus": mergeDirectKeys
786
+ };
787
+ utils$v.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
788
+ var merge2 = mergeMap[prop] || mergeDeepProperties;
789
+ var configValue = merge2(prop);
790
+ utils$v.isUndefined(configValue) && merge2 !== mergeDirectKeys || (config[prop] = configValue);
791
+ });
792
+ return config;
793
+ };
794
+ var data$1 = {
795
+ "version": "0.25.0"
796
+ };
797
+ var VERSION$1 = data$1.version;
798
+ var validators$5 = {};
799
+ ["object", "boolean", "number", "function", "string", "symbol"].forEach(function(type, i) {
800
+ validators$5[type] = function validator2(thing) {
801
+ return typeof thing === type || "a" + (i < 1 ? "n " : " ") + type;
802
+ };
803
+ });
804
+ var deprecatedWarnings$2 = {};
805
+ validators$5.transitional = function transitional(validator2, version2, message) {
806
+ function formatMessage(opt, desc) {
807
+ return "[Axios v" + VERSION$1 + "] Transitional option '" + opt + "'" + desc + (message ? ". " + message : "");
808
+ }
809
+ return function(value, opt, opts) {
810
+ if (validator2 === false) {
811
+ throw new Error(formatMessage(opt, " has been removed" + (version2 ? " in " + version2 : "")));
812
+ }
813
+ if (version2 && !deprecatedWarnings$2[opt]) {
814
+ deprecatedWarnings$2[opt] = true;
815
+ console.warn(formatMessage(opt, " has been deprecated since v" + version2 + " and will be removed in the near future"));
816
+ }
817
+ return validator2 ? validator2(value, opt, opts) : true;
818
+ };
819
+ };
820
+ function assertOptions$2(options, schema, allowUnknown) {
821
+ if (typeof options !== "object") {
822
+ throw new TypeError("options must be an object");
823
+ }
824
+ var keys = Object.keys(options);
825
+ var i = keys.length;
826
+ while (i-- > 0) {
827
+ var opt = keys[i];
828
+ var validator2 = schema[opt];
829
+ if (validator2) {
830
+ var value = options[opt];
831
+ var result = value === void 0 || validator2(value, opt, options);
832
+ if (result !== true) {
833
+ throw new TypeError("option " + opt + " must be " + result);
834
+ }
835
+ continue;
836
+ }
837
+ if (allowUnknown !== true) {
838
+ throw Error("Unknown option " + opt);
839
+ }
840
+ }
841
+ }
842
+ var validator$5 = {
843
+ assertOptions: assertOptions$2,
844
+ validators: validators$5
845
+ };
846
+ var utils$u = utils$G;
847
+ var buildURL$6 = buildURL$8;
848
+ var InterceptorManager$4 = InterceptorManager_1$2;
849
+ var dispatchRequest$4 = dispatchRequest$5;
850
+ var mergeConfig$7 = mergeConfig$8;
851
+ var validator$4 = validator$5;
852
+ var validators$4 = validator$4.validators;
853
+ function Axios$5(instanceConfig) {
854
+ this.defaults = instanceConfig;
855
+ this.interceptors = {
856
+ request: new InterceptorManager$4(),
857
+ response: new InterceptorManager$4()
858
+ };
859
+ }
860
+ Axios$5.prototype.request = function request(configOrUrl, config) {
861
+ if (typeof configOrUrl === "string") {
862
+ config = config || {};
863
+ config.url = configOrUrl;
864
+ } else {
865
+ config = configOrUrl || {};
866
+ }
867
+ if (!config.url) {
868
+ throw new Error("Provided config url is not valid");
869
+ }
870
+ config = mergeConfig$7(this.defaults, config);
871
+ if (config.method) {
872
+ config.method = config.method.toLowerCase();
873
+ } else if (this.defaults.method) {
874
+ config.method = this.defaults.method.toLowerCase();
875
+ } else {
876
+ config.method = "get";
877
+ }
878
+ var transitional4 = config.transitional;
879
+ if (transitional4 !== void 0) {
880
+ validator$4.assertOptions(transitional4, {
881
+ silentJSONParsing: validators$4.transitional(validators$4.boolean),
882
+ forcedJSONParsing: validators$4.transitional(validators$4.boolean),
883
+ clarifyTimeoutError: validators$4.transitional(validators$4.boolean)
884
+ }, false);
885
+ }
886
+ var requestInterceptorChain = [];
887
+ var synchronousRequestInterceptors = true;
888
+ this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
889
+ if (typeof interceptor.runWhen === "function" && interceptor.runWhen(config) === false) {
890
+ return;
891
+ }
892
+ synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
893
+ requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
894
+ });
895
+ var responseInterceptorChain = [];
896
+ this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
897
+ responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
898
+ });
899
+ var promise;
900
+ if (!synchronousRequestInterceptors) {
901
+ var chain = [dispatchRequest$4, void 0];
902
+ Array.prototype.unshift.apply(chain, requestInterceptorChain);
903
+ chain = chain.concat(responseInterceptorChain);
904
+ promise = Promise.resolve(config);
905
+ while (chain.length) {
906
+ promise = promise.then(chain.shift(), chain.shift());
907
+ }
908
+ return promise;
909
+ }
910
+ var newConfig = config;
911
+ while (requestInterceptorChain.length) {
912
+ var onFulfilled = requestInterceptorChain.shift();
913
+ var onRejected = requestInterceptorChain.shift();
914
+ try {
915
+ newConfig = onFulfilled(newConfig);
916
+ } catch (error) {
917
+ onRejected(error);
918
+ break;
919
+ }
920
+ }
921
+ try {
922
+ promise = dispatchRequest$4(newConfig);
923
+ } catch (error) {
924
+ return Promise.reject(error);
925
+ }
926
+ while (responseInterceptorChain.length) {
927
+ promise = promise.then(responseInterceptorChain.shift(), responseInterceptorChain.shift());
928
+ }
929
+ return promise;
930
+ };
931
+ Axios$5.prototype.getUri = function getUri(config) {
932
+ if (!config.url) {
933
+ throw new Error("Provided config url is not valid");
934
+ }
935
+ config = mergeConfig$7(this.defaults, config);
936
+ return buildURL$6(config.url, config.params, config.paramsSerializer).replace(/^\?/, "");
937
+ };
938
+ utils$u.forEach(["delete", "get", "head", "options"], function forEachMethodNoData2(method) {
939
+ Axios$5.prototype[method] = function(url, config) {
940
+ return this.request(mergeConfig$7(config || {}, {
941
+ method,
942
+ url,
943
+ data: (config || {}).data
944
+ }));
945
+ };
946
+ });
947
+ utils$u.forEach(["post", "put", "patch"], function forEachMethodWithData2(method) {
948
+ Axios$5.prototype[method] = function(url, data2, config) {
949
+ return this.request(mergeConfig$7(config || {}, {
950
+ method,
951
+ url,
952
+ data: data2
953
+ }));
954
+ };
955
+ });
956
+ var Axios_1$2 = Axios$5;
957
+ var Cancel$6 = Cancel_1$2;
958
+ function CancelToken$2(executor) {
959
+ if (typeof executor !== "function") {
960
+ throw new TypeError("executor must be a function.");
961
+ }
962
+ var resolvePromise;
963
+ this.promise = new Promise(function promiseExecutor(resolve) {
964
+ resolvePromise = resolve;
965
+ });
966
+ var token2 = this;
967
+ this.promise.then(function(cancel) {
968
+ if (!token2._listeners)
969
+ return;
970
+ var i;
971
+ var l = token2._listeners.length;
972
+ for (i = 0; i < l; i++) {
973
+ token2._listeners[i](cancel);
974
+ }
975
+ token2._listeners = null;
976
+ });
977
+ this.promise.then = function(onfulfilled) {
978
+ var _resolve;
979
+ var promise = new Promise(function(resolve) {
980
+ token2.subscribe(resolve);
981
+ _resolve = resolve;
982
+ }).then(onfulfilled);
983
+ promise.cancel = function reject() {
984
+ token2.unsubscribe(_resolve);
985
+ };
986
+ return promise;
987
+ };
988
+ executor(function cancel(message) {
989
+ if (token2.reason) {
990
+ return;
991
+ }
992
+ token2.reason = new Cancel$6(message);
993
+ resolvePromise(token2.reason);
994
+ });
995
+ }
996
+ CancelToken$2.prototype.throwIfRequested = function throwIfRequested() {
997
+ if (this.reason) {
998
+ throw this.reason;
999
+ }
1000
+ };
1001
+ CancelToken$2.prototype.subscribe = function subscribe(listener) {
1002
+ if (this.reason) {
1003
+ listener(this.reason);
1004
+ return;
1005
+ }
1006
+ if (this._listeners) {
1007
+ this._listeners.push(listener);
1008
+ } else {
1009
+ this._listeners = [listener];
1010
+ }
1011
+ };
1012
+ CancelToken$2.prototype.unsubscribe = function unsubscribe(listener) {
1013
+ if (!this._listeners) {
1014
+ return;
1015
+ }
1016
+ var index = this._listeners.indexOf(listener);
1017
+ if (index !== -1) {
1018
+ this._listeners.splice(index, 1);
1019
+ }
1020
+ };
1021
+ CancelToken$2.source = function source() {
1022
+ var cancel;
1023
+ var token2 = new CancelToken$2(function executor(c) {
1024
+ cancel = c;
1025
+ });
1026
+ return {
1027
+ token: token2,
1028
+ cancel
1029
+ };
1030
+ };
1031
+ var CancelToken_1$2 = CancelToken$2;
1032
+ var spread$2 = function spread(callback) {
1033
+ return function wrap(arr) {
1034
+ return callback.apply(null, arr);
1035
+ };
1036
+ };
1037
+ var utils$t = utils$G;
1038
+ var isAxiosError$2 = function isAxiosError(payload) {
1039
+ return utils$t.isObject(payload) && payload.isAxiosError === true;
1040
+ };
1041
+ var utils$s = utils$G;
1042
+ var bind$6 = bind$8;
1043
+ var Axios$4 = Axios_1$2;
1044
+ var mergeConfig$6 = mergeConfig$8;
1045
+ var defaults$9 = defaults_1$2;
1046
+ function createInstance$2(defaultConfig) {
1047
+ var context = new Axios$4(defaultConfig);
1048
+ var instance = bind$6(Axios$4.prototype.request, context);
1049
+ utils$s.extend(instance, Axios$4.prototype, context);
1050
+ utils$s.extend(instance, context);
1051
+ instance.create = function create2(instanceConfig) {
1052
+ return createInstance$2(mergeConfig$6(defaultConfig, instanceConfig));
1053
+ };
1054
+ return instance;
1055
+ }
1056
+ var axios$7 = createInstance$2(defaults$9);
1057
+ axios$7.Axios = Axios$4;
1058
+ axios$7.Cancel = Cancel_1$2;
1059
+ axios$7.CancelToken = CancelToken_1$2;
1060
+ axios$7.isCancel = isCancel$5;
1061
+ axios$7.VERSION = data$1.version;
1062
+ axios$7.all = function all(promises) {
1063
+ return Promise.all(promises);
1064
+ };
1065
+ axios$7.spread = spread$2;
1066
+ axios$7.isAxiosError = isAxiosError$2;
1067
+ axios$8.exports = axios$7;
1068
+ axios$8.exports.default = axios$7;
1069
+ var axios$6 = axios$8.exports;
1070
+ const SERVER_ERROR_CODE = 500;
1071
+ class HasuraAuthApi {
1072
+ constructor({ url = "" }) {
1073
+ this.url = url;
1074
+ this.httpClient = axios$6.create({
1075
+ baseURL: this.url
1076
+ });
1077
+ this.httpClient.interceptors.response.use((response) => response, (error) => {
1078
+ var _a, _b, _c, _d, _e, _f;
1079
+ return Promise.reject({
1080
+ message: (_d = (_c = (_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) != null ? _c : error.message) != null ? _d : JSON.stringify(error),
1081
+ status: (_f = (_e = error.response) == null ? void 0 : _e.status) != null ? _f : SERVER_ERROR_CODE
1082
+ });
1083
+ });
1084
+ }
1085
+ async signUpEmailPassword(params) {
1086
+ try {
1087
+ const res = await this.httpClient.post("/signup/email-password", params);
1088
+ return { data: res.data, error: null };
1089
+ } catch (error) {
1090
+ return { data: null, error };
1091
+ }
1092
+ }
1093
+ async signInEmailPassword(params) {
1094
+ try {
1095
+ const res = await this.httpClient.post("/signin/email-password", params);
1096
+ return { data: res.data, error: null };
1097
+ } catch (error) {
1098
+ return { data: null, error };
1099
+ }
1100
+ }
1101
+ async signInPasswordlessEmail(params) {
1102
+ try {
1103
+ const res = await this.httpClient.post("/signin/passwordless/email", params);
1104
+ return { data: res.data, error: null };
1105
+ } catch (error) {
1106
+ return { data: null, error };
1107
+ }
1108
+ }
1109
+ async signInPasswordlessSms(params) {
1110
+ try {
1111
+ const res = await this.httpClient.post("/signin/passwordless/sms", params);
1112
+ return { data: res.data, error: null };
1113
+ } catch (error) {
1114
+ return { data: null, error };
1115
+ }
1116
+ }
1117
+ async signInPasswordlessSmsOtp(params) {
1118
+ try {
1119
+ const res = await this.httpClient.post("/signin/passwordless/sms/otp", params);
1120
+ return { data: res.data, error: null };
1121
+ } catch (error) {
1122
+ return { data: null, error };
1123
+ }
1124
+ }
1125
+ async signOut(params) {
1126
+ try {
1127
+ await this.httpClient.post("/signout", params);
1128
+ return { error: null };
1129
+ } catch (error) {
1130
+ return { error };
1131
+ }
1132
+ }
1133
+ async refreshToken(params) {
1134
+ try {
1135
+ const res = await this.httpClient.post("/token", params);
1136
+ return { error: null, session: res.data };
1137
+ } catch (error) {
1138
+ return { error, session: null };
1139
+ }
1140
+ }
1141
+ async resetPassword(params) {
1142
+ try {
1143
+ await this.httpClient.post("/user/password/reset", params);
1144
+ return { error: null };
1145
+ } catch (error) {
1146
+ return { error };
1147
+ }
1148
+ }
1149
+ async changePassword(params) {
1150
+ try {
1151
+ await this.httpClient.post("/user/password", params, {
1152
+ headers: __spreadValues({}, this.generateAuthHeaders())
1153
+ });
1154
+ return { error: null };
1155
+ } catch (error) {
1156
+ return { error };
1157
+ }
1158
+ }
1159
+ async sendVerificationEmail(params) {
1160
+ try {
1161
+ await this.httpClient.post("/user/email/send-verification-email", params);
1162
+ return { error: null };
1163
+ } catch (error) {
1164
+ return { error };
1165
+ }
1166
+ }
1167
+ async changeEmail(params) {
1168
+ try {
1169
+ await this.httpClient.post("/user/email/change", params, {
1170
+ headers: __spreadValues({}, this.generateAuthHeaders())
1171
+ });
1172
+ return { error: null };
1173
+ } catch (error) {
1174
+ return { error };
1175
+ }
1176
+ }
1177
+ async deanonymize(params) {
1178
+ try {
1179
+ await this.httpClient.post("/user/deanonymize", params);
1180
+ return { error: null };
1181
+ } catch (error) {
1182
+ return { error };
1183
+ }
1184
+ }
1185
+ async verifyEmail(params) {
1186
+ try {
1187
+ const res = await this.httpClient.post("/user/email/verify", params);
1188
+ return { data: res.data, error: null };
1189
+ } catch (error) {
1190
+ return { data: null, error };
1191
+ }
1192
+ }
1193
+ setAccessToken(accessToken) {
1194
+ this.accessToken = accessToken;
1195
+ }
1196
+ generateAuthHeaders() {
1197
+ if (!this.accessToken) {
1198
+ return null;
1199
+ }
1200
+ return {
1201
+ Authorization: `Bearer ${this.accessToken}`
1202
+ };
1203
+ }
1204
+ }
1205
+ var queryString = {};
1206
+ var strictUriEncode = (str) => encodeURIComponent(str).replace(/[!'()*]/g, (x) => `%${x.charCodeAt(0).toString(16).toUpperCase()}`);
1207
+ var token = "%[a-f0-9]{2}";
1208
+ var singleMatcher = new RegExp(token, "gi");
1209
+ var multiMatcher = new RegExp("(" + token + ")+", "gi");
1210
+ function decodeComponents(components, split) {
1211
+ try {
1212
+ return decodeURIComponent(components.join(""));
1213
+ } catch (err) {
1214
+ }
1215
+ if (components.length === 1) {
1216
+ return components;
1217
+ }
1218
+ split = split || 1;
1219
+ var left = components.slice(0, split);
1220
+ var right = components.slice(split);
1221
+ return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
1222
+ }
1223
+ function decode(input) {
1224
+ try {
1225
+ return decodeURIComponent(input);
1226
+ } catch (err) {
1227
+ var tokens = input.match(singleMatcher);
1228
+ for (var i = 1; i < tokens.length; i++) {
1229
+ input = decodeComponents(tokens, i).join("");
1230
+ tokens = input.match(singleMatcher);
1231
+ }
1232
+ return input;
1233
+ }
1234
+ }
1235
+ function customDecodeURIComponent(input) {
1236
+ var replaceMap = {
1237
+ "%FE%FF": "\uFFFD\uFFFD",
1238
+ "%FF%FE": "\uFFFD\uFFFD"
1239
+ };
1240
+ var match = multiMatcher.exec(input);
1241
+ while (match) {
1242
+ try {
1243
+ replaceMap[match[0]] = decodeURIComponent(match[0]);
1244
+ } catch (err) {
1245
+ var result = decode(match[0]);
1246
+ if (result !== match[0]) {
1247
+ replaceMap[match[0]] = result;
1248
+ }
1249
+ }
1250
+ match = multiMatcher.exec(input);
1251
+ }
1252
+ replaceMap["%C2"] = "\uFFFD";
1253
+ var entries = Object.keys(replaceMap);
1254
+ for (var i = 0; i < entries.length; i++) {
1255
+ var key = entries[i];
1256
+ input = input.replace(new RegExp(key, "g"), replaceMap[key]);
1257
+ }
1258
+ return input;
1259
+ }
1260
+ var decodeUriComponent = function(encodedURI) {
1261
+ if (typeof encodedURI !== "string") {
1262
+ throw new TypeError("Expected `encodedURI` to be of type `string`, got `" + typeof encodedURI + "`");
1263
+ }
1264
+ try {
1265
+ encodedURI = encodedURI.replace(/\+/g, " ");
1266
+ return decodeURIComponent(encodedURI);
1267
+ } catch (err) {
1268
+ return customDecodeURIComponent(encodedURI);
1269
+ }
1270
+ };
1271
+ var splitOnFirst = (string, separator) => {
1272
+ if (!(typeof string === "string" && typeof separator === "string")) {
1273
+ throw new TypeError("Expected the arguments to be of type `string`");
1274
+ }
1275
+ if (separator === "") {
1276
+ return [string];
1277
+ }
1278
+ const separatorIndex = string.indexOf(separator);
1279
+ if (separatorIndex === -1) {
1280
+ return [string];
1281
+ }
1282
+ return [
1283
+ string.slice(0, separatorIndex),
1284
+ string.slice(separatorIndex + separator.length)
1285
+ ];
1286
+ };
1287
+ var filterObj = function(obj, predicate) {
1288
+ var ret = {};
1289
+ var keys = Object.keys(obj);
1290
+ var isArr = Array.isArray(predicate);
1291
+ for (var i = 0; i < keys.length; i++) {
1292
+ var key = keys[i];
1293
+ var val = obj[key];
1294
+ if (isArr ? predicate.indexOf(key) !== -1 : predicate(key, val, obj)) {
1295
+ ret[key] = val;
1296
+ }
1297
+ }
1298
+ return ret;
1299
+ };
1300
+ (function(exports) {
1301
+ const strictUriEncode$1 = strictUriEncode;
1302
+ const decodeComponent = decodeUriComponent;
1303
+ const splitOnFirst$1 = splitOnFirst;
1304
+ const filterObject = filterObj;
1305
+ const isNullOrUndefined = (value) => value === null || value === void 0;
1306
+ const encodeFragmentIdentifier = Symbol("encodeFragmentIdentifier");
1307
+ function encoderForArrayFormat(options) {
1308
+ switch (options.arrayFormat) {
1309
+ case "index":
1310
+ return (key) => (result, value) => {
1311
+ const index = result.length;
1312
+ if (value === void 0 || options.skipNull && value === null || options.skipEmptyString && value === "") {
1313
+ return result;
1314
+ }
1315
+ if (value === null) {
1316
+ return [...result, [encode2(key, options), "[", index, "]"].join("")];
1317
+ }
1318
+ return [
1319
+ ...result,
1320
+ [encode2(key, options), "[", encode2(index, options), "]=", encode2(value, options)].join("")
1321
+ ];
1322
+ };
1323
+ case "bracket":
1324
+ return (key) => (result, value) => {
1325
+ if (value === void 0 || options.skipNull && value === null || options.skipEmptyString && value === "") {
1326
+ return result;
1327
+ }
1328
+ if (value === null) {
1329
+ return [...result, [encode2(key, options), "[]"].join("")];
1330
+ }
1331
+ return [...result, [encode2(key, options), "[]=", encode2(value, options)].join("")];
1332
+ };
1333
+ case "colon-list-separator":
1334
+ return (key) => (result, value) => {
1335
+ if (value === void 0 || options.skipNull && value === null || options.skipEmptyString && value === "") {
1336
+ return result;
1337
+ }
1338
+ if (value === null) {
1339
+ return [...result, [encode2(key, options), ":list="].join("")];
1340
+ }
1341
+ return [...result, [encode2(key, options), ":list=", encode2(value, options)].join("")];
1342
+ };
1343
+ case "comma":
1344
+ case "separator":
1345
+ case "bracket-separator": {
1346
+ const keyValueSep = options.arrayFormat === "bracket-separator" ? "[]=" : "=";
1347
+ return (key) => (result, value) => {
1348
+ if (value === void 0 || options.skipNull && value === null || options.skipEmptyString && value === "") {
1349
+ return result;
1350
+ }
1351
+ value = value === null ? "" : value;
1352
+ if (result.length === 0) {
1353
+ return [[encode2(key, options), keyValueSep, encode2(value, options)].join("")];
1354
+ }
1355
+ return [[result, encode2(value, options)].join(options.arrayFormatSeparator)];
1356
+ };
1357
+ }
1358
+ default:
1359
+ return (key) => (result, value) => {
1360
+ if (value === void 0 || options.skipNull && value === null || options.skipEmptyString && value === "") {
1361
+ return result;
1362
+ }
1363
+ if (value === null) {
1364
+ return [...result, encode2(key, options)];
1365
+ }
1366
+ return [...result, [encode2(key, options), "=", encode2(value, options)].join("")];
1367
+ };
1368
+ }
1369
+ }
1370
+ function parserForArrayFormat(options) {
1371
+ let result;
1372
+ switch (options.arrayFormat) {
1373
+ case "index":
1374
+ return (key, value, accumulator) => {
1375
+ result = /\[(\d*)\]$/.exec(key);
1376
+ key = key.replace(/\[\d*\]$/, "");
1377
+ if (!result) {
1378
+ accumulator[key] = value;
1379
+ return;
1380
+ }
1381
+ if (accumulator[key] === void 0) {
1382
+ accumulator[key] = {};
1383
+ }
1384
+ accumulator[key][result[1]] = value;
1385
+ };
1386
+ case "bracket":
1387
+ return (key, value, accumulator) => {
1388
+ result = /(\[\])$/.exec(key);
1389
+ key = key.replace(/\[\]$/, "");
1390
+ if (!result) {
1391
+ accumulator[key] = value;
1392
+ return;
1393
+ }
1394
+ if (accumulator[key] === void 0) {
1395
+ accumulator[key] = [value];
1396
+ return;
1397
+ }
1398
+ accumulator[key] = [].concat(accumulator[key], value);
1399
+ };
1400
+ case "colon-list-separator":
1401
+ return (key, value, accumulator) => {
1402
+ result = /(:list)$/.exec(key);
1403
+ key = key.replace(/:list$/, "");
1404
+ if (!result) {
1405
+ accumulator[key] = value;
1406
+ return;
1407
+ }
1408
+ if (accumulator[key] === void 0) {
1409
+ accumulator[key] = [value];
1410
+ return;
1411
+ }
1412
+ accumulator[key] = [].concat(accumulator[key], value);
1413
+ };
1414
+ case "comma":
1415
+ case "separator":
1416
+ return (key, value, accumulator) => {
1417
+ const isArray2 = typeof value === "string" && value.includes(options.arrayFormatSeparator);
1418
+ const isEncodedArray = typeof value === "string" && !isArray2 && decode2(value, options).includes(options.arrayFormatSeparator);
1419
+ value = isEncodedArray ? decode2(value, options) : value;
1420
+ const newValue = isArray2 || isEncodedArray ? value.split(options.arrayFormatSeparator).map((item) => decode2(item, options)) : value === null ? value : decode2(value, options);
1421
+ accumulator[key] = newValue;
1422
+ };
1423
+ case "bracket-separator":
1424
+ return (key, value, accumulator) => {
1425
+ const isArray2 = /(\[\])$/.test(key);
1426
+ key = key.replace(/\[\]$/, "");
1427
+ if (!isArray2) {
1428
+ accumulator[key] = value ? decode2(value, options) : value;
1429
+ return;
1430
+ }
1431
+ const arrayValue = value === null ? [] : value.split(options.arrayFormatSeparator).map((item) => decode2(item, options));
1432
+ if (accumulator[key] === void 0) {
1433
+ accumulator[key] = arrayValue;
1434
+ return;
1435
+ }
1436
+ accumulator[key] = [].concat(accumulator[key], arrayValue);
1437
+ };
1438
+ default:
1439
+ return (key, value, accumulator) => {
1440
+ if (accumulator[key] === void 0) {
1441
+ accumulator[key] = value;
1442
+ return;
1443
+ }
1444
+ accumulator[key] = [].concat(accumulator[key], value);
1445
+ };
1446
+ }
1447
+ }
1448
+ function validateArrayFormatSeparator(value) {
1449
+ if (typeof value !== "string" || value.length !== 1) {
1450
+ throw new TypeError("arrayFormatSeparator must be single character string");
1451
+ }
1452
+ }
1453
+ function encode2(value, options) {
1454
+ if (options.encode) {
1455
+ return options.strict ? strictUriEncode$1(value) : encodeURIComponent(value);
1456
+ }
1457
+ return value;
1458
+ }
1459
+ function decode2(value, options) {
1460
+ if (options.decode) {
1461
+ return decodeComponent(value);
1462
+ }
1463
+ return value;
1464
+ }
1465
+ function keysSorter(input) {
1466
+ if (Array.isArray(input)) {
1467
+ return input.sort();
1468
+ }
1469
+ if (typeof input === "object") {
1470
+ return keysSorter(Object.keys(input)).sort((a, b) => Number(a) - Number(b)).map((key) => input[key]);
1471
+ }
1472
+ return input;
1473
+ }
1474
+ function removeHash(input) {
1475
+ const hashStart = input.indexOf("#");
1476
+ if (hashStart !== -1) {
1477
+ input = input.slice(0, hashStart);
1478
+ }
1479
+ return input;
1480
+ }
1481
+ function getHash(url) {
1482
+ let hash = "";
1483
+ const hashStart = url.indexOf("#");
1484
+ if (hashStart !== -1) {
1485
+ hash = url.slice(hashStart);
1486
+ }
1487
+ return hash;
1488
+ }
1489
+ function extract(input) {
1490
+ input = removeHash(input);
1491
+ const queryStart = input.indexOf("?");
1492
+ if (queryStart === -1) {
1493
+ return "";
1494
+ }
1495
+ return input.slice(queryStart + 1);
1496
+ }
1497
+ function parseValue(value, options) {
1498
+ if (options.parseNumbers && !Number.isNaN(Number(value)) && (typeof value === "string" && value.trim() !== "")) {
1499
+ value = Number(value);
1500
+ } else if (options.parseBooleans && value !== null && (value.toLowerCase() === "true" || value.toLowerCase() === "false")) {
1501
+ value = value.toLowerCase() === "true";
1502
+ }
1503
+ return value;
1504
+ }
1505
+ function parse(query, options) {
1506
+ options = Object.assign({
1507
+ decode: true,
1508
+ sort: true,
1509
+ arrayFormat: "none",
1510
+ arrayFormatSeparator: ",",
1511
+ parseNumbers: false,
1512
+ parseBooleans: false
1513
+ }, options);
1514
+ validateArrayFormatSeparator(options.arrayFormatSeparator);
1515
+ const formatter = parserForArrayFormat(options);
1516
+ const ret = Object.create(null);
1517
+ if (typeof query !== "string") {
1518
+ return ret;
1519
+ }
1520
+ query = query.trim().replace(/^[?#&]/, "");
1521
+ if (!query) {
1522
+ return ret;
1523
+ }
1524
+ for (const param of query.split("&")) {
1525
+ if (param === "") {
1526
+ continue;
1527
+ }
1528
+ let [key, value] = splitOnFirst$1(options.decode ? param.replace(/\+/g, " ") : param, "=");
1529
+ value = value === void 0 ? null : ["comma", "separator", "bracket-separator"].includes(options.arrayFormat) ? value : decode2(value, options);
1530
+ formatter(decode2(key, options), value, ret);
1531
+ }
1532
+ for (const key of Object.keys(ret)) {
1533
+ const value = ret[key];
1534
+ if (typeof value === "object" && value !== null) {
1535
+ for (const k of Object.keys(value)) {
1536
+ value[k] = parseValue(value[k], options);
1537
+ }
1538
+ } else {
1539
+ ret[key] = parseValue(value, options);
1540
+ }
1541
+ }
1542
+ if (options.sort === false) {
1543
+ return ret;
1544
+ }
1545
+ return (options.sort === true ? Object.keys(ret).sort() : Object.keys(ret).sort(options.sort)).reduce((result, key) => {
1546
+ const value = ret[key];
1547
+ if (Boolean(value) && typeof value === "object" && !Array.isArray(value)) {
1548
+ result[key] = keysSorter(value);
1549
+ } else {
1550
+ result[key] = value;
1551
+ }
1552
+ return result;
1553
+ }, Object.create(null));
1554
+ }
1555
+ exports.extract = extract;
1556
+ exports.parse = parse;
1557
+ exports.stringify = (object, options) => {
1558
+ if (!object) {
1559
+ return "";
1560
+ }
1561
+ options = Object.assign({
1562
+ encode: true,
1563
+ strict: true,
1564
+ arrayFormat: "none",
1565
+ arrayFormatSeparator: ","
1566
+ }, options);
1567
+ validateArrayFormatSeparator(options.arrayFormatSeparator);
1568
+ const shouldFilter = (key) => options.skipNull && isNullOrUndefined(object[key]) || options.skipEmptyString && object[key] === "";
1569
+ const formatter = encoderForArrayFormat(options);
1570
+ const objectCopy = {};
1571
+ for (const key of Object.keys(object)) {
1572
+ if (!shouldFilter(key)) {
1573
+ objectCopy[key] = object[key];
1574
+ }
1575
+ }
1576
+ const keys = Object.keys(objectCopy);
1577
+ if (options.sort !== false) {
1578
+ keys.sort(options.sort);
1579
+ }
1580
+ return keys.map((key) => {
1581
+ const value = object[key];
1582
+ if (value === void 0) {
1583
+ return "";
1584
+ }
1585
+ if (value === null) {
1586
+ return encode2(key, options);
1587
+ }
1588
+ if (Array.isArray(value)) {
1589
+ if (value.length === 0 && options.arrayFormat === "bracket-separator") {
1590
+ return encode2(key, options) + "[]";
1591
+ }
1592
+ return value.reduce(formatter(key), []).join("&");
1593
+ }
1594
+ return encode2(key, options) + "=" + encode2(value, options);
1595
+ }).filter((x) => x.length > 0).join("&");
1596
+ };
1597
+ exports.parseUrl = (url, options) => {
1598
+ options = Object.assign({
1599
+ decode: true
1600
+ }, options);
1601
+ const [url_, hash] = splitOnFirst$1(url, "#");
1602
+ return Object.assign({
1603
+ url: url_.split("?")[0] || "",
1604
+ query: parse(extract(url), options)
1605
+ }, options && options.parseFragmentIdentifier && hash ? { fragmentIdentifier: decode2(hash, options) } : {});
1606
+ };
1607
+ exports.stringifyUrl = (object, options) => {
1608
+ options = Object.assign({
1609
+ encode: true,
1610
+ strict: true,
1611
+ [encodeFragmentIdentifier]: true
1612
+ }, options);
1613
+ const url = removeHash(object.url).split("?")[0] || "";
1614
+ const queryFromUrl = exports.extract(object.url);
1615
+ const parsedQueryFromUrl = exports.parse(queryFromUrl, { sort: false });
1616
+ const query = Object.assign(parsedQueryFromUrl, object.query);
1617
+ let queryString2 = exports.stringify(query, options);
1618
+ if (queryString2) {
1619
+ queryString2 = `?${queryString2}`;
1620
+ }
1621
+ let hash = getHash(object.url);
1622
+ if (object.fragmentIdentifier) {
1623
+ hash = `#${options[encodeFragmentIdentifier] ? encode2(object.fragmentIdentifier, options) : object.fragmentIdentifier}`;
1624
+ }
1625
+ return `${url}${queryString2}${hash}`;
1626
+ };
1627
+ exports.pick = (input, filter, options) => {
1628
+ options = Object.assign({
1629
+ parseFragmentIdentifier: true,
1630
+ [encodeFragmentIdentifier]: false
1631
+ }, options);
1632
+ const { url, query, fragmentIdentifier } = exports.parseUrl(input, options);
1633
+ return exports.stringifyUrl({
1634
+ url,
1635
+ query: filterObject(query, filter),
1636
+ fragmentIdentifier
1637
+ }, options);
1638
+ };
1639
+ exports.exclude = (input, filter, options) => {
1640
+ const exclusionFilter = Array.isArray(filter) ? (key) => !filter.includes(key) : (key, value) => !filter(key, value);
1641
+ return exports.pick(input, exclusionFilter, options);
1642
+ };
1643
+ })(queryString);
1644
+ const NHOST_REFRESH_TOKEN = "nhostRefreshToken";
1645
+ const isBrowser = () => typeof window !== "undefined";
1646
+ class inMemoryLocalStorage {
1647
+ constructor() {
1648
+ this.memory = {};
1649
+ }
1650
+ setItem(key, value) {
1651
+ this.memory[key] = value;
1652
+ }
1653
+ getItem(key) {
1654
+ return this.memory[key];
1655
+ }
1656
+ removeItem(key) {
1657
+ delete this.memory[key];
1658
+ }
1659
+ }
1660
+ class HasuraAuthClient {
1661
+ constructor({
1662
+ url,
1663
+ autoRefreshToken = true,
1664
+ autoLogin = true,
1665
+ refreshIntervalTime,
1666
+ clientStorage,
1667
+ clientStorageType = "web"
1668
+ }) {
1669
+ this.refreshIntervalTime = refreshIntervalTime;
1670
+ if (!clientStorage) {
1671
+ this.clientStorage = isBrowser() ? localStorage : new inMemoryLocalStorage();
1672
+ } else {
1673
+ this.clientStorage = clientStorage;
1674
+ }
1675
+ this.clientStorageType = clientStorageType;
1676
+ this.onTokenChangedFunctions = [];
1677
+ this.onAuthChangedFunctions = [];
1678
+ this.refreshInterval;
1679
+ this.refreshSleepCheckInterval = 0;
1680
+ this.refreshIntervalSleepCheckLastSample = Date.now();
1681
+ this.sampleRate = 2e3;
1682
+ this.url = url;
1683
+ this.autoRefreshToken = autoRefreshToken;
1684
+ this.initAuthLoading = true;
1685
+ this.session = null;
1686
+ this.api = new HasuraAuthApi({ url: this.url });
1687
+ let refreshToken = null;
1688
+ let autoLoginFromQueryParameters = false;
1689
+ if (autoLogin && isBrowser() && window.location) {
1690
+ const urlParams = queryString.parse(window.location.toString().split("#")[1]);
1691
+ if ("refreshToken" in urlParams) {
1692
+ refreshToken = urlParams.refreshToken;
1693
+ }
1694
+ if ("otp" in urlParams && "email" in urlParams) {
1695
+ const { otp, email } = urlParams;
1696
+ this.signIn({
1697
+ otp,
1698
+ email
1699
+ });
1700
+ autoLoginFromQueryParameters = true;
1701
+ }
1702
+ }
1703
+ if (!autoLoginFromQueryParameters && autoLogin) {
1704
+ this._autoLogin(refreshToken);
1705
+ } else if (refreshToken) {
1706
+ this._setItem(NHOST_REFRESH_TOKEN, refreshToken);
1707
+ }
1708
+ }
1709
+ async signUp(params) {
1710
+ const { email, password } = params;
1711
+ if (email && password) {
1712
+ const { data: data2, error } = await this.api.signUpEmailPassword(params);
1713
+ if (error) {
1714
+ return { session: null, error };
1715
+ }
1716
+ if (!data2) {
1717
+ return {
1718
+ session: null,
1719
+ error: { message: "An error occurred on sign up.", status: 500 }
1720
+ };
1721
+ }
1722
+ const { session } = data2;
1723
+ if (session) {
1724
+ await this._setSession(session);
1725
+ }
1726
+ return { session, error: null };
1727
+ }
1728
+ return {
1729
+ session: null,
1730
+ error: { message: "Incorrect parameters", status: 500 }
1731
+ };
1732
+ }
1733
+ async signIn(params) {
1734
+ if ("provider" in params) {
1735
+ const { provider } = params;
1736
+ const providerUrl = `${this.url}/signin/provider/${provider}`;
1737
+ if (isBrowser()) {
1738
+ window.location.href = providerUrl;
1739
+ }
1740
+ return { providerUrl, provider, session: null, mfa: null, error: null };
1741
+ }
1742
+ if ("email" in params && "password" in params) {
1743
+ const { data: data2, error } = await this.api.signInEmailPassword(params);
1744
+ if (error) {
1745
+ return { session: null, mfa: null, error };
1746
+ }
1747
+ if (!data2) {
1748
+ return {
1749
+ session: null,
1750
+ mfa: null,
1751
+ error: { message: "Incorrect Data", status: 500 }
1752
+ };
1753
+ }
1754
+ const { session, mfa } = data2;
1755
+ if (session) {
1756
+ await this._setSession(session);
1757
+ }
1758
+ return { session, mfa, error: null };
1759
+ }
1760
+ if ("email" in params && !("otp" in params)) {
1761
+ const { error } = await this.api.signInPasswordlessEmail(params);
1762
+ if (error) {
1763
+ return { session: null, mfa: null, error };
1764
+ }
1765
+ return { session: null, mfa: null, error: null };
1766
+ }
1767
+ if ("phoneNumber" in params && !("otp" in params)) {
1768
+ const { error } = await this.api.signInPasswordlessSms(params);
1769
+ if (error) {
1770
+ return { session: null, mfa: null, error };
1771
+ }
1772
+ return { session: null, mfa: null, error: null };
1773
+ }
1774
+ if ("otp" in params) {
1775
+ const { data: data2, error } = await this.api.signInPasswordlessSmsOtp(params);
1776
+ if (error) {
1777
+ return { session: null, mfa: null, error };
1778
+ }
1779
+ if (!data2) {
1780
+ return {
1781
+ session: null,
1782
+ mfa: null,
1783
+ error: { message: "Incorrect data", status: 500 }
1784
+ };
1785
+ }
1786
+ const { session, mfa } = data2;
1787
+ if (session) {
1788
+ await this._setSession(session);
1789
+ }
1790
+ return { session, mfa, error: null };
1791
+ }
1792
+ return {
1793
+ session: null,
1794
+ mfa: null,
1795
+ error: { message: "Incorrect parameters", status: 500 }
1796
+ };
1797
+ }
1798
+ async signOut(params) {
1799
+ const refreshToken = await this._getItem(NHOST_REFRESH_TOKEN);
1800
+ this._clearSession();
1801
+ const { error } = await this.api.signOut({
1802
+ refreshToken,
1803
+ all: params == null ? void 0 : params.all
1804
+ });
1805
+ return { error };
1806
+ }
1807
+ async verifyEmail(params) {
1808
+ return await this.api.verifyEmail(params);
1809
+ }
1810
+ async resetPassword(params) {
1811
+ const { error } = await this.api.resetPassword(params);
1812
+ return { error };
1813
+ }
1814
+ async changePassword(params) {
1815
+ const { error } = await this.api.changePassword(params);
1816
+ return { error };
1817
+ }
1818
+ async sendVerificationEmail(params) {
1819
+ const { error } = await this.api.sendVerificationEmail(params);
1820
+ return { error };
1821
+ }
1822
+ async changeEmail(params) {
1823
+ const { error } = await this.api.changeEmail(params);
1824
+ return { error };
1825
+ }
1826
+ async deanonymize(params) {
1827
+ const { error } = await this.api.deanonymize(params);
1828
+ return { error };
1829
+ }
1830
+ onTokenChanged(fn) {
1831
+ this.onTokenChangedFunctions.push(fn);
1832
+ const index = this.onTokenChangedFunctions.length - 1;
1833
+ const unsubscribe3 = () => {
1834
+ try {
1835
+ this.onTokenChangedFunctions[index] = () => {
1836
+ };
1837
+ } catch {
1838
+ console.warn("Unable to unsubscribe onTokenChanged function. Maybe the functions is already unsubscribed?");
1839
+ }
1840
+ };
1841
+ return unsubscribe3;
1842
+ }
1843
+ onAuthStateChanged(fn) {
1844
+ this.onAuthChangedFunctions.push(fn);
1845
+ const index = this.onAuthChangedFunctions.length - 1;
1846
+ const unsubscribe3 = () => {
1847
+ try {
1848
+ this.onAuthChangedFunctions[index] = () => {
1849
+ };
1850
+ } catch {
1851
+ console.warn("Unable to unsubscribe onAuthStateChanged function. Maybe you already did?");
1852
+ }
1853
+ };
1854
+ return unsubscribe3;
1855
+ }
1856
+ isAuthenticated() {
1857
+ return this.session !== null;
1858
+ }
1859
+ async isAuthenticatedAsync() {
1860
+ return new Promise((resolve) => {
1861
+ if (!this.initAuthLoading) {
1862
+ resolve(this.isAuthenticated());
1863
+ } else {
1864
+ const unsubscribe3 = this.onAuthStateChanged((event, _session) => {
1865
+ resolve(event === "SIGNED_IN");
1866
+ unsubscribe3();
1867
+ });
1868
+ }
1869
+ });
1870
+ }
1871
+ getAuthenticationStatus() {
1872
+ if (this.initAuthLoading)
1873
+ return { isAuthenticated: false, isLoading: true };
1874
+ return { isAuthenticated: this.session !== null, isLoading: false };
1875
+ }
1876
+ getJWTToken() {
1877
+ return this.getAccessToken();
1878
+ }
1879
+ getAccessToken() {
1880
+ if (!this.session) {
1881
+ return void 0;
1882
+ }
1883
+ return this.session.accessToken;
1884
+ }
1885
+ async refreshSession(refreshToken) {
1886
+ const refreshTokenToUse = refreshToken || await this._getItem(NHOST_REFRESH_TOKEN);
1887
+ if (!refreshTokenToUse) {
1888
+ console.warn("no refresh token found. No way of refreshing session");
1889
+ }
1890
+ return this._refreshTokens(refreshTokenToUse);
1891
+ }
1892
+ getSession() {
1893
+ return this.session;
1894
+ }
1895
+ getUser() {
1896
+ return this.session ? this.session.user : null;
1897
+ }
1898
+ async _setItem(key, value) {
1899
+ if (typeof value !== "string") {
1900
+ console.error(`value is not of type "string"`);
1901
+ return;
1902
+ }
1903
+ switch (this.clientStorageType) {
1904
+ case "web":
1905
+ if (typeof this.clientStorage.setItem !== "function") {
1906
+ console.error(`this.clientStorage.setItem is not a function`);
1907
+ break;
1908
+ }
1909
+ this.clientStorage.setItem(key, value);
1910
+ break;
1911
+ case "custom":
1912
+ case "react-native":
1913
+ if (typeof this.clientStorage.setItem !== "function") {
1914
+ console.error(`this.clientStorage.setItem is not a function`);
1915
+ break;
1916
+ }
1917
+ await this.clientStorage.setItem(key, value);
1918
+ break;
1919
+ case "capacitor":
1920
+ if (typeof this.clientStorage.set !== "function") {
1921
+ console.error(`this.clientStorage.set is not a function`);
1922
+ break;
1923
+ }
1924
+ await this.clientStorage.set({ key, value });
1925
+ break;
1926
+ case "expo-secure-storage":
1927
+ if (typeof this.clientStorage.setItemAsync !== "function") {
1928
+ console.error(`this.clientStorage.setItemAsync is not a function`);
1929
+ break;
1930
+ }
1931
+ this.clientStorage.setItemAsync(key, value);
1932
+ break;
1933
+ }
1934
+ }
1935
+ async _getItem(key) {
1936
+ switch (this.clientStorageType) {
1937
+ case "web":
1938
+ if (typeof this.clientStorage.getItem !== "function") {
1939
+ console.error(`this.clientStorage.getItem is not a function`);
1940
+ break;
1941
+ }
1942
+ return this.clientStorage.getItem(key);
1943
+ case "custom":
1944
+ case "react-native":
1945
+ if (typeof this.clientStorage.getItem !== "function") {
1946
+ console.error(`this.clientStorage.getItem is not a function`);
1947
+ break;
1948
+ }
1949
+ return await this.clientStorage.getItem(key);
1950
+ case "capacitor":
1951
+ if (typeof this.clientStorage.get !== "function") {
1952
+ console.error(`this.clientStorage.get is not a function`);
1953
+ break;
1954
+ }
1955
+ const res = await this.clientStorage.get({ key });
1956
+ return res.value;
1957
+ case "expo-secure-storage":
1958
+ if (typeof this.clientStorage.getItemAsync !== "function") {
1959
+ console.error(`this.clientStorage.getItemAsync is not a function`);
1960
+ break;
1961
+ }
1962
+ return this.clientStorage.getItemAsync(key);
1963
+ default:
1964
+ return "";
1965
+ }
1966
+ return "";
1967
+ }
1968
+ async _removeItem(key) {
1969
+ switch (this.clientStorageType) {
1970
+ case "web":
1971
+ if (typeof this.clientStorage.removeItem !== "function") {
1972
+ console.error(`this.clientStorage.removeItem is not a function`);
1973
+ break;
1974
+ }
1975
+ return void this.clientStorage.removeItem(key);
1976
+ case "custom":
1977
+ case "react-native":
1978
+ if (typeof this.clientStorage.removeItem !== "function") {
1979
+ console.error(`this.clientStorage.removeItem is not a function`);
1980
+ break;
1981
+ }
1982
+ return void this.clientStorage.removeItem(key);
1983
+ case "capacitor":
1984
+ if (typeof this.clientStorage.remove !== "function") {
1985
+ console.error(`this.clientStorage.remove is not a function`);
1986
+ break;
1987
+ }
1988
+ await this.clientStorage.remove({ key });
1989
+ break;
1990
+ case "expo-secure-storage":
1991
+ if (typeof this.clientStorage.deleteItemAsync !== "function") {
1992
+ console.error(`this.clientStorage.deleteItemAsync is not a function`);
1993
+ break;
1994
+ }
1995
+ this.clientStorage.deleteItemAsync(key);
1996
+ break;
1997
+ }
1998
+ }
1999
+ _autoLogin(refreshToken) {
2000
+ if (!isBrowser()) {
2001
+ return;
2002
+ }
2003
+ this._refreshTokens(refreshToken);
2004
+ }
2005
+ async _refreshTokens(paramRefreshToken) {
2006
+ const refreshToken = paramRefreshToken || await this._getItem(NHOST_REFRESH_TOKEN);
2007
+ if (!refreshToken) {
2008
+ setTimeout(async () => {
2009
+ await this._clearSession();
2010
+ }, 0);
2011
+ return;
2012
+ }
2013
+ try {
2014
+ const { session, error } = await this.api.refreshToken({ refreshToken });
2015
+ if (error && error.status === 401) {
2016
+ await this._clearSession();
2017
+ return;
2018
+ }
2019
+ if (!session)
2020
+ throw new Error("Invalid session data");
2021
+ await this._setSession(session);
2022
+ this.tokenChanged();
2023
+ } catch {
2024
+ }
2025
+ }
2026
+ tokenChanged() {
2027
+ for (const tokenChangedFunction of this.onTokenChangedFunctions) {
2028
+ tokenChangedFunction(this.session);
2029
+ }
2030
+ }
2031
+ authStateChanged({
2032
+ event,
2033
+ session
2034
+ }) {
2035
+ if (event === "SIGNED_IN" && session) {
2036
+ this.api.setAccessToken(session.accessToken);
2037
+ } else {
2038
+ this.api.setAccessToken(void 0);
2039
+ }
2040
+ for (const authChangedFunction of this.onAuthChangedFunctions) {
2041
+ authChangedFunction(event, session);
2042
+ }
2043
+ }
2044
+ async _clearSession() {
2045
+ const { isLoading, isAuthenticated } = this.getAuthenticationStatus();
2046
+ this.session = null;
2047
+ this.initAuthLoading = false;
2048
+ await this._removeItem(NHOST_REFRESH_TOKEN);
2049
+ if (isLoading || isAuthenticated) {
2050
+ clearInterval(this.refreshInterval);
2051
+ clearInterval(this.refreshSleepCheckInterval);
2052
+ this.authStateChanged({ event: "SIGNED_OUT", session: null });
2053
+ }
2054
+ }
2055
+ async _setSession(session) {
2056
+ const { isAuthenticated } = this.getAuthenticationStatus();
2057
+ this.session = session;
2058
+ await this._setItem(NHOST_REFRESH_TOKEN, session.refreshToken);
2059
+ if (this.autoRefreshToken && !isAuthenticated) {
2060
+ const JWTExpiresIn = session.accessTokenExpiresIn;
2061
+ const refreshIntervalTime = this.refreshIntervalTime ? this.refreshIntervalTime : Math.max(1, JWTExpiresIn - 1);
2062
+ this.refreshInterval = setInterval(async () => {
2063
+ const refreshToken = await this._getItem(NHOST_REFRESH_TOKEN);
2064
+ await this._refreshTokens(refreshToken);
2065
+ }, refreshIntervalTime * 1e3);
2066
+ this.refreshIntervalSleepCheckLastSample = Date.now();
2067
+ this.refreshSleepCheckInterval = setInterval(async () => {
2068
+ if (Date.now() - this.refreshIntervalSleepCheckLastSample >= this.sampleRate * 2) {
2069
+ const refreshToken = await this._getItem(NHOST_REFRESH_TOKEN);
2070
+ await this._refreshTokens(refreshToken);
2071
+ }
2072
+ this.refreshIntervalSleepCheckLastSample = Date.now();
2073
+ }, this.sampleRate);
2074
+ this.authStateChanged({ event: "SIGNED_IN", session: this.session });
2075
+ }
2076
+ this.initAuthLoading = false;
2077
+ }
2078
+ }
2079
+ var axios$5 = { exports: {} };
2080
+ var bind$5 = function bind2(fn, thisArg) {
2081
+ return function wrap() {
2082
+ var args = new Array(arguments.length);
2083
+ for (var i = 0; i < args.length; i++) {
2084
+ args[i] = arguments[i];
2085
+ }
2086
+ return fn.apply(thisArg, args);
2087
+ };
2088
+ };
2089
+ var bind$4 = bind$5;
2090
+ var toString$1 = Object.prototype.toString;
2091
+ function isArray$1(val) {
2092
+ return toString$1.call(val) === "[object Array]";
2093
+ }
2094
+ function isUndefined$1(val) {
2095
+ return typeof val === "undefined";
2096
+ }
2097
+ function isBuffer$1(val) {
2098
+ return val !== null && !isUndefined$1(val) && val.constructor !== null && !isUndefined$1(val.constructor) && typeof val.constructor.isBuffer === "function" && val.constructor.isBuffer(val);
2099
+ }
2100
+ function isArrayBuffer$1(val) {
2101
+ return toString$1.call(val) === "[object ArrayBuffer]";
2102
+ }
2103
+ function isFormData$1(val) {
2104
+ return typeof FormData !== "undefined" && val instanceof FormData;
2105
+ }
2106
+ function isArrayBufferView$1(val) {
2107
+ var result;
2108
+ if (typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView) {
2109
+ result = ArrayBuffer.isView(val);
2110
+ } else {
2111
+ result = val && val.buffer && val.buffer instanceof ArrayBuffer;
2112
+ }
2113
+ return result;
2114
+ }
2115
+ function isString$1(val) {
2116
+ return typeof val === "string";
2117
+ }
2118
+ function isNumber$1(val) {
2119
+ return typeof val === "number";
2120
+ }
2121
+ function isObject$1(val) {
2122
+ return val !== null && typeof val === "object";
2123
+ }
2124
+ function isPlainObject$1(val) {
2125
+ if (toString$1.call(val) !== "[object Object]") {
2126
+ return false;
2127
+ }
2128
+ var prototype = Object.getPrototypeOf(val);
2129
+ return prototype === null || prototype === Object.prototype;
2130
+ }
2131
+ function isDate$1(val) {
2132
+ return toString$1.call(val) === "[object Date]";
2133
+ }
2134
+ function isFile$1(val) {
2135
+ return toString$1.call(val) === "[object File]";
2136
+ }
2137
+ function isBlob$1(val) {
2138
+ return toString$1.call(val) === "[object Blob]";
2139
+ }
2140
+ function isFunction$1(val) {
2141
+ return toString$1.call(val) === "[object Function]";
2142
+ }
2143
+ function isStream$1(val) {
2144
+ return isObject$1(val) && isFunction$1(val.pipe);
2145
+ }
2146
+ function isURLSearchParams$1(val) {
2147
+ return typeof URLSearchParams !== "undefined" && val instanceof URLSearchParams;
2148
+ }
2149
+ function trim$1(str) {
2150
+ return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, "");
2151
+ }
2152
+ function isStandardBrowserEnv$1() {
2153
+ if (typeof navigator !== "undefined" && (navigator.product === "ReactNative" || navigator.product === "NativeScript" || navigator.product === "NS")) {
2154
+ return false;
2155
+ }
2156
+ return typeof window !== "undefined" && typeof document !== "undefined";
2157
+ }
2158
+ function forEach$1(obj, fn) {
2159
+ if (obj === null || typeof obj === "undefined") {
2160
+ return;
2161
+ }
2162
+ if (typeof obj !== "object") {
2163
+ obj = [obj];
2164
+ }
2165
+ if (isArray$1(obj)) {
2166
+ for (var i = 0, l = obj.length; i < l; i++) {
2167
+ fn.call(null, obj[i], i, obj);
2168
+ }
2169
+ } else {
2170
+ for (var key in obj) {
2171
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
2172
+ fn.call(null, obj[key], key, obj);
2173
+ }
2174
+ }
2175
+ }
2176
+ }
2177
+ function merge$1() {
2178
+ var result = {};
2179
+ function assignValue(val, key) {
2180
+ if (isPlainObject$1(result[key]) && isPlainObject$1(val)) {
2181
+ result[key] = merge$1(result[key], val);
2182
+ } else if (isPlainObject$1(val)) {
2183
+ result[key] = merge$1({}, val);
2184
+ } else if (isArray$1(val)) {
2185
+ result[key] = val.slice();
2186
+ } else {
2187
+ result[key] = val;
2188
+ }
2189
+ }
2190
+ for (var i = 0, l = arguments.length; i < l; i++) {
2191
+ forEach$1(arguments[i], assignValue);
2192
+ }
2193
+ return result;
2194
+ }
2195
+ function extend$1(a, b, thisArg) {
2196
+ forEach$1(b, function assignValue(val, key) {
2197
+ if (thisArg && typeof val === "function") {
2198
+ a[key] = bind$4(val, thisArg);
2199
+ } else {
2200
+ a[key] = val;
2201
+ }
2202
+ });
2203
+ return a;
2204
+ }
2205
+ function stripBOM$1(content) {
2206
+ if (content.charCodeAt(0) === 65279) {
2207
+ content = content.slice(1);
2208
+ }
2209
+ return content;
2210
+ }
2211
+ var utils$r = {
2212
+ isArray: isArray$1,
2213
+ isArrayBuffer: isArrayBuffer$1,
2214
+ isBuffer: isBuffer$1,
2215
+ isFormData: isFormData$1,
2216
+ isArrayBufferView: isArrayBufferView$1,
2217
+ isString: isString$1,
2218
+ isNumber: isNumber$1,
2219
+ isObject: isObject$1,
2220
+ isPlainObject: isPlainObject$1,
2221
+ isUndefined: isUndefined$1,
2222
+ isDate: isDate$1,
2223
+ isFile: isFile$1,
2224
+ isBlob: isBlob$1,
2225
+ isFunction: isFunction$1,
2226
+ isStream: isStream$1,
2227
+ isURLSearchParams: isURLSearchParams$1,
2228
+ isStandardBrowserEnv: isStandardBrowserEnv$1,
2229
+ forEach: forEach$1,
2230
+ merge: merge$1,
2231
+ extend: extend$1,
2232
+ trim: trim$1,
2233
+ stripBOM: stripBOM$1
2234
+ };
2235
+ var utils$q = utils$r;
2236
+ function encode$1(val) {
2237
+ return encodeURIComponent(val).replace(/%3A/gi, ":").replace(/%24/g, "$").replace(/%2C/gi, ",").replace(/%20/g, "+").replace(/%5B/gi, "[").replace(/%5D/gi, "]");
2238
+ }
2239
+ var buildURL$5 = function buildURL2(url, params, paramsSerializer) {
2240
+ if (!params) {
2241
+ return url;
2242
+ }
2243
+ var serializedParams;
2244
+ if (paramsSerializer) {
2245
+ serializedParams = paramsSerializer(params);
2246
+ } else if (utils$q.isURLSearchParams(params)) {
2247
+ serializedParams = params.toString();
2248
+ } else {
2249
+ var parts = [];
2250
+ utils$q.forEach(params, function serialize(val, key) {
2251
+ if (val === null || typeof val === "undefined") {
2252
+ return;
2253
+ }
2254
+ if (utils$q.isArray(val)) {
2255
+ key = key + "[]";
2256
+ } else {
2257
+ val = [val];
2258
+ }
2259
+ utils$q.forEach(val, function parseValue(v) {
2260
+ if (utils$q.isDate(v)) {
2261
+ v = v.toISOString();
2262
+ } else if (utils$q.isObject(v)) {
2263
+ v = JSON.stringify(v);
2264
+ }
2265
+ parts.push(encode$1(key) + "=" + encode$1(v));
2266
+ });
2267
+ });
2268
+ serializedParams = parts.join("&");
2269
+ }
2270
+ if (serializedParams) {
2271
+ var hashmarkIndex = url.indexOf("#");
2272
+ if (hashmarkIndex !== -1) {
2273
+ url = url.slice(0, hashmarkIndex);
2274
+ }
2275
+ url += (url.indexOf("?") === -1 ? "?" : "&") + serializedParams;
2276
+ }
2277
+ return url;
2278
+ };
2279
+ var utils$p = utils$r;
2280
+ function InterceptorManager$3() {
2281
+ this.handlers = [];
2282
+ }
2283
+ InterceptorManager$3.prototype.use = function use2(fulfilled, rejected, options) {
2284
+ this.handlers.push({
2285
+ fulfilled,
2286
+ rejected,
2287
+ synchronous: options ? options.synchronous : false,
2288
+ runWhen: options ? options.runWhen : null
2289
+ });
2290
+ return this.handlers.length - 1;
2291
+ };
2292
+ InterceptorManager$3.prototype.eject = function eject2(id) {
2293
+ if (this.handlers[id]) {
2294
+ this.handlers[id] = null;
2295
+ }
2296
+ };
2297
+ InterceptorManager$3.prototype.forEach = function forEach2(fn) {
2298
+ utils$p.forEach(this.handlers, function forEachHandler(h) {
2299
+ if (h !== null) {
2300
+ fn(h);
2301
+ }
2302
+ });
2303
+ };
2304
+ var InterceptorManager_1$1 = InterceptorManager$3;
2305
+ var utils$o = utils$r;
2306
+ var normalizeHeaderName$3 = function normalizeHeaderName2(headers, normalizedName) {
2307
+ utils$o.forEach(headers, function processHeader(value, name2) {
2308
+ if (name2 !== normalizedName && name2.toUpperCase() === normalizedName.toUpperCase()) {
2309
+ headers[normalizedName] = value;
2310
+ delete headers[name2];
2311
+ }
2312
+ });
2313
+ };
2314
+ var enhanceError$5 = function enhanceError2(error, config, code, request4, response) {
2315
+ error.config = config;
2316
+ if (code) {
2317
+ error.code = code;
2318
+ }
2319
+ error.request = request4;
2320
+ error.response = response;
2321
+ error.isAxiosError = true;
2322
+ error.toJSON = function toJSON() {
2323
+ return {
2324
+ message: this.message,
2325
+ name: this.name,
2326
+ description: this.description,
2327
+ number: this.number,
2328
+ fileName: this.fileName,
2329
+ lineNumber: this.lineNumber,
2330
+ columnNumber: this.columnNumber,
2331
+ stack: this.stack,
2332
+ config: this.config,
2333
+ code: this.code
2334
+ };
2335
+ };
2336
+ return error;
2337
+ };
2338
+ var enhanceError$4 = enhanceError$5;
2339
+ var createError$5 = function createError2(message, config, code, request4, response) {
2340
+ var error = new Error(message);
2341
+ return enhanceError$4(error, config, code, request4, response);
2342
+ };
2343
+ var createError$4 = createError$5;
2344
+ var settle$3 = function settle2(resolve, reject, response) {
2345
+ var validateStatus4 = response.config.validateStatus;
2346
+ if (!response.status || !validateStatus4 || validateStatus4(response.status)) {
2347
+ resolve(response);
2348
+ } else {
2349
+ reject(createError$4("Request failed with status code " + response.status, response.config, null, response.request, response));
2350
+ }
2351
+ };
2352
+ var utils$n = utils$r;
2353
+ var cookies$3 = utils$n.isStandardBrowserEnv() ? function standardBrowserEnv3() {
2354
+ return {
2355
+ write: function write(name2, value, expires, path, domain, secure) {
2356
+ var cookie = [];
2357
+ cookie.push(name2 + "=" + encodeURIComponent(value));
2358
+ if (utils$n.isNumber(expires)) {
2359
+ cookie.push("expires=" + new Date(expires).toGMTString());
2360
+ }
2361
+ if (utils$n.isString(path)) {
2362
+ cookie.push("path=" + path);
2363
+ }
2364
+ if (utils$n.isString(domain)) {
2365
+ cookie.push("domain=" + domain);
2366
+ }
2367
+ if (secure === true) {
2368
+ cookie.push("secure");
2369
+ }
2370
+ document.cookie = cookie.join("; ");
2371
+ },
2372
+ read: function read(name2) {
2373
+ var match = document.cookie.match(new RegExp("(^|;\\s*)(" + name2 + ")=([^;]*)"));
2374
+ return match ? decodeURIComponent(match[3]) : null;
2375
+ },
2376
+ remove: function remove(name2) {
2377
+ this.write(name2, "", Date.now() - 864e5);
2378
+ }
2379
+ };
2380
+ }() : function nonStandardBrowserEnv3() {
2381
+ return {
2382
+ write: function write() {
2383
+ },
2384
+ read: function read() {
2385
+ return null;
2386
+ },
2387
+ remove: function remove() {
2388
+ }
2389
+ };
2390
+ }();
2391
+ var isAbsoluteURL$3 = function isAbsoluteURL2(url) {
2392
+ return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
2393
+ };
2394
+ var combineURLs$3 = function combineURLs2(baseURL, relativeURL) {
2395
+ return relativeURL ? baseURL.replace(/\/+$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
2396
+ };
2397
+ var isAbsoluteURL$2 = isAbsoluteURL$3;
2398
+ var combineURLs$2 = combineURLs$3;
2399
+ var buildFullPath$3 = function buildFullPath2(baseURL, requestedURL) {
2400
+ if (baseURL && !isAbsoluteURL$2(requestedURL)) {
2401
+ return combineURLs$2(baseURL, requestedURL);
2402
+ }
2403
+ return requestedURL;
2404
+ };
2405
+ var utils$m = utils$r;
2406
+ var ignoreDuplicateOf$1 = [
2407
+ "age",
2408
+ "authorization",
2409
+ "content-length",
2410
+ "content-type",
2411
+ "etag",
2412
+ "expires",
2413
+ "from",
2414
+ "host",
2415
+ "if-modified-since",
2416
+ "if-unmodified-since",
2417
+ "last-modified",
2418
+ "location",
2419
+ "max-forwards",
2420
+ "proxy-authorization",
2421
+ "referer",
2422
+ "retry-after",
2423
+ "user-agent"
2424
+ ];
2425
+ var parseHeaders$3 = function parseHeaders2(headers) {
2426
+ var parsed = {};
2427
+ var key;
2428
+ var val;
2429
+ var i;
2430
+ if (!headers) {
2431
+ return parsed;
2432
+ }
2433
+ utils$m.forEach(headers.split("\n"), function parser(line) {
2434
+ i = line.indexOf(":");
2435
+ key = utils$m.trim(line.substr(0, i)).toLowerCase();
2436
+ val = utils$m.trim(line.substr(i + 1));
2437
+ if (key) {
2438
+ if (parsed[key] && ignoreDuplicateOf$1.indexOf(key) >= 0) {
2439
+ return;
2440
+ }
2441
+ if (key === "set-cookie") {
2442
+ parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
2443
+ } else {
2444
+ parsed[key] = parsed[key] ? parsed[key] + ", " + val : val;
2445
+ }
2446
+ }
2447
+ });
2448
+ return parsed;
2449
+ };
2450
+ var utils$l = utils$r;
2451
+ var isURLSameOrigin$3 = utils$l.isStandardBrowserEnv() ? function standardBrowserEnv4() {
2452
+ var msie = /(msie|trident)/i.test(navigator.userAgent);
2453
+ var urlParsingNode = document.createElement("a");
2454
+ var originURL;
2455
+ function resolveURL(url) {
2456
+ var href = url;
2457
+ if (msie) {
2458
+ urlParsingNode.setAttribute("href", href);
2459
+ href = urlParsingNode.href;
2460
+ }
2461
+ urlParsingNode.setAttribute("href", href);
2462
+ return {
2463
+ href: urlParsingNode.href,
2464
+ protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, "") : "",
2465
+ host: urlParsingNode.host,
2466
+ search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, "") : "",
2467
+ hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, "") : "",
2468
+ hostname: urlParsingNode.hostname,
2469
+ port: urlParsingNode.port,
2470
+ pathname: urlParsingNode.pathname.charAt(0) === "/" ? urlParsingNode.pathname : "/" + urlParsingNode.pathname
2471
+ };
2472
+ }
2473
+ originURL = resolveURL(window.location.href);
2474
+ return function isURLSameOrigin2(requestURL) {
2475
+ var parsed = utils$l.isString(requestURL) ? resolveURL(requestURL) : requestURL;
2476
+ return parsed.protocol === originURL.protocol && parsed.host === originURL.host;
2477
+ };
2478
+ }() : function nonStandardBrowserEnv4() {
2479
+ return function isURLSameOrigin2() {
2480
+ return true;
2481
+ };
2482
+ }();
2483
+ var utils$k = utils$r;
2484
+ var settle$2 = settle$3;
2485
+ var cookies$2 = cookies$3;
2486
+ var buildURL$4 = buildURL$5;
2487
+ var buildFullPath$2 = buildFullPath$3;
2488
+ var parseHeaders$2 = parseHeaders$3;
2489
+ var isURLSameOrigin$2 = isURLSameOrigin$3;
2490
+ var createError$3 = createError$5;
2491
+ var xhr$1 = function xhrAdapter2(config) {
2492
+ return new Promise(function dispatchXhrRequest(resolve, reject) {
2493
+ var requestData = config.data;
2494
+ var requestHeaders = config.headers;
2495
+ var responseType = config.responseType;
2496
+ if (utils$k.isFormData(requestData)) {
2497
+ delete requestHeaders["Content-Type"];
2498
+ }
2499
+ var request4 = new XMLHttpRequest();
2500
+ if (config.auth) {
2501
+ var username = config.auth.username || "";
2502
+ var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : "";
2503
+ requestHeaders.Authorization = "Basic " + btoa(username + ":" + password);
2504
+ }
2505
+ var fullPath = buildFullPath$2(config.baseURL, config.url);
2506
+ request4.open(config.method.toUpperCase(), buildURL$4(fullPath, config.params, config.paramsSerializer), true);
2507
+ request4.timeout = config.timeout;
2508
+ function onloadend() {
2509
+ if (!request4) {
2510
+ return;
2511
+ }
2512
+ var responseHeaders = "getAllResponseHeaders" in request4 ? parseHeaders$2(request4.getAllResponseHeaders()) : null;
2513
+ var responseData = !responseType || responseType === "text" || responseType === "json" ? request4.responseText : request4.response;
2514
+ var response = {
2515
+ data: responseData,
2516
+ status: request4.status,
2517
+ statusText: request4.statusText,
2518
+ headers: responseHeaders,
2519
+ config,
2520
+ request: request4
2521
+ };
2522
+ settle$2(resolve, reject, response);
2523
+ request4 = null;
2524
+ }
2525
+ if ("onloadend" in request4) {
2526
+ request4.onloadend = onloadend;
2527
+ } else {
2528
+ request4.onreadystatechange = function handleLoad() {
2529
+ if (!request4 || request4.readyState !== 4) {
2530
+ return;
2531
+ }
2532
+ if (request4.status === 0 && !(request4.responseURL && request4.responseURL.indexOf("file:") === 0)) {
2533
+ return;
2534
+ }
2535
+ setTimeout(onloadend);
2536
+ };
2537
+ }
2538
+ request4.onabort = function handleAbort() {
2539
+ if (!request4) {
2540
+ return;
2541
+ }
2542
+ reject(createError$3("Request aborted", config, "ECONNABORTED", request4));
2543
+ request4 = null;
2544
+ };
2545
+ request4.onerror = function handleError() {
2546
+ reject(createError$3("Network Error", config, null, request4));
2547
+ request4 = null;
2548
+ };
2549
+ request4.ontimeout = function handleTimeout() {
2550
+ var timeoutErrorMessage = "timeout of " + config.timeout + "ms exceeded";
2551
+ if (config.timeoutErrorMessage) {
2552
+ timeoutErrorMessage = config.timeoutErrorMessage;
2553
+ }
2554
+ reject(createError$3(timeoutErrorMessage, config, config.transitional && config.transitional.clarifyTimeoutError ? "ETIMEDOUT" : "ECONNABORTED", request4));
2555
+ request4 = null;
2556
+ };
2557
+ if (utils$k.isStandardBrowserEnv()) {
2558
+ var xsrfValue = (config.withCredentials || isURLSameOrigin$2(fullPath)) && config.xsrfCookieName ? cookies$2.read(config.xsrfCookieName) : void 0;
2559
+ if (xsrfValue) {
2560
+ requestHeaders[config.xsrfHeaderName] = xsrfValue;
2561
+ }
2562
+ }
2563
+ if ("setRequestHeader" in request4) {
2564
+ utils$k.forEach(requestHeaders, function setRequestHeader(val, key) {
2565
+ if (typeof requestData === "undefined" && key.toLowerCase() === "content-type") {
2566
+ delete requestHeaders[key];
2567
+ } else {
2568
+ request4.setRequestHeader(key, val);
2569
+ }
2570
+ });
2571
+ }
2572
+ if (!utils$k.isUndefined(config.withCredentials)) {
2573
+ request4.withCredentials = !!config.withCredentials;
2574
+ }
2575
+ if (responseType && responseType !== "json") {
2576
+ request4.responseType = config.responseType;
2577
+ }
2578
+ if (typeof config.onDownloadProgress === "function") {
2579
+ request4.addEventListener("progress", config.onDownloadProgress);
2580
+ }
2581
+ if (typeof config.onUploadProgress === "function" && request4.upload) {
2582
+ request4.upload.addEventListener("progress", config.onUploadProgress);
2583
+ }
2584
+ if (config.cancelToken) {
2585
+ config.cancelToken.promise.then(function onCanceled(cancel) {
2586
+ if (!request4) {
2587
+ return;
2588
+ }
2589
+ request4.abort();
2590
+ reject(cancel);
2591
+ request4 = null;
2592
+ });
2593
+ }
2594
+ if (!requestData) {
2595
+ requestData = null;
2596
+ }
2597
+ request4.send(requestData);
2598
+ });
2599
+ };
2600
+ var utils$j = utils$r;
2601
+ var normalizeHeaderName$2 = normalizeHeaderName$3;
2602
+ var enhanceError$3 = enhanceError$5;
2603
+ var DEFAULT_CONTENT_TYPE$1 = {
2604
+ "Content-Type": "application/x-www-form-urlencoded"
2605
+ };
2606
+ function setContentTypeIfUnset$1(headers, value) {
2607
+ if (!utils$j.isUndefined(headers) && utils$j.isUndefined(headers["Content-Type"])) {
2608
+ headers["Content-Type"] = value;
2609
+ }
2610
+ }
2611
+ function getDefaultAdapter$1() {
2612
+ var adapter;
2613
+ if (typeof XMLHttpRequest !== "undefined") {
2614
+ adapter = xhr$1;
2615
+ } else if (typeof process !== "undefined" && Object.prototype.toString.call(process) === "[object process]") {
2616
+ adapter = xhr$1;
2617
+ }
2618
+ return adapter;
2619
+ }
2620
+ function stringifySafely$1(rawValue, parser, encoder) {
2621
+ if (utils$j.isString(rawValue)) {
2622
+ try {
2623
+ (parser || JSON.parse)(rawValue);
2624
+ return utils$j.trim(rawValue);
2625
+ } catch (e) {
2626
+ if (e.name !== "SyntaxError") {
2627
+ throw e;
2628
+ }
2629
+ }
2630
+ }
2631
+ return (encoder || JSON.stringify)(rawValue);
2632
+ }
2633
+ var defaults$8 = {
2634
+ transitional: {
2635
+ silentJSONParsing: true,
2636
+ forcedJSONParsing: true,
2637
+ clarifyTimeoutError: false
2638
+ },
2639
+ adapter: getDefaultAdapter$1(),
2640
+ transformRequest: [function transformRequest2(data2, headers) {
2641
+ normalizeHeaderName$2(headers, "Accept");
2642
+ normalizeHeaderName$2(headers, "Content-Type");
2643
+ if (utils$j.isFormData(data2) || utils$j.isArrayBuffer(data2) || utils$j.isBuffer(data2) || utils$j.isStream(data2) || utils$j.isFile(data2) || utils$j.isBlob(data2)) {
2644
+ return data2;
2645
+ }
2646
+ if (utils$j.isArrayBufferView(data2)) {
2647
+ return data2.buffer;
2648
+ }
2649
+ if (utils$j.isURLSearchParams(data2)) {
2650
+ setContentTypeIfUnset$1(headers, "application/x-www-form-urlencoded;charset=utf-8");
2651
+ return data2.toString();
2652
+ }
2653
+ if (utils$j.isObject(data2) || headers && headers["Content-Type"] === "application/json") {
2654
+ setContentTypeIfUnset$1(headers, "application/json");
2655
+ return stringifySafely$1(data2);
2656
+ }
2657
+ return data2;
2658
+ }],
2659
+ transformResponse: [function transformResponse2(data2) {
2660
+ var transitional4 = this.transitional;
2661
+ var silentJSONParsing = transitional4 && transitional4.silentJSONParsing;
2662
+ var forcedJSONParsing = transitional4 && transitional4.forcedJSONParsing;
2663
+ var strictJSONParsing = !silentJSONParsing && this.responseType === "json";
2664
+ if (strictJSONParsing || forcedJSONParsing && utils$j.isString(data2) && data2.length) {
2665
+ try {
2666
+ return JSON.parse(data2);
2667
+ } catch (e) {
2668
+ if (strictJSONParsing) {
2669
+ if (e.name === "SyntaxError") {
2670
+ throw enhanceError$3(e, this, "E_JSON_PARSE");
2671
+ }
2672
+ throw e;
2673
+ }
2674
+ }
2675
+ }
2676
+ return data2;
2677
+ }],
2678
+ timeout: 0,
2679
+ xsrfCookieName: "XSRF-TOKEN",
2680
+ xsrfHeaderName: "X-XSRF-TOKEN",
2681
+ maxContentLength: -1,
2682
+ maxBodyLength: -1,
2683
+ validateStatus: function validateStatus2(status) {
2684
+ return status >= 200 && status < 300;
2685
+ }
2686
+ };
2687
+ defaults$8.headers = {
2688
+ common: {
2689
+ "Accept": "application/json, text/plain, */*"
2690
+ }
2691
+ };
2692
+ utils$j.forEach(["delete", "get", "head"], function forEachMethodNoData3(method) {
2693
+ defaults$8.headers[method] = {};
2694
+ });
2695
+ utils$j.forEach(["post", "put", "patch"], function forEachMethodWithData3(method) {
2696
+ defaults$8.headers[method] = utils$j.merge(DEFAULT_CONTENT_TYPE$1);
2697
+ });
2698
+ var defaults_1$1 = defaults$8;
2699
+ var utils$i = utils$r;
2700
+ var defaults$7 = defaults_1$1;
2701
+ var transformData$3 = function transformData2(data2, headers, fns) {
2702
+ var context = this || defaults$7;
2703
+ utils$i.forEach(fns, function transform(fn) {
2704
+ data2 = fn.call(context, data2, headers);
2705
+ });
2706
+ return data2;
2707
+ };
2708
+ var isCancel$3 = function isCancel2(value) {
2709
+ return !!(value && value.__CANCEL__);
2710
+ };
2711
+ var utils$h = utils$r;
2712
+ var transformData$2 = transformData$3;
2713
+ var isCancel$2 = isCancel$3;
2714
+ var defaults$6 = defaults_1$1;
2715
+ function throwIfCancellationRequested$1(config) {
2716
+ if (config.cancelToken) {
2717
+ config.cancelToken.throwIfRequested();
2718
+ }
2719
+ }
2720
+ var dispatchRequest$3 = function dispatchRequest2(config) {
2721
+ throwIfCancellationRequested$1(config);
2722
+ config.headers = config.headers || {};
2723
+ config.data = transformData$2.call(config, config.data, config.headers, config.transformRequest);
2724
+ config.headers = utils$h.merge(config.headers.common || {}, config.headers[config.method] || {}, config.headers);
2725
+ utils$h.forEach(["delete", "get", "head", "post", "put", "patch", "common"], function cleanHeaderConfig(method) {
2726
+ delete config.headers[method];
2727
+ });
2728
+ var adapter = config.adapter || defaults$6.adapter;
2729
+ return adapter(config).then(function onAdapterResolution(response) {
2730
+ throwIfCancellationRequested$1(config);
2731
+ response.data = transformData$2.call(config, response.data, response.headers, config.transformResponse);
2732
+ return response;
2733
+ }, function onAdapterRejection(reason) {
2734
+ if (!isCancel$2(reason)) {
2735
+ throwIfCancellationRequested$1(config);
2736
+ if (reason && reason.response) {
2737
+ reason.response.data = transformData$2.call(config, reason.response.data, reason.response.headers, config.transformResponse);
2738
+ }
2739
+ }
2740
+ return Promise.reject(reason);
2741
+ });
2742
+ };
2743
+ var utils$g = utils$r;
2744
+ var mergeConfig$5 = function mergeConfig2(config1, config2) {
2745
+ config2 = config2 || {};
2746
+ var config = {};
2747
+ var valueFromConfig2Keys = ["url", "method", "data"];
2748
+ var mergeDeepPropertiesKeys = ["headers", "auth", "proxy", "params"];
2749
+ var defaultToConfig2Keys = [
2750
+ "baseURL",
2751
+ "transformRequest",
2752
+ "transformResponse",
2753
+ "paramsSerializer",
2754
+ "timeout",
2755
+ "timeoutMessage",
2756
+ "withCredentials",
2757
+ "adapter",
2758
+ "responseType",
2759
+ "xsrfCookieName",
2760
+ "xsrfHeaderName",
2761
+ "onUploadProgress",
2762
+ "onDownloadProgress",
2763
+ "decompress",
2764
+ "maxContentLength",
2765
+ "maxBodyLength",
2766
+ "maxRedirects",
2767
+ "transport",
2768
+ "httpAgent",
2769
+ "httpsAgent",
2770
+ "cancelToken",
2771
+ "socketPath",
2772
+ "responseEncoding"
2773
+ ];
2774
+ var directMergeKeys = ["validateStatus"];
2775
+ function getMergedValue(target, source4) {
2776
+ if (utils$g.isPlainObject(target) && utils$g.isPlainObject(source4)) {
2777
+ return utils$g.merge(target, source4);
2778
+ } else if (utils$g.isPlainObject(source4)) {
2779
+ return utils$g.merge({}, source4);
2780
+ } else if (utils$g.isArray(source4)) {
2781
+ return source4.slice();
2782
+ }
2783
+ return source4;
2784
+ }
2785
+ function mergeDeepProperties(prop) {
2786
+ if (!utils$g.isUndefined(config2[prop])) {
2787
+ config[prop] = getMergedValue(config1[prop], config2[prop]);
2788
+ } else if (!utils$g.isUndefined(config1[prop])) {
2789
+ config[prop] = getMergedValue(void 0, config1[prop]);
2790
+ }
2791
+ }
2792
+ utils$g.forEach(valueFromConfig2Keys, function valueFromConfig2(prop) {
2793
+ if (!utils$g.isUndefined(config2[prop])) {
2794
+ config[prop] = getMergedValue(void 0, config2[prop]);
2795
+ }
2796
+ });
2797
+ utils$g.forEach(mergeDeepPropertiesKeys, mergeDeepProperties);
2798
+ utils$g.forEach(defaultToConfig2Keys, function defaultToConfig2(prop) {
2799
+ if (!utils$g.isUndefined(config2[prop])) {
2800
+ config[prop] = getMergedValue(void 0, config2[prop]);
2801
+ } else if (!utils$g.isUndefined(config1[prop])) {
2802
+ config[prop] = getMergedValue(void 0, config1[prop]);
2803
+ }
2804
+ });
2805
+ utils$g.forEach(directMergeKeys, function merge2(prop) {
2806
+ if (prop in config2) {
2807
+ config[prop] = getMergedValue(config1[prop], config2[prop]);
2808
+ } else if (prop in config1) {
2809
+ config[prop] = getMergedValue(void 0, config1[prop]);
2810
+ }
2811
+ });
2812
+ var axiosKeys = valueFromConfig2Keys.concat(mergeDeepPropertiesKeys).concat(defaultToConfig2Keys).concat(directMergeKeys);
2813
+ var otherKeys = Object.keys(config1).concat(Object.keys(config2)).filter(function filterAxiosKeys(key) {
2814
+ return axiosKeys.indexOf(key) === -1;
2815
+ });
2816
+ utils$g.forEach(otherKeys, mergeDeepProperties);
2817
+ return config;
2818
+ };
2819
+ const name = "axios";
2820
+ const version = "0.21.4";
2821
+ const description = "Promise based HTTP client for the browser and node.js";
2822
+ const main = "index.js";
2823
+ const scripts = {
2824
+ test: "grunt test",
2825
+ start: "node ./sandbox/server.js",
2826
+ build: "NODE_ENV=production grunt build",
2827
+ preversion: "npm test",
2828
+ version: "npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json",
2829
+ postversion: "git push && git push --tags",
2830
+ examples: "node ./examples/server.js",
2831
+ coveralls: "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
2832
+ fix: "eslint --fix lib/**/*.js"
2833
+ };
2834
+ const repository = {
2835
+ type: "git",
2836
+ url: "https://github.com/axios/axios.git"
2837
+ };
2838
+ const keywords = [
2839
+ "xhr",
2840
+ "http",
2841
+ "ajax",
2842
+ "promise",
2843
+ "node"
2844
+ ];
2845
+ const author = "Matt Zabriskie";
2846
+ const license = "MIT";
2847
+ const bugs = {
2848
+ url: "https://github.com/axios/axios/issues"
2849
+ };
2850
+ const homepage = "https://axios-http.com";
2851
+ const devDependencies = {
2852
+ coveralls: "^3.0.0",
2853
+ "es6-promise": "^4.2.4",
2854
+ grunt: "^1.3.0",
2855
+ "grunt-banner": "^0.6.0",
2856
+ "grunt-cli": "^1.2.0",
2857
+ "grunt-contrib-clean": "^1.1.0",
2858
+ "grunt-contrib-watch": "^1.0.0",
2859
+ "grunt-eslint": "^23.0.0",
2860
+ "grunt-karma": "^4.0.0",
2861
+ "grunt-mocha-test": "^0.13.3",
2862
+ "grunt-ts": "^6.0.0-beta.19",
2863
+ "grunt-webpack": "^4.0.2",
2864
+ "istanbul-instrumenter-loader": "^1.0.0",
2865
+ "jasmine-core": "^2.4.1",
2866
+ karma: "^6.3.2",
2867
+ "karma-chrome-launcher": "^3.1.0",
2868
+ "karma-firefox-launcher": "^2.1.0",
2869
+ "karma-jasmine": "^1.1.1",
2870
+ "karma-jasmine-ajax": "^0.1.13",
2871
+ "karma-safari-launcher": "^1.0.0",
2872
+ "karma-sauce-launcher": "^4.3.6",
2873
+ "karma-sinon": "^1.0.5",
2874
+ "karma-sourcemap-loader": "^0.3.8",
2875
+ "karma-webpack": "^4.0.2",
2876
+ "load-grunt-tasks": "^3.5.2",
2877
+ minimist: "^1.2.0",
2878
+ mocha: "^8.2.1",
2879
+ sinon: "^4.5.0",
2880
+ "terser-webpack-plugin": "^4.2.3",
2881
+ typescript: "^4.0.5",
2882
+ "url-search-params": "^0.10.0",
2883
+ webpack: "^4.44.2",
2884
+ "webpack-dev-server": "^3.11.0"
2885
+ };
2886
+ const browser = {
2887
+ "./lib/adapters/http.js": "./lib/adapters/xhr.js"
2888
+ };
2889
+ const jsdelivr = "dist/axios.min.js";
2890
+ const unpkg = "dist/axios.min.js";
2891
+ const typings = "./index.d.ts";
2892
+ const dependencies = {
2893
+ "follow-redirects": "^1.14.0"
2894
+ };
2895
+ const bundlesize = [
2896
+ {
2897
+ path: "./dist/axios.min.js",
2898
+ threshold: "5kB"
2899
+ }
2900
+ ];
2901
+ var require$$0 = {
2902
+ name,
2903
+ version,
2904
+ description,
2905
+ main,
2906
+ scripts,
2907
+ repository,
2908
+ keywords,
2909
+ author,
2910
+ license,
2911
+ bugs,
2912
+ homepage,
2913
+ devDependencies,
2914
+ browser,
2915
+ jsdelivr,
2916
+ unpkg,
2917
+ typings,
2918
+ dependencies,
2919
+ bundlesize
2920
+ };
2921
+ var pkg = require$$0;
2922
+ var validators$3 = {};
2923
+ ["object", "boolean", "number", "function", "string", "symbol"].forEach(function(type, i) {
2924
+ validators$3[type] = function validator2(thing) {
2925
+ return typeof thing === type || "a" + (i < 1 ? "n " : " ") + type;
2926
+ };
2927
+ });
2928
+ var deprecatedWarnings$1 = {};
2929
+ var currentVerArr = pkg.version.split(".");
2930
+ function isOlderVersion(version2, thanVersion) {
2931
+ var pkgVersionArr = thanVersion ? thanVersion.split(".") : currentVerArr;
2932
+ var destVer = version2.split(".");
2933
+ for (var i = 0; i < 3; i++) {
2934
+ if (pkgVersionArr[i] > destVer[i]) {
2935
+ return true;
2936
+ } else if (pkgVersionArr[i] < destVer[i]) {
2937
+ return false;
2938
+ }
2939
+ }
2940
+ return false;
2941
+ }
2942
+ validators$3.transitional = function transitional2(validator2, version2, message) {
2943
+ var isDeprecated = version2 && isOlderVersion(version2);
2944
+ function formatMessage(opt, desc) {
2945
+ return "[Axios v" + pkg.version + "] Transitional option '" + opt + "'" + desc + (message ? ". " + message : "");
2946
+ }
2947
+ return function(value, opt, opts) {
2948
+ if (validator2 === false) {
2949
+ throw new Error(formatMessage(opt, " has been removed in " + version2));
2950
+ }
2951
+ if (isDeprecated && !deprecatedWarnings$1[opt]) {
2952
+ deprecatedWarnings$1[opt] = true;
2953
+ console.warn(formatMessage(opt, " has been deprecated since v" + version2 + " and will be removed in the near future"));
2954
+ }
2955
+ return validator2 ? validator2(value, opt, opts) : true;
2956
+ };
2957
+ };
2958
+ function assertOptions$1(options, schema, allowUnknown) {
2959
+ if (typeof options !== "object") {
2960
+ throw new TypeError("options must be an object");
2961
+ }
2962
+ var keys = Object.keys(options);
2963
+ var i = keys.length;
2964
+ while (i-- > 0) {
2965
+ var opt = keys[i];
2966
+ var validator2 = schema[opt];
2967
+ if (validator2) {
2968
+ var value = options[opt];
2969
+ var result = value === void 0 || validator2(value, opt, options);
2970
+ if (result !== true) {
2971
+ throw new TypeError("option " + opt + " must be " + result);
2972
+ }
2973
+ continue;
2974
+ }
2975
+ if (allowUnknown !== true) {
2976
+ throw Error("Unknown option " + opt);
2977
+ }
2978
+ }
2979
+ }
2980
+ var validator$3 = {
2981
+ isOlderVersion,
2982
+ assertOptions: assertOptions$1,
2983
+ validators: validators$3
2984
+ };
2985
+ var utils$f = utils$r;
2986
+ var buildURL$3 = buildURL$5;
2987
+ var InterceptorManager$2 = InterceptorManager_1$1;
2988
+ var dispatchRequest$2 = dispatchRequest$3;
2989
+ var mergeConfig$4 = mergeConfig$5;
2990
+ var validator$2 = validator$3;
2991
+ var validators$2 = validator$2.validators;
2992
+ function Axios$3(instanceConfig) {
2993
+ this.defaults = instanceConfig;
2994
+ this.interceptors = {
2995
+ request: new InterceptorManager$2(),
2996
+ response: new InterceptorManager$2()
2997
+ };
2998
+ }
2999
+ Axios$3.prototype.request = function request2(config) {
3000
+ if (typeof config === "string") {
3001
+ config = arguments[1] || {};
3002
+ config.url = arguments[0];
3003
+ } else {
3004
+ config = config || {};
3005
+ }
3006
+ config = mergeConfig$4(this.defaults, config);
3007
+ if (config.method) {
3008
+ config.method = config.method.toLowerCase();
3009
+ } else if (this.defaults.method) {
3010
+ config.method = this.defaults.method.toLowerCase();
3011
+ } else {
3012
+ config.method = "get";
3013
+ }
3014
+ var transitional4 = config.transitional;
3015
+ if (transitional4 !== void 0) {
3016
+ validator$2.assertOptions(transitional4, {
3017
+ silentJSONParsing: validators$2.transitional(validators$2.boolean, "1.0.0"),
3018
+ forcedJSONParsing: validators$2.transitional(validators$2.boolean, "1.0.0"),
3019
+ clarifyTimeoutError: validators$2.transitional(validators$2.boolean, "1.0.0")
3020
+ }, false);
3021
+ }
3022
+ var requestInterceptorChain = [];
3023
+ var synchronousRequestInterceptors = true;
3024
+ this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
3025
+ if (typeof interceptor.runWhen === "function" && interceptor.runWhen(config) === false) {
3026
+ return;
3027
+ }
3028
+ synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
3029
+ requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
3030
+ });
3031
+ var responseInterceptorChain = [];
3032
+ this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
3033
+ responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
3034
+ });
3035
+ var promise;
3036
+ if (!synchronousRequestInterceptors) {
3037
+ var chain = [dispatchRequest$2, void 0];
3038
+ Array.prototype.unshift.apply(chain, requestInterceptorChain);
3039
+ chain = chain.concat(responseInterceptorChain);
3040
+ promise = Promise.resolve(config);
3041
+ while (chain.length) {
3042
+ promise = promise.then(chain.shift(), chain.shift());
3043
+ }
3044
+ return promise;
3045
+ }
3046
+ var newConfig = config;
3047
+ while (requestInterceptorChain.length) {
3048
+ var onFulfilled = requestInterceptorChain.shift();
3049
+ var onRejected = requestInterceptorChain.shift();
3050
+ try {
3051
+ newConfig = onFulfilled(newConfig);
3052
+ } catch (error) {
3053
+ onRejected(error);
3054
+ break;
3055
+ }
3056
+ }
3057
+ try {
3058
+ promise = dispatchRequest$2(newConfig);
3059
+ } catch (error) {
3060
+ return Promise.reject(error);
3061
+ }
3062
+ while (responseInterceptorChain.length) {
3063
+ promise = promise.then(responseInterceptorChain.shift(), responseInterceptorChain.shift());
3064
+ }
3065
+ return promise;
3066
+ };
3067
+ Axios$3.prototype.getUri = function getUri2(config) {
3068
+ config = mergeConfig$4(this.defaults, config);
3069
+ return buildURL$3(config.url, config.params, config.paramsSerializer).replace(/^\?/, "");
3070
+ };
3071
+ utils$f.forEach(["delete", "get", "head", "options"], function forEachMethodNoData4(method) {
3072
+ Axios$3.prototype[method] = function(url, config) {
3073
+ return this.request(mergeConfig$4(config || {}, {
3074
+ method,
3075
+ url,
3076
+ data: (config || {}).data
3077
+ }));
3078
+ };
3079
+ });
3080
+ utils$f.forEach(["post", "put", "patch"], function forEachMethodWithData4(method) {
3081
+ Axios$3.prototype[method] = function(url, data2, config) {
3082
+ return this.request(mergeConfig$4(config || {}, {
3083
+ method,
3084
+ url,
3085
+ data: data2
3086
+ }));
3087
+ };
3088
+ });
3089
+ var Axios_1$1 = Axios$3;
3090
+ function Cancel$5(message) {
3091
+ this.message = message;
3092
+ }
3093
+ Cancel$5.prototype.toString = function toString2() {
3094
+ return "Cancel" + (this.message ? ": " + this.message : "");
3095
+ };
3096
+ Cancel$5.prototype.__CANCEL__ = true;
3097
+ var Cancel_1$1 = Cancel$5;
3098
+ var Cancel$4 = Cancel_1$1;
3099
+ function CancelToken$1(executor) {
3100
+ if (typeof executor !== "function") {
3101
+ throw new TypeError("executor must be a function.");
3102
+ }
3103
+ var resolvePromise;
3104
+ this.promise = new Promise(function promiseExecutor(resolve) {
3105
+ resolvePromise = resolve;
3106
+ });
3107
+ var token2 = this;
3108
+ executor(function cancel(message) {
3109
+ if (token2.reason) {
3110
+ return;
3111
+ }
3112
+ token2.reason = new Cancel$4(message);
3113
+ resolvePromise(token2.reason);
3114
+ });
3115
+ }
3116
+ CancelToken$1.prototype.throwIfRequested = function throwIfRequested2() {
3117
+ if (this.reason) {
3118
+ throw this.reason;
3119
+ }
3120
+ };
3121
+ CancelToken$1.source = function source2() {
3122
+ var cancel;
3123
+ var token2 = new CancelToken$1(function executor(c) {
3124
+ cancel = c;
3125
+ });
3126
+ return {
3127
+ token: token2,
3128
+ cancel
3129
+ };
3130
+ };
3131
+ var CancelToken_1$1 = CancelToken$1;
3132
+ var spread$1 = function spread2(callback) {
3133
+ return function wrap(arr) {
3134
+ return callback.apply(null, arr);
3135
+ };
3136
+ };
3137
+ var isAxiosError$1 = function isAxiosError2(payload) {
3138
+ return typeof payload === "object" && payload.isAxiosError === true;
3139
+ };
3140
+ var utils$e = utils$r;
3141
+ var bind$3 = bind$5;
3142
+ var Axios$2 = Axios_1$1;
3143
+ var mergeConfig$3 = mergeConfig$5;
3144
+ var defaults$5 = defaults_1$1;
3145
+ function createInstance$1(defaultConfig) {
3146
+ var context = new Axios$2(defaultConfig);
3147
+ var instance = bind$3(Axios$2.prototype.request, context);
3148
+ utils$e.extend(instance, Axios$2.prototype, context);
3149
+ utils$e.extend(instance, context);
3150
+ return instance;
3151
+ }
3152
+ var axios$4 = createInstance$1(defaults$5);
3153
+ axios$4.Axios = Axios$2;
3154
+ axios$4.create = function create(instanceConfig) {
3155
+ return createInstance$1(mergeConfig$3(axios$4.defaults, instanceConfig));
3156
+ };
3157
+ axios$4.Cancel = Cancel_1$1;
3158
+ axios$4.CancelToken = CancelToken_1$1;
3159
+ axios$4.isCancel = isCancel$3;
3160
+ axios$4.all = function all2(promises) {
3161
+ return Promise.all(promises);
3162
+ };
3163
+ axios$4.spread = spread$1;
3164
+ axios$4.isAxiosError = isAxiosError$1;
3165
+ axios$5.exports = axios$4;
3166
+ axios$5.exports.default = axios$4;
3167
+ var axios$3 = axios$5.exports;
3168
+ class HasuraStorageApi {
3169
+ constructor({ url }) {
3170
+ this.url = url;
3171
+ this.httpClient = axios$3.create({
3172
+ baseURL: this.url
3173
+ });
3174
+ }
3175
+ async upload(params) {
3176
+ try {
3177
+ const res = await this.httpClient.post("/files", params.file, {
3178
+ headers: __spreadValues(__spreadValues({}, this.generateUploadHeaders(params)), this.generateAuthHeaders())
3179
+ });
3180
+ return { fileMetadata: res.data, error: null };
3181
+ } catch (error) {
3182
+ return { fileMetadata: null, error };
3183
+ }
3184
+ }
3185
+ async getPresignedUrl(params) {
3186
+ try {
3187
+ const { fileId } = params;
3188
+ const res = await this.httpClient.get(`/files/${fileId}/presignedurl`, {
3189
+ headers: __spreadValues({}, this.generateAuthHeaders())
3190
+ });
3191
+ return { presignedUrl: res.data, error: null };
3192
+ } catch (error) {
3193
+ return { presignedUrl: null, error };
3194
+ }
3195
+ }
3196
+ async delete(params) {
3197
+ try {
3198
+ const { fileId } = params;
3199
+ await this.httpClient.delete(`/files/${fileId}`, {
3200
+ headers: __spreadValues({}, this.generateAuthHeaders())
3201
+ });
3202
+ return { error: null };
3203
+ } catch (error) {
3204
+ return { error };
3205
+ }
3206
+ }
3207
+ setAccessToken(accessToken) {
3208
+ this.accessToken = accessToken;
3209
+ }
3210
+ generateUploadHeaders(params) {
3211
+ const { bucketId, name: name2, id } = params;
3212
+ const uploadheaders = {};
3213
+ if (bucketId) {
3214
+ uploadheaders["x-nhost-bucket-id"] = bucketId;
3215
+ }
3216
+ if (id) {
3217
+ uploadheaders["x-nhost-file-id"] = id;
3218
+ }
3219
+ if (name2) {
3220
+ uploadheaders["x-nhost-file-name"] = name2;
3221
+ }
3222
+ return uploadheaders;
3223
+ }
3224
+ generateAuthHeaders() {
3225
+ if (!this.accessToken) {
3226
+ return null;
3227
+ }
3228
+ return {
3229
+ Authorization: `Bearer ${this.accessToken}`
3230
+ };
3231
+ }
3232
+ }
3233
+ class HasuraStorageClient {
3234
+ constructor({ url }) {
3235
+ this.url = url;
3236
+ this.api = new HasuraStorageApi({ url });
3237
+ }
3238
+ async upload(params) {
3239
+ const file = new FormData();
3240
+ file.append("file", params.file);
3241
+ const { fileMetadata, error } = await this.api.upload(__spreadProps(__spreadValues({}, params), {
3242
+ file
3243
+ }));
3244
+ if (error) {
3245
+ return { fileMetadata: null, error };
3246
+ }
3247
+ if (!fileMetadata) {
3248
+ return { fileMetadata: null, error: new Error("Invalid file returned") };
3249
+ }
3250
+ return { fileMetadata, error: null };
3251
+ }
3252
+ getUrl(params) {
3253
+ const { fileId } = params;
3254
+ return `${this.url}/files/${fileId}`;
3255
+ }
3256
+ async getPresignedUrl(params) {
3257
+ const { presignedUrl, error } = await this.api.getPresignedUrl(params);
3258
+ if (error) {
3259
+ return { presignedUrl: null, error };
3260
+ }
3261
+ if (!presignedUrl) {
3262
+ return { presignedUrl: null, error: new Error("Invalid file id") };
3263
+ }
3264
+ return { presignedUrl, error: null };
3265
+ }
3266
+ async delete(params) {
3267
+ const { error } = await this.api.delete(params);
3268
+ if (error) {
3269
+ return { error };
3270
+ }
3271
+ return { error: null };
3272
+ }
3273
+ setAccessToken(accessToken) {
3274
+ this.api.setAccessToken(accessToken);
3275
+ }
3276
+ }
3277
+ var axios$2 = { exports: {} };
3278
+ var bind$2 = function bind3(fn, thisArg) {
3279
+ return function wrap() {
3280
+ var args = new Array(arguments.length);
3281
+ for (var i = 0; i < args.length; i++) {
3282
+ args[i] = arguments[i];
3283
+ }
3284
+ return fn.apply(thisArg, args);
3285
+ };
3286
+ };
3287
+ var bind$1 = bind$2;
3288
+ var toString3 = Object.prototype.toString;
3289
+ function isArray(val) {
3290
+ return toString3.call(val) === "[object Array]";
3291
+ }
3292
+ function isUndefined(val) {
3293
+ return typeof val === "undefined";
3294
+ }
3295
+ function isBuffer(val) {
3296
+ return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor) && typeof val.constructor.isBuffer === "function" && val.constructor.isBuffer(val);
3297
+ }
3298
+ function isArrayBuffer(val) {
3299
+ return toString3.call(val) === "[object ArrayBuffer]";
3300
+ }
3301
+ function isFormData(val) {
3302
+ return typeof FormData !== "undefined" && val instanceof FormData;
3303
+ }
3304
+ function isArrayBufferView(val) {
3305
+ var result;
3306
+ if (typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView) {
3307
+ result = ArrayBuffer.isView(val);
3308
+ } else {
3309
+ result = val && val.buffer && val.buffer instanceof ArrayBuffer;
3310
+ }
3311
+ return result;
3312
+ }
3313
+ function isString(val) {
3314
+ return typeof val === "string";
3315
+ }
3316
+ function isNumber(val) {
3317
+ return typeof val === "number";
3318
+ }
3319
+ function isObject(val) {
3320
+ return val !== null && typeof val === "object";
3321
+ }
3322
+ function isPlainObject(val) {
3323
+ if (toString3.call(val) !== "[object Object]") {
3324
+ return false;
3325
+ }
3326
+ var prototype = Object.getPrototypeOf(val);
3327
+ return prototype === null || prototype === Object.prototype;
3328
+ }
3329
+ function isDate(val) {
3330
+ return toString3.call(val) === "[object Date]";
3331
+ }
3332
+ function isFile(val) {
3333
+ return toString3.call(val) === "[object File]";
3334
+ }
3335
+ function isBlob(val) {
3336
+ return toString3.call(val) === "[object Blob]";
3337
+ }
3338
+ function isFunction(val) {
3339
+ return toString3.call(val) === "[object Function]";
3340
+ }
3341
+ function isStream(val) {
3342
+ return isObject(val) && isFunction(val.pipe);
3343
+ }
3344
+ function isURLSearchParams(val) {
3345
+ return typeof URLSearchParams !== "undefined" && val instanceof URLSearchParams;
3346
+ }
3347
+ function trim(str) {
3348
+ return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, "");
3349
+ }
3350
+ function isStandardBrowserEnv() {
3351
+ if (typeof navigator !== "undefined" && (navigator.product === "ReactNative" || navigator.product === "NativeScript" || navigator.product === "NS")) {
3352
+ return false;
3353
+ }
3354
+ return typeof window !== "undefined" && typeof document !== "undefined";
3355
+ }
3356
+ function forEach3(obj, fn) {
3357
+ if (obj === null || typeof obj === "undefined") {
3358
+ return;
3359
+ }
3360
+ if (typeof obj !== "object") {
3361
+ obj = [obj];
3362
+ }
3363
+ if (isArray(obj)) {
3364
+ for (var i = 0, l = obj.length; i < l; i++) {
3365
+ fn.call(null, obj[i], i, obj);
3366
+ }
3367
+ } else {
3368
+ for (var key in obj) {
3369
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
3370
+ fn.call(null, obj[key], key, obj);
3371
+ }
3372
+ }
3373
+ }
3374
+ }
3375
+ function merge() {
3376
+ var result = {};
3377
+ function assignValue(val, key) {
3378
+ if (isPlainObject(result[key]) && isPlainObject(val)) {
3379
+ result[key] = merge(result[key], val);
3380
+ } else if (isPlainObject(val)) {
3381
+ result[key] = merge({}, val);
3382
+ } else if (isArray(val)) {
3383
+ result[key] = val.slice();
3384
+ } else {
3385
+ result[key] = val;
3386
+ }
3387
+ }
3388
+ for (var i = 0, l = arguments.length; i < l; i++) {
3389
+ forEach3(arguments[i], assignValue);
3390
+ }
3391
+ return result;
3392
+ }
3393
+ function extend(a, b, thisArg) {
3394
+ forEach3(b, function assignValue(val, key) {
3395
+ if (thisArg && typeof val === "function") {
3396
+ a[key] = bind$1(val, thisArg);
3397
+ } else {
3398
+ a[key] = val;
3399
+ }
3400
+ });
3401
+ return a;
3402
+ }
3403
+ function stripBOM(content) {
3404
+ if (content.charCodeAt(0) === 65279) {
3405
+ content = content.slice(1);
3406
+ }
3407
+ return content;
3408
+ }
3409
+ var utils$d = {
3410
+ isArray,
3411
+ isArrayBuffer,
3412
+ isBuffer,
3413
+ isFormData,
3414
+ isArrayBufferView,
3415
+ isString,
3416
+ isNumber,
3417
+ isObject,
3418
+ isPlainObject,
3419
+ isUndefined,
3420
+ isDate,
3421
+ isFile,
3422
+ isBlob,
3423
+ isFunction,
3424
+ isStream,
3425
+ isURLSearchParams,
3426
+ isStandardBrowserEnv,
3427
+ forEach: forEach3,
3428
+ merge,
3429
+ extend,
3430
+ trim,
3431
+ stripBOM
3432
+ };
3433
+ var utils$c = utils$d;
3434
+ function encode(val) {
3435
+ return encodeURIComponent(val).replace(/%3A/gi, ":").replace(/%24/g, "$").replace(/%2C/gi, ",").replace(/%20/g, "+").replace(/%5B/gi, "[").replace(/%5D/gi, "]");
3436
+ }
3437
+ var buildURL$2 = function buildURL3(url, params, paramsSerializer) {
3438
+ if (!params) {
3439
+ return url;
3440
+ }
3441
+ var serializedParams;
3442
+ if (paramsSerializer) {
3443
+ serializedParams = paramsSerializer(params);
3444
+ } else if (utils$c.isURLSearchParams(params)) {
3445
+ serializedParams = params.toString();
3446
+ } else {
3447
+ var parts = [];
3448
+ utils$c.forEach(params, function serialize(val, key) {
3449
+ if (val === null || typeof val === "undefined") {
3450
+ return;
3451
+ }
3452
+ if (utils$c.isArray(val)) {
3453
+ key = key + "[]";
3454
+ } else {
3455
+ val = [val];
3456
+ }
3457
+ utils$c.forEach(val, function parseValue(v) {
3458
+ if (utils$c.isDate(v)) {
3459
+ v = v.toISOString();
3460
+ } else if (utils$c.isObject(v)) {
3461
+ v = JSON.stringify(v);
3462
+ }
3463
+ parts.push(encode(key) + "=" + encode(v));
3464
+ });
3465
+ });
3466
+ serializedParams = parts.join("&");
3467
+ }
3468
+ if (serializedParams) {
3469
+ var hashmarkIndex = url.indexOf("#");
3470
+ if (hashmarkIndex !== -1) {
3471
+ url = url.slice(0, hashmarkIndex);
3472
+ }
3473
+ url += (url.indexOf("?") === -1 ? "?" : "&") + serializedParams;
3474
+ }
3475
+ return url;
3476
+ };
3477
+ var utils$b = utils$d;
3478
+ function InterceptorManager$1() {
3479
+ this.handlers = [];
3480
+ }
3481
+ InterceptorManager$1.prototype.use = function use3(fulfilled, rejected, options) {
3482
+ this.handlers.push({
3483
+ fulfilled,
3484
+ rejected,
3485
+ synchronous: options ? options.synchronous : false,
3486
+ runWhen: options ? options.runWhen : null
3487
+ });
3488
+ return this.handlers.length - 1;
3489
+ };
3490
+ InterceptorManager$1.prototype.eject = function eject3(id) {
3491
+ if (this.handlers[id]) {
3492
+ this.handlers[id] = null;
3493
+ }
3494
+ };
3495
+ InterceptorManager$1.prototype.forEach = function forEach4(fn) {
3496
+ utils$b.forEach(this.handlers, function forEachHandler(h) {
3497
+ if (h !== null) {
3498
+ fn(h);
3499
+ }
3500
+ });
3501
+ };
3502
+ var InterceptorManager_1 = InterceptorManager$1;
3503
+ var utils$a = utils$d;
3504
+ var normalizeHeaderName$1 = function normalizeHeaderName3(headers, normalizedName) {
3505
+ utils$a.forEach(headers, function processHeader(value, name2) {
3506
+ if (name2 !== normalizedName && name2.toUpperCase() === normalizedName.toUpperCase()) {
3507
+ headers[normalizedName] = value;
3508
+ delete headers[name2];
3509
+ }
3510
+ });
3511
+ };
3512
+ var enhanceError$2 = function enhanceError3(error, config, code, request4, response) {
3513
+ error.config = config;
3514
+ if (code) {
3515
+ error.code = code;
3516
+ }
3517
+ error.request = request4;
3518
+ error.response = response;
3519
+ error.isAxiosError = true;
3520
+ error.toJSON = function toJSON() {
3521
+ return {
3522
+ message: this.message,
3523
+ name: this.name,
3524
+ description: this.description,
3525
+ number: this.number,
3526
+ fileName: this.fileName,
3527
+ lineNumber: this.lineNumber,
3528
+ columnNumber: this.columnNumber,
3529
+ stack: this.stack,
3530
+ config: this.config,
3531
+ code: this.code,
3532
+ status: this.response && this.response.status ? this.response.status : null
3533
+ };
3534
+ };
3535
+ return error;
3536
+ };
3537
+ var enhanceError$1 = enhanceError$2;
3538
+ var createError$2 = function createError3(message, config, code, request4, response) {
3539
+ var error = new Error(message);
3540
+ return enhanceError$1(error, config, code, request4, response);
3541
+ };
3542
+ var createError$1 = createError$2;
3543
+ var settle$1 = function settle3(resolve, reject, response) {
3544
+ var validateStatus4 = response.config.validateStatus;
3545
+ if (!response.status || !validateStatus4 || validateStatus4(response.status)) {
3546
+ resolve(response);
3547
+ } else {
3548
+ reject(createError$1("Request failed with status code " + response.status, response.config, null, response.request, response));
3549
+ }
3550
+ };
3551
+ var utils$9 = utils$d;
3552
+ var cookies$1 = utils$9.isStandardBrowserEnv() ? function standardBrowserEnv5() {
3553
+ return {
3554
+ write: function write(name2, value, expires, path, domain, secure) {
3555
+ var cookie = [];
3556
+ cookie.push(name2 + "=" + encodeURIComponent(value));
3557
+ if (utils$9.isNumber(expires)) {
3558
+ cookie.push("expires=" + new Date(expires).toGMTString());
3559
+ }
3560
+ if (utils$9.isString(path)) {
3561
+ cookie.push("path=" + path);
3562
+ }
3563
+ if (utils$9.isString(domain)) {
3564
+ cookie.push("domain=" + domain);
3565
+ }
3566
+ if (secure === true) {
3567
+ cookie.push("secure");
3568
+ }
3569
+ document.cookie = cookie.join("; ");
3570
+ },
3571
+ read: function read(name2) {
3572
+ var match = document.cookie.match(new RegExp("(^|;\\s*)(" + name2 + ")=([^;]*)"));
3573
+ return match ? decodeURIComponent(match[3]) : null;
3574
+ },
3575
+ remove: function remove(name2) {
3576
+ this.write(name2, "", Date.now() - 864e5);
3577
+ }
3578
+ };
3579
+ }() : function nonStandardBrowserEnv5() {
3580
+ return {
3581
+ write: function write() {
3582
+ },
3583
+ read: function read() {
3584
+ return null;
3585
+ },
3586
+ remove: function remove() {
3587
+ }
3588
+ };
3589
+ }();
3590
+ var isAbsoluteURL$1 = function isAbsoluteURL3(url) {
3591
+ return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
3592
+ };
3593
+ var combineURLs$1 = function combineURLs3(baseURL, relativeURL) {
3594
+ return relativeURL ? baseURL.replace(/\/+$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
3595
+ };
3596
+ var isAbsoluteURL4 = isAbsoluteURL$1;
3597
+ var combineURLs4 = combineURLs$1;
3598
+ var buildFullPath$1 = function buildFullPath3(baseURL, requestedURL) {
3599
+ if (baseURL && !isAbsoluteURL4(requestedURL)) {
3600
+ return combineURLs4(baseURL, requestedURL);
3601
+ }
3602
+ return requestedURL;
3603
+ };
3604
+ var utils$8 = utils$d;
3605
+ var ignoreDuplicateOf = [
3606
+ "age",
3607
+ "authorization",
3608
+ "content-length",
3609
+ "content-type",
3610
+ "etag",
3611
+ "expires",
3612
+ "from",
3613
+ "host",
3614
+ "if-modified-since",
3615
+ "if-unmodified-since",
3616
+ "last-modified",
3617
+ "location",
3618
+ "max-forwards",
3619
+ "proxy-authorization",
3620
+ "referer",
3621
+ "retry-after",
3622
+ "user-agent"
3623
+ ];
3624
+ var parseHeaders$1 = function parseHeaders3(headers) {
3625
+ var parsed = {};
3626
+ var key;
3627
+ var val;
3628
+ var i;
3629
+ if (!headers) {
3630
+ return parsed;
3631
+ }
3632
+ utils$8.forEach(headers.split("\n"), function parser(line) {
3633
+ i = line.indexOf(":");
3634
+ key = utils$8.trim(line.substr(0, i)).toLowerCase();
3635
+ val = utils$8.trim(line.substr(i + 1));
3636
+ if (key) {
3637
+ if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
3638
+ return;
3639
+ }
3640
+ if (key === "set-cookie") {
3641
+ parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
3642
+ } else {
3643
+ parsed[key] = parsed[key] ? parsed[key] + ", " + val : val;
3644
+ }
3645
+ }
3646
+ });
3647
+ return parsed;
3648
+ };
3649
+ var utils$7 = utils$d;
3650
+ var isURLSameOrigin$1 = utils$7.isStandardBrowserEnv() ? function standardBrowserEnv6() {
3651
+ var msie = /(msie|trident)/i.test(navigator.userAgent);
3652
+ var urlParsingNode = document.createElement("a");
3653
+ var originURL;
3654
+ function resolveURL(url) {
3655
+ var href = url;
3656
+ if (msie) {
3657
+ urlParsingNode.setAttribute("href", href);
3658
+ href = urlParsingNode.href;
3659
+ }
3660
+ urlParsingNode.setAttribute("href", href);
3661
+ return {
3662
+ href: urlParsingNode.href,
3663
+ protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, "") : "",
3664
+ host: urlParsingNode.host,
3665
+ search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, "") : "",
3666
+ hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, "") : "",
3667
+ hostname: urlParsingNode.hostname,
3668
+ port: urlParsingNode.port,
3669
+ pathname: urlParsingNode.pathname.charAt(0) === "/" ? urlParsingNode.pathname : "/" + urlParsingNode.pathname
3670
+ };
3671
+ }
3672
+ originURL = resolveURL(window.location.href);
3673
+ return function isURLSameOrigin2(requestURL) {
3674
+ var parsed = utils$7.isString(requestURL) ? resolveURL(requestURL) : requestURL;
3675
+ return parsed.protocol === originURL.protocol && parsed.host === originURL.host;
3676
+ };
3677
+ }() : function nonStandardBrowserEnv6() {
3678
+ return function isURLSameOrigin2() {
3679
+ return true;
3680
+ };
3681
+ }();
3682
+ function Cancel$3(message) {
3683
+ this.message = message;
3684
+ }
3685
+ Cancel$3.prototype.toString = function toString4() {
3686
+ return "Cancel" + (this.message ? ": " + this.message : "");
3687
+ };
3688
+ Cancel$3.prototype.__CANCEL__ = true;
3689
+ var Cancel_1 = Cancel$3;
3690
+ var utils$6 = utils$d;
3691
+ var settle4 = settle$1;
3692
+ var cookies = cookies$1;
3693
+ var buildURL$1 = buildURL$2;
3694
+ var buildFullPath4 = buildFullPath$1;
3695
+ var parseHeaders4 = parseHeaders$1;
3696
+ var isURLSameOrigin = isURLSameOrigin$1;
3697
+ var createError4 = createError$2;
3698
+ var defaults$4 = defaults_1;
3699
+ var Cancel$2 = Cancel_1;
3700
+ var xhr = function xhrAdapter3(config) {
3701
+ return new Promise(function dispatchXhrRequest(resolve, reject) {
3702
+ var requestData = config.data;
3703
+ var requestHeaders = config.headers;
3704
+ var responseType = config.responseType;
3705
+ var onCanceled;
3706
+ function done() {
3707
+ if (config.cancelToken) {
3708
+ config.cancelToken.unsubscribe(onCanceled);
3709
+ }
3710
+ if (config.signal) {
3711
+ config.signal.removeEventListener("abort", onCanceled);
3712
+ }
3713
+ }
3714
+ if (utils$6.isFormData(requestData)) {
3715
+ delete requestHeaders["Content-Type"];
3716
+ }
3717
+ var request4 = new XMLHttpRequest();
3718
+ if (config.auth) {
3719
+ var username = config.auth.username || "";
3720
+ var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : "";
3721
+ requestHeaders.Authorization = "Basic " + btoa(username + ":" + password);
3722
+ }
3723
+ var fullPath = buildFullPath4(config.baseURL, config.url);
3724
+ request4.open(config.method.toUpperCase(), buildURL$1(fullPath, config.params, config.paramsSerializer), true);
3725
+ request4.timeout = config.timeout;
3726
+ function onloadend() {
3727
+ if (!request4) {
3728
+ return;
3729
+ }
3730
+ var responseHeaders = "getAllResponseHeaders" in request4 ? parseHeaders4(request4.getAllResponseHeaders()) : null;
3731
+ var responseData = !responseType || responseType === "text" || responseType === "json" ? request4.responseText : request4.response;
3732
+ var response = {
3733
+ data: responseData,
3734
+ status: request4.status,
3735
+ statusText: request4.statusText,
3736
+ headers: responseHeaders,
3737
+ config,
3738
+ request: request4
3739
+ };
3740
+ settle4(function _resolve(value) {
3741
+ resolve(value);
3742
+ done();
3743
+ }, function _reject(err) {
3744
+ reject(err);
3745
+ done();
3746
+ }, response);
3747
+ request4 = null;
3748
+ }
3749
+ if ("onloadend" in request4) {
3750
+ request4.onloadend = onloadend;
3751
+ } else {
3752
+ request4.onreadystatechange = function handleLoad() {
3753
+ if (!request4 || request4.readyState !== 4) {
3754
+ return;
3755
+ }
3756
+ if (request4.status === 0 && !(request4.responseURL && request4.responseURL.indexOf("file:") === 0)) {
3757
+ return;
3758
+ }
3759
+ setTimeout(onloadend);
3760
+ };
3761
+ }
3762
+ request4.onabort = function handleAbort() {
3763
+ if (!request4) {
3764
+ return;
3765
+ }
3766
+ reject(createError4("Request aborted", config, "ECONNABORTED", request4));
3767
+ request4 = null;
3768
+ };
3769
+ request4.onerror = function handleError() {
3770
+ reject(createError4("Network Error", config, null, request4));
3771
+ request4 = null;
3772
+ };
3773
+ request4.ontimeout = function handleTimeout() {
3774
+ var timeoutErrorMessage = config.timeout ? "timeout of " + config.timeout + "ms exceeded" : "timeout exceeded";
3775
+ var transitional4 = config.transitional || defaults$4.transitional;
3776
+ if (config.timeoutErrorMessage) {
3777
+ timeoutErrorMessage = config.timeoutErrorMessage;
3778
+ }
3779
+ reject(createError4(timeoutErrorMessage, config, transitional4.clarifyTimeoutError ? "ETIMEDOUT" : "ECONNABORTED", request4));
3780
+ request4 = null;
3781
+ };
3782
+ if (utils$6.isStandardBrowserEnv()) {
3783
+ var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ? cookies.read(config.xsrfCookieName) : void 0;
3784
+ if (xsrfValue) {
3785
+ requestHeaders[config.xsrfHeaderName] = xsrfValue;
3786
+ }
3787
+ }
3788
+ if ("setRequestHeader" in request4) {
3789
+ utils$6.forEach(requestHeaders, function setRequestHeader(val, key) {
3790
+ if (typeof requestData === "undefined" && key.toLowerCase() === "content-type") {
3791
+ delete requestHeaders[key];
3792
+ } else {
3793
+ request4.setRequestHeader(key, val);
3794
+ }
3795
+ });
3796
+ }
3797
+ if (!utils$6.isUndefined(config.withCredentials)) {
3798
+ request4.withCredentials = !!config.withCredentials;
3799
+ }
3800
+ if (responseType && responseType !== "json") {
3801
+ request4.responseType = config.responseType;
3802
+ }
3803
+ if (typeof config.onDownloadProgress === "function") {
3804
+ request4.addEventListener("progress", config.onDownloadProgress);
3805
+ }
3806
+ if (typeof config.onUploadProgress === "function" && request4.upload) {
3807
+ request4.upload.addEventListener("progress", config.onUploadProgress);
3808
+ }
3809
+ if (config.cancelToken || config.signal) {
3810
+ onCanceled = function(cancel) {
3811
+ if (!request4) {
3812
+ return;
3813
+ }
3814
+ reject(!cancel || cancel && cancel.type ? new Cancel$2("canceled") : cancel);
3815
+ request4.abort();
3816
+ request4 = null;
3817
+ };
3818
+ config.cancelToken && config.cancelToken.subscribe(onCanceled);
3819
+ if (config.signal) {
3820
+ config.signal.aborted ? onCanceled() : config.signal.addEventListener("abort", onCanceled);
3821
+ }
3822
+ }
3823
+ if (!requestData) {
3824
+ requestData = null;
3825
+ }
3826
+ request4.send(requestData);
3827
+ });
3828
+ };
3829
+ var utils$5 = utils$d;
3830
+ var normalizeHeaderName4 = normalizeHeaderName$1;
3831
+ var enhanceError4 = enhanceError$2;
3832
+ var DEFAULT_CONTENT_TYPE = {
3833
+ "Content-Type": "application/x-www-form-urlencoded"
3834
+ };
3835
+ function setContentTypeIfUnset(headers, value) {
3836
+ if (!utils$5.isUndefined(headers) && utils$5.isUndefined(headers["Content-Type"])) {
3837
+ headers["Content-Type"] = value;
3838
+ }
3839
+ }
3840
+ function getDefaultAdapter() {
3841
+ var adapter;
3842
+ if (typeof XMLHttpRequest !== "undefined") {
3843
+ adapter = xhr;
3844
+ } else if (typeof process !== "undefined" && Object.prototype.toString.call(process) === "[object process]") {
3845
+ adapter = xhr;
3846
+ }
3847
+ return adapter;
3848
+ }
3849
+ function stringifySafely(rawValue, parser, encoder) {
3850
+ if (utils$5.isString(rawValue)) {
3851
+ try {
3852
+ (parser || JSON.parse)(rawValue);
3853
+ return utils$5.trim(rawValue);
3854
+ } catch (e) {
3855
+ if (e.name !== "SyntaxError") {
3856
+ throw e;
3857
+ }
3858
+ }
3859
+ }
3860
+ return (encoder || JSON.stringify)(rawValue);
3861
+ }
3862
+ var defaults$3 = {
3863
+ transitional: {
3864
+ silentJSONParsing: true,
3865
+ forcedJSONParsing: true,
3866
+ clarifyTimeoutError: false
3867
+ },
3868
+ adapter: getDefaultAdapter(),
3869
+ transformRequest: [function transformRequest3(data2, headers) {
3870
+ normalizeHeaderName4(headers, "Accept");
3871
+ normalizeHeaderName4(headers, "Content-Type");
3872
+ if (utils$5.isFormData(data2) || utils$5.isArrayBuffer(data2) || utils$5.isBuffer(data2) || utils$5.isStream(data2) || utils$5.isFile(data2) || utils$5.isBlob(data2)) {
3873
+ return data2;
3874
+ }
3875
+ if (utils$5.isArrayBufferView(data2)) {
3876
+ return data2.buffer;
3877
+ }
3878
+ if (utils$5.isURLSearchParams(data2)) {
3879
+ setContentTypeIfUnset(headers, "application/x-www-form-urlencoded;charset=utf-8");
3880
+ return data2.toString();
3881
+ }
3882
+ if (utils$5.isObject(data2) || headers && headers["Content-Type"] === "application/json") {
3883
+ setContentTypeIfUnset(headers, "application/json");
3884
+ return stringifySafely(data2);
3885
+ }
3886
+ return data2;
3887
+ }],
3888
+ transformResponse: [function transformResponse3(data2) {
3889
+ var transitional4 = this.transitional || defaults$3.transitional;
3890
+ var silentJSONParsing = transitional4 && transitional4.silentJSONParsing;
3891
+ var forcedJSONParsing = transitional4 && transitional4.forcedJSONParsing;
3892
+ var strictJSONParsing = !silentJSONParsing && this.responseType === "json";
3893
+ if (strictJSONParsing || forcedJSONParsing && utils$5.isString(data2) && data2.length) {
3894
+ try {
3895
+ return JSON.parse(data2);
3896
+ } catch (e) {
3897
+ if (strictJSONParsing) {
3898
+ if (e.name === "SyntaxError") {
3899
+ throw enhanceError4(e, this, "E_JSON_PARSE");
3900
+ }
3901
+ throw e;
3902
+ }
3903
+ }
3904
+ }
3905
+ return data2;
3906
+ }],
3907
+ timeout: 0,
3908
+ xsrfCookieName: "XSRF-TOKEN",
3909
+ xsrfHeaderName: "X-XSRF-TOKEN",
3910
+ maxContentLength: -1,
3911
+ maxBodyLength: -1,
3912
+ validateStatus: function validateStatus3(status) {
3913
+ return status >= 200 && status < 300;
3914
+ },
3915
+ headers: {
3916
+ common: {
3917
+ "Accept": "application/json, text/plain, */*"
3918
+ }
3919
+ }
3920
+ };
3921
+ utils$5.forEach(["delete", "get", "head"], function forEachMethodNoData5(method) {
3922
+ defaults$3.headers[method] = {};
3923
+ });
3924
+ utils$5.forEach(["post", "put", "patch"], function forEachMethodWithData5(method) {
3925
+ defaults$3.headers[method] = utils$5.merge(DEFAULT_CONTENT_TYPE);
3926
+ });
3927
+ var defaults_1 = defaults$3;
3928
+ var utils$4 = utils$d;
3929
+ var defaults$2 = defaults_1;
3930
+ var transformData$1 = function transformData3(data2, headers, fns) {
3931
+ var context = this || defaults$2;
3932
+ utils$4.forEach(fns, function transform(fn) {
3933
+ data2 = fn.call(context, data2, headers);
3934
+ });
3935
+ return data2;
3936
+ };
3937
+ var isCancel$1 = function isCancel3(value) {
3938
+ return !!(value && value.__CANCEL__);
3939
+ };
3940
+ var utils$3 = utils$d;
3941
+ var transformData4 = transformData$1;
3942
+ var isCancel4 = isCancel$1;
3943
+ var defaults$1 = defaults_1;
3944
+ var Cancel$1 = Cancel_1;
3945
+ function throwIfCancellationRequested(config) {
3946
+ if (config.cancelToken) {
3947
+ config.cancelToken.throwIfRequested();
3948
+ }
3949
+ if (config.signal && config.signal.aborted) {
3950
+ throw new Cancel$1("canceled");
3951
+ }
3952
+ }
3953
+ var dispatchRequest$1 = function dispatchRequest3(config) {
3954
+ throwIfCancellationRequested(config);
3955
+ config.headers = config.headers || {};
3956
+ config.data = transformData4.call(config, config.data, config.headers, config.transformRequest);
3957
+ config.headers = utils$3.merge(config.headers.common || {}, config.headers[config.method] || {}, config.headers);
3958
+ utils$3.forEach(["delete", "get", "head", "post", "put", "patch", "common"], function cleanHeaderConfig(method) {
3959
+ delete config.headers[method];
3960
+ });
3961
+ var adapter = config.adapter || defaults$1.adapter;
3962
+ return adapter(config).then(function onAdapterResolution(response) {
3963
+ throwIfCancellationRequested(config);
3964
+ response.data = transformData4.call(config, response.data, response.headers, config.transformResponse);
3965
+ return response;
3966
+ }, function onAdapterRejection(reason) {
3967
+ if (!isCancel4(reason)) {
3968
+ throwIfCancellationRequested(config);
3969
+ if (reason && reason.response) {
3970
+ reason.response.data = transformData4.call(config, reason.response.data, reason.response.headers, config.transformResponse);
3971
+ }
3972
+ }
3973
+ return Promise.reject(reason);
3974
+ });
3975
+ };
3976
+ var utils$2 = utils$d;
3977
+ var mergeConfig$2 = function mergeConfig3(config1, config2) {
3978
+ config2 = config2 || {};
3979
+ var config = {};
3980
+ function getMergedValue(target, source4) {
3981
+ if (utils$2.isPlainObject(target) && utils$2.isPlainObject(source4)) {
3982
+ return utils$2.merge(target, source4);
3983
+ } else if (utils$2.isPlainObject(source4)) {
3984
+ return utils$2.merge({}, source4);
3985
+ } else if (utils$2.isArray(source4)) {
3986
+ return source4.slice();
3987
+ }
3988
+ return source4;
3989
+ }
3990
+ function mergeDeepProperties(prop) {
3991
+ if (!utils$2.isUndefined(config2[prop])) {
3992
+ return getMergedValue(config1[prop], config2[prop]);
3993
+ } else if (!utils$2.isUndefined(config1[prop])) {
3994
+ return getMergedValue(void 0, config1[prop]);
3995
+ }
3996
+ }
3997
+ function valueFromConfig2(prop) {
3998
+ if (!utils$2.isUndefined(config2[prop])) {
3999
+ return getMergedValue(void 0, config2[prop]);
4000
+ }
4001
+ }
4002
+ function defaultToConfig2(prop) {
4003
+ if (!utils$2.isUndefined(config2[prop])) {
4004
+ return getMergedValue(void 0, config2[prop]);
4005
+ } else if (!utils$2.isUndefined(config1[prop])) {
4006
+ return getMergedValue(void 0, config1[prop]);
4007
+ }
4008
+ }
4009
+ function mergeDirectKeys(prop) {
4010
+ if (prop in config2) {
4011
+ return getMergedValue(config1[prop], config2[prop]);
4012
+ } else if (prop in config1) {
4013
+ return getMergedValue(void 0, config1[prop]);
4014
+ }
4015
+ }
4016
+ var mergeMap = {
4017
+ "url": valueFromConfig2,
4018
+ "method": valueFromConfig2,
4019
+ "data": valueFromConfig2,
4020
+ "baseURL": defaultToConfig2,
4021
+ "transformRequest": defaultToConfig2,
4022
+ "transformResponse": defaultToConfig2,
4023
+ "paramsSerializer": defaultToConfig2,
4024
+ "timeout": defaultToConfig2,
4025
+ "timeoutMessage": defaultToConfig2,
4026
+ "withCredentials": defaultToConfig2,
4027
+ "adapter": defaultToConfig2,
4028
+ "responseType": defaultToConfig2,
4029
+ "xsrfCookieName": defaultToConfig2,
4030
+ "xsrfHeaderName": defaultToConfig2,
4031
+ "onUploadProgress": defaultToConfig2,
4032
+ "onDownloadProgress": defaultToConfig2,
4033
+ "decompress": defaultToConfig2,
4034
+ "maxContentLength": defaultToConfig2,
4035
+ "maxBodyLength": defaultToConfig2,
4036
+ "transport": defaultToConfig2,
4037
+ "httpAgent": defaultToConfig2,
4038
+ "httpsAgent": defaultToConfig2,
4039
+ "cancelToken": defaultToConfig2,
4040
+ "socketPath": defaultToConfig2,
4041
+ "responseEncoding": defaultToConfig2,
4042
+ "validateStatus": mergeDirectKeys
4043
+ };
4044
+ utils$2.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
4045
+ var merge2 = mergeMap[prop] || mergeDeepProperties;
4046
+ var configValue = merge2(prop);
4047
+ utils$2.isUndefined(configValue) && merge2 !== mergeDirectKeys || (config[prop] = configValue);
4048
+ });
4049
+ return config;
4050
+ };
4051
+ var data = {
4052
+ "version": "0.23.0"
4053
+ };
4054
+ var VERSION = data.version;
4055
+ var validators$1 = {};
4056
+ ["object", "boolean", "number", "function", "string", "symbol"].forEach(function(type, i) {
4057
+ validators$1[type] = function validator2(thing) {
4058
+ return typeof thing === type || "a" + (i < 1 ? "n " : " ") + type;
4059
+ };
4060
+ });
4061
+ var deprecatedWarnings = {};
4062
+ validators$1.transitional = function transitional3(validator2, version2, message) {
4063
+ function formatMessage(opt, desc) {
4064
+ return "[Axios v" + VERSION + "] Transitional option '" + opt + "'" + desc + (message ? ". " + message : "");
4065
+ }
4066
+ return function(value, opt, opts) {
4067
+ if (validator2 === false) {
4068
+ throw new Error(formatMessage(opt, " has been removed" + (version2 ? " in " + version2 : "")));
4069
+ }
4070
+ if (version2 && !deprecatedWarnings[opt]) {
4071
+ deprecatedWarnings[opt] = true;
4072
+ console.warn(formatMessage(opt, " has been deprecated since v" + version2 + " and will be removed in the near future"));
4073
+ }
4074
+ return validator2 ? validator2(value, opt, opts) : true;
4075
+ };
4076
+ };
4077
+ function assertOptions(options, schema, allowUnknown) {
4078
+ if (typeof options !== "object") {
4079
+ throw new TypeError("options must be an object");
4080
+ }
4081
+ var keys = Object.keys(options);
4082
+ var i = keys.length;
4083
+ while (i-- > 0) {
4084
+ var opt = keys[i];
4085
+ var validator2 = schema[opt];
4086
+ if (validator2) {
4087
+ var value = options[opt];
4088
+ var result = value === void 0 || validator2(value, opt, options);
4089
+ if (result !== true) {
4090
+ throw new TypeError("option " + opt + " must be " + result);
4091
+ }
4092
+ continue;
4093
+ }
4094
+ if (allowUnknown !== true) {
4095
+ throw Error("Unknown option " + opt);
4096
+ }
4097
+ }
4098
+ }
4099
+ var validator$1 = {
4100
+ assertOptions,
4101
+ validators: validators$1
4102
+ };
4103
+ var utils$1 = utils$d;
4104
+ var buildURL4 = buildURL$2;
4105
+ var InterceptorManager = InterceptorManager_1;
4106
+ var dispatchRequest4 = dispatchRequest$1;
4107
+ var mergeConfig$1 = mergeConfig$2;
4108
+ var validator = validator$1;
4109
+ var validators = validator.validators;
4110
+ function Axios$1(instanceConfig) {
4111
+ this.defaults = instanceConfig;
4112
+ this.interceptors = {
4113
+ request: new InterceptorManager(),
4114
+ response: new InterceptorManager()
4115
+ };
4116
+ }
4117
+ Axios$1.prototype.request = function request3(config) {
4118
+ if (typeof config === "string") {
4119
+ config = arguments[1] || {};
4120
+ config.url = arguments[0];
4121
+ } else {
4122
+ config = config || {};
4123
+ }
4124
+ config = mergeConfig$1(this.defaults, config);
4125
+ if (config.method) {
4126
+ config.method = config.method.toLowerCase();
4127
+ } else if (this.defaults.method) {
4128
+ config.method = this.defaults.method.toLowerCase();
4129
+ } else {
4130
+ config.method = "get";
4131
+ }
4132
+ var transitional4 = config.transitional;
4133
+ if (transitional4 !== void 0) {
4134
+ validator.assertOptions(transitional4, {
4135
+ silentJSONParsing: validators.transitional(validators.boolean),
4136
+ forcedJSONParsing: validators.transitional(validators.boolean),
4137
+ clarifyTimeoutError: validators.transitional(validators.boolean)
4138
+ }, false);
4139
+ }
4140
+ var requestInterceptorChain = [];
4141
+ var synchronousRequestInterceptors = true;
4142
+ this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
4143
+ if (typeof interceptor.runWhen === "function" && interceptor.runWhen(config) === false) {
4144
+ return;
4145
+ }
4146
+ synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
4147
+ requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
4148
+ });
4149
+ var responseInterceptorChain = [];
4150
+ this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
4151
+ responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
4152
+ });
4153
+ var promise;
4154
+ if (!synchronousRequestInterceptors) {
4155
+ var chain = [dispatchRequest4, void 0];
4156
+ Array.prototype.unshift.apply(chain, requestInterceptorChain);
4157
+ chain = chain.concat(responseInterceptorChain);
4158
+ promise = Promise.resolve(config);
4159
+ while (chain.length) {
4160
+ promise = promise.then(chain.shift(), chain.shift());
4161
+ }
4162
+ return promise;
4163
+ }
4164
+ var newConfig = config;
4165
+ while (requestInterceptorChain.length) {
4166
+ var onFulfilled = requestInterceptorChain.shift();
4167
+ var onRejected = requestInterceptorChain.shift();
4168
+ try {
4169
+ newConfig = onFulfilled(newConfig);
4170
+ } catch (error) {
4171
+ onRejected(error);
4172
+ break;
4173
+ }
4174
+ }
4175
+ try {
4176
+ promise = dispatchRequest4(newConfig);
4177
+ } catch (error) {
4178
+ return Promise.reject(error);
4179
+ }
4180
+ while (responseInterceptorChain.length) {
4181
+ promise = promise.then(responseInterceptorChain.shift(), responseInterceptorChain.shift());
4182
+ }
4183
+ return promise;
4184
+ };
4185
+ Axios$1.prototype.getUri = function getUri3(config) {
4186
+ config = mergeConfig$1(this.defaults, config);
4187
+ return buildURL4(config.url, config.params, config.paramsSerializer).replace(/^\?/, "");
4188
+ };
4189
+ utils$1.forEach(["delete", "get", "head", "options"], function forEachMethodNoData6(method) {
4190
+ Axios$1.prototype[method] = function(url, config) {
4191
+ return this.request(mergeConfig$1(config || {}, {
4192
+ method,
4193
+ url,
4194
+ data: (config || {}).data
4195
+ }));
4196
+ };
4197
+ });
4198
+ utils$1.forEach(["post", "put", "patch"], function forEachMethodWithData6(method) {
4199
+ Axios$1.prototype[method] = function(url, data2, config) {
4200
+ return this.request(mergeConfig$1(config || {}, {
4201
+ method,
4202
+ url,
4203
+ data: data2
4204
+ }));
4205
+ };
4206
+ });
4207
+ var Axios_1 = Axios$1;
4208
+ var Cancel = Cancel_1;
4209
+ function CancelToken(executor) {
4210
+ if (typeof executor !== "function") {
4211
+ throw new TypeError("executor must be a function.");
4212
+ }
4213
+ var resolvePromise;
4214
+ this.promise = new Promise(function promiseExecutor(resolve) {
4215
+ resolvePromise = resolve;
4216
+ });
4217
+ var token2 = this;
4218
+ this.promise.then(function(cancel) {
4219
+ if (!token2._listeners)
4220
+ return;
4221
+ var i;
4222
+ var l = token2._listeners.length;
4223
+ for (i = 0; i < l; i++) {
4224
+ token2._listeners[i](cancel);
4225
+ }
4226
+ token2._listeners = null;
4227
+ });
4228
+ this.promise.then = function(onfulfilled) {
4229
+ var _resolve;
4230
+ var promise = new Promise(function(resolve) {
4231
+ token2.subscribe(resolve);
4232
+ _resolve = resolve;
4233
+ }).then(onfulfilled);
4234
+ promise.cancel = function reject() {
4235
+ token2.unsubscribe(_resolve);
4236
+ };
4237
+ return promise;
4238
+ };
4239
+ executor(function cancel(message) {
4240
+ if (token2.reason) {
4241
+ return;
4242
+ }
4243
+ token2.reason = new Cancel(message);
4244
+ resolvePromise(token2.reason);
4245
+ });
4246
+ }
4247
+ CancelToken.prototype.throwIfRequested = function throwIfRequested3() {
4248
+ if (this.reason) {
4249
+ throw this.reason;
4250
+ }
4251
+ };
4252
+ CancelToken.prototype.subscribe = function subscribe2(listener) {
4253
+ if (this.reason) {
4254
+ listener(this.reason);
4255
+ return;
4256
+ }
4257
+ if (this._listeners) {
4258
+ this._listeners.push(listener);
4259
+ } else {
4260
+ this._listeners = [listener];
4261
+ }
4262
+ };
4263
+ CancelToken.prototype.unsubscribe = function unsubscribe2(listener) {
4264
+ if (!this._listeners) {
4265
+ return;
4266
+ }
4267
+ var index = this._listeners.indexOf(listener);
4268
+ if (index !== -1) {
4269
+ this._listeners.splice(index, 1);
4270
+ }
4271
+ };
4272
+ CancelToken.source = function source3() {
4273
+ var cancel;
4274
+ var token2 = new CancelToken(function executor(c) {
4275
+ cancel = c;
4276
+ });
4277
+ return {
4278
+ token: token2,
4279
+ cancel
4280
+ };
4281
+ };
4282
+ var CancelToken_1 = CancelToken;
4283
+ var spread3 = function spread4(callback) {
4284
+ return function wrap(arr) {
4285
+ return callback.apply(null, arr);
4286
+ };
4287
+ };
4288
+ var isAxiosError3 = function isAxiosError4(payload) {
4289
+ return typeof payload === "object" && payload.isAxiosError === true;
4290
+ };
4291
+ var utils = utils$d;
4292
+ var bind4 = bind$2;
4293
+ var Axios = Axios_1;
4294
+ var mergeConfig4 = mergeConfig$2;
4295
+ var defaults = defaults_1;
4296
+ function createInstance(defaultConfig) {
4297
+ var context = new Axios(defaultConfig);
4298
+ var instance = bind4(Axios.prototype.request, context);
4299
+ utils.extend(instance, Axios.prototype, context);
4300
+ utils.extend(instance, context);
4301
+ instance.create = function create2(instanceConfig) {
4302
+ return createInstance(mergeConfig4(defaultConfig, instanceConfig));
4303
+ };
4304
+ return instance;
4305
+ }
4306
+ var axios$1 = createInstance(defaults);
4307
+ axios$1.Axios = Axios;
4308
+ axios$1.Cancel = Cancel_1;
4309
+ axios$1.CancelToken = CancelToken_1;
4310
+ axios$1.isCancel = isCancel$1;
4311
+ axios$1.VERSION = data.version;
4312
+ axios$1.all = function all3(promises) {
4313
+ return Promise.all(promises);
4314
+ };
4315
+ axios$1.spread = spread3;
4316
+ axios$1.isAxiosError = isAxiosError3;
4317
+ axios$2.exports = axios$1;
4318
+ axios$2.exports.default = axios$1;
4319
+ var axios = axios$2.exports;
4320
+ class NhostFunctionsClient {
4321
+ constructor(params) {
4322
+ const { url } = params;
4323
+ this.accessToken = null;
4324
+ this.instance = axios.create({
4325
+ baseURL: url
4326
+ });
4327
+ }
4328
+ async call(url, data2, config) {
4329
+ const headers = __spreadValues(__spreadValues({}, this.generateAccessTokenHeaders()), config == null ? void 0 : config.headers);
4330
+ let res;
4331
+ try {
4332
+ res = await this.instance.post(url, data2, __spreadProps(__spreadValues({}, config), { headers }));
4333
+ } catch (error) {
4334
+ if (error instanceof Error) {
4335
+ return { res: null, error };
4336
+ }
4337
+ }
4338
+ if (!res) {
4339
+ return {
4340
+ res: null,
4341
+ error: new Error("Unable to make post request to funtion")
4342
+ };
4343
+ }
4344
+ return { res, error: null };
4345
+ }
4346
+ setAccessToken(accessToken) {
4347
+ if (!accessToken) {
4348
+ this.accessToken = null;
4349
+ return;
4350
+ }
4351
+ this.accessToken = accessToken;
4352
+ }
4353
+ generateAccessTokenHeaders() {
4354
+ if (!this.accessToken) {
4355
+ return;
4356
+ }
4357
+ return {
4358
+ Authorization: `Bearer ${this.accessToken}`
4359
+ };
4360
+ }
4361
+ }
4362
+ class NhostGraphqlClient {
4363
+ constructor(params) {
4364
+ const { url } = params;
4365
+ this.url = url;
4366
+ this.accessToken = null;
4367
+ this.instance = axios.create({
4368
+ baseURL: url
4369
+ });
4370
+ }
4371
+ async request(document2, variables, config) {
4372
+ const headers = __spreadValues(__spreadValues({}, config == null ? void 0 : config.headers), this.generateAccessTokenHeaders());
4373
+ const operationName = "";
4374
+ let responseData;
4375
+ try {
4376
+ const res = await this.instance.post("", {
4377
+ operationName: operationName || void 0,
4378
+ query: document2,
4379
+ variables
4380
+ }, __spreadProps(__spreadValues({}, config), { headers }));
4381
+ responseData = res.data;
4382
+ } catch (error) {
4383
+ if (error instanceof Error) {
4384
+ return { data: null, error };
4385
+ }
4386
+ console.error(error);
4387
+ return {
4388
+ data: null,
4389
+ error: new Error("Unable to get do GraphQL request")
4390
+ };
4391
+ }
4392
+ if (typeof responseData !== "object" || Array.isArray(responseData) || responseData === null) {
4393
+ return {
4394
+ data: null,
4395
+ error: new Error("incorrect response data from GraphQL server")
4396
+ };
4397
+ }
4398
+ responseData = responseData;
4399
+ if (responseData.errors) {
4400
+ return {
4401
+ data: null,
4402
+ error: responseData.errors
4403
+ };
4404
+ }
4405
+ return { data: responseData.data, error: null };
4406
+ }
4407
+ getUrl() {
4408
+ return this.url;
4409
+ }
4410
+ setAccessToken(accessToken) {
4411
+ if (!accessToken) {
4412
+ this.accessToken = null;
4413
+ return;
4414
+ }
4415
+ this.accessToken = accessToken;
4416
+ }
4417
+ generateAccessTokenHeaders() {
4418
+ if (!this.accessToken) {
4419
+ return;
4420
+ }
4421
+ return {
4422
+ Authorization: `Bearer ${this.accessToken}`
4423
+ };
4424
+ }
4425
+ }
4426
+ class NhostClient {
4427
+ constructor(params) {
4428
+ if (!params.backendUrl)
4429
+ throw new Error("Please specify a `backendUrl`. Docs: [todo]!");
4430
+ const {
4431
+ backendUrl,
4432
+ refreshIntervalTime,
4433
+ clientStorage,
4434
+ clientStorageType,
4435
+ autoRefreshToken,
4436
+ autoLogin
4437
+ } = params;
4438
+ this.auth = new HasuraAuthClient({
4439
+ url: `${backendUrl}/v1/auth`,
4440
+ refreshIntervalTime,
4441
+ clientStorage,
4442
+ clientStorageType,
4443
+ autoRefreshToken,
4444
+ autoLogin
4445
+ });
4446
+ this.storage = new HasuraStorageClient({
4447
+ url: `${backendUrl}/v1/storage`
4448
+ });
4449
+ this.functions = new NhostFunctionsClient({
4450
+ url: `${backendUrl}/v1/functions`
4451
+ });
4452
+ this.graphql = new NhostGraphqlClient({
4453
+ url: `${backendUrl}/v1/graphql`
4454
+ });
4455
+ this.storage.setAccessToken(this.auth.getAccessToken());
4456
+ this.functions.setAccessToken(this.auth.getAccessToken());
4457
+ this.graphql.setAccessToken(this.auth.getAccessToken());
4458
+ this.auth.onAuthStateChanged((_event, session) => {
4459
+ this.storage.setAccessToken(session == null ? void 0 : session.accessToken);
4460
+ this.functions.setAccessToken(session == null ? void 0 : session.accessToken);
4461
+ this.graphql.setAccessToken(session == null ? void 0 : session.accessToken);
4462
+ });
4463
+ this.auth.onTokenChanged((session) => {
4464
+ this.storage.setAccessToken(session == null ? void 0 : session.accessToken);
4465
+ this.functions.setAccessToken(session == null ? void 0 : session.accessToken);
4466
+ this.graphql.setAccessToken(session == null ? void 0 : session.accessToken);
4467
+ });
4468
+ }
4469
+ }
4470
+ const createClient = (config) => new NhostClient(config);
4471
+ export { NhostClient, createClient };