@rdlabo/ionic-angular-kit 21.4.7 → 21.4.9
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/fesm2022/rdlabo-ionic-angular-kit-offline.mjs +30 -5
- package/fesm2022/rdlabo-ionic-angular-kit-offline.mjs.map +1 -1
- package/fesm2022/rdlabo-ionic-angular-kit.mjs +106 -15
- package/fesm2022/rdlabo-ionic-angular-kit.mjs.map +1 -1
- package/package.json +1 -1
- package/types/rdlabo-ionic-angular-kit-offline.d.ts +4 -0
- package/types/rdlabo-ionic-angular-kit.d.ts +7 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { inject, Injectable, InjectionToken, makeEnvironmentProviders, ElementRef, Injector, input, computed, HostListener, Directive, ErrorHandler, provideAppInitializer, Optional, afterNextRender } from '@angular/core';
|
|
2
|
+
import { inject, Injectable, InjectionToken, makeEnvironmentProviders, ElementRef, Injector, input, computed, HostListener, Directive, ErrorHandler, DestroyRef, provideAppInitializer, Optional, afterNextRender } from '@angular/core';
|
|
3
3
|
import { Storage } from '@ionic/storage-angular';
|
|
4
4
|
import { ModalController, PopoverController, ToastController, AlertController, LoadingController, NavController } from '@ionic/angular/standalone';
|
|
5
5
|
import { Capacitor } from '@capacitor/core';
|
|
6
6
|
import { Keyboard } from '@capacitor/keyboard';
|
|
7
7
|
import { ImpactStyle, Haptics } from '@capacitor/haptics';
|
|
8
8
|
import { FORM_FIELD } from '@angular/forms/signals';
|
|
9
|
-
import { BehaviorSubject, throwError, of, from, retry, timer, Subject, Observable, startWith } from 'rxjs';
|
|
9
|
+
import { BehaviorSubject, Subscription, throwError, of, from, retry, timer, Subject, Observable, startWith } from 'rxjs';
|
|
10
10
|
import { Router } from '@angular/router';
|
|
11
11
|
import { catchError, map, mergeMap, timeout, tap } from 'rxjs/operators';
|
|
12
12
|
import { HttpContextToken, HttpErrorResponse, HttpResponse } from '@angular/common/http';
|
|
@@ -1286,71 +1286,162 @@ class KitAuthRecoveryService {
|
|
|
1286
1286
|
#access = inject(KitAuthAccessService);
|
|
1287
1287
|
#config = inject(KIT_AUTH_RECOVERY_CONFIG);
|
|
1288
1288
|
#errorHandler = inject(ErrorHandler);
|
|
1289
|
+
#destroyRef = inject(DestroyRef);
|
|
1289
1290
|
#subscription = null;
|
|
1290
1291
|
#recovery = null;
|
|
1292
|
+
#recoveryRevision = null;
|
|
1293
|
+
#retryTimer = null;
|
|
1294
|
+
#available = false;
|
|
1295
|
+
#retryRequested = false;
|
|
1296
|
+
#destroyed = false;
|
|
1297
|
+
constructor() {
|
|
1298
|
+
this.#destroyRef.onDestroy(() => {
|
|
1299
|
+
this.#destroyed = true;
|
|
1300
|
+
this.#clearRetry();
|
|
1301
|
+
this.#subscription?.unsubscribe();
|
|
1302
|
+
this.#subscription = null;
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
1291
1305
|
/** Subscribe to the configured remote-availability stream once. */
|
|
1292
1306
|
initialize() {
|
|
1307
|
+
if (this.#destroyed)
|
|
1308
|
+
return;
|
|
1293
1309
|
const recovery = this.#config.remoteRecovery;
|
|
1294
1310
|
if (!recovery || this.#subscription)
|
|
1295
1311
|
return;
|
|
1296
|
-
this.#subscription =
|
|
1312
|
+
this.#subscription = new Subscription();
|
|
1313
|
+
this.#subscription.add(recovery.availability().subscribe({
|
|
1297
1314
|
next: (available) => {
|
|
1298
|
-
|
|
1315
|
+
this.#available = available;
|
|
1316
|
+
if (available && this.#access.mode === 'local') {
|
|
1317
|
+
this.#clearRetry();
|
|
1299
1318
|
void this.recover();
|
|
1319
|
+
}
|
|
1320
|
+
else if (this.#access.mode === 'local') {
|
|
1321
|
+
this.#scheduleRetry();
|
|
1322
|
+
}
|
|
1300
1323
|
},
|
|
1301
1324
|
error: (error) => this.#errorHandler.handleError(error),
|
|
1302
|
-
});
|
|
1325
|
+
}));
|
|
1326
|
+
this.#subscription.add(this.#access.mode$.subscribe((mode) => {
|
|
1327
|
+
if (mode !== 'local') {
|
|
1328
|
+
this.#clearRetry();
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1331
|
+
if (this.#available) {
|
|
1332
|
+
void this.recover();
|
|
1333
|
+
}
|
|
1334
|
+
else {
|
|
1335
|
+
this.#scheduleRetry();
|
|
1336
|
+
}
|
|
1337
|
+
}));
|
|
1303
1338
|
}
|
|
1304
1339
|
/** Run one ordered remote recovery attempt, coalescing concurrent triggers. */
|
|
1305
1340
|
recover() {
|
|
1306
|
-
if (this.#
|
|
1341
|
+
if (this.#destroyed)
|
|
1342
|
+
return Promise.resolve();
|
|
1343
|
+
if (this.#recovery) {
|
|
1344
|
+
if (this.#access.mode === 'local' &&
|
|
1345
|
+
this.#recoveryRevision !== null &&
|
|
1346
|
+
this.#access.revision > this.#recoveryRevision) {
|
|
1347
|
+
this.#retryRequested = true;
|
|
1348
|
+
}
|
|
1307
1349
|
return this.#recovery;
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1350
|
+
}
|
|
1351
|
+
const running = this.#runRecovery();
|
|
1352
|
+
this.#recoveryRevision = this.#access.revision;
|
|
1353
|
+
const promise = running.finally(() => {
|
|
1354
|
+
if (this.#recovery !== promise)
|
|
1355
|
+
return;
|
|
1356
|
+
this.#recovery = null;
|
|
1357
|
+
this.#recoveryRevision = null;
|
|
1358
|
+
if (this.#destroyed)
|
|
1359
|
+
return;
|
|
1360
|
+
if (!this.#retryRequested)
|
|
1361
|
+
return;
|
|
1362
|
+
this.#retryRequested = false;
|
|
1363
|
+
if (this.#access.mode !== 'local')
|
|
1364
|
+
return;
|
|
1365
|
+
if (this.#available) {
|
|
1366
|
+
void this.recover();
|
|
1367
|
+
}
|
|
1368
|
+
else {
|
|
1369
|
+
this.#scheduleRetry();
|
|
1370
|
+
}
|
|
1311
1371
|
});
|
|
1312
1372
|
this.#recovery = promise;
|
|
1313
1373
|
return promise;
|
|
1314
1374
|
}
|
|
1315
1375
|
async #runRecovery() {
|
|
1316
1376
|
const recovery = this.#config.remoteRecovery;
|
|
1317
|
-
if (!recovery || this.#access.mode !== 'local')
|
|
1377
|
+
if (this.#destroyed || !recovery || this.#access.mode !== 'local')
|
|
1318
1378
|
return;
|
|
1319
1379
|
const lease = this.#access.beginTransition();
|
|
1320
1380
|
let expectedRevision = this.#access.revision;
|
|
1321
1381
|
const isCurrent = () => this.#access.revision === expectedRevision;
|
|
1322
1382
|
try {
|
|
1323
1383
|
const result = await recovery.reauthenticate(lease);
|
|
1324
|
-
if (!isCurrent() || this.#access.mode !== 'local')
|
|
1384
|
+
if (this.#destroyed || !isCurrent() || this.#access.mode !== 'local')
|
|
1325
1385
|
return;
|
|
1326
1386
|
if (result === false) {
|
|
1387
|
+
this.#clearRetry();
|
|
1327
1388
|
this.#access.clear();
|
|
1328
1389
|
return;
|
|
1329
1390
|
}
|
|
1330
|
-
if (!(await result.activate(lease)) ||
|
|
1391
|
+
if (!(await result.activate(lease)) ||
|
|
1392
|
+
this.#destroyed ||
|
|
1393
|
+
!isCurrent() ||
|
|
1394
|
+
this.#access.mode !== 'local') {
|
|
1331
1395
|
return;
|
|
1396
|
+
}
|
|
1397
|
+
this.#clearRetry();
|
|
1332
1398
|
this.#access.grantRemote();
|
|
1333
1399
|
expectedRevision = this.#access.revision;
|
|
1334
1400
|
await result.resume();
|
|
1335
1401
|
}
|
|
1336
1402
|
catch (error) {
|
|
1337
|
-
if (!isCurrent())
|
|
1403
|
+
if (this.#destroyed || !isCurrent())
|
|
1338
1404
|
return;
|
|
1339
1405
|
if (isExplicitAuthDenial(error)) {
|
|
1406
|
+
this.#clearRetry();
|
|
1340
1407
|
this.#access.clear();
|
|
1341
1408
|
}
|
|
1342
|
-
else if (
|
|
1409
|
+
else if (this.#config.isUnavailableError?.(error)) {
|
|
1410
|
+
this.#scheduleRetry();
|
|
1411
|
+
}
|
|
1412
|
+
else {
|
|
1343
1413
|
this.#errorHandler.handleError(error);
|
|
1344
1414
|
}
|
|
1345
1415
|
}
|
|
1346
1416
|
}
|
|
1417
|
+
#scheduleRetry() {
|
|
1418
|
+
const recovery = this.#config.remoteRecovery;
|
|
1419
|
+
if (this.#destroyed || !recovery || this.#retryTimer || this.#access.mode !== 'local')
|
|
1420
|
+
return;
|
|
1421
|
+
this.#retryTimer = setTimeout(() => {
|
|
1422
|
+
this.#retryTimer = null;
|
|
1423
|
+
if (this.#access.mode === 'local')
|
|
1424
|
+
void this.recover();
|
|
1425
|
+
}, this.#retryDelayMs(recovery.retryDelayMs));
|
|
1426
|
+
}
|
|
1427
|
+
#clearRetry() {
|
|
1428
|
+
if (!this.#retryTimer)
|
|
1429
|
+
return;
|
|
1430
|
+
clearTimeout(this.#retryTimer);
|
|
1431
|
+
this.#retryTimer = null;
|
|
1432
|
+
}
|
|
1433
|
+
#retryDelayMs(configured) {
|
|
1434
|
+
if (configured === undefined || !Number.isFinite(configured))
|
|
1435
|
+
return 30_000;
|
|
1436
|
+
return Math.max(1_000, configured);
|
|
1437
|
+
}
|
|
1347
1438
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: KitAuthRecoveryService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1348
1439
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: KitAuthRecoveryService, providedIn: 'root' }); }
|
|
1349
1440
|
}
|
|
1350
1441
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: KitAuthRecoveryService, decorators: [{
|
|
1351
1442
|
type: Injectable,
|
|
1352
1443
|
args: [{ providedIn: 'root' }]
|
|
1353
|
-
}] });
|
|
1444
|
+
}], ctorParameters: () => [] });
|
|
1354
1445
|
/** Returns true for authoritative authentication denials that must never use local fallback. */
|
|
1355
1446
|
function isExplicitAuthDenial(error) {
|
|
1356
1447
|
if (typeof error !== 'object' || error === null)
|