@rdlabo/ionic-angular-kit 21.4.6 → 21.4.8
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/README.md +16 -6
- package/fesm2022/rdlabo-ionic-angular-kit-offline.mjs +23 -3
- package/fesm2022/rdlabo-ionic-angular-kit-offline.mjs.map +1 -1
- package/fesm2022/rdlabo-ionic-angular-kit.mjs +126 -21
- 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 +20 -2
|
@@ -1,15 +1,15 @@
|
|
|
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
|
-
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
|
|
12
|
+
import { HttpContextToken, HttpErrorResponse, HttpResponse } from '@angular/common/http';
|
|
13
13
|
import { Network } from '@capacitor/network';
|
|
14
14
|
import { App } from '@capacitor/app';
|
|
15
15
|
|
|
@@ -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)
|
|
@@ -1628,6 +1719,17 @@ function isRemoteAccessActivation(value) {
|
|
|
1628
1719
|
typeof value.resume === 'function');
|
|
1629
1720
|
}
|
|
1630
1721
|
|
|
1722
|
+
/**
|
|
1723
|
+
* Marks the narrowly scoped credential-exchange request that establishes remote access.
|
|
1724
|
+
*
|
|
1725
|
+
* @remarks
|
|
1726
|
+
* When shared auth access enforcement is enabled, the application starts in `none` (or may be
|
|
1727
|
+
* recovering from `local`) and therefore cannot make ordinary authenticated requests. The one
|
|
1728
|
+
* server request that verifies the current provider credential must set this context token. It
|
|
1729
|
+
* still runs the complete header, retry, denial, and error pipeline; only the pre-existing
|
|
1730
|
+
* `remote` access requirement is deferred until that exchange succeeds.
|
|
1731
|
+
*/
|
|
1732
|
+
const KIT_AUTH_BOOTSTRAP_REQUEST = new HttpContextToken(() => false);
|
|
1631
1733
|
/**
|
|
1632
1734
|
* HTTP methods that are safe to retry automatically.
|
|
1633
1735
|
*
|
|
@@ -1799,10 +1901,11 @@ const dispatchError = (config, req, error) => {
|
|
|
1799
1901
|
const kitAuthInterceptor = (request, next) => {
|
|
1800
1902
|
const config = inject(KIT_HTTP_CONFIG);
|
|
1801
1903
|
const access = inject(KitAuthAccessService);
|
|
1904
|
+
const isAuthBootstrap = request.context.get(KIT_AUTH_BOOTSTRAP_REQUEST);
|
|
1802
1905
|
if (config.bypass?.(request)) {
|
|
1803
1906
|
return next(request);
|
|
1804
1907
|
}
|
|
1805
|
-
if (config.enforceAuthAccessMode && access.mode !== 'remote') {
|
|
1908
|
+
if (config.enforceAuthAccessMode && access.mode !== 'remote' && !isAuthBootstrap) {
|
|
1806
1909
|
const error = new HttpErrorResponse({
|
|
1807
1910
|
// `local` deliberately looks like a transport failure so an outer offline read interceptor
|
|
1808
1911
|
// may resolve it. `none` must not use status 0, otherwise that interceptor could expose a
|
|
@@ -1864,9 +1967,11 @@ const kitAuthInterceptor = (request, next) => {
|
|
|
1864
1967
|
dispatchError(config, req, error);
|
|
1865
1968
|
return throwError(() => error);
|
|
1866
1969
|
}
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1970
|
+
if (!isAuthBootstrap) {
|
|
1971
|
+
const fallback = config.offlineFallback?.(req, error);
|
|
1972
|
+
if (fallback) {
|
|
1973
|
+
return fallback;
|
|
1974
|
+
}
|
|
1870
1975
|
}
|
|
1871
1976
|
dispatchError(config, req, error);
|
|
1872
1977
|
return throwError(() => error);
|
|
@@ -2595,5 +2700,5 @@ function mountViewModel(host, onMount) {
|
|
|
2595
2700
|
* Generated bundle index. Do not edit.
|
|
2596
2701
|
*/
|
|
2597
2702
|
|
|
2598
|
-
export { KIT_AUTH_CONFIG, KIT_AUTH_RECOVERY_CONFIG, KIT_HTTP_CONFIG, KIT_LAST_AUTH_EMAIL_KEY, KIT_OVERLAY_CONFIG, KIT_REALTIME_CLIENT_ID, KIT_THEME_STORAGE_KEY, KitAuthAccessService, KitAuthInputDirective, KitAuthRecoveryService, KitLoadingController, KitMaintenanceController, KitOverlayController, KitRealtimeConnection, KitRealtimeLivenessWatchdog, KitReloadAlertController, KitStorageService, arrayConcatById, disableHandler, isExplicitAuthDenial, isMaintenanceError, kitAuthInterceptor, kitChangeEventDisabled, kitClearStoragePreservingKeys, kitCreateDidEnter, kitForgetEmail, kitImpact, kitIsValidEmail, kitKeyboardInit, kitPresentAuthFailedAlert, kitPresentLanguageActionSheet, kitRealtimeProtocols, kitRecallEmail, kitRememberEmail, kitRequireAuthorizedGuard, kitRequireConfirmingGuard, kitRequiredUnauthorizedGuard, mountViewModel, objectEqual, provideKitAuth, provideKitHttp, provideKitOverlay, toKitWebSocketUrl };
|
|
2703
|
+
export { KIT_AUTH_BOOTSTRAP_REQUEST, KIT_AUTH_CONFIG, KIT_AUTH_RECOVERY_CONFIG, KIT_HTTP_CONFIG, KIT_LAST_AUTH_EMAIL_KEY, KIT_OVERLAY_CONFIG, KIT_REALTIME_CLIENT_ID, KIT_THEME_STORAGE_KEY, KitAuthAccessService, KitAuthInputDirective, KitAuthRecoveryService, KitLoadingController, KitMaintenanceController, KitOverlayController, KitRealtimeConnection, KitRealtimeLivenessWatchdog, KitReloadAlertController, KitStorageService, arrayConcatById, disableHandler, isExplicitAuthDenial, isMaintenanceError, kitAuthInterceptor, kitChangeEventDisabled, kitClearStoragePreservingKeys, kitCreateDidEnter, kitForgetEmail, kitImpact, kitIsValidEmail, kitKeyboardInit, kitPresentAuthFailedAlert, kitPresentLanguageActionSheet, kitRealtimeProtocols, kitRecallEmail, kitRememberEmail, kitRequireAuthorizedGuard, kitRequireConfirmingGuard, kitRequiredUnauthorizedGuard, mountViewModel, objectEqual, provideKitAuth, provideKitHttp, provideKitOverlay, toKitWebSocketUrl };
|
|
2599
2704
|
//# sourceMappingURL=rdlabo-ionic-angular-kit.mjs.map
|