@spica-devkit/identity 0.13.0 → 0.13.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.
- package/index.d.ts +123 -0
- package/index.js +467 -0
- package/index.js.map +1 -0
- package/index.mjs +454 -0
- package/index.mjs.map +1 -0
- package/package.json +9 -6
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -918
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -906
- package/dist/index.mjs.map +0 -1
- package/dist/src/identity.d.ts +0 -36
- package/dist/src/index.d.ts +0 -2
- package/dist/src/interface.d.ts +0 -69
package/dist/index.mjs
DELETED
|
@@ -1,906 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
function logWarning(response) {
|
|
4
|
-
const warning = response.headers["warning"];
|
|
5
|
-
if (warning) {
|
|
6
|
-
console.warn(warning);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
class Axios {
|
|
10
|
-
constructor(config) {
|
|
11
|
-
this.interceptors = {
|
|
12
|
-
request: {
|
|
13
|
-
onFulfilled: (request) => {
|
|
14
|
-
request.maxBodyLength = Number.MAX_SAFE_INTEGER;
|
|
15
|
-
request.maxContentLength = Number.MAX_SAFE_INTEGER;
|
|
16
|
-
if (!request.headers["Authorization"]) {
|
|
17
|
-
throw new Error("You should call initialize method with a valid apikey or identity token.");
|
|
18
|
-
}
|
|
19
|
-
return request;
|
|
20
|
-
},
|
|
21
|
-
onRejected: (error) => {
|
|
22
|
-
return Promise.reject(error);
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
response: {
|
|
26
|
-
onFulfilled: (response) => {
|
|
27
|
-
logWarning(response);
|
|
28
|
-
return response.data;
|
|
29
|
-
},
|
|
30
|
-
onRejected: (error) => {
|
|
31
|
-
return Promise.reject(error.response ? error.response.data : error);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
this.instance = axios.create(config);
|
|
36
|
-
this.instance.interceptors.request.use(this.interceptors.request.onFulfilled, this.interceptors.request.onRejected);
|
|
37
|
-
this.instance.interceptors.response.use(this.interceptors.response.onFulfilled, this.interceptors.response.onRejected);
|
|
38
|
-
this.baseUrl = this.instance.defaults.baseURL;
|
|
39
|
-
this.instance.defaults.paramsSerializer = paramsSerializer;
|
|
40
|
-
}
|
|
41
|
-
setBaseUrl(url) {
|
|
42
|
-
this.instance.defaults.baseURL = url;
|
|
43
|
-
}
|
|
44
|
-
setWriteDefaults(writeDefaults) {
|
|
45
|
-
for (const [header, value] of Object.entries(writeDefaults.headers)) {
|
|
46
|
-
this.instance.defaults.headers.post[header] = value;
|
|
47
|
-
this.instance.defaults.headers.put[header] = value;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
setAuthorization(authorization) {
|
|
51
|
-
this.instance.defaults.headers["Authorization"] = authorization;
|
|
52
|
-
}
|
|
53
|
-
get(url, config) {
|
|
54
|
-
return this.instance.get(url, config);
|
|
55
|
-
}
|
|
56
|
-
post(url, body, config) {
|
|
57
|
-
return this.instance.post(url, body, config);
|
|
58
|
-
}
|
|
59
|
-
put(url, body, config) {
|
|
60
|
-
return this.instance.put(url, body, config);
|
|
61
|
-
}
|
|
62
|
-
patch(url, body, config) {
|
|
63
|
-
return this.instance.patch(url, body, config);
|
|
64
|
-
}
|
|
65
|
-
delete(url, config) {
|
|
66
|
-
return this.instance.delete(url, config);
|
|
67
|
-
}
|
|
68
|
-
request(config) {
|
|
69
|
-
return this.instance.request(config);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function encode(val) {
|
|
73
|
-
return encodeURIComponent(val)
|
|
74
|
-
.replace(/%3A/gi, ":")
|
|
75
|
-
.replace(/%24/g, "$")
|
|
76
|
-
.replace(/%2C/gi, ",")
|
|
77
|
-
.replace(/%20/g, "+")
|
|
78
|
-
.replace(/%5B/gi, "[")
|
|
79
|
-
.replace(/%5D/gi, "]");
|
|
80
|
-
}
|
|
81
|
-
function utilsIsURLSearchParams(val) {
|
|
82
|
-
return typeof URLSearchParams !== "undefined" && val instanceof URLSearchParams;
|
|
83
|
-
}
|
|
84
|
-
function utilsIsArray(val) {
|
|
85
|
-
return toString.call(val) === "[object Array]";
|
|
86
|
-
}
|
|
87
|
-
function utilsIsDate(val) {
|
|
88
|
-
return toString.call(val) === "[object Date]";
|
|
89
|
-
}
|
|
90
|
-
function utilsIsObject(val) {
|
|
91
|
-
return val !== null && typeof val === "object";
|
|
92
|
-
}
|
|
93
|
-
function utilsForEach(obj, fn) {
|
|
94
|
-
if (obj === null || typeof obj === "undefined") {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (typeof obj !== "object") {
|
|
98
|
-
obj = [obj];
|
|
99
|
-
}
|
|
100
|
-
if (utilsIsArray(obj)) {
|
|
101
|
-
for (var i = 0, l = obj.length; i < l; i++) {
|
|
102
|
-
fn.call(null, obj[i], i, obj);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
for (var key in obj) {
|
|
107
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
108
|
-
fn.call(null, obj[key], key, obj);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
function paramsSerializer(params) {
|
|
114
|
-
if (utilsIsURLSearchParams(params)) {
|
|
115
|
-
return params.toString();
|
|
116
|
-
}
|
|
117
|
-
var parts = [];
|
|
118
|
-
utilsForEach(params, function serialize(val, key) {
|
|
119
|
-
if (val === null || typeof val === "undefined") {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (utilsIsArray(val)) {
|
|
123
|
-
key = key + "[]";
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
val = [val];
|
|
127
|
-
}
|
|
128
|
-
utilsForEach(val, function parseValue(v) {
|
|
129
|
-
if (utilsIsDate(v)) {
|
|
130
|
-
v = v.toISOString();
|
|
131
|
-
}
|
|
132
|
-
else if (utilsIsObject(v)) {
|
|
133
|
-
v = JSON.stringify(v);
|
|
134
|
-
}
|
|
135
|
-
parts.push(encode(key) + "=" + encode(v));
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
return parts.join("&");
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
let service$1;
|
|
142
|
-
function initialize$1(options) {
|
|
143
|
-
let authorization;
|
|
144
|
-
if ("apikey" in options) {
|
|
145
|
-
authorization = `APIKEY ${options.apikey}`;
|
|
146
|
-
}
|
|
147
|
-
else if ("identity" in options) {
|
|
148
|
-
authorization = `IDENTITY ${options.identity}`;
|
|
149
|
-
}
|
|
150
|
-
checkInitialized(authorization);
|
|
151
|
-
const publicUrl = options.publicUrl || getPublicUrl();
|
|
152
|
-
if (!publicUrl) {
|
|
153
|
-
throw new Error("Public url must be provided.");
|
|
154
|
-
}
|
|
155
|
-
if (!service$1) {
|
|
156
|
-
service$1 = new Axios({ baseURL: publicUrl, headers: { Authorization: authorization } });
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
service$1.setBaseUrl(publicUrl);
|
|
160
|
-
service$1.setAuthorization(authorization);
|
|
161
|
-
}
|
|
162
|
-
return { authorization, publicUrl, service: service$1 };
|
|
163
|
-
}
|
|
164
|
-
function checkInitialized(authorization) {
|
|
165
|
-
if (!authorization) {
|
|
166
|
-
throw new Error("You should call initialize method with a valid apikey or identity token.");
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
function getPublicUrl() {
|
|
170
|
-
return isPlatformBrowser() ? undefined : process.env.__INTERNAL__SPICA__PUBLIC_URL__;
|
|
171
|
-
}
|
|
172
|
-
function isPlatformBrowser() {
|
|
173
|
-
return typeof window !== "undefined";
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/******************************************************************************
|
|
177
|
-
Copyright (c) Microsoft Corporation.
|
|
178
|
-
|
|
179
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
180
|
-
purpose with or without fee is hereby granted.
|
|
181
|
-
|
|
182
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
183
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
184
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
185
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
186
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
187
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
188
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
189
|
-
***************************************************************************** */
|
|
190
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
191
|
-
|
|
192
|
-
var extendStatics = function(d, b) {
|
|
193
|
-
extendStatics = Object.setPrototypeOf ||
|
|
194
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
195
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
196
|
-
return extendStatics(d, b);
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
function __extends(d, b) {
|
|
200
|
-
if (typeof b !== "function" && b !== null)
|
|
201
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
202
|
-
extendStatics(d, b);
|
|
203
|
-
function __() { this.constructor = d; }
|
|
204
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function __values(o) {
|
|
208
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
209
|
-
if (m) return m.call(o);
|
|
210
|
-
if (o && typeof o.length === "number") return {
|
|
211
|
-
next: function () {
|
|
212
|
-
if (o && i >= o.length) o = undefined;
|
|
213
|
-
return { value: o && o[i++], done: !o };
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
function __read(o, n) {
|
|
220
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
221
|
-
if (!m) return o;
|
|
222
|
-
var i = m.call(o), r, ar = [], e;
|
|
223
|
-
try {
|
|
224
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
225
|
-
}
|
|
226
|
-
catch (error) { e = { error: error }; }
|
|
227
|
-
finally {
|
|
228
|
-
try {
|
|
229
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
230
|
-
}
|
|
231
|
-
finally { if (e) throw e.error; }
|
|
232
|
-
}
|
|
233
|
-
return ar;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function __spreadArray(to, from, pack) {
|
|
237
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
238
|
-
if (ar || !(i in from)) {
|
|
239
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
240
|
-
ar[i] = from[i];
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
247
|
-
var e = new Error(message);
|
|
248
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
function isFunction(value) {
|
|
252
|
-
return typeof value === 'function';
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function createErrorClass(createImpl) {
|
|
256
|
-
var _super = function (instance) {
|
|
257
|
-
Error.call(instance);
|
|
258
|
-
instance.stack = new Error().stack;
|
|
259
|
-
};
|
|
260
|
-
var ctorFunc = createImpl(_super);
|
|
261
|
-
ctorFunc.prototype = Object.create(Error.prototype);
|
|
262
|
-
ctorFunc.prototype.constructor = ctorFunc;
|
|
263
|
-
return ctorFunc;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
var UnsubscriptionError = createErrorClass(function (_super) {
|
|
267
|
-
return function UnsubscriptionErrorImpl(errors) {
|
|
268
|
-
_super(this);
|
|
269
|
-
this.message = errors
|
|
270
|
-
? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ')
|
|
271
|
-
: '';
|
|
272
|
-
this.name = 'UnsubscriptionError';
|
|
273
|
-
this.errors = errors;
|
|
274
|
-
};
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
function arrRemove(arr, item) {
|
|
278
|
-
if (arr) {
|
|
279
|
-
var index = arr.indexOf(item);
|
|
280
|
-
0 <= index && arr.splice(index, 1);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
var Subscription = (function () {
|
|
285
|
-
function Subscription(initialTeardown) {
|
|
286
|
-
this.initialTeardown = initialTeardown;
|
|
287
|
-
this.closed = false;
|
|
288
|
-
this._parentage = null;
|
|
289
|
-
this._finalizers = null;
|
|
290
|
-
}
|
|
291
|
-
Subscription.prototype.unsubscribe = function () {
|
|
292
|
-
var e_1, _a, e_2, _b;
|
|
293
|
-
var errors;
|
|
294
|
-
if (!this.closed) {
|
|
295
|
-
this.closed = true;
|
|
296
|
-
var _parentage = this._parentage;
|
|
297
|
-
if (_parentage) {
|
|
298
|
-
this._parentage = null;
|
|
299
|
-
if (Array.isArray(_parentage)) {
|
|
300
|
-
try {
|
|
301
|
-
for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
|
|
302
|
-
var parent_1 = _parentage_1_1.value;
|
|
303
|
-
parent_1.remove(this);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
307
|
-
finally {
|
|
308
|
-
try {
|
|
309
|
-
if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
|
|
310
|
-
}
|
|
311
|
-
finally { if (e_1) throw e_1.error; }
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
_parentage.remove(this);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
var initialFinalizer = this.initialTeardown;
|
|
319
|
-
if (isFunction(initialFinalizer)) {
|
|
320
|
-
try {
|
|
321
|
-
initialFinalizer();
|
|
322
|
-
}
|
|
323
|
-
catch (e) {
|
|
324
|
-
errors = e instanceof UnsubscriptionError ? e.errors : [e];
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
var _finalizers = this._finalizers;
|
|
328
|
-
if (_finalizers) {
|
|
329
|
-
this._finalizers = null;
|
|
330
|
-
try {
|
|
331
|
-
for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
|
|
332
|
-
var finalizer = _finalizers_1_1.value;
|
|
333
|
-
try {
|
|
334
|
-
execFinalizer(finalizer);
|
|
335
|
-
}
|
|
336
|
-
catch (err) {
|
|
337
|
-
errors = errors !== null && errors !== void 0 ? errors : [];
|
|
338
|
-
if (err instanceof UnsubscriptionError) {
|
|
339
|
-
errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
|
|
340
|
-
}
|
|
341
|
-
else {
|
|
342
|
-
errors.push(err);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
348
|
-
finally {
|
|
349
|
-
try {
|
|
350
|
-
if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
|
|
351
|
-
}
|
|
352
|
-
finally { if (e_2) throw e_2.error; }
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
if (errors) {
|
|
356
|
-
throw new UnsubscriptionError(errors);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
Subscription.prototype.add = function (teardown) {
|
|
361
|
-
var _a;
|
|
362
|
-
if (teardown && teardown !== this) {
|
|
363
|
-
if (this.closed) {
|
|
364
|
-
execFinalizer(teardown);
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
if (teardown instanceof Subscription) {
|
|
368
|
-
if (teardown.closed || teardown._hasParent(this)) {
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
teardown._addParent(this);
|
|
372
|
-
}
|
|
373
|
-
(this._finalizers = (_a = this._finalizers) !== null && _a !== undefined ? _a : []).push(teardown);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
Subscription.prototype._hasParent = function (parent) {
|
|
378
|
-
var _parentage = this._parentage;
|
|
379
|
-
return _parentage === parent || (Array.isArray(_parentage) && _parentage.includes(parent));
|
|
380
|
-
};
|
|
381
|
-
Subscription.prototype._addParent = function (parent) {
|
|
382
|
-
var _parentage = this._parentage;
|
|
383
|
-
this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
|
|
384
|
-
};
|
|
385
|
-
Subscription.prototype._removeParent = function (parent) {
|
|
386
|
-
var _parentage = this._parentage;
|
|
387
|
-
if (_parentage === parent) {
|
|
388
|
-
this._parentage = null;
|
|
389
|
-
}
|
|
390
|
-
else if (Array.isArray(_parentage)) {
|
|
391
|
-
arrRemove(_parentage, parent);
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
Subscription.prototype.remove = function (teardown) {
|
|
395
|
-
var _finalizers = this._finalizers;
|
|
396
|
-
_finalizers && arrRemove(_finalizers, teardown);
|
|
397
|
-
if (teardown instanceof Subscription) {
|
|
398
|
-
teardown._removeParent(this);
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
Subscription.EMPTY = (function () {
|
|
402
|
-
var empty = new Subscription();
|
|
403
|
-
empty.closed = true;
|
|
404
|
-
return empty;
|
|
405
|
-
})();
|
|
406
|
-
return Subscription;
|
|
407
|
-
}());
|
|
408
|
-
Subscription.EMPTY;
|
|
409
|
-
function isSubscription(value) {
|
|
410
|
-
return (value instanceof Subscription ||
|
|
411
|
-
(value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe)));
|
|
412
|
-
}
|
|
413
|
-
function execFinalizer(finalizer) {
|
|
414
|
-
if (isFunction(finalizer)) {
|
|
415
|
-
finalizer();
|
|
416
|
-
}
|
|
417
|
-
else {
|
|
418
|
-
finalizer.unsubscribe();
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
var config = {
|
|
423
|
-
onUnhandledError: null,
|
|
424
|
-
onStoppedNotification: null,
|
|
425
|
-
Promise: undefined,
|
|
426
|
-
useDeprecatedSynchronousErrorHandling: false,
|
|
427
|
-
useDeprecatedNextContext: false,
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
var timeoutProvider = {
|
|
431
|
-
setTimeout: function (handler, timeout) {
|
|
432
|
-
var args = [];
|
|
433
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
434
|
-
args[_i - 2] = arguments[_i];
|
|
435
|
-
}
|
|
436
|
-
return setTimeout.apply(undefined, __spreadArray([handler, timeout], __read(args)));
|
|
437
|
-
},
|
|
438
|
-
clearTimeout: function (handle) {
|
|
439
|
-
return (clearTimeout)(handle);
|
|
440
|
-
},
|
|
441
|
-
delegate: undefined,
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
function reportUnhandledError(err) {
|
|
445
|
-
timeoutProvider.setTimeout(function () {
|
|
446
|
-
{
|
|
447
|
-
throw err;
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
function noop() { }
|
|
453
|
-
|
|
454
|
-
function errorContext(cb) {
|
|
455
|
-
{
|
|
456
|
-
cb();
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
var Subscriber = (function (_super) {
|
|
461
|
-
__extends(Subscriber, _super);
|
|
462
|
-
function Subscriber(destination) {
|
|
463
|
-
var _this = _super.call(this) || this;
|
|
464
|
-
_this.isStopped = false;
|
|
465
|
-
if (destination) {
|
|
466
|
-
_this.destination = destination;
|
|
467
|
-
if (isSubscription(destination)) {
|
|
468
|
-
destination.add(_this);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
else {
|
|
472
|
-
_this.destination = EMPTY_OBSERVER;
|
|
473
|
-
}
|
|
474
|
-
return _this;
|
|
475
|
-
}
|
|
476
|
-
Subscriber.create = function (next, error, complete) {
|
|
477
|
-
return new SafeSubscriber(next, error, complete);
|
|
478
|
-
};
|
|
479
|
-
Subscriber.prototype.next = function (value) {
|
|
480
|
-
if (this.isStopped) ;
|
|
481
|
-
else {
|
|
482
|
-
this._next(value);
|
|
483
|
-
}
|
|
484
|
-
};
|
|
485
|
-
Subscriber.prototype.error = function (err) {
|
|
486
|
-
if (this.isStopped) ;
|
|
487
|
-
else {
|
|
488
|
-
this.isStopped = true;
|
|
489
|
-
this._error(err);
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
Subscriber.prototype.complete = function () {
|
|
493
|
-
if (this.isStopped) ;
|
|
494
|
-
else {
|
|
495
|
-
this.isStopped = true;
|
|
496
|
-
this._complete();
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
Subscriber.prototype.unsubscribe = function () {
|
|
500
|
-
if (!this.closed) {
|
|
501
|
-
this.isStopped = true;
|
|
502
|
-
_super.prototype.unsubscribe.call(this);
|
|
503
|
-
this.destination = null;
|
|
504
|
-
}
|
|
505
|
-
};
|
|
506
|
-
Subscriber.prototype._next = function (value) {
|
|
507
|
-
this.destination.next(value);
|
|
508
|
-
};
|
|
509
|
-
Subscriber.prototype._error = function (err) {
|
|
510
|
-
try {
|
|
511
|
-
this.destination.error(err);
|
|
512
|
-
}
|
|
513
|
-
finally {
|
|
514
|
-
this.unsubscribe();
|
|
515
|
-
}
|
|
516
|
-
};
|
|
517
|
-
Subscriber.prototype._complete = function () {
|
|
518
|
-
try {
|
|
519
|
-
this.destination.complete();
|
|
520
|
-
}
|
|
521
|
-
finally {
|
|
522
|
-
this.unsubscribe();
|
|
523
|
-
}
|
|
524
|
-
};
|
|
525
|
-
return Subscriber;
|
|
526
|
-
}(Subscription));
|
|
527
|
-
var ConsumerObserver = (function () {
|
|
528
|
-
function ConsumerObserver(partialObserver) {
|
|
529
|
-
this.partialObserver = partialObserver;
|
|
530
|
-
}
|
|
531
|
-
ConsumerObserver.prototype.next = function (value) {
|
|
532
|
-
var partialObserver = this.partialObserver;
|
|
533
|
-
if (partialObserver.next) {
|
|
534
|
-
try {
|
|
535
|
-
partialObserver.next(value);
|
|
536
|
-
}
|
|
537
|
-
catch (error) {
|
|
538
|
-
handleUnhandledError(error);
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
ConsumerObserver.prototype.error = function (err) {
|
|
543
|
-
var partialObserver = this.partialObserver;
|
|
544
|
-
if (partialObserver.error) {
|
|
545
|
-
try {
|
|
546
|
-
partialObserver.error(err);
|
|
547
|
-
}
|
|
548
|
-
catch (error) {
|
|
549
|
-
handleUnhandledError(error);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
else {
|
|
553
|
-
handleUnhandledError(err);
|
|
554
|
-
}
|
|
555
|
-
};
|
|
556
|
-
ConsumerObserver.prototype.complete = function () {
|
|
557
|
-
var partialObserver = this.partialObserver;
|
|
558
|
-
if (partialObserver.complete) {
|
|
559
|
-
try {
|
|
560
|
-
partialObserver.complete();
|
|
561
|
-
}
|
|
562
|
-
catch (error) {
|
|
563
|
-
handleUnhandledError(error);
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
};
|
|
567
|
-
return ConsumerObserver;
|
|
568
|
-
}());
|
|
569
|
-
var SafeSubscriber = (function (_super) {
|
|
570
|
-
__extends(SafeSubscriber, _super);
|
|
571
|
-
function SafeSubscriber(observerOrNext, error, complete) {
|
|
572
|
-
var _this = _super.call(this) || this;
|
|
573
|
-
var partialObserver;
|
|
574
|
-
if (isFunction(observerOrNext) || !observerOrNext) {
|
|
575
|
-
partialObserver = {
|
|
576
|
-
next: (observerOrNext !== null && observerOrNext !== undefined ? observerOrNext : undefined),
|
|
577
|
-
error: error !== null && error !== undefined ? error : undefined,
|
|
578
|
-
complete: complete !== null && complete !== undefined ? complete : undefined,
|
|
579
|
-
};
|
|
580
|
-
}
|
|
581
|
-
else {
|
|
582
|
-
{
|
|
583
|
-
partialObserver = observerOrNext;
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
_this.destination = new ConsumerObserver(partialObserver);
|
|
587
|
-
return _this;
|
|
588
|
-
}
|
|
589
|
-
return SafeSubscriber;
|
|
590
|
-
}(Subscriber));
|
|
591
|
-
function handleUnhandledError(error) {
|
|
592
|
-
{
|
|
593
|
-
reportUnhandledError(error);
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
function defaultErrorHandler(err) {
|
|
597
|
-
throw err;
|
|
598
|
-
}
|
|
599
|
-
var EMPTY_OBSERVER = {
|
|
600
|
-
closed: true,
|
|
601
|
-
next: noop,
|
|
602
|
-
error: defaultErrorHandler,
|
|
603
|
-
complete: noop,
|
|
604
|
-
};
|
|
605
|
-
|
|
606
|
-
var observable = (function () { return (typeof Symbol === 'function' && Symbol.observable) || '@@observable'; })();
|
|
607
|
-
|
|
608
|
-
function identity(x) {
|
|
609
|
-
return x;
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
function pipeFromArray(fns) {
|
|
613
|
-
if (fns.length === 0) {
|
|
614
|
-
return identity;
|
|
615
|
-
}
|
|
616
|
-
if (fns.length === 1) {
|
|
617
|
-
return fns[0];
|
|
618
|
-
}
|
|
619
|
-
return function piped(input) {
|
|
620
|
-
return fns.reduce(function (prev, fn) { return fn(prev); }, input);
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
var Observable = (function () {
|
|
625
|
-
function Observable(subscribe) {
|
|
626
|
-
if (subscribe) {
|
|
627
|
-
this._subscribe = subscribe;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
Observable.prototype.lift = function (operator) {
|
|
631
|
-
var observable = new Observable();
|
|
632
|
-
observable.source = this;
|
|
633
|
-
observable.operator = operator;
|
|
634
|
-
return observable;
|
|
635
|
-
};
|
|
636
|
-
Observable.prototype.subscribe = function (observerOrNext, error, complete) {
|
|
637
|
-
var _this = this;
|
|
638
|
-
var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
|
|
639
|
-
errorContext(function () {
|
|
640
|
-
var _a = _this, operator = _a.operator, source = _a.source;
|
|
641
|
-
subscriber.add(operator
|
|
642
|
-
?
|
|
643
|
-
operator.call(subscriber, source)
|
|
644
|
-
: source
|
|
645
|
-
?
|
|
646
|
-
_this._subscribe(subscriber)
|
|
647
|
-
:
|
|
648
|
-
_this._trySubscribe(subscriber));
|
|
649
|
-
});
|
|
650
|
-
return subscriber;
|
|
651
|
-
};
|
|
652
|
-
Observable.prototype._trySubscribe = function (sink) {
|
|
653
|
-
try {
|
|
654
|
-
return this._subscribe(sink);
|
|
655
|
-
}
|
|
656
|
-
catch (err) {
|
|
657
|
-
sink.error(err);
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
Observable.prototype.forEach = function (next, promiseCtor) {
|
|
661
|
-
var _this = this;
|
|
662
|
-
promiseCtor = getPromiseCtor(promiseCtor);
|
|
663
|
-
return new promiseCtor(function (resolve, reject) {
|
|
664
|
-
var subscriber = new SafeSubscriber({
|
|
665
|
-
next: function (value) {
|
|
666
|
-
try {
|
|
667
|
-
next(value);
|
|
668
|
-
}
|
|
669
|
-
catch (err) {
|
|
670
|
-
reject(err);
|
|
671
|
-
subscriber.unsubscribe();
|
|
672
|
-
}
|
|
673
|
-
},
|
|
674
|
-
error: reject,
|
|
675
|
-
complete: resolve,
|
|
676
|
-
});
|
|
677
|
-
_this.subscribe(subscriber);
|
|
678
|
-
});
|
|
679
|
-
};
|
|
680
|
-
Observable.prototype._subscribe = function (subscriber) {
|
|
681
|
-
var _a;
|
|
682
|
-
return (_a = this.source) === null || _a === undefined ? undefined : _a.subscribe(subscriber);
|
|
683
|
-
};
|
|
684
|
-
Observable.prototype[observable] = function () {
|
|
685
|
-
return this;
|
|
686
|
-
};
|
|
687
|
-
Observable.prototype.pipe = function () {
|
|
688
|
-
var operations = [];
|
|
689
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
690
|
-
operations[_i] = arguments[_i];
|
|
691
|
-
}
|
|
692
|
-
return pipeFromArray(operations)(this);
|
|
693
|
-
};
|
|
694
|
-
Observable.prototype.toPromise = function (promiseCtor) {
|
|
695
|
-
var _this = this;
|
|
696
|
-
promiseCtor = getPromiseCtor(promiseCtor);
|
|
697
|
-
return new promiseCtor(function (resolve, reject) {
|
|
698
|
-
var value;
|
|
699
|
-
_this.subscribe(function (x) { return (value = x); }, function (err) { return reject(err); }, function () { return resolve(value); });
|
|
700
|
-
});
|
|
701
|
-
};
|
|
702
|
-
Observable.create = function (subscribe) {
|
|
703
|
-
return new Observable(subscribe);
|
|
704
|
-
};
|
|
705
|
-
return Observable;
|
|
706
|
-
}());
|
|
707
|
-
function getPromiseCtor(promiseCtor) {
|
|
708
|
-
var _a;
|
|
709
|
-
return (_a = promiseCtor !== null && promiseCtor !== undefined ? promiseCtor : config.Promise) !== null && _a !== undefined ? _a : Promise;
|
|
710
|
-
}
|
|
711
|
-
function isObserver(value) {
|
|
712
|
-
return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
|
|
713
|
-
}
|
|
714
|
-
function isSubscriber(value) {
|
|
715
|
-
return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value));
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
function deepCopyJSON(param) {
|
|
719
|
-
return JSON.parse(JSON.stringify(param));
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
let authorization;
|
|
723
|
-
let service;
|
|
724
|
-
const identitySegment = "passport/identity";
|
|
725
|
-
class _Challenge {
|
|
726
|
-
constructor(res, answerResponseMapper = r => r) {
|
|
727
|
-
this.res = res;
|
|
728
|
-
this.answerResponseMapper = answerResponseMapper;
|
|
729
|
-
}
|
|
730
|
-
show() {
|
|
731
|
-
return this.res.challenge;
|
|
732
|
-
}
|
|
733
|
-
answer(answer) {
|
|
734
|
-
return service.post(this.res.answerUrl, { answer }).then(r => this.answerResponseMapper(r));
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
function initialize(options) {
|
|
738
|
-
const { authorization: _authorization, service: _service } = initialize$1(options);
|
|
739
|
-
authorization = _authorization;
|
|
740
|
-
service = _service;
|
|
741
|
-
service.setWriteDefaults({
|
|
742
|
-
headers: {
|
|
743
|
-
"Content-Type": "application/json"
|
|
744
|
-
}
|
|
745
|
-
});
|
|
746
|
-
}
|
|
747
|
-
function verifyToken(token, baseUrl) {
|
|
748
|
-
const _baseUrl = baseUrl ? baseUrl : service ? service.baseUrl : undefined;
|
|
749
|
-
if (!_baseUrl) {
|
|
750
|
-
throw new Error("You should pass the base url of the server or call the initialize method.");
|
|
751
|
-
}
|
|
752
|
-
const req = new Axios({ baseURL: _baseUrl });
|
|
753
|
-
return req.get(`${identitySegment}/verify`, { headers: { Authorization: token } });
|
|
754
|
-
}
|
|
755
|
-
async function login(identifier, password, tokenLifeSpan) {
|
|
756
|
-
checkInitialized(authorization);
|
|
757
|
-
return service
|
|
758
|
-
.post("/passport/identify", {
|
|
759
|
-
identifier,
|
|
760
|
-
password,
|
|
761
|
-
expires: tokenLifeSpan
|
|
762
|
-
})
|
|
763
|
-
.then(r => {
|
|
764
|
-
if (isTokenScheme(r)) {
|
|
765
|
-
return r.token;
|
|
766
|
-
}
|
|
767
|
-
const challenge = new _Challenge(r, r => r.token);
|
|
768
|
-
return challenge;
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
|
-
function isTokenScheme(response) {
|
|
772
|
-
return typeof response.token == "string";
|
|
773
|
-
}
|
|
774
|
-
function isChallenge(tokenOrChallenge) {
|
|
775
|
-
return typeof tokenOrChallenge.show == "function" && typeof tokenOrChallenge.answer == "function";
|
|
776
|
-
}
|
|
777
|
-
async function loginWithStrategy(id) {
|
|
778
|
-
checkInitialized(authorization);
|
|
779
|
-
const { url, state } = await service.get(`/passport/strategy/${id}/url`);
|
|
780
|
-
const token = new Observable(observer => {
|
|
781
|
-
service
|
|
782
|
-
.post("/passport/identify", {
|
|
783
|
-
state
|
|
784
|
-
})
|
|
785
|
-
.then(r => {
|
|
786
|
-
if (isTokenScheme(r)) {
|
|
787
|
-
observer.next(r.token);
|
|
788
|
-
}
|
|
789
|
-
else {
|
|
790
|
-
const challenge = new _Challenge(r, r => r.token);
|
|
791
|
-
observer.next(challenge);
|
|
792
|
-
}
|
|
793
|
-
observer.complete();
|
|
794
|
-
})
|
|
795
|
-
.catch(e => observer.error(e));
|
|
796
|
-
});
|
|
797
|
-
return {
|
|
798
|
-
url,
|
|
799
|
-
token
|
|
800
|
-
};
|
|
801
|
-
}
|
|
802
|
-
var authfactor;
|
|
803
|
-
(function (authfactor) {
|
|
804
|
-
function list() {
|
|
805
|
-
return service.get("passport/identity/factors");
|
|
806
|
-
}
|
|
807
|
-
authfactor.list = list;
|
|
808
|
-
async function register(identityId, factor) {
|
|
809
|
-
const response = await service.post(`passport/identity/${identityId}/start-factor-verification`, factor);
|
|
810
|
-
const challenge = new _Challenge(response, response => response.message);
|
|
811
|
-
return challenge;
|
|
812
|
-
}
|
|
813
|
-
authfactor.register = register;
|
|
814
|
-
function unregister(identityId) {
|
|
815
|
-
return service.delete(`passport/identity/${identityId}/factors`);
|
|
816
|
-
}
|
|
817
|
-
authfactor.unregister = unregister;
|
|
818
|
-
})(authfactor || (authfactor = {}));
|
|
819
|
-
function getStrategies() {
|
|
820
|
-
return service.get("/passport/strategies");
|
|
821
|
-
}
|
|
822
|
-
function get(id) {
|
|
823
|
-
checkInitialized(authorization);
|
|
824
|
-
return service.get(`${identitySegment}/${id}`);
|
|
825
|
-
}
|
|
826
|
-
function getAll(queryParams = {}) {
|
|
827
|
-
checkInitialized(authorization);
|
|
828
|
-
return service.get(identitySegment, {
|
|
829
|
-
params: queryParams
|
|
830
|
-
});
|
|
831
|
-
}
|
|
832
|
-
async function insert(identity) {
|
|
833
|
-
checkInitialized(authorization);
|
|
834
|
-
identity = deepCopyJSON(identity);
|
|
835
|
-
const desiredPolicies = identity.policies;
|
|
836
|
-
delete identity.policies;
|
|
837
|
-
const insertedIdentity = await service.post(identitySegment, identity);
|
|
838
|
-
return policy.attach(insertedIdentity._id, desiredPolicies).then(policies => {
|
|
839
|
-
insertedIdentity.policies = policies;
|
|
840
|
-
return insertedIdentity;
|
|
841
|
-
});
|
|
842
|
-
}
|
|
843
|
-
async function update(id, identity) {
|
|
844
|
-
checkInitialized(authorization);
|
|
845
|
-
const existingIdentity = await service.get(`${identitySegment}/${id}`);
|
|
846
|
-
identity = deepCopyJSON(identity);
|
|
847
|
-
const desiredPolicies = identity.policies;
|
|
848
|
-
delete identity.policies;
|
|
849
|
-
const { onlyInFirst: policiesForDetach, onlyInSecond: policiesForAttach } = getArrayDifferences(existingIdentity.policies, desiredPolicies);
|
|
850
|
-
const updatedIdentity = await service.put(`${identitySegment}/${id}`, identity);
|
|
851
|
-
updatedIdentity.policies = desiredPolicies;
|
|
852
|
-
await policy.attach(id, policiesForAttach);
|
|
853
|
-
await policy.detach(id, policiesForDetach);
|
|
854
|
-
return updatedIdentity;
|
|
855
|
-
}
|
|
856
|
-
function remove(id) {
|
|
857
|
-
checkInitialized(authorization);
|
|
858
|
-
return service.delete(`${identitySegment}/${id}`);
|
|
859
|
-
}
|
|
860
|
-
var policy;
|
|
861
|
-
(function (policy) {
|
|
862
|
-
function attach(identityId, policyIds = []) {
|
|
863
|
-
checkInitialized(authorization);
|
|
864
|
-
const promises = [];
|
|
865
|
-
const attachedPolicies = new Set();
|
|
866
|
-
for (const policyId of policyIds) {
|
|
867
|
-
const promise = service
|
|
868
|
-
.put(`${identitySegment}/${identityId}/policy/${policyId}`, {})
|
|
869
|
-
.then(() => attachedPolicies.add(policyId))
|
|
870
|
-
.catch(e => {
|
|
871
|
-
console.error(`Failed to attach policy with id ${policyId}: `, e);
|
|
872
|
-
return e;
|
|
873
|
-
});
|
|
874
|
-
promises.push(promise);
|
|
875
|
-
}
|
|
876
|
-
return Promise.all(promises).then(() => Array.from(attachedPolicies));
|
|
877
|
-
}
|
|
878
|
-
policy.attach = attach;
|
|
879
|
-
function detach(identityId, policyIds = []) {
|
|
880
|
-
checkInitialized(authorization);
|
|
881
|
-
const promises = [];
|
|
882
|
-
const detachedPolicies = new Set();
|
|
883
|
-
for (const policyId of policyIds) {
|
|
884
|
-
const promise = service
|
|
885
|
-
.delete(`${identitySegment}/${identityId}/policy/${policyId}`)
|
|
886
|
-
.then(() => detachedPolicies.add(policyId))
|
|
887
|
-
.catch(e => {
|
|
888
|
-
console.error(`Failed to detach policy with id ${policyId}: `, e);
|
|
889
|
-
return e;
|
|
890
|
-
});
|
|
891
|
-
promises.push(promise);
|
|
892
|
-
}
|
|
893
|
-
return Promise.all(promises).then(() => Array.from(detachedPolicies));
|
|
894
|
-
}
|
|
895
|
-
policy.detach = detach;
|
|
896
|
-
})(policy || (policy = {}));
|
|
897
|
-
function getArrayDifferences(arr1, arr2) {
|
|
898
|
-
const set1 = new Set(arr1);
|
|
899
|
-
const set2 = new Set(arr2);
|
|
900
|
-
const onlyInFirst = arr1.filter(item => !set2.has(item));
|
|
901
|
-
const onlyInSecond = arr2.filter(item => !set1.has(item));
|
|
902
|
-
return { onlyInFirst, onlyInSecond };
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
export { authfactor, get, getAll, getStrategies, initialize, insert, isChallenge, login, loginWithStrategy, policy, remove, update, verifyToken };
|
|
906
|
-
//# sourceMappingURL=index.mjs.map
|