@dbg-riskit/common 15.0.1 → 16.0.0
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/esm2022/lib/error.types.mjs +19 -0
- package/esm2022/lib/indexeddb/indexed.db.array.subject.mjs +31 -0
- package/esm2022/lib/indexeddb/indexed.db.store.mjs +121 -0
- package/esm2022/lib/indexeddb/indexed.db.subject.mjs +62 -0
- package/esm2022/lib/indexeddb/subject.subscription.mjs +31 -0
- package/esm2022/lib/replay.subject.ext.mjs +23 -0
- package/{fesm2020 → fesm2022}/dbg-riskit-common.mjs +16 -7
- package/{fesm2020 → fesm2022}/dbg-riskit-common.mjs.map +1 -1
- package/lib/common.types.d.ts +8 -8
- package/package.json +5 -11
- package/esm2020/lib/error.types.mjs +0 -19
- package/esm2020/lib/indexeddb/indexed.db.array.subject.mjs +0 -30
- package/esm2020/lib/indexeddb/indexed.db.store.mjs +0 -118
- package/esm2020/lib/indexeddb/indexed.db.subject.mjs +0 -61
- package/esm2020/lib/indexeddb/subject.subscription.mjs +0 -29
- package/esm2020/lib/replay.subject.ext.mjs +0 -21
- package/fesm2015/dbg-riskit-common.mjs +0 -749
- package/fesm2015/dbg-riskit-common.mjs.map +0 -1
- /package/{esm2020 → esm2022}/dbg-riskit-common.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/auth.types.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/base64.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/common.functions.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/common.types.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/date.utils.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/file.types.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/global.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/indexeddb/polyfill.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/indexeddb/request.wrappers.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/logger.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/random.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/rxjs.utils.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/storage.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/string.utils.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/uid.utils.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/user.info.mjs +0 -0
- /package/{esm2020 → esm2022}/public_api.mjs +0 -0
|
@@ -1,749 +0,0 @@
|
|
|
1
|
-
import { filter, map, switchMap, retryWhen, mergeMap, finalize } from 'rxjs/operators';
|
|
2
|
-
import { Observable, of, defer, zip, Subscription, Subject, ObjectUnsubscribedError, ReplaySubject, throwError, timer } from 'rxjs';
|
|
3
|
-
|
|
4
|
-
let globalContainer = {};
|
|
5
|
-
if (typeof global !== 'undefined') {
|
|
6
|
-
globalContainer = global;
|
|
7
|
-
}
|
|
8
|
-
if (typeof window !== 'undefined') {
|
|
9
|
-
globalContainer = window;
|
|
10
|
-
}
|
|
11
|
-
const globalScope = globalContainer;
|
|
12
|
-
|
|
13
|
-
var AuthTokenType;
|
|
14
|
-
(function (AuthTokenType) {
|
|
15
|
-
AuthTokenType[AuthTokenType["NONE"] = 0] = "NONE";
|
|
16
|
-
AuthTokenType[AuthTokenType["API"] = 1] = "API";
|
|
17
|
-
AuthTokenType[AuthTokenType["AUTH"] = 2] = "AUTH";
|
|
18
|
-
})(AuthTokenType || (AuthTokenType = {}));
|
|
19
|
-
|
|
20
|
-
var ObservableEventType;
|
|
21
|
-
(function (ObservableEventType) {
|
|
22
|
-
/**
|
|
23
|
-
* A progress event was received.
|
|
24
|
-
*/
|
|
25
|
-
ObservableEventType[ObservableEventType["Progress"] = 0] = "Progress";
|
|
26
|
-
/**
|
|
27
|
-
* A result event was received.
|
|
28
|
-
*/
|
|
29
|
-
ObservableEventType[ObservableEventType["Result"] = 1] = "Result";
|
|
30
|
-
})(ObservableEventType || (ObservableEventType = {}));
|
|
31
|
-
function isEventObject(unknown) {
|
|
32
|
-
return (typeof unknown === 'object'
|
|
33
|
-
&& unknown != null
|
|
34
|
-
&& 'type' in unknown);
|
|
35
|
-
}
|
|
36
|
-
function extractResult() {
|
|
37
|
-
return (observable) => observable.pipe(filter((event) => event.type === ObservableEventType.Result), map((event) => {
|
|
38
|
-
const resultEvent = event;
|
|
39
|
-
return resultEvent.result;
|
|
40
|
-
}));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
class ErrorType {
|
|
44
|
-
isError() {
|
|
45
|
-
return this === ErrorType.ERROR;
|
|
46
|
-
}
|
|
47
|
-
isNetworkError() {
|
|
48
|
-
return this === ErrorType.NETWORK;
|
|
49
|
-
}
|
|
50
|
-
isRequestError() {
|
|
51
|
-
return this === ErrorType.REQUEST;
|
|
52
|
-
}
|
|
53
|
-
isAuthError() {
|
|
54
|
-
return this === ErrorType.AUTH;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
ErrorType.NETWORK = new ErrorType();
|
|
58
|
-
ErrorType.REQUEST = new ErrorType();
|
|
59
|
-
ErrorType.AUTH = new ErrorType();
|
|
60
|
-
ErrorType.ERROR = new ErrorType();
|
|
61
|
-
|
|
62
|
-
const CONTENT_TYPE = {
|
|
63
|
-
APPLICATION_FORM: 'application/x-www-form-urlencoded',
|
|
64
|
-
APPLICATION_FORM_DATA: 'multipart/form-data',
|
|
65
|
-
APPLICATION_JSON: 'application/json',
|
|
66
|
-
TEXT_CSV: 'text/csv;charset=utf-8;',
|
|
67
|
-
TEXT_JAVASCRIPT: 'text/javascript',
|
|
68
|
-
TEXT_CSS: 'text/css',
|
|
69
|
-
TEXT_PLAIN: 'text/plain'
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
function toString(value) {
|
|
73
|
-
if (value == null) {
|
|
74
|
-
return '';
|
|
75
|
-
}
|
|
76
|
-
switch (typeof value) {
|
|
77
|
-
case 'string':
|
|
78
|
-
return value;
|
|
79
|
-
case 'boolean':
|
|
80
|
-
return value ? 'true' : 'false';
|
|
81
|
-
case 'number':
|
|
82
|
-
return value.toString(10);
|
|
83
|
-
case 'object':
|
|
84
|
-
return value.toString();
|
|
85
|
-
case 'bigint':
|
|
86
|
-
return value.toString();
|
|
87
|
-
case 'function':
|
|
88
|
-
return value.toString();
|
|
89
|
-
default:
|
|
90
|
-
return String(value);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
class DateUtils {
|
|
95
|
-
/**
|
|
96
|
-
* Converts UTC timestamp to Date object.
|
|
97
|
-
*
|
|
98
|
-
* @param utcTimestamp Value in milliseconds since midnight, January 1, 1970 UTC.
|
|
99
|
-
* @return Date object.
|
|
100
|
-
*/
|
|
101
|
-
static utcTimestampToDate(utcTimestamp) {
|
|
102
|
-
const date = new Date(0);
|
|
103
|
-
date.setUTCMilliseconds(utcTimestamp);
|
|
104
|
-
return date;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Converts Date object to UTC timestamp.
|
|
108
|
-
*
|
|
109
|
-
* @param date Date object.
|
|
110
|
-
* @return Value in milliseconds since midnight, January 1, 1970 UTC.
|
|
111
|
-
*/
|
|
112
|
-
static toUTCTimestamp(date) {
|
|
113
|
-
return date.valueOf();
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Converts date represented as number in form yyyyMMdd to Date object.
|
|
117
|
-
*
|
|
118
|
-
* @param businessDate Date represented as number in form yyyyMMdd.
|
|
119
|
-
* @return Date object.
|
|
120
|
-
*/
|
|
121
|
-
static parseBusinessDay(businessDate) {
|
|
122
|
-
const bdate = toString(businessDate);
|
|
123
|
-
const year = parseInt(bdate.substr(0, 4), 10);
|
|
124
|
-
const month = parseInt(bdate.substr(4, 2), 10);
|
|
125
|
-
const day = parseInt(bdate.substr(6, 2), 10);
|
|
126
|
-
return new Date(year, month - 1, day);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Converts Date object to date represented as number in form yyyyMMdd.
|
|
130
|
-
*
|
|
131
|
-
* @param date Date object.
|
|
132
|
-
* @return Date represented as number in form yyyyMMdd.
|
|
133
|
-
*/
|
|
134
|
-
static toBusinessDay(date) {
|
|
135
|
-
return date.getFullYear() * 10000 + (date.getMonth() + 1) * 100 + date.getDate();
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const indexedDB = ('indexedDB' in globalScope && globalScope.indexedDB)
|
|
140
|
-
|| ('mozIndexedDB' in globalScope && globalScope.mozIndexedDB)
|
|
141
|
-
|| ('webkitIndexedDB' in globalScope && globalScope.webkitIndexedDB)
|
|
142
|
-
|| ('msIndexedDB' in globalScope && globalScope.msIndexedDB);
|
|
143
|
-
|
|
144
|
-
function requestToObservable(request, result, tearDown) {
|
|
145
|
-
return new Observable((subscriber) => {
|
|
146
|
-
request.onsuccess = (ev) => {
|
|
147
|
-
subscriber.next(result(ev));
|
|
148
|
-
subscriber.complete();
|
|
149
|
-
};
|
|
150
|
-
request.onerror = () => {
|
|
151
|
-
subscriber.error('IndexedDB request failed.');
|
|
152
|
-
};
|
|
153
|
-
return () => {
|
|
154
|
-
subscriber.complete();
|
|
155
|
-
if (tearDown) {
|
|
156
|
-
if (typeof tearDown.unsubscribe === 'function') {
|
|
157
|
-
tearDown.unsubscribe();
|
|
158
|
-
}
|
|
159
|
-
else if (typeof tearDown === 'function') {
|
|
160
|
-
tearDown();
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
function cursorRequestToStream(request, tx, result, tearDown) {
|
|
167
|
-
return new Observable((subscriber) => {
|
|
168
|
-
let running = true;
|
|
169
|
-
request.onsuccess = (ev) => {
|
|
170
|
-
const cursor = ev.target.result;
|
|
171
|
-
// If the cursor is pointing at something, ask for the data
|
|
172
|
-
if (cursor == null) {
|
|
173
|
-
subscriber.complete();
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
if (running) {
|
|
177
|
-
subscriber.next(result(cursor));
|
|
178
|
-
// Move on to the next object in store
|
|
179
|
-
cursor.continue();
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
subscriber.complete();
|
|
183
|
-
tx.abort();
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
request.onerror = () => {
|
|
188
|
-
subscriber.error('Failed to load data from IndexedDB.');
|
|
189
|
-
};
|
|
190
|
-
tx.oncomplete = () => {
|
|
191
|
-
subscriber.complete();
|
|
192
|
-
};
|
|
193
|
-
return () => {
|
|
194
|
-
running = false;
|
|
195
|
-
if (tearDown) {
|
|
196
|
-
if (typeof tearDown.unsubscribe === 'function') {
|
|
197
|
-
tearDown.unsubscribe();
|
|
198
|
-
}
|
|
199
|
-
else if (typeof tearDown === 'function') {
|
|
200
|
-
tearDown();
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
class IndexedDbStore {
|
|
208
|
-
constructor(dbName, key, version) {
|
|
209
|
-
this.dbName = dbName;
|
|
210
|
-
this.key = key;
|
|
211
|
-
this.version = version;
|
|
212
|
-
this._bakValue = [];
|
|
213
|
-
}
|
|
214
|
-
get indexedDB() {
|
|
215
|
-
const request = indexedDB.open(this.dbName, this.version || 1);
|
|
216
|
-
let db;
|
|
217
|
-
let close = false;
|
|
218
|
-
request.onupgradeneeded = (ev) => {
|
|
219
|
-
db = ev.target.result;
|
|
220
|
-
let params = { autoIncrement: true };
|
|
221
|
-
if (this.key != null) {
|
|
222
|
-
params = { keyPath: toString(this.key) };
|
|
223
|
-
}
|
|
224
|
-
db.createObjectStore(this.dbName, params);
|
|
225
|
-
if (close) {
|
|
226
|
-
db.close();
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
return requestToObservable(request, (ev) => {
|
|
230
|
-
db = ev.target.result;
|
|
231
|
-
if (close) {
|
|
232
|
-
db.close();
|
|
233
|
-
}
|
|
234
|
-
return db;
|
|
235
|
-
}, () => {
|
|
236
|
-
close = true;
|
|
237
|
-
if (db) {
|
|
238
|
-
db.close();
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
add(value) {
|
|
243
|
-
return this.bulkAdd([value]).pipe(map((savedValue) => savedValue ? savedValue[0] : null));
|
|
244
|
-
}
|
|
245
|
-
bulkAdd(value) {
|
|
246
|
-
if (!indexedDB) {
|
|
247
|
-
this._bakValue = this._bakValue.concat(value);
|
|
248
|
-
return of(this._bakValue);
|
|
249
|
-
}
|
|
250
|
-
return this.readWriteStore.pipe(switchMap((store) => {
|
|
251
|
-
return this._saveBulk(store, value);
|
|
252
|
-
}));
|
|
253
|
-
}
|
|
254
|
-
replace(value) {
|
|
255
|
-
return this.bulkReplace([value]).pipe(map((savedValue) => savedValue ? savedValue[0] : null));
|
|
256
|
-
}
|
|
257
|
-
bulkReplace(value) {
|
|
258
|
-
if (!indexedDB) {
|
|
259
|
-
this._bakValue = value;
|
|
260
|
-
return of(this._bakValue);
|
|
261
|
-
}
|
|
262
|
-
return this._clear().pipe(switchMap((store) => {
|
|
263
|
-
return this._saveBulk(store, value);
|
|
264
|
-
}));
|
|
265
|
-
}
|
|
266
|
-
clear() {
|
|
267
|
-
if (!indexedDB) {
|
|
268
|
-
this._bakValue = [];
|
|
269
|
-
return of(void 0);
|
|
270
|
-
}
|
|
271
|
-
return this._clear().pipe(map(() => void 0));
|
|
272
|
-
}
|
|
273
|
-
get readWriteStore() {
|
|
274
|
-
return this.indexedDB.pipe(map((db) => {
|
|
275
|
-
const tx = db.transaction(this.dbName, 'readwrite');
|
|
276
|
-
return tx.objectStore(this.dbName);
|
|
277
|
-
}));
|
|
278
|
-
}
|
|
279
|
-
_clear() {
|
|
280
|
-
return this.readWriteStore.pipe(switchMap((store) => {
|
|
281
|
-
const request = store.clear();
|
|
282
|
-
return requestToObservable(request, () => store);
|
|
283
|
-
}));
|
|
284
|
-
}
|
|
285
|
-
_saveBulk(store, items) {
|
|
286
|
-
return defer(() => {
|
|
287
|
-
const requests = [of(null)];
|
|
288
|
-
if (items != null) {
|
|
289
|
-
items.forEach((item) => {
|
|
290
|
-
requests.push(requestToObservable(store.add(item), () => null));
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
return zip(...requests);
|
|
294
|
-
}).pipe(map(() => {
|
|
295
|
-
return items;
|
|
296
|
-
}));
|
|
297
|
-
}
|
|
298
|
-
get all() {
|
|
299
|
-
if (!indexedDB) {
|
|
300
|
-
return of(this._bakValue);
|
|
301
|
-
}
|
|
302
|
-
return this.indexedDB.pipe(switchMap((db) => new Observable((subscriber) => {
|
|
303
|
-
const tx = db.transaction(this.dbName, 'readonly');
|
|
304
|
-
const store = tx.objectStore(this.dbName);
|
|
305
|
-
const req = store.openCursor();
|
|
306
|
-
const items = [];
|
|
307
|
-
return cursorRequestToStream(req, tx, (cursor) => {
|
|
308
|
-
return cursor.value;
|
|
309
|
-
})
|
|
310
|
-
.subscribe((item) => items.push(item), (err) => {
|
|
311
|
-
subscriber.error(err);
|
|
312
|
-
}, () => {
|
|
313
|
-
subscriber.next(items);
|
|
314
|
-
subscriber.complete();
|
|
315
|
-
});
|
|
316
|
-
})));
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* We need this JSDoc comment for affecting ESDoc.
|
|
322
|
-
*/
|
|
323
|
-
class SubjectSubscription extends Subscription {
|
|
324
|
-
constructor(subject, subscriber) {
|
|
325
|
-
super();
|
|
326
|
-
this.subject = subject;
|
|
327
|
-
this.subscriber = subscriber;
|
|
328
|
-
this.closed = false;
|
|
329
|
-
}
|
|
330
|
-
unsubscribe() {
|
|
331
|
-
if (this.closed || this.subject == null) {
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
this.closed = true;
|
|
335
|
-
const subject = this.subject;
|
|
336
|
-
const observers = subject.observers;
|
|
337
|
-
this.subject = null;
|
|
338
|
-
if (!observers || observers.length === 0 || subject.isStopped || subject.closed) {
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
const subscriberIndex = observers.indexOf(this.subscriber);
|
|
342
|
-
if (subscriberIndex !== -1) {
|
|
343
|
-
observers.splice(subscriberIndex, 1);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
class IndexedDBReplaySubject extends Subject {
|
|
349
|
-
constructor(dbName, key, version) {
|
|
350
|
-
super();
|
|
351
|
-
this.storage = new IndexedDbStore(dbName, key, version);
|
|
352
|
-
}
|
|
353
|
-
get hasData() {
|
|
354
|
-
return this.lastValue.pipe(map((val) => {
|
|
355
|
-
return val != null;
|
|
356
|
-
}));
|
|
357
|
-
}
|
|
358
|
-
get lastValue() {
|
|
359
|
-
return this.storage.all.pipe(map((value) => value ? value[0] : null));
|
|
360
|
-
}
|
|
361
|
-
next(value) {
|
|
362
|
-
this.storage.replace(value).subscribe((storedValue) => {
|
|
363
|
-
if (storedValue != null) {
|
|
364
|
-
this._next(storedValue);
|
|
365
|
-
}
|
|
366
|
-
}, (err) => {
|
|
367
|
-
super.error(err);
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
_next(value) {
|
|
371
|
-
super.next(value);
|
|
372
|
-
}
|
|
373
|
-
_subscribe(subscriber) {
|
|
374
|
-
let subscription;
|
|
375
|
-
switch (true) {
|
|
376
|
-
case this.closed:
|
|
377
|
-
throw new ObjectUnsubscribedError();
|
|
378
|
-
case this.hasError:
|
|
379
|
-
case this.isStopped:
|
|
380
|
-
subscription = Subscription.EMPTY;
|
|
381
|
-
break;
|
|
382
|
-
default:
|
|
383
|
-
this.observers.push(subscriber);
|
|
384
|
-
subscription = new SubjectSubscription(this, subscriber);
|
|
385
|
-
}
|
|
386
|
-
const result = new Subscription();
|
|
387
|
-
result.add(subscription);
|
|
388
|
-
result.add(this.lastValue.subscribe((value) => {
|
|
389
|
-
if (value != null) {
|
|
390
|
-
subscriber.next(value);
|
|
391
|
-
}
|
|
392
|
-
if (this.hasError) {
|
|
393
|
-
subscriber.error(this.thrownError);
|
|
394
|
-
}
|
|
395
|
-
else if (this.isStopped) {
|
|
396
|
-
subscriber.complete();
|
|
397
|
-
}
|
|
398
|
-
}, (err) => {
|
|
399
|
-
subscriber.error(err);
|
|
400
|
-
}));
|
|
401
|
-
return result;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
class IndexedDBArrayReplaySubject extends IndexedDBReplaySubject {
|
|
406
|
-
constructor(partitionSize, dbName, version) {
|
|
407
|
-
super(dbName, null, version);
|
|
408
|
-
this.partitionSize = partitionSize;
|
|
409
|
-
}
|
|
410
|
-
get lastValue() {
|
|
411
|
-
return this.storage.all.pipe(map((items) => {
|
|
412
|
-
if (!items || items.length === 0) {
|
|
413
|
-
return null;
|
|
414
|
-
}
|
|
415
|
-
return items.reduce((result, subItems) => {
|
|
416
|
-
return result.concat(subItems);
|
|
417
|
-
}, []);
|
|
418
|
-
}));
|
|
419
|
-
}
|
|
420
|
-
next(value) {
|
|
421
|
-
const rows = [];
|
|
422
|
-
for (let i = 0; i <= value.length / this.partitionSize; i++) {
|
|
423
|
-
rows[i] = value.slice(i * this.partitionSize, (i + 1) * this.partitionSize);
|
|
424
|
-
}
|
|
425
|
-
this.storage.bulkReplace(rows).subscribe(() => {
|
|
426
|
-
this._next(value);
|
|
427
|
-
}, (err) => {
|
|
428
|
-
super.error(err);
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
class ReplaySubjectExt extends ReplaySubject {
|
|
434
|
-
constructor(bufferSize, windowTime, scheduler) {
|
|
435
|
-
super(bufferSize, windowTime, scheduler);
|
|
436
|
-
this._hasData = false;
|
|
437
|
-
this.oldNext = this.next;
|
|
438
|
-
this.next = this.nextAndStoreValue;
|
|
439
|
-
}
|
|
440
|
-
nextAndStoreValue(value) {
|
|
441
|
-
this._lastValue = value;
|
|
442
|
-
this._hasData = true;
|
|
443
|
-
this.oldNext(value);
|
|
444
|
-
}
|
|
445
|
-
get hasData() {
|
|
446
|
-
return this._hasData;
|
|
447
|
-
}
|
|
448
|
-
get lastValue() {
|
|
449
|
-
return this._lastValue;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
function retry(logger, maxRetryAttempts = 5, scalingDuration = 1000) {
|
|
454
|
-
return retryWhen(((errors) => errors.pipe(mergeMap((error, i) => {
|
|
455
|
-
const retryAttempt = i + 1;
|
|
456
|
-
// if maximum number of retries have been met
|
|
457
|
-
// or response is a status code we don't wish to retry, throw error
|
|
458
|
-
if (retryAttempt >= maxRetryAttempts) {
|
|
459
|
-
return throwError(error);
|
|
460
|
-
}
|
|
461
|
-
logger.info(`Attempt ${retryAttempt}: retrying in ${retryAttempt * scalingDuration}ms`);
|
|
462
|
-
// retry after 1s, 2s, etc...
|
|
463
|
-
return timer(retryAttempt * scalingDuration);
|
|
464
|
-
}), finalize(() => logger.info('We are done!')))));
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
const KEY_PREFIX = 'auto-ws';
|
|
468
|
-
function LocalStorage(key, keyPrefix = KEY_PREFIX) {
|
|
469
|
-
return _WebStorage(localStorage, key, keyPrefix);
|
|
470
|
-
}
|
|
471
|
-
function SessionStorage(key, keyPrefix = KEY_PREFIX) {
|
|
472
|
-
return _WebStorage(sessionStorage, key, keyPrefix);
|
|
473
|
-
}
|
|
474
|
-
const _WebStorage = (webStorage, key, keyPrefix) => {
|
|
475
|
-
return (target, propertyName) => {
|
|
476
|
-
const storageKey = key || propertyName;
|
|
477
|
-
const objectKey = Symbol(`__${WebStorageUtility.generateStorageKey(storageKey, keyPrefix)}`);
|
|
478
|
-
Object.defineProperty(target, propertyName, {
|
|
479
|
-
configurable: true,
|
|
480
|
-
get() {
|
|
481
|
-
if (this[objectKey]) {
|
|
482
|
-
return this[objectKey];
|
|
483
|
-
}
|
|
484
|
-
this[objectKey] = WebStorageUtility.get(webStorage, storageKey, keyPrefix);
|
|
485
|
-
return this[objectKey];
|
|
486
|
-
},
|
|
487
|
-
set(newValue) {
|
|
488
|
-
this[objectKey] = newValue;
|
|
489
|
-
if (newValue == null) {
|
|
490
|
-
WebStorageUtility.remove(webStorage, storageKey, keyPrefix);
|
|
491
|
-
}
|
|
492
|
-
else {
|
|
493
|
-
WebStorageUtility.set(webStorage, storageKey, keyPrefix, newValue);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
});
|
|
497
|
-
};
|
|
498
|
-
};
|
|
499
|
-
class WebStorageUtility {
|
|
500
|
-
static generateStorageKey(key, keyPrefix) {
|
|
501
|
-
return `${keyPrefix}_${key}`;
|
|
502
|
-
}
|
|
503
|
-
static get(storage, key, keyPrefix) {
|
|
504
|
-
const storageKey = WebStorageUtility.generateStorageKey(key, keyPrefix);
|
|
505
|
-
try {
|
|
506
|
-
const value = storage.getItem(storageKey);
|
|
507
|
-
return WebStorageUtility.getGettable(value);
|
|
508
|
-
}
|
|
509
|
-
catch (e) {
|
|
510
|
-
this.clear(storage, storageKey);
|
|
511
|
-
return null;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
static set(storage, key, keyPrefix, value) {
|
|
515
|
-
const storageKey = WebStorageUtility.generateStorageKey(key, keyPrefix);
|
|
516
|
-
try {
|
|
517
|
-
storage.setItem(storageKey, WebStorageUtility.getSettable(value));
|
|
518
|
-
}
|
|
519
|
-
catch (e) {
|
|
520
|
-
this.clear(storage, storageKey);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
static clear(storage, storageKey) {
|
|
524
|
-
try {
|
|
525
|
-
storage.removeItem(storageKey);
|
|
526
|
-
}
|
|
527
|
-
catch (e) {
|
|
528
|
-
// Just catch and ignore
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
static remove(storage, key, keyPrefix) {
|
|
532
|
-
const storageKey = WebStorageUtility.generateStorageKey(key, keyPrefix);
|
|
533
|
-
this.clear(storage, storageKey);
|
|
534
|
-
}
|
|
535
|
-
static getSettable(value) {
|
|
536
|
-
return typeof value === 'string' ? value : JSON.stringify(value);
|
|
537
|
-
}
|
|
538
|
-
static getGettable(value) {
|
|
539
|
-
if (value == null) {
|
|
540
|
-
return null;
|
|
541
|
-
}
|
|
542
|
-
try {
|
|
543
|
-
return JSON.parse(value);
|
|
544
|
-
}
|
|
545
|
-
catch (e) {
|
|
546
|
-
return value;
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
const crypto = ('crypto' in globalScope && globalScope.crypto)
|
|
552
|
-
|| ('msCrypto' in globalScope && globalScope.msCrypto)
|
|
553
|
-
|| null;
|
|
554
|
-
function secureRandom() {
|
|
555
|
-
if (crypto && typeof crypto.getRandomValues === 'function') {
|
|
556
|
-
const array = new Uint16Array(1);
|
|
557
|
-
crypto.getRandomValues(array);
|
|
558
|
-
return array[0] / 65535; // Max Uint16 is 65535
|
|
559
|
-
}
|
|
560
|
-
return Math.random();
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
class UIDUtils {
|
|
564
|
-
static computeUID(...data) {
|
|
565
|
-
if (data && data.length) {
|
|
566
|
-
return data.map((value) => {
|
|
567
|
-
if (value == null) {
|
|
568
|
-
return '';
|
|
569
|
-
}
|
|
570
|
-
return toString(value).replace('\.', '');
|
|
571
|
-
}).join('-');
|
|
572
|
-
}
|
|
573
|
-
return UIDUtils.generateUID();
|
|
574
|
-
}
|
|
575
|
-
static generateUID() {
|
|
576
|
-
const s4 = () => {
|
|
577
|
-
return Math.floor((1 + secureRandom()) * 0x10000)
|
|
578
|
-
.toString(16)
|
|
579
|
-
.substring(1);
|
|
580
|
-
};
|
|
581
|
-
return `${s4() + s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
const BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
586
|
-
const atobAvailable = 'atob' in globalScope && typeof globalScope.atob === 'function';
|
|
587
|
-
const btoaAvailable = 'btoa' in globalScope && typeof globalScope.btoa === 'function';
|
|
588
|
-
// credits for decoder goes to https://github.com/atk
|
|
589
|
-
function base64decode(str) {
|
|
590
|
-
let source = str
|
|
591
|
-
.replace(/-/g, '+')
|
|
592
|
-
.replace(/_/g, '/');
|
|
593
|
-
// Add padding if missing
|
|
594
|
-
switch (source.length % 4) {
|
|
595
|
-
case 0:
|
|
596
|
-
break;
|
|
597
|
-
case 2:
|
|
598
|
-
source += '==';
|
|
599
|
-
break;
|
|
600
|
-
case 3:
|
|
601
|
-
source += '=';
|
|
602
|
-
break;
|
|
603
|
-
default:
|
|
604
|
-
throw new Error('Illegal base64 string!');
|
|
605
|
-
}
|
|
606
|
-
let output = '';
|
|
607
|
-
if (atobAvailable) {
|
|
608
|
-
output = atob(str);
|
|
609
|
-
}
|
|
610
|
-
else {
|
|
611
|
-
source = source.replace(/=+$/, '');
|
|
612
|
-
if (source.length % 4 === 1) {
|
|
613
|
-
throw new Error('\'atob\' failed: The string to be decoded is not correctly encoded.');
|
|
614
|
-
}
|
|
615
|
-
/* eslint-disable no-bitwise, no-cond-assign */
|
|
616
|
-
for (
|
|
617
|
-
// initialize result and counters
|
|
618
|
-
let bc = 0, bs = 0, buffer, idx = 0;
|
|
619
|
-
// get next character
|
|
620
|
-
buffer = source.charAt(idx++);
|
|
621
|
-
// character found in table? initialize bit storage and add its ascii value;
|
|
622
|
-
~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,
|
|
623
|
-
// and if not first of each 4 characters,
|
|
624
|
-
// convert the first 8 bits to one ascii character
|
|
625
|
-
bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0) {
|
|
626
|
-
// try to find character in table (0-63, not found => -1)
|
|
627
|
-
buffer = BASE64_CHARS.indexOf(buffer);
|
|
628
|
-
}
|
|
629
|
-
/* eslint-enable */
|
|
630
|
-
}
|
|
631
|
-
// https://developer.mozilla.org/en/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem
|
|
632
|
-
return decodeURIComponent(Array.prototype.map.call(output, (c) => {
|
|
633
|
-
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
634
|
-
}).join(''));
|
|
635
|
-
}
|
|
636
|
-
function base64encode(buffer) {
|
|
637
|
-
let arrayBuffer;
|
|
638
|
-
if (typeof buffer === 'string') {
|
|
639
|
-
if (btoaAvailable) {
|
|
640
|
-
return btoa(buffer);
|
|
641
|
-
}
|
|
642
|
-
arrayBuffer = string2buffer(buffer);
|
|
643
|
-
}
|
|
644
|
-
else {
|
|
645
|
-
arrayBuffer = buffer;
|
|
646
|
-
}
|
|
647
|
-
let base64 = '';
|
|
648
|
-
const bytes = new Uint8Array(arrayBuffer);
|
|
649
|
-
const byteLength = bytes.byteLength;
|
|
650
|
-
const byteRemainder = byteLength % 3;
|
|
651
|
-
const mainLength = byteLength - byteRemainder;
|
|
652
|
-
let a;
|
|
653
|
-
let b;
|
|
654
|
-
let c;
|
|
655
|
-
let d;
|
|
656
|
-
let chunk;
|
|
657
|
-
/* eslint-disable no-bitwise */
|
|
658
|
-
// Main loop deals with bytes in chunks of 3
|
|
659
|
-
for (let i = 0; i < mainLength; i = i + 3) {
|
|
660
|
-
// Combine the three bytes into a single integer
|
|
661
|
-
chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];
|
|
662
|
-
// Use bitmasks to extract 6-bit segments from the triplet
|
|
663
|
-
a = (chunk & 16515072) >> 18; // 16515072 = (2^6 - 1) << 18
|
|
664
|
-
b = (chunk & 258048) >> 12; // 258048 = (2^6 - 1) << 12
|
|
665
|
-
c = (chunk & 4032) >> 6; // 4032 = (2^6 - 1) << 6
|
|
666
|
-
d = chunk & 63; // 63 = 2^6 - 1
|
|
667
|
-
// Convert the raw binary segments to the appropriate ASCII encoding
|
|
668
|
-
base64 += BASE64_CHARS[a] + BASE64_CHARS[b] + BASE64_CHARS[c] + BASE64_CHARS[d];
|
|
669
|
-
}
|
|
670
|
-
// Deal with the remaining bytes and padding
|
|
671
|
-
if (byteRemainder === 1) {
|
|
672
|
-
chunk = bytes[mainLength];
|
|
673
|
-
a = (chunk & 252) >> 2; // 252 = (2^6 - 1) << 2
|
|
674
|
-
// Set the 4 least significant bits to zero
|
|
675
|
-
b = (chunk & 3) << 4; // 3 = 2^2 - 1
|
|
676
|
-
base64 += `${BASE64_CHARS[a] + BASE64_CHARS[b]}==`;
|
|
677
|
-
}
|
|
678
|
-
else if (byteRemainder === 2) {
|
|
679
|
-
chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1];
|
|
680
|
-
a = (chunk & 64512) >> 10; // 64512 = (2^6 - 1) << 10
|
|
681
|
-
b = (chunk & 1008) >> 4; // 1008 = (2^6 - 1) << 4
|
|
682
|
-
// Set the 2 least significant bits to zero
|
|
683
|
-
c = (chunk & 15) << 2; // 15 = 2^4 - 1
|
|
684
|
-
base64 += `${BASE64_CHARS[a] + BASE64_CHARS[b] + BASE64_CHARS[c]}=`;
|
|
685
|
-
}
|
|
686
|
-
/* eslint-enable */
|
|
687
|
-
return base64;
|
|
688
|
-
}
|
|
689
|
-
function string2buffer(source) {
|
|
690
|
-
const encoder = 'TextEncoder' in globalScope ? new TextEncoder() : {
|
|
691
|
-
encode(str) {
|
|
692
|
-
return Uint8Array.from(Array.prototype.slice.apply(str), (char) => char.codePointAt(0) || 0);
|
|
693
|
-
}
|
|
694
|
-
};
|
|
695
|
-
return encoder.encode(source);
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
class Logger {
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
function deepClone(obj) {
|
|
702
|
-
return obj && JSON.parse(JSON.stringify(obj));
|
|
703
|
-
}
|
|
704
|
-
function isObject(obj) {
|
|
705
|
-
return typeof obj === 'object' && obj != null;
|
|
706
|
-
}
|
|
707
|
-
/* eslint-enable */
|
|
708
|
-
function deepEqual(x, y, ignoreArrayOrderOrPaths = [], ignoreArrayOrder = false) {
|
|
709
|
-
let ignorePaths = [];
|
|
710
|
-
if (typeof ignoreArrayOrderOrPaths === 'boolean') {
|
|
711
|
-
ignoreArrayOrder = ignoreArrayOrderOrPaths;
|
|
712
|
-
}
|
|
713
|
-
else if (Array.isArray(ignoreArrayOrderOrPaths)) {
|
|
714
|
-
ignorePaths = ignoreArrayOrderOrPaths;
|
|
715
|
-
}
|
|
716
|
-
return deepEqualImpl(x, y, '', ignorePaths, ignoreArrayOrder);
|
|
717
|
-
}
|
|
718
|
-
function deepEqualImpl(x, y, parentPath, ignorePaths, ignoreArrayOrder) {
|
|
719
|
-
if (x === y) {
|
|
720
|
-
return true;
|
|
721
|
-
}
|
|
722
|
-
if (Array.isArray(x) && Array.isArray(y) && ignoreArrayOrder) {
|
|
723
|
-
x = x.slice().sort();
|
|
724
|
-
y = y.slice().sort();
|
|
725
|
-
}
|
|
726
|
-
if (isObject(x) && isObject(y)) {
|
|
727
|
-
const xObj = x;
|
|
728
|
-
const yObj = y;
|
|
729
|
-
const xKeys = Object.keys(xObj).filter((key) => ignorePaths.indexOf(`${parentPath}.${key}`) === -1);
|
|
730
|
-
const yKeys = Object.keys(yObj).filter((key) => ignorePaths.indexOf(`${parentPath}.${key}`) === -1);
|
|
731
|
-
if (xKeys.length !== yKeys.length) {
|
|
732
|
-
return false;
|
|
733
|
-
}
|
|
734
|
-
return xKeys.every((key) => {
|
|
735
|
-
if (!(key in yObj)) {
|
|
736
|
-
return false;
|
|
737
|
-
}
|
|
738
|
-
return deepEqualImpl(xObj[key], yObj[key], `${parentPath}.${key}`, ignorePaths, ignoreArrayOrder);
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
return false;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
/**
|
|
745
|
-
* Generated bundle index. Do not edit.
|
|
746
|
-
*/
|
|
747
|
-
|
|
748
|
-
export { AuthTokenType, CONTENT_TYPE, DateUtils, ErrorType, IndexedDBArrayReplaySubject, IndexedDBReplaySubject, IndexedDbStore, LocalStorage, Logger, ObservableEventType, ReplaySubjectExt, SessionStorage, UIDUtils, base64decode, base64encode, deepClone, deepEqual, extractResult, globalScope, isEventObject, retry, secureRandom, string2buffer, toString };
|
|
749
|
-
//# sourceMappingURL=dbg-riskit-common.mjs.map
|