@spica-devkit/identity 0.9.12 → 0.9.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,4 +1,24 @@
1
- import axios from 'axios';
1
+ import axios_1 from 'axios';
2
+
3
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
4
+
5
+ function createCommonjsModule(fn, basedir, module) {
6
+ return module = {
7
+ path: basedir,
8
+ exports: {},
9
+ require: function (path, base) {
10
+ return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
11
+ }
12
+ }, fn(module, module.exports), module.exports;
13
+ }
14
+
15
+ function commonjsRequire () {
16
+ throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
17
+ }
18
+
19
+ var request = createCommonjsModule(function (module, exports) {
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.Axios = exports.logWarning = void 0;
2
22
 
3
23
  function logWarning(response) {
4
24
  const warning = response.headers["warning"];
@@ -6,6 +26,7 @@ function logWarning(response) {
6
26
  console.warn(warning);
7
27
  }
8
28
  }
29
+ exports.logWarning = logWarning;
9
30
  class Axios {
10
31
  constructor(config) {
11
32
  this.interceptors = {
@@ -30,7 +51,7 @@ class Axios {
30
51
  }
31
52
  }
32
53
  };
33
- this.instance = axios.create(config);
54
+ this.instance = axios_1.default.create(config);
34
55
  this.instance.interceptors.request.use(this.interceptors.request.onFulfilled, this.interceptors.request.onRejected);
35
56
  this.instance.interceptors.response.use(this.interceptors.response.onFulfilled, this.interceptors.response.onRejected);
36
57
  this.baseUrl = this.instance.defaults.baseURL;
@@ -63,6 +84,13 @@ class Axios {
63
84
  return this.instance.delete(url, config);
64
85
  }
65
86
  }
87
+ exports.Axios = Axios;
88
+
89
+ });
90
+
91
+ var initialize_1 = createCommonjsModule(function (module, exports) {
92
+ Object.defineProperty(exports, "__esModule", { value: true });
93
+ exports.isPlatformBrowser = exports.checkInitialized = exports.initialize = void 0;
66
94
 
67
95
  let service;
68
96
  function initialize(options) {
@@ -79,7 +107,7 @@ function initialize(options) {
79
107
  throw new Error("Public url must be provided.");
80
108
  }
81
109
  if (!service) {
82
- service = new Axios({ baseURL: publicUrl, headers: { Authorization: authorization } });
110
+ service = new request.Axios({ baseURL: publicUrl, headers: { Authorization: authorization } });
83
111
  }
84
112
  else {
85
113
  service.setBaseUrl(publicUrl);
@@ -87,51 +115,727 @@ function initialize(options) {
87
115
  }
88
116
  return { authorization, publicUrl, service };
89
117
  }
118
+ exports.initialize = initialize;
90
119
  function checkInitialized(authorization) {
91
120
  if (!authorization) {
92
121
  throw new Error("You should call initialize method with a valid apikey or identity token.");
93
122
  }
94
123
  }
124
+ exports.checkInitialized = checkInitialized;
95
125
  function getPublicUrl() {
96
126
  return isPlatformBrowser() ? undefined : process.env.__INTERNAL__SPICA__PUBLIC_URL__;
97
127
  }
98
128
  function isPlatformBrowser() {
99
129
  return typeof window !== "undefined";
100
130
  }
131
+ exports.isPlatformBrowser = isPlatformBrowser;
101
132
 
102
- var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
103
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
104
- return new (P || (P = Promise))(function (resolve, reject) {
105
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
106
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
107
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
108
- step((generator = generator.apply(thisArg, _arguments || [])).next());
109
- });
133
+ });
134
+
135
+ var _interface = createCommonjsModule(function (module, exports) {
136
+ Object.defineProperty(exports, "__esModule", { value: true });
137
+
138
+ });
139
+
140
+ var url = createCommonjsModule(function (module, exports) {
141
+ Object.defineProperty(exports, "__esModule", { value: true });
142
+ exports.buildUrl = void 0;
143
+ function buildUrl(baseUrl, queryParams = {}) {
144
+ const url = new URL(baseUrl);
145
+ for (let [key, value] of Object.entries(queryParams)) {
146
+ if (typeof value != "string") {
147
+ value = JSON.stringify(value);
148
+ }
149
+ url.searchParams.set(key, value);
150
+ }
151
+ return url;
152
+ }
153
+ exports.buildUrl = buildUrl;
154
+
155
+ });
156
+
157
+ var src = createCommonjsModule(function (module, exports) {
158
+ var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
159
+ if (k2 === undefined) k2 = k;
160
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
161
+ }) : (function(o, m, k, k2) {
162
+ if (k2 === undefined) k2 = k;
163
+ o[k2] = m[k];
164
+ }));
165
+ var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
166
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
110
167
  };
168
+ Object.defineProperty(exports, "__esModule", { value: true });
169
+ __exportStar(initialize_1, exports);
170
+ __exportStar(_interface, exports);
171
+ __exportStar(request, exports);
172
+ __exportStar(url, exports);
173
+
174
+ });
175
+
176
+ var internal_common = createCommonjsModule(function (module, exports) {
177
+ var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
178
+ if (k2 === undefined) k2 = k;
179
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
180
+ }) : (function(o, m, k, k2) {
181
+ if (k2 === undefined) k2 = k;
182
+ o[k2] = m[k];
183
+ }));
184
+ var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
185
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
186
+ };
187
+ Object.defineProperty(exports, "__esModule", { value: true });
188
+ __exportStar(src, exports);
189
+
190
+ });
191
+
192
+ /*! *****************************************************************************
193
+ Copyright (c) Microsoft Corporation.
194
+
195
+ Permission to use, copy, modify, and/or distribute this software for any
196
+ purpose with or without fee is hereby granted.
197
+
198
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
199
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
200
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
201
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
202
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
203
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
204
+ PERFORMANCE OF THIS SOFTWARE.
205
+ ***************************************************************************** */
206
+ /* global Reflect, Promise */
207
+
208
+ var extendStatics = function(d, b) {
209
+ extendStatics = Object.setPrototypeOf ||
210
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
211
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
212
+ return extendStatics(d, b);
213
+ };
214
+
215
+ function __extends(d, b) {
216
+ extendStatics(d, b);
217
+ function __() { this.constructor = d; }
218
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
219
+ }
220
+
221
+ /** PURE_IMPORTS_START PURE_IMPORTS_END */
222
+ function isFunction(x) {
223
+ return typeof x === 'function';
224
+ }
225
+
226
+ /** PURE_IMPORTS_START PURE_IMPORTS_END */
227
+ var _enable_super_gross_mode_that_will_cause_bad_things = false;
228
+ var config = {
229
+ Promise: undefined,
230
+ set useDeprecatedSynchronousErrorHandling(value) {
231
+ if (value) {
232
+ var error = /*@__PURE__*/ new Error();
233
+ /*@__PURE__*/ console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \n' + error.stack);
234
+ }
235
+ _enable_super_gross_mode_that_will_cause_bad_things = value;
236
+ },
237
+ get useDeprecatedSynchronousErrorHandling() {
238
+ return _enable_super_gross_mode_that_will_cause_bad_things;
239
+ },
240
+ };
241
+
242
+ /** PURE_IMPORTS_START PURE_IMPORTS_END */
243
+ function hostReportError(err) {
244
+ setTimeout(function () { throw err; }, 0);
245
+ }
246
+
247
+ /** PURE_IMPORTS_START _config,_util_hostReportError PURE_IMPORTS_END */
248
+ var empty = {
249
+ closed: true,
250
+ next: function (value) { },
251
+ error: function (err) {
252
+ if (config.useDeprecatedSynchronousErrorHandling) {
253
+ throw err;
254
+ }
255
+ else {
256
+ hostReportError(err);
257
+ }
258
+ },
259
+ complete: function () { }
260
+ };
261
+
262
+ /** PURE_IMPORTS_START PURE_IMPORTS_END */
263
+ var isArray = /*@__PURE__*/ (function () { return Array.isArray || (function (x) { return x && typeof x.length === 'number'; }); })();
264
+
265
+ /** PURE_IMPORTS_START PURE_IMPORTS_END */
266
+ function isObject(x) {
267
+ return x !== null && typeof x === 'object';
268
+ }
269
+
270
+ /** PURE_IMPORTS_START PURE_IMPORTS_END */
271
+ var UnsubscriptionErrorImpl = /*@__PURE__*/ (function () {
272
+ function UnsubscriptionErrorImpl(errors) {
273
+ Error.call(this);
274
+ this.message = errors ?
275
+ errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ') : '';
276
+ this.name = 'UnsubscriptionError';
277
+ this.errors = errors;
278
+ return this;
279
+ }
280
+ UnsubscriptionErrorImpl.prototype = /*@__PURE__*/ Object.create(Error.prototype);
281
+ return UnsubscriptionErrorImpl;
282
+ })();
283
+ var UnsubscriptionError = UnsubscriptionErrorImpl;
284
+
285
+ /** PURE_IMPORTS_START _util_isArray,_util_isObject,_util_isFunction,_util_UnsubscriptionError PURE_IMPORTS_END */
286
+ var Subscription = /*@__PURE__*/ (function () {
287
+ function Subscription(unsubscribe) {
288
+ this.closed = false;
289
+ this._parentOrParents = null;
290
+ this._subscriptions = null;
291
+ if (unsubscribe) {
292
+ this._ctorUnsubscribe = true;
293
+ this._unsubscribe = unsubscribe;
294
+ }
295
+ }
296
+ Subscription.prototype.unsubscribe = function () {
297
+ var errors;
298
+ if (this.closed) {
299
+ return;
300
+ }
301
+ var _a = this, _parentOrParents = _a._parentOrParents, _ctorUnsubscribe = _a._ctorUnsubscribe, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions;
302
+ this.closed = true;
303
+ this._parentOrParents = null;
304
+ this._subscriptions = null;
305
+ if (_parentOrParents instanceof Subscription) {
306
+ _parentOrParents.remove(this);
307
+ }
308
+ else if (_parentOrParents !== null) {
309
+ for (var index = 0; index < _parentOrParents.length; ++index) {
310
+ var parent_1 = _parentOrParents[index];
311
+ parent_1.remove(this);
312
+ }
313
+ }
314
+ if (isFunction(_unsubscribe)) {
315
+ if (_ctorUnsubscribe) {
316
+ this._unsubscribe = undefined;
317
+ }
318
+ try {
319
+ _unsubscribe.call(this);
320
+ }
321
+ catch (e) {
322
+ errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e];
323
+ }
324
+ }
325
+ if (isArray(_subscriptions)) {
326
+ var index = -1;
327
+ var len = _subscriptions.length;
328
+ while (++index < len) {
329
+ var sub = _subscriptions[index];
330
+ if (isObject(sub)) {
331
+ try {
332
+ sub.unsubscribe();
333
+ }
334
+ catch (e) {
335
+ errors = errors || [];
336
+ if (e instanceof UnsubscriptionError) {
337
+ errors = errors.concat(flattenUnsubscriptionErrors(e.errors));
338
+ }
339
+ else {
340
+ errors.push(e);
341
+ }
342
+ }
343
+ }
344
+ }
345
+ }
346
+ if (errors) {
347
+ throw new UnsubscriptionError(errors);
348
+ }
349
+ };
350
+ Subscription.prototype.add = function (teardown) {
351
+ var subscription = teardown;
352
+ if (!teardown) {
353
+ return Subscription.EMPTY;
354
+ }
355
+ switch (typeof teardown) {
356
+ case 'function':
357
+ subscription = new Subscription(teardown);
358
+ case 'object':
359
+ if (subscription === this || subscription.closed || typeof subscription.unsubscribe !== 'function') {
360
+ return subscription;
361
+ }
362
+ else if (this.closed) {
363
+ subscription.unsubscribe();
364
+ return subscription;
365
+ }
366
+ else if (!(subscription instanceof Subscription)) {
367
+ var tmp = subscription;
368
+ subscription = new Subscription();
369
+ subscription._subscriptions = [tmp];
370
+ }
371
+ break;
372
+ default: {
373
+ throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');
374
+ }
375
+ }
376
+ var _parentOrParents = subscription._parentOrParents;
377
+ if (_parentOrParents === null) {
378
+ subscription._parentOrParents = this;
379
+ }
380
+ else if (_parentOrParents instanceof Subscription) {
381
+ if (_parentOrParents === this) {
382
+ return subscription;
383
+ }
384
+ subscription._parentOrParents = [_parentOrParents, this];
385
+ }
386
+ else if (_parentOrParents.indexOf(this) === -1) {
387
+ _parentOrParents.push(this);
388
+ }
389
+ else {
390
+ return subscription;
391
+ }
392
+ var subscriptions = this._subscriptions;
393
+ if (subscriptions === null) {
394
+ this._subscriptions = [subscription];
395
+ }
396
+ else {
397
+ subscriptions.push(subscription);
398
+ }
399
+ return subscription;
400
+ };
401
+ Subscription.prototype.remove = function (subscription) {
402
+ var subscriptions = this._subscriptions;
403
+ if (subscriptions) {
404
+ var subscriptionIndex = subscriptions.indexOf(subscription);
405
+ if (subscriptionIndex !== -1) {
406
+ subscriptions.splice(subscriptionIndex, 1);
407
+ }
408
+ }
409
+ };
410
+ Subscription.EMPTY = (function (empty) {
411
+ empty.closed = true;
412
+ return empty;
413
+ }(new Subscription()));
414
+ return Subscription;
415
+ }());
416
+ function flattenUnsubscriptionErrors(errors) {
417
+ return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError) ? err.errors : err); }, []);
418
+ }
419
+
420
+ /** PURE_IMPORTS_START PURE_IMPORTS_END */
421
+ var rxSubscriber = /*@__PURE__*/ (function () {
422
+ return typeof Symbol === 'function'
423
+ ? /*@__PURE__*/ Symbol('rxSubscriber')
424
+ : '@@rxSubscriber_' + /*@__PURE__*/ Math.random();
425
+ })();
426
+
427
+ /** PURE_IMPORTS_START tslib,_util_isFunction,_Observer,_Subscription,_internal_symbol_rxSubscriber,_config,_util_hostReportError PURE_IMPORTS_END */
428
+ var Subscriber = /*@__PURE__*/ (function (_super) {
429
+ __extends(Subscriber, _super);
430
+ function Subscriber(destinationOrNext, error, complete) {
431
+ var _this = _super.call(this) || this;
432
+ _this.syncErrorValue = null;
433
+ _this.syncErrorThrown = false;
434
+ _this.syncErrorThrowable = false;
435
+ _this.isStopped = false;
436
+ switch (arguments.length) {
437
+ case 0:
438
+ _this.destination = empty;
439
+ break;
440
+ case 1:
441
+ if (!destinationOrNext) {
442
+ _this.destination = empty;
443
+ break;
444
+ }
445
+ if (typeof destinationOrNext === 'object') {
446
+ if (destinationOrNext instanceof Subscriber) {
447
+ _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;
448
+ _this.destination = destinationOrNext;
449
+ destinationOrNext.add(_this);
450
+ }
451
+ else {
452
+ _this.syncErrorThrowable = true;
453
+ _this.destination = new SafeSubscriber(_this, destinationOrNext);
454
+ }
455
+ break;
456
+ }
457
+ default:
458
+ _this.syncErrorThrowable = true;
459
+ _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete);
460
+ break;
461
+ }
462
+ return _this;
463
+ }
464
+ Subscriber.prototype[rxSubscriber] = function () { return this; };
465
+ Subscriber.create = function (next, error, complete) {
466
+ var subscriber = new Subscriber(next, error, complete);
467
+ subscriber.syncErrorThrowable = false;
468
+ return subscriber;
469
+ };
470
+ Subscriber.prototype.next = function (value) {
471
+ if (!this.isStopped) {
472
+ this._next(value);
473
+ }
474
+ };
475
+ Subscriber.prototype.error = function (err) {
476
+ if (!this.isStopped) {
477
+ this.isStopped = true;
478
+ this._error(err);
479
+ }
480
+ };
481
+ Subscriber.prototype.complete = function () {
482
+ if (!this.isStopped) {
483
+ this.isStopped = true;
484
+ this._complete();
485
+ }
486
+ };
487
+ Subscriber.prototype.unsubscribe = function () {
488
+ if (this.closed) {
489
+ return;
490
+ }
491
+ this.isStopped = true;
492
+ _super.prototype.unsubscribe.call(this);
493
+ };
494
+ Subscriber.prototype._next = function (value) {
495
+ this.destination.next(value);
496
+ };
497
+ Subscriber.prototype._error = function (err) {
498
+ this.destination.error(err);
499
+ this.unsubscribe();
500
+ };
501
+ Subscriber.prototype._complete = function () {
502
+ this.destination.complete();
503
+ this.unsubscribe();
504
+ };
505
+ Subscriber.prototype._unsubscribeAndRecycle = function () {
506
+ var _parentOrParents = this._parentOrParents;
507
+ this._parentOrParents = null;
508
+ this.unsubscribe();
509
+ this.closed = false;
510
+ this.isStopped = false;
511
+ this._parentOrParents = _parentOrParents;
512
+ return this;
513
+ };
514
+ return Subscriber;
515
+ }(Subscription));
516
+ var SafeSubscriber = /*@__PURE__*/ (function (_super) {
517
+ __extends(SafeSubscriber, _super);
518
+ function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) {
519
+ var _this = _super.call(this) || this;
520
+ _this._parentSubscriber = _parentSubscriber;
521
+ var next;
522
+ var context = _this;
523
+ if (isFunction(observerOrNext)) {
524
+ next = observerOrNext;
525
+ }
526
+ else if (observerOrNext) {
527
+ next = observerOrNext.next;
528
+ error = observerOrNext.error;
529
+ complete = observerOrNext.complete;
530
+ if (observerOrNext !== empty) {
531
+ context = Object.create(observerOrNext);
532
+ if (isFunction(context.unsubscribe)) {
533
+ _this.add(context.unsubscribe.bind(context));
534
+ }
535
+ context.unsubscribe = _this.unsubscribe.bind(_this);
536
+ }
537
+ }
538
+ _this._context = context;
539
+ _this._next = next;
540
+ _this._error = error;
541
+ _this._complete = complete;
542
+ return _this;
543
+ }
544
+ SafeSubscriber.prototype.next = function (value) {
545
+ if (!this.isStopped && this._next) {
546
+ var _parentSubscriber = this._parentSubscriber;
547
+ if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
548
+ this.__tryOrUnsub(this._next, value);
549
+ }
550
+ else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {
551
+ this.unsubscribe();
552
+ }
553
+ }
554
+ };
555
+ SafeSubscriber.prototype.error = function (err) {
556
+ if (!this.isStopped) {
557
+ var _parentSubscriber = this._parentSubscriber;
558
+ var useDeprecatedSynchronousErrorHandling = config.useDeprecatedSynchronousErrorHandling;
559
+ if (this._error) {
560
+ if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
561
+ this.__tryOrUnsub(this._error, err);
562
+ this.unsubscribe();
563
+ }
564
+ else {
565
+ this.__tryOrSetError(_parentSubscriber, this._error, err);
566
+ this.unsubscribe();
567
+ }
568
+ }
569
+ else if (!_parentSubscriber.syncErrorThrowable) {
570
+ this.unsubscribe();
571
+ if (useDeprecatedSynchronousErrorHandling) {
572
+ throw err;
573
+ }
574
+ hostReportError(err);
575
+ }
576
+ else {
577
+ if (useDeprecatedSynchronousErrorHandling) {
578
+ _parentSubscriber.syncErrorValue = err;
579
+ _parentSubscriber.syncErrorThrown = true;
580
+ }
581
+ else {
582
+ hostReportError(err);
583
+ }
584
+ this.unsubscribe();
585
+ }
586
+ }
587
+ };
588
+ SafeSubscriber.prototype.complete = function () {
589
+ var _this = this;
590
+ if (!this.isStopped) {
591
+ var _parentSubscriber = this._parentSubscriber;
592
+ if (this._complete) {
593
+ var wrappedComplete = function () { return _this._complete.call(_this._context); };
594
+ if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
595
+ this.__tryOrUnsub(wrappedComplete);
596
+ this.unsubscribe();
597
+ }
598
+ else {
599
+ this.__tryOrSetError(_parentSubscriber, wrappedComplete);
600
+ this.unsubscribe();
601
+ }
602
+ }
603
+ else {
604
+ this.unsubscribe();
605
+ }
606
+ }
607
+ };
608
+ SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) {
609
+ try {
610
+ fn.call(this._context, value);
611
+ }
612
+ catch (err) {
613
+ this.unsubscribe();
614
+ if (config.useDeprecatedSynchronousErrorHandling) {
615
+ throw err;
616
+ }
617
+ else {
618
+ hostReportError(err);
619
+ }
620
+ }
621
+ };
622
+ SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) {
623
+ if (!config.useDeprecatedSynchronousErrorHandling) {
624
+ throw new Error('bad call');
625
+ }
626
+ try {
627
+ fn.call(this._context, value);
628
+ }
629
+ catch (err) {
630
+ if (config.useDeprecatedSynchronousErrorHandling) {
631
+ parent.syncErrorValue = err;
632
+ parent.syncErrorThrown = true;
633
+ return true;
634
+ }
635
+ else {
636
+ hostReportError(err);
637
+ return true;
638
+ }
639
+ }
640
+ return false;
641
+ };
642
+ SafeSubscriber.prototype._unsubscribe = function () {
643
+ var _parentSubscriber = this._parentSubscriber;
644
+ this._context = null;
645
+ this._parentSubscriber = null;
646
+ _parentSubscriber.unsubscribe();
647
+ };
648
+ return SafeSubscriber;
649
+ }(Subscriber));
650
+
651
+ /** PURE_IMPORTS_START _Subscriber PURE_IMPORTS_END */
652
+ function canReportError(observer) {
653
+ while (observer) {
654
+ var _a = observer, closed_1 = _a.closed, destination = _a.destination, isStopped = _a.isStopped;
655
+ if (closed_1 || isStopped) {
656
+ return false;
657
+ }
658
+ else if (destination && destination instanceof Subscriber) {
659
+ observer = destination;
660
+ }
661
+ else {
662
+ observer = null;
663
+ }
664
+ }
665
+ return true;
666
+ }
667
+
668
+ /** PURE_IMPORTS_START _Subscriber,_symbol_rxSubscriber,_Observer PURE_IMPORTS_END */
669
+ function toSubscriber(nextOrObserver, error, complete) {
670
+ if (nextOrObserver) {
671
+ if (nextOrObserver instanceof Subscriber) {
672
+ return nextOrObserver;
673
+ }
674
+ if (nextOrObserver[rxSubscriber]) {
675
+ return nextOrObserver[rxSubscriber]();
676
+ }
677
+ }
678
+ if (!nextOrObserver && !error && !complete) {
679
+ return new Subscriber(empty);
680
+ }
681
+ return new Subscriber(nextOrObserver, error, complete);
682
+ }
683
+
684
+ /** PURE_IMPORTS_START PURE_IMPORTS_END */
685
+ var observable = /*@__PURE__*/ (function () { return typeof Symbol === 'function' && Symbol.observable || '@@observable'; })();
686
+
687
+ /** PURE_IMPORTS_START PURE_IMPORTS_END */
688
+ function identity(x) {
689
+ return x;
690
+ }
691
+
692
+ /** PURE_IMPORTS_START _identity PURE_IMPORTS_END */
693
+ function pipeFromArray(fns) {
694
+ if (fns.length === 0) {
695
+ return identity;
696
+ }
697
+ if (fns.length === 1) {
698
+ return fns[0];
699
+ }
700
+ return function piped(input) {
701
+ return fns.reduce(function (prev, fn) { return fn(prev); }, input);
702
+ };
703
+ }
704
+
705
+ /** PURE_IMPORTS_START _util_canReportError,_util_toSubscriber,_symbol_observable,_util_pipe,_config PURE_IMPORTS_END */
706
+ var Observable = /*@__PURE__*/ (function () {
707
+ function Observable(subscribe) {
708
+ this._isScalar = false;
709
+ if (subscribe) {
710
+ this._subscribe = subscribe;
711
+ }
712
+ }
713
+ Observable.prototype.lift = function (operator) {
714
+ var observable = new Observable();
715
+ observable.source = this;
716
+ observable.operator = operator;
717
+ return observable;
718
+ };
719
+ Observable.prototype.subscribe = function (observerOrNext, error, complete) {
720
+ var operator = this.operator;
721
+ var sink = toSubscriber(observerOrNext, error, complete);
722
+ if (operator) {
723
+ sink.add(operator.call(sink, this.source));
724
+ }
725
+ else {
726
+ sink.add(this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?
727
+ this._subscribe(sink) :
728
+ this._trySubscribe(sink));
729
+ }
730
+ if (config.useDeprecatedSynchronousErrorHandling) {
731
+ if (sink.syncErrorThrowable) {
732
+ sink.syncErrorThrowable = false;
733
+ if (sink.syncErrorThrown) {
734
+ throw sink.syncErrorValue;
735
+ }
736
+ }
737
+ }
738
+ return sink;
739
+ };
740
+ Observable.prototype._trySubscribe = function (sink) {
741
+ try {
742
+ return this._subscribe(sink);
743
+ }
744
+ catch (err) {
745
+ if (config.useDeprecatedSynchronousErrorHandling) {
746
+ sink.syncErrorThrown = true;
747
+ sink.syncErrorValue = err;
748
+ }
749
+ if (canReportError(sink)) {
750
+ sink.error(err);
751
+ }
752
+ else {
753
+ console.warn(err);
754
+ }
755
+ }
756
+ };
757
+ Observable.prototype.forEach = function (next, promiseCtor) {
758
+ var _this = this;
759
+ promiseCtor = getPromiseCtor(promiseCtor);
760
+ return new promiseCtor(function (resolve, reject) {
761
+ var subscription;
762
+ subscription = _this.subscribe(function (value) {
763
+ try {
764
+ next(value);
765
+ }
766
+ catch (err) {
767
+ reject(err);
768
+ if (subscription) {
769
+ subscription.unsubscribe();
770
+ }
771
+ }
772
+ }, reject, resolve);
773
+ });
774
+ };
775
+ Observable.prototype._subscribe = function (subscriber) {
776
+ var source = this.source;
777
+ return source && source.subscribe(subscriber);
778
+ };
779
+ Observable.prototype[observable] = function () {
780
+ return this;
781
+ };
782
+ Observable.prototype.pipe = function () {
783
+ var operations = [];
784
+ for (var _i = 0; _i < arguments.length; _i++) {
785
+ operations[_i] = arguments[_i];
786
+ }
787
+ if (operations.length === 0) {
788
+ return this;
789
+ }
790
+ return pipeFromArray(operations)(this);
791
+ };
792
+ Observable.prototype.toPromise = function (promiseCtor) {
793
+ var _this = this;
794
+ promiseCtor = getPromiseCtor(promiseCtor);
795
+ return new promiseCtor(function (resolve, reject) {
796
+ var value;
797
+ _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); });
798
+ });
799
+ };
800
+ Observable.create = function (subscribe) {
801
+ return new Observable(subscribe);
802
+ };
803
+ return Observable;
804
+ }());
805
+ function getPromiseCtor(promiseCtor) {
806
+ if (!promiseCtor) {
807
+ promiseCtor = Promise;
808
+ }
809
+ if (!promiseCtor) {
810
+ throw new Error('no Promise impl found');
811
+ }
812
+ return promiseCtor;
813
+ }
814
+
111
815
  let authorization;
112
- let service$1;
816
+ let service;
113
817
  const identitySegment = "passport/identity";
114
- function initialize$1(options) {
115
- const { authorization: _authorization, service: _service } = initialize(options);
818
+ function initialize(options) {
819
+ const { authorization: _authorization, service: _service } = internal_common.initialize(options);
116
820
  authorization = _authorization;
117
- service$1 = _service;
118
- service$1.setWriteDefaults({
821
+ service = _service;
822
+ service.setWriteDefaults({
119
823
  headers: {
120
824
  "Content-Type": "application/json"
121
825
  }
122
826
  });
123
827
  }
124
828
  function verifyToken(token, baseUrl) {
125
- const _baseUrl = baseUrl ? baseUrl : service$1 ? service$1.baseUrl : undefined;
829
+ const _baseUrl = baseUrl ? baseUrl : service ? service.baseUrl : undefined;
126
830
  if (!_baseUrl) {
127
831
  throw new Error("You should pass the base url of the server or call the initialize method.");
128
832
  }
129
- const req = new Axios({ baseURL: _baseUrl });
833
+ const req = new internal_common.Axios({ baseURL: _baseUrl });
130
834
  return req.get(`${identitySegment}/verify`, { headers: { Authorization: token } });
131
835
  }
132
836
  function login(identifier, password, tokenLifeSpan) {
133
- checkInitialized(authorization);
134
- return service$1
837
+ internal_common.checkInitialized(authorization);
838
+ return service
135
839
  .post("/passport/identify", {
136
840
  identifier,
137
841
  password,
@@ -139,43 +843,63 @@ function login(identifier, password, tokenLifeSpan) {
139
843
  })
140
844
  .then(response => response.token);
141
845
  }
846
+ async function loginWithStrategy(id) {
847
+ internal_common.checkInitialized(authorization);
848
+ const { url, state } = await service.get(`/passport/strategy/${id}/url`);
849
+ const token = new Observable(observer => {
850
+ service
851
+ .post("/passport/identify", {
852
+ state
853
+ })
854
+ .then(({ token }) => {
855
+ observer.next(token);
856
+ observer.complete();
857
+ })
858
+ .catch(e => observer.error(e));
859
+ });
860
+ return {
861
+ url,
862
+ token
863
+ };
864
+ }
865
+ function getStrategies() {
866
+ return service.get("/passport/strategies");
867
+ }
142
868
  function get(id) {
143
- checkInitialized(authorization);
144
- return service$1.get(`${identitySegment}/${id}`);
869
+ internal_common.checkInitialized(authorization);
870
+ return service.get(`${identitySegment}/${id}`);
145
871
  }
146
872
  function getAll(queryParams = {}) {
147
- checkInitialized(authorization);
148
- return service$1.get(identitySegment, {
873
+ internal_common.checkInitialized(authorization);
874
+ return service.get(identitySegment, {
149
875
  params: queryParams
150
876
  });
151
877
  }
152
- function insert(identity) {
153
- return __awaiter(this, void 0, void 0, function* () {
154
- checkInitialized(authorization);
155
- const insertedIdentity = yield service$1.post(identitySegment, identity);
156
- return policy.attach(insertedIdentity._id, identity.policies).then(policies => {
157
- insertedIdentity.policies = policies;
158
- return insertedIdentity;
159
- });
878
+ async function insert(identity) {
879
+ internal_common.checkInitialized(authorization);
880
+ const insertedIdentity = await service.post(identitySegment, identity);
881
+ return policy.attach(insertedIdentity._id, identity.policies).then(policies => {
882
+ insertedIdentity.policies = policies;
883
+ return insertedIdentity;
160
884
  });
161
885
  }
162
886
  function update(id, identity) {
163
- checkInitialized(authorization);
164
- return service$1.put(`${identitySegment}/${id}`, identity);
887
+ internal_common.checkInitialized(authorization);
888
+ return service.put(`${identitySegment}/${id}`, identity);
165
889
  }
166
890
  function remove(id) {
167
- checkInitialized(authorization);
168
- return service$1.delete(`${identitySegment}/${id}`);
891
+ internal_common.checkInitialized(authorization);
892
+ return service.delete(`${identitySegment}/${id}`);
169
893
  }
170
894
  // policy attach detach
171
895
  var policy;
172
896
  (function (policy) {
173
897
  function attach(identityId, policyIds = []) {
174
- checkInitialized(authorization);
898
+ internal_common.checkInitialized(authorization);
175
899
  const promises = [];
176
900
  const attachedPolicies = new Set();
177
901
  for (const policyId of policyIds) {
178
- const promise = service$1
902
+ const promise = service
179
903
  .put(`${identitySegment}/${identityId}/policy/${policyId}`, {})
180
904
  .then(() => attachedPolicies.add(policyId))
181
905
  .catch(e => {
@@ -188,11 +912,11 @@ var policy;
188
912
  }
189
913
  policy.attach = attach;
190
914
  function detach(identityId, policyIds = []) {
191
- checkInitialized(authorization);
915
+ internal_common.checkInitialized(authorization);
192
916
  const promises = [];
193
917
  const detachedPolicies = new Set();
194
918
  for (const policyId of policyIds) {
195
- const promise = service$1
919
+ const promise = service
196
920
  .delete(`${identitySegment}/${identityId}/policy/${policyId}`)
197
921
  .then(() => detachedPolicies.add(policyId))
198
922
  .catch(e => {
@@ -206,5 +930,5 @@ var policy;
206
930
  policy.detach = detach;
207
931
  })(policy || (policy = {}));
208
932
 
209
- export { get, getAll, initialize$1 as initialize, insert, login, policy, remove, update, verifyToken };
933
+ export { get, getAll, getStrategies, initialize, insert, login, loginWithStrategy, policy, remove, update, verifyToken };
210
934
  //# sourceMappingURL=index.mjs.map