@sanity/client 3.3.1 → 3.4.0-beta.esm.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4317 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
+ };
5
+
6
+ // node_modules/object-assign/index.js
7
+ var require_object_assign = __commonJS({
8
+ "node_modules/object-assign/index.js"(exports, module) {
9
+ "use strict";
10
+ var getOwnPropertySymbols = Object.getOwnPropertySymbols;
11
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
12
+ var propIsEnumerable = Object.prototype.propertyIsEnumerable;
13
+ function toObject(val) {
14
+ if (val === null || val === void 0) {
15
+ throw new TypeError("Object.assign cannot be called with null or undefined");
16
+ }
17
+ return Object(val);
18
+ }
19
+ function shouldUseNative() {
20
+ try {
21
+ if (!Object.assign) {
22
+ return false;
23
+ }
24
+ var test1 = new String("abc");
25
+ test1[5] = "de";
26
+ if (Object.getOwnPropertyNames(test1)[0] === "5") {
27
+ return false;
28
+ }
29
+ var test2 = {};
30
+ for (var i = 0; i < 10; i++) {
31
+ test2["_" + String.fromCharCode(i)] = i;
32
+ }
33
+ var order2 = Object.getOwnPropertyNames(test2).map(function(n) {
34
+ return test2[n];
35
+ });
36
+ if (order2.join("") !== "0123456789") {
37
+ return false;
38
+ }
39
+ var test3 = {};
40
+ "abcdefghijklmnopqrst".split("").forEach(function(letter) {
41
+ test3[letter] = letter;
42
+ });
43
+ if (Object.keys(Object.assign({}, test3)).join("") !== "abcdefghijklmnopqrst") {
44
+ return false;
45
+ }
46
+ return true;
47
+ } catch (err) {
48
+ return false;
49
+ }
50
+ }
51
+ module.exports = shouldUseNative() ? Object.assign : function(target, source) {
52
+ var from;
53
+ var to = toObject(target);
54
+ var symbols;
55
+ for (var s = 1; s < arguments.length; s++) {
56
+ from = Object(arguments[s]);
57
+ for (var key in from) {
58
+ if (hasOwnProperty.call(from, key)) {
59
+ to[key] = from[key];
60
+ }
61
+ }
62
+ if (getOwnPropertySymbols) {
63
+ symbols = getOwnPropertySymbols(from);
64
+ for (var i = 0; i < symbols.length; i++) {
65
+ if (propIsEnumerable.call(from, symbols[i])) {
66
+ to[symbols[i]] = from[symbols[i]];
67
+ }
68
+ }
69
+ }
70
+ }
71
+ return to;
72
+ };
73
+ }
74
+ });
75
+
76
+ // node_modules/rxjs/internal/util/isFunction.js
77
+ var require_isFunction = __commonJS({
78
+ "node_modules/rxjs/internal/util/isFunction.js"(exports) {
79
+ "use strict";
80
+ Object.defineProperty(exports, "__esModule", { value: true });
81
+ function isFunction(x) {
82
+ return typeof x === "function";
83
+ }
84
+ exports.isFunction = isFunction;
85
+ }
86
+ });
87
+
88
+ // node_modules/rxjs/internal/config.js
89
+ var require_config = __commonJS({
90
+ "node_modules/rxjs/internal/config.js"(exports) {
91
+ "use strict";
92
+ Object.defineProperty(exports, "__esModule", { value: true });
93
+ var _enable_super_gross_mode_that_will_cause_bad_things = false;
94
+ exports.config = {
95
+ Promise: void 0,
96
+ set useDeprecatedSynchronousErrorHandling(value) {
97
+ if (value) {
98
+ var error = new Error();
99
+ console.warn("DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \n" + error.stack);
100
+ } else if (_enable_super_gross_mode_that_will_cause_bad_things) {
101
+ console.log("RxJS: Back to a better error behavior. Thank you. <3");
102
+ }
103
+ _enable_super_gross_mode_that_will_cause_bad_things = value;
104
+ },
105
+ get useDeprecatedSynchronousErrorHandling() {
106
+ return _enable_super_gross_mode_that_will_cause_bad_things;
107
+ }
108
+ };
109
+ }
110
+ });
111
+
112
+ // node_modules/rxjs/internal/util/hostReportError.js
113
+ var require_hostReportError = __commonJS({
114
+ "node_modules/rxjs/internal/util/hostReportError.js"(exports) {
115
+ "use strict";
116
+ Object.defineProperty(exports, "__esModule", { value: true });
117
+ function hostReportError(err) {
118
+ setTimeout(function() {
119
+ throw err;
120
+ }, 0);
121
+ }
122
+ exports.hostReportError = hostReportError;
123
+ }
124
+ });
125
+
126
+ // node_modules/rxjs/internal/Observer.js
127
+ var require_Observer = __commonJS({
128
+ "node_modules/rxjs/internal/Observer.js"(exports) {
129
+ "use strict";
130
+ Object.defineProperty(exports, "__esModule", { value: true });
131
+ var config_1 = require_config();
132
+ var hostReportError_1 = require_hostReportError();
133
+ exports.empty = {
134
+ closed: true,
135
+ next: function(value) {
136
+ },
137
+ error: function(err) {
138
+ if (config_1.config.useDeprecatedSynchronousErrorHandling) {
139
+ throw err;
140
+ } else {
141
+ hostReportError_1.hostReportError(err);
142
+ }
143
+ },
144
+ complete: function() {
145
+ }
146
+ };
147
+ }
148
+ });
149
+
150
+ // node_modules/rxjs/internal/util/isArray.js
151
+ var require_isArray = __commonJS({
152
+ "node_modules/rxjs/internal/util/isArray.js"(exports) {
153
+ "use strict";
154
+ Object.defineProperty(exports, "__esModule", { value: true });
155
+ exports.isArray = function() {
156
+ return Array.isArray || function(x) {
157
+ return x && typeof x.length === "number";
158
+ };
159
+ }();
160
+ }
161
+ });
162
+
163
+ // node_modules/rxjs/internal/util/isObject.js
164
+ var require_isObject = __commonJS({
165
+ "node_modules/rxjs/internal/util/isObject.js"(exports) {
166
+ "use strict";
167
+ Object.defineProperty(exports, "__esModule", { value: true });
168
+ function isObject(x) {
169
+ return x !== null && typeof x === "object";
170
+ }
171
+ exports.isObject = isObject;
172
+ }
173
+ });
174
+
175
+ // node_modules/rxjs/internal/util/UnsubscriptionError.js
176
+ var require_UnsubscriptionError = __commonJS({
177
+ "node_modules/rxjs/internal/util/UnsubscriptionError.js"(exports) {
178
+ "use strict";
179
+ Object.defineProperty(exports, "__esModule", { value: true });
180
+ var UnsubscriptionErrorImpl = function() {
181
+ function UnsubscriptionErrorImpl2(errors) {
182
+ Error.call(this);
183
+ this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function(err, i) {
184
+ return i + 1 + ") " + err.toString();
185
+ }).join("\n ") : "";
186
+ this.name = "UnsubscriptionError";
187
+ this.errors = errors;
188
+ return this;
189
+ }
190
+ UnsubscriptionErrorImpl2.prototype = Object.create(Error.prototype);
191
+ return UnsubscriptionErrorImpl2;
192
+ }();
193
+ exports.UnsubscriptionError = UnsubscriptionErrorImpl;
194
+ }
195
+ });
196
+
197
+ // node_modules/rxjs/internal/Subscription.js
198
+ var require_Subscription = __commonJS({
199
+ "node_modules/rxjs/internal/Subscription.js"(exports) {
200
+ "use strict";
201
+ Object.defineProperty(exports, "__esModule", { value: true });
202
+ var isArray_1 = require_isArray();
203
+ var isObject_1 = require_isObject();
204
+ var isFunction_1 = require_isFunction();
205
+ var UnsubscriptionError_1 = require_UnsubscriptionError();
206
+ var Subscription = function() {
207
+ function Subscription2(unsubscribe) {
208
+ this.closed = false;
209
+ this._parentOrParents = null;
210
+ this._subscriptions = null;
211
+ if (unsubscribe) {
212
+ this._ctorUnsubscribe = true;
213
+ this._unsubscribe = unsubscribe;
214
+ }
215
+ }
216
+ Subscription2.prototype.unsubscribe = function() {
217
+ var errors;
218
+ if (this.closed) {
219
+ return;
220
+ }
221
+ var _a = this, _parentOrParents = _a._parentOrParents, _ctorUnsubscribe = _a._ctorUnsubscribe, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions;
222
+ this.closed = true;
223
+ this._parentOrParents = null;
224
+ this._subscriptions = null;
225
+ if (_parentOrParents instanceof Subscription2) {
226
+ _parentOrParents.remove(this);
227
+ } else if (_parentOrParents !== null) {
228
+ for (var index = 0; index < _parentOrParents.length; ++index) {
229
+ var parent_1 = _parentOrParents[index];
230
+ parent_1.remove(this);
231
+ }
232
+ }
233
+ if (isFunction_1.isFunction(_unsubscribe)) {
234
+ if (_ctorUnsubscribe) {
235
+ this._unsubscribe = void 0;
236
+ }
237
+ try {
238
+ _unsubscribe.call(this);
239
+ } catch (e) {
240
+ errors = e instanceof UnsubscriptionError_1.UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e];
241
+ }
242
+ }
243
+ if (isArray_1.isArray(_subscriptions)) {
244
+ var index = -1;
245
+ var len = _subscriptions.length;
246
+ while (++index < len) {
247
+ var sub = _subscriptions[index];
248
+ if (isObject_1.isObject(sub)) {
249
+ try {
250
+ sub.unsubscribe();
251
+ } catch (e) {
252
+ errors = errors || [];
253
+ if (e instanceof UnsubscriptionError_1.UnsubscriptionError) {
254
+ errors = errors.concat(flattenUnsubscriptionErrors(e.errors));
255
+ } else {
256
+ errors.push(e);
257
+ }
258
+ }
259
+ }
260
+ }
261
+ }
262
+ if (errors) {
263
+ throw new UnsubscriptionError_1.UnsubscriptionError(errors);
264
+ }
265
+ };
266
+ Subscription2.prototype.add = function(teardown) {
267
+ var subscription = teardown;
268
+ if (!teardown) {
269
+ return Subscription2.EMPTY;
270
+ }
271
+ switch (typeof teardown) {
272
+ case "function":
273
+ subscription = new Subscription2(teardown);
274
+ case "object":
275
+ if (subscription === this || subscription.closed || typeof subscription.unsubscribe !== "function") {
276
+ return subscription;
277
+ } else if (this.closed) {
278
+ subscription.unsubscribe();
279
+ return subscription;
280
+ } else if (!(subscription instanceof Subscription2)) {
281
+ var tmp = subscription;
282
+ subscription = new Subscription2();
283
+ subscription._subscriptions = [tmp];
284
+ }
285
+ break;
286
+ default: {
287
+ throw new Error("unrecognized teardown " + teardown + " added to Subscription.");
288
+ }
289
+ }
290
+ var _parentOrParents = subscription._parentOrParents;
291
+ if (_parentOrParents === null) {
292
+ subscription._parentOrParents = this;
293
+ } else if (_parentOrParents instanceof Subscription2) {
294
+ if (_parentOrParents === this) {
295
+ return subscription;
296
+ }
297
+ subscription._parentOrParents = [_parentOrParents, this];
298
+ } else if (_parentOrParents.indexOf(this) === -1) {
299
+ _parentOrParents.push(this);
300
+ } else {
301
+ return subscription;
302
+ }
303
+ var subscriptions = this._subscriptions;
304
+ if (subscriptions === null) {
305
+ this._subscriptions = [subscription];
306
+ } else {
307
+ subscriptions.push(subscription);
308
+ }
309
+ return subscription;
310
+ };
311
+ Subscription2.prototype.remove = function(subscription) {
312
+ var subscriptions = this._subscriptions;
313
+ if (subscriptions) {
314
+ var subscriptionIndex = subscriptions.indexOf(subscription);
315
+ if (subscriptionIndex !== -1) {
316
+ subscriptions.splice(subscriptionIndex, 1);
317
+ }
318
+ }
319
+ };
320
+ Subscription2.EMPTY = function(empty) {
321
+ empty.closed = true;
322
+ return empty;
323
+ }(new Subscription2());
324
+ return Subscription2;
325
+ }();
326
+ exports.Subscription = Subscription;
327
+ function flattenUnsubscriptionErrors(errors) {
328
+ return errors.reduce(function(errs, err) {
329
+ return errs.concat(err instanceof UnsubscriptionError_1.UnsubscriptionError ? err.errors : err);
330
+ }, []);
331
+ }
332
+ }
333
+ });
334
+
335
+ // node_modules/rxjs/internal/symbol/rxSubscriber.js
336
+ var require_rxSubscriber = __commonJS({
337
+ "node_modules/rxjs/internal/symbol/rxSubscriber.js"(exports) {
338
+ "use strict";
339
+ Object.defineProperty(exports, "__esModule", { value: true });
340
+ exports.rxSubscriber = function() {
341
+ return typeof Symbol === "function" ? Symbol("rxSubscriber") : "@@rxSubscriber_" + Math.random();
342
+ }();
343
+ exports.$$rxSubscriber = exports.rxSubscriber;
344
+ }
345
+ });
346
+
347
+ // node_modules/rxjs/internal/Subscriber.js
348
+ var require_Subscriber = __commonJS({
349
+ "node_modules/rxjs/internal/Subscriber.js"(exports) {
350
+ "use strict";
351
+ var __extends = exports && exports.__extends || function() {
352
+ var extendStatics = function(d, b) {
353
+ extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
354
+ d2.__proto__ = b2;
355
+ } || function(d2, b2) {
356
+ for (var p in b2)
357
+ if (b2.hasOwnProperty(p))
358
+ d2[p] = b2[p];
359
+ };
360
+ return extendStatics(d, b);
361
+ };
362
+ return function(d, b) {
363
+ extendStatics(d, b);
364
+ function __() {
365
+ this.constructor = d;
366
+ }
367
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
368
+ };
369
+ }();
370
+ Object.defineProperty(exports, "__esModule", { value: true });
371
+ var isFunction_1 = require_isFunction();
372
+ var Observer_1 = require_Observer();
373
+ var Subscription_1 = require_Subscription();
374
+ var rxSubscriber_1 = require_rxSubscriber();
375
+ var config_1 = require_config();
376
+ var hostReportError_1 = require_hostReportError();
377
+ var Subscriber = function(_super) {
378
+ __extends(Subscriber2, _super);
379
+ function Subscriber2(destinationOrNext, error, complete) {
380
+ var _this = _super.call(this) || this;
381
+ _this.syncErrorValue = null;
382
+ _this.syncErrorThrown = false;
383
+ _this.syncErrorThrowable = false;
384
+ _this.isStopped = false;
385
+ switch (arguments.length) {
386
+ case 0:
387
+ _this.destination = Observer_1.empty;
388
+ break;
389
+ case 1:
390
+ if (!destinationOrNext) {
391
+ _this.destination = Observer_1.empty;
392
+ break;
393
+ }
394
+ if (typeof destinationOrNext === "object") {
395
+ if (destinationOrNext instanceof Subscriber2) {
396
+ _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;
397
+ _this.destination = destinationOrNext;
398
+ destinationOrNext.add(_this);
399
+ } else {
400
+ _this.syncErrorThrowable = true;
401
+ _this.destination = new SafeSubscriber(_this, destinationOrNext);
402
+ }
403
+ break;
404
+ }
405
+ default:
406
+ _this.syncErrorThrowable = true;
407
+ _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete);
408
+ break;
409
+ }
410
+ return _this;
411
+ }
412
+ Subscriber2.prototype[rxSubscriber_1.rxSubscriber] = function() {
413
+ return this;
414
+ };
415
+ Subscriber2.create = function(next, error, complete) {
416
+ var subscriber = new Subscriber2(next, error, complete);
417
+ subscriber.syncErrorThrowable = false;
418
+ return subscriber;
419
+ };
420
+ Subscriber2.prototype.next = function(value) {
421
+ if (!this.isStopped) {
422
+ this._next(value);
423
+ }
424
+ };
425
+ Subscriber2.prototype.error = function(err) {
426
+ if (!this.isStopped) {
427
+ this.isStopped = true;
428
+ this._error(err);
429
+ }
430
+ };
431
+ Subscriber2.prototype.complete = function() {
432
+ if (!this.isStopped) {
433
+ this.isStopped = true;
434
+ this._complete();
435
+ }
436
+ };
437
+ Subscriber2.prototype.unsubscribe = function() {
438
+ if (this.closed) {
439
+ return;
440
+ }
441
+ this.isStopped = true;
442
+ _super.prototype.unsubscribe.call(this);
443
+ };
444
+ Subscriber2.prototype._next = function(value) {
445
+ this.destination.next(value);
446
+ };
447
+ Subscriber2.prototype._error = function(err) {
448
+ this.destination.error(err);
449
+ this.unsubscribe();
450
+ };
451
+ Subscriber2.prototype._complete = function() {
452
+ this.destination.complete();
453
+ this.unsubscribe();
454
+ };
455
+ Subscriber2.prototype._unsubscribeAndRecycle = function() {
456
+ var _parentOrParents = this._parentOrParents;
457
+ this._parentOrParents = null;
458
+ this.unsubscribe();
459
+ this.closed = false;
460
+ this.isStopped = false;
461
+ this._parentOrParents = _parentOrParents;
462
+ return this;
463
+ };
464
+ return Subscriber2;
465
+ }(Subscription_1.Subscription);
466
+ exports.Subscriber = Subscriber;
467
+ var SafeSubscriber = function(_super) {
468
+ __extends(SafeSubscriber2, _super);
469
+ function SafeSubscriber2(_parentSubscriber, observerOrNext, error, complete) {
470
+ var _this = _super.call(this) || this;
471
+ _this._parentSubscriber = _parentSubscriber;
472
+ var next;
473
+ var context = _this;
474
+ if (isFunction_1.isFunction(observerOrNext)) {
475
+ next = observerOrNext;
476
+ } else if (observerOrNext) {
477
+ next = observerOrNext.next;
478
+ error = observerOrNext.error;
479
+ complete = observerOrNext.complete;
480
+ if (observerOrNext !== Observer_1.empty) {
481
+ context = Object.create(observerOrNext);
482
+ if (isFunction_1.isFunction(context.unsubscribe)) {
483
+ _this.add(context.unsubscribe.bind(context));
484
+ }
485
+ context.unsubscribe = _this.unsubscribe.bind(_this);
486
+ }
487
+ }
488
+ _this._context = context;
489
+ _this._next = next;
490
+ _this._error = error;
491
+ _this._complete = complete;
492
+ return _this;
493
+ }
494
+ SafeSubscriber2.prototype.next = function(value) {
495
+ if (!this.isStopped && this._next) {
496
+ var _parentSubscriber = this._parentSubscriber;
497
+ if (!config_1.config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
498
+ this.__tryOrUnsub(this._next, value);
499
+ } else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {
500
+ this.unsubscribe();
501
+ }
502
+ }
503
+ };
504
+ SafeSubscriber2.prototype.error = function(err) {
505
+ if (!this.isStopped) {
506
+ var _parentSubscriber = this._parentSubscriber;
507
+ var useDeprecatedSynchronousErrorHandling = config_1.config.useDeprecatedSynchronousErrorHandling;
508
+ if (this._error) {
509
+ if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
510
+ this.__tryOrUnsub(this._error, err);
511
+ this.unsubscribe();
512
+ } else {
513
+ this.__tryOrSetError(_parentSubscriber, this._error, err);
514
+ this.unsubscribe();
515
+ }
516
+ } else if (!_parentSubscriber.syncErrorThrowable) {
517
+ this.unsubscribe();
518
+ if (useDeprecatedSynchronousErrorHandling) {
519
+ throw err;
520
+ }
521
+ hostReportError_1.hostReportError(err);
522
+ } else {
523
+ if (useDeprecatedSynchronousErrorHandling) {
524
+ _parentSubscriber.syncErrorValue = err;
525
+ _parentSubscriber.syncErrorThrown = true;
526
+ } else {
527
+ hostReportError_1.hostReportError(err);
528
+ }
529
+ this.unsubscribe();
530
+ }
531
+ }
532
+ };
533
+ SafeSubscriber2.prototype.complete = function() {
534
+ var _this = this;
535
+ if (!this.isStopped) {
536
+ var _parentSubscriber = this._parentSubscriber;
537
+ if (this._complete) {
538
+ var wrappedComplete = function() {
539
+ return _this._complete.call(_this._context);
540
+ };
541
+ if (!config_1.config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
542
+ this.__tryOrUnsub(wrappedComplete);
543
+ this.unsubscribe();
544
+ } else {
545
+ this.__tryOrSetError(_parentSubscriber, wrappedComplete);
546
+ this.unsubscribe();
547
+ }
548
+ } else {
549
+ this.unsubscribe();
550
+ }
551
+ }
552
+ };
553
+ SafeSubscriber2.prototype.__tryOrUnsub = function(fn, value) {
554
+ try {
555
+ fn.call(this._context, value);
556
+ } catch (err) {
557
+ this.unsubscribe();
558
+ if (config_1.config.useDeprecatedSynchronousErrorHandling) {
559
+ throw err;
560
+ } else {
561
+ hostReportError_1.hostReportError(err);
562
+ }
563
+ }
564
+ };
565
+ SafeSubscriber2.prototype.__tryOrSetError = function(parent, fn, value) {
566
+ if (!config_1.config.useDeprecatedSynchronousErrorHandling) {
567
+ throw new Error("bad call");
568
+ }
569
+ try {
570
+ fn.call(this._context, value);
571
+ } catch (err) {
572
+ if (config_1.config.useDeprecatedSynchronousErrorHandling) {
573
+ parent.syncErrorValue = err;
574
+ parent.syncErrorThrown = true;
575
+ return true;
576
+ } else {
577
+ hostReportError_1.hostReportError(err);
578
+ return true;
579
+ }
580
+ }
581
+ return false;
582
+ };
583
+ SafeSubscriber2.prototype._unsubscribe = function() {
584
+ var _parentSubscriber = this._parentSubscriber;
585
+ this._context = null;
586
+ this._parentSubscriber = null;
587
+ _parentSubscriber.unsubscribe();
588
+ };
589
+ return SafeSubscriber2;
590
+ }(Subscriber);
591
+ exports.SafeSubscriber = SafeSubscriber;
592
+ }
593
+ });
594
+
595
+ // node_modules/rxjs/internal/util/canReportError.js
596
+ var require_canReportError = __commonJS({
597
+ "node_modules/rxjs/internal/util/canReportError.js"(exports) {
598
+ "use strict";
599
+ Object.defineProperty(exports, "__esModule", { value: true });
600
+ var Subscriber_1 = require_Subscriber();
601
+ function canReportError(observer) {
602
+ while (observer) {
603
+ var _a = observer, closed_1 = _a.closed, destination = _a.destination, isStopped = _a.isStopped;
604
+ if (closed_1 || isStopped) {
605
+ return false;
606
+ } else if (destination && destination instanceof Subscriber_1.Subscriber) {
607
+ observer = destination;
608
+ } else {
609
+ observer = null;
610
+ }
611
+ }
612
+ return true;
613
+ }
614
+ exports.canReportError = canReportError;
615
+ }
616
+ });
617
+
618
+ // node_modules/rxjs/internal/util/toSubscriber.js
619
+ var require_toSubscriber = __commonJS({
620
+ "node_modules/rxjs/internal/util/toSubscriber.js"(exports) {
621
+ "use strict";
622
+ Object.defineProperty(exports, "__esModule", { value: true });
623
+ var Subscriber_1 = require_Subscriber();
624
+ var rxSubscriber_1 = require_rxSubscriber();
625
+ var Observer_1 = require_Observer();
626
+ function toSubscriber(nextOrObserver, error, complete) {
627
+ if (nextOrObserver) {
628
+ if (nextOrObserver instanceof Subscriber_1.Subscriber) {
629
+ return nextOrObserver;
630
+ }
631
+ if (nextOrObserver[rxSubscriber_1.rxSubscriber]) {
632
+ return nextOrObserver[rxSubscriber_1.rxSubscriber]();
633
+ }
634
+ }
635
+ if (!nextOrObserver && !error && !complete) {
636
+ return new Subscriber_1.Subscriber(Observer_1.empty);
637
+ }
638
+ return new Subscriber_1.Subscriber(nextOrObserver, error, complete);
639
+ }
640
+ exports.toSubscriber = toSubscriber;
641
+ }
642
+ });
643
+
644
+ // node_modules/rxjs/internal/symbol/observable.js
645
+ var require_observable = __commonJS({
646
+ "node_modules/rxjs/internal/symbol/observable.js"(exports) {
647
+ "use strict";
648
+ Object.defineProperty(exports, "__esModule", { value: true });
649
+ exports.observable = function() {
650
+ return typeof Symbol === "function" && Symbol.observable || "@@observable";
651
+ }();
652
+ }
653
+ });
654
+
655
+ // node_modules/rxjs/internal/util/identity.js
656
+ var require_identity = __commonJS({
657
+ "node_modules/rxjs/internal/util/identity.js"(exports) {
658
+ "use strict";
659
+ Object.defineProperty(exports, "__esModule", { value: true });
660
+ function identity(x) {
661
+ return x;
662
+ }
663
+ exports.identity = identity;
664
+ }
665
+ });
666
+
667
+ // node_modules/rxjs/internal/util/pipe.js
668
+ var require_pipe = __commonJS({
669
+ "node_modules/rxjs/internal/util/pipe.js"(exports) {
670
+ "use strict";
671
+ Object.defineProperty(exports, "__esModule", { value: true });
672
+ var identity_1 = require_identity();
673
+ function pipe() {
674
+ var fns = [];
675
+ for (var _i = 0; _i < arguments.length; _i++) {
676
+ fns[_i] = arguments[_i];
677
+ }
678
+ return pipeFromArray(fns);
679
+ }
680
+ exports.pipe = pipe;
681
+ function pipeFromArray(fns) {
682
+ if (fns.length === 0) {
683
+ return identity_1.identity;
684
+ }
685
+ if (fns.length === 1) {
686
+ return fns[0];
687
+ }
688
+ return function piped(input) {
689
+ return fns.reduce(function(prev, fn) {
690
+ return fn(prev);
691
+ }, input);
692
+ };
693
+ }
694
+ exports.pipeFromArray = pipeFromArray;
695
+ }
696
+ });
697
+
698
+ // node_modules/rxjs/internal/Observable.js
699
+ var require_Observable = __commonJS({
700
+ "node_modules/rxjs/internal/Observable.js"(exports) {
701
+ "use strict";
702
+ Object.defineProperty(exports, "__esModule", { value: true });
703
+ var canReportError_1 = require_canReportError();
704
+ var toSubscriber_1 = require_toSubscriber();
705
+ var observable_1 = require_observable();
706
+ var pipe_1 = require_pipe();
707
+ var config_1 = require_config();
708
+ var Observable = function() {
709
+ function Observable2(subscribe) {
710
+ this._isScalar = false;
711
+ if (subscribe) {
712
+ this._subscribe = subscribe;
713
+ }
714
+ }
715
+ Observable2.prototype.lift = function(operator) {
716
+ var observable = new Observable2();
717
+ observable.source = this;
718
+ observable.operator = operator;
719
+ return observable;
720
+ };
721
+ Observable2.prototype.subscribe = function(observerOrNext, error, complete) {
722
+ var operator = this.operator;
723
+ var sink = toSubscriber_1.toSubscriber(observerOrNext, error, complete);
724
+ if (operator) {
725
+ sink.add(operator.call(sink, this.source));
726
+ } else {
727
+ sink.add(this.source || config_1.config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable ? this._subscribe(sink) : this._trySubscribe(sink));
728
+ }
729
+ if (config_1.config.useDeprecatedSynchronousErrorHandling) {
730
+ if (sink.syncErrorThrowable) {
731
+ sink.syncErrorThrowable = false;
732
+ if (sink.syncErrorThrown) {
733
+ throw sink.syncErrorValue;
734
+ }
735
+ }
736
+ }
737
+ return sink;
738
+ };
739
+ Observable2.prototype._trySubscribe = function(sink) {
740
+ try {
741
+ return this._subscribe(sink);
742
+ } catch (err) {
743
+ if (config_1.config.useDeprecatedSynchronousErrorHandling) {
744
+ sink.syncErrorThrown = true;
745
+ sink.syncErrorValue = err;
746
+ }
747
+ if (canReportError_1.canReportError(sink)) {
748
+ sink.error(err);
749
+ } else {
750
+ console.warn(err);
751
+ }
752
+ }
753
+ };
754
+ Observable2.prototype.forEach = function(next, promiseCtor) {
755
+ var _this = this;
756
+ promiseCtor = getPromiseCtor(promiseCtor);
757
+ return new promiseCtor(function(resolve, reject) {
758
+ var subscription;
759
+ subscription = _this.subscribe(function(value) {
760
+ try {
761
+ next(value);
762
+ } catch (err) {
763
+ reject(err);
764
+ if (subscription) {
765
+ subscription.unsubscribe();
766
+ }
767
+ }
768
+ }, reject, resolve);
769
+ });
770
+ };
771
+ Observable2.prototype._subscribe = function(subscriber) {
772
+ var source = this.source;
773
+ return source && source.subscribe(subscriber);
774
+ };
775
+ Observable2.prototype[observable_1.observable] = function() {
776
+ return this;
777
+ };
778
+ Observable2.prototype.pipe = function() {
779
+ var operations = [];
780
+ for (var _i = 0; _i < arguments.length; _i++) {
781
+ operations[_i] = arguments[_i];
782
+ }
783
+ if (operations.length === 0) {
784
+ return this;
785
+ }
786
+ return pipe_1.pipeFromArray(operations)(this);
787
+ };
788
+ Observable2.prototype.toPromise = function(promiseCtor) {
789
+ var _this = this;
790
+ promiseCtor = getPromiseCtor(promiseCtor);
791
+ return new promiseCtor(function(resolve, reject) {
792
+ var value;
793
+ _this.subscribe(function(x) {
794
+ return value = x;
795
+ }, function(err) {
796
+ return reject(err);
797
+ }, function() {
798
+ return resolve(value);
799
+ });
800
+ });
801
+ };
802
+ Observable2.create = function(subscribe) {
803
+ return new Observable2(subscribe);
804
+ };
805
+ return Observable2;
806
+ }();
807
+ exports.Observable = Observable;
808
+ function getPromiseCtor(promiseCtor) {
809
+ if (!promiseCtor) {
810
+ promiseCtor = config_1.config.Promise || Promise;
811
+ }
812
+ if (!promiseCtor) {
813
+ throw new Error("no Promise impl found");
814
+ }
815
+ return promiseCtor;
816
+ }
817
+ }
818
+ });
819
+
820
+ // node_modules/rxjs/internal/operators/filter.js
821
+ var require_filter = __commonJS({
822
+ "node_modules/rxjs/internal/operators/filter.js"(exports) {
823
+ "use strict";
824
+ var __extends = exports && exports.__extends || function() {
825
+ var extendStatics = function(d, b) {
826
+ extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
827
+ d2.__proto__ = b2;
828
+ } || function(d2, b2) {
829
+ for (var p in b2)
830
+ if (b2.hasOwnProperty(p))
831
+ d2[p] = b2[p];
832
+ };
833
+ return extendStatics(d, b);
834
+ };
835
+ return function(d, b) {
836
+ extendStatics(d, b);
837
+ function __() {
838
+ this.constructor = d;
839
+ }
840
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
841
+ };
842
+ }();
843
+ Object.defineProperty(exports, "__esModule", { value: true });
844
+ var Subscriber_1 = require_Subscriber();
845
+ function filter(predicate, thisArg) {
846
+ return function filterOperatorFunction(source) {
847
+ return source.lift(new FilterOperator(predicate, thisArg));
848
+ };
849
+ }
850
+ exports.filter = filter;
851
+ var FilterOperator = function() {
852
+ function FilterOperator2(predicate, thisArg) {
853
+ this.predicate = predicate;
854
+ this.thisArg = thisArg;
855
+ }
856
+ FilterOperator2.prototype.call = function(subscriber, source) {
857
+ return source.subscribe(new FilterSubscriber(subscriber, this.predicate, this.thisArg));
858
+ };
859
+ return FilterOperator2;
860
+ }();
861
+ var FilterSubscriber = function(_super) {
862
+ __extends(FilterSubscriber2, _super);
863
+ function FilterSubscriber2(destination, predicate, thisArg) {
864
+ var _this = _super.call(this, destination) || this;
865
+ _this.predicate = predicate;
866
+ _this.thisArg = thisArg;
867
+ _this.count = 0;
868
+ return _this;
869
+ }
870
+ FilterSubscriber2.prototype._next = function(value) {
871
+ var result;
872
+ try {
873
+ result = this.predicate.call(this.thisArg, value, this.count++);
874
+ } catch (err) {
875
+ this.destination.error(err);
876
+ return;
877
+ }
878
+ if (result) {
879
+ this.destination.next(value);
880
+ }
881
+ };
882
+ return FilterSubscriber2;
883
+ }(Subscriber_1.Subscriber);
884
+ }
885
+ });
886
+
887
+ // node_modules/rxjs/internal/operators/map.js
888
+ var require_map = __commonJS({
889
+ "node_modules/rxjs/internal/operators/map.js"(exports) {
890
+ "use strict";
891
+ var __extends = exports && exports.__extends || function() {
892
+ var extendStatics = function(d, b) {
893
+ extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
894
+ d2.__proto__ = b2;
895
+ } || function(d2, b2) {
896
+ for (var p in b2)
897
+ if (b2.hasOwnProperty(p))
898
+ d2[p] = b2[p];
899
+ };
900
+ return extendStatics(d, b);
901
+ };
902
+ return function(d, b) {
903
+ extendStatics(d, b);
904
+ function __() {
905
+ this.constructor = d;
906
+ }
907
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
908
+ };
909
+ }();
910
+ Object.defineProperty(exports, "__esModule", { value: true });
911
+ var Subscriber_1 = require_Subscriber();
912
+ function map(project, thisArg) {
913
+ return function mapOperation(source) {
914
+ if (typeof project !== "function") {
915
+ throw new TypeError("argument is not a function. Are you looking for `mapTo()`?");
916
+ }
917
+ return source.lift(new MapOperator(project, thisArg));
918
+ };
919
+ }
920
+ exports.map = map;
921
+ var MapOperator = function() {
922
+ function MapOperator2(project, thisArg) {
923
+ this.project = project;
924
+ this.thisArg = thisArg;
925
+ }
926
+ MapOperator2.prototype.call = function(subscriber, source) {
927
+ return source.subscribe(new MapSubscriber(subscriber, this.project, this.thisArg));
928
+ };
929
+ return MapOperator2;
930
+ }();
931
+ exports.MapOperator = MapOperator;
932
+ var MapSubscriber = function(_super) {
933
+ __extends(MapSubscriber2, _super);
934
+ function MapSubscriber2(destination, project, thisArg) {
935
+ var _this = _super.call(this, destination) || this;
936
+ _this.project = project;
937
+ _this.count = 0;
938
+ _this.thisArg = thisArg || _this;
939
+ return _this;
940
+ }
941
+ MapSubscriber2.prototype._next = function(value) {
942
+ var result;
943
+ try {
944
+ result = this.project.call(this.thisArg, value, this.count++);
945
+ } catch (err) {
946
+ this.destination.error(err);
947
+ return;
948
+ }
949
+ this.destination.next(result);
950
+ };
951
+ return MapSubscriber2;
952
+ }(Subscriber_1.Subscriber);
953
+ }
954
+ });
955
+
956
+ // src/util/observable.js
957
+ var require_observable2 = __commonJS({
958
+ "src/util/observable.js"(exports, module) {
959
+ var { Observable } = require_Observable();
960
+ var { filter } = require_filter();
961
+ var { map } = require_map();
962
+ module.exports = {
963
+ Observable,
964
+ filter,
965
+ map
966
+ };
967
+ }
968
+ });
969
+
970
+ // src/util/getSelection.js
971
+ var require_getSelection = __commonJS({
972
+ "src/util/getSelection.js"(exports, module) {
973
+ module.exports = function getSelection(sel) {
974
+ if (typeof sel === "string" || Array.isArray(sel)) {
975
+ return { id: sel };
976
+ }
977
+ if (sel && sel.query) {
978
+ return "params" in sel ? { query: sel.query, params: sel.params } : { query: sel.query };
979
+ }
980
+ const selectionOpts = [
981
+ "* Document ID (<docId>)",
982
+ "* Array of document IDs",
983
+ "* Object containing `query`"
984
+ ].join("\n");
985
+ throw new Error(`Unknown selection - must be one of:
986
+
987
+ ${selectionOpts}`);
988
+ };
989
+ }
990
+ });
991
+
992
+ // src/validators.js
993
+ var require_validators = __commonJS({
994
+ "src/validators.js"(exports) {
995
+ var VALID_ASSET_TYPES = ["image", "file"];
996
+ var VALID_INSERT_LOCATIONS = ["before", "after", "replace"];
997
+ exports.dataset = (name) => {
998
+ if (!/^(~[a-z0-9]{1}[-\w]{0,63}|[a-z0-9]{1}[-\w]{0,63})$/.test(name)) {
999
+ throw new Error("Datasets can only contain lowercase characters, numbers, underscores and dashes, and start with tilde, and be maximum 64 characters");
1000
+ }
1001
+ };
1002
+ exports.projectId = (id) => {
1003
+ if (!/^[-a-z0-9]+$/i.test(id)) {
1004
+ throw new Error("`projectId` can only contain only a-z, 0-9 and dashes");
1005
+ }
1006
+ };
1007
+ exports.validateAssetType = (type) => {
1008
+ if (VALID_ASSET_TYPES.indexOf(type) === -1) {
1009
+ throw new Error(`Invalid asset type: ${type}. Must be one of ${VALID_ASSET_TYPES.join(", ")}`);
1010
+ }
1011
+ };
1012
+ exports.validateObject = (op, val) => {
1013
+ if (val === null || typeof val !== "object" || Array.isArray(val)) {
1014
+ throw new Error(`${op}() takes an object of properties`);
1015
+ }
1016
+ };
1017
+ exports.requireDocumentId = (op, doc) => {
1018
+ if (!doc._id) {
1019
+ throw new Error(`${op}() requires that the document contains an ID ("_id" property)`);
1020
+ }
1021
+ exports.validateDocumentId(op, doc._id);
1022
+ };
1023
+ exports.validateDocumentId = (op, id) => {
1024
+ if (typeof id !== "string" || !/^[a-z0-9_.-]+$/i.test(id)) {
1025
+ throw new Error(`${op}(): "${id}" is not a valid document ID`);
1026
+ }
1027
+ };
1028
+ exports.validateInsert = (at, selector, items) => {
1029
+ const signature = "insert(at, selector, items)";
1030
+ if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
1031
+ const valid = VALID_INSERT_LOCATIONS.map((loc) => `"${loc}"`).join(", ");
1032
+ throw new Error(`${signature} takes an "at"-argument which is one of: ${valid}`);
1033
+ }
1034
+ if (typeof selector !== "string") {
1035
+ throw new Error(`${signature} takes a "selector"-argument which must be a string`);
1036
+ }
1037
+ if (!Array.isArray(items)) {
1038
+ throw new Error(`${signature} takes an "items"-argument which must be an array`);
1039
+ }
1040
+ };
1041
+ exports.hasDataset = (config) => {
1042
+ if (!config.dataset) {
1043
+ throw new Error("`dataset` must be provided to perform queries");
1044
+ }
1045
+ return config.dataset || "";
1046
+ };
1047
+ exports.requestTag = (tag) => {
1048
+ if (typeof tag !== "string" || !/^[a-z0-9._-]{1,75}$/i.test(tag)) {
1049
+ throw new Error(`Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long.`);
1050
+ }
1051
+ return tag;
1052
+ };
1053
+ }
1054
+ });
1055
+
1056
+ // src/data/patch.js
1057
+ var require_patch = __commonJS({
1058
+ "src/data/patch.js"(exports, module) {
1059
+ var assign = require_object_assign();
1060
+ var getSelection = require_getSelection();
1061
+ var validate = require_validators();
1062
+ var validateObject = validate.validateObject;
1063
+ var validateInsert = validate.validateInsert;
1064
+ function Patch(selection, operations = {}, client = null) {
1065
+ this.selection = selection;
1066
+ this.operations = assign({}, operations);
1067
+ this.client = client;
1068
+ }
1069
+ assign(Patch.prototype, {
1070
+ clone() {
1071
+ return new Patch(this.selection, assign({}, this.operations), this.client);
1072
+ },
1073
+ set(props) {
1074
+ return this._assign("set", props);
1075
+ },
1076
+ diffMatchPatch(props) {
1077
+ validateObject("diffMatchPatch", props);
1078
+ return this._assign("diffMatchPatch", props);
1079
+ },
1080
+ unset(attrs) {
1081
+ if (!Array.isArray(attrs)) {
1082
+ throw new Error("unset(attrs) takes an array of attributes to unset, non-array given");
1083
+ }
1084
+ this.operations = assign({}, this.operations, { unset: attrs });
1085
+ return this;
1086
+ },
1087
+ setIfMissing(props) {
1088
+ return this._assign("setIfMissing", props);
1089
+ },
1090
+ replace(props) {
1091
+ validateObject("replace", props);
1092
+ return this._set("set", { $: props });
1093
+ },
1094
+ inc(props) {
1095
+ return this._assign("inc", props);
1096
+ },
1097
+ dec(props) {
1098
+ return this._assign("dec", props);
1099
+ },
1100
+ insert(at, selector, items) {
1101
+ validateInsert(at, selector, items);
1102
+ return this._assign("insert", { [at]: selector, items });
1103
+ },
1104
+ append(selector, items) {
1105
+ return this.insert("after", `${selector}[-1]`, items);
1106
+ },
1107
+ prepend(selector, items) {
1108
+ return this.insert("before", `${selector}[0]`, items);
1109
+ },
1110
+ splice(selector, start, deleteCount, items) {
1111
+ const delAll = typeof deleteCount === "undefined" || deleteCount === -1;
1112
+ const startIndex = start < 0 ? start - 1 : start;
1113
+ const delCount = delAll ? -1 : Math.max(0, start + deleteCount);
1114
+ const delRange = startIndex < 0 && delCount >= 0 ? "" : delCount;
1115
+ const rangeSelector = `${selector}[${startIndex}:${delRange}]`;
1116
+ return this.insert("replace", rangeSelector, items || []);
1117
+ },
1118
+ ifRevisionId(rev) {
1119
+ this.operations.ifRevisionID = rev;
1120
+ return this;
1121
+ },
1122
+ serialize() {
1123
+ return assign(getSelection(this.selection), this.operations);
1124
+ },
1125
+ toJSON() {
1126
+ return this.serialize();
1127
+ },
1128
+ commit(options = {}) {
1129
+ if (!this.client) {
1130
+ throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
1131
+ }
1132
+ const returnFirst = typeof this.selection === "string";
1133
+ const opts = assign({ returnFirst, returnDocuments: true }, options);
1134
+ return this.client.mutate({ patch: this.serialize() }, opts);
1135
+ },
1136
+ reset() {
1137
+ this.operations = {};
1138
+ return this;
1139
+ },
1140
+ _set(op, props) {
1141
+ return this._assign(op, props, false);
1142
+ },
1143
+ _assign(op, props, merge = true) {
1144
+ validateObject(op, props);
1145
+ this.operations = assign({}, this.operations, {
1146
+ [op]: assign({}, merge && this.operations[op] || {}, props)
1147
+ });
1148
+ return this;
1149
+ }
1150
+ });
1151
+ module.exports = Patch;
1152
+ }
1153
+ });
1154
+
1155
+ // src/data/transaction.js
1156
+ var require_transaction = __commonJS({
1157
+ "src/data/transaction.js"(exports, module) {
1158
+ var assign = require_object_assign();
1159
+ var validators = require_validators();
1160
+ var Patch = require_patch();
1161
+ var defaultMutateOptions = { returnDocuments: false };
1162
+ function Transaction(operations = [], client, transactionId) {
1163
+ this.trxId = transactionId;
1164
+ this.operations = operations;
1165
+ this.client = client;
1166
+ }
1167
+ assign(Transaction.prototype, {
1168
+ clone() {
1169
+ return new Transaction(this.operations.slice(0), this.client, this.trxId);
1170
+ },
1171
+ create(doc) {
1172
+ validators.validateObject("create", doc);
1173
+ return this._add({ create: doc });
1174
+ },
1175
+ createIfNotExists(doc) {
1176
+ const op = "createIfNotExists";
1177
+ validators.validateObject(op, doc);
1178
+ validators.requireDocumentId(op, doc);
1179
+ return this._add({ [op]: doc });
1180
+ },
1181
+ createOrReplace(doc) {
1182
+ const op = "createOrReplace";
1183
+ validators.validateObject(op, doc);
1184
+ validators.requireDocumentId(op, doc);
1185
+ return this._add({ [op]: doc });
1186
+ },
1187
+ delete(documentId) {
1188
+ validators.validateDocumentId("delete", documentId);
1189
+ return this._add({ delete: { id: documentId } });
1190
+ },
1191
+ patch(documentId, patchOps) {
1192
+ const isBuilder = typeof patchOps === "function";
1193
+ const isPatch = documentId instanceof Patch;
1194
+ if (isPatch) {
1195
+ return this._add({ patch: documentId.serialize() });
1196
+ }
1197
+ if (isBuilder) {
1198
+ const patch = patchOps(new Patch(documentId, {}, this.client));
1199
+ if (!(patch instanceof Patch)) {
1200
+ throw new Error("function passed to `patch()` must return the patch");
1201
+ }
1202
+ return this._add({ patch: patch.serialize() });
1203
+ }
1204
+ return this._add({ patch: assign({ id: documentId }, patchOps) });
1205
+ },
1206
+ transactionId(id) {
1207
+ if (!id) {
1208
+ return this.trxId;
1209
+ }
1210
+ this.trxId = id;
1211
+ return this;
1212
+ },
1213
+ serialize() {
1214
+ return this.operations.slice();
1215
+ },
1216
+ toJSON() {
1217
+ return this.serialize();
1218
+ },
1219
+ commit(options) {
1220
+ if (!this.client) {
1221
+ throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
1222
+ }
1223
+ return this.client.mutate(this.serialize(), assign({ transactionId: this.trxId }, defaultMutateOptions, options || {}));
1224
+ },
1225
+ reset() {
1226
+ this.operations = [];
1227
+ return this;
1228
+ },
1229
+ _add(mut) {
1230
+ this.operations.push(mut);
1231
+ return this;
1232
+ }
1233
+ });
1234
+ module.exports = Transaction;
1235
+ }
1236
+ });
1237
+
1238
+ // src/data/encodeQueryString.js
1239
+ var require_encodeQueryString = __commonJS({
1240
+ "src/data/encodeQueryString.js"(exports, module) {
1241
+ var enc = encodeURIComponent;
1242
+ module.exports = ({ query, params = {}, options = {} }) => {
1243
+ const { tag, ...opts } = options;
1244
+ const q = `query=${enc(query)}`;
1245
+ const base = tag ? `?tag=${enc(tag)}&${q}` : `?${q}`;
1246
+ const qString = Object.keys(params).reduce((qs, param) => `${qs}&${enc(`$${param}`)}=${enc(JSON.stringify(params[param]))}`, base);
1247
+ return Object.keys(opts).reduce((qs, option) => {
1248
+ return options[option] ? `${qs}&${enc(option)}=${enc(options[option])}` : qs;
1249
+ }, qString);
1250
+ };
1251
+ }
1252
+ });
1253
+
1254
+ // node_modules/event-source-polyfill/src/eventsource.js
1255
+ var require_eventsource = __commonJS({
1256
+ "node_modules/event-source-polyfill/src/eventsource.js"(exports, module) {
1257
+ (function(global2) {
1258
+ "use strict";
1259
+ var setTimeout2 = global2.setTimeout;
1260
+ var clearTimeout2 = global2.clearTimeout;
1261
+ var XMLHttpRequest2 = global2.XMLHttpRequest;
1262
+ var XDomainRequest2 = global2.XDomainRequest;
1263
+ var ActiveXObject = global2.ActiveXObject;
1264
+ var NativeEventSource = global2.EventSource;
1265
+ var document = global2.document;
1266
+ var Promise2 = global2.Promise;
1267
+ var fetch2 = global2.fetch;
1268
+ var Response = global2.Response;
1269
+ var TextDecoder = global2.TextDecoder;
1270
+ var TextEncoder = global2.TextEncoder;
1271
+ var AbortController2 = global2.AbortController;
1272
+ if (typeof window !== "undefined" && typeof document !== "undefined" && !("readyState" in document) && document.body == null) {
1273
+ document.readyState = "loading";
1274
+ window.addEventListener("load", function(event) {
1275
+ document.readyState = "complete";
1276
+ }, false);
1277
+ }
1278
+ if (XMLHttpRequest2 == null && ActiveXObject != null) {
1279
+ XMLHttpRequest2 = function() {
1280
+ return new ActiveXObject("Microsoft.XMLHTTP");
1281
+ };
1282
+ }
1283
+ if (Object.create == void 0) {
1284
+ Object.create = function(C) {
1285
+ function F() {
1286
+ }
1287
+ F.prototype = C;
1288
+ return new F();
1289
+ };
1290
+ }
1291
+ if (!Date.now) {
1292
+ Date.now = function now() {
1293
+ return new Date().getTime();
1294
+ };
1295
+ }
1296
+ if (AbortController2 == void 0) {
1297
+ var originalFetch2 = fetch2;
1298
+ fetch2 = function(url, options) {
1299
+ var signal = options.signal;
1300
+ return originalFetch2(url, { headers: options.headers, credentials: options.credentials, cache: options.cache }).then(function(response) {
1301
+ var reader = response.body.getReader();
1302
+ signal._reader = reader;
1303
+ if (signal._aborted) {
1304
+ signal._reader.cancel();
1305
+ }
1306
+ return {
1307
+ status: response.status,
1308
+ statusText: response.statusText,
1309
+ headers: response.headers,
1310
+ body: {
1311
+ getReader: function() {
1312
+ return reader;
1313
+ }
1314
+ }
1315
+ };
1316
+ });
1317
+ };
1318
+ AbortController2 = function() {
1319
+ this.signal = {
1320
+ _reader: null,
1321
+ _aborted: false
1322
+ };
1323
+ this.abort = function() {
1324
+ if (this.signal._reader != null) {
1325
+ this.signal._reader.cancel();
1326
+ }
1327
+ this.signal._aborted = true;
1328
+ };
1329
+ };
1330
+ }
1331
+ function TextDecoderPolyfill() {
1332
+ this.bitsNeeded = 0;
1333
+ this.codePoint = 0;
1334
+ }
1335
+ TextDecoderPolyfill.prototype.decode = function(octets) {
1336
+ function valid(codePoint2, shift, octetsCount2) {
1337
+ if (octetsCount2 === 1) {
1338
+ return codePoint2 >= 128 >> shift && codePoint2 << shift <= 2047;
1339
+ }
1340
+ if (octetsCount2 === 2) {
1341
+ return codePoint2 >= 2048 >> shift && codePoint2 << shift <= 55295 || codePoint2 >= 57344 >> shift && codePoint2 << shift <= 65535;
1342
+ }
1343
+ if (octetsCount2 === 3) {
1344
+ return codePoint2 >= 65536 >> shift && codePoint2 << shift <= 1114111;
1345
+ }
1346
+ throw new Error();
1347
+ }
1348
+ function octetsCount(bitsNeeded2, codePoint2) {
1349
+ if (bitsNeeded2 === 6 * 1) {
1350
+ return codePoint2 >> 6 > 15 ? 3 : codePoint2 > 31 ? 2 : 1;
1351
+ }
1352
+ if (bitsNeeded2 === 6 * 2) {
1353
+ return codePoint2 > 15 ? 3 : 2;
1354
+ }
1355
+ if (bitsNeeded2 === 6 * 3) {
1356
+ return 3;
1357
+ }
1358
+ throw new Error();
1359
+ }
1360
+ var REPLACER = 65533;
1361
+ var string = "";
1362
+ var bitsNeeded = this.bitsNeeded;
1363
+ var codePoint = this.codePoint;
1364
+ for (var i = 0; i < octets.length; i += 1) {
1365
+ var octet = octets[i];
1366
+ if (bitsNeeded !== 0) {
1367
+ if (octet < 128 || octet > 191 || !valid(codePoint << 6 | octet & 63, bitsNeeded - 6, octetsCount(bitsNeeded, codePoint))) {
1368
+ bitsNeeded = 0;
1369
+ codePoint = REPLACER;
1370
+ string += String.fromCharCode(codePoint);
1371
+ }
1372
+ }
1373
+ if (bitsNeeded === 0) {
1374
+ if (octet >= 0 && octet <= 127) {
1375
+ bitsNeeded = 0;
1376
+ codePoint = octet;
1377
+ } else if (octet >= 192 && octet <= 223) {
1378
+ bitsNeeded = 6 * 1;
1379
+ codePoint = octet & 31;
1380
+ } else if (octet >= 224 && octet <= 239) {
1381
+ bitsNeeded = 6 * 2;
1382
+ codePoint = octet & 15;
1383
+ } else if (octet >= 240 && octet <= 247) {
1384
+ bitsNeeded = 6 * 3;
1385
+ codePoint = octet & 7;
1386
+ } else {
1387
+ bitsNeeded = 0;
1388
+ codePoint = REPLACER;
1389
+ }
1390
+ if (bitsNeeded !== 0 && !valid(codePoint, bitsNeeded, octetsCount(bitsNeeded, codePoint))) {
1391
+ bitsNeeded = 0;
1392
+ codePoint = REPLACER;
1393
+ }
1394
+ } else {
1395
+ bitsNeeded -= 6;
1396
+ codePoint = codePoint << 6 | octet & 63;
1397
+ }
1398
+ if (bitsNeeded === 0) {
1399
+ if (codePoint <= 65535) {
1400
+ string += String.fromCharCode(codePoint);
1401
+ } else {
1402
+ string += String.fromCharCode(55296 + (codePoint - 65535 - 1 >> 10));
1403
+ string += String.fromCharCode(56320 + (codePoint - 65535 - 1 & 1023));
1404
+ }
1405
+ }
1406
+ }
1407
+ this.bitsNeeded = bitsNeeded;
1408
+ this.codePoint = codePoint;
1409
+ return string;
1410
+ };
1411
+ var supportsStreamOption = function() {
1412
+ try {
1413
+ return new TextDecoder().decode(new TextEncoder().encode("test"), { stream: true }) === "test";
1414
+ } catch (error) {
1415
+ console.debug("TextDecoder does not support streaming option. Using polyfill instead: " + error);
1416
+ }
1417
+ return false;
1418
+ };
1419
+ if (TextDecoder == void 0 || TextEncoder == void 0 || !supportsStreamOption()) {
1420
+ TextDecoder = TextDecoderPolyfill;
1421
+ }
1422
+ var k = function() {
1423
+ };
1424
+ function XHRWrapper(xhr) {
1425
+ this.withCredentials = false;
1426
+ this.readyState = 0;
1427
+ this.status = 0;
1428
+ this.statusText = "";
1429
+ this.responseText = "";
1430
+ this.onprogress = k;
1431
+ this.onload = k;
1432
+ this.onerror = k;
1433
+ this.onreadystatechange = k;
1434
+ this._contentType = "";
1435
+ this._xhr = xhr;
1436
+ this._sendTimeout = 0;
1437
+ this._abort = k;
1438
+ }
1439
+ XHRWrapper.prototype.open = function(method, url) {
1440
+ this._abort(true);
1441
+ var that = this;
1442
+ var xhr = this._xhr;
1443
+ var state = 1;
1444
+ var timeout = 0;
1445
+ this._abort = function(silent) {
1446
+ if (that._sendTimeout !== 0) {
1447
+ clearTimeout2(that._sendTimeout);
1448
+ that._sendTimeout = 0;
1449
+ }
1450
+ if (state === 1 || state === 2 || state === 3) {
1451
+ state = 4;
1452
+ xhr.onload = k;
1453
+ xhr.onerror = k;
1454
+ xhr.onabort = k;
1455
+ xhr.onprogress = k;
1456
+ xhr.onreadystatechange = k;
1457
+ xhr.abort();
1458
+ if (timeout !== 0) {
1459
+ clearTimeout2(timeout);
1460
+ timeout = 0;
1461
+ }
1462
+ if (!silent) {
1463
+ that.readyState = 4;
1464
+ that.onabort(null);
1465
+ that.onreadystatechange();
1466
+ }
1467
+ }
1468
+ state = 0;
1469
+ };
1470
+ var onStart = function() {
1471
+ if (state === 1) {
1472
+ var status = 0;
1473
+ var statusText = "";
1474
+ var contentType = void 0;
1475
+ if (!("contentType" in xhr)) {
1476
+ try {
1477
+ status = xhr.status;
1478
+ statusText = xhr.statusText;
1479
+ contentType = xhr.getResponseHeader("Content-Type");
1480
+ } catch (error) {
1481
+ status = 0;
1482
+ statusText = "";
1483
+ contentType = void 0;
1484
+ }
1485
+ } else {
1486
+ status = 200;
1487
+ statusText = "OK";
1488
+ contentType = xhr.contentType;
1489
+ }
1490
+ if (status !== 0) {
1491
+ state = 2;
1492
+ that.readyState = 2;
1493
+ that.status = status;
1494
+ that.statusText = statusText;
1495
+ that._contentType = contentType;
1496
+ that.onreadystatechange();
1497
+ }
1498
+ }
1499
+ };
1500
+ var onProgress = function() {
1501
+ onStart();
1502
+ if (state === 2 || state === 3) {
1503
+ state = 3;
1504
+ var responseText = "";
1505
+ try {
1506
+ responseText = xhr.responseText;
1507
+ } catch (error) {
1508
+ }
1509
+ that.readyState = 3;
1510
+ that.responseText = responseText;
1511
+ that.onprogress();
1512
+ }
1513
+ };
1514
+ var onFinish = function(type, event) {
1515
+ if (event == null || event.preventDefault == null) {
1516
+ event = {
1517
+ preventDefault: k
1518
+ };
1519
+ }
1520
+ onProgress();
1521
+ if (state === 1 || state === 2 || state === 3) {
1522
+ state = 4;
1523
+ if (timeout !== 0) {
1524
+ clearTimeout2(timeout);
1525
+ timeout = 0;
1526
+ }
1527
+ that.readyState = 4;
1528
+ if (type === "load") {
1529
+ that.onload(event);
1530
+ } else if (type === "error") {
1531
+ that.onerror(event);
1532
+ } else if (type === "abort") {
1533
+ that.onabort(event);
1534
+ } else {
1535
+ throw new TypeError();
1536
+ }
1537
+ that.onreadystatechange();
1538
+ }
1539
+ };
1540
+ var onReadyStateChange = function(event) {
1541
+ if (xhr != void 0) {
1542
+ if (xhr.readyState === 4) {
1543
+ if (!("onload" in xhr) || !("onerror" in xhr) || !("onabort" in xhr)) {
1544
+ onFinish(xhr.responseText === "" ? "error" : "load", event);
1545
+ }
1546
+ } else if (xhr.readyState === 3) {
1547
+ if (!("onprogress" in xhr)) {
1548
+ onProgress();
1549
+ }
1550
+ } else if (xhr.readyState === 2) {
1551
+ onStart();
1552
+ }
1553
+ }
1554
+ };
1555
+ var onTimeout = function() {
1556
+ timeout = setTimeout2(function() {
1557
+ onTimeout();
1558
+ }, 500);
1559
+ if (xhr.readyState === 3) {
1560
+ onProgress();
1561
+ }
1562
+ };
1563
+ if ("onload" in xhr) {
1564
+ xhr.onload = function(event) {
1565
+ onFinish("load", event);
1566
+ };
1567
+ }
1568
+ if ("onerror" in xhr) {
1569
+ xhr.onerror = function(event) {
1570
+ onFinish("error", event);
1571
+ };
1572
+ }
1573
+ if ("onabort" in xhr) {
1574
+ xhr.onabort = function(event) {
1575
+ onFinish("abort", event);
1576
+ };
1577
+ }
1578
+ if ("onprogress" in xhr) {
1579
+ xhr.onprogress = onProgress;
1580
+ }
1581
+ if ("onreadystatechange" in xhr) {
1582
+ xhr.onreadystatechange = function(event) {
1583
+ onReadyStateChange(event);
1584
+ };
1585
+ }
1586
+ if ("contentType" in xhr || !("ontimeout" in XMLHttpRequest2.prototype)) {
1587
+ url += (url.indexOf("?") === -1 ? "?" : "&") + "padding=true";
1588
+ }
1589
+ xhr.open(method, url, true);
1590
+ if ("readyState" in xhr) {
1591
+ timeout = setTimeout2(function() {
1592
+ onTimeout();
1593
+ }, 0);
1594
+ }
1595
+ };
1596
+ XHRWrapper.prototype.abort = function() {
1597
+ this._abort(false);
1598
+ };
1599
+ XHRWrapper.prototype.getResponseHeader = function(name) {
1600
+ return this._contentType;
1601
+ };
1602
+ XHRWrapper.prototype.setRequestHeader = function(name, value) {
1603
+ var xhr = this._xhr;
1604
+ if ("setRequestHeader" in xhr) {
1605
+ xhr.setRequestHeader(name, value);
1606
+ }
1607
+ };
1608
+ XHRWrapper.prototype.getAllResponseHeaders = function() {
1609
+ return this._xhr.getAllResponseHeaders != void 0 ? this._xhr.getAllResponseHeaders() || "" : "";
1610
+ };
1611
+ XHRWrapper.prototype.send = function() {
1612
+ if ((!("ontimeout" in XMLHttpRequest2.prototype) || !("sendAsBinary" in XMLHttpRequest2.prototype) && !("mozAnon" in XMLHttpRequest2.prototype)) && document != void 0 && document.readyState != void 0 && document.readyState !== "complete") {
1613
+ var that = this;
1614
+ that._sendTimeout = setTimeout2(function() {
1615
+ that._sendTimeout = 0;
1616
+ that.send();
1617
+ }, 4);
1618
+ return;
1619
+ }
1620
+ var xhr = this._xhr;
1621
+ if ("withCredentials" in xhr) {
1622
+ xhr.withCredentials = this.withCredentials;
1623
+ }
1624
+ try {
1625
+ xhr.send(void 0);
1626
+ } catch (error1) {
1627
+ throw error1;
1628
+ }
1629
+ };
1630
+ function toLowerCase(name) {
1631
+ return name.replace(/[A-Z]/g, function(c) {
1632
+ return String.fromCharCode(c.charCodeAt(0) + 32);
1633
+ });
1634
+ }
1635
+ function HeadersPolyfill(all) {
1636
+ var map = /* @__PURE__ */ Object.create(null);
1637
+ var array = all.split("\r\n");
1638
+ for (var i = 0; i < array.length; i += 1) {
1639
+ var line = array[i];
1640
+ var parts = line.split(": ");
1641
+ var name = parts.shift();
1642
+ var value = parts.join(": ");
1643
+ map[toLowerCase(name)] = value;
1644
+ }
1645
+ this._map = map;
1646
+ }
1647
+ HeadersPolyfill.prototype.get = function(name) {
1648
+ return this._map[toLowerCase(name)];
1649
+ };
1650
+ if (XMLHttpRequest2 != null && XMLHttpRequest2.HEADERS_RECEIVED == null) {
1651
+ XMLHttpRequest2.HEADERS_RECEIVED = 2;
1652
+ }
1653
+ function XHRTransport() {
1654
+ }
1655
+ XHRTransport.prototype.open = function(xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
1656
+ xhr.open("GET", url);
1657
+ var offset = 0;
1658
+ xhr.onprogress = function() {
1659
+ var responseText = xhr.responseText;
1660
+ var chunk = responseText.slice(offset);
1661
+ offset += chunk.length;
1662
+ onProgressCallback(chunk);
1663
+ };
1664
+ xhr.onerror = function(event) {
1665
+ event.preventDefault();
1666
+ onFinishCallback(new Error("NetworkError"));
1667
+ };
1668
+ xhr.onload = function() {
1669
+ onFinishCallback(null);
1670
+ };
1671
+ xhr.onabort = function() {
1672
+ onFinishCallback(null);
1673
+ };
1674
+ xhr.onreadystatechange = function() {
1675
+ if (xhr.readyState === XMLHttpRequest2.HEADERS_RECEIVED) {
1676
+ var status = xhr.status;
1677
+ var statusText = xhr.statusText;
1678
+ var contentType = xhr.getResponseHeader("Content-Type");
1679
+ var headers2 = xhr.getAllResponseHeaders();
1680
+ onStartCallback(status, statusText, contentType, new HeadersPolyfill(headers2));
1681
+ }
1682
+ };
1683
+ xhr.withCredentials = withCredentials;
1684
+ for (var name in headers) {
1685
+ if (Object.prototype.hasOwnProperty.call(headers, name)) {
1686
+ xhr.setRequestHeader(name, headers[name]);
1687
+ }
1688
+ }
1689
+ xhr.send();
1690
+ return xhr;
1691
+ };
1692
+ function HeadersWrapper(headers) {
1693
+ this._headers = headers;
1694
+ }
1695
+ HeadersWrapper.prototype.get = function(name) {
1696
+ return this._headers.get(name);
1697
+ };
1698
+ function FetchTransport() {
1699
+ }
1700
+ FetchTransport.prototype.open = function(xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
1701
+ var reader = null;
1702
+ var controller = new AbortController2();
1703
+ var signal = controller.signal;
1704
+ var textDecoder = new TextDecoder();
1705
+ fetch2(url, {
1706
+ headers,
1707
+ credentials: withCredentials ? "include" : "same-origin",
1708
+ signal,
1709
+ cache: "no-store"
1710
+ }).then(function(response) {
1711
+ reader = response.body.getReader();
1712
+ onStartCallback(response.status, response.statusText, response.headers.get("Content-Type"), new HeadersWrapper(response.headers));
1713
+ return new Promise2(function(resolve, reject) {
1714
+ var readNextChunk = function() {
1715
+ reader.read().then(function(result) {
1716
+ if (result.done) {
1717
+ resolve(void 0);
1718
+ } else {
1719
+ var chunk = textDecoder.decode(result.value, { stream: true });
1720
+ onProgressCallback(chunk);
1721
+ readNextChunk();
1722
+ }
1723
+ })["catch"](function(error) {
1724
+ reject(error);
1725
+ });
1726
+ };
1727
+ readNextChunk();
1728
+ });
1729
+ })["catch"](function(error) {
1730
+ if (error.name === "AbortError") {
1731
+ return void 0;
1732
+ } else {
1733
+ return error;
1734
+ }
1735
+ }).then(function(error) {
1736
+ onFinishCallback(error);
1737
+ });
1738
+ return {
1739
+ abort: function() {
1740
+ if (reader != null) {
1741
+ reader.cancel();
1742
+ }
1743
+ controller.abort();
1744
+ }
1745
+ };
1746
+ };
1747
+ function EventTarget() {
1748
+ this._listeners = /* @__PURE__ */ Object.create(null);
1749
+ }
1750
+ function throwError(e) {
1751
+ setTimeout2(function() {
1752
+ throw e;
1753
+ }, 0);
1754
+ }
1755
+ EventTarget.prototype.dispatchEvent = function(event) {
1756
+ event.target = this;
1757
+ var typeListeners = this._listeners[event.type];
1758
+ if (typeListeners != void 0) {
1759
+ var length = typeListeners.length;
1760
+ for (var i = 0; i < length; i += 1) {
1761
+ var listener = typeListeners[i];
1762
+ try {
1763
+ if (typeof listener.handleEvent === "function") {
1764
+ listener.handleEvent(event);
1765
+ } else {
1766
+ listener.call(this, event);
1767
+ }
1768
+ } catch (e) {
1769
+ throwError(e);
1770
+ }
1771
+ }
1772
+ }
1773
+ };
1774
+ EventTarget.prototype.addEventListener = function(type, listener) {
1775
+ type = String(type);
1776
+ var listeners = this._listeners;
1777
+ var typeListeners = listeners[type];
1778
+ if (typeListeners == void 0) {
1779
+ typeListeners = [];
1780
+ listeners[type] = typeListeners;
1781
+ }
1782
+ var found = false;
1783
+ for (var i = 0; i < typeListeners.length; i += 1) {
1784
+ if (typeListeners[i] === listener) {
1785
+ found = true;
1786
+ }
1787
+ }
1788
+ if (!found) {
1789
+ typeListeners.push(listener);
1790
+ }
1791
+ };
1792
+ EventTarget.prototype.removeEventListener = function(type, listener) {
1793
+ type = String(type);
1794
+ var listeners = this._listeners;
1795
+ var typeListeners = listeners[type];
1796
+ if (typeListeners != void 0) {
1797
+ var filtered = [];
1798
+ for (var i = 0; i < typeListeners.length; i += 1) {
1799
+ if (typeListeners[i] !== listener) {
1800
+ filtered.push(typeListeners[i]);
1801
+ }
1802
+ }
1803
+ if (filtered.length === 0) {
1804
+ delete listeners[type];
1805
+ } else {
1806
+ listeners[type] = filtered;
1807
+ }
1808
+ }
1809
+ };
1810
+ function Event(type) {
1811
+ this.type = type;
1812
+ this.target = void 0;
1813
+ }
1814
+ function MessageEvent(type, options) {
1815
+ Event.call(this, type);
1816
+ this.data = options.data;
1817
+ this.lastEventId = options.lastEventId;
1818
+ }
1819
+ MessageEvent.prototype = Object.create(Event.prototype);
1820
+ function ConnectionEvent(type, options) {
1821
+ Event.call(this, type);
1822
+ this.status = options.status;
1823
+ this.statusText = options.statusText;
1824
+ this.headers = options.headers;
1825
+ }
1826
+ ConnectionEvent.prototype = Object.create(Event.prototype);
1827
+ function ErrorEvent(type, options) {
1828
+ Event.call(this, type);
1829
+ this.error = options.error;
1830
+ }
1831
+ ErrorEvent.prototype = Object.create(Event.prototype);
1832
+ var WAITING = -1;
1833
+ var CONNECTING = 0;
1834
+ var OPEN = 1;
1835
+ var CLOSED = 2;
1836
+ var AFTER_CR = -1;
1837
+ var FIELD_START = 0;
1838
+ var FIELD = 1;
1839
+ var VALUE_START = 2;
1840
+ var VALUE = 3;
1841
+ var contentTypeRegExp = /^text\/event\-stream(;.*)?$/i;
1842
+ var MINIMUM_DURATION = 1e3;
1843
+ var MAXIMUM_DURATION = 18e6;
1844
+ var parseDuration = function(value, def) {
1845
+ var n = value == null ? def : parseInt(value, 10);
1846
+ if (n !== n) {
1847
+ n = def;
1848
+ }
1849
+ return clampDuration(n);
1850
+ };
1851
+ var clampDuration = function(n) {
1852
+ return Math.min(Math.max(n, MINIMUM_DURATION), MAXIMUM_DURATION);
1853
+ };
1854
+ var fire = function(that, f, event) {
1855
+ try {
1856
+ if (typeof f === "function") {
1857
+ f.call(that, event);
1858
+ }
1859
+ } catch (e) {
1860
+ throwError(e);
1861
+ }
1862
+ };
1863
+ function EventSourcePolyfill(url, options) {
1864
+ EventTarget.call(this);
1865
+ options = options || {};
1866
+ this.onopen = void 0;
1867
+ this.onmessage = void 0;
1868
+ this.onerror = void 0;
1869
+ this.url = void 0;
1870
+ this.readyState = void 0;
1871
+ this.withCredentials = void 0;
1872
+ this.headers = void 0;
1873
+ this._close = void 0;
1874
+ start(this, url, options);
1875
+ }
1876
+ function getBestXHRTransport() {
1877
+ return XMLHttpRequest2 != void 0 && "withCredentials" in XMLHttpRequest2.prototype || XDomainRequest2 == void 0 ? new XMLHttpRequest2() : new XDomainRequest2();
1878
+ }
1879
+ var isFetchSupported = fetch2 != void 0 && Response != void 0 && "body" in Response.prototype;
1880
+ function start(es, url, options) {
1881
+ url = String(url);
1882
+ var withCredentials = Boolean(options.withCredentials);
1883
+ var lastEventIdQueryParameterName = options.lastEventIdQueryParameterName || "lastEventId";
1884
+ var initialRetry = clampDuration(1e3);
1885
+ var heartbeatTimeout = parseDuration(options.heartbeatTimeout, 45e3);
1886
+ var lastEventId = "";
1887
+ var retry = initialRetry;
1888
+ var wasActivity = false;
1889
+ var textLength = 0;
1890
+ var headers = options.headers || {};
1891
+ var TransportOption = options.Transport;
1892
+ var xhr = isFetchSupported && TransportOption == void 0 ? void 0 : new XHRWrapper(TransportOption != void 0 ? new TransportOption() : getBestXHRTransport());
1893
+ var transport = TransportOption != null && typeof TransportOption !== "string" ? new TransportOption() : xhr == void 0 ? new FetchTransport() : new XHRTransport();
1894
+ var abortController = void 0;
1895
+ var timeout = 0;
1896
+ var currentState = WAITING;
1897
+ var dataBuffer = "";
1898
+ var lastEventIdBuffer = "";
1899
+ var eventTypeBuffer = "";
1900
+ var textBuffer = "";
1901
+ var state = FIELD_START;
1902
+ var fieldStart = 0;
1903
+ var valueStart = 0;
1904
+ var onStart = function(status, statusText, contentType, headers2) {
1905
+ if (currentState === CONNECTING) {
1906
+ if (status === 200 && contentType != void 0 && contentTypeRegExp.test(contentType)) {
1907
+ currentState = OPEN;
1908
+ wasActivity = Date.now();
1909
+ retry = initialRetry;
1910
+ es.readyState = OPEN;
1911
+ var event = new ConnectionEvent("open", {
1912
+ status,
1913
+ statusText,
1914
+ headers: headers2
1915
+ });
1916
+ es.dispatchEvent(event);
1917
+ fire(es, es.onopen, event);
1918
+ } else {
1919
+ var message = "";
1920
+ if (status !== 200) {
1921
+ if (statusText) {
1922
+ statusText = statusText.replace(/\s+/g, " ");
1923
+ }
1924
+ message = "EventSource's response has a status " + status + " " + statusText + " that is not 200. Aborting the connection.";
1925
+ } else {
1926
+ message = "EventSource's response has a Content-Type specifying an unsupported type: " + (contentType == void 0 ? "-" : contentType.replace(/\s+/g, " ")) + ". Aborting the connection.";
1927
+ }
1928
+ close();
1929
+ var event = new ConnectionEvent("error", {
1930
+ status,
1931
+ statusText,
1932
+ headers: headers2
1933
+ });
1934
+ es.dispatchEvent(event);
1935
+ fire(es, es.onerror, event);
1936
+ console.error(message);
1937
+ }
1938
+ }
1939
+ };
1940
+ var onProgress = function(textChunk) {
1941
+ if (currentState === OPEN) {
1942
+ var n = -1;
1943
+ for (var i = 0; i < textChunk.length; i += 1) {
1944
+ var c = textChunk.charCodeAt(i);
1945
+ if (c === "\n".charCodeAt(0) || c === "\r".charCodeAt(0)) {
1946
+ n = i;
1947
+ }
1948
+ }
1949
+ var chunk = (n !== -1 ? textBuffer : "") + textChunk.slice(0, n + 1);
1950
+ textBuffer = (n === -1 ? textBuffer : "") + textChunk.slice(n + 1);
1951
+ if (textChunk !== "") {
1952
+ wasActivity = Date.now();
1953
+ textLength += textChunk.length;
1954
+ }
1955
+ for (var position = 0; position < chunk.length; position += 1) {
1956
+ var c = chunk.charCodeAt(position);
1957
+ if (state === AFTER_CR && c === "\n".charCodeAt(0)) {
1958
+ state = FIELD_START;
1959
+ } else {
1960
+ if (state === AFTER_CR) {
1961
+ state = FIELD_START;
1962
+ }
1963
+ if (c === "\r".charCodeAt(0) || c === "\n".charCodeAt(0)) {
1964
+ if (state !== FIELD_START) {
1965
+ if (state === FIELD) {
1966
+ valueStart = position + 1;
1967
+ }
1968
+ var field = chunk.slice(fieldStart, valueStart - 1);
1969
+ var value = chunk.slice(valueStart + (valueStart < position && chunk.charCodeAt(valueStart) === " ".charCodeAt(0) ? 1 : 0), position);
1970
+ if (field === "data") {
1971
+ dataBuffer += "\n";
1972
+ dataBuffer += value;
1973
+ } else if (field === "id") {
1974
+ lastEventIdBuffer = value;
1975
+ } else if (field === "event") {
1976
+ eventTypeBuffer = value;
1977
+ } else if (field === "retry") {
1978
+ initialRetry = parseDuration(value, initialRetry);
1979
+ retry = initialRetry;
1980
+ } else if (field === "heartbeatTimeout") {
1981
+ heartbeatTimeout = parseDuration(value, heartbeatTimeout);
1982
+ if (timeout !== 0) {
1983
+ clearTimeout2(timeout);
1984
+ timeout = setTimeout2(function() {
1985
+ onTimeout();
1986
+ }, heartbeatTimeout);
1987
+ }
1988
+ }
1989
+ }
1990
+ if (state === FIELD_START) {
1991
+ if (dataBuffer !== "") {
1992
+ lastEventId = lastEventIdBuffer;
1993
+ if (eventTypeBuffer === "") {
1994
+ eventTypeBuffer = "message";
1995
+ }
1996
+ var event = new MessageEvent(eventTypeBuffer, {
1997
+ data: dataBuffer.slice(1),
1998
+ lastEventId: lastEventIdBuffer
1999
+ });
2000
+ es.dispatchEvent(event);
2001
+ if (eventTypeBuffer === "open") {
2002
+ fire(es, es.onopen, event);
2003
+ } else if (eventTypeBuffer === "message") {
2004
+ fire(es, es.onmessage, event);
2005
+ } else if (eventTypeBuffer === "error") {
2006
+ fire(es, es.onerror, event);
2007
+ }
2008
+ if (currentState === CLOSED) {
2009
+ return;
2010
+ }
2011
+ }
2012
+ dataBuffer = "";
2013
+ eventTypeBuffer = "";
2014
+ }
2015
+ state = c === "\r".charCodeAt(0) ? AFTER_CR : FIELD_START;
2016
+ } else {
2017
+ if (state === FIELD_START) {
2018
+ fieldStart = position;
2019
+ state = FIELD;
2020
+ }
2021
+ if (state === FIELD) {
2022
+ if (c === ":".charCodeAt(0)) {
2023
+ valueStart = position + 1;
2024
+ state = VALUE_START;
2025
+ }
2026
+ } else if (state === VALUE_START) {
2027
+ state = VALUE;
2028
+ }
2029
+ }
2030
+ }
2031
+ }
2032
+ }
2033
+ };
2034
+ var onFinish = function(error) {
2035
+ if (currentState === OPEN || currentState === CONNECTING) {
2036
+ currentState = WAITING;
2037
+ if (timeout !== 0) {
2038
+ clearTimeout2(timeout);
2039
+ timeout = 0;
2040
+ }
2041
+ timeout = setTimeout2(function() {
2042
+ onTimeout();
2043
+ }, retry);
2044
+ retry = clampDuration(Math.min(initialRetry * 16, retry * 2));
2045
+ es.readyState = CONNECTING;
2046
+ var event = new ErrorEvent("error", { error });
2047
+ es.dispatchEvent(event);
2048
+ fire(es, es.onerror, event);
2049
+ if (error != void 0) {
2050
+ console.error(error);
2051
+ }
2052
+ }
2053
+ };
2054
+ var close = function() {
2055
+ currentState = CLOSED;
2056
+ if (abortController != void 0) {
2057
+ abortController.abort();
2058
+ abortController = void 0;
2059
+ }
2060
+ if (timeout !== 0) {
2061
+ clearTimeout2(timeout);
2062
+ timeout = 0;
2063
+ }
2064
+ es.readyState = CLOSED;
2065
+ };
2066
+ var onTimeout = function() {
2067
+ timeout = 0;
2068
+ if (currentState !== WAITING) {
2069
+ if (!wasActivity && abortController != void 0) {
2070
+ onFinish(new Error("No activity within " + heartbeatTimeout + " milliseconds. " + (currentState === CONNECTING ? "No response received." : textLength + " chars received.") + " Reconnecting."));
2071
+ if (abortController != void 0) {
2072
+ abortController.abort();
2073
+ abortController = void 0;
2074
+ }
2075
+ } else {
2076
+ var nextHeartbeat = Math.max((wasActivity || Date.now()) + heartbeatTimeout - Date.now(), 1);
2077
+ wasActivity = false;
2078
+ timeout = setTimeout2(function() {
2079
+ onTimeout();
2080
+ }, nextHeartbeat);
2081
+ }
2082
+ return;
2083
+ }
2084
+ wasActivity = false;
2085
+ textLength = 0;
2086
+ timeout = setTimeout2(function() {
2087
+ onTimeout();
2088
+ }, heartbeatTimeout);
2089
+ currentState = CONNECTING;
2090
+ dataBuffer = "";
2091
+ eventTypeBuffer = "";
2092
+ lastEventIdBuffer = lastEventId;
2093
+ textBuffer = "";
2094
+ fieldStart = 0;
2095
+ valueStart = 0;
2096
+ state = FIELD_START;
2097
+ var requestURL = url;
2098
+ if (url.slice(0, 5) !== "data:" && url.slice(0, 5) !== "blob:") {
2099
+ if (lastEventId !== "") {
2100
+ var i = url.indexOf("?");
2101
+ requestURL = i === -1 ? url : url.slice(0, i + 1) + url.slice(i + 1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g, function(p, paramName) {
2102
+ return paramName === lastEventIdQueryParameterName ? "" : p;
2103
+ });
2104
+ requestURL += (url.indexOf("?") === -1 ? "?" : "&") + lastEventIdQueryParameterName + "=" + encodeURIComponent(lastEventId);
2105
+ }
2106
+ }
2107
+ var withCredentials2 = es.withCredentials;
2108
+ var requestHeaders = {};
2109
+ requestHeaders["Accept"] = "text/event-stream";
2110
+ var headers2 = es.headers;
2111
+ if (headers2 != void 0) {
2112
+ for (var name in headers2) {
2113
+ if (Object.prototype.hasOwnProperty.call(headers2, name)) {
2114
+ requestHeaders[name] = headers2[name];
2115
+ }
2116
+ }
2117
+ }
2118
+ try {
2119
+ abortController = transport.open(xhr, onStart, onProgress, onFinish, requestURL, withCredentials2, requestHeaders);
2120
+ } catch (error) {
2121
+ close();
2122
+ throw error;
2123
+ }
2124
+ };
2125
+ es.url = url;
2126
+ es.readyState = CONNECTING;
2127
+ es.withCredentials = withCredentials;
2128
+ es.headers = headers;
2129
+ es._close = close;
2130
+ onTimeout();
2131
+ }
2132
+ EventSourcePolyfill.prototype = Object.create(EventTarget.prototype);
2133
+ EventSourcePolyfill.prototype.CONNECTING = CONNECTING;
2134
+ EventSourcePolyfill.prototype.OPEN = OPEN;
2135
+ EventSourcePolyfill.prototype.CLOSED = CLOSED;
2136
+ EventSourcePolyfill.prototype.close = function() {
2137
+ this._close();
2138
+ };
2139
+ EventSourcePolyfill.CONNECTING = CONNECTING;
2140
+ EventSourcePolyfill.OPEN = OPEN;
2141
+ EventSourcePolyfill.CLOSED = CLOSED;
2142
+ EventSourcePolyfill.prototype.withCredentials = void 0;
2143
+ var R = NativeEventSource;
2144
+ if (XMLHttpRequest2 != void 0 && (NativeEventSource == void 0 || !("withCredentials" in NativeEventSource.prototype))) {
2145
+ R = EventSourcePolyfill;
2146
+ }
2147
+ (function(factory) {
2148
+ if (typeof module === "object" && typeof module.exports === "object") {
2149
+ var v = factory(exports);
2150
+ if (v !== void 0)
2151
+ module.exports = v;
2152
+ } else if (typeof define === "function" && define.amd) {
2153
+ define(["exports"], factory);
2154
+ } else {
2155
+ factory(global2);
2156
+ }
2157
+ })(function(exports2) {
2158
+ exports2.EventSourcePolyfill = EventSourcePolyfill;
2159
+ exports2.NativeEventSource = NativeEventSource;
2160
+ exports2.EventSource = R;
2161
+ });
2162
+ })(typeof globalThis === "undefined" ? typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : exports : globalThis);
2163
+ }
2164
+ });
2165
+
2166
+ // node_modules/@sanity/eventsource/browser.js
2167
+ var require_browser = __commonJS({
2168
+ "node_modules/@sanity/eventsource/browser.js"(exports, module) {
2169
+ var evs = require_eventsource();
2170
+ module.exports = evs.EventSourcePolyfill;
2171
+ }
2172
+ });
2173
+
2174
+ // src/util/pick.js
2175
+ var require_pick = __commonJS({
2176
+ "src/util/pick.js"(exports, module) {
2177
+ module.exports = (obj, props) => props.reduce((selection, prop) => {
2178
+ if (typeof obj[prop] === "undefined") {
2179
+ return selection;
2180
+ }
2181
+ selection[prop] = obj[prop];
2182
+ return selection;
2183
+ }, {});
2184
+ }
2185
+ });
2186
+
2187
+ // src/util/defaults.js
2188
+ var require_defaults = __commonJS({
2189
+ "src/util/defaults.js"(exports, module) {
2190
+ module.exports = (obj, defaults) => Object.keys(defaults).concat(Object.keys(obj)).reduce((target, prop) => {
2191
+ target[prop] = typeof obj[prop] === "undefined" ? defaults[prop] : obj[prop];
2192
+ return target;
2193
+ }, {});
2194
+ }
2195
+ });
2196
+
2197
+ // src/data/listen.js
2198
+ var require_listen = __commonJS({
2199
+ "src/data/listen.js"(exports, module) {
2200
+ var assign = require_object_assign();
2201
+ var { Observable } = require_observable2();
2202
+ var polyfilledEventSource = require_browser();
2203
+ var pick = require_pick();
2204
+ var defaults = require_defaults();
2205
+ var encodeQueryString = require_encodeQueryString();
2206
+ var MAX_URL_LENGTH = 16e3 - 1200;
2207
+ var EventSource = polyfilledEventSource;
2208
+ var possibleOptions = [
2209
+ "includePreviousRevision",
2210
+ "includeResult",
2211
+ "visibility",
2212
+ "effectFormat",
2213
+ "tag"
2214
+ ];
2215
+ var defaultOptions = {
2216
+ includeResult: true
2217
+ };
2218
+ module.exports = function listen(query, params, opts = {}) {
2219
+ const { url, token, withCredentials, requestTagPrefix } = this.clientConfig;
2220
+ const tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag;
2221
+ const options = { ...defaults(opts, defaultOptions), tag };
2222
+ const listenOpts = pick(options, possibleOptions);
2223
+ const qs = encodeQueryString({ query, params, options: listenOpts, tag });
2224
+ const uri = `${url}${this.getDataUrl("listen", qs)}`;
2225
+ if (uri.length > MAX_URL_LENGTH) {
2226
+ return new Observable((observer) => observer.error(new Error("Query too large for listener")));
2227
+ }
2228
+ const listenFor = options.events ? options.events : ["mutation"];
2229
+ const shouldEmitReconnect = listenFor.indexOf("reconnect") !== -1;
2230
+ const esOptions = {};
2231
+ if (token || withCredentials) {
2232
+ esOptions.withCredentials = true;
2233
+ }
2234
+ if (token) {
2235
+ esOptions.headers = {
2236
+ Authorization: `Bearer ${token}`
2237
+ };
2238
+ }
2239
+ return new Observable((observer) => {
2240
+ let es = getEventSource();
2241
+ let reconnectTimer;
2242
+ let stopped = false;
2243
+ function onError() {
2244
+ if (stopped) {
2245
+ return;
2246
+ }
2247
+ emitReconnect();
2248
+ if (stopped) {
2249
+ return;
2250
+ }
2251
+ if (es.readyState === EventSource.CLOSED) {
2252
+ unsubscribe();
2253
+ clearTimeout(reconnectTimer);
2254
+ reconnectTimer = setTimeout(open, 100);
2255
+ }
2256
+ }
2257
+ function onChannelError(err) {
2258
+ observer.error(cooerceError(err));
2259
+ }
2260
+ function onMessage(evt) {
2261
+ const event = parseEvent(evt);
2262
+ return event instanceof Error ? observer.error(event) : observer.next(event);
2263
+ }
2264
+ function onDisconnect(evt) {
2265
+ stopped = true;
2266
+ unsubscribe();
2267
+ observer.complete();
2268
+ }
2269
+ function unsubscribe() {
2270
+ es.removeEventListener("error", onError, false);
2271
+ es.removeEventListener("channelError", onChannelError, false);
2272
+ es.removeEventListener("disconnect", onDisconnect, false);
2273
+ listenFor.forEach((type) => es.removeEventListener(type, onMessage, false));
2274
+ es.close();
2275
+ }
2276
+ function emitReconnect() {
2277
+ if (shouldEmitReconnect) {
2278
+ observer.next({ type: "reconnect" });
2279
+ }
2280
+ }
2281
+ function getEventSource() {
2282
+ const evs = new EventSource(uri, esOptions);
2283
+ evs.addEventListener("error", onError, false);
2284
+ evs.addEventListener("channelError", onChannelError, false);
2285
+ evs.addEventListener("disconnect", onDisconnect, false);
2286
+ listenFor.forEach((type) => evs.addEventListener(type, onMessage, false));
2287
+ return evs;
2288
+ }
2289
+ function open() {
2290
+ es = getEventSource();
2291
+ }
2292
+ function stop() {
2293
+ stopped = true;
2294
+ unsubscribe();
2295
+ }
2296
+ return stop;
2297
+ });
2298
+ };
2299
+ function parseEvent(event) {
2300
+ try {
2301
+ const data = event.data && JSON.parse(event.data) || {};
2302
+ return assign({ type: event.type }, data);
2303
+ } catch (err) {
2304
+ return err;
2305
+ }
2306
+ }
2307
+ function cooerceError(err) {
2308
+ if (err instanceof Error) {
2309
+ return err;
2310
+ }
2311
+ const evt = parseEvent(err);
2312
+ return evt instanceof Error ? evt : new Error(extractErrorMessage(evt));
2313
+ }
2314
+ function extractErrorMessage(err) {
2315
+ if (!err.error) {
2316
+ return err.message || "Unknown listener error";
2317
+ }
2318
+ if (err.error.description) {
2319
+ return err.error.description;
2320
+ }
2321
+ return typeof err.error === "string" ? err.error : JSON.stringify(err.error, null, 2);
2322
+ }
2323
+ }
2324
+ });
2325
+
2326
+ // src/data/dataMethods.js
2327
+ var require_dataMethods = __commonJS({
2328
+ "src/data/dataMethods.js"(exports, module) {
2329
+ var assign = require_object_assign();
2330
+ var { map, filter } = require_observable2();
2331
+ var validators = require_validators();
2332
+ var getSelection = require_getSelection();
2333
+ var encodeQueryString = require_encodeQueryString();
2334
+ var Transaction = require_transaction();
2335
+ var Patch = require_patch();
2336
+ var listen = require_listen();
2337
+ var excludeFalsey = (param, defValue) => {
2338
+ const value = typeof param === "undefined" ? defValue : param;
2339
+ return param === false ? void 0 : value;
2340
+ };
2341
+ var getMutationQuery = (options = {}) => {
2342
+ return {
2343
+ dryRun: options.dryRun,
2344
+ returnIds: true,
2345
+ returnDocuments: excludeFalsey(options.returnDocuments, true),
2346
+ visibility: options.visibility || "sync",
2347
+ autoGenerateArrayKeys: options.autoGenerateArrayKeys,
2348
+ skipCrossDatasetReferenceValidation: options.skipCrossDatasetReferenceValidation
2349
+ };
2350
+ };
2351
+ var isResponse = (event) => event.type === "response";
2352
+ var getBody = (event) => event.body;
2353
+ var indexBy = (docs, attr) => docs.reduce((indexed, doc) => {
2354
+ indexed[attr(doc)] = doc;
2355
+ return indexed;
2356
+ }, /* @__PURE__ */ Object.create(null));
2357
+ var toPromise = (observable) => observable.toPromise();
2358
+ var getQuerySizeLimit = 11264;
2359
+ module.exports = {
2360
+ listen,
2361
+ getDataUrl(operation, path) {
2362
+ const config = this.clientConfig;
2363
+ const catalog = validators.hasDataset(config);
2364
+ const baseUri = `/${operation}/${catalog}`;
2365
+ const uri = path ? `${baseUri}/${path}` : baseUri;
2366
+ return `/data${uri}`.replace(/\/($|\?)/, "$1");
2367
+ },
2368
+ fetch(query, params, options = {}) {
2369
+ const mapResponse = options.filterResponse === false ? (res) => res : (res) => res.result;
2370
+ const observable = this._dataRequest("query", { query, params }, options).pipe(map(mapResponse));
2371
+ return this.isPromiseAPI() ? toPromise(observable) : observable;
2372
+ },
2373
+ getDocument(id, opts = {}) {
2374
+ const options = { uri: this.getDataUrl("doc", id), json: true, tag: opts.tag };
2375
+ const observable = this._requestObservable(options).pipe(filter(isResponse), map((event) => event.body.documents && event.body.documents[0]));
2376
+ return this.isPromiseAPI() ? toPromise(observable) : observable;
2377
+ },
2378
+ getDocuments(ids, opts = {}) {
2379
+ const options = { uri: this.getDataUrl("doc", ids.join(",")), json: true, tag: opts.tag };
2380
+ const observable = this._requestObservable(options).pipe(filter(isResponse), map((event) => {
2381
+ const indexed = indexBy(event.body.documents || [], (doc) => doc._id);
2382
+ return ids.map((id) => indexed[id] || null);
2383
+ }));
2384
+ return this.isPromiseAPI() ? toPromise(observable) : observable;
2385
+ },
2386
+ create(doc, options) {
2387
+ return this._create(doc, "create", options);
2388
+ },
2389
+ createIfNotExists(doc, options) {
2390
+ validators.requireDocumentId("createIfNotExists", doc);
2391
+ return this._create(doc, "createIfNotExists", options);
2392
+ },
2393
+ createOrReplace(doc, options) {
2394
+ validators.requireDocumentId("createOrReplace", doc);
2395
+ return this._create(doc, "createOrReplace", options);
2396
+ },
2397
+ patch(selector, operations) {
2398
+ return new Patch(selector, operations, this);
2399
+ },
2400
+ delete(selection, options) {
2401
+ return this.dataRequest("mutate", { mutations: [{ delete: getSelection(selection) }] }, options);
2402
+ },
2403
+ mutate(mutations, options) {
2404
+ const mut = mutations instanceof Patch || mutations instanceof Transaction ? mutations.serialize() : mutations;
2405
+ const muts = Array.isArray(mut) ? mut : [mut];
2406
+ const transactionId = options && options.transactionId;
2407
+ return this.dataRequest("mutate", { mutations: muts, transactionId }, options);
2408
+ },
2409
+ transaction(operations) {
2410
+ return new Transaction(operations, this);
2411
+ },
2412
+ dataRequest(endpoint, body, options = {}) {
2413
+ const request = this._dataRequest(endpoint, body, options);
2414
+ return this.isPromiseAPI() ? toPromise(request) : request;
2415
+ },
2416
+ _dataRequest(endpoint, body, options = {}) {
2417
+ const isMutation = endpoint === "mutate";
2418
+ const isQuery = endpoint === "query";
2419
+ const strQuery = !isMutation && encodeQueryString(body);
2420
+ const useGet = !isMutation && strQuery.length < getQuerySizeLimit;
2421
+ const stringQuery = useGet ? strQuery : "";
2422
+ const returnFirst = options.returnFirst;
2423
+ const { timeout, token, tag, headers } = options;
2424
+ const uri = this.getDataUrl(endpoint, stringQuery);
2425
+ const reqOptions = {
2426
+ method: useGet ? "GET" : "POST",
2427
+ uri,
2428
+ json: true,
2429
+ body: useGet ? void 0 : body,
2430
+ query: isMutation && getMutationQuery(options),
2431
+ timeout,
2432
+ headers,
2433
+ token,
2434
+ tag,
2435
+ canUseCdn: isQuery
2436
+ };
2437
+ return this._requestObservable(reqOptions).pipe(filter(isResponse), map(getBody), map((res) => {
2438
+ if (!isMutation) {
2439
+ return res;
2440
+ }
2441
+ const results = res.results || [];
2442
+ if (options.returnDocuments) {
2443
+ return returnFirst ? results[0] && results[0].document : results.map((mut) => mut.document);
2444
+ }
2445
+ const key = returnFirst ? "documentId" : "documentIds";
2446
+ const ids = returnFirst ? results[0] && results[0].id : results.map((mut) => mut.id);
2447
+ return {
2448
+ transactionId: res.transactionId,
2449
+ results,
2450
+ [key]: ids
2451
+ };
2452
+ }));
2453
+ },
2454
+ _create(doc, op, options = {}) {
2455
+ const mutation = { [op]: doc };
2456
+ const opts = assign({ returnFirst: true, returnDocuments: true }, options);
2457
+ return this.dataRequest("mutate", { mutations: [mutation] }, opts);
2458
+ }
2459
+ };
2460
+ }
2461
+ });
2462
+
2463
+ // src/datasets/datasetsClient.js
2464
+ var require_datasetsClient = __commonJS({
2465
+ "src/datasets/datasetsClient.js"(exports, module) {
2466
+ var assign = require_object_assign();
2467
+ var validate = require_validators();
2468
+ function DatasetsClient(client) {
2469
+ this.request = client.request.bind(client);
2470
+ }
2471
+ assign(DatasetsClient.prototype, {
2472
+ create(name, options) {
2473
+ return this._modify("PUT", name, options);
2474
+ },
2475
+ edit(name, options) {
2476
+ return this._modify("PATCH", name, options);
2477
+ },
2478
+ delete(name) {
2479
+ return this._modify("DELETE", name);
2480
+ },
2481
+ list() {
2482
+ return this.request({ uri: "/datasets" });
2483
+ },
2484
+ _modify(method, name, body) {
2485
+ validate.dataset(name);
2486
+ return this.request({ method, uri: `/datasets/${name}`, body });
2487
+ }
2488
+ });
2489
+ module.exports = DatasetsClient;
2490
+ }
2491
+ });
2492
+
2493
+ // src/projects/projectsClient.js
2494
+ var require_projectsClient = __commonJS({
2495
+ "src/projects/projectsClient.js"(exports, module) {
2496
+ var assign = require_object_assign();
2497
+ function ProjectsClient(client) {
2498
+ this.client = client;
2499
+ }
2500
+ assign(ProjectsClient.prototype, {
2501
+ list() {
2502
+ return this.client.request({ uri: "/projects" });
2503
+ },
2504
+ getById(id) {
2505
+ return this.client.request({ uri: `/projects/${id}` });
2506
+ }
2507
+ });
2508
+ module.exports = ProjectsClient;
2509
+ }
2510
+ });
2511
+
2512
+ // src/http/queryString.js
2513
+ var require_queryString = __commonJS({
2514
+ "src/http/queryString.js"(exports, module) {
2515
+ module.exports = (params) => {
2516
+ const qs = [];
2517
+ for (const key in params) {
2518
+ if (params.hasOwnProperty(key)) {
2519
+ qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`);
2520
+ }
2521
+ }
2522
+ return qs.length > 0 ? `?${qs.join("&")}` : "";
2523
+ };
2524
+ }
2525
+ });
2526
+
2527
+ // src/assets/assetsClient.js
2528
+ var require_assetsClient = __commonJS({
2529
+ "src/assets/assetsClient.js"(exports, module) {
2530
+ var assign = require_object_assign();
2531
+ var { map, filter } = require_observable2();
2532
+ var queryString = require_queryString();
2533
+ var validators = require_validators();
2534
+ function AssetsClient(client) {
2535
+ this.client = client;
2536
+ }
2537
+ function optionsFromFile(opts, file) {
2538
+ if (typeof window === "undefined" || !(file instanceof window.File)) {
2539
+ return opts;
2540
+ }
2541
+ return assign({
2542
+ filename: opts.preserveFilename === false ? void 0 : file.name,
2543
+ contentType: file.type
2544
+ }, opts);
2545
+ }
2546
+ assign(AssetsClient.prototype, {
2547
+ upload(assetType, body, opts = {}) {
2548
+ validators.validateAssetType(assetType);
2549
+ let meta = opts.extract || void 0;
2550
+ if (meta && !meta.length) {
2551
+ meta = ["none"];
2552
+ }
2553
+ const dataset = validators.hasDataset(this.client.clientConfig);
2554
+ const assetEndpoint = assetType === "image" ? "images" : "files";
2555
+ const options = optionsFromFile(opts, body);
2556
+ const { tag, label, title, description, creditLine, filename, source } = options;
2557
+ const query = {
2558
+ label,
2559
+ title,
2560
+ description,
2561
+ filename,
2562
+ meta,
2563
+ creditLine
2564
+ };
2565
+ if (source) {
2566
+ query.sourceId = source.id;
2567
+ query.sourceName = source.name;
2568
+ query.sourceUrl = source.url;
2569
+ }
2570
+ const observable = this.client._requestObservable({
2571
+ tag,
2572
+ method: "POST",
2573
+ timeout: options.timeout || 0,
2574
+ uri: `/assets/${assetEndpoint}/${dataset}`,
2575
+ headers: options.contentType ? { "Content-Type": options.contentType } : {},
2576
+ query,
2577
+ body
2578
+ });
2579
+ return this.client.isPromiseAPI() ? observable.pipe(filter((event) => event.type === "response"), map((event) => event.body.document)).toPromise() : observable;
2580
+ },
2581
+ delete(type, id) {
2582
+ console.warn("client.assets.delete() is deprecated, please use client.delete(<document-id>)");
2583
+ let docId = id || "";
2584
+ if (!/^(image|file)-/.test(docId)) {
2585
+ docId = `${type}-${docId}`;
2586
+ } else if (type._id) {
2587
+ docId = type._id;
2588
+ }
2589
+ validators.hasDataset(this.client.clientConfig);
2590
+ return this.client.delete(docId);
2591
+ },
2592
+ getImageUrl(ref, query) {
2593
+ const id = ref._ref || ref;
2594
+ if (typeof id !== "string") {
2595
+ throw new Error("getImageUrl() needs either an object with a _ref, or a string with an asset document ID");
2596
+ }
2597
+ if (!/^image-[A-Za-z0-9_]+-\d+x\d+-[a-z]{1,5}$/.test(id)) {
2598
+ throw new Error(`Unsupported asset ID "${id}". URL generation only works for auto-generated IDs.`);
2599
+ }
2600
+ const [, assetId, size, format] = id.split("-");
2601
+ validators.hasDataset(this.client.clientConfig);
2602
+ const { projectId, dataset } = this.client.clientConfig;
2603
+ const qs = query ? queryString(query) : "";
2604
+ return `https://cdn.sanity.io/images/${projectId}/${dataset}/${assetId}-${size}.${format}${qs}`;
2605
+ }
2606
+ });
2607
+ module.exports = AssetsClient;
2608
+ }
2609
+ });
2610
+
2611
+ // src/users/usersClient.js
2612
+ var require_usersClient = __commonJS({
2613
+ "src/users/usersClient.js"(exports, module) {
2614
+ var assign = require_object_assign();
2615
+ function UsersClient(client) {
2616
+ this.client = client;
2617
+ }
2618
+ assign(UsersClient.prototype, {
2619
+ getById(id) {
2620
+ return this.client.request({ uri: `/users/${id}` });
2621
+ }
2622
+ });
2623
+ module.exports = UsersClient;
2624
+ }
2625
+ });
2626
+
2627
+ // src/auth/authClient.js
2628
+ var require_authClient = __commonJS({
2629
+ "src/auth/authClient.js"(exports, module) {
2630
+ var assign = require_object_assign();
2631
+ function AuthClient(client) {
2632
+ this.client = client;
2633
+ }
2634
+ assign(AuthClient.prototype, {
2635
+ getLoginProviders() {
2636
+ return this.client.request({ uri: "/auth/providers" });
2637
+ },
2638
+ logout() {
2639
+ return this.client.request({ uri: "/auth/logout", method: "POST" });
2640
+ }
2641
+ });
2642
+ module.exports = AuthClient;
2643
+ }
2644
+ });
2645
+
2646
+ // node_modules/nano-pubsub/index.js
2647
+ var require_nano_pubsub = __commonJS({
2648
+ "node_modules/nano-pubsub/index.js"(exports, module) {
2649
+ module.exports = function Pubsub() {
2650
+ var subscribers = [];
2651
+ return {
2652
+ subscribe,
2653
+ publish
2654
+ };
2655
+ function subscribe(subscriber) {
2656
+ subscribers.push(subscriber);
2657
+ return function unsubscribe() {
2658
+ var idx = subscribers.indexOf(subscriber);
2659
+ if (idx > -1) {
2660
+ subscribers.splice(idx, 1);
2661
+ }
2662
+ };
2663
+ }
2664
+ function publish() {
2665
+ for (var i = 0; i < subscribers.length; i++) {
2666
+ subscribers[i].apply(null, arguments);
2667
+ }
2668
+ }
2669
+ };
2670
+ }
2671
+ });
2672
+
2673
+ // node_modules/get-it/lib/util/middlewareReducer.js
2674
+ var require_middlewareReducer = __commonJS({
2675
+ "node_modules/get-it/lib/util/middlewareReducer.js"(exports, module) {
2676
+ "use strict";
2677
+ module.exports = function(middleware) {
2678
+ var applyMiddleware = function applyMiddleware2(hook, defaultValue) {
2679
+ var bailEarly = hook === "onError";
2680
+ var value = defaultValue;
2681
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
2682
+ args[_key - 2] = arguments[_key];
2683
+ }
2684
+ for (var i = 0; i < middleware[hook].length; i++) {
2685
+ var handler = middleware[hook][i];
2686
+ value = handler.apply(void 0, [value].concat(args));
2687
+ if (bailEarly && !value) {
2688
+ break;
2689
+ }
2690
+ }
2691
+ return value;
2692
+ };
2693
+ return applyMiddleware;
2694
+ };
2695
+ }
2696
+ });
2697
+
2698
+ // node_modules/requires-port/index.js
2699
+ var require_requires_port = __commonJS({
2700
+ "node_modules/requires-port/index.js"(exports, module) {
2701
+ "use strict";
2702
+ module.exports = function required(port, protocol) {
2703
+ protocol = protocol.split(":")[0];
2704
+ port = +port;
2705
+ if (!port)
2706
+ return false;
2707
+ switch (protocol) {
2708
+ case "http":
2709
+ case "ws":
2710
+ return port !== 80;
2711
+ case "https":
2712
+ case "wss":
2713
+ return port !== 443;
2714
+ case "ftp":
2715
+ return port !== 21;
2716
+ case "gopher":
2717
+ return port !== 70;
2718
+ case "file":
2719
+ return false;
2720
+ }
2721
+ return port !== 0;
2722
+ };
2723
+ }
2724
+ });
2725
+
2726
+ // node_modules/querystringify/index.js
2727
+ var require_querystringify = __commonJS({
2728
+ "node_modules/querystringify/index.js"(exports) {
2729
+ "use strict";
2730
+ var has = Object.prototype.hasOwnProperty;
2731
+ var undef;
2732
+ function decode(input) {
2733
+ try {
2734
+ return decodeURIComponent(input.replace(/\+/g, " "));
2735
+ } catch (e) {
2736
+ return null;
2737
+ }
2738
+ }
2739
+ function encode(input) {
2740
+ try {
2741
+ return encodeURIComponent(input);
2742
+ } catch (e) {
2743
+ return null;
2744
+ }
2745
+ }
2746
+ function querystring(query) {
2747
+ var parser = /([^=?#&]+)=?([^&]*)/g, result = {}, part;
2748
+ while (part = parser.exec(query)) {
2749
+ var key = decode(part[1]), value = decode(part[2]);
2750
+ if (key === null || value === null || key in result)
2751
+ continue;
2752
+ result[key] = value;
2753
+ }
2754
+ return result;
2755
+ }
2756
+ function querystringify(obj, prefix) {
2757
+ prefix = prefix || "";
2758
+ var pairs = [], value, key;
2759
+ if (typeof prefix !== "string")
2760
+ prefix = "?";
2761
+ for (key in obj) {
2762
+ if (has.call(obj, key)) {
2763
+ value = obj[key];
2764
+ if (!value && (value === null || value === undef || isNaN(value))) {
2765
+ value = "";
2766
+ }
2767
+ key = encode(key);
2768
+ value = encode(value);
2769
+ if (key === null || value === null)
2770
+ continue;
2771
+ pairs.push(key + "=" + value);
2772
+ }
2773
+ }
2774
+ return pairs.length ? prefix + pairs.join("&") : "";
2775
+ }
2776
+ exports.stringify = querystringify;
2777
+ exports.parse = querystring;
2778
+ }
2779
+ });
2780
+
2781
+ // node_modules/url-parse/index.js
2782
+ var require_url_parse = __commonJS({
2783
+ "node_modules/url-parse/index.js"(exports, module) {
2784
+ "use strict";
2785
+ var required = require_requires_port();
2786
+ var qs = require_querystringify();
2787
+ var controlOrWhitespace = /^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/;
2788
+ var CRHTLF = /[\n\r\t]/g;
2789
+ var slashes = /^[A-Za-z][A-Za-z0-9+-.]*:\/\//;
2790
+ var port = /:\d+$/;
2791
+ var protocolre = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i;
2792
+ var windowsDriveLetter = /^[a-zA-Z]:/;
2793
+ function trimLeft(str) {
2794
+ return (str ? str : "").toString().replace(controlOrWhitespace, "");
2795
+ }
2796
+ var rules = [
2797
+ ["#", "hash"],
2798
+ ["?", "query"],
2799
+ function sanitize(address, url) {
2800
+ return isSpecial(url.protocol) ? address.replace(/\\/g, "/") : address;
2801
+ },
2802
+ ["/", "pathname"],
2803
+ ["@", "auth", 1],
2804
+ [NaN, "host", void 0, 1, 1],
2805
+ [/:(\d*)$/, "port", void 0, 1],
2806
+ [NaN, "hostname", void 0, 1, 1]
2807
+ ];
2808
+ var ignore = { hash: 1, query: 1 };
2809
+ function lolcation(loc) {
2810
+ var globalVar;
2811
+ if (typeof window !== "undefined")
2812
+ globalVar = window;
2813
+ else if (typeof global !== "undefined")
2814
+ globalVar = global;
2815
+ else if (typeof self !== "undefined")
2816
+ globalVar = self;
2817
+ else
2818
+ globalVar = {};
2819
+ var location = globalVar.location || {};
2820
+ loc = loc || location;
2821
+ var finaldestination = {}, type = typeof loc, key;
2822
+ if (loc.protocol === "blob:") {
2823
+ finaldestination = new Url(unescape(loc.pathname), {});
2824
+ } else if (type === "string") {
2825
+ finaldestination = new Url(loc, {});
2826
+ for (key in ignore)
2827
+ delete finaldestination[key];
2828
+ } else if (type === "object") {
2829
+ for (key in loc) {
2830
+ if (key in ignore)
2831
+ continue;
2832
+ finaldestination[key] = loc[key];
2833
+ }
2834
+ if (finaldestination.slashes === void 0) {
2835
+ finaldestination.slashes = slashes.test(loc.href);
2836
+ }
2837
+ }
2838
+ return finaldestination;
2839
+ }
2840
+ function isSpecial(scheme) {
2841
+ return scheme === "file:" || scheme === "ftp:" || scheme === "http:" || scheme === "https:" || scheme === "ws:" || scheme === "wss:";
2842
+ }
2843
+ function extractProtocol(address, location) {
2844
+ address = trimLeft(address);
2845
+ address = address.replace(CRHTLF, "");
2846
+ location = location || {};
2847
+ var match = protocolre.exec(address);
2848
+ var protocol = match[1] ? match[1].toLowerCase() : "";
2849
+ var forwardSlashes = !!match[2];
2850
+ var otherSlashes = !!match[3];
2851
+ var slashesCount = 0;
2852
+ var rest;
2853
+ if (forwardSlashes) {
2854
+ if (otherSlashes) {
2855
+ rest = match[2] + match[3] + match[4];
2856
+ slashesCount = match[2].length + match[3].length;
2857
+ } else {
2858
+ rest = match[2] + match[4];
2859
+ slashesCount = match[2].length;
2860
+ }
2861
+ } else {
2862
+ if (otherSlashes) {
2863
+ rest = match[3] + match[4];
2864
+ slashesCount = match[3].length;
2865
+ } else {
2866
+ rest = match[4];
2867
+ }
2868
+ }
2869
+ if (protocol === "file:") {
2870
+ if (slashesCount >= 2) {
2871
+ rest = rest.slice(2);
2872
+ }
2873
+ } else if (isSpecial(protocol)) {
2874
+ rest = match[4];
2875
+ } else if (protocol) {
2876
+ if (forwardSlashes) {
2877
+ rest = rest.slice(2);
2878
+ }
2879
+ } else if (slashesCount >= 2 && isSpecial(location.protocol)) {
2880
+ rest = match[4];
2881
+ }
2882
+ return {
2883
+ protocol,
2884
+ slashes: forwardSlashes || isSpecial(protocol),
2885
+ slashesCount,
2886
+ rest
2887
+ };
2888
+ }
2889
+ function resolve(relative, base) {
2890
+ if (relative === "")
2891
+ return base;
2892
+ var path = (base || "/").split("/").slice(0, -1).concat(relative.split("/")), i = path.length, last = path[i - 1], unshift = false, up = 0;
2893
+ while (i--) {
2894
+ if (path[i] === ".") {
2895
+ path.splice(i, 1);
2896
+ } else if (path[i] === "..") {
2897
+ path.splice(i, 1);
2898
+ up++;
2899
+ } else if (up) {
2900
+ if (i === 0)
2901
+ unshift = true;
2902
+ path.splice(i, 1);
2903
+ up--;
2904
+ }
2905
+ }
2906
+ if (unshift)
2907
+ path.unshift("");
2908
+ if (last === "." || last === "..")
2909
+ path.push("");
2910
+ return path.join("/");
2911
+ }
2912
+ function Url(address, location, parser) {
2913
+ address = trimLeft(address);
2914
+ address = address.replace(CRHTLF, "");
2915
+ if (!(this instanceof Url)) {
2916
+ return new Url(address, location, parser);
2917
+ }
2918
+ var relative, extracted, parse, instruction, index, key, instructions = rules.slice(), type = typeof location, url = this, i = 0;
2919
+ if (type !== "object" && type !== "string") {
2920
+ parser = location;
2921
+ location = null;
2922
+ }
2923
+ if (parser && typeof parser !== "function")
2924
+ parser = qs.parse;
2925
+ location = lolcation(location);
2926
+ extracted = extractProtocol(address || "", location);
2927
+ relative = !extracted.protocol && !extracted.slashes;
2928
+ url.slashes = extracted.slashes || relative && location.slashes;
2929
+ url.protocol = extracted.protocol || location.protocol || "";
2930
+ address = extracted.rest;
2931
+ if (extracted.protocol === "file:" && (extracted.slashesCount !== 2 || windowsDriveLetter.test(address)) || !extracted.slashes && (extracted.protocol || extracted.slashesCount < 2 || !isSpecial(url.protocol))) {
2932
+ instructions[3] = [/(.*)/, "pathname"];
2933
+ }
2934
+ for (; i < instructions.length; i++) {
2935
+ instruction = instructions[i];
2936
+ if (typeof instruction === "function") {
2937
+ address = instruction(address, url);
2938
+ continue;
2939
+ }
2940
+ parse = instruction[0];
2941
+ key = instruction[1];
2942
+ if (parse !== parse) {
2943
+ url[key] = address;
2944
+ } else if (typeof parse === "string") {
2945
+ index = parse === "@" ? address.lastIndexOf(parse) : address.indexOf(parse);
2946
+ if (~index) {
2947
+ if (typeof instruction[2] === "number") {
2948
+ url[key] = address.slice(0, index);
2949
+ address = address.slice(index + instruction[2]);
2950
+ } else {
2951
+ url[key] = address.slice(index);
2952
+ address = address.slice(0, index);
2953
+ }
2954
+ }
2955
+ } else if (index = parse.exec(address)) {
2956
+ url[key] = index[1];
2957
+ address = address.slice(0, index.index);
2958
+ }
2959
+ url[key] = url[key] || (relative && instruction[3] ? location[key] || "" : "");
2960
+ if (instruction[4])
2961
+ url[key] = url[key].toLowerCase();
2962
+ }
2963
+ if (parser)
2964
+ url.query = parser(url.query);
2965
+ if (relative && location.slashes && url.pathname.charAt(0) !== "/" && (url.pathname !== "" || location.pathname !== "")) {
2966
+ url.pathname = resolve(url.pathname, location.pathname);
2967
+ }
2968
+ if (url.pathname.charAt(0) !== "/" && isSpecial(url.protocol)) {
2969
+ url.pathname = "/" + url.pathname;
2970
+ }
2971
+ if (!required(url.port, url.protocol)) {
2972
+ url.host = url.hostname;
2973
+ url.port = "";
2974
+ }
2975
+ url.username = url.password = "";
2976
+ if (url.auth) {
2977
+ index = url.auth.indexOf(":");
2978
+ if (~index) {
2979
+ url.username = url.auth.slice(0, index);
2980
+ url.username = encodeURIComponent(decodeURIComponent(url.username));
2981
+ url.password = url.auth.slice(index + 1);
2982
+ url.password = encodeURIComponent(decodeURIComponent(url.password));
2983
+ } else {
2984
+ url.username = encodeURIComponent(decodeURIComponent(url.auth));
2985
+ }
2986
+ url.auth = url.password ? url.username + ":" + url.password : url.username;
2987
+ }
2988
+ url.origin = url.protocol !== "file:" && isSpecial(url.protocol) && url.host ? url.protocol + "//" + url.host : "null";
2989
+ url.href = url.toString();
2990
+ }
2991
+ function set(part, value, fn) {
2992
+ var url = this;
2993
+ switch (part) {
2994
+ case "query":
2995
+ if (typeof value === "string" && value.length) {
2996
+ value = (fn || qs.parse)(value);
2997
+ }
2998
+ url[part] = value;
2999
+ break;
3000
+ case "port":
3001
+ url[part] = value;
3002
+ if (!required(value, url.protocol)) {
3003
+ url.host = url.hostname;
3004
+ url[part] = "";
3005
+ } else if (value) {
3006
+ url.host = url.hostname + ":" + value;
3007
+ }
3008
+ break;
3009
+ case "hostname":
3010
+ url[part] = value;
3011
+ if (url.port)
3012
+ value += ":" + url.port;
3013
+ url.host = value;
3014
+ break;
3015
+ case "host":
3016
+ url[part] = value;
3017
+ if (port.test(value)) {
3018
+ value = value.split(":");
3019
+ url.port = value.pop();
3020
+ url.hostname = value.join(":");
3021
+ } else {
3022
+ url.hostname = value;
3023
+ url.port = "";
3024
+ }
3025
+ break;
3026
+ case "protocol":
3027
+ url.protocol = value.toLowerCase();
3028
+ url.slashes = !fn;
3029
+ break;
3030
+ case "pathname":
3031
+ case "hash":
3032
+ if (value) {
3033
+ var char = part === "pathname" ? "/" : "#";
3034
+ url[part] = value.charAt(0) !== char ? char + value : value;
3035
+ } else {
3036
+ url[part] = value;
3037
+ }
3038
+ break;
3039
+ case "username":
3040
+ case "password":
3041
+ url[part] = encodeURIComponent(value);
3042
+ break;
3043
+ case "auth":
3044
+ var index = value.indexOf(":");
3045
+ if (~index) {
3046
+ url.username = value.slice(0, index);
3047
+ url.username = encodeURIComponent(decodeURIComponent(url.username));
3048
+ url.password = value.slice(index + 1);
3049
+ url.password = encodeURIComponent(decodeURIComponent(url.password));
3050
+ } else {
3051
+ url.username = encodeURIComponent(decodeURIComponent(value));
3052
+ }
3053
+ }
3054
+ for (var i = 0; i < rules.length; i++) {
3055
+ var ins = rules[i];
3056
+ if (ins[4])
3057
+ url[ins[1]] = url[ins[1]].toLowerCase();
3058
+ }
3059
+ url.auth = url.password ? url.username + ":" + url.password : url.username;
3060
+ url.origin = url.protocol !== "file:" && isSpecial(url.protocol) && url.host ? url.protocol + "//" + url.host : "null";
3061
+ url.href = url.toString();
3062
+ return url;
3063
+ }
3064
+ function toString(stringify) {
3065
+ if (!stringify || typeof stringify !== "function")
3066
+ stringify = qs.stringify;
3067
+ var query, url = this, host = url.host, protocol = url.protocol;
3068
+ if (protocol && protocol.charAt(protocol.length - 1) !== ":")
3069
+ protocol += ":";
3070
+ var result = protocol + (url.protocol && url.slashes || isSpecial(url.protocol) ? "//" : "");
3071
+ if (url.username) {
3072
+ result += url.username;
3073
+ if (url.password)
3074
+ result += ":" + url.password;
3075
+ result += "@";
3076
+ } else if (url.password) {
3077
+ result += ":" + url.password;
3078
+ result += "@";
3079
+ } else if (url.protocol !== "file:" && isSpecial(url.protocol) && !host && url.pathname !== "/") {
3080
+ result += "@";
3081
+ }
3082
+ if (host[host.length - 1] === ":" || port.test(url.hostname) && !url.port) {
3083
+ host += ":";
3084
+ }
3085
+ result += host + url.pathname;
3086
+ query = typeof url.query === "object" ? stringify(url.query) : url.query;
3087
+ if (query)
3088
+ result += query.charAt(0) !== "?" ? "?" + query : query;
3089
+ if (url.hash)
3090
+ result += url.hash;
3091
+ return result;
3092
+ }
3093
+ Url.prototype = { set, toString };
3094
+ Url.extractProtocol = extractProtocol;
3095
+ Url.location = lolcation;
3096
+ Url.trimLeft = trimLeft;
3097
+ Url.qs = qs;
3098
+ module.exports = Url;
3099
+ }
3100
+ });
3101
+
3102
+ // node_modules/get-it/lib/middleware/defaultOptionsProcessor.js
3103
+ var require_defaultOptionsProcessor = __commonJS({
3104
+ "node_modules/get-it/lib/middleware/defaultOptionsProcessor.js"(exports, module) {
3105
+ "use strict";
3106
+ var objectAssign = require_object_assign();
3107
+ var urlParse = require_url_parse();
3108
+ var isReactNative = typeof navigator === "undefined" ? false : navigator.product === "ReactNative";
3109
+ var has = Object.prototype.hasOwnProperty;
3110
+ var defaultOptions = {
3111
+ timeout: isReactNative ? 6e4 : 12e4
3112
+ };
3113
+ module.exports = function(opts) {
3114
+ var options = typeof opts === "string" ? objectAssign({
3115
+ url: opts
3116
+ }, defaultOptions) : objectAssign({}, defaultOptions, opts);
3117
+ var url = urlParse(options.url, {}, true);
3118
+ options.timeout = normalizeTimeout(options.timeout);
3119
+ if (options.query) {
3120
+ url.query = objectAssign({}, url.query, removeUndefined(options.query));
3121
+ }
3122
+ options.method = options.body && !options.method ? "POST" : (options.method || "GET").toUpperCase();
3123
+ options.url = url.toString(stringifyQueryString);
3124
+ return options;
3125
+ };
3126
+ function stringifyQueryString(obj) {
3127
+ var pairs = [];
3128
+ for (var key in obj) {
3129
+ if (has.call(obj, key)) {
3130
+ push(key, obj[key]);
3131
+ }
3132
+ }
3133
+ return pairs.length ? pairs.join("&") : "";
3134
+ function push(key2, val) {
3135
+ if (Array.isArray(val)) {
3136
+ val.forEach(function(item) {
3137
+ return push(key2, item);
3138
+ });
3139
+ } else {
3140
+ pairs.push([key2, val].map(encodeURIComponent).join("="));
3141
+ }
3142
+ }
3143
+ }
3144
+ function normalizeTimeout(time) {
3145
+ if (time === false || time === 0) {
3146
+ return false;
3147
+ }
3148
+ if (time.connect || time.socket) {
3149
+ return time;
3150
+ }
3151
+ var delay = Number(time);
3152
+ if (isNaN(delay)) {
3153
+ return normalizeTimeout(defaultOptions.timeout);
3154
+ }
3155
+ return {
3156
+ connect: delay,
3157
+ socket: delay
3158
+ };
3159
+ }
3160
+ function removeUndefined(obj) {
3161
+ var target = {};
3162
+ for (var key in obj) {
3163
+ if (obj[key] !== void 0) {
3164
+ target[key] = obj[key];
3165
+ }
3166
+ }
3167
+ return target;
3168
+ }
3169
+ }
3170
+ });
3171
+
3172
+ // node_modules/get-it/lib/middleware/defaultOptionsValidator.js
3173
+ var require_defaultOptionsValidator = __commonJS({
3174
+ "node_modules/get-it/lib/middleware/defaultOptionsValidator.js"(exports, module) {
3175
+ "use strict";
3176
+ var validUrl = /^https?:\/\//i;
3177
+ module.exports = function(options) {
3178
+ if (!validUrl.test(options.url)) {
3179
+ throw new Error('"'.concat(options.url, '" is not a valid URL'));
3180
+ }
3181
+ };
3182
+ }
3183
+ });
3184
+
3185
+ // node_modules/same-origin/url-parser.js
3186
+ var require_url_parser = __commonJS({
3187
+ "node_modules/same-origin/url-parser.js"(exports, module) {
3188
+ "use strict";
3189
+ var regex = /^(?:(?:(?:([^:\/#\?]+:)?(?:(?:\/\/)((?:((?:[^:@\/#\?]+)(?:\:(?:[^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((?:\/?(?:[^\/\?#]+\/+)*)(?:[^\?#]*)))?(\?[^#]+)?)(#.*)?/;
3190
+ module.exports = {
3191
+ regex,
3192
+ parse: function(url) {
3193
+ var match = regex.exec(url);
3194
+ if (!match) {
3195
+ return {};
3196
+ }
3197
+ return {
3198
+ protocol: (match[1] || "").toLowerCase() || void 0,
3199
+ hostname: (match[5] || "").toLowerCase() || void 0,
3200
+ port: match[6] || void 0
3201
+ };
3202
+ }
3203
+ };
3204
+ }
3205
+ });
3206
+
3207
+ // node_modules/same-origin/index.js
3208
+ var require_same_origin = __commonJS({
3209
+ "node_modules/same-origin/index.js"(exports, module) {
3210
+ "use strict";
3211
+ var url = require_url_parser();
3212
+ module.exports = function(uri1, uri2, ieMode) {
3213
+ if (uri1 === uri2) {
3214
+ return true;
3215
+ }
3216
+ var url1 = url.parse(uri1, false, true);
3217
+ var url2 = url.parse(uri2, false, true);
3218
+ var url1Port = url1.port | 0 || (url1.protocol === "https" ? 443 : 80);
3219
+ var url2Port = url2.port | 0 || (url2.protocol === "https" ? 443 : 80);
3220
+ var match = {
3221
+ proto: url1.protocol === url2.protocol,
3222
+ hostname: url1.hostname === url2.hostname,
3223
+ port: url1Port === url2Port
3224
+ };
3225
+ return match.proto && match.hostname && (match.port || ieMode);
3226
+ };
3227
+ }
3228
+ });
3229
+
3230
+ // node_modules/parse-headers/parse-headers.js
3231
+ var require_parse_headers = __commonJS({
3232
+ "node_modules/parse-headers/parse-headers.js"(exports, module) {
3233
+ var trim = function(string) {
3234
+ return string.replace(/^\s+|\s+$/g, "");
3235
+ };
3236
+ var isArray = function(arg) {
3237
+ return Object.prototype.toString.call(arg) === "[object Array]";
3238
+ };
3239
+ module.exports = function(headers) {
3240
+ if (!headers)
3241
+ return {};
3242
+ var result = {};
3243
+ var headersArr = trim(headers).split("\n");
3244
+ for (var i = 0; i < headersArr.length; i++) {
3245
+ var row = headersArr[i];
3246
+ var index = row.indexOf(":"), key = trim(row.slice(0, index)).toLowerCase(), value = trim(row.slice(index + 1));
3247
+ if (typeof result[key] === "undefined") {
3248
+ result[key] = value;
3249
+ } else if (isArray(result[key])) {
3250
+ result[key].push(value);
3251
+ } else {
3252
+ result[key] = [result[key], value];
3253
+ }
3254
+ }
3255
+ return result;
3256
+ };
3257
+ }
3258
+ });
3259
+
3260
+ // node_modules/get-it/lib/request/browser/fetchXhr.js
3261
+ var require_fetchXhr = __commonJS({
3262
+ "node_modules/get-it/lib/request/browser/fetchXhr.js"(exports, module) {
3263
+ "use strict";
3264
+ function FetchXhr() {
3265
+ this.readyState = 0;
3266
+ }
3267
+ FetchXhr.prototype.open = function(method, url) {
3268
+ this._method = method;
3269
+ this._url = url;
3270
+ this._resHeaders = "";
3271
+ this.readyState = 1;
3272
+ this.onreadystatechange();
3273
+ };
3274
+ FetchXhr.prototype.abort = function() {
3275
+ if (this._controller) {
3276
+ this._controller.abort();
3277
+ }
3278
+ };
3279
+ FetchXhr.prototype.getAllResponseHeaders = function() {
3280
+ return this._resHeaders;
3281
+ };
3282
+ FetchXhr.prototype.setRequestHeader = function(key, value) {
3283
+ this._headers = this._headers || {};
3284
+ this._headers[key] = value;
3285
+ };
3286
+ FetchXhr.prototype.send = function(body) {
3287
+ var _this = this;
3288
+ var ctrl = this._controller = typeof AbortController === "function" && new AbortController();
3289
+ var textBody = this.responseType !== "arraybuffer";
3290
+ var options = {
3291
+ method: this._method,
3292
+ headers: this._headers,
3293
+ signal: ctrl && ctrl.signal,
3294
+ body
3295
+ };
3296
+ if (typeof window !== "undefined") {
3297
+ options.credentials = this.withCredentials ? "include" : "omit";
3298
+ }
3299
+ fetch(this._url, options).then(function(res) {
3300
+ res.headers.forEach(function(value, key) {
3301
+ _this._resHeaders += "".concat(key, ": ").concat(value, "\r\n");
3302
+ });
3303
+ _this.status = res.status;
3304
+ _this.statusText = res.statusText;
3305
+ _this.readyState = 3;
3306
+ return textBody ? res.text() : res.arrayBuffer();
3307
+ }).then(function(resBody) {
3308
+ if (textBody) {
3309
+ _this.responseText = resBody;
3310
+ } else {
3311
+ _this.response = resBody;
3312
+ }
3313
+ _this.readyState = 4;
3314
+ _this.onreadystatechange();
3315
+ }).catch(function(err) {
3316
+ if (err.name === "AbortError") {
3317
+ _this.onabort();
3318
+ return;
3319
+ }
3320
+ _this.onerror(err);
3321
+ });
3322
+ };
3323
+ module.exports = FetchXhr;
3324
+ }
3325
+ });
3326
+
3327
+ // node_modules/get-it/lib/request/browser-request.js
3328
+ var require_browser_request = __commonJS({
3329
+ "node_modules/get-it/lib/request/browser-request.js"(exports, module) {
3330
+ "use strict";
3331
+ var sameOrigin = require_same_origin();
3332
+ var parseHeaders = require_parse_headers();
3333
+ var FetchXhr = require_fetchXhr();
3334
+ var noop = function noop2() {
3335
+ };
3336
+ var win = typeof window === "undefined" ? void 0 : window;
3337
+ var adapter = win ? "xhr" : "fetch";
3338
+ var XmlHttpRequest = typeof XMLHttpRequest === "function" ? XMLHttpRequest : noop;
3339
+ var hasXhr2 = "withCredentials" in new XmlHttpRequest();
3340
+ var XDR = typeof XDomainRequest === "undefined" ? void 0 : XDomainRequest;
3341
+ var CrossDomainRequest = hasXhr2 ? XmlHttpRequest : XDR;
3342
+ if (!win) {
3343
+ XmlHttpRequest = FetchXhr;
3344
+ CrossDomainRequest = FetchXhr;
3345
+ }
3346
+ module.exports = function(context, callback) {
3347
+ var opts = context.options;
3348
+ var options = context.applyMiddleware("finalizeOptions", opts);
3349
+ var timers = {};
3350
+ var cors = win && win.location && !sameOrigin(win.location.href, options.url);
3351
+ var injectedResponse = context.applyMiddleware("interceptRequest", void 0, {
3352
+ adapter,
3353
+ context
3354
+ });
3355
+ if (injectedResponse) {
3356
+ var cbTimer = setTimeout(callback, 0, null, injectedResponse);
3357
+ var cancel = function cancel2() {
3358
+ return clearTimeout(cbTimer);
3359
+ };
3360
+ return {
3361
+ abort: cancel
3362
+ };
3363
+ }
3364
+ var xhr = cors ? new CrossDomainRequest() : new XmlHttpRequest();
3365
+ var isXdr = win && win.XDomainRequest && xhr instanceof win.XDomainRequest;
3366
+ var headers = options.headers;
3367
+ var delays = options.timeout;
3368
+ var aborted = false;
3369
+ var loaded = false;
3370
+ var timedOut = false;
3371
+ xhr.onerror = onError;
3372
+ xhr.ontimeout = onError;
3373
+ xhr.onabort = function() {
3374
+ stopTimers(true);
3375
+ aborted = true;
3376
+ };
3377
+ xhr.onprogress = function() {
3378
+ };
3379
+ var loadEvent = isXdr ? "onload" : "onreadystatechange";
3380
+ xhr[loadEvent] = function() {
3381
+ resetTimers();
3382
+ if (aborted || xhr.readyState !== 4 && !isXdr) {
3383
+ return;
3384
+ }
3385
+ if (xhr.status === 0) {
3386
+ return;
3387
+ }
3388
+ onLoad();
3389
+ };
3390
+ xhr.open(options.method, options.url, true);
3391
+ xhr.withCredentials = !!options.withCredentials;
3392
+ if (headers && xhr.setRequestHeader) {
3393
+ for (var key in headers) {
3394
+ if (headers.hasOwnProperty(key)) {
3395
+ xhr.setRequestHeader(key, headers[key]);
3396
+ }
3397
+ }
3398
+ } else if (headers && isXdr) {
3399
+ throw new Error("Headers cannot be set on an XDomainRequest object");
3400
+ }
3401
+ if (options.rawBody) {
3402
+ xhr.responseType = "arraybuffer";
3403
+ }
3404
+ context.applyMiddleware("onRequest", {
3405
+ options,
3406
+ adapter,
3407
+ request: xhr,
3408
+ context
3409
+ });
3410
+ xhr.send(options.body || null);
3411
+ if (delays) {
3412
+ timers.connect = setTimeout(function() {
3413
+ return timeoutRequest("ETIMEDOUT");
3414
+ }, delays.connect);
3415
+ }
3416
+ return {
3417
+ abort
3418
+ };
3419
+ function abort() {
3420
+ aborted = true;
3421
+ if (xhr) {
3422
+ xhr.abort();
3423
+ }
3424
+ }
3425
+ function timeoutRequest(code) {
3426
+ timedOut = true;
3427
+ xhr.abort();
3428
+ var error = new Error(code === "ESOCKETTIMEDOUT" ? "Socket timed out on request to ".concat(options.url) : "Connection timed out on request to ".concat(options.url));
3429
+ error.code = code;
3430
+ context.channels.error.publish(error);
3431
+ }
3432
+ function resetTimers() {
3433
+ if (!delays) {
3434
+ return;
3435
+ }
3436
+ stopTimers();
3437
+ timers.socket = setTimeout(function() {
3438
+ return timeoutRequest("ESOCKETTIMEDOUT");
3439
+ }, delays.socket);
3440
+ }
3441
+ function stopTimers(force) {
3442
+ if (force || aborted || xhr.readyState >= 2 && timers.connect) {
3443
+ clearTimeout(timers.connect);
3444
+ }
3445
+ if (timers.socket) {
3446
+ clearTimeout(timers.socket);
3447
+ }
3448
+ }
3449
+ function onError(error) {
3450
+ if (loaded) {
3451
+ return;
3452
+ }
3453
+ stopTimers(true);
3454
+ loaded = true;
3455
+ xhr = null;
3456
+ var err = error || new Error("Network error while attempting to reach ".concat(options.url));
3457
+ err.isNetworkError = true;
3458
+ err.request = options;
3459
+ callback(err);
3460
+ }
3461
+ function reduceResponse() {
3462
+ var statusCode = xhr.status;
3463
+ var statusMessage = xhr.statusText;
3464
+ if (isXdr && statusCode === void 0) {
3465
+ statusCode = 200;
3466
+ } else if (statusCode > 12e3 && statusCode < 12156) {
3467
+ return onError();
3468
+ } else {
3469
+ statusCode = xhr.status === 1223 ? 204 : xhr.status;
3470
+ statusMessage = xhr.status === 1223 ? "No Content" : statusMessage;
3471
+ }
3472
+ return {
3473
+ body: xhr.response || xhr.responseText,
3474
+ url: options.url,
3475
+ method: options.method,
3476
+ headers: isXdr ? {} : parseHeaders(xhr.getAllResponseHeaders()),
3477
+ statusCode,
3478
+ statusMessage
3479
+ };
3480
+ }
3481
+ function onLoad() {
3482
+ if (aborted || loaded || timedOut) {
3483
+ return;
3484
+ }
3485
+ if (xhr.status === 0) {
3486
+ onError(new Error("Unknown XHR error"));
3487
+ return;
3488
+ }
3489
+ stopTimers();
3490
+ loaded = true;
3491
+ callback(null, reduceResponse());
3492
+ }
3493
+ };
3494
+ }
3495
+ });
3496
+
3497
+ // node_modules/get-it/lib/request/index.js
3498
+ var require_request = __commonJS({
3499
+ "node_modules/get-it/lib/request/index.js"(exports, module) {
3500
+ "use strict";
3501
+ module.exports = require_browser_request();
3502
+ }
3503
+ });
3504
+
3505
+ // node_modules/get-it/lib/index.js
3506
+ var require_lib = __commonJS({
3507
+ "node_modules/get-it/lib/index.js"(exports, module) {
3508
+ "use strict";
3509
+ var pubsub = require_nano_pubsub();
3510
+ var middlewareReducer = require_middlewareReducer();
3511
+ var processOptions = require_defaultOptionsProcessor();
3512
+ var validateOptions = require_defaultOptionsValidator();
3513
+ var httpRequester = require_request();
3514
+ var channelNames = ["request", "response", "progress", "error", "abort"];
3515
+ var middlehooks = ["processOptions", "validateOptions", "interceptRequest", "finalizeOptions", "onRequest", "onResponse", "onError", "onReturn", "onHeaders"];
3516
+ module.exports = function createRequester() {
3517
+ var initMiddleware = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
3518
+ var httpRequest = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : httpRequester;
3519
+ var loadedMiddleware = [];
3520
+ var middleware = middlehooks.reduce(function(ware, name) {
3521
+ ware[name] = ware[name] || [];
3522
+ return ware;
3523
+ }, {
3524
+ processOptions: [processOptions],
3525
+ validateOptions: [validateOptions]
3526
+ });
3527
+ function request(opts) {
3528
+ var channels = channelNames.reduce(function(target, name) {
3529
+ target[name] = pubsub();
3530
+ return target;
3531
+ }, {});
3532
+ var applyMiddleware = middlewareReducer(middleware);
3533
+ var options = applyMiddleware("processOptions", opts);
3534
+ applyMiddleware("validateOptions", options);
3535
+ var context = {
3536
+ options,
3537
+ channels,
3538
+ applyMiddleware
3539
+ };
3540
+ var ongoingRequest = null;
3541
+ var unsubscribe = channels.request.subscribe(function(ctx) {
3542
+ ongoingRequest = httpRequest(ctx, function(err, res) {
3543
+ return onResponse(err, res, ctx);
3544
+ });
3545
+ });
3546
+ channels.abort.subscribe(function() {
3547
+ unsubscribe();
3548
+ if (ongoingRequest) {
3549
+ ongoingRequest.abort();
3550
+ }
3551
+ });
3552
+ var returnValue = applyMiddleware("onReturn", channels, context);
3553
+ if (returnValue === channels) {
3554
+ channels.request.publish(context);
3555
+ }
3556
+ return returnValue;
3557
+ function onResponse(reqErr, res, ctx) {
3558
+ var error = reqErr;
3559
+ var response = res;
3560
+ if (!error) {
3561
+ try {
3562
+ response = applyMiddleware("onResponse", res, ctx);
3563
+ } catch (err) {
3564
+ response = null;
3565
+ error = err;
3566
+ }
3567
+ }
3568
+ error = error && applyMiddleware("onError", error, ctx);
3569
+ if (error) {
3570
+ channels.error.publish(error);
3571
+ } else if (response) {
3572
+ channels.response.publish(response);
3573
+ }
3574
+ }
3575
+ }
3576
+ request.use = function use(newMiddleware) {
3577
+ if (!newMiddleware) {
3578
+ throw new Error("Tried to add middleware that resolved to falsey value");
3579
+ }
3580
+ if (typeof newMiddleware === "function") {
3581
+ throw new Error("Tried to add middleware that was a function. It probably expects you to pass options to it.");
3582
+ }
3583
+ if (newMiddleware.onReturn && middleware.onReturn.length > 0) {
3584
+ throw new Error("Tried to add new middleware with `onReturn` handler, but another handler has already been registered for this event");
3585
+ }
3586
+ middlehooks.forEach(function(key) {
3587
+ if (newMiddleware[key]) {
3588
+ middleware[key].push(newMiddleware[key]);
3589
+ }
3590
+ });
3591
+ loadedMiddleware.push(newMiddleware);
3592
+ return request;
3593
+ };
3594
+ request.clone = function clone() {
3595
+ return createRequester(loadedMiddleware);
3596
+ };
3597
+ initMiddleware.forEach(request.use);
3598
+ return request;
3599
+ };
3600
+ }
3601
+ });
3602
+
3603
+ // node_modules/get-it/index.js
3604
+ var require_get_it = __commonJS({
3605
+ "node_modules/get-it/index.js"(exports, module) {
3606
+ module.exports = require_lib();
3607
+ }
3608
+ });
3609
+
3610
+ // node_modules/get-it/lib/util/global.js
3611
+ var require_global = __commonJS({
3612
+ "node_modules/get-it/lib/util/global.js"(exports, module) {
3613
+ "use strict";
3614
+ if (typeof globalThis !== "undefined") {
3615
+ module.exports = globalThis;
3616
+ } else if (typeof window !== "undefined") {
3617
+ module.exports = window;
3618
+ } else if (typeof global !== "undefined") {
3619
+ module.exports = global;
3620
+ } else if (typeof self !== "undefined") {
3621
+ module.exports = self;
3622
+ } else {
3623
+ module.exports = {};
3624
+ }
3625
+ }
3626
+ });
3627
+
3628
+ // node_modules/get-it/lib/middleware/observable.js
3629
+ var require_observable3 = __commonJS({
3630
+ "node_modules/get-it/lib/middleware/observable.js"(exports, module) {
3631
+ "use strict";
3632
+ var global2 = require_global();
3633
+ var objectAssign = require_object_assign();
3634
+ module.exports = function() {
3635
+ var opts = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
3636
+ var Observable = opts.implementation || global2.Observable;
3637
+ if (!Observable) {
3638
+ throw new Error("`Observable` is not available in global scope, and no implementation was passed");
3639
+ }
3640
+ return {
3641
+ onReturn: function onReturn(channels, context) {
3642
+ return new Observable(function(observer) {
3643
+ channels.error.subscribe(function(err) {
3644
+ return observer.error(err);
3645
+ });
3646
+ channels.progress.subscribe(function(event) {
3647
+ return observer.next(objectAssign({
3648
+ type: "progress"
3649
+ }, event));
3650
+ });
3651
+ channels.response.subscribe(function(response) {
3652
+ observer.next(objectAssign({
3653
+ type: "response"
3654
+ }, response));
3655
+ observer.complete();
3656
+ });
3657
+ channels.request.publish(context);
3658
+ return function() {
3659
+ return channels.abort.publish();
3660
+ };
3661
+ });
3662
+ }
3663
+ };
3664
+ };
3665
+ }
3666
+ });
3667
+
3668
+ // node_modules/isobject/index.js
3669
+ var require_isobject = __commonJS({
3670
+ "node_modules/isobject/index.js"(exports, module) {
3671
+ "use strict";
3672
+ module.exports = function isObject(val) {
3673
+ return val != null && typeof val === "object" && Array.isArray(val) === false;
3674
+ };
3675
+ }
3676
+ });
3677
+
3678
+ // node_modules/is-plain-object/index.js
3679
+ var require_is_plain_object = __commonJS({
3680
+ "node_modules/is-plain-object/index.js"(exports, module) {
3681
+ "use strict";
3682
+ var isObject = require_isobject();
3683
+ function isObjectObject(o) {
3684
+ return isObject(o) === true && Object.prototype.toString.call(o) === "[object Object]";
3685
+ }
3686
+ module.exports = function isPlainObject(o) {
3687
+ var ctor, prot;
3688
+ if (isObjectObject(o) === false)
3689
+ return false;
3690
+ ctor = o.constructor;
3691
+ if (typeof ctor !== "function")
3692
+ return false;
3693
+ prot = ctor.prototype;
3694
+ if (isObjectObject(prot) === false)
3695
+ return false;
3696
+ if (prot.hasOwnProperty("isPrototypeOf") === false) {
3697
+ return false;
3698
+ }
3699
+ return true;
3700
+ };
3701
+ }
3702
+ });
3703
+
3704
+ // node_modules/get-it/lib/middleware/jsonRequest.js
3705
+ var require_jsonRequest = __commonJS({
3706
+ "node_modules/get-it/lib/middleware/jsonRequest.js"(exports, module) {
3707
+ "use strict";
3708
+ function _typeof(obj) {
3709
+ "@babel/helpers - typeof";
3710
+ return _typeof = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(obj2) {
3711
+ return typeof obj2;
3712
+ } : function(obj2) {
3713
+ return obj2 && typeof Symbol == "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
3714
+ }, _typeof(obj);
3715
+ }
3716
+ var objectAssign = require_object_assign();
3717
+ var isPlainObject = require_is_plain_object();
3718
+ var serializeTypes = ["boolean", "string", "number"];
3719
+ var isBuffer = function isBuffer2(obj) {
3720
+ return !!obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
3721
+ };
3722
+ module.exports = function() {
3723
+ return {
3724
+ processOptions: function processOptions(options) {
3725
+ var body = options.body;
3726
+ if (!body) {
3727
+ return options;
3728
+ }
3729
+ var isStream = typeof body.pipe === "function";
3730
+ var shouldSerialize = !isStream && !isBuffer(body) && (serializeTypes.indexOf(_typeof(body)) !== -1 || Array.isArray(body) || isPlainObject(body));
3731
+ if (!shouldSerialize) {
3732
+ return options;
3733
+ }
3734
+ return objectAssign({}, options, {
3735
+ body: JSON.stringify(options.body),
3736
+ headers: objectAssign({}, options.headers, {
3737
+ "Content-Type": "application/json"
3738
+ })
3739
+ });
3740
+ }
3741
+ };
3742
+ };
3743
+ }
3744
+ });
3745
+
3746
+ // node_modules/get-it/lib/middleware/jsonResponse.js
3747
+ var require_jsonResponse = __commonJS({
3748
+ "node_modules/get-it/lib/middleware/jsonResponse.js"(exports, module) {
3749
+ "use strict";
3750
+ var objectAssign = require_object_assign();
3751
+ module.exports = function(opts) {
3752
+ return {
3753
+ onResponse: function onResponse(response) {
3754
+ var contentType = response.headers["content-type"] || "";
3755
+ var shouldDecode = opts && opts.force || contentType.indexOf("application/json") !== -1;
3756
+ if (!response.body || !contentType || !shouldDecode) {
3757
+ return response;
3758
+ }
3759
+ return objectAssign({}, response, {
3760
+ body: tryParse(response.body)
3761
+ });
3762
+ },
3763
+ processOptions: function processOptions(options) {
3764
+ return objectAssign({}, options, {
3765
+ headers: objectAssign({
3766
+ Accept: "application/json"
3767
+ }, options.headers)
3768
+ });
3769
+ }
3770
+ };
3771
+ };
3772
+ function tryParse(body) {
3773
+ try {
3774
+ return JSON.parse(body);
3775
+ } catch (err) {
3776
+ err.message = "Failed to parsed response body as JSON: ".concat(err.message);
3777
+ throw err;
3778
+ }
3779
+ }
3780
+ }
3781
+ });
3782
+
3783
+ // node_modules/get-it/lib/middleware/progress/browser-progress.js
3784
+ var require_browser_progress = __commonJS({
3785
+ "node_modules/get-it/lib/middleware/progress/browser-progress.js"(exports, module) {
3786
+ "use strict";
3787
+ module.exports = function() {
3788
+ return {
3789
+ onRequest: function onRequest(evt) {
3790
+ if (evt.adapter !== "xhr") {
3791
+ return;
3792
+ }
3793
+ var xhr = evt.request;
3794
+ var context = evt.context;
3795
+ if ("upload" in xhr && "onprogress" in xhr.upload) {
3796
+ xhr.upload.onprogress = handleProgress("upload");
3797
+ }
3798
+ if ("onprogress" in xhr) {
3799
+ xhr.onprogress = handleProgress("download");
3800
+ }
3801
+ function handleProgress(stage) {
3802
+ return function(event) {
3803
+ var percent = event.lengthComputable ? event.loaded / event.total * 100 : -1;
3804
+ context.channels.progress.publish({
3805
+ stage,
3806
+ percent,
3807
+ total: event.total,
3808
+ loaded: event.loaded,
3809
+ lengthComputable: event.lengthComputable
3810
+ });
3811
+ };
3812
+ }
3813
+ }
3814
+ };
3815
+ };
3816
+ }
3817
+ });
3818
+
3819
+ // node_modules/get-it/lib/middleware/progress/index.js
3820
+ var require_progress = __commonJS({
3821
+ "node_modules/get-it/lib/middleware/progress/index.js"(exports, module) {
3822
+ "use strict";
3823
+ module.exports = require_browser_progress();
3824
+ }
3825
+ });
3826
+
3827
+ // node_modules/make-error/index.js
3828
+ var require_make_error = __commonJS({
3829
+ "node_modules/make-error/index.js"(exports, module) {
3830
+ "use strict";
3831
+ var construct = typeof Reflect !== "undefined" ? Reflect.construct : void 0;
3832
+ var defineProperty = Object.defineProperty;
3833
+ var captureStackTrace = Error.captureStackTrace;
3834
+ if (captureStackTrace === void 0) {
3835
+ captureStackTrace = function captureStackTrace2(error) {
3836
+ var container = new Error();
3837
+ defineProperty(error, "stack", {
3838
+ configurable: true,
3839
+ get: function getStack() {
3840
+ var stack = container.stack;
3841
+ defineProperty(this, "stack", {
3842
+ configurable: true,
3843
+ value: stack,
3844
+ writable: true
3845
+ });
3846
+ return stack;
3847
+ },
3848
+ set: function setStack(stack) {
3849
+ defineProperty(error, "stack", {
3850
+ configurable: true,
3851
+ value: stack,
3852
+ writable: true
3853
+ });
3854
+ }
3855
+ });
3856
+ };
3857
+ }
3858
+ function BaseError(message) {
3859
+ if (message !== void 0) {
3860
+ defineProperty(this, "message", {
3861
+ configurable: true,
3862
+ value: message,
3863
+ writable: true
3864
+ });
3865
+ }
3866
+ var cname = this.constructor.name;
3867
+ if (cname !== void 0 && cname !== this.name) {
3868
+ defineProperty(this, "name", {
3869
+ configurable: true,
3870
+ value: cname,
3871
+ writable: true
3872
+ });
3873
+ }
3874
+ captureStackTrace(this, this.constructor);
3875
+ }
3876
+ BaseError.prototype = Object.create(Error.prototype, {
3877
+ constructor: {
3878
+ configurable: true,
3879
+ value: BaseError,
3880
+ writable: true
3881
+ }
3882
+ });
3883
+ var setFunctionName = function() {
3884
+ function setFunctionName2(fn, name) {
3885
+ return defineProperty(fn, "name", {
3886
+ configurable: true,
3887
+ value: name
3888
+ });
3889
+ }
3890
+ try {
3891
+ var f = function() {
3892
+ };
3893
+ setFunctionName2(f, "foo");
3894
+ if (f.name === "foo") {
3895
+ return setFunctionName2;
3896
+ }
3897
+ } catch (_) {
3898
+ }
3899
+ }();
3900
+ function makeError(constructor, super_) {
3901
+ if (super_ == null || super_ === Error) {
3902
+ super_ = BaseError;
3903
+ } else if (typeof super_ !== "function") {
3904
+ throw new TypeError("super_ should be a function");
3905
+ }
3906
+ var name;
3907
+ if (typeof constructor === "string") {
3908
+ name = constructor;
3909
+ constructor = construct !== void 0 ? function() {
3910
+ return construct(super_, arguments, this.constructor);
3911
+ } : function() {
3912
+ super_.apply(this, arguments);
3913
+ };
3914
+ if (setFunctionName !== void 0) {
3915
+ setFunctionName(constructor, name);
3916
+ name = void 0;
3917
+ }
3918
+ } else if (typeof constructor !== "function") {
3919
+ throw new TypeError("constructor should be either a string or a function");
3920
+ }
3921
+ constructor.super_ = constructor["super"] = super_;
3922
+ var properties = {
3923
+ constructor: {
3924
+ configurable: true,
3925
+ value: constructor,
3926
+ writable: true
3927
+ }
3928
+ };
3929
+ if (name !== void 0) {
3930
+ properties.name = {
3931
+ configurable: true,
3932
+ value: name,
3933
+ writable: true
3934
+ };
3935
+ }
3936
+ constructor.prototype = Object.create(super_.prototype, properties);
3937
+ return constructor;
3938
+ }
3939
+ exports = module.exports = makeError;
3940
+ exports.BaseError = BaseError;
3941
+ }
3942
+ });
3943
+
3944
+ // src/http/errors.js
3945
+ var require_errors = __commonJS({
3946
+ "src/http/errors.js"(exports) {
3947
+ var makeError = require_make_error();
3948
+ var assign = require_object_assign();
3949
+ function ClientError(res) {
3950
+ const props = extractErrorProps(res);
3951
+ ClientError.super.call(this, props.message);
3952
+ assign(this, props);
3953
+ }
3954
+ function ServerError(res) {
3955
+ const props = extractErrorProps(res);
3956
+ ServerError.super.call(this, props.message);
3957
+ assign(this, props);
3958
+ }
3959
+ function extractErrorProps(res) {
3960
+ const body = res.body;
3961
+ const props = {
3962
+ response: res,
3963
+ statusCode: res.statusCode,
3964
+ responseBody: stringifyBody(body, res)
3965
+ };
3966
+ if (body.error && body.message) {
3967
+ props.message = `${body.error} - ${body.message}`;
3968
+ return props;
3969
+ }
3970
+ if (body.error && body.error.description) {
3971
+ props.message = body.error.description;
3972
+ props.details = body.error;
3973
+ return props;
3974
+ }
3975
+ props.message = body.error || body.message || httpErrorMessage(res);
3976
+ return props;
3977
+ }
3978
+ function httpErrorMessage(res) {
3979
+ const statusMessage = res.statusMessage ? ` ${res.statusMessage}` : "";
3980
+ return `${res.method}-request to ${res.url} resulted in HTTP ${res.statusCode}${statusMessage}`;
3981
+ }
3982
+ function stringifyBody(body, res) {
3983
+ const contentType = (res.headers["content-type"] || "").toLowerCase();
3984
+ const isJson = contentType.indexOf("application/json") !== -1;
3985
+ return isJson ? JSON.stringify(body, null, 2) : body;
3986
+ }
3987
+ makeError(ClientError);
3988
+ makeError(ServerError);
3989
+ exports.ClientError = ClientError;
3990
+ exports.ServerError = ServerError;
3991
+ }
3992
+ });
3993
+
3994
+ // src/http/browserMiddleware.js
3995
+ var require_browserMiddleware = __commonJS({
3996
+ "src/http/browserMiddleware.js"(exports, module) {
3997
+ module.exports = [];
3998
+ }
3999
+ });
4000
+
4001
+ // src/http/request.js
4002
+ var require_request2 = __commonJS({
4003
+ "src/http/request.js"(exports, module) {
4004
+ var getIt = require_get_it();
4005
+ var assign = require_object_assign();
4006
+ var observable = require_observable3();
4007
+ var jsonRequest = require_jsonRequest();
4008
+ var jsonResponse = require_jsonResponse();
4009
+ var progress = require_progress();
4010
+ var { Observable } = require_observable2();
4011
+ var { ClientError, ServerError } = require_errors();
4012
+ var httpError = {
4013
+ onResponse: (res) => {
4014
+ if (res.statusCode >= 500) {
4015
+ throw new ServerError(res);
4016
+ } else if (res.statusCode >= 400) {
4017
+ throw new ClientError(res);
4018
+ }
4019
+ return res;
4020
+ }
4021
+ };
4022
+ var printWarnings = {
4023
+ onResponse: (res) => {
4024
+ const warn = res.headers["x-sanity-warning"];
4025
+ const warnings = Array.isArray(warn) ? warn : [warn];
4026
+ warnings.filter(Boolean).forEach((msg) => console.warn(msg));
4027
+ return res;
4028
+ }
4029
+ };
4030
+ var envSpecific = require_browserMiddleware();
4031
+ var middleware = envSpecific.concat([
4032
+ printWarnings,
4033
+ jsonRequest(),
4034
+ jsonResponse(),
4035
+ progress(),
4036
+ httpError,
4037
+ observable({ implementation: Observable })
4038
+ ]);
4039
+ var request = getIt(middleware);
4040
+ function httpRequest(options, requester = request) {
4041
+ return requester(assign({ maxRedirects: 0 }, options));
4042
+ }
4043
+ httpRequest.defaultRequester = request;
4044
+ httpRequest.ClientError = ClientError;
4045
+ httpRequest.ServerError = ServerError;
4046
+ module.exports = httpRequest;
4047
+ }
4048
+ });
4049
+
4050
+ // src/http/requestOptions.js
4051
+ var require_requestOptions = __commonJS({
4052
+ "src/http/requestOptions.js"(exports, module) {
4053
+ var assign = require_object_assign();
4054
+ var projectHeader = "X-Sanity-Project-ID";
4055
+ module.exports = (config, overrides = {}) => {
4056
+ const headers = {};
4057
+ const token = overrides.token || config.token;
4058
+ if (token) {
4059
+ headers.Authorization = `Bearer ${token}`;
4060
+ }
4061
+ if (!overrides.useGlobalApi && !config.useProjectHostname && config.projectId) {
4062
+ headers[projectHeader] = config.projectId;
4063
+ }
4064
+ const withCredentials = Boolean(typeof overrides.withCredentials === "undefined" ? config.token || config.withCredentials : overrides.withCredentials);
4065
+ const timeout = typeof overrides.timeout === "undefined" ? config.timeout : overrides.timeout;
4066
+ return assign({}, overrides, {
4067
+ headers: assign({}, headers, overrides.headers || {}),
4068
+ timeout: typeof timeout === "undefined" ? 5 * 60 * 1e3 : timeout,
4069
+ proxy: overrides.proxy || config.proxy,
4070
+ json: true,
4071
+ withCredentials
4072
+ });
4073
+ };
4074
+ }
4075
+ });
4076
+
4077
+ // node_modules/@sanity/generate-help-url/dist/generate-help-url.cjs.js
4078
+ var require_generate_help_url_cjs = __commonJS({
4079
+ "node_modules/@sanity/generate-help-url/dist/generate-help-url.cjs.js"(exports) {
4080
+ "use strict";
4081
+ Object.defineProperty(exports, "__esModule", { value: true });
4082
+ exports[Symbol.toStringTag] = "Module";
4083
+ var t = "https://docs.sanity.io/help/";
4084
+ function r(e) {
4085
+ return t + e;
4086
+ }
4087
+ exports.generateHelpUrl = r;
4088
+ }
4089
+ });
4090
+
4091
+ // src/util/once.js
4092
+ var require_once = __commonJS({
4093
+ "src/util/once.js"(exports, module) {
4094
+ module.exports = (fn) => {
4095
+ let didCall = false;
4096
+ let returnValue;
4097
+ return (...args) => {
4098
+ if (didCall) {
4099
+ return returnValue;
4100
+ }
4101
+ returnValue = fn(...args);
4102
+ didCall = true;
4103
+ return returnValue;
4104
+ };
4105
+ };
4106
+ }
4107
+ });
4108
+
4109
+ // src/warnings.js
4110
+ var require_warnings = __commonJS({
4111
+ "src/warnings.js"(exports) {
4112
+ var generateHelpUrl = require_generate_help_url_cjs().generateHelpUrl;
4113
+ var once = require_once();
4114
+ var createWarningPrinter = (message) => once((...args) => console.warn(message.join(" "), ...args));
4115
+ exports.printCdnWarning = createWarningPrinter([
4116
+ "You are not using the Sanity CDN. That means your data is always fresh, but the CDN is faster and",
4117
+ `cheaper. Think about it! For more info, see ${generateHelpUrl("js-client-cdn-configuration")}.`,
4118
+ "To hide this warning, please set the `useCdn` option to either `true` or `false` when creating",
4119
+ "the client."
4120
+ ]);
4121
+ exports.printBrowserTokenWarning = createWarningPrinter([
4122
+ "You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.",
4123
+ `See ${generateHelpUrl("js-client-browser-token")} for more information and how to hide this warning.`
4124
+ ]);
4125
+ exports.printNoApiVersionSpecifiedWarning = createWarningPrinter([
4126
+ "Using the Sanity client without specifying an API version is deprecated.",
4127
+ `See ${generateHelpUrl("js-client-api-version")}`
4128
+ ]);
4129
+ }
4130
+ });
4131
+
4132
+ // src/config.js
4133
+ var require_config2 = __commonJS({
4134
+ "src/config.js"(exports) {
4135
+ var generateHelpUrl = require_generate_help_url_cjs().generateHelpUrl;
4136
+ var assign = require_object_assign();
4137
+ var validate = require_validators();
4138
+ var warnings = require_warnings();
4139
+ var defaultCdnHost = "apicdn.sanity.io";
4140
+ var defaultConfig = {
4141
+ apiHost: "https://api.sanity.io",
4142
+ apiVersion: "1",
4143
+ useProjectHostname: true,
4144
+ isPromiseAPI: true
4145
+ };
4146
+ var LOCALHOSTS = ["localhost", "127.0.0.1", "0.0.0.0"];
4147
+ var isLocal = (host) => LOCALHOSTS.indexOf(host) !== -1;
4148
+ exports.defaultConfig = defaultConfig;
4149
+ exports.initConfig = (config, prevConfig) => {
4150
+ const specifiedConfig = assign({}, prevConfig, config);
4151
+ if (!specifiedConfig.apiVersion) {
4152
+ warnings.printNoApiVersionSpecifiedWarning();
4153
+ }
4154
+ const newConfig = assign({}, defaultConfig, specifiedConfig);
4155
+ const projectBased = newConfig.useProjectHostname;
4156
+ if (typeof Promise === "undefined") {
4157
+ const helpUrl = generateHelpUrl("js-client-promise-polyfill");
4158
+ throw new Error(`No native Promise-implementation found, polyfill needed - see ${helpUrl}`);
4159
+ }
4160
+ if (projectBased && !newConfig.projectId) {
4161
+ throw new Error("Configuration must contain `projectId`");
4162
+ }
4163
+ const isBrowser = typeof window !== "undefined" && window.location && window.location.hostname;
4164
+ const isLocalhost = isBrowser && isLocal(window.location.hostname);
4165
+ if (isBrowser && isLocalhost && newConfig.token && newConfig.ignoreBrowserTokenWarning !== true) {
4166
+ warnings.printBrowserTokenWarning();
4167
+ } else if (typeof newConfig.useCdn === "undefined") {
4168
+ warnings.printCdnWarning();
4169
+ }
4170
+ if (projectBased) {
4171
+ validate.projectId(newConfig.projectId);
4172
+ }
4173
+ if (newConfig.dataset) {
4174
+ validate.dataset(newConfig.dataset);
4175
+ }
4176
+ if ("requestTagPrefix" in newConfig) {
4177
+ newConfig.requestTagPrefix = newConfig.requestTagPrefix ? validate.requestTag(newConfig.requestTagPrefix).replace(/\.+$/, "") : void 0;
4178
+ }
4179
+ newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, "");
4180
+ newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost;
4181
+ newConfig.useCdn = Boolean(newConfig.useCdn) && !newConfig.withCredentials;
4182
+ exports.validateApiVersion(newConfig.apiVersion);
4183
+ const hostParts = newConfig.apiHost.split("://", 2);
4184
+ const protocol = hostParts[0];
4185
+ const host = hostParts[1];
4186
+ const cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
4187
+ if (newConfig.useProjectHostname) {
4188
+ newConfig.url = `${protocol}://${newConfig.projectId}.${host}/v${newConfig.apiVersion}`;
4189
+ newConfig.cdnUrl = `${protocol}://${newConfig.projectId}.${cdnHost}/v${newConfig.apiVersion}`;
4190
+ } else {
4191
+ newConfig.url = `${newConfig.apiHost}/v${newConfig.apiVersion}`;
4192
+ newConfig.cdnUrl = newConfig.url;
4193
+ }
4194
+ return newConfig;
4195
+ };
4196
+ exports.validateApiVersion = function validateApiVersion(apiVersion) {
4197
+ if (apiVersion === "1" || apiVersion === "X") {
4198
+ return;
4199
+ }
4200
+ const apiDate = new Date(apiVersion);
4201
+ const apiVersionValid = /^\d{4}-\d{2}-\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0;
4202
+ if (!apiVersionValid) {
4203
+ throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
4204
+ }
4205
+ };
4206
+ }
4207
+ });
4208
+
4209
+ // src/sanityClient.js
4210
+ var require_sanityClient = __commonJS({
4211
+ "src/sanityClient.js"(exports, module) {
4212
+ var assign = require_object_assign();
4213
+ var { Observable, map, filter } = require_observable2();
4214
+ var Patch = require_patch();
4215
+ var Transaction = require_transaction();
4216
+ var dataMethods = require_dataMethods();
4217
+ var DatasetsClient = require_datasetsClient();
4218
+ var ProjectsClient = require_projectsClient();
4219
+ var AssetsClient = require_assetsClient();
4220
+ var UsersClient = require_usersClient();
4221
+ var AuthClient = require_authClient();
4222
+ var httpRequest = require_request2();
4223
+ var getRequestOptions = require_requestOptions();
4224
+ var { defaultConfig, initConfig } = require_config2();
4225
+ var validate = require_validators();
4226
+ var toPromise = (observable) => observable.toPromise();
4227
+ function SanityClient(config = defaultConfig) {
4228
+ if (!(this instanceof SanityClient)) {
4229
+ return new SanityClient(config);
4230
+ }
4231
+ this.config(config);
4232
+ this.assets = new AssetsClient(this);
4233
+ this.datasets = new DatasetsClient(this);
4234
+ this.projects = new ProjectsClient(this);
4235
+ this.users = new UsersClient(this);
4236
+ this.auth = new AuthClient(this);
4237
+ if (this.clientConfig.isPromiseAPI) {
4238
+ const observableConfig = assign({}, this.clientConfig, { isPromiseAPI: false });
4239
+ this.observable = new SanityClient(observableConfig);
4240
+ }
4241
+ }
4242
+ assign(SanityClient.prototype, dataMethods);
4243
+ assign(SanityClient.prototype, {
4244
+ clone() {
4245
+ return new SanityClient(this.config());
4246
+ },
4247
+ config(newConfig) {
4248
+ if (typeof newConfig === "undefined") {
4249
+ return assign({}, this.clientConfig);
4250
+ }
4251
+ if (this.observable) {
4252
+ const observableConfig = assign({}, newConfig, { isPromiseAPI: false });
4253
+ this.observable.config(observableConfig);
4254
+ }
4255
+ this.clientConfig = initConfig(newConfig, this.clientConfig || {});
4256
+ return this;
4257
+ },
4258
+ withConfig(newConfig) {
4259
+ return this.clone().config(newConfig);
4260
+ },
4261
+ getUrl(uri, useCdn = false) {
4262
+ const base = useCdn ? this.clientConfig.cdnUrl : this.clientConfig.url;
4263
+ return `${base}/${uri.replace(/^\//, "")}`;
4264
+ },
4265
+ isPromiseAPI() {
4266
+ return this.clientConfig.isPromiseAPI;
4267
+ },
4268
+ _requestObservable(options) {
4269
+ const uri = options.url || options.uri;
4270
+ const canUseCdn = typeof options.canUseCdn === "undefined" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/") === 0 : options.canUseCdn;
4271
+ const useCdn = this.clientConfig.useCdn && canUseCdn;
4272
+ const tag = options.tag && this.clientConfig.requestTagPrefix ? [this.clientConfig.requestTagPrefix, options.tag].join(".") : options.tag || this.clientConfig.requestTagPrefix;
4273
+ if (tag) {
4274
+ options.query = { tag: validate.requestTag(tag), ...options.query };
4275
+ }
4276
+ const reqOptions = getRequestOptions(this.clientConfig, assign({}, options, {
4277
+ url: this.getUrl(uri, useCdn)
4278
+ }));
4279
+ return new Observable((subscriber) => httpRequest(reqOptions, this.clientConfig.requester).subscribe(subscriber));
4280
+ },
4281
+ request(options) {
4282
+ const observable = this._requestObservable(options).pipe(filter((event) => event.type === "response"), map((event) => event.body));
4283
+ return this.isPromiseAPI() ? toPromise(observable) : observable;
4284
+ }
4285
+ });
4286
+ SanityClient.Patch = Patch;
4287
+ SanityClient.Transaction = Transaction;
4288
+ SanityClient.ClientError = httpRequest.ClientError;
4289
+ SanityClient.ServerError = httpRequest.ServerError;
4290
+ SanityClient.requester = httpRequest.defaultRequester;
4291
+ module.exports = SanityClient;
4292
+ }
4293
+ });
4294
+ export default require_sanityClient();
4295
+ /*
4296
+ object-assign
4297
+ (c) Sindre Sorhus
4298
+ @license MIT
4299
+ */
4300
+ /*!
4301
+ * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
4302
+ *
4303
+ * Copyright (c) 2014-2017, Jon Schlinkert.
4304
+ * Released under the MIT License.
4305
+ */
4306
+ /*!
4307
+ * isobject <https://github.com/jonschlinkert/isobject>
4308
+ *
4309
+ * Copyright (c) 2014-2017, Jon Schlinkert.
4310
+ * Released under the MIT License.
4311
+ */
4312
+ /** @license
4313
+ * eventsource.js
4314
+ * Available under MIT License (MIT)
4315
+ * https://github.com/Yaffle/EventSource/
4316
+ */
4317
+ //# sourceMappingURL=sanityClient.browser.mjs.map