@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 CHANGED
@@ -419,8 +419,7 @@ provideKitAuth(() => {
419
419
  resume: () => offline.resumeRemoteSession(),
420
420
  };
421
421
  },
422
- onUnavailable: async (_state, _error, lease) =>
423
- (await offline.activateOfflineSession(auth.currentSubject(), lease)) !== null,
422
+ onUnavailable: async (_state, _error, lease) => (await offline.activateOfflineSession(auth.currentSubject(), lease)) !== null,
424
423
  isUnavailableError: isOfflineFallbackError,
425
424
  remoteRecovery: {
426
425
  availability: () => auth.authorityAvailable$,
@@ -428,8 +427,7 @@ provideKitAuth(() => {
428
427
  const session = await auth.tryExchangeCredential();
429
428
  return session
430
429
  ? {
431
- activate: (lease) =>
432
- offline.prepareRemoteSession(session.userId, session.groupIds, session.subject, lease),
430
+ activate: (lease) => offline.prepareRemoteSession(session.userId, session.groupIds, session.subject, lease),
433
431
  resume: () => offline.resumeRemoteSession(),
434
432
  }
435
433
  : false;
@@ -669,8 +667,20 @@ export const appConfig: ApplicationConfig = {
669
667
  ```
670
668
 
671
669
  For an offline replica, use
672
- `withInterceptors([offlineInterceptor, kitAuthInterceptor])` in that order. Authentication/bootstrap endpoints that
673
- must run before `remote` is granted must be explicitly covered by `bypass`; do not globally relax
670
+ `withInterceptors([offlineInterceptor, kitAuthInterceptor])` in that order. The credential-exchange
671
+ request that must run before `remote` is granted sets `KIT_AUTH_BOOTSTRAP_REQUEST` in its
672
+ `HttpContext`, together with the offline entry point's `OFFLINE_BYPASS`:
673
+
674
+ ```ts
675
+ const context = new HttpContext().set(KIT_AUTH_BOOTSTRAP_REQUEST, true).set(OFFLINE_BYPASS, true);
676
+ http.post('/login', body, { context });
677
+ ```
678
+
679
+ It still receives authentication headers and uses the normal denial/error pipeline; only the
680
+ pre-existing `remote` requirement is deferred. The auth interceptor never consults its configured
681
+ offline fallback for this request, while `OFFLINE_BYPASS` prevents an outer offline interceptor
682
+ from replacing a transport failure with local data. Do not use the broader HTTP `bypass` hook,
683
+ because that also skips authentication headers and error handling, and do not globally relax
674
684
  `enforceAuthAccessMode`.
675
685
 
676
686
  **Error dispatch** (after retries, in `catchError`):
@@ -1399,6 +1399,11 @@ class OfflineSessionService {
1399
1399
  this.#localAccessThisRun = false;
1400
1400
  this.#remoteActivatedThisRun = false;
1401
1401
  }
1402
+ /** Immediately revoke local and remote runtime access while durable cleanup is pending. */
1403
+ revokeAccess() {
1404
+ this.#localAccessThisRun = false;
1405
+ this.#remoteActivatedThisRun = false;
1406
+ }
1402
1407
  /** Disable remote pull/replay eligibility while retaining the verified local manifest. */
1403
1408
  async suspendRemoteSession() {
1404
1409
  await this.initialize();
@@ -1488,6 +1493,7 @@ class OfflineSyncService {
1488
1493
  #knownScopes;
1489
1494
  #activeUserId;
1490
1495
  #flushPromise;
1496
+ #flushTransitions;
1491
1497
  #generation;
1492
1498
  #sendingTransitions;
1493
1499
  #enqueueTail;
@@ -1507,6 +1513,7 @@ class OfflineSyncService {
1507
1513
  this.#knownScopes = new Map();
1508
1514
  this.#activeUserId = null;
1509
1515
  this.#flushPromise = null;
1516
+ this.#flushTransitions = new Set();
1510
1517
  this.#generation = 0;
1511
1518
  this.#sendingTransitions = new Set();
1512
1519
  this.#enqueueTail = Promise.resolve();
@@ -1566,7 +1573,8 @@ class OfflineSyncService {
1566
1573
  await this.#refreshState();
1567
1574
  }
1568
1575
  async resetSession() {
1569
- this.#invalidateFlush();
1576
+ this.revokeSession();
1577
+ await Promise.allSettled([this.#enqueueTail, ...this.#flushTransitions]);
1570
1578
  await this.#waitForSendingTransitions();
1571
1579
  await this.#restoreInterruptedCommands();
1572
1580
  this.#activeUserId = null;
@@ -1574,12 +1582,17 @@ class OfflineSyncService {
1574
1582
  this.#commands.set([]);
1575
1583
  this.#scheduleRetry(null);
1576
1584
  }
1585
+ /** Synchronously invalidate in-flight enqueue and transport work owned by the current session. */
1586
+ revokeSession() {
1587
+ this.#invalidateFlush();
1588
+ }
1577
1589
  enqueue(request, options = {}) {
1578
- const enqueue = this.#enqueueTail.then(() => this.#enqueue(request, options));
1590
+ const generation = this.#generation;
1591
+ const enqueue = this.#enqueueTail.then(() => this.#enqueue(request, options, generation));
1579
1592
  this.#enqueueTail = enqueue.then(() => undefined, () => undefined);
1580
1593
  return enqueue;
1581
1594
  }
1582
- async #enqueue(request, options) {
1595
+ async #enqueue(request, options, generation) {
1583
1596
  await this.initialize();
1584
1597
  const session = await this.#getLocalSession();
1585
1598
  if (!session)
@@ -1628,6 +1641,9 @@ class OfflineSyncService {
1628
1641
  fetchedAt: Date.now(),
1629
1642
  syncState: 'pending',
1630
1643
  };
1644
+ if (generation !== this.#generation) {
1645
+ throw new Error('Offline session changed before the command could be persisted');
1646
+ }
1631
1647
  await this.#repository.transactReplica({ putRows: [optimisticRow], putCommands: [command] });
1632
1648
  await this.#refreshState();
1633
1649
  if (options.flush !== false && this.#network.connected())
@@ -1665,10 +1681,12 @@ class OfflineSyncService {
1665
1681
  return this.#flushPromise;
1666
1682
  const generation = this.#generation;
1667
1683
  const promise = this.#runFlush(generation).finally(() => {
1684
+ this.#flushTransitions.delete(promise);
1668
1685
  if (this.#flushPromise === promise)
1669
1686
  this.#flushPromise = null;
1670
1687
  });
1671
1688
  this.#flushPromise = promise;
1689
+ this.#flushTransitions.add(promise);
1672
1690
  return promise;
1673
1691
  }
1674
1692
  async #runFlush(generation) {
@@ -2109,6 +2127,8 @@ class OfflineCoordinatorService {
2109
2127
  });
2110
2128
  }
2111
2129
  clearActiveSession() {
2130
+ this.#sync.revokeSession();
2131
+ this.#session.revokeAccess();
2112
2132
  ++this.#transitionRevision;
2113
2133
  return this.#enqueueTransition(async () => {
2114
2134
  await this.#sync.resetSession();